#ifndef FIREWALL_H #define FIREWALL_H #include "Arduino.h" #include "AsyncJson.h" #include "ArduinoJson.h" #ifdef ESP32 #include "WiFi.h" #include "AsyncTCP.h" #elif defined(ESP8266) #include "ESP8266WiFi.h" #include "ESPAsyncTCP.h" #endif #include "ESPAsyncWebServer.h" #define PROTOCOL_LENGTH 4 #define TARGET_LENGTH 7 typedef struct firewall_rule { int key; char source[IP4ADDR_STRLEN_MAX]; char destination[IP4ADDR_STRLEN_MAX]; char protocol[PROTOCOL_LENGTH]; char target[TARGET_LENGTH]; struct firewall_rule *next; } firewall_rule_t; class ESPFirewall { unsigned int amount_of_rules = 0; struct firewall_rule *head = NULL; AsyncWebServer *firewall_api; // Firewall Actions void add_rule_to_firewall(firewall_rule_t *); firewall_rule_t *get_rule_from_firewall(int key); // Firewall-API Actions void setup_routing(); void json_message_response(AsyncWebServerRequest *, String, int); String construct_json_firewall_rule(firewall_rule_t *); String construct_json_firewall(); void not_found(AsyncWebServerRequest *); void get_firewall_rule_handler(AsyncWebServerRequest *); void get_firewall_rules_handler(AsyncWebServerRequest *); void post_firewall_handler(AsyncWebServerRequest *); bool request_has_firewall_parameter(AsyncWebServerRequest *); public: ESPFirewall(int port = 8080); }; #endif