2022-04-10 20:46:54 +02:00
|
|
|
#ifndef FIREWALL_H
|
|
|
|
#define FIREWALL_H
|
|
|
|
|
2022-04-11 17:02:58 +02:00
|
|
|
#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"
|
2022-04-10 20:46:54 +02:00
|
|
|
|
2022-04-11 18:06:21 +02:00
|
|
|
#define PROTOCOL_LENGTH 4
|
|
|
|
#define TARGET_LENGTH 7
|
|
|
|
|
2022-04-11 11:47:50 +02:00
|
|
|
typedef struct firewall_rule
|
|
|
|
{
|
|
|
|
int key;
|
2022-04-11 17:46:44 +02:00
|
|
|
char source[IP4ADDR_STRLEN_MAX];
|
|
|
|
char destination[IP4ADDR_STRLEN_MAX];
|
2022-04-11 18:06:21 +02:00
|
|
|
char protocol[PROTOCOL_LENGTH];
|
|
|
|
char target[TARGET_LENGTH];
|
2022-04-11 11:47:50 +02:00
|
|
|
struct firewall_rule *next;
|
|
|
|
} firewall_rule_t;
|
|
|
|
|
2022-04-10 20:46:54 +02:00
|
|
|
class ESPFirewall
|
|
|
|
{
|
2022-04-11 17:02:58 +02:00
|
|
|
AsyncWebServer *firewall_api;
|
|
|
|
unsigned int amount_of_rules = 0;
|
|
|
|
struct firewall_rule *head = NULL;
|
2022-04-11 11:47:50 +02:00
|
|
|
|
2022-04-11 18:40:57 +02:00
|
|
|
void prepare_firewall_json(DynamicJsonDocument &json, firewall_rule_t *rule);
|
2022-04-11 18:06:21 +02:00
|
|
|
void add_rule_to_firewall(firewall_rule_t *rule);
|
2022-04-11 18:19:03 +02:00
|
|
|
void get_firewall_rules_handler(AsyncWebServerRequest *request);
|
|
|
|
void get_firewall_rule_handler(AsyncWebServerRequest *request);
|
2022-04-11 17:02:58 +02:00
|
|
|
void post_firewall_handler(AsyncWebServerRequest *request);
|
|
|
|
void not_found(AsyncWebServerRequest *request);
|
2022-04-11 18:06:21 +02:00
|
|
|
bool request_has_firewall_parameter(AsyncWebServerRequest *request);
|
2022-04-10 20:46:54 +02:00
|
|
|
void setup_routing();
|
|
|
|
|
|
|
|
public:
|
2022-04-11 11:47:50 +02:00
|
|
|
ESPFirewall(int port = 8080);
|
2022-04-10 20:46:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|