You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MainClass.cpp 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // Created by robin on 8/8/15.
  3. //
  4. #include <iostream>
  5. #include <sysexits.h>
  6. #include <DBO/Result.h>
  7. #include "CommandLineParser.h"
  8. #include "Business/PdnsSlave.h"
  9. #include "MainClass.h"
  10. MainClass::MainClass(int argc, char *argv[])
  11. : _argc(argc)
  12. , _argv(argv)
  13. {
  14. }
  15. int MainClass::main()
  16. {
  17. CommandLineOption configFile("config", 'c', "Path to the configuration file",
  18. "FILE", "/etc/pdns-slave/pdns-slave.json");
  19. CommandLineOption check("check", 'C', "Only check configurations", "", "");
  20. CommandLineOption help("help", 'h', "Displays this help", "", "");
  21. CommandLineParser parser(_argc, _argv);
  22. parser.addOption(&help);
  23. parser.addOption(&configFile);
  24. parser.addOption(&check);
  25. if (!parser.parse())
  26. return parser.showHelp(EX_USAGE);
  27. if (help.isSet())
  28. return parser.showHelp(0, false);
  29. auto filePath = configFile.getValue();
  30. std::cout << "Using configuration file " << filePath << std::endl;
  31. PdnsSlave pdnsSlave(filePath);
  32. BResult res;
  33. Result<Actions> res2;
  34. std::cout << "Reading pdns-slave configuration" << std::endl;
  35. if (!(res = pdnsSlave.readConfig()))
  36. {
  37. std::cerr << "Failed to read pdns-slave configuration" << std::endl;
  38. res.print();
  39. return 1;
  40. }
  41. res.print();
  42. std::cout << "Reading dhcpd template" << std::endl;
  43. if (!(res = pdnsSlave.readDhcpdTemplate()))
  44. {
  45. std::cerr << "Failed to read dhcpd template" << std::endl;
  46. res.print();
  47. return 2;
  48. }
  49. res.print();
  50. std::cout << "Reading hosts configuration" << std::endl;
  51. if (!(res2 = pdnsSlave.readHosts()))
  52. {
  53. std::cerr << "Failed to read hosts configuration" << std::endl;
  54. res2.print();
  55. return 3;
  56. }
  57. res2.print();
  58. if (!check.isSet())
  59. {
  60. std::cout << "Overriding dns" << std::endl;
  61. if (!(res = pdnsSlave.overridePdns()))
  62. {
  63. std::cerr << "Failed to override dns" << std::endl;
  64. res.print();
  65. return 4;
  66. }
  67. res.print();
  68. std::cout << "Overriding dhcp" << std::endl;
  69. if (!(res = pdnsSlave.overrideDhcp()))
  70. {
  71. std::cerr << "Failed to override dhcp" << std::endl;
  72. res.print();
  73. return 5;
  74. }
  75. res.print();
  76. }
  77. return 0;
  78. }