A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol
C arduinobluetoothcan-busdebuggingeepromesp32flipperzerogpiohardware-hackingi2cjtagopenocdprotocolspwmradiorfidspisubghzuartwifi
add http handlers for network controller
Geo363ae57e5553
diff --git a/src/Abstracts/ANetworkController.cpp b/src/Abstracts/ANetworkController.cppindex 338e4357..6eaf6918 100644--- a/src/Abstracts/ANetworkController.cpp+++ b/src/Abstracts/ANetworkController.cpp@@ -11,7 +11,8 @@ ANetworkController::ANetworkController(NetcatService& netcatService,NmapService& nmapService,ICMPService& icmpService,- NvsService& nvsService,+ NvsService& nvsService,+ HttpService& httpService,ArgTransformer& argTransformer,UserInputManager& userInputManager)@@ -26,6 +27,7 @@ ANetworkController::ANetworkController(nmapService(nmapService),icmpService(icmpService),nvsService(nvsService),+ httpService(httpService),argTransformer(argTransformer),userInputManager(userInputManager){@@ -390,4 +392,79 @@ void ANetworkController::handleSsh(const TerminalCommand &cmd)// Close SSHsshService.close();terminalView.println("\r\n\nSSH: Session closed.");+}++/*+HTTP+*/+void ANetworkController::handleHttp(const TerminalCommand &cmd)+{+ #ifndef DEVICE_M5STICK++ // Check connection+ if (!wifiService.isConnected() && !ethernetService.isConnected())+ {+ terminalView.println("HTTP: You must be connected to Wi-Fi or Ethernet. Use 'connect' first.");+ return;+ }++ const auto sub = cmd.getSubcommand();++ // http get <url>+ if (sub == "get" && !cmd.getArgs().empty()) {+ handleHttpGet(cmd);+ return;+ // PH for POST, PUT, DELETE+ } else if (sub == "post" || sub == "put" || sub == "delete") {+ terminalView.println("HTTP: Only GET implemented for now.");+ return;+ // http <url>+ } else if (!sub.empty() && cmd.getArgs().empty()) {+ handleHttpGet(cmd);+ return;+ } else {+ terminalView.println("Usage: http <get|post|put|delete> <url>");+ }++ #else++ terminalView.println("HTTP: M5Stick is not supported.");++ #endif+}++/*+HTTP GET+*/+void ANetworkController::handleHttpGet(const TerminalCommand &cmd)+{+ if (cmd.getSubcommand() == "get" && cmd.getArgs().empty())+ {+ terminalView.println("Usage: http get <url>");+ return;+ }++ // Support for http <url> or http get <url>+ auto arg = cmd.getArgs().empty() ? cmd.getSubcommand() : cmd.getArgs();+ std::string url = argTransformer.ensureHttpScheme(arg);++ terminalView.println("HTTP: Sending GET request to " + url + "...");++ httpService.startGetTask(url, 5000, 8192, true);++ // Wait until timeout or response is ready+ const unsigned long deadline = millis() + 5000;+ while (!httpService.isResponseReady() && millis() < deadline) {+ delay(50);+ }++ if (httpService.isResponseReady()) {+ terminalView.println("\n========== HTTP GET =============");+ auto formatted = argTransformer.normalizeLines(httpService.lastResponse());+ terminalView.println(formatted);+ terminalView.println("=================================\n");++ } else {+ terminalView.println("\nHTTP: Error, request timed out");+ }}\ No newline at end of filediff --git a/src/Abstracts/ANetworkController.h b/src/Abstracts/ANetworkController.hindex 4b832ea8..15f44339 100644--- a/src/Abstracts/ANetworkController.h+++ b/src/Abstracts/ANetworkController.h@@ -17,6 +17,7 @@#include "Managers/UserInputManager.h"#include "States/GlobalState.h"#include "Models/TerminalCommand.h"+#include "Services/HttpService.h"class ANetworkController {public:@@ -32,7 +33,8 @@ public:NetcatService& netcatService,NmapService& nmapService,ICMPService& icmpService,- NvsService& nvsService,+ NvsService& nvsService,+ HttpService& httpService,ArgTransformer& argTransformer,UserInputManager& userInputManager);@@ -43,6 +45,8 @@ protected:void handleSsh(const TerminalCommand& cmd);void handlePing(const TerminalCommand& cmd);void handleDiscovery(const TerminalCommand &cmd);+ void handleHttp(const TerminalCommand &cmd);+ void handleHttpGet(const TerminalCommand &cmd);protected:ITerminalView& terminalView;@@ -59,7 +63,8 @@ protected:NetcatService& netcatService;NmapService& nmapService;ICMPService& icmpService;-+ HttpService& httpService;+ArgTransformer& argTransformer;UserInputManager& userInputManager;GlobalState& globalState = GlobalState::getInstance();