The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
installmgr.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * installmgr.cpp - InstallMgr functions
4  *
5  * $Id: installmgr.cpp 3822 2020-11-03 18:54:47Z scribe $
6  *
7  * Copyright 2002-2013 CrossWire Bible Society (http://www.crosswire.org)
8  * CrossWire Bible Society
9  * P. O. Box 2528
10  * Tempe, AZ 85280-2528
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU General Public License as published by the
14  * Free Software Foundation version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * General Public License for more details.
20  *
21  */
22 
23 #ifndef EXCLUDEZLIB
24 #include <zipcomprs.h>
25 #endif
26 
27 #include <installmgr.h>
28 #include <filemgr.h>
29 #include <utilstr.h>
30 
31 #include <swmgr.h>
32 #include <swmodule.h>
33 #include <swversion.h>
34 #include <swlog.h>
35 #include <dirent.h>
36 
37 #include <stdio.h>
38 #include <map>
39 
40 #ifdef CURLAVAILABLE
41 #include <curlftpt.h>
42 #include <curlhttpt.h>
43 #else
44 #include <ftplibftpt.h>
45 #endif
46 
47 #include <iostream>
48 
49 
50 using std::map;
51 
52 
54 
55 namespace {
56 
57  static void removeTrailingSlash(SWBuf &buf) {
58  int len = (int)buf.size();
59  if ((buf[len-1] == '/')
60  || (buf[len-1] == '\\'))
61  buf.size(len-1);
62  }
63 
64  static const char *masterRepoList = "masterRepoList.conf";
65 
66 }
67 
68 
69 const unsigned int InstallMgr::MODSTAT_OLDER = 0x001;
70 const unsigned int InstallMgr::MODSTAT_SAMEVERSION = 0x002;
71 const unsigned int InstallMgr::MODSTAT_UPDATED = 0x004;
72 const unsigned int InstallMgr::MODSTAT_NEW = 0x008;
73 const unsigned int InstallMgr::MODSTAT_CIPHERED = 0x010;
74 const unsigned int InstallMgr::MODSTAT_CIPHERKEYPRESENT = 0x020;
76 
77 
78 // override this method and provide your own custom RemoteTransport subclass
79 // here we try a couple defaults if sword was compiled with support for them.
80 // see these classes for examples of how to make your own
82 #ifdef CURLAVAILABLE
83  return new CURLFTPTransport(host, statusReporter);
84 #else
85  return new FTPLibFTPTransport(host, statusReporter);
86 #endif
87 }
88 
89 
91 #ifdef CURLAVAILABLE
92  return new CURLHTTPTransport(host, statusReporter);
93 #else
94  return 0;
95 #endif
96 }
97 
98 
99 InstallMgr::InstallMgr(const char *privatePath, StatusReporter *sr, SWBuf u, SWBuf p) {
100  passive = true;
101  timeoutMillis = 10000;
102  unverifiedPeerAllowed = true;
103  statusReporter = sr;
104  this->u = u;
105  this->p = p;
106  this->privatePath = 0;
107  this->transport = 0;
108  installConf = 0;
109  stdstr(&(this->privatePath), privatePath);
110  if (this->privatePath) {
111  int len = (int)strlen(this->privatePath);
112  if ((this->privatePath[len-1] == '/')
113  || (this->privatePath[len-1] == '\\'))
114  this->privatePath[len-1] = 0;
115  }
116  confPath = (SWBuf)privatePath + "/InstallMgr.conf";
118 
119  readInstallConf();
120 }
121 
122 
124  delete [] privatePath;
125  delete installConf;
126  clearSources();
127 }
128 
129 
131  for (InstallSourceMap::iterator it = sources.begin(); it != sources.end(); ++it) {
132  delete it->second;
133  }
134  sources.clear();
135 }
136 
137 
139 
140  if (installConf) delete installConf;
141 
143 
144  clearSources();
145 
146  setFTPPassive(stricmp((*installConf)["General"]["PassiveFTP"].c_str(), "false") != 0);
147  long t = atol((*installConf)["General"]["TimeoutMillis"].c_str());
148  if (t > 0) setTimeoutMillis(t);
149  setUnverifiedPeerAllowed(stricmp((*installConf)["General"]["UnverifiedPeerAllowed"].c_str(), "false") != 0);
150 
151  SectionMap::iterator confSection = installConf->getSections().find("Sources");
152  ConfigEntMap::iterator sourceBegin;
153  ConfigEntMap::iterator sourceEnd;
154 
155  if (confSection != installConf->getSections().end()) {
156 
157  sourceBegin = confSection->second.lower_bound("FTPSource");
158  sourceEnd = confSection->second.upper_bound("FTPSource");
159 
160  while (sourceBegin != sourceEnd) {
161  InstallSource *is = new InstallSource("FTP", sourceBegin->second.c_str());
162  sources[is->caption] = is;
163  SWBuf parent = (SWBuf)privatePath + "/" + is->uid + "/file";
164  FileMgr::createParent(parent.c_str());
165  is->localShadow = (SWBuf)privatePath + "/" + is->uid;
166  sourceBegin++;
167  }
168 
169 #ifdef CURLSFTPAVAILABLE
170  sourceBegin = confSection->second.lower_bound("SFTPSource");
171  sourceEnd = confSection->second.upper_bound("SFTPSource");
172 
173  while (sourceBegin != sourceEnd) {
174  InstallSource *is = new InstallSource("SFTP", sourceBegin->second.c_str());
175  sources[is->caption] = is;
176  SWBuf parent = (SWBuf)privatePath + "/" + is->uid + "/file";
177  FileMgr::createParent(parent.c_str());
178  is->localShadow = (SWBuf)privatePath + "/" + is->uid;
179  sourceBegin++;
180  }
181 #endif // CURLSFTPAVAILABLE
182 
183  sourceBegin = confSection->second.lower_bound("HTTPSource");
184  sourceEnd = confSection->second.upper_bound("HTTPSource");
185 
186  while (sourceBegin != sourceEnd) {
187  InstallSource *is = new InstallSource("HTTP", sourceBegin->second.c_str());
188  sources[is->caption] = is;
189  SWBuf parent = (SWBuf)privatePath + "/" + is->uid + "/file";
190  FileMgr::createParent(parent.c_str());
191  is->localShadow = (SWBuf)privatePath + "/" + is->uid;
192  sourceBegin++;
193  }
194 
195  sourceBegin = confSection->second.lower_bound("HTTPSSource");
196  sourceEnd = confSection->second.upper_bound("HTTPSSource");
197 
198  while (sourceBegin != sourceEnd) {
199  InstallSource *is = new InstallSource("HTTPS", sourceBegin->second.c_str());
200  sources[is->caption] = is;
201  SWBuf parent = (SWBuf)privatePath + "/" + is->uid + "/file";
202  FileMgr::createParent(parent.c_str());
203  is->localShadow = (SWBuf)privatePath + "/" + is->uid;
204  sourceBegin++;
205  }
206  }
207 
208  defaultMods.clear();
209  confSection = installConf->getSections().find("General");
210  if (confSection != installConf->getSections().end()) {
211  sourceBegin = confSection->second.lower_bound("DefaultMod");
212  sourceEnd = confSection->second.upper_bound("DefaultMod");
213 
214  while (sourceBegin != sourceEnd) {
215  defaultMods.insert(sourceBegin->second.c_str());
216  sourceBegin++;
217  }
218  }
219 }
220 
221 
223 
224  installConf->getSection("Sources").clear();
225 
226  for (InstallSourceMap::iterator it = sources.begin(); it != sources.end(); ++it) {
227  if (it->second) {
228  installConf->getSection("Sources").insert(ConfigEntMap::value_type(it->second->type + "Source", it->second->getConfEnt().c_str()));
229  }
230  }
231  (*installConf)["General"]["PassiveFTP"] = (isFTPPassive()) ? "true" : "false";
232  (*installConf)["General"]["UnverifiedPeerAllowed"] = (isUnverifiedPeerAllowed()) ? "true" : "false";
233 
234  installConf->save();
235 }
236 
237 
239 
240 
241 int InstallMgr::removeModule(SWMgr *manager, const char *moduleName) {
242  SectionMap::iterator module;
243  ConfigEntMap::iterator fileBegin;
244  ConfigEntMap::iterator fileEnd, entry;
245 
246  // save our own copy, cuz when we remove the module from the SWMgr
247  // it's likely we'll free the memory passed to us in moduleName
248  SWBuf modName = moduleName;
249  module = manager->config->getSections().find(modName);
250 
251  if (module != manager->config->getSections().end()) {
252  // to be sure all files are closed
253  // this does not remove the .conf information from SWMgr
254  manager->deleteModule(modName);
255 
256  fileBegin = module->second.lower_bound("File");
257  fileEnd = module->second.upper_bound("File");
258 
259  SWBuf modFile;
260  SWBuf modDir;
261  entry = module->second.find("AbsoluteDataPath");
262  modDir = entry->second.c_str();
263  removeTrailingSlash(modDir);
264  if (fileBegin != fileEnd) { // remove each file
265  while (fileBegin != fileEnd) {
266  modFile = modDir;
267  modFile += "/";
268  modFile += fileBegin->second.c_str();
269  //remove file
270  FileMgr::removeFile(modFile.c_str());
271  fileBegin++;
272  }
273  }
274  else { //remove all files in DataPath directory
275  ConfigEntMap::iterator entry;
276  FileMgr::removeDir(modDir.c_str());
277  std::vector<DirEntry> dirList = FileMgr::getDirList(manager->configPath);
278  for (unsigned int i = 0; i < dirList.size(); ++i) {
279  if (dirList[i].name.endsWith(".conf")) {
280  modFile = manager->configPath;
281  removeTrailingSlash(modFile);
282  modFile += "/";
283  modFile += dirList[i].name;
284  SWConfig *config = new SWConfig(modFile.c_str());
285  if (config->getSections().find(modName) != config->getSections().end()) {
286  delete config;
287  FileMgr::removeFile(modFile.c_str());
288  }
289  else delete config;
290  }
291  }
292  }
293  return 0;
294  }
295  return 1;
296 }
297 
298 
299 // TODO: rename to netCopy
300 int InstallMgr::remoteCopy(InstallSource *is, const char *src, const char *dest, bool dirTransfer, const char *suffix) {
301 SWLOGD("remoteCopy: %s, %s, %s, %c, %s", (is?is->source.c_str():"null"), src, (dest?dest:"null"), (dirTransfer?'t':'f'), (suffix?suffix:"null"));
302 
303  // assert user disclaimer has been confirmed
304  if (!isUserDisclaimerConfirmed()) return -1;
305 
306  int retVal = 0;
307  RemoteTransport *trans = 0;
308  if (is->type == "FTP"
309 #ifdef CURLSFTPAVAILABLE
310  || is->type == "SFTP"
311 #endif
312  ) {
313 
315  trans->setPassive(passive);
317  }
318  else if (is->type == "HTTP" || is->type == "HTTPS") {
320  }
321  transport = trans; // set classwide current transport for other thread terminate() call
322  if (is->u.length()) {
323  trans->setUser(is->u);
324  trans->setPasswd(is->p);
325  }
326  else {
327  trans->setUser(u);
328  trans->setPasswd(p);
329  }
330 
332 
333  SWBuf urlPrefix;
334  if (is->type == "HTTP") {
335  urlPrefix = (SWBuf) "http://";
336  }
337  else if (is->type == "HTTPS") {
338  urlPrefix = (SWBuf) "https://";
339  }
340 #ifdef CURLSFTPAVAILABLE
341  else if (is->type == "SFTP") {
342  urlPrefix = (SWBuf) "sftp://";
343  }
344 #endif
345  else {
346  urlPrefix = (SWBuf) "ftp://";
347  }
348  urlPrefix.append(is->source);
349 
350  // let's be sure we can connect. This seems to be necessary but sucks
351 // SWBuf url = urlPrefix + is->directory.c_str() + "/"; //dont forget the final slash
352 // if (trans->getURL("swdirlist.tmp", url.c_str())) {
353 // SWLOGD("FTPCopy: failed to get dir %s\n", url.c_str());
354 // return -1;
355 // }
356 
357 
358  if (dirTransfer) {
359  SWBuf dir = (SWBuf)is->directory.c_str();
360  removeTrailingSlash(dir);
361  dir += (SWBuf)"/" + src; //dont forget the final slash
362 SWLOGD("remoteCopy: dirTransfer: %s", dir.c_str());
363 
364  retVal = trans->copyDirectory(urlPrefix, dir, dest, suffix);
365 
366 
367  }
368  else {
369  SWTRY {
370  SWBuf url = urlPrefix + is->directory.c_str();
371  removeTrailingSlash(url);
372  url += (SWBuf)"/" + src; //dont forget the final slash
373  retVal = trans->getURL(dest, url.c_str());
374  if (retVal) {
375 SWLOGD("netCopy: failed to get file %s", url.c_str());
376  }
377  }
378  SWCATCH (...) {
379  retVal = -1;
380  }
381  }
382  SWTRY {
383  RemoteTransport *deleteMe = trans;
384  // do this order for threadsafeness
385  // (see terminate())
386  trans = transport = 0;
387  delete deleteMe;
388  }
389  SWCATCH (...) {}
390  return retVal;
391 }
392 
393 
394 int InstallMgr::installModule(SWMgr *destMgr, const char *fromLocation, const char *modName, InstallSource *is) {
395  int retVal = 0;
396  SectionMap::iterator module, section;
397  ConfigEntMap::iterator fileBegin;
398  ConfigEntMap::iterator fileEnd;
399  ConfigEntMap::iterator entry;
400  SWBuf sourceDir;
401  SWBuf buffer;
402  bool aborted = false;
403  bool cipher = false;
404  SWBuf modFile;
405 
406 SWLOGD("***** InstallMgr::installModule\n");
407  if (fromLocation) {
408 SWLOGD("***** fromLocation: %s \n", fromLocation);
409  }
410 SWLOGD("***** modName: %s \n", modName);
411 
412  if (is)
413  sourceDir = (SWBuf)privatePath + "/" + is->uid;
414  else sourceDir = fromLocation;
415 
416  removeTrailingSlash(sourceDir);
417  sourceDir += '/';
418 
419  SWMgr mgr(sourceDir.c_str());
420 
421  module = mgr.config->getSections().find(modName);
422 
423  if (module != mgr.config->getSections().end()) {
424 
425  entry = module->second.find("CipherKey");
426  if (entry != module->second.end())
427  cipher = true;
428 
429  //
430  // This first check is a method to allow a module to specify each
431  // file that needs to be copied
432  //
433  fileEnd = module->second.upper_bound("File");
434  fileBegin = module->second.lower_bound("File");
435 
436  if (fileBegin != fileEnd) { // copy each file
437  if (is) {
438  while (fileBegin != fileEnd) { // netCopy each file first
439  buffer = sourceDir + fileBegin->second.c_str();
440  if (remoteCopy(is, fileBegin->second.c_str(), buffer.c_str())) {
441  aborted = true;
442  break; // user aborted
443  }
444  fileBegin++;
445  }
446  fileBegin = module->second.lower_bound("File");
447  }
448 
449  if (!aborted) {
450  // DO THE INSTALL
451  while (fileBegin != fileEnd && !retVal) {
452  SWBuf sourcePath = sourceDir;
453  sourcePath += fileBegin->second.c_str();
454  SWBuf dest = destMgr->prefixPath;
455  removeTrailingSlash(dest);
456  dest += '/';
457  dest += fileBegin->second.c_str();
458  retVal = FileMgr::copyFile(sourcePath.c_str(), dest.c_str());
459 
460  fileBegin++;
461  }
462  }
463  //---------------
464 
465  if (is) {
466  fileBegin = module->second.lower_bound("File");
467  while (fileBegin != fileEnd) { // delete each tmp netCopied file
468  buffer = sourceDir + fileBegin->second.c_str();
469  FileMgr::removeFile(buffer.c_str());
470  fileBegin++;
471  }
472  }
473  }
474 
475  // This is the REAL install code, the above code I don't think has
476  // ever been used
477  //
478  // Copy all files in DataPath directory
479  //
480  else {
481  ConfigEntMap::iterator entry;
482 
483  entry = module->second.find("AbsoluteDataPath");
484  if (entry != module->second.end()) {
485  SWBuf absolutePath = entry->second.c_str();
486  SWBuf relativePath = absolutePath;
487  entry = module->second.find("PrefixPath");
488  if (entry != module->second.end()) {
489  relativePath << strlen(entry->second.c_str());
490  }
491  else {
492  relativePath << strlen(mgr.prefixPath);
493  }
494 SWLOGD("***** mgr.prefixPath: %s \n", mgr.prefixPath);
495 SWLOGD("***** destMgr->prefixPath: %s \n", destMgr->prefixPath);
496 SWLOGD("***** absolutePath: %s \n", absolutePath.c_str());
497 SWLOGD("***** relativePath: %s \n", relativePath.c_str());
498 
499  if (is) {
500  if (remoteCopy(is, relativePath.c_str(), absolutePath.c_str(), true)) {
501  aborted = true; // user aborted
502  }
503  }
504  if (!aborted) {
505  SWBuf destPath = (SWBuf)destMgr->prefixPath + relativePath;
506  retVal = FileMgr::copyDir(absolutePath.c_str(), destPath.c_str());
507  }
508  if (is) { // delete tmp netCopied files
509 // mgr->deleteModule(modName);
510  FileMgr::removeDir(absolutePath.c_str());
511  }
512  }
513  }
514  if (!aborted) {
515  SWBuf confDir = sourceDir + "mods.d/";
516  std::vector<DirEntry> dirList = FileMgr::getDirList(confDir);
517  for (unsigned int i = 0; i < dirList.size() && !retVal; ++i) {
518  if (dirList[i].name.endsWith(".conf")) {
519  modFile = confDir;
520  modFile += dirList[i].name;
521  SWConfig *config = new SWConfig(modFile);
522  if (config->getSections().find(modName) != config->getSections().end()) {
523  SWBuf targetFile = destMgr->configPath; //"./mods.d/";
524  removeTrailingSlash(targetFile);
525  targetFile += "/";
526  targetFile += dirList[i].name;
527  retVal = FileMgr::copyFile(modFile.c_str(), targetFile.c_str());
528  if (cipher) {
529  if (getCipherCode(modName, config)) {
530  SWMgr newDest(destMgr->prefixPath);
531  removeModule(&newDest, modName);
532  aborted = true;
533  }
534  else {
535  config->save();
536  retVal = FileMgr::copyFile(modFile.c_str(), targetFile.c_str());
537  }
538  }
539  }
540  delete config;
541  }
542  }
543  }
544  return (aborted) ? -9 : retVal;
545  }
546  return 1;
547 }
548 
549 
551 
552  // assert user disclaimer has been confirmed
553  if (!isUserDisclaimerConfirmed()) return -1;
554 
555  SWBuf root = (SWBuf)privatePath + (SWBuf)"/" + is->uid.c_str();
556  removeTrailingSlash(root);
557  SWBuf target = root + "/mods.d";
558  int errorCode = -1; //0 means successful
559 
560  FileMgr::removeDir(target.c_str());
561 
562  if (!FileMgr::existsDir(target))
563  FileMgr::createPathAndFile(target+"/globals.conf");
564 
565 #ifndef EXCLUDEZLIB
566  SWBuf archive = root + "/mods.d.tar.gz";
567 
568  errorCode = remoteCopy(is, "mods.d.tar.gz", archive.c_str(), false);
569  if (!errorCode) { //sucessfully downloaded the tar,gz of module configs
570  int fd = FileMgr::openFileReadOnly(archive.c_str());
571  ZipCompress::unTarGZ(fd, root.c_str());
572  FileMgr::closeFile(fd);
573  }
574  else if (errorCode > -2) // don't try the next attempt on connection error or user requested termination
575 #endif
576  errorCode = remoteCopy(is, "mods.d", target.c_str(), true, ".conf"); //copy the whole directory
577 
578  is->flush();
579  return errorCode;
580 }
581 
582 
583 bool InstallMgr::isDefaultModule(const char *modName) {
584  return defaultMods.count(modName);
585 }
586 
587 
588 /************************************************************************
589  * getModuleStatus - compare the modules of two SWMgrs and return a
590  * vector describing the status of each. See MODSTAT_*
591  */
592 map<SWModule *, int> InstallMgr::getModuleStatus(const SWMgr &base, const SWMgr &other, bool utilModules) {
593  map<SWModule *, int> retVal;
594  SWBuf targetVersion;
595  SWBuf sourceVersion;
596  SWBuf softwareVersion;
597  bool cipher;
598  bool keyPresent;
599  int modStat;
600 
601  for (ModMap::const_iterator mod = (!utilModules ? other.getModules().begin() : other.getUtilModules().begin()); mod != (!utilModules ? other.getModules().end() : other.getUtilModules().end()); ++mod) {
602 
603  modStat = 0;
604 
605  cipher = false;
606  keyPresent = false;
607 
608  const char *v = mod->second->getConfigEntry("CipherKey");
609  if (v) {
610  cipher = true;
611  keyPresent = *v;
612  }
613 
614  targetVersion = "0.0";
615  sourceVersion = "1.0";
616  softwareVersion = (const char *)SWVersion::currentVersion;
617 
618  v = mod->second->getConfigEntry("Version");
619  if (v) sourceVersion = v;
620 
621  v = mod->second->getConfigEntry("MinimumVersion");
622  if (v) softwareVersion = v;
623 
624  const SWModule *baseMod = base.getModule(mod->first);
625  if (baseMod) {
626  targetVersion = "1.0";
627  v = baseMod->getConfigEntry("Version");
628  if (v) targetVersion = v;
629  modStat |= (SWVersion(sourceVersion.c_str()) > SWVersion(targetVersion.c_str())) ? MODSTAT_UPDATED : (SWVersion(sourceVersion.c_str()) < SWVersion(targetVersion.c_str())) ? MODSTAT_OLDER : MODSTAT_SAMEVERSION;
630  }
631  else modStat |= MODSTAT_NEW;
632 
633  if (cipher) modStat |= MODSTAT_CIPHERED;
634  if (keyPresent) modStat |= MODSTAT_CIPHERKEYPRESENT;
635  retVal[mod->second] = modStat;
636  }
637  return retVal;
638 }
639 
640 
641 /************************************************************************
642  * refreshRemoteSourceConfiguration - grab master list of know remote
643  * sources and integrate it with our configurations.
644  */
646 
647  // assert user disclaimer has been confirmed
648  if (!isUserDisclaimerConfirmed()) return -1;
649 
650  SWBuf root = (SWBuf)privatePath;
651  removeTrailingSlash(root);
652  SWBuf masterRepoListPath = root + "/" + masterRepoList;
653  InstallSource is("FTP");
654  is.source = "ftp.crosswire.org";
655  is.directory = "/pub/sword";
656  int errorCode = remoteCopy(&is, masterRepoList, masterRepoListPath.c_str(), false);
657  if (!errorCode) { //sucessfully downloaded the repo list
658  SWConfig masterList(masterRepoListPath);
659  SectionMap::iterator sections = masterList.getSections().find("Repos");
660  if (sections != masterList.getSections().end()) {
661  for (ConfigEntMap::iterator actions = sections->second.begin(); actions != sections->second.end(); actions++) {
662  // Search through our current sources and see if we have a matching UID
663  InstallSourceMap::iterator it;
664  for (it = sources.begin(); it != sources.end(); ++it) {
665  // is this our UID?
666  if ((it->second) && (it->second->uid == actions->first)) {
667  if (actions->second == "REMOVE") {
668  // be sure to call save/reload after this
669  // or this could be dangerous
670  delete it->second;
671  it->second = 0;
672  }
673  else {
674  SWBuf key = actions->second.stripPrefix('=');
675  if (key == "FTPSource") {
676  // we might consider instantiating a temp IS
677  // from our config string and then copy only
678  // some entries. This would allow the use to
679  // change some fields and not have them overwritten
680  // but it seems like we might want to change any
681  // of the current fields so we don't do this now
682  // InstallSource i("FTP", actions->second);
683  delete it->second;
684  it->second = new InstallSource("FTP", actions->second.c_str());
685  it->second->uid = actions->first;
686  }
687  }
688  break;
689  }
690  }
691  // didn't find our UID, let's add it
692  if (it == sources.end()) {
693  SWBuf key = actions->second.stripPrefix('=');
694  if (key == "FTPSource") {
695  if (actions->second != "REMOVE") {
696  InstallSource *is = new InstallSource("FTP", actions->second.c_str());
697  is->uid = actions->first;
698  sources[is->caption] = is;
699  }
700  }
701  }
702  }
703 
704  // persist and re-read
705  saveInstallConf();
706  readInstallConf();
707 
708  return 0;
709  }
710  }
711  return -1;
712 }
713 
714 
715 InstallSource::InstallSource(const char *type, const char *confEnt) {
716  this->type = type;
717  mgr = 0;
718  userData = 0;
719  if (confEnt) {
720  SWBuf buf = confEnt;
721  caption = buf.stripPrefix('|', true);
722  source = buf.stripPrefix('|', true);
723  directory = buf.stripPrefix('|', true);
724  u = buf.stripPrefix('|', true);
725  p = buf.stripPrefix('|', true);
726  uid = buf.stripPrefix('|', true);
727 
728  if (!uid.length()) uid = source;
729 
731  }
732 }
733 
734 
736  if (mgr)
737  delete mgr;
738 }
739 
740 
742  if (mgr) {
743  delete mgr;
744  mgr = 0;
745  }
746 }
747 
748 
750  if (!mgr)
751  // ..., false = don't augment ~home directory.
752  mgr = new SWMgr(localShadow.c_str(), true, 0, false, false);
753  return mgr;
754 }
755 
756 
778 
780  std::cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
781  std::cout << " -=+* WARNING *+=- -=+* WARNING *+=-\n\n\n";
782  std::cout << "Although Install Manager provides a convenient way for installing\n";
783  std::cout << "and upgrading SWORD components, it also uses a systematic method\n";
784  std::cout << "for accessing sites which gives packet sniffers a target to lock\n";
785  std::cout << "into for singling out users. \n\n\n";
786  std::cout << "IF YOU LIVE IN A PERSECUTED COUNTRY AND DO NOT WISH TO RISK DETECTION,\n";
787  std::cout << "YOU SHOULD *NOT* USE INSTALL MANAGER'S REMOTE SOURCE FEATURES.\n\n\n";
788  std::cout << "Also, Remote Sources other than CrossWire may contain less than\n";
789  std::cout << "quality modules, modules with unorthodox content, or even modules\n";
790  std::cout << "which are not legitimately distributable. Many repositories\n";
791  std::cout << "contain wonderfully useful content. These repositories simply\n";
792  std::cout << "are not reviewed or maintained by CrossWire and CrossWire\n";
793  std::cout << "cannot be held responsible for their content. CAVEAT EMPTOR.\n\n\n";
794  std::cout << "If you understand this and are willing to enable remote source features\n";
795  std::cout << "then type yes at the prompt\n\n";
796  std::cout << "enable? [no] ";
797 
798  char prompt[10];
799  fgets(prompt, 9, stdin);
800  userDisclaimerConfirmed = (!strcmp(prompt, "yes\n"));
801  std::cout << "\n";
802  }
804 }
805 
806 
808 
void clearSources()
Definition: installmgr.cpp:130
virtual int refreshRemoteSourceConfiguration()
Definition: installmgr.cpp:645
static char unTarGZ(int fd, const char *destPath)
Definition: zipcomprs.cpp:373
void terminate()
Definition: installmgr.cpp:238
static const char * masterRepoList
Definition: installmgr.cpp:64
#define SWORD_NAMESPACE_START
Definition: defs.h:39
void setUnverifiedPeerAllowed(bool val)
Definition: remotetrans.h:98
Definition: swmgr.h:93
bool unverifiedPeerAllowed
Definition: installmgr.h:80
static int removeDir(const char *targetDir)
Definition: filemgr.cpp:639
Definition: swbuf.h:47
bool isFTPPassive()
Definition: installmgr.h:267
unsigned long length() const
Definition: swbuf.h:197
SWMgr * getMgr()
Definition: installmgr.cpp:749
virtual RemoteTransport * createFTPTransport(const char *host, StatusReporter *statusReporter)
Definition: installmgr.cpp:81
static const unsigned int MODSTAT_OLDER
Definition: installmgr.h:99
static const unsigned int MODSTAT_CIPHERKEYPRESENT
Definition: installmgr.h:104
virtual SectionMap & getSections()
Definition: swconfig.cpp:186
SWBuf source
Definition: installmgr.h:51
char * privatePath
Definition: installmgr.h:74
void setTimeoutMillis(long timeoutMillis)
Definition: remotetrans.h:93
static signed char existsDir(const char *ipath, const char *idirName=0)
Definition: filemgr.cpp:357
static int openFileReadOnly(const char *fName)
Definition: filemgr.cpp:474
virtual const char * getConfigEntry(const char *key) const
Definition: swmodule.cpp:1159
virtual ~InstallSource()
Definition: installmgr.cpp:735
virtual char getURL(const char *destPath, const char *sourceURL, SWBuf *destBuf=0)
Definition: remotetrans.cpp:78
SWText * module
Definition: osis2mod.cpp:105
char * prefixPath
Definition: swmgr.h:312
StatusReporter * statusReporter
Definition: installmgr.cpp:48
preg buffer
Definition: regex.c:8089
bool isDefaultModule(const char *modName)
Definition: installmgr.cpp:583
ModMap & getModules()
Definition: swmgr.cpp:1574
ModMap & getUtilModules()
Definition: swmgr.cpp:1575
static void closeFile(int fd)
Definition: filemgr.cpp:491
SWBuf caption
Definition: installmgr.h:50
void setPassive(bool passive)
Definition: remotetrans.h:92
#define SWTRY
Definition: defs.h:57
StatusReporter * statusReporter
Definition: installmgr.h:76
int stricmp(const char *s1, const char *s2)
Definition: utilstr.cpp:194
void setUnverifiedPeerAllowed(bool allowed)
Definition: installmgr.h:272
void setTimeoutMillis(long timeoutMillis)
Definition: installmgr.h:269
SWBuf p
Definition: installmgr.h:79
static const unsigned int MODSTAT_NEW
Definition: installmgr.h:102
virtual ~InstallMgr()
Definition: installmgr.cpp:123
SWModule * getModule(const char *modName)
Definition: swmgr.h:360
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
SWConfig * config
Definition: swmgr.h:302
ConfigEntMap & getSection(const char *section)
Definition: swconfig.h:76
void saveInstallConf()
Definition: installmgr.cpp:222
static std::map< SWModule *, int > getModuleStatus(const SWMgr &base, const SWMgr &other, bool utilModules=false)
Definition: installmgr.cpp:592
void * userData
Definition: installmgr.h:59
#define SWCATCH(x)
Definition: defs.h:58
bool isUnverifiedPeerAllowed()
Definition: installmgr.h:273
const char * c_str() const
Definition: swbuf.h:158
SWBuf & append(const char *str, long max=-1)
Definition: swbuf.h:274
static int removeFile(const char *fName)
Definition: filemgr.cpp:517
static int copyFile(const char *srcFile, const char *destFile)
Definition: filemgr.cpp:496
void readInstallConf()
Definition: installmgr.cpp:138
void setFTPPassive(bool passive)
Definition: installmgr.h:266
int copyDirectory(const char *urlPrefix, const char *dir, const char *dest, const char *suffix)
static void removeTrailingSlash(SWBuf &buf)
Definition: installmgr.cpp:57
SWBuf u
Definition: installmgr.h:79
void setUser(const char *user)
Definition: remotetrans.h:96
std::set< SWBuf > defaultMods
Definition: installmgr.h:73
static const unsigned int MODSTAT_CIPHERED
Definition: installmgr.h:103
InstallSourceMap sources
Definition: installmgr.h:111
static int createParent(const char *pName)
Definition: filemgr.cpp:426
unsigned long size() const
Definition: swbuf.h:185
const char * stripPrefix(char separator, bool endOfStringAsSeparator=false)
Definition: swbuf.h:457
bool passive
Definition: installmgr.h:77
static bool userDisclaimerConfirmed
Definition: installmgr.h:98
static std::vector< struct DirEntry > getDirList(const char *dirPath, bool includeSize=false, bool includeIsDirectory=true)
Definition: filemgr.cpp:379
virtual int installModule(SWMgr *destMgr, const char *fromLocation, const char *modName, InstallSource *is=0)
Definition: installmgr.cpp:394
void setPasswd(const char *passwd)
Definition: remotetrans.h:97
static SWVersion currentVersion
Definition: swversion.h:69
static int createPathAndFile(const char *fName)
Definition: filemgr.cpp:479
SWBuf confPath
Definition: installmgr.h:75
SWBuf localShadow
Definition: installmgr.h:58
long timeoutMillis
Definition: installmgr.h:78
SWConfig * installConf
Definition: installmgr.h:106
virtual int remoteCopy(InstallSource *is, const char *src, const char *dest, bool dirTransfer=false, const char *suffix="")
Definition: installmgr.cpp:300
virtual int refreshRemoteSource(InstallSource *is)
Definition: installmgr.cpp:550
static int copyDir(const char *srcDir, const char *destDir)
Definition: filemgr.cpp:618
void deleteModule(const char *)
Definition: swmgr.cpp:1535
virtual RemoteTransport * createHTTPTransport(const char *host, StatusReporter *statusReporter)
Definition: installmgr.cpp:90
InstallMgr(const char *privatePath="./", StatusReporter *statusReporter=0, SWBuf u="ftp", SWBuf p="installmgr@user.com")
Definition: installmgr.cpp:99
static const unsigned int MODSTAT_UPDATED
Definition: installmgr.h:101
#define SWORD_NAMESPACE_END
Definition: defs.h:40
SWMgr * mgr
Definition: installmgr.h:43
#define SWLOGD(...)
Definition: defs.h:187
RemoteTransport * transport
Definition: installmgr.h:94
SWBuf directory
Definition: installmgr.h:52
virtual int removeModule(SWMgr *manager, const char *modName)
Definition: installmgr.cpp:241
virtual bool getCipherCode(const char *modName, SWConfig *config)
Definition: installmgr.h:222
InstallSource(const char *type, const char *confEnt=0)
Definition: installmgr.cpp:715
char * configPath
Definition: swmgr.h:316
virtual bool isUserDisclaimerConfirmed() const
Definition: installmgr.cpp:777
SWMgr * mgr
Definition: installmgr.cpp:46
static const unsigned int MODSTAT_SAMEVERSION
Definition: installmgr.h:100
virtual void save() const
Definition: swconfig.cpp:115
static time_t base
Definition: ftpparse.c:47