mirror of
https://github.com/justcallmekoko/ESP32Marauder.git
synced 2025-12-12 07:40:58 -08:00
Join with saved wifi credentials
This commit is contained in:
@@ -1367,6 +1367,7 @@ void CommandLine::runCommand(String input) {
|
||||
else if (cmd_args.get(0) == JOIN_CMD) {
|
||||
int ap_sw = this->argSearch(&cmd_args, "-a");
|
||||
int pw_sw = this->argSearch(&cmd_args, "-p");
|
||||
int s_sw = this->argSearch(&cmd_args, "-s");
|
||||
|
||||
if ((ap_sw != -1) && (pw_sw != -1)) {
|
||||
int index = cmd_args.get(ap_sw + 1).toInt();
|
||||
@@ -1381,6 +1382,20 @@ void CommandLine::runCommand(String input) {
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
else if (s_sw != -1) {
|
||||
String ssid = settings_obj.loadSetting<String>("ClientSSID");
|
||||
String pw = settings_obj.loadSetting<String>("ClientPW");
|
||||
|
||||
if ((ssid != "") && (pw != "")) {
|
||||
wifi_scan_obj.joinWiFi(ssid, pw, false);
|
||||
#ifdef HAS_SCREEN
|
||||
menu_function_obj.changeMenu(menu_function_obj.current_menu);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
Serial.println("There are no saved WiFi credentials");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Serial.println("You did not provide the proper args");
|
||||
return;
|
||||
|
||||
@@ -160,7 +160,7 @@ 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";
|
||||
const char PROGMEM HELP_JOIN_CMD[] = "join -a <index> -p <password>";
|
||||
const char PROGMEM HELP_JOIN_CMD[] = "join -a <index> -p <password>/-s";
|
||||
|
||||
// Bluetooth sniff/scan
|
||||
const char PROGMEM HELP_BT_SNIFF_CMD[] = "sniffbt [-t] <airtag/flipper>";
|
||||
|
||||
@@ -2698,6 +2698,50 @@ void MenuFunctions::RunSetup()
|
||||
this->changeMenu(&wifiAPMenu);
|
||||
});
|
||||
|
||||
this->addNodes(&wifiGeneralMenu, "Join Saved WiFi", TFTWHITE, NULL, KEYBOARD_ICO, [this](){
|
||||
String ssid = settings_obj.loadSetting<String>("ClientSSID");
|
||||
String pw = settings_obj.loadSetting<String>("ClientPW");
|
||||
|
||||
if ((ssid != "") && (pw != "")) {
|
||||
wifi_scan_obj.joinWiFi(ssid, pw, false);
|
||||
this->changeMenu(&wifiGeneralMenu);
|
||||
}
|
||||
else {
|
||||
// Add the back button
|
||||
wifiAPMenu.list->clear();
|
||||
this->addNodes(&wifiAPMenu, text09, TFTLIGHTGREY, NULL, 0, [this]() {
|
||||
this->changeMenu(wifiAPMenu.parentMenu);
|
||||
});
|
||||
|
||||
// Populate the menu with buttons
|
||||
for (int i = 0; i < access_points->size(); i++) {
|
||||
// This is the menu node
|
||||
this->addNodes(&wifiAPMenu, access_points->get(i).essid, TFTCYAN, NULL, 255, [this, i](){
|
||||
// Join WiFi using mini keyboard
|
||||
#ifdef HAS_MINI_KB
|
||||
this->changeMenu(&miniKbMenu);
|
||||
String password = this->miniKeyboard(&miniKbMenu, true);
|
||||
if (password != "") {
|
||||
Serial.println("Using SSID: " + (String)access_points->get(i).essid + " Password: " + (String)password);
|
||||
wifi_scan_obj.currentScanMode = LV_JOIN_WIFI;
|
||||
wifi_scan_obj.StartScan(LV_JOIN_WIFI, TFT_YELLOW);
|
||||
wifi_scan_obj.joinWiFi(access_points->get(i).essid, password);
|
||||
this->changeMenu(current_menu);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Join WiFi using touch screen keyboard
|
||||
#ifdef HAS_TOUCH
|
||||
wifi_scan_obj.currentScanMode = LV_JOIN_WIFI;
|
||||
wifi_scan_obj.StartScan(LV_JOIN_WIFI, TFT_YELLOW);
|
||||
joinWiFiGFX(access_points->get(i).essid);
|
||||
#endif
|
||||
});
|
||||
}
|
||||
this->changeMenu(&wifiAPMenu);
|
||||
}
|
||||
});
|
||||
|
||||
wifiStationMenu.parentMenu = &wifiAPMenu;
|
||||
this->addNodes(&wifiStationMenu, text09, TFTLIGHTGREY, NULL, 0, [this]() {
|
||||
this->changeMenu(wifiStationMenu.parentMenu);
|
||||
|
||||
@@ -846,6 +846,10 @@ bool WiFiScan::joinWiFi(String ssid, String password, bool gui)
|
||||
display_obj.tft.setTextWrap(false, false);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
settings_obj.saveSetting<bool>("ClientSSID", ssid);
|
||||
settings_obj.saveSetting<bool>("ClientPW", password);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -860,6 +864,8 @@ void WiFiScan::initWiFi(uint8_t scan_mode) {
|
||||
this->force_probe = settings_obj.loadSetting<bool>(text_table4[6]);
|
||||
this->save_pcap = settings_obj.loadSetting<bool>(text_table4[7]);
|
||||
this->ep_deauth = settings_obj.loadSetting<bool>("EPDeauth");
|
||||
settings_obj.loadSetting<String>("ClientSSID");
|
||||
settings_obj.loadSetting<String>("ClientPW");
|
||||
//Serial.println(F("Initialization complete"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,10 @@ String Settings::loadSetting<String>(String key) {
|
||||
return json["Settings"][i]["value"];
|
||||
}
|
||||
|
||||
Serial.println("Did not find setting named " + (String)key + ". Creating...");
|
||||
if (this->createDefaultSettings(SPIFFS, true, json["Settings"].size(), "String", key))
|
||||
return "";
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -169,6 +173,52 @@ bool Settings::saveSetting<bool>(String key, bool value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T Settings::saveSetting(String key, String value) {}
|
||||
|
||||
template<>
|
||||
bool Settings::saveSetting<bool>(String key, String value) {
|
||||
DynamicJsonDocument json(1024); // ArduinoJson v6
|
||||
|
||||
if (deserializeJson(json, this->json_settings_string)) {
|
||||
Serial.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;
|
||||
|
||||
Serial.println("Saving setting...");
|
||||
|
||||
File settingsFile = SPIFFS.open("/settings.json", FILE_WRITE);
|
||||
|
||||
if (!settingsFile) {
|
||||
Serial.println(F("Failed to create settings file"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (serializeJson(json, settingsFile) == 0) {
|
||||
Serial.println(F("Failed to write to file"));
|
||||
}
|
||||
if (serializeJson(json, settings_string) == 0) {
|
||||
Serial.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
|
||||
|
||||
@@ -288,6 +338,18 @@ bool Settings::createDefaultSettings(fs::FS &fs, bool spec, uint8_t index, Strin
|
||||
jsonBuffer["Settings"][4]["range"]["min"] = false;
|
||||
jsonBuffer["Settings"][4]["range"]["max"] = true;
|
||||
|
||||
jsonBuffer["Settings"][5]["name"] = "ClientSSID";
|
||||
jsonBuffer["Settings"][5]["type"] = "String";
|
||||
jsonBuffer["Settings"][5]["value"] = "";
|
||||
jsonBuffer["Settings"][5]["range"]["min"] = "";
|
||||
jsonBuffer["Settings"][5]["range"]["max"] = "";
|
||||
|
||||
jsonBuffer["Settings"][6]["name"] = "ClientPW";
|
||||
jsonBuffer["Settings"][6]["type"] = "String";
|
||||
jsonBuffer["Settings"][6]["value"] = "";
|
||||
jsonBuffer["Settings"][6]["range"]["min"] = "";
|
||||
jsonBuffer["Settings"][6]["range"]["max"] = "";
|
||||
|
||||
//jsonBuffer.printTo(settingsFile);
|
||||
if (serializeJson(jsonBuffer, settingsFile) == 0) {
|
||||
Serial.println(F("Failed to write to file"));
|
||||
@@ -321,6 +383,23 @@ bool Settings::createDefaultSettings(fs::FS &fs, bool spec, uint8_t index, Strin
|
||||
Serial.println("Failed to write to file");
|
||||
}
|
||||
}
|
||||
|
||||
else if (typeStr == "String") {
|
||||
Serial.println("Creating String setting...");
|
||||
json["Settings"][index]["name"] = name;
|
||||
json["Settings"][index]["type"] = typeStr;
|
||||
json["Settings"][index]["value"] = "";
|
||||
json["Settings"][index]["range"]["min"] = "";
|
||||
json["Settings"][index]["range"]["max"] = "";
|
||||
|
||||
if (serializeJson(json, settings_string) == 0) {
|
||||
Serial.println("Failed to write to string");
|
||||
}
|
||||
|
||||
if (serializeJson(json, settingsFile) == 0) {
|
||||
Serial.println("Failed to write to file");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close the file
|
||||
|
||||
@@ -31,6 +31,9 @@ class Settings {
|
||||
template <typename T>
|
||||
T saveSetting(String key, bool value);
|
||||
|
||||
template <typename T>
|
||||
T saveSetting(String key, String value);
|
||||
|
||||
bool toggleSetting(String key);
|
||||
String getSettingType(String key);
|
||||
String setting_index_to_name(int i);
|
||||
|
||||
Reference in New Issue
Block a user