thinking about how to compare firewall rules

This commit is contained in:
Florian Hoss 2022-05-02 21:01:08 +02:00
parent 3e1ec7ebb0
commit 50ebe9a5a4
2 changed files with 24 additions and 0 deletions

View file

@ -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

View file

@ -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();
}