From 8e29479aea6c3f10d230baba14398de8d4b94827 Mon Sep 17 00:00:00 2001 From: Florian Hoss Date: Tue, 3 May 2022 20:40:42 +0200 Subject: [PATCH] basic function to check client --- ESPFirewall/lib/Firewall/src/Firewall.cpp | 12 ++++++++++++ ESPFirewall/lib/Firewall/src/Firewall.hpp | 3 +++ ESPFirewall/src/main.cpp | 7 ++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/ESPFirewall/lib/Firewall/src/Firewall.cpp b/ESPFirewall/lib/Firewall/src/Firewall.cpp index 72f178b..3d13968 100644 --- a/ESPFirewall/lib/Firewall/src/Firewall.cpp +++ b/ESPFirewall/lib/Firewall/src/Firewall.cpp @@ -118,4 +118,16 @@ namespace fw Storage::store_all_firewall_rules(rule_head); return SUCCESS; } + + bool Firewall::is_client_allowed(WiFiClient client) + { + const char *ip = client.remoteIP().toString().c_str(); + const uint16_t port = client.remotePort(); + + Serial.print("Client connected: "); + Serial.print(client.remoteIP()); + Serial.print(":"); + Serial.println(client.remotePort()); + return true; + } } diff --git a/ESPFirewall/lib/Firewall/src/Firewall.hpp b/ESPFirewall/lib/Firewall/src/Firewall.hpp index c033dbe..2427838 100644 --- a/ESPFirewall/lib/Firewall/src/Firewall.hpp +++ b/ESPFirewall/lib/Firewall/src/Firewall.hpp @@ -3,6 +3,7 @@ #include "Utils.hpp" #include "Storage.hpp" +#include "WiFiClient.h" namespace fw { @@ -18,6 +19,8 @@ namespace fw firewall_rule_t *get_rule_from_firewall(const uint8_t key); ok_t delete_rule_from_firewall(const uint8_t key); + bool is_client_allowed(WiFiClient client); + protected: uint8_t amount_of_rules = 0; firewall_rule_t *rule_head = NULL; diff --git a/ESPFirewall/src/main.cpp b/ESPFirewall/src/main.cpp index 43d6267..2e5e9c3 100644 --- a/ESPFirewall/src/main.cpp +++ b/ESPFirewall/src/main.cpp @@ -45,9 +45,10 @@ void loop() WiFiClient client = wifiServer.available(); if (client) { - Serial.print("Client connected with IP:"); - Serial.println(client.remoteIP()); + if (firewall->is_client_allowed(client)) + Serial.println("allowed"); + else + Serial.println("rejected"); client.stop(); - Serial.println("Client disconnected"); } } \ No newline at end of file