get firewall rule over url parameter and regex

This commit is contained in:
Florian Hoss 2022-04-11 18:19:03 +02:00
parent 0e1bf6a915
commit 945f1fd3b6
3 changed files with 24 additions and 7 deletions

View file

@ -26,7 +26,7 @@ void ESPFirewall::add_rule_to_firewall(firewall_rule_t *rule)
return;
}
void ESPFirewall::get_firewall_handler(AsyncWebServerRequest *request)
void ESPFirewall::get_firewall_rules_handler(AsyncWebServerRequest *request)
{
firewall_rule_t *ptr = this->head;
DynamicJsonDocument json(1024);
@ -47,6 +47,17 @@ void ESPFirewall::get_firewall_handler(AsyncWebServerRequest *request)
request->send(200, "application/json", response);
}
void ESPFirewall::get_firewall_rule_handler(AsyncWebServerRequest *request)
{
int rule_number = request->pathArg(0).toInt();
DynamicJsonDocument json(1024);
String response;
json["message"] = "get firewall rule";
json["key"] = rule_number;
serializeJson(json, response);
request->send(404, "application/json", response);
}
void ESPFirewall::post_firewall_handler(AsyncWebServerRequest *request)
{
DynamicJsonDocument json(1024);
@ -103,7 +114,8 @@ bool ESPFirewall::request_has_firewall_parameter(AsyncWebServerRequest *request)
void ESPFirewall::setup_routing()
{
firewall_api->on("/api/v1/firewall", HTTP_GET, std::bind(&ESPFirewall::get_firewall_handler, this, std::placeholders::_1));
firewall_api->on("^\\/api/v1/firewall\\/([0-9]+)$", HTTP_GET, std::bind(&ESPFirewall::get_firewall_rule_handler, this, std::placeholders::_1));
firewall_api->on("/api/v1/firewall", HTTP_GET, std::bind(&ESPFirewall::get_firewall_rules_handler, this, std::placeholders::_1));
firewall_api->on("/api/v1/firewall", HTTP_POST, std::bind(&ESPFirewall::post_firewall_handler, this, std::placeholders::_1));
firewall_api->onNotFound(std::bind(&ESPFirewall::not_found, this, std::placeholders::_1));
this->firewall_api->begin();

View file

@ -33,7 +33,8 @@ class ESPFirewall
struct firewall_rule *head = NULL;
void add_rule_to_firewall(firewall_rule_t *rule);
void get_firewall_handler(AsyncWebServerRequest *request);
void get_firewall_rules_handler(AsyncWebServerRequest *request);
void get_firewall_rule_handler(AsyncWebServerRequest *request);
void post_firewall_handler(AsyncWebServerRequest *request);
void not_found(AsyncWebServerRequest *request);
bool request_has_firewall_parameter(AsyncWebServerRequest *request);

View file

@ -13,7 +13,9 @@ platform = espressif32
board = esp32-evb
framework = arduino
monitor_speed = 115200
build_flags = -DCORE_DEBUG_LEVEL=3
build_flags =
-DCORE_DEBUG_LEVEL=3
-DASYNCWEBSERVER_REGEX
lib_deps =
bblanchon/ArduinoJson@^6.19.4
ottowinter/ESPAsyncWebServer-esphome@^2.1.0
@ -23,7 +25,9 @@ platform = espressif32
board = az-delivery-devkit-v4
framework = arduino
monitor_speed = 115200
build_flags = -DCORE_DEBUG_LEVEL=3
build_flags =
-DCORE_DEBUG_LEVEL=3
-DASYNCWEBSERVER_REGEX
lib_deps =
bblanchon/ArduinoJson@^6.19.4
ottowinter/ESPAsyncWebServer-esphome@^2.1.0