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

57 lines
1.1 KiB
C++
Raw Normal View History

2022-04-10 20:46:54 +02:00
#include "theSecrets.h"
2022-04-24 18:28:41 +02:00
#include "theCerts.h"
2022-04-23 23:36:44 +02:00
#ifdef ESP32
2022-04-24 12:48:01 +02:00
#include "WiFi.h"
2022-04-23 23:36:44 +02:00
#elif defined(ESP8266)
2022-04-24 12:48:01 +02:00
#include "ESP8266WiFi.h"
2022-04-23 23:36:44 +02:00
#endif
2022-04-24 00:13:20 +02:00
#include "Firewall.hpp"
2022-04-20 07:58:06 +02:00
2022-04-24 00:13:20 +02:00
fw::Firewall *firewall;
2022-05-02 17:22:04 +02:00
String ip = "0.0.0.0";
WiFiServer wifiServer(80);
2022-04-10 20:46:54 +02:00
void setup_wifi()
{
2022-04-23 23:36:44 +02:00
Serial.begin(115200);
2022-04-10 20:46:54 +02:00
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, psk);
2022-04-23 23:36:44 +02:00
Serial.printf("Attempting to connect to WPA SSID: %s\n", ssid);
2022-04-21 16:10:31 +02:00
while (WiFi.status() != WL_CONNECTED)
2022-04-10 20:46:54 +02:00
{
2022-04-23 23:36:44 +02:00
Serial.print('.');
delay(1000);
2022-04-10 20:46:54 +02:00
}
2022-04-23 23:36:44 +02:00
Serial.println();
Serial.print("IP Address: ");
2022-05-02 17:22:04 +02:00
ip = WiFi.localIP().toString();
Serial.println(ip);
wifiServer.begin();
2022-04-10 20:46:54 +02:00
}
2022-04-10 14:38:03 +02:00
void setup()
{
2022-04-10 15:55:42 +02:00
setup_wifi();
2022-05-02 17:22:04 +02:00
firewall = new fw::Firewall(cert, key, username, password, ip, 8080);
2022-04-10 14:38:03 +02:00
}
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");
}
2022-04-24 00:13:20 +02:00
firewall->handle_api_client();
2022-04-10 14:38:03 +02:00
}