main.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 (-135KB)\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. std::string param(argv[i]);
  45. if (param == "--no-favicon") {
  46. if (no_http) continue;
  47. qInfo().noquote() << " * Web page favicon disabled";
  48. no_favicon = true;
  49. } else if (param == "--no-http") {
  50. if (no_api) continue;
  51. qInfo().noquote() << " * Web interface disabled";
  52. no_http = true;
  53. } else if (param == "--no-api") {
  54. if (no_http) continue;
  55. qInfo().noquote() << " * API disabled";
  56. no_api = true;
  57. } else if (param == "--no-resolve") {
  58. qInfo().noquote() << " * Resolving disabled (only meship)";
  59. no_resolve = true;
  60. }
  61. }
  62. if (no_favicon or no_http or no_api or no_resolve) {
  63. qInfo().noquote() << "";
  64. }
  65. // INIT OPTIONS AND START RESOLVER
  66. if (not no_http) {
  67. funcs::createHtmlPage(no_favicon);
  68. }
  69. Resolver server(address, port);
  70. if (no_http) server.disableWebPage();
  71. if (no_api) server.disableAPI();
  72. if (no_resolve) server.disableResolv();
  73. return a.exec();
  74. }