firewall routes can be created
This commit is contained in:
parent
9dfd1d06ab
commit
c33414ade1
2 changed files with 19 additions and 7 deletions
|
@ -7,11 +7,15 @@ ESPFirewall::ESPFirewall(int port)
|
||||||
this->setup_routing();
|
this->setup_routing();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESPFirewall::add_rule_to_firewall()
|
void ESPFirewall::add_rule_to_firewall(const char *source, const char *destination, const char *protocol, const char *target)
|
||||||
{
|
{
|
||||||
firewall_rule_t *temp;
|
firewall_rule_t *temp;
|
||||||
firewall_rule_t *link = (firewall_rule_t *)malloc(sizeof(firewall_rule_t));
|
firewall_rule_t *link = (firewall_rule_t *)malloc(sizeof(firewall_rule_t));
|
||||||
link->key = ++amount_of_rules;
|
link->key = ++amount_of_rules;
|
||||||
|
strcpy(link->source, source);
|
||||||
|
strcpy(link->destination, destination);
|
||||||
|
strcpy(link->protocol, protocol);
|
||||||
|
strcpy(link->target, target);
|
||||||
if (head == NULL)
|
if (head == NULL)
|
||||||
{
|
{
|
||||||
head = link;
|
head = link;
|
||||||
|
@ -39,6 +43,10 @@ void ESPFirewall::get_firewall_handler(AsyncWebServerRequest *request)
|
||||||
{
|
{
|
||||||
JsonObject rule = rules.createNestedObject();
|
JsonObject rule = rules.createNestedObject();
|
||||||
rule["key"] = ptr->key;
|
rule["key"] = ptr->key;
|
||||||
|
rule["source"] = ptr->source;
|
||||||
|
rule["destination"] = ptr->destination;
|
||||||
|
rule["protocol"] = ptr->protocol;
|
||||||
|
rule["target"] = ptr->target;
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
}
|
}
|
||||||
serializeJson(json, response);
|
serializeJson(json, response);
|
||||||
|
@ -52,15 +60,15 @@ void ESPFirewall::post_firewall_handler(AsyncWebServerRequest *request)
|
||||||
int response_code;
|
int response_code;
|
||||||
if (request->hasArg("source") || request->hasArg("destination") || request->hasArg("protocol") || request->hasArg("target"))
|
if (request->hasArg("source") || request->hasArg("destination") || request->hasArg("protocol") || request->hasArg("target"))
|
||||||
{
|
{
|
||||||
String source = request->arg("source");
|
const char *source = request->arg("source").c_str();
|
||||||
String destination = request->arg("destination");
|
const char *destination = request->arg("destination").c_str();
|
||||||
String protocol = request->arg("protocol");
|
const char *protocol = request->arg("protocol").c_str();
|
||||||
String target = request->arg("target");
|
const char *target = request->arg("target").c_str();
|
||||||
json["source"] = source;
|
json["source"] = source;
|
||||||
json["destination"] = destination;
|
json["destination"] = destination;
|
||||||
json["protocol"] = protocol;
|
json["protocol"] = protocol;
|
||||||
json["target"] = target;
|
json["target"] = target;
|
||||||
add_rule_to_firewall();
|
add_rule_to_firewall(source, destination, protocol, target);
|
||||||
response_code = 200;
|
response_code = 200;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -16,6 +16,10 @@
|
||||||
typedef struct firewall_rule
|
typedef struct firewall_rule
|
||||||
{
|
{
|
||||||
int key;
|
int key;
|
||||||
|
char source[IP4ADDR_STRLEN_MAX];
|
||||||
|
char destination[IP4ADDR_STRLEN_MAX];
|
||||||
|
char protocol[4];
|
||||||
|
char target[7];
|
||||||
struct firewall_rule *next;
|
struct firewall_rule *next;
|
||||||
} firewall_rule_t;
|
} firewall_rule_t;
|
||||||
|
|
||||||
|
@ -25,7 +29,7 @@ class ESPFirewall
|
||||||
unsigned int amount_of_rules = 0;
|
unsigned int amount_of_rules = 0;
|
||||||
struct firewall_rule *head = NULL;
|
struct firewall_rule *head = NULL;
|
||||||
|
|
||||||
void add_rule_to_firewall();
|
void add_rule_to_firewall(const char *source, const char *destination, const char *protocol, const char *target);
|
||||||
void get_firewall_handler(AsyncWebServerRequest *request);
|
void get_firewall_handler(AsyncWebServerRequest *request);
|
||||||
void post_firewall_handler(AsyncWebServerRequest *request);
|
void post_firewall_handler(AsyncWebServerRequest *request);
|
||||||
void not_found(AsyncWebServerRequest *request);
|
void not_found(AsyncWebServerRequest *request);
|
||||||
|
|
Reference in a new issue