create firewall rule set on startup
This commit is contained in:
parent
06b122de64
commit
66dffbc2fc
1 changed files with 15 additions and 15 deletions
|
@ -3,6 +3,7 @@
|
|||
ESPFirewall::ESPFirewall(int port)
|
||||
{
|
||||
this->setup_eeprom();
|
||||
this->eeprom_read_firewall_rules();
|
||||
log_i("Starting Firewall-API on %i", port);
|
||||
this->firewall_api = new AsyncWebServer(port);
|
||||
this->setup_routing();
|
||||
|
@ -57,9 +58,6 @@ firewall_target_t ESPFirewall::string_to_target(String &target)
|
|||
void ESPFirewall::setup_eeprom()
|
||||
{
|
||||
EEPROM.begin(this->eeprom_size);
|
||||
this->amount_of_rules = 0;
|
||||
// this->amount_of_rules = EEPROM.readUChar(this->eeprom_settings_head);
|
||||
log_i("Amount of Rules %i", this->amount_of_rules);
|
||||
}
|
||||
|
||||
void ESPFirewall::eeprom_write_firewall_rule(firewall_rule_t *rule_ptr)
|
||||
|
@ -87,15 +85,18 @@ void ESPFirewall::eeprom_read_firewall_rule(uint8_t &eeprom_address)
|
|||
eeprom_address += sizeof(firewall_protocol_t);
|
||||
rule_ptr->target = static_cast<firewall_target_t>(EEPROM.read(eeprom_address));
|
||||
eeprom_address += sizeof(firewall_target_t);
|
||||
log_i("Source: %s, Destination: %s, Protocol: %u, Target: %u",
|
||||
add_rule_to_firewall(rule_ptr);
|
||||
log_i("%s, %s, %s, %s",
|
||||
rule_ptr->source,
|
||||
rule_ptr->destination,
|
||||
rule_ptr->protocol,
|
||||
rule_ptr->target);
|
||||
protocol_to_string(rule_ptr->protocol),
|
||||
target_to_string(rule_ptr->target));
|
||||
}
|
||||
|
||||
void ESPFirewall::eeprom_read_firewall_rules()
|
||||
{
|
||||
this->amount_of_rules = EEPROM.readUChar(this->eeprom_settings_head);
|
||||
log_i("Amount of existing Rules %i", this->amount_of_rules);
|
||||
uint8_t eeprom_address = eeprom_start_firewall_rules;
|
||||
for (uint8_t i = 0; i < this->amount_of_rules; i++)
|
||||
{
|
||||
|
@ -103,29 +104,29 @@ void ESPFirewall::eeprom_read_firewall_rules()
|
|||
}
|
||||
}
|
||||
|
||||
void ESPFirewall::add_rule_to_firewall(firewall_rule_t *rule)
|
||||
void ESPFirewall::add_rule_to_firewall(firewall_rule_t *rule_ptr)
|
||||
{
|
||||
firewall_rule_t *temp;
|
||||
if (head == NULL)
|
||||
if (this->head == NULL)
|
||||
{
|
||||
head = rule;
|
||||
rule->next = NULL;
|
||||
this->head = rule_ptr;
|
||||
rule_ptr->next = NULL;
|
||||
return;
|
||||
}
|
||||
temp = head;
|
||||
temp = this->head;
|
||||
while (temp->next != NULL)
|
||||
{
|
||||
temp = temp->next;
|
||||
}
|
||||
temp->next = rule;
|
||||
rule->next = NULL;
|
||||
temp->next = rule_ptr;
|
||||
rule_ptr->next = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
firewall_rule_t *ESPFirewall::get_rule_from_firewall(int key)
|
||||
{
|
||||
firewall_rule_t *rule_ptr = this->head;
|
||||
if (head == NULL)
|
||||
if (this->head == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
@ -258,7 +259,6 @@ void ESPFirewall::get_firewall_rule_handler(AsyncWebServerRequest *request)
|
|||
|
||||
void ESPFirewall::get_firewall_rules_handler(AsyncWebServerRequest *request)
|
||||
{
|
||||
eeprom_read_firewall_rules();
|
||||
String response = construct_json_firewall();
|
||||
request->send(200, "application/json", response);
|
||||
}
|
||||
|
|
Reference in a new issue