Renamed SerialInterface to CLI

This commit is contained in:
Stefan Kremser
2018-10-10 18:13:10 +02:00
parent 5ed9cc9d9c
commit a687a94546
6 changed files with 2439 additions and 2439 deletions

View File

@@ -1,4 +1,4 @@
#include "SerialInterface.h" #include "CLI.h"
/* /*
A short introduction for the reader: A short introduction for the reader:
@@ -14,42 +14,42 @@
Also: NEVER CHANGE A RUNNING SYSTEM! Also: NEVER CHANGE A RUNNING SYSTEM!
*/ */
SerialInterface::SerialInterface() { CLI::CLI() {
list = new SimpleList<String>; list = new SimpleList<String>;
} }
void SerialInterface::load() { void CLI::load() {
checkFile(execPath, String()); checkFile(execPath, String());
executing = true; executing = true;
} }
void SerialInterface::load(String filepath) { void CLI::load(String filepath) {
execPath = filepath; execPath = filepath;
load(); load();
} }
void SerialInterface::enable() { void CLI::enable() {
enabled = true; enabled = true;
prntln(CLI_SERIAL_ENABLED); prntln(CLI_SERIAL_ENABLED);
} }
void SerialInterface::disable() { void CLI::disable() {
enabled = true; enabled = true;
prntln(CLI_SERIAL_DISABLED); prntln(CLI_SERIAL_DISABLED);
} }
void SerialInterface::error(String message) { void CLI::error(String message) {
prnt(CLI_ERROR); prnt(CLI_ERROR);
prntln(message); prntln(message);
} }
void SerialInterface::parameterError(String parameter) { void CLI::parameterError(String parameter) {
prnt(CLI_ERROR_PARAMETER); prnt(CLI_ERROR_PARAMETER);
prnt(parameter); prnt(parameter);
prntln(DOUBLEQUOTES); prntln(DOUBLEQUOTES);
} }
bool SerialInterface::isInt(String str) { bool CLI::isInt(String str) {
if (eqls(str, STR_TRUE) || eqls(str, STR_FALSE)) return true; if (eqls(str, STR_TRUE) || eqls(str, STR_FALSE)) return true;
for (uint32_t i = 0; i < str.length(); i++) for (uint32_t i = 0; i < str.length(); i++)
@@ -58,13 +58,13 @@ bool SerialInterface::isInt(String str) {
return true; return true;
} }
int SerialInterface::toInt(String str) { int CLI::toInt(String str) {
if (eqls(str, STR_TRUE)) return 1; if (eqls(str, STR_TRUE)) return 1;
else if (eqls(str, STR_FALSE)) return 0; else if (eqls(str, STR_FALSE)) return 0;
else return str.toInt(); else return str.toInt();
} }
uint32_t SerialInterface::getTime(String time) { uint32_t CLI::getTime(String time) {
int value = time.toInt(); int value = time.toInt();
if (value < 0) value = -value; if (value < 0) value = -value;
@@ -75,11 +75,11 @@ uint32_t SerialInterface::getTime(String time) {
return value; return value;
} }
bool SerialInterface::eqlsCMD(int i, const char* keyword) { bool CLI::eqlsCMD(int i, const char* keyword) {
return eqls(list->get(i).c_str(), keyword); return eqls(list->get(i).c_str(), keyword);
} }
void SerialInterface::stopScript() { void CLI::stopScript() {
if (continuously) { if (continuously) {
continuously = false; continuously = false;
prnt(CLI_STOPPED_SCRIPT); prnt(CLI_STOPPED_SCRIPT);
@@ -90,7 +90,7 @@ void SerialInterface::stopScript() {
} }
} }
void SerialInterface::update() { void CLI::update() {
if (executing) { if (executing) {
if (execPath.charAt(0) != SLASH) execPath = SLASH + execPath; if (execPath.charAt(0) != SLASH) execPath = SLASH + execPath;
prnt(CLI_EXECUTING); prnt(CLI_EXECUTING);
@@ -130,7 +130,7 @@ void SerialInterface::update() {
} }
} }
void SerialInterface::runCommands(String input) { void CLI::runCommands(String input) {
String tmp; String tmp;
for (uint32_t i = 0; i < input.length(); i++) { for (uint32_t i = 0; i < input.length(); i++) {
@@ -150,7 +150,7 @@ void SerialInterface::runCommands(String input) {
if (tmp.length() > 0) runCommand(tmp); if (tmp.length() > 0) runCommand(tmp);
} }
void SerialInterface::runCommand(String input) { void CLI::runCommand(String input) {
input.replace(String(NEWLINE), String()); input.replace(String(NEWLINE), String());
input.replace(String(CARRIAGERETURN), String()); input.replace(String(CARRIAGERETURN), String());

View File

@@ -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

View File

@@ -35,7 +35,7 @@ void Settings::load() {
if (data.containsKey(keyword(S_DISPLAY_TIMEOUT))) setDisplayTimeout(data.get<uint32_t>(keyword(S_DISPLAY_TIMEOUT))); if (data.containsKey(keyword(S_DISPLAY_TIMEOUT))) setDisplayTimeout(data.get<uint32_t>(keyword(S_DISPLAY_TIMEOUT)));
if (data.containsKey(keyword(S_SERIALINTERFACE))) setSerialInterface(data.get<bool>(keyword(S_SERIALINTERFACE))); if (data.containsKey(keyword(S_SERIALINTERFACE))) setCLI(data.get<bool>(keyword(S_SERIALINTERFACE)));
if (data.containsKey(keyword(S_SERIAL_ECHO))) setSerialEcho(data.get<bool>(keyword(S_SERIAL_ECHO))); if (data.containsKey(keyword(S_SERIAL_ECHO))) setSerialEcho(data.get<bool>(keyword(S_SERIAL_ECHO)));
@@ -117,7 +117,7 @@ void Settings::reset() {
setAutosaveTime(10000); setAutosaveTime(10000);
setDisplayInterface(USE_DISPLAY); setDisplayInterface(USE_DISPLAY);
setDisplayTimeout(600); setDisplayTimeout(600);
setSerialInterface(true); setCLI(true);
setSerialEcho(true); setSerialEcho(true);
setWebInterface(true); setWebInterface(true);
setWebSpiffs(false); setWebSpiffs(false);
@@ -163,7 +163,7 @@ String Settings::getJsonStr() {
data.set(keyword(S_AUTOSAVETIME), autosaveTime); data.set(keyword(S_AUTOSAVETIME), autosaveTime);
data.set(keyword(S_DISPLAYINTERFACE), displayInterface); data.set(keyword(S_DISPLAYINTERFACE), displayInterface);
data.set(keyword(S_DISPLAY_TIMEOUT), displayTimeout); data.set(keyword(S_DISPLAY_TIMEOUT), displayTimeout);
data.set(keyword(S_SERIALINTERFACE), serialInterface); data.set(keyword(S_SERIALINTERFACE), cli);
data.set(keyword(S_SERIAL_ECHO), serialEcho); data.set(keyword(S_SERIAL_ECHO), serialEcho);
data.set(keyword(S_WEBINTERFACE), webInterface); data.set(keyword(S_WEBINTERFACE), webInterface);
data.set(keyword(S_WEB_SPIFFS), webSpiffs); data.set(keyword(S_WEB_SPIFFS), webSpiffs);
@@ -230,7 +230,7 @@ void Settings::set(const char* str, String value) {
if (eqls(str, S_BEACONCHANNEL)) setBeaconChannel(s2b(value)); if (eqls(str, S_BEACONCHANNEL)) setBeaconChannel(s2b(value));
else if (eqls(str, S_AUTOSAVE)) setAutosave(s2b(value)); else if (eqls(str, S_AUTOSAVE)) setAutosave(s2b(value));
else if (eqls(str, S_BEACONINTERVAL)) setBeaconInterval(s2b(value)); else if (eqls(str, S_BEACONINTERVAL)) setBeaconInterval(s2b(value));
else if (eqls(str, S_SERIALINTERFACE)) setSerialInterface(s2b(value)); else if (eqls(str, S_SERIALINTERFACE)) setCLI(s2b(value));
else if (eqls(str, S_DISPLAYINTERFACE)) setDisplayInterface(s2b(value)); else if (eqls(str, S_DISPLAYINTERFACE)) setDisplayInterface(s2b(value));
else if (eqls(str, S_WEBINTERFACE)) setWebInterface(s2b(value)); else if (eqls(str, S_WEBINTERFACE)) setWebInterface(s2b(value));
else if (eqls(str, S_RANDOMTX)) setRandomTX(s2b(value)); else if (eqls(str, S_RANDOMTX)) setRandomTX(s2b(value));
@@ -282,7 +282,7 @@ String Settings::get(const char* str) {
else if (eqls(str, S_BEACONCHANNEL)) return b2s(beaconChannel); else if (eqls(str, S_BEACONCHANNEL)) return b2s(beaconChannel);
else if (eqls(str, S_AUTOSAVE)) return b2s(autosave); else if (eqls(str, S_AUTOSAVE)) return b2s(autosave);
else if (eqls(str, S_BEACONINTERVAL)) return b2s(beaconInterval); else if (eqls(str, S_BEACONINTERVAL)) return b2s(beaconInterval);
else if (eqls(str, S_SERIALINTERFACE)) return b2s(serialInterface); else if (eqls(str, S_SERIALINTERFACE)) return b2s(cli);
else if (eqls(str, S_DISPLAYINTERFACE)) return b2s(displayInterface); else if (eqls(str, S_DISPLAYINTERFACE)) return b2s(displayInterface);
else if (eqls(str, S_WEBINTERFACE)) return b2s(webInterface); else if (eqls(str, S_WEBINTERFACE)) return b2s(webInterface);
else if (eqls(str, S_RANDOMTX)) return b2s(randomTX); else if (eqls(str, S_RANDOMTX)) return b2s(randomTX);
@@ -371,8 +371,8 @@ String Settings::getPassword() {
return password; return password;
} }
bool Settings::getSerialInterface() { bool Settings::getCLI() {
return serialInterface; return cli;
} }
bool Settings::getDisplayInterface() { bool Settings::getDisplayInterface() {
@@ -516,8 +516,8 @@ void Settings::setPassword(String password) {
} }
} }
void Settings::setSerialInterface(bool serialInterface) { void Settings::setCLI(bool cli) {
Settings::serialInterface = serialInterface; Settings::cli = cli;
changed = true; changed = true;
} }

View File

@@ -49,7 +49,7 @@ class Settings {
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();
@@ -78,7 +78,7 @@ class Settings {
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);
@@ -106,7 +106,7 @@ class Settings {
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;

View File

@@ -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

View File

@@ -389,7 +389,7 @@ void startAP(String path, String ssid, String password, uint8_t ch, bool hidden,
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, []() {