mirror of
https://github.com/SpacehuhnTech/esp8266_deauther.git
synced 2025-12-23 15:10:06 +01:00
Renamed SerialInterface to CLI
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
#ifndef SerialInterface_h
|
#ifndef CLI_h
|
||||||
#define SerialInterface_h
|
#define CLI_h
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
@@ -44,9 +44,9 @@ extern void printWifiStatus();
|
|||||||
extern void startAP(String path, String ssid, String password, uint8_t ch, bool hidden, bool captivePortal);
|
extern void startAP(String path, String ssid, String password, uint8_t ch, bool hidden, bool captivePortal);
|
||||||
extern void wifiUpdate();
|
extern void wifiUpdate();
|
||||||
|
|
||||||
class SerialInterface {
|
class CLI {
|
||||||
public:
|
public:
|
||||||
SerialInterface();
|
CLI();
|
||||||
void enable();
|
void enable();
|
||||||
void load();
|
void load();
|
||||||
void load(String filepath);
|
void load(String filepath);
|
||||||
@@ -81,4 +81,4 @@ class SerialInterface {
|
|||||||
bool eqlsCMD(int i, const char* keyword);
|
bool eqlsCMD(int i, const char* keyword);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ifndef SerialInterface_h
|
#endif // ifndef CLI_h
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,142 +1,142 @@
|
|||||||
#ifndef Settings_h
|
#ifndef Settings_h
|
||||||
#define Settings_h
|
#define Settings_h
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "user_interface.h"
|
#include "user_interface.h"
|
||||||
}
|
}
|
||||||
#include "ArduinoJson.h"
|
#include "ArduinoJson.h"
|
||||||
#include "language.h"
|
#include "language.h"
|
||||||
#include "A_config.h"
|
#include "A_config.h"
|
||||||
|
|
||||||
#define VERSION "v2.0.6"
|
#define VERSION "v2.0.6"
|
||||||
|
|
||||||
extern void checkFile(String path, String data);
|
extern void checkFile(String path, String data);
|
||||||
extern JsonVariant parseJSONFile(String path, DynamicJsonBuffer& jsonBuffer);
|
extern JsonVariant parseJSONFile(String path, DynamicJsonBuffer& jsonBuffer);
|
||||||
extern bool writeFile(String path, String& buf);
|
extern bool writeFile(String path, String& buf);
|
||||||
extern void saveJSONFile(String path, JsonObject& root);
|
extern void saveJSONFile(String path, JsonObject& root);
|
||||||
extern String macToStr(uint8_t* mac);
|
extern String macToStr(uint8_t* mac);
|
||||||
extern void getRandomMac(uint8_t* mac);
|
extern void getRandomMac(uint8_t* mac);
|
||||||
extern bool strToMac(String macStr, uint8_t* mac);
|
extern bool strToMac(String macStr, uint8_t* mac);
|
||||||
extern void setWifiChannel(uint8_t ch);
|
extern void setWifiChannel(uint8_t ch);
|
||||||
extern String fixUtf8(String str);
|
extern String fixUtf8(String str);
|
||||||
extern void copyWebFiles(bool force);
|
extern void copyWebFiles(bool force);
|
||||||
extern bool macValid(uint8_t* mac);
|
extern bool macValid(uint8_t* mac);
|
||||||
|
|
||||||
class Settings {
|
class Settings {
|
||||||
public:
|
public:
|
||||||
Settings();
|
Settings();
|
||||||
void load();
|
void load();
|
||||||
void load(String filepath);
|
void load(String filepath);
|
||||||
void save(bool force);
|
void save(bool force);
|
||||||
void save(bool force, String filepath);
|
void save(bool force, String filepath);
|
||||||
void reset();
|
void reset();
|
||||||
void print();
|
void print();
|
||||||
|
|
||||||
void set(const char* str, String value);
|
void set(const char* str, String value);
|
||||||
String get(const char* str);
|
String get(const char* str);
|
||||||
|
|
||||||
String getVersion();
|
String getVersion();
|
||||||
uint16_t getDeauthsPerTarget();
|
uint16_t getDeauthsPerTarget();
|
||||||
uint8_t getDeauthReason();
|
uint8_t getDeauthReason();
|
||||||
bool getBeaconChannel();
|
bool getBeaconChannel();
|
||||||
uint8_t getForcePackets();
|
uint8_t getForcePackets();
|
||||||
bool getAutosave();
|
bool getAutosave();
|
||||||
uint32_t getAutosaveTime();
|
uint32_t getAutosaveTime();
|
||||||
uint8_t getMaxCh();
|
uint8_t getMaxCh();
|
||||||
bool getBeaconInterval();
|
bool getBeaconInterval();
|
||||||
uint8_t getChannel();
|
uint8_t getChannel();
|
||||||
String getSSID();
|
String getSSID();
|
||||||
String getPassword();
|
String getPassword();
|
||||||
bool getSerialInterface();
|
bool getCLI();
|
||||||
bool getDisplayInterface();
|
bool getDisplayInterface();
|
||||||
bool getWebInterface();
|
bool getWebInterface();
|
||||||
uint16_t getChTime();
|
uint16_t getChTime();
|
||||||
uint8_t* getMacSt();
|
uint8_t* getMacSt();
|
||||||
uint8_t* getMacAP();
|
uint8_t* getMacAP();
|
||||||
bool getRandomTX();
|
bool getRandomTX();
|
||||||
uint32_t getAttackTimeout();
|
uint32_t getAttackTimeout();
|
||||||
bool getLedEnabled();
|
bool getLedEnabled();
|
||||||
uint8_t getProbesPerSSID();
|
uint8_t getProbesPerSSID();
|
||||||
bool getHidden();
|
bool getHidden();
|
||||||
bool getCaptivePortal();
|
bool getCaptivePortal();
|
||||||
uint16_t getMinDeauths();
|
uint16_t getMinDeauths();
|
||||||
uint32_t getDisplayTimeout();
|
uint32_t getDisplayTimeout();
|
||||||
String getLang();
|
String getLang();
|
||||||
bool getSerialEcho();
|
bool getSerialEcho();
|
||||||
bool getWebSpiffs();
|
bool getWebSpiffs();
|
||||||
|
|
||||||
void setDeauthsPerTarget(uint16_t deauthsPerTarget);
|
void setDeauthsPerTarget(uint16_t deauthsPerTarget);
|
||||||
void setDeauthReason(uint8_t deauthReason);
|
void setDeauthReason(uint8_t deauthReason);
|
||||||
void setBeaconChannel(bool beaconChannel);
|
void setBeaconChannel(bool beaconChannel);
|
||||||
void setForcePackets(uint8_t forcePackets);
|
void setForcePackets(uint8_t forcePackets);
|
||||||
void setAutosave(bool autosave);
|
void setAutosave(bool autosave);
|
||||||
void setAutosaveTime(uint32_t autosaveTime);
|
void setAutosaveTime(uint32_t autosaveTime);
|
||||||
void setMaxCh(uint8_t maxCh);
|
void setMaxCh(uint8_t maxCh);
|
||||||
void setBeaconInterval(bool beaconInterval);
|
void setBeaconInterval(bool beaconInterval);
|
||||||
void setChannel(uint8_t channel);
|
void setChannel(uint8_t channel);
|
||||||
void setSSID(String ssid);
|
void setSSID(String ssid);
|
||||||
void setPassword(String password);
|
void setPassword(String password);
|
||||||
void setSerialInterface(bool serialInterface);
|
void setCLI(bool cli);
|
||||||
void setDisplayInterface(bool displayInterface);
|
void setDisplayInterface(bool displayInterface);
|
||||||
void setWebInterface(bool webInterface);
|
void setWebInterface(bool webInterface);
|
||||||
void setChTime(uint16_t chTime);
|
void setChTime(uint16_t chTime);
|
||||||
void setMacSt(String macStr);
|
void setMacSt(String macStr);
|
||||||
bool setMacSt(uint8_t* macSt);
|
bool setMacSt(uint8_t* macSt);
|
||||||
void setMacAP(String macStr);
|
void setMacAP(String macStr);
|
||||||
bool setMacAP(uint8_t* macAP);
|
bool setMacAP(uint8_t* macAP);
|
||||||
void setRandomTX(bool randomTX);
|
void setRandomTX(bool randomTX);
|
||||||
void setAttackTimeout(uint32_t attackTimeout);
|
void setAttackTimeout(uint32_t attackTimeout);
|
||||||
void setLedEnabled(bool ledEnabled);
|
void setLedEnabled(bool ledEnabled);
|
||||||
void setProbesPerSSID(uint8_t probesPerSSID);
|
void setProbesPerSSID(uint8_t probesPerSSID);
|
||||||
void setHidden(bool hidden);
|
void setHidden(bool hidden);
|
||||||
void setCaptivePortal(bool captivePortal);
|
void setCaptivePortal(bool captivePortal);
|
||||||
void setMinDeauths(uint16_t minDeauths);
|
void setMinDeauths(uint16_t minDeauths);
|
||||||
void setDisplayTimeout(uint32_t displayTimeout);
|
void setDisplayTimeout(uint32_t displayTimeout);
|
||||||
void setLang(String lang);
|
void setLang(String lang);
|
||||||
void setSerialEcho(bool serialEcho);
|
void setSerialEcho(bool serialEcho);
|
||||||
void setWebSpiffs(bool webSpiffs);
|
void setWebSpiffs(bool webSpiffs);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
String version = VERSION;
|
String version = VERSION;
|
||||||
|
|
||||||
bool beaconChannel = false;
|
bool beaconChannel = false;
|
||||||
bool autosave = true;
|
bool autosave = true;
|
||||||
bool beaconInterval = false;
|
bool beaconInterval = false;
|
||||||
bool serialInterface = true;
|
bool cli = true;
|
||||||
bool displayInterface = USE_DISPLAY;
|
bool displayInterface = USE_DISPLAY;
|
||||||
bool webInterface = true;
|
bool webInterface = true;
|
||||||
bool webSpiffs = false;
|
bool webSpiffs = false;
|
||||||
bool randomTX = false;
|
bool randomTX = false;
|
||||||
bool ledEnabled = true;
|
bool ledEnabled = true;
|
||||||
bool serialEcho = true;
|
bool serialEcho = true;
|
||||||
|
|
||||||
uint32_t attackTimeout = 600;
|
uint32_t attackTimeout = 600;
|
||||||
uint32_t autosaveTime = 10000;
|
uint32_t autosaveTime = 10000;
|
||||||
uint32_t displayTimeout = 600;
|
uint32_t displayTimeout = 600;
|
||||||
uint16_t deauthsPerTarget = 20;
|
uint16_t deauthsPerTarget = 20;
|
||||||
uint16_t chTime = 384;
|
uint16_t chTime = 384;
|
||||||
uint16_t minDeauths = 3;
|
uint16_t minDeauths = 3;
|
||||||
uint8_t forcePackets = 1;
|
uint8_t forcePackets = 1;
|
||||||
uint8_t maxCh = 13;
|
uint8_t maxCh = 13;
|
||||||
uint8_t channel = 1;
|
uint8_t channel = 1;
|
||||||
uint8_t deauthReason = 1;
|
uint8_t deauthReason = 1;
|
||||||
uint8_t* macSt;
|
uint8_t* macSt;
|
||||||
uint8_t* macAP;
|
uint8_t* macAP;
|
||||||
uint8_t probesPerSSID = 1;
|
uint8_t probesPerSSID = 1;
|
||||||
|
|
||||||
String ssid = "pwned";
|
String ssid = "pwned";
|
||||||
String password = "deauther";
|
String password = "deauther";
|
||||||
bool hidden = false;
|
bool hidden = false;
|
||||||
bool captivePortal = true;
|
bool captivePortal = true;
|
||||||
String lang = "en";
|
String lang = "en";
|
||||||
|
|
||||||
String FILE_PATH = "/settings.json";
|
String FILE_PATH = "/settings.json";
|
||||||
|
|
||||||
String getJsonStr();
|
String getJsonStr();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ifndef Settings_h
|
#endif // ifndef Settings_h
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ extern "C" {
|
|||||||
#include "SSIDs.h"
|
#include "SSIDs.h"
|
||||||
#include "Scan.h"
|
#include "Scan.h"
|
||||||
#include "Attack.h"
|
#include "Attack.h"
|
||||||
#include "SerialInterface.h"
|
#include "CLI.h"
|
||||||
#include "DisplayUI.h"
|
#include "DisplayUI.h"
|
||||||
#include "A_config.h"
|
#include "A_config.h"
|
||||||
#include "webfiles.h"
|
#include "webfiles.h"
|
||||||
@@ -32,7 +32,7 @@ Accesspoints accesspoints;
|
|||||||
Stations stations;
|
Stations stations;
|
||||||
Scan scan;
|
Scan scan;
|
||||||
Attack attack;
|
Attack attack;
|
||||||
SerialInterface serialInterface;
|
CLI cli;
|
||||||
DisplayUI displayUI;
|
DisplayUI displayUI;
|
||||||
|
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
@@ -100,7 +100,7 @@ void setup() {
|
|||||||
// load everything else
|
// load everything else
|
||||||
names.load();
|
names.load();
|
||||||
ssids.load();
|
ssids.load();
|
||||||
serialInterface.load();
|
cli.load();
|
||||||
|
|
||||||
// create scan.json
|
// create scan.json
|
||||||
scan.setup();
|
scan.setup();
|
||||||
@@ -119,8 +119,8 @@ void setup() {
|
|||||||
loadWifiConfigDefaults();
|
loadWifiConfigDefaults();
|
||||||
|
|
||||||
// dis/enable serial command interface
|
// dis/enable serial command interface
|
||||||
if (settings.getSerialInterface()) {
|
if (settings.getCLI()) {
|
||||||
serialInterface.enable();
|
cli.enable();
|
||||||
} else {
|
} else {
|
||||||
prntln(SETUP_SERIAL_WARNING);
|
prntln(SETUP_SERIAL_WARNING);
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
@@ -144,7 +144,7 @@ void loop() {
|
|||||||
|
|
||||||
attack.update(); // run attacks
|
attack.update(); // run attacks
|
||||||
displayUI.update();
|
displayUI.update();
|
||||||
serialInterface.update(); // read and run serial input
|
cli.update(); // read and run serial input
|
||||||
scan.update(); // run scan
|
scan.update(); // run scan
|
||||||
ssids.update(); // run random mode, if enabled
|
ssids.update(); // run random mode, if enabled
|
||||||
led->update(); // update LED color
|
led->update(); // update LED color
|
||||||
|
|||||||
@@ -1,491 +1,491 @@
|
|||||||
#ifndef WifiManager_h
|
#ifndef WifiManager_h
|
||||||
#define WifiManager_h
|
#define WifiManager_h
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <WiFiClient.h>
|
#include <WiFiClient.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
#include <DNSServer.h>
|
#include <DNSServer.h>
|
||||||
#include <ESP8266mDNS.h>
|
#include <ESP8266mDNS.h>
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "user_interface.h"
|
#include "user_interface.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
#define WIFI_MODE_OFF 0
|
#define WIFI_MODE_OFF 0
|
||||||
#define WIFI_MODE_AP 1
|
#define WIFI_MODE_AP 1
|
||||||
#define WIFI_MODE_STATION 2
|
#define WIFI_MODE_STATION 2
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This file contains all necessary functions for hosting and connecting to an access point.
|
This file contains all necessary functions for hosting and connecting to an access point.
|
||||||
For compatibility and simplicity, all those functions are global.
|
For compatibility and simplicity, all those functions are global.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Important strings
|
// Important strings
|
||||||
const char W_DEAUTHER[] PROGMEM = "deauth.me"; // captive portal domain (alternative to 192.168.4.1)
|
const char W_DEAUTHER[] PROGMEM = "deauth.me"; // captive portal domain (alternative to 192.168.4.1)
|
||||||
const char W_WEBINTERFACE[] PROGMEM = "/web"; // default folder containing the web files
|
const char W_WEBINTERFACE[] PROGMEM = "/web"; // default folder containing the web files
|
||||||
const char W_ERROR_PASSWORD[] PROGMEM = "ERROR: Password must have at least 8 characters!";
|
const char W_ERROR_PASSWORD[] PROGMEM = "ERROR: Password must have at least 8 characters!";
|
||||||
const char W_DEFAULT_LANG[] PROGMEM = "/lang/default.lang";
|
const char W_DEFAULT_LANG[] PROGMEM = "/lang/default.lang";
|
||||||
|
|
||||||
const char W_HTML[] PROGMEM = "text/html";
|
const char W_HTML[] PROGMEM = "text/html";
|
||||||
const char W_CSS[] PROGMEM = "text/css";
|
const char W_CSS[] PROGMEM = "text/css";
|
||||||
const char W_JS[] PROGMEM = "application/javascript";
|
const char W_JS[] PROGMEM = "application/javascript";
|
||||||
const char W_PNG[] PROGMEM = "image/png";
|
const char W_PNG[] PROGMEM = "image/png";
|
||||||
const char W_GIF[] PROGMEM = "image/gif";
|
const char W_GIF[] PROGMEM = "image/gif";
|
||||||
const char W_JPG[] PROGMEM = "image/jpeg";
|
const char W_JPG[] PROGMEM = "image/jpeg";
|
||||||
const char W_ICON[] PROGMEM = "image/x-icon";
|
const char W_ICON[] PROGMEM = "image/x-icon";
|
||||||
const char W_XML[] PROGMEM = "text/xml";
|
const char W_XML[] PROGMEM = "text/xml";
|
||||||
const char W_XPDF[] PROGMEM = "application/x-pdf";
|
const char W_XPDF[] PROGMEM = "application/x-pdf";
|
||||||
const char W_XZIP[] PROGMEM = "application/x-zip";
|
const char W_XZIP[] PROGMEM = "application/x-zip";
|
||||||
const char W_GZIP[] PROGMEM = "application/x-gzip";
|
const char W_GZIP[] PROGMEM = "application/x-gzip";
|
||||||
const char W_JSON[] PROGMEM = "application/json";
|
const char W_JSON[] PROGMEM = "application/json";
|
||||||
const char W_TXT[] PROGMEM = "text/plain";
|
const char W_TXT[] PROGMEM = "text/plain";
|
||||||
|
|
||||||
const char W_DOT_HTM[] PROGMEM = ".htm";
|
const char W_DOT_HTM[] PROGMEM = ".htm";
|
||||||
const char W_DOT_HTML[] PROGMEM = ".html";
|
const char W_DOT_HTML[] PROGMEM = ".html";
|
||||||
const char W_DOT_CSS[] PROGMEM = ".css";
|
const char W_DOT_CSS[] PROGMEM = ".css";
|
||||||
const char W_DOT_JS[] PROGMEM = ".js";
|
const char W_DOT_JS[] PROGMEM = ".js";
|
||||||
const char W_DOT_PNG[] PROGMEM = ".png";
|
const char W_DOT_PNG[] PROGMEM = ".png";
|
||||||
const char W_DOT_GIF[] PROGMEM = ".gif";
|
const char W_DOT_GIF[] PROGMEM = ".gif";
|
||||||
const char W_DOT_JPG[] PROGMEM = ".jpg";
|
const char W_DOT_JPG[] PROGMEM = ".jpg";
|
||||||
const char W_DOT_ICON[] PROGMEM = ".ico";
|
const char W_DOT_ICON[] PROGMEM = ".ico";
|
||||||
const char W_DOT_XML[] PROGMEM = ".xml";
|
const char W_DOT_XML[] PROGMEM = ".xml";
|
||||||
const char W_DOT_PDF[] PROGMEM = ".pdf";
|
const char W_DOT_PDF[] PROGMEM = ".pdf";
|
||||||
const char W_DOT_ZIP[] PROGMEM = ".zip";
|
const char W_DOT_ZIP[] PROGMEM = ".zip";
|
||||||
const char W_DOT_GZIP[] PROGMEM = ".gz";
|
const char W_DOT_GZIP[] PROGMEM = ".gz";
|
||||||
const char W_DOT_JSON[] PROGMEM = ".json";
|
const char W_DOT_JSON[] PROGMEM = ".json";
|
||||||
|
|
||||||
// Server and other global objects
|
// Server and other global objects
|
||||||
ESP8266WebServer server(80);
|
ESP8266WebServer server(80);
|
||||||
DNSServer dnsServer;
|
DNSServer dnsServer;
|
||||||
IPAddress apIP(192, 168, 4, 1);
|
IPAddress apIP(192, 168, 4, 1);
|
||||||
IPAddress netMsk(255, 255, 255, 0);
|
IPAddress netMsk(255, 255, 255, 0);
|
||||||
File fsUploadFile;
|
File fsUploadFile;
|
||||||
|
|
||||||
// current WiFi mode and config
|
// current WiFi mode and config
|
||||||
uint8_t wifiMode = WIFI_MODE_OFF;
|
uint8_t wifiMode = WIFI_MODE_OFF;
|
||||||
|
|
||||||
bool wifi_config_hidden = false;
|
bool wifi_config_hidden = false;
|
||||||
bool wifi_config_captivePortal = false;
|
bool wifi_config_captivePortal = false;
|
||||||
String wifi_config_ssid;
|
String wifi_config_ssid;
|
||||||
String wifi_config_password;
|
String wifi_config_password;
|
||||||
String wifi_config_path;
|
String wifi_config_path;
|
||||||
|
|
||||||
void stopAP() {
|
void stopAP() {
|
||||||
if (wifiMode == WIFI_MODE_AP) {
|
if (wifiMode == WIFI_MODE_AP) {
|
||||||
wifi_promiscuous_enable(0);
|
wifi_promiscuous_enable(0);
|
||||||
WiFi.persistent(false);
|
WiFi.persistent(false);
|
||||||
WiFi.disconnect(true);
|
WiFi.disconnect(true);
|
||||||
wifi_set_opmode(STATION_MODE);
|
wifi_set_opmode(STATION_MODE);
|
||||||
prntln(W_STOPPED_AP);
|
prntln(W_STOPPED_AP);
|
||||||
wifiMode = WIFI_MODE_STATION;
|
wifiMode = WIFI_MODE_STATION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wifiUpdate() {
|
void wifiUpdate() {
|
||||||
if ((wifiMode != WIFI_MODE_OFF) && !scan.isScanning()) {
|
if ((wifiMode != WIFI_MODE_OFF) && !scan.isScanning()) {
|
||||||
server.handleClient();
|
server.handleClient();
|
||||||
dnsServer.processNextRequest();
|
dnsServer.processNextRequest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String getWifiMode() {
|
String getWifiMode() {
|
||||||
switch (wifiMode) {
|
switch (wifiMode) {
|
||||||
case WIFI_MODE_OFF:
|
case WIFI_MODE_OFF:
|
||||||
return W_MODE_OFF;
|
return W_MODE_OFF;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WIFI_MODE_AP:
|
case WIFI_MODE_AP:
|
||||||
return W_MODE_AP;
|
return W_MODE_AP;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WIFI_MODE_STATION:
|
case WIFI_MODE_STATION:
|
||||||
return W_MODE_ST;
|
return W_MODE_ST;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return String();
|
return String();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String getContentType(String filename) {
|
String getContentType(String filename) {
|
||||||
if (server.hasArg("download")) return String(F("application/octet-stream"));
|
if (server.hasArg("download")) return String(F("application/octet-stream"));
|
||||||
|
|
||||||
if (filename.endsWith(str(W_DOT_GZIP))) filename = filename.substring(0, filename.length() - 3);
|
if (filename.endsWith(str(W_DOT_GZIP))) filename = filename.substring(0, filename.length() - 3);
|
||||||
|
|
||||||
if (filename.endsWith(str(W_DOT_HTM))) return str(W_HTML);
|
if (filename.endsWith(str(W_DOT_HTM))) return str(W_HTML);
|
||||||
|
|
||||||
if (filename.endsWith(str(W_DOT_HTML))) return str(W_HTML);
|
if (filename.endsWith(str(W_DOT_HTML))) return str(W_HTML);
|
||||||
|
|
||||||
if (filename.endsWith(str(W_DOT_CSS))) return str(W_CSS);
|
if (filename.endsWith(str(W_DOT_CSS))) return str(W_CSS);
|
||||||
|
|
||||||
if (filename.endsWith(str(W_DOT_JS))) return str(W_JS);
|
if (filename.endsWith(str(W_DOT_JS))) return str(W_JS);
|
||||||
|
|
||||||
if (filename.endsWith(str(W_DOT_PNG))) return str(W_PNG);
|
if (filename.endsWith(str(W_DOT_PNG))) return str(W_PNG);
|
||||||
|
|
||||||
if (filename.endsWith(str(W_DOT_GIF))) return str(W_GIF);
|
if (filename.endsWith(str(W_DOT_GIF))) return str(W_GIF);
|
||||||
|
|
||||||
if (filename.endsWith(str(W_DOT_JPG))) return str(W_JPG);
|
if (filename.endsWith(str(W_DOT_JPG))) return str(W_JPG);
|
||||||
|
|
||||||
if (filename.endsWith(str(W_DOT_ICON))) return str(W_ICON);
|
if (filename.endsWith(str(W_DOT_ICON))) return str(W_ICON);
|
||||||
|
|
||||||
if (filename.endsWith(str(W_DOT_XML))) return str(W_XML);
|
if (filename.endsWith(str(W_DOT_XML))) return str(W_XML);
|
||||||
|
|
||||||
if (filename.endsWith(str(W_DOT_PDF))) return str(W_XPDF);
|
if (filename.endsWith(str(W_DOT_PDF))) return str(W_XPDF);
|
||||||
|
|
||||||
if (filename.endsWith(str(W_DOT_ZIP))) return str(W_XZIP);
|
if (filename.endsWith(str(W_DOT_ZIP))) return str(W_XZIP);
|
||||||
|
|
||||||
if (filename.endsWith(str(W_DOT_JSON))) return str(W_JSON);
|
if (filename.endsWith(str(W_DOT_JSON))) return str(W_JSON);
|
||||||
|
|
||||||
return str(W_TXT);
|
return str(W_TXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handleFileRead(String path) {
|
bool handleFileRead(String path) {
|
||||||
prnt(W_AP_REQUEST);
|
prnt(W_AP_REQUEST);
|
||||||
prnt(path);
|
prnt(path);
|
||||||
|
|
||||||
if (!path.charAt(0) == SLASH) path = String(SLASH) + path;
|
if (!path.charAt(0) == SLASH) path = String(SLASH) + path;
|
||||||
|
|
||||||
if (path.charAt(path.length() - 1) == SLASH) path += String(F("index.html"));
|
if (path.charAt(path.length() - 1) == SLASH) path += String(F("index.html"));
|
||||||
|
|
||||||
String contentType = getContentType(path);
|
String contentType = getContentType(path);
|
||||||
|
|
||||||
if (!SPIFFS.exists(path)) {
|
if (!SPIFFS.exists(path)) {
|
||||||
if (SPIFFS.exists(path + str(W_DOT_GZIP))) path += str(W_DOT_GZIP);
|
if (SPIFFS.exists(path + str(W_DOT_GZIP))) path += str(W_DOT_GZIP);
|
||||||
else if (SPIFFS.exists(wifi_config_path + path)) path = wifi_config_path + path;
|
else if (SPIFFS.exists(wifi_config_path + path)) path = wifi_config_path + path;
|
||||||
else if (SPIFFS.exists(wifi_config_path + path + str(W_DOT_GZIP))) path = wifi_config_path + path + str(
|
else if (SPIFFS.exists(wifi_config_path + path + str(W_DOT_GZIP))) path = wifi_config_path + path + str(
|
||||||
W_DOT_GZIP);
|
W_DOT_GZIP);
|
||||||
else {
|
else {
|
||||||
prntln(W_NOT_FOUND);
|
prntln(W_NOT_FOUND);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
File file = SPIFFS.open(path, "r");
|
File file = SPIFFS.open(path, "r");
|
||||||
server.streamFile(file, contentType);
|
server.streamFile(file, contentType);
|
||||||
file.close();
|
file.close();
|
||||||
prnt(SPACE);
|
prnt(SPACE);
|
||||||
prntln(W_OK);
|
prntln(W_OK);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void handleFileUpload() {
|
void handleFileUpload() {
|
||||||
// only allow uploads on /edit address
|
// only allow uploads on /edit address
|
||||||
if (server.uri() != "/edit")
|
if (server.uri() != "/edit")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
HTTPUpload& upload = server.upload();
|
HTTPUpload& upload = server.upload();
|
||||||
if (upload.status == UPLOAD_FILE_START) {
|
if (upload.status == UPLOAD_FILE_START) {
|
||||||
String filename = upload.filename;
|
String filename = upload.filename;
|
||||||
if (!filename.charAt(0) == SLASH) filename = String(SLASH) + filename;
|
if (!filename.charAt(0) == SLASH) filename = String(SLASH) + filename;
|
||||||
//Serial.print("handleFileUpload Name: ");
|
//Serial.print("handleFileUpload Name: ");
|
||||||
//Serial.println(filename);
|
//Serial.println(filename);
|
||||||
fsUploadFile = SPIFFS.open(filename, "w");
|
fsUploadFile = SPIFFS.open(filename, "w");
|
||||||
filename = String();
|
filename = String();
|
||||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||||
//Serial.print("handleFileUpload Data: ");
|
//Serial.print("handleFileUpload Data: ");
|
||||||
//Serial.println(upload.currentSize);
|
//Serial.println(upload.currentSize);
|
||||||
if (fsUploadFile)
|
if (fsUploadFile)
|
||||||
fsUploadFile.write(upload.buf, upload.currentSize);
|
fsUploadFile.write(upload.buf, upload.currentSize);
|
||||||
} else if (upload.status == UPLOAD_FILE_END) {
|
} else if (upload.status == UPLOAD_FILE_END) {
|
||||||
if (fsUploadFile)
|
if (fsUploadFile)
|
||||||
fsUploadFile.close();
|
fsUploadFile.close();
|
||||||
//Serial.print("handleFileUpload Size: ");
|
//Serial.print("handleFileUpload Size: ");
|
||||||
//Serial.println(upload.totalSize);
|
//Serial.println(upload.totalSize);
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void handleFileDelete() {
|
void handleFileDelete() {
|
||||||
if (server.args() == 0)
|
if (server.args() == 0)
|
||||||
return server.send(500, str(W_TXT), str(W_BAD_ARGS));
|
return server.send(500, str(W_TXT), str(W_BAD_ARGS));
|
||||||
|
|
||||||
String path = server.arg(0);
|
String path = server.arg(0);
|
||||||
//Serial.println("handleFileDelete: " + path);
|
//Serial.println("handleFileDelete: " + path);
|
||||||
if (path == String(SLASH))
|
if (path == String(SLASH))
|
||||||
return server.send(500, str(W_TXT), str(W_BAD_PATH));
|
return server.send(500, str(W_TXT), str(W_BAD_PATH));
|
||||||
if (!SPIFFS.exists(path))
|
if (!SPIFFS.exists(path))
|
||||||
return server.send(404, str(W_TXT), str(W_FILE_NOT_FOUND));
|
return server.send(404, str(W_TXT), str(W_FILE_NOT_FOUND));
|
||||||
SPIFFS.remove(path);
|
SPIFFS.remove(path);
|
||||||
server.send(200, str(W_TXT), String());
|
server.send(200, str(W_TXT), String());
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void handleFileCreate() {
|
void handleFileCreate() {
|
||||||
if (server.args() == 0)
|
if (server.args() == 0)
|
||||||
return server.send(500, str(W_TXT), str(W_BAD_ARGS));
|
return server.send(500, str(W_TXT), str(W_BAD_ARGS));
|
||||||
|
|
||||||
String path = server.arg(0);
|
String path = server.arg(0);
|
||||||
//Serial.println("handleFileCreate: " + path);
|
//Serial.println("handleFileCreate: " + path);
|
||||||
if (path == String(SLASH))
|
if (path == String(SLASH))
|
||||||
return server.send(500, str(W_TXT), str(W_BAD_PATH));
|
return server.send(500, str(W_TXT), str(W_BAD_PATH));
|
||||||
if (SPIFFS.exists(path))
|
if (SPIFFS.exists(path))
|
||||||
return server.send(500, str(W_TXT), "FILE EXISTS");
|
return server.send(500, str(W_TXT), "FILE EXISTS");
|
||||||
File file = SPIFFS.open(path, "w");
|
File file = SPIFFS.open(path, "w");
|
||||||
if (file)
|
if (file)
|
||||||
file.close();
|
file.close();
|
||||||
else
|
else
|
||||||
return server.send(500, str(W_TXT), "CREATE FAILED");
|
return server.send(500, str(W_TXT), "CREATE FAILED");
|
||||||
server.send(200, str(W_TXT), "");
|
server.send(200, str(W_TXT), "");
|
||||||
}*/
|
}*/
|
||||||
void handleFileList() {
|
void handleFileList() {
|
||||||
if (!server.hasArg("dir")) {
|
if (!server.hasArg("dir")) {
|
||||||
server.send(500, str(W_TXT), str(W_BAD_ARGS));
|
server.send(500, str(W_TXT), str(W_BAD_ARGS));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String path = server.arg("dir");
|
String path = server.arg("dir");
|
||||||
// Serial.println("handleFileList: " + path);
|
// Serial.println("handleFileList: " + path);
|
||||||
Dir dir = SPIFFS.openDir(path);
|
Dir dir = SPIFFS.openDir(path);
|
||||||
|
|
||||||
String output = String(OPEN_BRACKET); // {
|
String output = String(OPEN_BRACKET); // {
|
||||||
File entry;
|
File entry;
|
||||||
bool first = true;
|
bool first = true;
|
||||||
|
|
||||||
while (dir.next()) {
|
while (dir.next()) {
|
||||||
entry = dir.openFile("r");
|
entry = dir.openFile("r");
|
||||||
|
|
||||||
if (first) first = false;
|
if (first) first = false;
|
||||||
else output += COMMA; // ,
|
else output += COMMA; // ,
|
||||||
|
|
||||||
output += OPEN_BRACKET; // [
|
output += OPEN_BRACKET; // [
|
||||||
output += String(DOUBLEQUOTES) + entry.name() + String(DOUBLEQUOTES); // "filename"
|
output += String(DOUBLEQUOTES) + entry.name() + String(DOUBLEQUOTES); // "filename"
|
||||||
output += CLOSE_BRACKET; // ]
|
output += CLOSE_BRACKET; // ]
|
||||||
|
|
||||||
entry.close();
|
entry.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
output += CLOSE_BRACKET;
|
output += CLOSE_BRACKET;
|
||||||
server.send(200, str(W_JSON).c_str(), output);
|
server.send(200, str(W_JSON).c_str(), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendProgmem(const char* ptr, size_t size, const char* type) {
|
void sendProgmem(const char* ptr, size_t size, const char* type) {
|
||||||
server.sendHeader("Content-Encoding", "gzip");
|
server.sendHeader("Content-Encoding", "gzip");
|
||||||
server.sendHeader("Cache-Control", "max-age=86400");
|
server.sendHeader("Cache-Control", "max-age=86400");
|
||||||
server.send_P(200, str(type).c_str(), ptr, size);
|
server.send_P(200, str(type).c_str(), ptr, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// path = folder of web files, ssid = name of network, password = password ("0" => no password), hidden = if the network
|
// path = folder of web files, ssid = name of network, password = password ("0" => no password), hidden = if the network
|
||||||
// is visible, captivePortal = enable a captive portal
|
// is visible, captivePortal = enable a captive portal
|
||||||
void startAP(String path, String ssid, String password, uint8_t ch, bool hidden, bool captivePortal) {
|
void startAP(String path, String ssid, String password, uint8_t ch, bool hidden, bool captivePortal) {
|
||||||
if (password.length() < 8) {
|
if (password.length() < 8) {
|
||||||
prntln(W_ERROR_PASSWORD);
|
prntln(W_ERROR_PASSWORD);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!path.charAt(0) == SLASH) path = String(SLASH) + path;
|
if (!path.charAt(0) == SLASH) path = String(SLASH) + path;
|
||||||
|
|
||||||
if (password == String(ZERO)) password = String(NEWLINE);
|
if (password == String(ZERO)) password = String(NEWLINE);
|
||||||
|
|
||||||
wifi_config_path = path;
|
wifi_config_path = path;
|
||||||
wifi_config_ssid = ssid;
|
wifi_config_ssid = ssid;
|
||||||
wifi_config_password = password;
|
wifi_config_password = password;
|
||||||
setWifiChannel(ch);
|
setWifiChannel(ch);
|
||||||
wifi_config_hidden = hidden;
|
wifi_config_hidden = hidden;
|
||||||
wifi_config_captivePortal = captivePortal;
|
wifi_config_captivePortal = captivePortal;
|
||||||
|
|
||||||
WiFi.softAPConfig(apIP, apIP, netMsk);
|
WiFi.softAPConfig(apIP, apIP, netMsk);
|
||||||
WiFi.softAP(ssid.c_str(), password.c_str(), wifi_channel, hidden);
|
WiFi.softAP(ssid.c_str(), password.c_str(), wifi_channel, hidden);
|
||||||
|
|
||||||
dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
|
dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
|
||||||
dnsServer.start(53, String(ASTERIX), apIP);
|
dnsServer.start(53, String(ASTERIX), apIP);
|
||||||
|
|
||||||
MDNS.begin(str(W_DEAUTHER).c_str());
|
MDNS.begin(str(W_DEAUTHER).c_str());
|
||||||
|
|
||||||
server.on(String(F("/list")).c_str(), HTTP_GET, handleFileList); // list directory
|
server.on(String(F("/list")).c_str(), HTTP_GET, handleFileList); // list directory
|
||||||
|
|
||||||
|
|
||||||
// ================================================================
|
// ================================================================
|
||||||
// post here the output of the webConverter.py
|
// post here the output of the webConverter.py
|
||||||
|
|
||||||
if (!settings.getWebSpiffs()) {
|
if (!settings.getWebSpiffs()) {
|
||||||
server.on(String(SLASH).c_str(), HTTP_GET, []() {
|
server.on(String(SLASH).c_str(), HTTP_GET, []() {
|
||||||
sendProgmem(indexhtml, sizeof(indexhtml), W_HTML);
|
sendProgmem(indexhtml, sizeof(indexhtml), W_HTML);
|
||||||
});
|
});
|
||||||
server.on(String(F("/attack.html")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/attack.html")).c_str(), HTTP_GET, []() {
|
||||||
sendProgmem(attackhtml, sizeof(attackhtml), W_HTML);
|
sendProgmem(attackhtml, sizeof(attackhtml), W_HTML);
|
||||||
});
|
});
|
||||||
server.on(String(F("/index.html")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/index.html")).c_str(), HTTP_GET, []() {
|
||||||
sendProgmem(indexhtml, sizeof(indexhtml), W_HTML);
|
sendProgmem(indexhtml, sizeof(indexhtml), W_HTML);
|
||||||
});
|
});
|
||||||
server.on(String(F("/info.html")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/info.html")).c_str(), HTTP_GET, []() {
|
||||||
sendProgmem(infohtml, sizeof(infohtml), W_HTML);
|
sendProgmem(infohtml, sizeof(infohtml), W_HTML);
|
||||||
});
|
});
|
||||||
server.on(String(F("/scan.html")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/scan.html")).c_str(), HTTP_GET, []() {
|
||||||
sendProgmem(scanhtml, sizeof(scanhtml), W_HTML);
|
sendProgmem(scanhtml, sizeof(scanhtml), W_HTML);
|
||||||
});
|
});
|
||||||
server.on(String(F("/settings.html")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/settings.html")).c_str(), HTTP_GET, []() {
|
||||||
sendProgmem(settingshtml, sizeof(settingshtml), W_HTML);
|
sendProgmem(settingshtml, sizeof(settingshtml), W_HTML);
|
||||||
});
|
});
|
||||||
server.on(String(F("/ssids.html")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/ssids.html")).c_str(), HTTP_GET, []() {
|
||||||
sendProgmem(ssidshtml, sizeof(ssidshtml), W_HTML);
|
sendProgmem(ssidshtml, sizeof(ssidshtml), W_HTML);
|
||||||
});
|
});
|
||||||
server.on(String(F("/style.css")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/style.css")).c_str(), HTTP_GET, []() {
|
||||||
sendProgmem(stylecss, sizeof(stylecss), W_CSS);
|
sendProgmem(stylecss, sizeof(stylecss), W_CSS);
|
||||||
});
|
});
|
||||||
server.on(String(F("/js/attack.js")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/js/attack.js")).c_str(), HTTP_GET, []() {
|
||||||
sendProgmem(attackjs, sizeof(attackjs), W_JS);
|
sendProgmem(attackjs, sizeof(attackjs), W_JS);
|
||||||
});
|
});
|
||||||
server.on(String(F("/js/scan.js")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/js/scan.js")).c_str(), HTTP_GET, []() {
|
||||||
sendProgmem(scanjs, sizeof(scanjs), W_JS);
|
sendProgmem(scanjs, sizeof(scanjs), W_JS);
|
||||||
});
|
});
|
||||||
server.on(String(F("/js/settings.js")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/js/settings.js")).c_str(), HTTP_GET, []() {
|
||||||
sendProgmem(settingsjs, sizeof(settingsjs), W_JS);
|
sendProgmem(settingsjs, sizeof(settingsjs), W_JS);
|
||||||
});
|
});
|
||||||
server.on(String(F("/js/site.js")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/js/site.js")).c_str(), HTTP_GET, []() {
|
||||||
sendProgmem(sitejs, sizeof(sitejs), W_JS);
|
sendProgmem(sitejs, sizeof(sitejs), W_JS);
|
||||||
});
|
});
|
||||||
server.on(String(F("/js/ssids.js")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/js/ssids.js")).c_str(), HTTP_GET, []() {
|
||||||
sendProgmem(ssidsjs, sizeof(ssidsjs), W_JS);
|
sendProgmem(ssidsjs, sizeof(ssidsjs), W_JS);
|
||||||
});
|
});
|
||||||
server.on(String(F("/lang/cn.lang")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/lang/cn.lang")).c_str(), HTTP_GET, []() {
|
||||||
sendProgmem(cnlang, sizeof(cnlang), W_JSON);
|
sendProgmem(cnlang, sizeof(cnlang), W_JSON);
|
||||||
});
|
});
|
||||||
server.on(String(F("/lang/cs.lang")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/lang/cs.lang")).c_str(), HTTP_GET, []() {
|
||||||
sendProgmem(cslang, sizeof(cslang), W_JSON);
|
sendProgmem(cslang, sizeof(cslang), W_JSON);
|
||||||
});
|
});
|
||||||
server.on(String(F("/lang/de.lang")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/lang/de.lang")).c_str(), HTTP_GET, []() {
|
||||||
sendProgmem(delang, sizeof(delang), W_JSON);
|
sendProgmem(delang, sizeof(delang), W_JSON);
|
||||||
});
|
});
|
||||||
server.on(String(F("/lang/en.lang")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/lang/en.lang")).c_str(), HTTP_GET, []() {
|
||||||
sendProgmem(enlang, sizeof(enlang), W_JSON);
|
sendProgmem(enlang, sizeof(enlang), W_JSON);
|
||||||
});
|
});
|
||||||
server.on(String(F("/lang/fr.lang")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/lang/fr.lang")).c_str(), HTTP_GET, []() {
|
||||||
sendProgmem(frlang, sizeof(frlang), W_JSON);
|
sendProgmem(frlang, sizeof(frlang), W_JSON);
|
||||||
});
|
});
|
||||||
server.on(String(F("/lang/it.lang")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/lang/it.lang")).c_str(), HTTP_GET, []() {
|
||||||
sendProgmem(itlang, sizeof(itlang), W_JSON);
|
sendProgmem(itlang, sizeof(itlang), W_JSON);
|
||||||
});
|
});
|
||||||
server.on(String(F("/lang/ru.lang")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/lang/ru.lang")).c_str(), HTTP_GET, []() {
|
||||||
sendProgmem(rulang, sizeof(rulang), W_JSON);
|
sendProgmem(rulang, sizeof(rulang), W_JSON);
|
||||||
});
|
});
|
||||||
server.on(String(F("/lang/tlh.lang")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/lang/tlh.lang")).c_str(), HTTP_GET, []() {
|
||||||
sendProgmem(tlhlang, sizeof(tlhlang), W_JSON);
|
sendProgmem(tlhlang, sizeof(tlhlang), W_JSON);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
server.on(str(W_DEFAULT_LANG).c_str(), HTTP_GET, []() {
|
server.on(str(W_DEFAULT_LANG).c_str(), HTTP_GET, []() {
|
||||||
if (!settings.getWebSpiffs()) {
|
if (!settings.getWebSpiffs()) {
|
||||||
if (settings.getLang() == String(F("cn"))) sendProgmem(cnlang, sizeof(cnlang), W_JSON);
|
if (settings.getLang() == String(F("cn"))) sendProgmem(cnlang, sizeof(cnlang), W_JSON);
|
||||||
else if (settings.getLang() == String(F("cs"))) sendProgmem(cslang, sizeof(cslang), W_JSON);
|
else if (settings.getLang() == String(F("cs"))) sendProgmem(cslang, sizeof(cslang), W_JSON);
|
||||||
else if (settings.getLang() == String(F("de"))) sendProgmem(delang, sizeof(delang), W_JSON);
|
else if (settings.getLang() == String(F("de"))) sendProgmem(delang, sizeof(delang), W_JSON);
|
||||||
else if (settings.getLang() == String(F("en"))) sendProgmem(enlang, sizeof(enlang), W_JSON);
|
else if (settings.getLang() == String(F("en"))) sendProgmem(enlang, sizeof(enlang), W_JSON);
|
||||||
else if (settings.getLang() == String(F("fr"))) sendProgmem(frlang, sizeof(frlang), W_JSON);
|
else if (settings.getLang() == String(F("fr"))) sendProgmem(frlang, sizeof(frlang), W_JSON);
|
||||||
else if (settings.getLang() == String(F("it"))) sendProgmem(itlang, sizeof(itlang), W_JSON);
|
else if (settings.getLang() == String(F("it"))) sendProgmem(itlang, sizeof(itlang), W_JSON);
|
||||||
else if (settings.getLang() == String(F("ru"))) sendProgmem(rulang, sizeof(rulang), W_JSON);
|
else if (settings.getLang() == String(F("ru"))) sendProgmem(rulang, sizeof(rulang), W_JSON);
|
||||||
else if (settings.getLang() == String(F("tlh"))) sendProgmem(tlhlang, sizeof(tlhlang), W_JSON);
|
else if (settings.getLang() == String(F("tlh"))) sendProgmem(tlhlang, sizeof(tlhlang), W_JSON);
|
||||||
|
|
||||||
else handleFileRead(String(F("/web/lang/")) + settings.getLang() + String(F(".lang")));
|
else handleFileRead(String(F("/web/lang/")) + settings.getLang() + String(F(".lang")));
|
||||||
} else {
|
} else {
|
||||||
handleFileRead(String(F("/web/lang/")) + settings.getLang() + String(F(".lang")));
|
handleFileRead(String(F("/web/lang/")) + settings.getLang() + String(F(".lang")));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// ================================================================
|
// ================================================================
|
||||||
|
|
||||||
server.on(String(F("/run")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/run")).c_str(), HTTP_GET, []() {
|
||||||
server.send(200, str(W_TXT), str(W_OK).c_str());
|
server.send(200, str(W_TXT), str(W_OK).c_str());
|
||||||
serialInterface.runCommands(server.arg("cmd"));
|
cli.runCommands(server.arg("cmd"));
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on(String(F("/attack.json")).c_str(), HTTP_GET, []() {
|
server.on(String(F("/attack.json")).c_str(), HTTP_GET, []() {
|
||||||
server.send(200, str(W_JSON), attack.getStatusJSON());
|
server.send(200, str(W_JSON), attack.getStatusJSON());
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
//load editor
|
//load editor
|
||||||
server.on("/edit", HTTP_GET, [](){
|
server.on("/edit", HTTP_GET, [](){
|
||||||
if(!handleFileRead("/edit.htm")) server.send(404, str(W_TXT), "FileNotFound");
|
if(!handleFileRead("/edit.htm")) server.send(404, str(W_TXT), "FileNotFound");
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/edit", HTTP_PUT, handleFileCreate); //create file
|
server.on("/edit", HTTP_PUT, handleFileCreate); //create file
|
||||||
server.on("/edit", HTTP_DELETE, handleFileDelete); //delete file
|
server.on("/edit", HTTP_DELETE, handleFileDelete); //delete file
|
||||||
|
|
||||||
//first callback is called after the request has ended with all parsed arguments
|
//first callback is called after the request has ended with all parsed arguments
|
||||||
//second callback handles file uploads at that location
|
//second callback handles file uploads at that location
|
||||||
server.on("/edit", HTTP_POST, [](){
|
server.on("/edit", HTTP_POST, [](){
|
||||||
server.send(200, str(W_TXT), "");
|
server.send(200, str(W_TXT), "");
|
||||||
}, handleFileUpload);
|
}, handleFileUpload);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// aggressively caching static assets
|
// aggressively caching static assets
|
||||||
server.serveStatic("/js", SPIFFS, String(wifi_config_path + "/js").c_str(), "max-age=86400");
|
server.serveStatic("/js", SPIFFS, String(wifi_config_path + "/js").c_str(), "max-age=86400");
|
||||||
|
|
||||||
// called when the url is not defined here
|
// called when the url is not defined here
|
||||||
// use it to load content from SPIFFS
|
// use it to load content from SPIFFS
|
||||||
server.onNotFound([]() {
|
server.onNotFound([]() {
|
||||||
if (!handleFileRead(server.uri())) {
|
if (!handleFileRead(server.uri())) {
|
||||||
server.send(404, str(W_TXT), str(W_FILE_NOT_FOUND));
|
server.send(404, str(W_TXT), str(W_FILE_NOT_FOUND));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
server.begin();
|
server.begin();
|
||||||
wifiMode = WIFI_MODE_AP;
|
wifiMode = WIFI_MODE_AP;
|
||||||
|
|
||||||
prntln(W_STARTED_AP);
|
prntln(W_STARTED_AP);
|
||||||
printWifiStatus();
|
printWifiStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void printWifiStatus() {
|
void printWifiStatus() {
|
||||||
prnt(String(F("[WiFi] Path: '")));
|
prnt(String(F("[WiFi] Path: '")));
|
||||||
prnt(wifi_config_path);
|
prnt(wifi_config_path);
|
||||||
prnt(String(F("', Mode: '")));
|
prnt(String(F("', Mode: '")));
|
||||||
|
|
||||||
switch (wifiMode) {
|
switch (wifiMode) {
|
||||||
case WIFI_MODE_OFF:
|
case WIFI_MODE_OFF:
|
||||||
prnt(W_MODE_OFF);
|
prnt(W_MODE_OFF);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WIFI_MODE_AP:
|
case WIFI_MODE_AP:
|
||||||
prnt(W_AP);
|
prnt(W_AP);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WIFI_MODE_STATION:
|
case WIFI_MODE_STATION:
|
||||||
prnt(W_STATION);
|
prnt(W_STATION);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
prnt(String(F("', SSID: '")));
|
prnt(String(F("', SSID: '")));
|
||||||
prnt(wifi_config_ssid);
|
prnt(wifi_config_ssid);
|
||||||
prnt(String(F("', password: '")));
|
prnt(String(F("', password: '")));
|
||||||
prnt(wifi_config_password);
|
prnt(wifi_config_password);
|
||||||
prnt(String(F("', channel: '")));
|
prnt(String(F("', channel: '")));
|
||||||
prnt(wifi_channel);
|
prnt(wifi_channel);
|
||||||
prnt(String(F("', hidden: ")));
|
prnt(String(F("', hidden: ")));
|
||||||
prnt(b2s(wifi_config_hidden));
|
prnt(b2s(wifi_config_hidden));
|
||||||
prnt(String(F(", captive-portal: ")));
|
prnt(String(F(", captive-portal: ")));
|
||||||
prntln(b2s(wifi_config_captivePortal));
|
prntln(b2s(wifi_config_captivePortal));
|
||||||
}
|
}
|
||||||
|
|
||||||
void startAP() {
|
void startAP() {
|
||||||
startAP(wifi_config_path.c_str(), wifi_config_ssid.c_str(),
|
startAP(wifi_config_path.c_str(), wifi_config_ssid.c_str(),
|
||||||
wifi_config_password.c_str(), wifi_channel, wifi_config_hidden, wifi_config_captivePortal);
|
wifi_config_password.c_str(), wifi_channel, wifi_config_hidden, wifi_config_captivePortal);
|
||||||
}
|
}
|
||||||
|
|
||||||
void startAP(String path) {
|
void startAP(String path) {
|
||||||
wifi_config_path = path;
|
wifi_config_path = path;
|
||||||
startAP();
|
startAP();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadWifiConfigDefaults() {
|
void loadWifiConfigDefaults() {
|
||||||
wifi_config_hidden = settings.getHidden();
|
wifi_config_hidden = settings.getHidden();
|
||||||
wifi_config_ssid = settings.getSSID();
|
wifi_config_ssid = settings.getSSID();
|
||||||
wifi_config_password = settings.getPassword();
|
wifi_config_password = settings.getPassword();
|
||||||
wifi_config_captivePortal = settings.getCaptivePortal();
|
wifi_config_captivePortal = settings.getCaptivePortal();
|
||||||
wifi_config_path = str(W_WEBINTERFACE);
|
wifi_config_path = str(W_WEBINTERFACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void resumeAP() {
|
void resumeAP() {
|
||||||
if (wifiMode != WIFI_MODE_AP) {
|
if (wifiMode != WIFI_MODE_AP) {
|
||||||
wifiMode = WIFI_MODE_AP;
|
wifiMode = WIFI_MODE_AP;
|
||||||
wifi_promiscuous_enable(0);
|
wifi_promiscuous_enable(0);
|
||||||
WiFi.softAPConfig(apIP, apIP, netMsk);
|
WiFi.softAPConfig(apIP, apIP, netMsk);
|
||||||
WiFi.softAP(wifi_config_ssid.c_str(), wifi_config_password.c_str(), wifi_channel, wifi_config_hidden);
|
WiFi.softAP(wifi_config_ssid.c_str(), wifi_config_password.c_str(), wifi_channel, wifi_config_hidden);
|
||||||
prntln(W_STARTED_AP);
|
prntln(W_STARTED_AP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ifndef WifiManager_h
|
#endif // ifndef WifiManager_h
|
||||||
|
|||||||
Reference in New Issue
Block a user