mild refactor

This commit is contained in:
Jet 2023-07-09 13:24:14 +01:00
parent 9b72a14f01
commit 640ab01909
3 changed files with 34 additions and 20 deletions

View File

@ -11,9 +11,8 @@ void setup() {
// start the frontend and don't exit until either timer elapse or user ends it
// the timer here is set at 2 minutes
unsigned long timer = millis();
Frontend frontend;
while (!frontend.do_spoof && (millis() - timer < 120000)) {
Frontend frontend(120000);
while (!frontend.do_spoof) {
frontend.handleClient();
}

View File

@ -1,6 +1,6 @@
#include "frontend.h"
Frontend::Frontend()
Frontend::Frontend(unsigned long idletime)
: server(80)
{
// AP parameters
@ -21,10 +21,19 @@ Frontend::Frontend()
// Starting the Server
server.begin();
// record the time the server started and when to end
timer = millis();
maxtime = timer + idletime;
}
void Frontend::handleClient() {
server.handleClient();
// automatically start spoofing if we've passed the maxtime
if (millis() > maxtime) {
startSpoof();
}
}
void Frontend::handleOnConnect() {
@ -32,21 +41,22 @@ void Frontend::handleOnConnect() {
server.send(200, "text/html", HTML());
}
void Frontend::handleNotFound() {
server.send(404, "text/plain", "Not found");
}
void Frontend::startSpoof() {
do_spoof = true;
WiFi.softAPdisconnect (true);
}
void Frontend::handleForm() {
latitude = server.arg("latitude").toFloat();
longitude = server.arg("longitude").toFloat();
server.send(200, "text/html", HTML());
}
void Frontend::startSpoof() {
do_spoof = true;
server.stop();
WiFi.softAPdisconnect (true);
}
void Frontend::handleNotFound() {
server.send(404, "text/plain", "Not found");
}
String Frontend::HTML() {
String msg = R"rawliteral(
<!DOCTYPE html>
@ -56,7 +66,10 @@ String Frontend::HTML() {
<title>Remote ID Spoofer</title>
<style>
html{font-family:Helvetica; display:inline-block; margin:0px auto; text-align:center;}
body{margin-top: 50px;} h1{color: #444444; margin: 50px auto 30px;} h3{color:#444444; margin-bottom: 50px;}
body{margin-top: 50px;}
h1{color: #444444; margin: 50px auto 30px;}
h3{color:#444444; margin-bottom: 50px;}
form{color:#444444; margin-bottom: 50px;}
.button{display:block; width:80px; background-color:#f48100; border:none; color:white; padding: 13px 30px; text-decoration:none; font-size:25px; margin: 0px auto 35px; cursor:pointer; border-radius:4px;}
.button-on{background-color:#f48100;}
.button-on:active{background-color:#f48100;}
@ -79,9 +92,9 @@ String Frontend::HTML() {
msg += String(longitude, 10);
msg += "</p>\n";
msg += "<p>Pressing this button will cause the device to turn off the web server and enter spoofing only mode.</p>\n";
msg += "<p>Please confirm your GPS coordinates before doing so.</p>\n";
msg += "<p>You will not be able to reconnect to this page without a power cycle.</p>\n";
msg += "<p>Pressing this button will cause the device to turn off the web server and enter spoofing only mode.\n";
msg += "Please confirm your GPS coordinates before doing so.\n";
msg += "You will not be able to reconnect to this page without a power cycle.</p>\n";
msg += "<a class=\"button button-on\" href=\"/start\">Start Spoofing</a>\n";
msg += R"rawliteral(

View File

@ -9,12 +9,14 @@ class Frontend {
ESP8266WebServer server;
String HTML();
void handleOnConnect();
void handleNotFound();
void startSpoof();
void handleForm();
void startSpoof();
void handleNotFound();
unsigned long maxtime = 0.0;
unsigned long timer = 0.0;
public:
Frontend();
Frontend(unsigned long idletime);
void handleClient();
bool do_spoof = false;
double latitude = 52.439100;