basic function to check client
This commit is contained in:
parent
dfb92d6bf9
commit
8e29479aea
3 changed files with 19 additions and 3 deletions
|
@ -118,4 +118,16 @@ namespace fw
|
||||||
Storage::store_all_firewall_rules(rule_head);
|
Storage::store_all_firewall_rules(rule_head);
|
||||||
return SUCCESS;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
#include "Storage.hpp"
|
#include "Storage.hpp"
|
||||||
|
#include "WiFiClient.h"
|
||||||
|
|
||||||
namespace fw
|
namespace fw
|
||||||
{
|
{
|
||||||
|
@ -18,6 +19,8 @@ namespace fw
|
||||||
firewall_rule_t *get_rule_from_firewall(const uint8_t key);
|
firewall_rule_t *get_rule_from_firewall(const uint8_t key);
|
||||||
ok_t delete_rule_from_firewall(const uint8_t key);
|
ok_t delete_rule_from_firewall(const uint8_t key);
|
||||||
|
|
||||||
|
bool is_client_allowed(WiFiClient client);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint8_t amount_of_rules = 0;
|
uint8_t amount_of_rules = 0;
|
||||||
firewall_rule_t *rule_head = NULL;
|
firewall_rule_t *rule_head = NULL;
|
||||||
|
|
|
@ -45,9 +45,10 @@ void loop()
|
||||||
WiFiClient client = wifiServer.available();
|
WiFiClient client = wifiServer.available();
|
||||||
if (client)
|
if (client)
|
||||||
{
|
{
|
||||||
Serial.print("Client connected with IP:");
|
if (firewall->is_client_allowed(client))
|
||||||
Serial.println(client.remoteIP());
|
Serial.println("allowed");
|
||||||
|
else
|
||||||
|
Serial.println("rejected");
|
||||||
client.stop();
|
client.stop();
|
||||||
Serial.println("Client disconnected");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in a new issue