This repository has been archived on 2024-10-30. You can view files and clone it, but cannot push or open issues or pull requests.
esp-firewall/ESPFirewall/src/main.cpp
2022-05-02 21:01:08 +02:00

57 lines
No EOL
1.1 KiB
C++

#include "theSecrets.h"
#include "theCerts.h"
#ifdef ESP32
#include "WiFi.h"
#elif defined(ESP8266)
#include "ESP8266WiFi.h"
#endif
#include "Firewall.hpp"
fw::Firewall *firewall;
String ip = "0.0.0.0";
WiFiServer wifiServer(80);
void setup_wifi()
{
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, psk);
Serial.printf("Attempting to connect to WPA SSID: %s\n", ssid);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print('.');
delay(1000);
}
Serial.println();
Serial.print("IP Address: ");
ip = WiFi.localIP().toString();
Serial.println(ip);
wifiServer.begin();
}
void setup()
{
setup_wifi();
firewall = new fw::Firewall(cert, key, username, password, ip, 8080);
}
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();
}