From 50ebe9a5a43a8ee982e4dbbfd46533dcc102ee0f Mon Sep 17 00:00:00 2001 From: Florian Hoss Date: Mon, 2 May 2022 21:01:08 +0200 Subject: [PATCH] thinking about how to compare firewall rules --- ESPFirewall/lib/Firewall/src/Firewall.hpp | 8 ++++++++ ESPFirewall/src/main.cpp | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/ESPFirewall/lib/Firewall/src/Firewall.hpp b/ESPFirewall/lib/Firewall/src/Firewall.hpp index bbd3b8f..e0dcaee 100644 --- a/ESPFirewall/lib/Firewall/src/Firewall.hpp +++ b/ESPFirewall/lib/Firewall/src/Firewall.hpp @@ -12,6 +12,7 @@ namespace fw Firewall(const char *, const char *, const char *, const char *, const String ip, const uint16_t = 8080); ~Firewall(); void handle_api_client(); + bool check_client(WiFiClient); }; Firewall::Firewall(const char *cert, const char *key, const char *username, const char *password, const String ip, const uint16_t port) @@ -21,6 +22,13 @@ namespace fw { handle_client(); } + bool Firewall::check_client(WiFiClient client) + { + if (client.remoteIP()) + return false; + else + return true; + } } #endif diff --git a/ESPFirewall/src/main.cpp b/ESPFirewall/src/main.cpp index 0d0d349..c0aa9ac 100644 --- a/ESPFirewall/src/main.cpp +++ b/ESPFirewall/src/main.cpp @@ -11,6 +11,7 @@ fw::Firewall *firewall; String ip = "0.0.0.0"; +WiFiServer wifiServer(80); void setup_wifi() { @@ -27,6 +28,7 @@ void setup_wifi() Serial.print("IP Address: "); ip = WiFi.localIP().toString(); Serial.println(ip); + wifiServer.begin(); } void setup() @@ -37,5 +39,19 @@ void setup() void loop() { + WiFiClient client = wifiServer.available(); + if (client) + { + Serial.print("Client connected with IP:"); + Serial.println(client.remoteIP()); + + if (firewall->check_client(client)) + Serial.println("good client"); + else + Serial.println("bad client"); + + client.stop(); + Serial.println("Client disconnected"); + } firewall->handle_api_client(); } \ No newline at end of file