Skip to content

A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol

fix #16 and some refactor to wifi controller

Geo7620084066d1
diff --git a/src/Controllers/WifiController.cpp b/src/Controllers/WifiController.cpp
index 23ef23eb..eea6b568 100644
--- a/src/Controllers/WifiController.cpp
+++ b/src/Controllers/WifiController.cpp
@@ -3,8 +3,29 @@
/*
Constructor
*/
-WifiController::WifiController(ITerminalView &terminalView, IInput &terminalInput, IInput &deviceInput, WifiService &wifiService, SshService &sshService, NetcatService &netcatService, NmapService &nmapService, NvsService &nvsService, ArgTransformer &argTransformer)
- : terminalView(terminalView), terminalInput(terminalInput), deviceInput(deviceInput), wifiService(wifiService), sshService(sshService), netcatService(netcatService), nmapService(nmapService), nvsService(nvsService), argTransformer(argTransformer) {}
+WifiController::WifiController(
+ ITerminalView &terminalView,
+ IInput &terminalInput,
+ IInput &deviceInput,
+ WifiService &wifiService,
+ SshService &sshService,
+ NetcatService &netcatService,
+ NmapService &nmapService,
+ NvsService &nvsService,
+ ArgTransformer &argTransformer,
+ UserInputManager &userInputManager
+)
+ : terminalView(terminalView),
+ terminalInput(terminalInput),
+ deviceInput(deviceInput),
+ wifiService(wifiService),
+ sshService(sshService),
+ netcatService(netcatService),
+ nmapService(nmapService),
+ nvsService(nvsService),
+ argTransformer(argTransformer),
+ userInputManager(userInputManager)
+{}
/*
Entry point for command
@@ -43,8 +64,18 @@ void WifiController::handleConnect(const TerminalCommand &cmd)
return;
}
- std::string ssid = cmd.getSubcommand();
- std::string password = cmd.getArgs();
+ std::string full = cmd.getSubcommand() + " " + cmd.getArgs();
+
+ // Find the last space to separate SSID and password
+ size_t pos = full.find_last_of(' ');
+ if (pos == std::string::npos || pos == full.size() - 1)
+ {
+ terminalView.println("Usage: connect <ssid> <password>");
+ return;
+ }
+
+ std::string ssid = full.substr(0, pos);
+ std::string password = full.substr(pos + 1);
terminalView.println("WiFi: Connecting to " + ssid + "...");
@@ -557,7 +588,6 @@ void WifiController::handleNmap(const TerminalCommand &cmd)
terminalView.println("\r\n\nNmap: Scan finished.");
}
-
/*
Config
*/
diff --git a/src/Controllers/WifiController.h b/src/Controllers/WifiController.h
index 75cfae71..62be7779 100644
--- a/src/Controllers/WifiController.h
+++ b/src/Controllers/WifiController.h
@@ -8,6 +8,7 @@
#include <Services/NetcatService.h>
#include <Services/NmapService.h>
#include <Transformers/ArgTransformer.h>
+#include <Managers/UserInputManager.h>
#include <Models/TerminalCommand.h>
#include <States/GlobalState.h>
#include <Preferences.h>
@@ -24,7 +25,8 @@ public:
NetcatService& netcatService,
NmapService& nmapService,
NvsService& nvsService,
- ArgTransformer& argTransformer
+ ArgTransformer& argTransformer,
+ UserInputManager& userInputManager
);
// Entry point for Wi-Fi command
@@ -43,6 +45,7 @@ private:
NetcatService& netcatService;
NmapService& nmapService;
ArgTransformer& argTransformer;
+ UserInputManager& userInputManager;
GlobalState& state = GlobalState::getInstance();
bool configured = false;
Preferences preferences;