main.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "resolver.h"
  2. #include "version.h"
  3. #include "funcs.h"
  4. #include <QCoreApplication>
  5. #include <QDebug>
  6. int main(int argc, char *argv[])
  7. {
  8. if (argc < 3) {
  9. qInfo().noquote() << "\
  10. Usage: <address-to-bind> <port> [options]\n\n\
  11. --no-api\tStart without API (only HTTP version)\n\
  12. --no-http\tStart without web version (only API)\n\
  13. --no-resolve\tOnly meship domains mode\n\
  14. --no-favicon\tWeb page without favicon (-14KB)\n\n\
  15. Mario DNS tool v"+ VERSION + "\n";
  16. return 0;
  17. }
  18. QCoreApplication a(argc, argv);
  19. // ACII MODERN ART
  20. qInfo().noquote() <<"\
  21. +---------------------------------------+\n\
  22. | _ __ ___ __ _ _ __ _ ___ |\n\
  23. | | '_ ` _ \\ / _` | '__| |/ _ \\ |\n\
  24. | | | | | | | (_| | | | | (_) | |\n\
  25. | |_| |_| |_|\\__,_|_|_ |_|\\___/ _ |\n\
  26. | | | | | | | |\n\
  27. | __| |_ __ ___ | |_ ___ ___ | | |\n\
  28. | / _` | '_ \\/ __| | __/ _ \\ / _ \\| | |\n\
  29. | | (_| | | | \\__ \\ | || (_) | (_) | | |\n\
  30. | \\__,_|_| |_|___/ \\__\\___/ \\___/|_| |\n\
  31. | ver. " + VERSION + " |\n\
  32. +---------------------------------------+\n\
  33. | https://notabug.org/acetone/mario-dns |\n\
  34. | " + COPYRIGHT + " |\n\
  35. +---------------------------------------+\n";
  36. QString address(argv[1]);
  37. quint32 port(QString(argv[2]).toInt());
  38. // INPUT OPTIONS
  39. bool no_favicon = false;
  40. bool no_http = false;
  41. bool no_api = false;
  42. bool no_resolve = false;
  43. for (int i = 3; i < argc; ++i)
  44. {
  45. std::string param(argv[i]);
  46. if (param == "--no-favicon") {
  47. if (no_http) continue;
  48. qInfo().noquote() << " * Web page favicon disabled";
  49. no_favicon = true;
  50. } else if (param == "--no-http") {
  51. if (no_api) continue;
  52. qInfo().noquote() << " * Web interface disabled";
  53. no_http = true;
  54. } else if (param == "--no-api") {
  55. if (no_http) continue;
  56. qInfo().noquote() << " * API disabled";
  57. no_api = true;
  58. } else if (param == "--no-resolve") {
  59. qInfo().noquote() << " * Resolving disabled (only meship)";
  60. no_resolve = true;
  61. }
  62. }
  63. if (no_favicon or no_http or no_api or no_resolve) {
  64. qInfo().noquote() << "";
  65. }
  66. // INIT OPTIONS AND START RESOLVER
  67. if (not no_http) {
  68. funcs::createHtmlPage(no_favicon);
  69. }
  70. Resolver server(address, port);
  71. if (no_http) server.disableWebPage();
  72. if (no_api) server.disableAPI();
  73. if (no_resolve) server.disableResolv();
  74. return a.exec();
  75. }