works, needs more work

This commit is contained in:
Florian Hoss 2022-04-10 20:46:54 +02:00
parent f94639c1a0
commit 4d23c1039b
6 changed files with 75 additions and 66 deletions

View file

@ -0,0 +1,27 @@
#include "Firewall.h"
ESPFirewall::ESPFirewall()
{
log_i("Firewall!");
firewall_api->on("/api/v1/firewall", HTTP_GET, std::bind(&ESPFirewall::get_firewall_rules, this));
firewall_api->begin();
}
void ESPFirewall::get_firewall_rules()
{
this->custom_message_response("Firewall", 200);
}
void ESPFirewall::custom_message_response(const char *message, int response_code)
{
cJSON *json_response = cJSON_CreateObject();
cJSON_AddBoolToObject(json_response, "ok", true);
cJSON_AddStringToObject(json_response, "message", message);
firewall_api->send(response_code, "application/json", cJSON_Print(json_response));
cJSON_Delete(json_response);
}
void ESPFirewall::handle_clients()
{
this->firewall_api->handleClient();
}

View file

@ -0,0 +1,20 @@
#ifndef FIREWALL_H
#define FIREWALL_H
#include "WebServer.h"
#include "cJSON.h"
#include "esp32-hal-log.h"
class ESPFirewall
{
WebServer *firewall_api = new WebServer(8080);
void get_firewall_rules();
void setup_routing();
void custom_message_response(const char *message, int response_code);
public:
ESPFirewall();
void handle_clients();
};
#endif