cfg.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #include <kopano/platform.h>
  18. #include <iostream>
  19. #include <list>
  20. #include <getopt.h>
  21. using namespace std;
  22. #include "LDAPConfigCheck.h"
  23. #include "UnixConfigCheck.h"
  24. #include "ServerConfigCheck.h"
  25. #include "GatewayConfigCheck.h"
  26. #include "IcalConfigCheck.h"
  27. #include "MonitorConfigCheck.h"
  28. #include "SpoolerConfigCheck.h"
  29. #include "DAgentConfigCheck.h"
  30. static const struct option long_options[] = {
  31. { "help", no_argument, NULL, 'h' },
  32. { "ldap", required_argument, NULL, 'l' },
  33. { "unix", required_argument, NULL, 'u' },
  34. { "server", required_argument, NULL, 's' },
  35. { "gateway",required_argument, NULL, 'g' },
  36. { "ical", required_argument, NULL, 'i' },
  37. { "monitor",required_argument, NULL, 'm' },
  38. { "spooler",required_argument, NULL, 'p' },
  39. { "dagent", required_argument, NULL, 'a' },
  40. { "hosted", required_argument, NULL, 'c' },
  41. { "distributed", required_argument, NULL, 'd' },
  42. {},
  43. };
  44. static void print_help(char *lpszName)
  45. {
  46. cout << "Configuration files validator tool" << endl;
  47. cout << endl;
  48. cout << "Usage:" << endl;
  49. cout << lpszName << " [options]" << endl;
  50. cout << endl;
  51. cout << "[-l|--ldap] <file>\tLocation of LDAP plugin configuration file" << endl;
  52. cout << "[-u|--unix] <file>\tLocation of Unix plugin configuration file" << endl;
  53. cout << "[-s|--server] <file>\tLocation of kopano-server configuration file" << endl;
  54. cout << "[-g|--gateway] <file>\tLocation of kopano-gateway configuration file" << endl;
  55. cout << "[-i|--ical] <file>\tLocation of kopano-ical configuration file" << endl;
  56. cout << "[-m|--monitor] <file>\tLocation of kopano-monitor configuration file" << endl;
  57. cout << "[-p|--spooler] <file>\tLocation of kopano-spooler configuration file" << endl;
  58. cout << "[-a|--dagent] <file>\tLocation of kopano-dagent configuration file" << endl;
  59. cout << "[-c|--hosted] [y|n]\tForce multi-company/hosted support to \'on\' or \'off\'" << endl;
  60. cout << "[-d|--distributed] [y|n]\tForce multi-server/distributed support to \'on\' or \'off\'" << endl;
  61. cout << "[-h|--help]\t\tPrint this help text" << endl;
  62. }
  63. int main(int argc, char* argv[])
  64. {
  65. list<ECConfigCheck*> check;
  66. std::string strHosted, strMulti;
  67. bool bHosted = false;
  68. bool bMulti = false;
  69. while (true) {
  70. char c = getopt_long(argc, argv, "l:u:s:g:i:m:p:a:c:d:h", long_options, NULL);
  71. if (c == -1)
  72. break;
  73. switch (c) {
  74. case 'l':
  75. check.push_back(new LDAPConfigCheck(optarg));
  76. break;
  77. case 'u':
  78. check.push_back(new UnixConfigCheck(optarg));
  79. break;
  80. case 's':
  81. check.push_back(new ServerConfigCheck(optarg));
  82. /* Check if hosted is enabled, make sure we don't overwrite commandline */
  83. if (strHosted.empty())
  84. strHosted = (*check.rbegin())->getSetting("enable_hosted_kopano");
  85. break;
  86. case 'g':
  87. check.push_back(new GatewayConfigCheck(optarg));
  88. break;
  89. case 'i':
  90. check.push_back(new IcalConfigCheck(optarg));
  91. break;
  92. case 'm':
  93. check.push_back(new MonitorConfigCheck(optarg));
  94. break;
  95. case 'p':
  96. check.push_back(new SpoolerConfigCheck(optarg));
  97. break;
  98. case 'a':
  99. check.push_back(new DAgentConfigCheck(optarg));
  100. break;
  101. case 'c':
  102. strHosted = optarg;
  103. break;
  104. case 'd':
  105. strMulti = optarg;
  106. break;
  107. case 'h':
  108. default:
  109. print_help(argv[0]);
  110. return 0;
  111. }
  112. }
  113. if (check.empty()) {
  114. print_help(argv[0]);
  115. return 1;
  116. }
  117. bHosted = (strHosted[0] == 'y' || strHosted[0] == 'Y' ||
  118. strHosted[0] == 't' || strHosted[0] == 'T' ||
  119. strHosted[0] == '1');
  120. bMulti = (strMulti[0] == 'y' || strMulti[0] == 'Y' ||
  121. strMulti[0] == 't' || strMulti[0] == 'T' ||
  122. strMulti[0] == '1');
  123. for (const auto &it : check) {
  124. if (it->isDirty())
  125. continue;
  126. it->setHosted(bHosted);
  127. it->setMulti(bMulti);
  128. it->loadChecks();
  129. it->validate();
  130. /* We are only looping through the list once, just cleanup
  131. * and don't care about leaving broken pointers in the list. */
  132. delete it;
  133. }
  134. return 0;
  135. }