Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added WebConsole for v2 #1617

Open
wants to merge 7 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@
*.pyc

utils/web_converter/css_html_js_minify/__pycache__/

utils/simple_web_converter/__pycache__

web_interface/gz/*

.vscode
4 changes: 3 additions & 1 deletion esp8266_deauther/A_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#define DEFAULT_ESP8266

#define ENABLE_WEB_CONSOLE

// #define NODEMCU
// #define WEMOS_D1_MINI
// #define HACKHELD_VEGA
Expand Down Expand Up @@ -727,4 +729,4 @@
// ========== ERROR CHECKS ========== //
#if LED_MODE_BRIGHTNESS == 0
#error LED_MODE_BRIGHTNESS must not be zero!
#endif /* if LED_MODE_BRIGHTNESS == 0 */
#endif /* if LED_MODE_BRIGHTNESS == 0 */
Binary file added esp8266_deauther/data/web/js/webconsole.js.gz
Binary file not shown.
Binary file not shown.
Binary file added esp8266_deauther/data/web/webconsole.html.gz
Binary file not shown.
3 changes: 2 additions & 1 deletion esp8266_deauther/esp8266_deauther.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ extern "C" {

#include "oui.h"
#include "language.h"
#include "functions.h"
//#include "functions.h"
#include <LittleFS.h>
#include "settings.h"
#include "Names.h"
#include "SSIDs.h"
Expand Down
84 changes: 81 additions & 3 deletions esp8266_deauther/functions.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
/* This software is licensed under the MIT License: https://github.com/spacehuhntech/esp8266_deauther */

#pragma once
#ifndef __FUNCTIONS_H__
#define __FUNCTIONS_H__

#include "Arduino.h"
#include <LittleFS.h>
extern "C" {
#include "user_interface.h"
}
#include "src/ArduinoJson-v5.13.5/ArduinoJson.h"

#include "A_config.h"
/*
Here is a collection of useful functions and variables.
They are used globally via an 'extern' reference in every class.
Expand Down Expand Up @@ -247,22 +249,52 @@ String b2a(bool input) {
bool s2b(String input) {
return eqls(input, STR_TRUE);
}
// ===== WEBCONSOLE FUNCTIONS ===== //
#ifdef ENABLE_WEB_CONSOLE
String WebConsoleOutputCache="";

void WebConsoleMemoryHandler(){
//The main job of this funtion to clear the memory occupied by webconsole output cache
//If the cache uses memory more than 4kB, this function will clear the cache.
//This way we can limit the memory usage by webconsole
if(WebConsoleOutputCache.length()>4096){
//Clear the WebConsoleOutputCache
WebConsoleOutputCache="";
}
}
#endif

// ===== PRINT FUNCTIONS ===== //
void prnt(const String s) {
Serial.print(s);
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+=s;
#endif
}

void prnt(const bool b) {
Serial.print(b2s(b));
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+=b2s(b);
#endif
}

void prnt(const char c) {
Serial.print(c);
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+=(String)c;
#endif
}

void prnt(const char* ptr) {
Serial.print(FPSTR(ptr));
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+=FPSTR(ptr);
#endif
}

void prnt(const char* ptr, int len) {
Expand All @@ -271,30 +303,64 @@ void prnt(const char* ptr, int len) {

void prnt(const int i) {
Serial.print((String)i);
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+=(String)i;
#endif
}

void prnt(const uint32_t i) {
Serial.printf("%u", i);
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
char* s="";
sprintf(s,"%u",i);
WebConsoleOutputCache+=s;
#endif
}

void prntln() {
Serial.println();
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+='\n';
#endif
}

void prntln(const String s) {
Serial.println(s);
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+=s;
WebConsoleOutputCache+='\n';
#endif
}

void prntln(const bool b) {
Serial.println(b2s(b));
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+=b2s(b);
WebConsoleOutputCache+='\n';
#endif
}

void prntln(const char c) {
Serial.println(c);
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+=(String)c;
WebConsoleOutputCache+='\n';
#endif
}

void prntln(const char* ptr) {
Serial.println(FPSTR(ptr));
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+=FPSTR(ptr);
WebConsoleOutputCache+='\n';
#endif
}

void prntln(const char* ptr, int len) {
Expand All @@ -304,10 +370,21 @@ void prntln(const char* ptr, int len) {

void prntln(const int i) {
Serial.println((String)i);
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+=(String)i;
#endif
}

void prntln(const uint32_t i) {
Serial.printf("%u\r\n", i);
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
char* s="";
sprintf(s,"%u",i);
WebConsoleOutputCache+=s;
WebConsoleOutputCache+='\n';
#endif
}

/* ===== WiFi ===== */
Expand All @@ -331,6 +408,7 @@ void setOutputPower(float dBm) {
}

/* ===== MAC ADDRESSES ===== */
#include "oui.h"
bool macBroadcast(uint8_t* mac) {
for (uint8_t i = 0; i < 6; i++)
if (mac[i] != broadcast[i]) return false;
Expand Down Expand Up @@ -401,7 +479,6 @@ int binSearchVendors(uint8_t* searchBytes, int lowerEnd, int upperEnd) {

return -1;
}

String searchVendor(uint8_t* mac) {
String vendorName = String();
int pos = binSearchVendors(mac, 0, sizeof(data_macs) / 5 - 1);
Expand Down Expand Up @@ -828,4 +905,5 @@ String formatBytes(size_t bytes) {
else if (bytes < (1024 * 1024)) return String(bytes / 1024.0) + "KB";
else if (bytes < (1024 * 1024 * 1024)) return String(bytes / 1024.0 / 1024.0) + "MB";
else return String(bytes / 1024.0 / 1024.0 / 1024.0) + "GB";
}
}
#endif
2 changes: 1 addition & 1 deletion esp8266_deauther/oui.h
Original file line number Diff line number Diff line change
Expand Up @@ -39799,4 +39799,4 @@ const static uint8_t data_macs[] PROGMEM = {
0xFC, 0xFF, 0xAA, 0x57, 0x17
#endif
};
#endif
#endif
25 changes: 23 additions & 2 deletions esp8266_deauther/webfiles.h

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions esp8266_deauther/wifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ extern "C" {
#include "CLI.h"
#include "Attack.h"
#include "Scan.h"
#ifdef ENABLE_WEB_CONSOLE
#include "functions.h"
#endif

extern bool progmemToSpiffs(const char* adr, int len, String path);

Expand Down Expand Up @@ -295,6 +298,14 @@ namespace wifi {
server.on("/settings.html", HTTP_GET, []() {
sendProgmem(settingshtml, sizeof(settingshtml), W_HTML);
});
#ifdef ENABLE_WEB_CONSOLE
server.on("/webconsole.html", HTTP_GET, []() {
sendProgmem(webconsolehtml, sizeof(webconsolehtml), W_HTML);
});
server.on("/js/webconsole.js", HTTP_GET, []() {
sendProgmem(webconsolejs, sizeof(webconsolejs), W_JS);
});
#endif
server.on("/style.css", HTTP_GET, []() {
sendProgmem(stylecss, sizeof(stylecss), W_CSS);
});
Expand Down Expand Up @@ -414,7 +425,13 @@ namespace wifi {
String input = server.arg("cmd");
cli.exec(input);
});

#ifdef ENABLE_WEB_CONSOLE
server.on("/console", HTTP_GET, []() {
server.send(200, str(W_TXT), WebConsoleOutputCache.c_str());
//Clearing the cache once it is sent
WebConsoleOutputCache="";
});
#endif
server.on("/attack.json", HTTP_GET, []() {
server.send(200, str(W_JSON), attack.getStatusJSON());
});
Expand Down Expand Up @@ -462,4 +479,4 @@ namespace wifi {
dns.processNextRequest();
}
}
}
}
Loading