Эх сурвалжийг харах

Refactor modules for work with Frieren

DSR! 2 жил өмнө
parent
commit
d8c5d24eb7
66 өөрчлөгдсөн 2080 нэмэгдсэн , 3938 устгасан
  1. 29 59
      modules/src/Cabinet/api/module.php
  2. 16 38
      modules/src/Commander/api/module.php
  3. 23 50
      modules/src/ConnectedClients/api/module.php
  4. 38 115
      modules/src/CursedScreech/api/module.php
  5. 39 75
      modules/src/DNSMasqSpoof/api/module.php
  6. 59 113
      modules/src/DNSspoof/api/module.php
  7. 13 25
      modules/src/DWall/api/module.php
  8. 56 102
      modules/src/Deauth/api/module.php
  9. 34 117
      modules/src/EvilPortal/api/module.php
  10. 1 0
      modules/src/EvilPortal/includes/api/API.php
  11. 4 3
      modules/src/EvilPortal/includes/api/Portal.php
  12. 2 0
      modules/src/EvilPortal/includes/api/index.php
  13. 1 0
      modules/src/EvilPortal/includes/skeleton/MyPortal.php
  14. 1 0
      modules/src/EvilPortal/includes/targeted_skeleton/MyPortal.php
  15. 28 82
      modules/src/HTTPProxy/api/module.php
  16. 46 75
      modules/src/HackRF/api/module.php
  17. 13 33
      modules/src/InternetSpeedTest/api/module.php
  18. 56 104
      modules/src/KeyManager/api/module.php
  19. 173 206
      modules/src/LEDController/api/module.php
  20. 12 26
      modules/src/Locate/api/module.php
  21. 22 48
      modules/src/LogManager/api/module.php
  22. 12 18
      modules/src/MACInfo/api/module.php
  23. 34 60
      modules/src/Meterpreter/api/module.php
  24. 83 130
      modules/src/ModemManager/api/module.php
  25. 7 14
      modules/src/ModuleMaker/Extra/module.php
  26. 18 33
      modules/src/ModuleMaker/api/module.php
  27. 73 121
      modules/src/Occupineapple/api/module.php
  28. 37 73
      modules/src/OnlineHashCrack/api/module.php
  29. 53 81
      modules/src/OpenVPNConnect/api/module.php
  30. 44 86
      modules/src/PMKIDAttack/api/module.php
  31. 40 104
      modules/src/Papers/api/module.php
  32. 49 180
      modules/src/PortalAuth/api/module.php
  33. 1 0
      modules/src/PortalAuth/includes/scripts/injects/Blank/MyPortal.php
  34. 1 0
      modules/src/PortalAuth/includes/scripts/injects/Blank/backups/MyPortal.php
  35. 1 0
      modules/src/PortalAuth/includes/scripts/injects/Free_WiFi_Week/MyPortal.php
  36. 1 0
      modules/src/PortalAuth/includes/scripts/injects/Free_WiFi_Week/backups/MyPortal.php
  37. 1 0
      modules/src/PortalAuth/includes/scripts/injects/Harvester/MyPortal.php
  38. 1 0
      modules/src/PortalAuth/includes/scripts/injects/Harvester/backups/MyPortal.php
  39. 1 0
      modules/src/PortalAuth/includes/scripts/injects/Payloader/MyPortal.php
  40. 1 0
      modules/src/PortalAuth/includes/scripts/injects/Payloader/backups/MyPortal.php
  41. 1 0
      modules/src/PortalAuth/includes/scripts/skeleton/MyPortal.php
  42. 17 42
      modules/src/RandomRoll/api/module.php
  43. 98 146
      modules/src/Responder/api/module.php
  44. 24 49
      modules/src/SSIDManager/api/module.php
  45. 55 105
      modules/src/SSLsplit/api/module.php
  46. 11 29
      modules/src/SignalStrength/api/module.php
  47. 2 1
      modules/src/SiteSurvey/api/iwlist_parser.php
  48. 72 126
      modules/src/SiteSurvey/api/module.php
  49. 30 68
      modules/src/Status/api/module.php
  50. 22 47
      modules/src/Terminal/api/module.php
  51. 48 86
      modules/src/Themes/api/module.php
  52. 28 71
      modules/src/ZeroTier/api/module.php
  53. 40 89
      modules/src/autossh/api/module.php
  54. 15 31
      modules/src/base64encdec/api/module.php
  55. 62 107
      modules/src/dump1090/api/module.php
  56. 54 94
      modules/src/get/api/module.php
  57. 7 6
      modules/src/get/includes/unprotected/get/get.php
  58. 8 7
      modules/src/get/includes/unprotected/get/get_write.php
  59. 54 102
      modules/src/ngrep/api/module.php
  60. 47 84
      modules/src/nmap/api/module.php
  61. 49 91
      modules/src/p0f/api/module.php
  62. 42 83
      modules/src/tcpdump/api/module.php
  63. 44 80
      modules/src/tor/api/module.php
  64. 49 93
      modules/src/urlsnarf/api/module.php
  65. 2 1
      modules/src/wps/api/iwlist_parser.php
  66. 75 129
      modules/src/wps/api/module.php

+ 29 - 59
modules/src/Cabinet/api/module.php

@@ -1,45 +1,14 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class Cabinet extends Module
+/* Code modified by Frieren Auto Refactor */
+class Cabinet extends Controller
 {
 
-	public function route()
-	{
-		switch($this->request->action) {
-			case 'getDirectoryContents':
-				$this->getDirectoryContents();
-				break;
-
-			case 'getParentDirectory':
-				$this->getParentDirectory();
-				break;
-
-			case 'deleteFile':
-				$this->deleteFile();
-				break;
-
-			case 'editFile':
-				$this->editFile();
-				break;
-
-			case 'getFileContents':
-				$this->getFileContents();
-				break;
-
-			case 'createFolder':
-				$this->createFolder();
-				break;
-
-            case 'download':
-                $this->response = $this->download($this->request->filePath);
-                break;
-
-		}
-	}
+	protected $endpointRoutes = ['getDirectoryContents', 'getParentDirectory', 'deleteFile', 'editFile', 'getFileContents', 'createFolder', 'download'];
 
-	private function getDirectoryContents()
+	public function getDirectoryContents()
 	{
-		$dir = $this->request->directory;
+		$dir = $this->request['directory'];
 
 		$success = false;
 		$contents = array();
@@ -54,13 +23,13 @@ class Cabinet extends Module
 			$success = true;
 		}
 
-		$this->response = array("success" => $success, "contents" => $contents, "directory" => $dir);
+		$this->responseHandler->setData(array("success" => $success, "contents" => $contents, "directory" => $dir));
 
 	}
 
-	private function getParentDirectory()
+	public function getParentDirectory()
 	{
-		$dir = $this->request->directory;
+		$dir = $this->request['directory'];
 		$success = false;
 		$parent = "";
 
@@ -69,13 +38,13 @@ class Cabinet extends Module
 			$success = true;
 		}
 
-		$this->response = array("success" => $success, "parent" => $parent);
+		$this->responseHandler->setData(array("success" => $success, "parent" => $parent));
 
 	}
 
-	private function deleteFile()
+	public function deleteFile()
 	{
-		$f = $this->request->file;
+		$f = $this->request['file'];
 		$success = false;
 
 		if (file_exists($f)) {
@@ -86,14 +55,14 @@ class Cabinet extends Module
 			$success = true;
 		}
 
-		$this->response = array("success" => $success);
+		$this->responseHandler->setData(array("success" => $success));
 
 	}
 
-	private function editFile()
+	public function editFile()
 	{
-		$f = $this->request->file;
-		$data = $this->request->contents;
+		$f = $this->request['file'];
+		$data = $this->request['contents'];
 		$success = false;
 
 		file_put_contents($f, $data);
@@ -101,12 +70,12 @@ class Cabinet extends Module
 			$success = true;
 		}
 
-		$this->response = array("success" => $success);
+		$this->responseHandler->setData(array("success" => $success));
 	}
 
-	private function getFileContents()
+	public function getFileContents()
 	{
-		$f = $this->request->file;
+		$f = $this->request['file'];
 		$success = false;
 		$content = "";
 		$size = "0 Bytes";
@@ -117,14 +86,14 @@ class Cabinet extends Module
 			$size = $this->readableFileSize($f);
 		}
 
-		$this->response = array("success" => $success, "content" => $content, "size" => $size);
+		$this->responseHandler->setData(array("success" => $success, "content" => $content, "size" => $size));
 
 	}
 
-	private function createFolder()
+	public function createFolder()
 	{
-		$dir = $this->request->directory;
-		$name = $this->request->name;
+		$dir = $this->request['directory'];
+		$name = $this->request['name'];
 		$success = false;
 
 		if (!is_dir($dir . '/' . $name)) {
@@ -132,7 +101,7 @@ class Cabinet extends Module
 			mkdir($dir . "/" . $name);
 		}
 
-		$this->response = array("success" => $success);
+		$this->responseHandler->setData(array("success" => $success));
 	}
 
     /**
@@ -140,12 +109,13 @@ class Cabinet extends Module
      * @param: The path to the file to download
      * @return array : array
      */
-    private function download($filePath)
+    public function download()
     {
+        $filePath = $this->request['filePath'];
         if (file_exists($filePath)) {
-            return array("success" => true, "message" => null, "download" => $this->downloadFile($filePath));
+            $this->responseHandler->setData( array("success" => true, "message" => null, "download" => $this->systemHelper->downloadFile($filePath)) );
         } else {
-            return array("success" => false, "message" => "File does not exist", "download" => null);
+            $this->responseHandler->setData( array("success" => false, "message" => "File does not exist", "download" => null) );
         }
     }
 
@@ -154,7 +124,7 @@ class Cabinet extends Module
      * @param $file: The file to get size of
      * @return string: File size plus unit. Exp: 3.14M
      */
-    private function readableFileSize($file) {
+    public function readableFileSize($file) {
         $size = filesize($file);
 
         if ($size == null)

+ 16 - 38
modules/src/Commander/api/module.php

@@ -1,61 +1,39 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class Commander extends Module
+/* Code modified by Frieren Auto Refactor */
+class Commander extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'startCommander':
-                $this->startCommander();
-                break;
-
-            case 'stopCommander':
-                $this->stopCommander();
-                break;
-
-            case 'getConfiguration':
-                $this->getConfiguration();
-                break;
-
-            case 'saveConfiguration':
-                $this->saveConfiguration();
-                break;
-
-            case 'restoreDefaultConfiguration':
-                $this->restoreDefaultConfiguration();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['startCommander', 'stopCommander', 'getConfiguration', 'saveConfiguration', 'restoreDefaultConfiguration'];
 
-    private function startCommander()
+    public function startCommander()
     {
-        $this->execBackground('cd /pineapple/modules/Commander/Python && python commander.py');
-        $this->response = array("success" => true);
+        $this->systemHelper->execBackground('cd /pineapple/modules/Commander/Python && python commander.py');
+        $this->responseHandler->setData(array("success" => true));
     }
 
-    private function stopCommander()
+    public function stopCommander()
     {
         exec('kill -9 $(pgrep -f commander)');
-        $this->response = array("success" => true);
+        $this->responseHandler->setData(array("success" => true));
     }
 
-    private function getConfiguration()
+    public function getConfiguration()
     {
         $config = file_get_contents('/pineapple/modules/Commander/Python/commander.conf');
-        $this->response = array("CommanderConfiguration" => $config);
+        $this->responseHandler->setData(array("CommanderConfiguration" => $config));
     }
 
-    private function saveConfiguration()
+    public function saveConfiguration()
     {
-        $config = $this->request->CommanderConfiguration;
+        $config = $this->request['CommanderConfiguration'];
         file_put_contents('/pineapple/modules/Commander/Python/commander.conf', $config);
-        $this->response = array("success" => true);
+        $this->responseHandler->setData(array("success" => true));
     }
 
-    private function restoreDefaultConfiguration()
+    public function restoreDefaultConfiguration()
     {
         $defaultConfig = file_get_contents('/pineapple/modules/Commander/assets/default.conf');
         file_put_contents('/pineapple/modules/Commander/Python/commander.conf', $defaultConfig);
-        $this->response = array("success" => true);
+        $this->responseHandler->setData(array("success" => true));
     }
 }

+ 23 - 50
modules/src/ConnectedClients/api/module.php

@@ -1,78 +1,51 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class ConnectedClients extends Module
+/* Code modified by Frieren Auto Refactor */
+class ConnectedClients extends Controller
 {
-	public function route()
-	{
-		switch ($this->request->action) {
-			case 'getVersionInfo':
-			$this->getVersionInfo();
-			break;
-			case 'getDHCPLeases':
-			$this->getDHCPLeases();
-			break;
-			case 'getBlacklist':
-			$this->getBlacklist();
-			break;
-			case 'getConnectedClients':
-			$this->getConnectedClients();
-			break;
-			case 'removeMacAddress':
-			$this->removeMacAddress();
-			break;
-			case 'addMacAddress':
-			$this->addMacAddress();
-			break;
-			case 'disassociateMac':
-			$this->disassociateMac();
-			break;
-			case 'deauthenticateMac':
-			$this->deauthenticateMac();
-			break;
-		}
-	}
+	protected $endpointRoutes = ['getVersionInfo', 'getDHCPLeases', 'getBlacklist', 'getConnectedClients', 'removeMacAddress', 'addMacAddress', 'disassociateMac', 'deauthenticateMac'];
 
 	protected function getVersionInfo() {
 		$moduleInfo = @json_decode(file_get_contents("/pineapple/modules/ConnectedClients/module.info"));
-		$this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
+		$this->responseHandler->setData(array('title' => $moduleInfo->title, 'version' => $moduleInfo->version));
 	}
 
-	private function getDHCPLeases() {
+	public function getDHCPLeases() {
 		exec("cat /tmp/dhcp.leases", $dhcpleases);
-		$this->response = array('dhcpleases' => $dhcpleases);		
+		$this->responseHandler->setData(array('dhcpleases' => $dhcpleases));		
 
 	}
 
-	private function getBlacklist() {
+	public function getBlacklist() {
 		exec("pineapple karma list_macs", $mac_list);
-		$this->response = array('blacklist' => $mac_list);
+		$this->responseHandler->setData(array('blacklist' => $mac_list));
 	}
 
-	private function getConnectedClients() {
+	public function getConnectedClients() {
 		exec("iwconfig 2>/dev/null | grep IEEE | awk '{print $1}'", $wlandev);
 		exec("iw dev $wlandev[0] station dump | grep Station | awk '{print $2}'", $wlan0clients);
 		exec("iw dev $wlandev[1] station dump | grep Station | awk '{print $2}'", $wlan01clients);
 		exec("iw dev $wlandev[2] station dump | grep Station | awk '{print $2}'", $wlan1clients);
-		$this->response = array('wlan0clients' => $wlan0clients, 'wlan01clients' => $wlan01clients, 'wlan1clients' => $wlan1clients, 'wlandev' => $wlandev);
+		$this->responseHandler->setData(array('wlan0clients' => $wlan0clients, 'wlan01clients' => $wlan01clients, 'wlan1clients' => $wlan1clients, 'wlandev' => $wlandev));
 	}
 
-	private function removeMacAddress() {
-		exec('pineapple karma del_mac "'.$this->request->macAddress.'"', $removeMacResponse);
-		$this->response = array('removeMacResponse' => $removeMacResponse);
+	public function removeMacAddress() {
+		exec('pineapple karma del_mac "'.$this->request['macAddress'].'"', $removeMacResponse);
+		$this->responseHandler->setData(array('removeMacResponse' => $removeMacResponse));
 	}
 
-	private function addMacAddress() {
-		exec('pineapple karma add_mac "'.$this->request->macAddress.'"', $addMacResponse);
-		$this->response = array('addMacResponse' => $addMacResponse);
+	public function addMacAddress() {
+		exec('pineapple karma add_mac "'.$this->request['macAddress'].'"', $addMacResponse);
+		$this->responseHandler->setData(array('addMacResponse' => $addMacResponse));
 	}
 
-	private function disassociateMac() {
-		exec('hostapd_cli disassociate "'.$this->request->macAddress.'"', $disassociateResponse);
-		$this->response = array('disassociateResponse' => $disassociateResponse);
+	public function disassociateMac() {
+		exec('hostapd_cli disassociate "'.$this->request['macAddress'].'"', $disassociateResponse);
+		$this->responseHandler->setData(array('disassociateResponse' => $disassociateResponse));
 	}
 
-	private function deauthenticateMac() {
-		exec('hostapd_cli deauthenticate "'.$this->request->macAddress.'"', $deauthenticateResponse);
-		$this->response = array('deauthSuccess' => 'Successful', 'deauthenticateResponse' => $deauthenticateResponse);
+	public function deauthenticateMac() {
+		exec('hostapd_cli deauthenticate "'.$this->request['macAddress'].'"', $deauthenticateResponse);
+		$this->responseHandler->setData(array('deauthSuccess' => 'Successful', 'deauthenticateResponse' => $deauthenticateResponse));
 	}
 }

+ 38 - 115
modules/src/CursedScreech/api/module.php

@@ -1,6 +1,8 @@
 <?php
 
-namespace pineapple;
+namespace frieren\core;
+
+/* Code modified by Frieren Auto Refactor */
 
 // Root level includes
 define('__INCLUDES__', "/pineapple/modules/CursedScreech/includes/");
@@ -64,93 +66,14 @@ if (!empty($_FILES)) {
 	die();
 }
 
-class CursedScreech extends Module {
-	public function route() {
-		switch ($this->request->action) {
-			case 'init':
-				$this->init();
-				break;
-			case 'depends':
-				$this->depends($this->request->task);
-				break;
-			case 'loadSettings':
-				$this->loadSettings();
-				break;
-			case 'updateSettings':
-				$this->updateSettings($this->request->settings);
-				break;
-			case 'readLog':
-				$this->retrieveLog($this->request->logName, $this->request->type);
-				break;
-			case 'getLogs':
-				$this->getLogs($this->request->type);
-				break;
-			case 'clearLog':
-				$this->clearLog($this->request->logName, $this->request->type);
-				break;
-			case 'deleteLog':
-				$this->deleteLog($this->request->logName, $this->request->type);
-				break;
-			case 'startProc':
-				$this->startProc($this->request->procName);
-				break;
-			case 'procStatus':
-				$this->procStatus($this->request->procName);
-				break;
-			case 'stopProc':
-				$this->stopProc($this->request->procName);
-				break;
-			case 'loadCertificates':
-				if (is_dir(__SSLSTORE__)) {
-					$this->loadCertificates();
-				} else {
-					$this->respond(false, "Papers is not installed. Please enter a path to your keys manually.");
-				}
-				break;
-			case 'loadTargets':
-				$this->loadTargets();
-				break;
-			case 'deleteTarget':
-				$this->deleteTarget($this->request->target);
-				break;
-			case 'sendCommand':
-				$this->sendCommand($this->request->command, $this->request->targets);
-				break;
-			case 'downloadLog':
-				$this->downloadLog($this->request->logName, $this->request->logType);
-				break;
-			case 'loadEZCmds':
-				$this->loadEZCmds();
-				break;
-			case 'saveEZCmds':
-				$this->saveEZCmds($this->request->ezcmds);
-				break;
-			case 'genPayload':
-				$this->genPayload($this->request->type);
-				break;
-			case 'clearDownloads':
-				$this->clearDownloads();
-				break;
-			case 'loadAvailableInterfaces':
-				$this->loadAvailableInterfaces();
-				break;
-			case 'getPayloads':
-				$this->getPayloads();
-				break;
-			case 'deletePayload':
-				$this->deletePayload($this->request->filePath);
-				break;
-			case 'cfgUploadLimit':
-				$this->cfgUploadLimit();
-				break;
-		}
-	}
+class CursedScreech extends Controller {
+	protected $endpointRoutes = ['init', 'depends', 'loadSettings', 'updateSettings', 'readLog', 'getLogs', 'clearLog', 'deleteLog', 'startProc', 'procStatus', 'stopProc', 'loadCertificates', 'loadTargets', 'deleteTarget', 'sendCommand', 'downloadLog', 'loadEZCmds', 'saveEZCmds', 'genPayload', 'clearDownloads', 'loadAvailableInterfaces', 'getPayloads', 'deletePayload', 'cfgUploadLimit'];
 	
 	/* ============================ */
 	/*        INIT FUNCTIONS        */
 	/* ============================ */
 	
-	private function init() {
+	public function init() {
 		if (!file_exists(__LOGS__)) {
 			if (!mkdir(__LOGS__, 0755, true)) {
 				$this->respond(false, "Failed to create logs directory");
@@ -179,7 +102,7 @@ class CursedScreech extends Module {
 	/*      DEPENDS FUNCTIONS       */
 	/* ============================ */
 	
-	private function depends($action) {
+	public function depends($action) {
 		$retData = array();
 		
 		if ($action == "install") {
@@ -211,7 +134,7 @@ class CursedScreech extends Module {
 	/*      SETTINGS FUNCTIONS      */
 	/* ============================ */
 	
-	private function loadSettings(){
+	public function loadSettings(){
 		$configs = array();
 		$config_file = fopen(__SETTINGS__, "r");
 		if ($config_file) {
@@ -226,7 +149,7 @@ class CursedScreech extends Module {
 		return $configs;
 	}
 	
-	private function updateSettings($settings) {
+	public function updateSettings($settings) {
 		// Load the current settings from file
 		$configs = $this->loadSettings();
 		
@@ -257,7 +180,7 @@ class CursedScreech extends Module {
 	/*       FOREST FUNCTIONS       */
 	/* ============================ */
 	
-	private function startProc($procName) {
+	public function startProc($procName) {
 		if ($procName == "kuro.py") {
 			file_put_contents(__ACTIVITYLOG__, "[+] Starting Kuro...\n", FILE_APPEND);
 		}
@@ -275,7 +198,7 @@ class CursedScreech extends Module {
 		}
 	}
 	
-	private function procStatus($procName) {
+	public function procStatus($procName) {
 		if (($status = $this->getPID($procName)) != "") {
 			$this->respond(true, null, $status);
 			return true;
@@ -284,7 +207,7 @@ class CursedScreech extends Module {
 		return false;
 	}
 	
-	private function stopProc($procName) {
+	public function stopProc($procName) {
 		// Check if the process is running, if so grab it's PID
 		if (($pid = $this->getPID($procName)) == "") {
 			$this->respond(true);
@@ -309,7 +232,7 @@ class CursedScreech extends Module {
 		return false;
 	}
 	
-	private function getPID($procName) {
+	public function getPID($procName) {
 		$data = array();
 		exec("pgrep -lf " . $procName, $data);
 		$output = explode(" ", $data[0]);
@@ -319,7 +242,7 @@ class CursedScreech extends Module {
 		return false;
 	}
 	
-	private function loadTargets() {
+	public function loadTargets() {
 		$targets = array();
 		$fh = fopen(__TARGETS__, "r");
 		if ($fh) {
@@ -335,7 +258,7 @@ class CursedScreech extends Module {
 		return $targets;
 	}
 	
-	private function deleteTarget($target) {
+	public function deleteTarget($target) {
 		$targetFile = explode("\n", file_get_contents(__TARGETS__));
 		$key = array_search($target, $targetFile, true);
 		if ($key !== False) {
@@ -350,7 +273,7 @@ class CursedScreech extends Module {
 		return true;
 	}
 	
-	private function sendCommand($cmd, $targets) {
+	public function sendCommand($cmd, $targets) {
 		if (count($targets) == 0) {
 			$this->respond(false);
 			return;
@@ -372,17 +295,17 @@ class CursedScreech extends Module {
 		}
 	}
 	
-	private function downloadLog($logName, $type) {
+	public function downloadLog($logName, $type) {
 		$dir = ($type == "forest") ? __FOREST__ : (($type == "targets") ? __TARGETLOGS__ : "");
 		if (file_exists($dir . $logName)) {
-			$this->respond(true, null, $this->downloadFile($dir . $logName));
+			$this->respond(true, null, $this->systemHelper->downloadFile($dir . $logName));
 			return true;
 		}
 		$this->respond(false);
 		return false;
 	}
 	
-	private function genPayload($type) {
+	public function genPayload($type) {
 		if ($type == "python") {
 			$dir = __API_PY__;
 			$payload = "payload.py";
@@ -446,14 +369,14 @@ class CursedScreech extends Module {
 		
 		// Check if a file exists in the downloads directory
 		if (count(scandir(__API_DL__)) > 2) {
-			$this->respond(true, null, $this->downloadFile(__API_DL__ . $zip));
+			$this->respond(true, null, $this->systemHelper->downloadFile(__API_DL__ . $zip));
 			return true;
 		}
 		$this->respond(false);
 		return false;
 	}
 	
-	private function clearDownloads() {
+	public function clearDownloads() {
 		$files = scandir(__API_DL__);
 		$success = true;
 		foreach ($files as $file) {
@@ -466,7 +389,7 @@ class CursedScreech extends Module {
 		return $success;
 	}
 	
-	private function loadAvailableInterfaces() {
+	public function loadAvailableInterfaces() {
 		$data = array();
 		exec(__SCRIPTS__ . "getListeningInterfaces.sh", $data);
 		if ($data == NULL) {
@@ -480,7 +403,7 @@ class CursedScreech extends Module {
 	//    PAYLOAD FUNCTIONS    //
 	//=========================//
 	
-	private function getPayloads() {
+	public function getPayloads() {
 		$files = [];
 		
 		foreach (scandir(__PAYLOADS__) as $file) {
@@ -491,7 +414,7 @@ class CursedScreech extends Module {
 		return $files;
 	}
 	
-	private function deletePayload($filePath) {
+	public function deletePayload($filePath) {
 		if (!unlink($filePath)) {
 			$this->logError("Delete Payload", "Failed to delete payload at path " . $filePath);
 			$this->respond(false);
@@ -501,7 +424,7 @@ class CursedScreech extends Module {
 		return true;
 	}
 	
-	private function cfgUploadLimit() {
+	public function cfgUploadLimit() {
 		$data = array();
 		$res = exec("python " . __SCRIPTS__ . "cfgUploadLimit.py > /dev/null 2>&1 &", $data);
 		if ($res != "") {
@@ -517,7 +440,7 @@ class CursedScreech extends Module {
 	/*        EZ CMD FUNCTIONS      */
 	/* ============================ */
 	
-	private function loadEZCmds() {
+	public function loadEZCmds() {
 		$contents = explode("\n", file_get_contents(__EZCMDS__));
 		$cmdDict = array();
 		foreach ($contents as $line) {
@@ -529,7 +452,7 @@ class CursedScreech extends Module {
 		return $cmdDict;
 	}
 	
-	private function saveEZCmds($cmds) {
+	public function saveEZCmds($cmds) {
 		$fh = fopen(__EZCMDS__, "w");
 		if (!$fh) {
 			$this->respond(false);
@@ -545,14 +468,14 @@ class CursedScreech extends Module {
 	/*         MISCELLANEOUS        */
 	/* ============================ */
 	
-	private function respond($success, $msg = null, $data = null, $error = null) {
-		$this->response = array("success" => $success,"message" => $msg, "data" => $data, "error" => $error);
+	public function respond($success, $msg = null, $data = null, $error = null) {
+		$this->responseHandler->setData(array("success" => $success,"message" => $msg, "data" => $data, "error" => $error));
 	}
 	
 	/* ============================ */
 	/*         LOG FUNCTIONS        */
 	/* ============================ */
-	private function getLogs($type) {
+	public function getLogs($type) {
 		$dir = ($type == "error") ? __LOGS__ : (($type == "targets") ? __TARGETLOGS__ : __CHANGELOGS__);
 		$contents = array();
 		foreach (scandir($dir) as $log) {
@@ -562,7 +485,7 @@ class CursedScreech extends Module {
 		$this->respond(true, null, $contents);
 	}
 	
-	private function retrieveLog($logname, $type) {
+	public function retrieveLog($logname, $type) {
 		$dir = ($type == "error") ? __LOGS__ : (($type == "help") ? __HELPFILES__ : (($type == "forest") ? __FOREST__ : (($type == "targets") ? __TARGETLOGS__ : __CHANGELOGS__)));
 		$data = file_get_contents($dir . $logname);
 		if (!$data) {
@@ -572,14 +495,14 @@ class CursedScreech extends Module {
 		$this->respond(true, null, $data);
 	}
 	
-	private function clearLog($log,$type) {
+	public function clearLog($log,$type) {
 		$dir = ($type == "forest") ? __FOREST__ : (($type == "targets") ? __TARGETLOGS__ : "");
 		$fh = fopen($dir . $log, "w");
 		fclose($fh);
 		$this->respond(true);
 	}
 	
-	private function deleteLog($logname, $type) {
+	public function deleteLog($logname, $type) {
 		$dir = ($type == "error") ? __LOGS__ : (($type == "targets") ? __TARGETLOGS__ : __CHANGELOGS__);
 		$res = unlink($dir . $logname);
 		if (!$res) {
@@ -589,7 +512,7 @@ class CursedScreech extends Module {
 		$this->respond(true);
 	}
 	
-	private function logError($filename, $data) {
+	public function logError($filename, $data) {
 		$time = exec("date +'%H_%M_%S'");
 		$fh = fopen(__LOGS__ . str_replace(" ","_",$filename) . "_" . $time . ".txt", "w+");
 		fwrite($fh, $data);
@@ -600,12 +523,12 @@ class CursedScreech extends Module {
 	/*         KEY FUNCTIONS TO INTERFACE WITH PAPERS        */
 	/* ===================================================== */
 	
-	private function loadCertificates() {
+	public function loadCertificates() {
 		$certs = $this->getKeys(__SSLSTORE__);
 		$this->respond(true,null,$certs);
 	}
 	
-	private function getKeys($dir) {
+	public function getKeys($dir) {
 		$keyType = "TLS/SSL";
 		$keys = scandir($dir);
 		$certs = array();
@@ -632,7 +555,7 @@ class CursedScreech extends Module {
 		return $certs;
 	}
 	
-	private function objNameExistsInArray($name, $arr) {
+	public function objNameExistsInArray($name, $arr) {
 		foreach ($arr as $x) {
 			if ($x->Name == $name) {
 				return True;
@@ -641,7 +564,7 @@ class CursedScreech extends Module {
 		return False;
 	}
 	
-	private function keyIsEncrypted($keyName) {
+	public function keyIsEncrypted($keyName) {
 		$data = array();
 		$keyDir = __SSLSTORE__;
 		exec(__SCRIPTS__ . "testEncrypt.sh -k " . $keyName . " -d " . $keyDir . " 2>&1", $data);

+ 39 - 75
modules/src/DNSMasqSpoof/api/module.php

@@ -1,49 +1,13 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class DNSMasqSpoof extends Module
+/* Code modified by Frieren Auto Refactor */
+class DNSMasqSpoof extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'refreshInfo':
-                $this->refreshInfo();
-                break;
-            case 'refreshOutput':
-                $this->refreshOutput();
-                break;
-            case 'refreshStatus':
-                $this->refreshStatus();
-                break;
-            case 'toggleDNSMasqSpoof':
-                $this->toggleDNSMasqSpoof();
-                break;
-            case 'handleDependencies':
-                $this->handleDependencies();
-                break;
-            case 'handleDependenciesStatus':
-                $this->handleDependenciesStatus();
-                break;
-            case 'toggleDNSMasqSpoofOnBoot':
-                $this->toggleDNSMasqSpoofOnBoot();
-                break;
-            case 'saveLandingPageData':
-                $this->saveLandingPageData();
-                break;
-            case 'getLandingPageData':
-                $this->getLandingPageData();
-                break;
-            case 'saveHostsData':
-                $this->saveHostsData();
-                break;
-            case 'getHostsData':
-                $this->getHostsData();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['refreshInfo', 'refreshOutput', 'refreshStatus', 'toggleDNSMasqSpoof', 'handleDependencies', 'handleDependenciesStatus', 'toggleDNSMasqSpoofOnBoot', 'saveLandingPageData', 'getLandingPageData', 'saveHostsData', 'getHostsData'];
 
     protected function checkDep($dependencyName)
     {
-        return ($this->checkDependency($dependencyName) && ($this->uciGet("dnsmasqspoof.module.installed")));
+        return ($this->systemHelper->checkDependency($dependencyName) && ($this->systemHelper->uciGet("dnsmasqspoof.module.installed")));
     }
 
     protected function getDevice()
@@ -59,30 +23,30 @@ class DNSMasqSpoof extends Module
     protected function refreshInfo()
     {
         $moduleInfo = @json_decode(file_get_contents("/pineapple/modules/DNSMasqSpoof/module.info"));
-        $this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
+        $this->responseHandler->setData(array('title' => $moduleInfo->title, 'version' => $moduleInfo->version));
     }
 
-    private function handleDependencies()
+    public function handleDependencies()
     {
         if (!$this->checkDep("dnsmasq")) {
-            $this->execBackground("/pineapple/modules/DNSMasqSpoof/scripts/dependencies.sh install ".$this->request->destination);
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/DNSMasqSpoof/scripts/dependencies.sh install ".$this->request['destination']);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->execBackground("/pineapple/modules/DNSMasqSpoof/scripts/dependencies.sh remove");
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/DNSMasqSpoof/scripts/dependencies.sh remove");
+            $this->responseHandler->setData(array('success' => true));
         }
     }
 
-    private function handleDependenciesStatus()
+    public function handleDependenciesStatus()
     {
         if (!file_exists('/tmp/DNSMasqSpoof.progress')) {
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function toggleDNSMasqSpoofOnBoot()
+    public function toggleDNSMasqSpoofOnBoot()
     {
         if (exec("cat /etc/rc.local | grep DNSMasqSpoof/scripts/autostart_dnsmasqspoof.sh") == "") {
             exec("sed -i '/exit 0/d' /etc/rc.local");
@@ -93,19 +57,19 @@ class DNSMasqSpoof extends Module
         }
     }
 
-    private function toggleDNSMasqSpoof()
+    public function toggleDNSMasqSpoof()
     {
-        if (!$this->checkRunning("dnsmasq")) {
-            $this->execBackground("/pineapple/modules/DNSMasqSpoof/scripts/dnsmasqspoof.sh start");
+        if (!$this->systemHelper->checkRunning("dnsmasq")) {
+            $this->systemHelper->execBackground("/pineapple/modules/DNSMasqSpoof/scripts/dnsmasqspoof.sh start");
         } else {
-            $this->execBackground("/pineapple/modules/DNSMasqSpoof/scripts/dnsmasqspoof.sh stop");
+            $this->systemHelper->execBackground("/pineapple/modules/DNSMasqSpoof/scripts/dnsmasqspoof.sh stop");
         }
     }
 
-    private function refreshStatus()
+    public function refreshStatus()
     {
         if (!file_exists('/tmp/DNSMasqSpoof.progress')) {
-            if (!$this->checkDependency("dnsmasq")) {
+            if (!$this->systemHelper->checkDependency("dnsmasq")) {
                 $installed = false;
                 $install = "Not installed";
                 $installLabel = "danger";
@@ -122,7 +86,7 @@ class DNSMasqSpoof extends Module
                 $installLabel = "success";
                 $processing = false;
 
-                if ($this->checkRunning("dnsmasq")) {
+                if ($this->systemHelper->checkRunning("dnsmasq")) {
                     $status = "Stop";
                     $statusLabel = "danger";
                 } else {
@@ -151,46 +115,46 @@ class DNSMasqSpoof extends Module
             $bootLabelOFF = "danger";
         }
 
-        $device = $this->getDevice();
-        $sdAvailable = $this->isSDAvailable();
+        $device = $this->systemHelper->getDevice();
+        $sdAvailable = $this->systemHelper->isSDAvailable();
 
-        $this->response = array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "bootLabelON" => $bootLabelON, "bootLabelOFF" => $bootLabelOFF, "processing" => $processing);
+        $this->responseHandler->setData(array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "bootLabelON" => $bootLabelON, "bootLabelOFF" => $bootLabelOFF, "processing" => $processing));
     }
 
-    private function refreshOutput()
+    public function refreshOutput()
     {
-        if ($this->checkDependency("dnsmasq")) {
-            if ($this->checkRunning("dnsmasq")) {
-                $this->response = "DNSMasq Spoof is running...";
+        if ($this->systemHelper->checkDependency("dnsmasq")) {
+            if ($this->systemHelper->checkRunning("dnsmasq")) {
+                $this->responseHandler->setData("DNSMasq Spoof is running...");
             } else {
-                $this->response = "DNSMasq Spoof is not running...";
+                $this->responseHandler->setData("DNSMasq Spoof is not running...");
             }
         } else {
-            $this->response = "DNSMasq Spoof is not installed...";
+            $this->responseHandler->setData("DNSMasq Spoof is not installed...");
         }
     }
 
-    private function saveLandingPageData()
+    public function saveLandingPageData()
     {
         $filename = '/www/index.php';
-        file_put_contents($filename, $this->request->configurationData);
+        file_put_contents($filename, $this->request['configurationData']);
     }
 
-    private function getLandingPageData()
+    public function getLandingPageData()
     {
         $configurationData = file_get_contents('/www/index.php');
-        $this->response = array("configurationData" => $configurationData);
+        $this->responseHandler->setData(array("configurationData" => $configurationData));
     }
 
-    private function saveHostsData()
+    public function saveHostsData()
     {
         $filename = '/pineapple/modules/DNSMasqSpoof/hosts/dnsmasq.hosts';
-        file_put_contents($filename, $this->request->configurationData);
+        file_put_contents($filename, $this->request['configurationData']);
     }
 
-    private function getHostsData()
+    public function getHostsData()
     {
         $configurationData = file_get_contents('/pineapple/modules/DNSMasqSpoof/hosts/dnsmasq.hosts');
-        $this->response = array("configurationData" => $configurationData);
+        $this->responseHandler->setData(array("configurationData" => $configurationData));
     }
 }

+ 59 - 113
modules/src/DNSspoof/api/module.php

@@ -1,67 +1,13 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class DNSspoof extends Module
+/* Code modified by Frieren Auto Refactor */
+class DNSspoof extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'refreshInfo':
-                    $this->refreshInfo();
-                    break;
-            case 'refreshOutput':
-                $this->refreshOutput();
-                break;
-            case 'refreshStatus':
-                $this->refreshStatus();
-                break;
-            case 'toggleDNSspoof':
-                $this->toggleDNSspoof();
-                break;
-            case 'handleDependencies':
-                $this->handleDependencies();
-                break;
-            case 'handleDependenciesStatus':
-                $this->handleDependenciesStatus();
-                break;
-            case 'refreshHistory':
-                $this->refreshHistory();
-                break;
-            case 'viewHistory':
-                $this->viewHistory();
-                break;
-            case 'deleteHistory':
-                $this->deleteHistory();
-                break;
-            case 'downloadHistory':
-                $this->downloadHistory();
-                break;
-            case 'toggleDNSspoofOnBoot':
-                $this->toggleDNSspoofOnBoot();
-                break;
-            case 'getInterfaces':
-                $this->getInterfaces();
-                break;
-            case 'saveAutostartSettings':
-                $this->saveAutostartSettings();
-                break;
-            case 'saveLandingPageData':
-                $this->saveLandingPageData();
-                break;
-            case 'getLandingPageData':
-                $this->getLandingPageData();
-                break;
-            case 'saveHostsData':
-                $this->saveHostsData();
-                break;
-            case 'getHostsData':
-                $this->getHostsData();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['refreshInfo', 'refreshOutput', 'refreshStatus', 'toggleDNSspoof', 'handleDependencies', 'handleDependenciesStatus', 'refreshHistory', 'viewHistory', 'deleteHistory', 'downloadHistory', 'toggleDNSspoofOnBoot', 'getInterfaces', 'saveAutostartSettings', 'saveLandingPageData', 'getLandingPageData', 'saveHostsData', 'getHostsData'];
 
     protected function checkDep($dependencyName)
     {
-        return ($this->checkDependency($dependencyName) && ($this->uciGet("dnsspoof.module.installed")));
+        return ($this->systemHelper->checkDependency($dependencyName) && ($this->systemHelper->uciGet("dnsspoof.module.installed")));
     }
 
     protected function getDevice()
@@ -72,30 +18,30 @@ class DNSspoof extends Module
     protected function refreshInfo()
     {
         $moduleInfo = @json_decode(file_get_contents("/pineapple/modules/DNSspoof/module.info"));
-        $this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
+        $this->responseHandler->setData(array('title' => $moduleInfo->title, 'version' => $moduleInfo->version));
     }
 
-    private function handleDependencies()
+    public function handleDependencies()
     {
         if (!$this->checkDep("dnsspoof")) {
-            $this->execBackground("/pineapple/modules/DNSspoof/scripts/dependencies.sh install ".$this->request->destination);
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/DNSspoof/scripts/dependencies.sh install ".$this->request['destination']);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->execBackground("/pineapple/modules/DNSspoof/scripts/dependencies.sh remove");
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/DNSspoof/scripts/dependencies.sh remove");
+            $this->responseHandler->setData(array('success' => true));
         }
     }
 
-    private function handleDependenciesStatus()
+    public function handleDependenciesStatus()
     {
         if (!file_exists('/tmp/DNSspoof.progress')) {
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function toggleDNSspoofOnBoot()
+    public function toggleDNSspoofOnBoot()
     {
         if (exec("cat /etc/rc.local | grep DNSspoof/scripts/autostart_dnsspoof.sh") == "") {
             exec("sed -i '/exit 0/d' /etc/rc.local");
@@ -106,30 +52,30 @@ class DNSspoof extends Module
         }
     }
 
-    private function toggleDNSspoof()
+    public function toggleDNSspoof()
     {
-        if (!$this->checkRunning("dnsspoof")) {
-            $this->uciSet("dnsspoof.run.interface", $this->request->interface);
+        if (!$this->systemHelper->checkRunning("dnsspoof")) {
+            $this->systemHelper->uciSet("dnsspoof.run.interface", $this->request['interface']);
 
-            $this->execBackground("/pineapple/modules/DNSspoof/scripts/dnsspoof.sh start");
+            $this->systemHelper->execBackground("/pineapple/modules/DNSspoof/scripts/dnsspoof.sh start");
         } else {
-            $this->uciSet("dnsspoof.run.interface", '');
+            $this->systemHelper->uciSet("dnsspoof.run.interface", '');
 
-            $this->execBackground("/pineapple/modules/DNSspoof/scripts/dnsspoof.sh stop");
+            $this->systemHelper->execBackground("/pineapple/modules/DNSspoof/scripts/dnsspoof.sh stop");
         }
     }
 
-    private function getInterfaces()
+    public function getInterfaces()
     {
         exec("cat /proc/net/dev | tail -n +3 | cut -f1 -d: | sed 's/ //g'", $interfaceArray);
 
-        $this->response = array("interfaces" => $interfaceArray, "selected" => $this->uciGet("dnsspoof.run.interface"));
+        $this->responseHandler->setData(array("interfaces" => $interfaceArray, "selected" => $this->systemHelper->uciGet("dnsspoof.run.interface")));
     }
 
-    private function refreshStatus()
+    public function refreshStatus()
     {
         if (!file_exists('/tmp/DNSspoof.progress')) {
-            if (!$this->checkDependency("dnsspoof")) {
+            if (!$this->systemHelper->checkDependency("dnsspoof")) {
                 $installed = false;
                 $install = "Not installed";
                 $installLabel = "danger";
@@ -146,7 +92,7 @@ class DNSspoof extends Module
                 $installLabel = "success";
                 $processing = false;
 
-                if ($this->checkRunning("dnsspoof")) {
+                if ($this->systemHelper->checkRunning("dnsspoof")) {
                     $status = "Stop";
                     $statusLabel = "danger";
                 } else {
@@ -175,16 +121,16 @@ class DNSspoof extends Module
             $bootLabelOFF = "danger";
         }
 
-        $device = $this->getDevice();
-        $sdAvailable = $this->isSDAvailable();
+        $device = $this->systemHelper->getDevice();
+        $sdAvailable = $this->systemHelper->isSDAvailable();
 
-        $this->response = array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "bootLabelON" => $bootLabelON, "bootLabelOFF" => $bootLabelOFF, "processing" => $processing);
+        $this->responseHandler->setData(array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "bootLabelON" => $bootLabelON, "bootLabelOFF" => $bootLabelOFF, "processing" => $processing));
     }
 
-    private function refreshOutput()
+    public function refreshOutput()
     {
-        if ($this->checkDependency("dnsspoof")) {
-            if ($this->checkRunning("dnsspoof")) {
+        if ($this->systemHelper->checkDependency("dnsspoof")) {
+            if ($this->systemHelper->checkRunning("dnsspoof")) {
                 $path = "/pineapple/modules/DNSspoof/log";
 
                 $latest_ctime = 0;
@@ -202,8 +148,8 @@ class DNSspoof extends Module
                 if ($latest_filename != "") {
                     $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/DNSspoof/log/".$latest_filename));
 
-                    if ($this->request->filter != "") {
-                        $filter = $this->request->filter;
+                    if ($this->request['filter'] != "") {
+                        $filter = $this->request['filter'];
 
                         $cmd = "cat /pineapple/modules/DNSspoof/log/".$latest_filename." | ".$filter;
                     } else {
@@ -212,20 +158,20 @@ class DNSspoof extends Module
 
                     exec($cmd, $output);
                     if (!empty($output)) {
-                        $this->response = implode("\n", array_reverse($output));
+                        $this->responseHandler->setData(implode("\n", array_reverse($output)));
                     } else {
-                        $this->response = "Empty log...";
+                        $this->responseHandler->setData("Empty log...");
                     }
                 }
             } else {
-                $this->response = "DNSspoof is not running...";
+                $this->responseHandler->setData("DNSspoof is not running...");
             }
         } else {
-            $this->response = "DNSspoof is not installed...";
+            $this->responseHandler->setData("DNSspoof is not installed...");
         }
     }
 
-    private function refreshHistory()
+    public function refreshHistory()
     {
         $this->streamFunction = function () {
             $log_list = array_reverse(glob("/pineapple/modules/DNSspoof/log/*"));
@@ -246,55 +192,55 @@ class DNSspoof extends Module
         };
     }
 
-    private function viewHistory()
+    public function viewHistory()
     {
-        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/DNSspoof/log/".$this->request->file));
-        exec("cat /pineapple/modules/DNSspoof/log/".$this->request->file, $output);
+        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/DNSspoof/log/".$this->request['file']));
+        exec("cat /pineapple/modules/DNSspoof/log/".$this->request['file'], $output);
 
         if (!empty($output)) {
-            $this->response = array("output" => implode("\n", $output), "date" => $log_date);
+            $this->responseHandler->setData(array("output" => implode("\n", $output), "date" => $log_date));
         } else {
-            $this->response = array("output" => "Empty log...", "date" => $log_date);
+            $this->responseHandler->setData(array("output" => "Empty log...", "date" => $log_date));
         }
     }
 
-    private function deleteHistory()
+    public function deleteHistory()
     {
-        exec("rm -rf /pineapple/modules/DNSspoof/log/".$this->request->file);
+        exec("rm -rf /pineapple/modules/DNSspoof/log/".$this->request['file']);
     }
 
-    private function downloadHistory()
+    public function downloadHistory()
     {
-        $this->response = array("download" => $this->downloadFile("/pineapple/modules/DNSspoof/log/".$this->request->file));
+        $this->responseHandler->setData(array("download" => $this->systemHelper->downloadFile("/pineapple/modules/DNSspoof/log/".$this->request['file'])));
     }
 
-    private function saveAutostartSettings()
+    public function saveAutostartSettings()
     {
-        $settings = $this->request->settings;
-        $this->uciSet("dnsspoof.autostart.interface", $settings->interface);
+        $settings = $this->request['settings'];
+        $this->systemHelper->uciSet("dnsspoof.autostart.interface", $settings->interface);
     }
 
-    private function saveLandingPageData()
+    public function saveLandingPageData()
     {
         $filename = '/www/index.php';
-        file_put_contents($filename, $this->request->configurationData);
+        file_put_contents($filename, $this->request['configurationData']);
     }
 
-    private function getLandingPageData()
+    public function getLandingPageData()
     {
         $configurationData = file_get_contents('/www/index.php');
-        $this->response = array("configurationData" => $configurationData);
+        $this->responseHandler->setData(array("configurationData" => $configurationData));
     }
 
-    private function saveHostsData()
+    public function saveHostsData()
     {
         $filename = '/etc/pineapple/spoofhost';
-        file_put_contents($filename, $this->request->configurationData);
+        file_put_contents($filename, $this->request['configurationData']);
     }
 
-    private function getHostsData()
+    public function getHostsData()
     {
         $configurationData = file_get_contents('/etc/pineapple/spoofhost');
-        $this->response = array("configurationData" => $configurationData);
+        $this->responseHandler->setData(array("configurationData" => $configurationData));
     }
 }

+ 13 - 25
modules/src/DWall/api/module.php

@@ -1,44 +1,32 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class DWall extends Module
+/* Code modified by Frieren Auto Refactor */
+class DWall extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'enable':
-                $this->enable();
-                break;
-            case 'disable':
-                $this->disable();
-                break;
-            case 'getStatus':
-                $this->getStatus();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['enable', 'disable', 'getStatus'];
 
-    private function enable()
+    public function enable()
     {
         $this->disable();
 
-        $this->execBackground("python /pineapple/modules/DWall/assets/DWall.py");
-        $this->execBackground("/usr/sbin/http_sniffer br-lan");
-        $this->response = array("success" => true);
+        $this->systemHelper->execBackground("python /pineapple/modules/DWall/assets/DWall.py");
+        $this->systemHelper->execBackground("/usr/sbin/http_sniffer br-lan");
+        $this->responseHandler->setData(array("success" => true));
     }
 
-    private function disable()
+    public function disable()
     {
         exec("killall http_sniffer");
         exec("kill \$(ps -aux | grep DWall | head -n1 | awk '{print $2}')");
-        $this->response = array("success" => true);
+        $this->responseHandler->setData(array("success" => true));
     }
 
-    private function getStatus()
+    public function getStatus()
     {
         if (trim(exec("ps -aux | grep [D]Wall.py")) != "" && trim(exec("ps -aux | grep [h]ttp_sniffer")) != "") {
-            $this->response = array("running" => true);
+            $this->responseHandler->setData(array("running" => true));
         } else {
-            $this->response = array("running" => false);
+            $this->responseHandler->setData(array("running" => false));
         }
     }
 }

+ 56 - 102
modules/src/Deauth/api/module.php

@@ -1,61 +1,15 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
+/* Code modified by Frieren Auto Refactor */
 //putenv('LD_LIBRARY_PATH='.getenv('LD_LIBRARY_PATH').':/sd/lib:/sd/usr/lib');
 //putenv('PATH='.getenv('PATH').':/sd/usr/bin:/sd/usr/sbin');
-
-class Deauth extends Module
+class Deauth extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'refreshInfo':
-                $this->refreshInfo();
-                break;
-            case 'refreshOutput':
-                $this->refreshOutput();
-                break;
-            case 'refreshStatus':
-                $this->refreshStatus();
-                break;
-            case 'togglemdk3':
-                $this->togglemdk3();
-                break;
-            case 'handleDependencies':
-                $this->handleDependencies();
-                break;
-            case 'handleDependenciesStatus':
-                $this->handleDependenciesStatus();
-                break;
-            case 'getInterfaces':
-                $this->getInterfaces();
-                break;
-            case 'scanForNetworks':
-                $this->scanForNetworks();
-                break;
-            case 'getSettings':
-                $this->getSettings();
-                break;
-            case 'setSettings':
-                $this->setSettings();
-                break;
-            case 'saveAutostartSettings':
-                $this->saveAutostartSettings();
-                break;
-            case 'togglemdk3OnBoot':
-                $this->togglemdk3OnBoot();
-                break;
-            case 'getListsData':
-                $this->getListsData();
-                break;
-            case 'saveListsData':
-                $this->saveListsData();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['refreshInfo', 'refreshOutput', 'refreshStatus', 'togglemdk3', 'handleDependencies', 'handleDependenciesStatus', 'getInterfaces', 'scanForNetworks', 'getSettings', 'setSettings', 'saveAutostartSettings', 'togglemdk3OnBoot', 'getListsData', 'saveListsData'];
 
     protected function checkDep($dependencyName)
     {
-        return ($this->checkDependency($dependencyName) && ($this->uciGet("deauth.module.installed")));
+        return ($this->systemHelper->checkDependency($dependencyName) && ($this->systemHelper->uciGet("deauth.module.installed")));
     }
 
     protected function getDevice()
@@ -66,21 +20,21 @@ class Deauth extends Module
     protected function refreshInfo()
     {
         $moduleInfo = @json_decode(file_get_contents("/pineapple/modules/Deauth/module.info"));
-        $this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
+        $this->responseHandler->setData(array('title' => $moduleInfo->title, 'version' => $moduleInfo->version));
     }
 
-    private function handleDependencies()
+    public function handleDependencies()
     {
         if (!$this->checkDep("mdk3")) {
-            $this->execBackground("/pineapple/modules/Deauth/scripts/dependencies.sh install ".$this->request->destination);
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/Deauth/scripts/dependencies.sh install ".$this->request['destination']);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->execBackground("/pineapple/modules/Deauth/scripts/dependencies.sh remove");
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/Deauth/scripts/dependencies.sh remove");
+            $this->responseHandler->setData(array('success' => true));
         }
     }
 
-    private function togglemdk3OnBoot()
+    public function togglemdk3OnBoot()
     {
         if (exec("cat /etc/rc.local | grep Deauth/scripts/autostart_deauth.sh") == "") {
             exec("sed -i '/exit 0/d' /etc/rc.local");
@@ -91,29 +45,29 @@ class Deauth extends Module
         }
     }
 
-    private function handleDependenciesStatus()
+    public function handleDependenciesStatus()
     {
         if (!file_exists('/tmp/Deauth.progress')) {
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function togglemdk3()
+    public function togglemdk3()
     {
-        if (!$this->checkRunning("mdk3")) {
-            $this->uciSet("deauth.run.interface", $this->request->interface);
+        if (!$this->systemHelper->checkRunning("mdk3")) {
+            $this->systemHelper->uciSet("deauth.run.interface", $this->request['interface']);
 
-            $this->execBackground("/pineapple/modules/Deauth/scripts/deauth.sh start");
+            $this->systemHelper->execBackground("/pineapple/modules/Deauth/scripts/deauth.sh start");
         } else {
-            $this->uciSet("deauth.run.interface", '');
+            $this->systemHelper->uciSet("deauth.run.interface", '');
 
-            $this->execBackground("/pineapple/modules/Deauth/scripts/deauth.sh stop");
+            $this->systemHelper->execBackground("/pineapple/modules/Deauth/scripts/deauth.sh stop");
         }
     }
 
-    private function refreshStatus()
+    public function refreshStatus()
     {
         if (!file_exists('/tmp/Deauth.progress')) {
             if (!$this->checkDep("mdk3")) {
@@ -133,7 +87,7 @@ class Deauth extends Module
                 $installLabel = "success";
                 $processing = false;
 
-                if ($this->checkRunning("mdk3")) {
+                if ($this->systemHelper->checkRunning("mdk3")) {
                     $status = "Stop";
                     $statusLabel = "danger";
                 } else {
@@ -162,40 +116,40 @@ class Deauth extends Module
             $bootLabelOFF = "danger";
         }
 
-        $device = $this->getDevice();
-        $sdAvailable = $this->isSDAvailable();
+        $device = $this->systemHelper->getDevice();
+        $sdAvailable = $this->systemHelper->isSDAvailable();
 
-        $this->response = array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "bootLabelON" => $bootLabelON, "bootLabelOFF" => $bootLabelOFF, "processing" => $processing);
+        $this->responseHandler->setData(array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "bootLabelON" => $bootLabelON, "bootLabelOFF" => $bootLabelOFF, "processing" => $processing));
     }
 
-    private function refreshOutput()
+    public function refreshOutput()
     {
-        if ($this->checkDependency("mdk3")) {
-            if ($this->checkRunning("mdk3")) {
+        if ($this->systemHelper->checkDependency("mdk3")) {
+            if ($this->systemHelper->checkRunning("mdk3")) {
                 exec("cat /tmp/deauth.log", $output);
                 if (!empty($output)) {
-                    $this->response = implode("\n", array_reverse($output));
+                    $this->responseHandler->setData(implode("\n", array_reverse($output)));
                 } else {
-                    $this->response = "Empty log...";
+                    $this->responseHandler->setData("Empty log...");
                 }
             } else {
-                $this->response = "Deauth is not running...";
+                $this->responseHandler->setData("Deauth is not running...");
             }
         } else {
-            $this->response = "mdk3 is not installed...";
+            $this->responseHandler->setData("mdk3 is not installed...");
         }
     }
 
-    private function getInterfaces()
+    public function getInterfaces()
     {
         exec("iwconfig 2> /dev/null | grep \"wlan*\" | awk '{print $1}'", $interfaceArray);
 
-        $this->response = array("interfaces" => $interfaceArray, "selected" => $this->uciGet("deauth.run.interface"));
+        $this->responseHandler->setData(array("interfaces" => $interfaceArray, "selected" => $this->systemHelper->uciGet("deauth.run.interface")));
     }
 
-    private function scanForNetworks()
+    public function scanForNetworks()
     {
-        $interface = escapeshellarg($this->request->interface);
+        $interface = escapeshellarg($this->request['interface']);
         if (substr($interface, -4, -1) === "mon") {
             if ($interface == "'wlan1mon'") {
                 exec("killall pineap");
@@ -235,46 +189,46 @@ class Deauth extends Module
                 array_push($returnArray, $accessPoint);
             }
         }
-        $this->response = $returnArray;
+        $this->responseHandler->setData($returnArray);
     }
 
-    private function getSettings()
+    public function getSettings()
     {
         $settings = array(
-                    'speed' => $this->uciGet("deauth.settings.speed"),
-                    'channels' => $this->uciGet("deauth.settings.channels"),
-                    'mode' => $this->uciGet("deauth.settings.mode")
+                    'speed' => $this->systemHelper->uciGet("deauth.settings.speed"),
+                    'channels' => $this->systemHelper->uciGet("deauth.settings.channels"),
+                    'mode' => $this->systemHelper->uciGet("deauth.settings.mode")
                     );
-        $this->response = array('settings' => $settings);
+        $this->responseHandler->setData(array('settings' => $settings));
     }
 
-    private function setSettings()
+    public function setSettings()
     {
-        $settings = $this->request->settings;
-        $this->uciSet("deauth.settings.speed", $settings->speed);
-        $this->uciSet("deauth.settings.channels", $settings->channels);
-        $this->uciSet("deauth.settings.mode", $settings->mode);
+        $settings = $this->request['settings'];
+        $this->systemHelper->uciSet("deauth.settings.speed", $settings->speed);
+        $this->systemHelper->uciSet("deauth.settings.channels", $settings->channels);
+        $this->systemHelper->uciSet("deauth.settings.mode", $settings->mode);
     }
 
-    private function saveAutostartSettings()
+    public function saveAutostartSettings()
     {
-        $settings = $this->request->settings;
-        $this->uciSet("deauth.autostart.interface", $settings->interface);
+        $settings = $this->request['settings'];
+        $this->systemHelper->uciSet("deauth.autostart.interface", $settings->interface);
     }
 
-    private function getListsData()
+    public function getListsData()
     {
         $blacklistData = file_get_contents('/pineapple/modules/Deauth/lists/blacklist.lst');
         $whitelistData = file_get_contents('/pineapple/modules/Deauth/lists/whitelist.lst');
-        $this->response = array("blacklistData" => $blacklistData, "whitelistData" => $whitelistData );
+        $this->responseHandler->setData(array("blacklistData" => $blacklistData, "whitelistData" => $whitelistData ));
     }
 
-    private function saveListsData()
+    public function saveListsData()
     {
         $filename = '/pineapple/modules/Deauth/lists/blacklist.lst';
-        file_put_contents($filename, $this->request->blacklistData);
+        file_put_contents($filename, $this->request['blacklistData']);
 
         $filename = '/pineapple/modules/Deauth/lists/whitelist.lst';
-        file_put_contents($filename, $this->request->whitelistData);
+        file_put_contents($filename, $this->request['whitelistData']);
     }
 }

+ 34 - 117
modules/src/EvilPortal/api/module.php

@@ -1,109 +1,26 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class EvilPortal extends Module
+/* Code modified by Frieren Auto Refactor */
+class EvilPortal extends Controller
 {
 
+    protected $endpointRoutes = ['status', 'writeFileContent', 'deletePortal', 'deleteDirectory', 'deleteFile', 'getDirectoryContent', 'getFileContent', 'download', 'listAvailablePortals', 'createNewPortal', 'movePortal', 'activatePortal', 'deactivatePortal', 'getRules', 'saveRules', 'toggleOnBoot', 'toggleCaptivePortal', 'removeClientFromList', 'authorizeClient'];
     // CONSTANTS
     private $CLIENTS_FILE = '/tmp/EVILPORTAL_CLIENTS.txt';
     private $ALLOWED_FILE = '/pineapple/modules/EvilPortal/data/allowed.txt';
     private $STORAGE_LOCATIONS = array("sd" => "/sd/portals/", "internal" => "/root/portals/");
     private $BASE_EP_COMMAND = 'module EvilPortal';
-    // CONSTANTS
-
-    /**
-     * An implementation of the route method from Module.
-     * This method routes the request to the method that handles it.
-     */
-    public function route()
-    {
-        $this->createPortalFolders();  // if the portal folders (/root/portals | /sd/portals) do not exist create them.
-
-        switch ($this->request->action) {
-
-            case 'status':
-                $this->response = array(
-                    "running" => $this->checkEvilPortalRunning(),
-                    "startOnBoot" => $this->checkAutoStart(),
-                    "sdAvailable" => $this->isSDAvailable()
-                );
-                break;
-
-            case 'writeFileContent':
-                $this->response = $this->writeFileContents($this->request->filePath, $this->request->content, $this->request->append);
-                break;
-
-            case 'deletePortal':
-            case 'deleteDirectory':
-            case 'deleteFile':
-                $this->response = $this->deleteFileOrDirectory($this->request->filePath);
-                break;
-
-            case 'getDirectoryContent':
-            case 'getFileContent':
-                $this->response =  $this->getFileOrDirectoryContents($this->request->filePath);
-                break;
-
-            case 'download':
-                $this->response = $this->download($this->request->filePath);
-                break;
-
-            case 'listAvailablePortals':
-                $this->response = $this->getListOfPortals();
-                break;
-
-            case 'createNewPortal':
-                $this->response = $this->createNewPortal($this->request->name, $this->request->type, $this->request->storage);
-                break;
-
-            case 'movePortal':
-                $this->response = $this->movePortal($this->request->name, $this->request->storage);
-                break;
-
-            case 'activatePortal':
-                $this->response = $this->activatePortal($this->request->name, $this->request->storage);
-                break;
-
-            case 'deactivatePortal':
-                $this->response = $this->deactivatePortal($this->request->name, $this->request->storage);
-                break;
-
-            case 'getRules':
-                $this->response = $this->getPortalRules($this->request->name, $this->request->storage);
-                break;
-
-            case 'saveRules':
-                $this->response = $this->savePortalRules($this->request->name, $this->request->storage, $this->request->rules);
-                break;
-
-            case 'toggleOnBoot':
-                $this->response = $this->autoStartEvilPortal();
-                break;
-
-            case 'toggleCaptivePortal':
-                $this->response = $this->toggleCaptivePortal();
-                break;
-
-            case 'removeClientFromList':
-                $this->response = $this->removeFromList($this->request->clientIP, $this->request->listName);
-                break;
-
-            case 'authorizeClient':
-                $this->authorizeClient($this->request->clientIP);
-                $this->response = array("success" => true);
-                break;
-        }
-    }
 
     /**
      * Create the folders that portals are stored in if they don't exist
      */
-    private function createPortalFolders()
+    public function createPortalFolders()
     {
         if (!is_dir($this->STORAGE_LOCATIONS["internal"])) {
             mkdir($this->STORAGE_LOCATIONS["internal"]);
         }
 
-        if (!is_dir($this->STORAGE_LOCATIONS["sd"]) and $this->isSDAvailable()) {
+        if (!is_dir($this->STORAGE_LOCATIONS["sd"]) and $this->systemHelper->isSDAvailable()) {
             mkdir($this->STORAGE_LOCATIONS["sd"]);
         }
     }
@@ -114,7 +31,7 @@ class EvilPortal extends Module
      * @param $file: The name of the file
      * @return bool: Is the file deletable or not
      */
-    private function isFileDeletable($file)
+    public function isFileDeletable($file)
     {
         if (substr($file, -strlen(".ep")) == ".ep")
             return false;
@@ -130,7 +47,7 @@ class EvilPortal extends Module
      * @param $file : The file or directory to get contents of
      * @return array
      */
-    private function getFileOrDirectoryContents($file)
+    public function getFileOrDirectoryContents($file)
     {
 
         if (!file_exists($file)) {
@@ -177,7 +94,7 @@ class EvilPortal extends Module
      * @param $append : Should the data be appended to the end of the file (true) or over-write the file (false)
      * @return array
      */
-    private function writeFileContents($file, $content, $append)
+    public function writeFileContents($file, $content, $append)
     {
         if ($append)
             file_put_contents($file, $content, FILE_APPEND);
@@ -192,7 +109,7 @@ class EvilPortal extends Module
      * @param $filePath
      * @return array
      */
-    private function deleteFileOrDirectory($filePath)
+    public function deleteFileOrDirectory($filePath)
     {
         if ($this->isFileDeletable(basename($filePath))) {
             exec(escapeshellcmd("rm -rf {$filePath}"));
@@ -211,10 +128,10 @@ class EvilPortal extends Module
      * @param: The path to the file to download
      * @return array : array
      */
-    private function download($filePath)
+    public function download($filePath)
     {
         if (file_exists($filePath)) {
-            return array("success" => true, "message" => null, "download" => $this->downloadFile($filePath));
+            return array("success" => true, "message" => null, "download" => $this->systemHelper->downloadFile($filePath));
         } else {
             return array("success" => false, "message" => "File does not exist", "download" => null);
         }
@@ -223,7 +140,7 @@ class EvilPortal extends Module
     /**
      * Get a list of portals found on internal and sd storage.
      */
-    private function getListOfPortals()
+    public function getListOfPortals()
     {
 
         // an array of all of the portals found
@@ -231,7 +148,7 @@ class EvilPortal extends Module
         $availableMediums = array("internal");
 
         // if the sd card is available add it to the availableMediums
-        if ($this->isSDAvailable()) {
+        if ($this->systemHelper->isSDAvailable()) {
             array_push($availableMediums, "sd");
         }
 
@@ -264,7 +181,7 @@ class EvilPortal extends Module
      * @param $storage : The storage medium to save the portal to (sd or internal)
      * @return array
      */
-    private function createNewPortal($name, $type, $storage)
+    public function createNewPortal($name, $type, $storage)
     {
         // force the name of the portal to be lower cased and replace spaces with underscores
         $name = strtolower(str_replace(' ', '_', $name));
@@ -277,12 +194,12 @@ class EvilPortal extends Module
 
         // verify that no portal with the same name already exists
         if (file_exists("{$this->STORAGE_LOCATIONS["internal"]}{$name}") or
-            (file_exists("{$this->STORAGE_LOCATIONS["sd"]}{$name}") and $this->isSDAvailable())) {
+            (file_exists("{$this->STORAGE_LOCATIONS["sd"]}{$name}") and $this->systemHelper->isSDAvailable())) {
             return array("success" => false, "message" => "A portal named {$name} already exists!");
         }
 
         // if the portal is supposed to be stored on the SD card, make sure that it is indeed available first.
-        if ($storage == "sd" and !$this->isSDAvailable()) {
+        if ($storage == "sd" and !$this->systemHelper->isSDAvailable()) {
             return array("success" => false, "message" => "There is no SD card available!");
         }
 
@@ -323,7 +240,7 @@ class EvilPortal extends Module
      * @param $storage : The current storage medium
      * @return array
      */
-    private function movePortal($name, $storage)
+    public function movePortal($name, $storage)
     {
         $storage = ($storage == "internal" || $storage == "sd") ? $storage : "internal";
         $newMedium = ($storage == "internal") ? "sd" : "internal";
@@ -335,7 +252,7 @@ class EvilPortal extends Module
         } else
 
         // make sure that an SD card is inserted if it is going to be needed
-        if (($storage == "sd" || $newMedium == "sd") && !$this->isSDAvailable()) {
+        if (($storage == "sd" || $newMedium == "sd") && !$this->systemHelper->isSDAvailable()) {
             return array("success" => false, "message" => "Please insert a SD card to preform this action.");
         }
 
@@ -374,7 +291,7 @@ class EvilPortal extends Module
      * @param $storage: The storage medium the portal is on
      * @return array
      */
-    private function activatePortal($name, $storage)
+    public function activatePortal($name, $storage)
     {
         $dir = $this->STORAGE_LOCATIONS[$storage];
 
@@ -421,7 +338,7 @@ class EvilPortal extends Module
      * @param $storage: The storage medium the portal is on
      * @return array
      */
-    private function deactivatePortal($name, $storage)
+    public function deactivatePortal($name, $storage)
     {
         $storage = ($storage == "internal" || $storage == "sd") ? $storage : "internal";
         $dir = $this->STORAGE_LOCATIONS[$storage];
@@ -461,7 +378,7 @@ class EvilPortal extends Module
      * @param $storage: The storage medium of the portal
      * @return array
      */
-    private function getPortalRules($name, $storage)
+    public function getPortalRules($name, $storage)
     {
         $storage = ($storage == "internal" || $storage == "sd") ? $storage : "internal";
         $path = $this->STORAGE_LOCATIONS[$storage];
@@ -487,7 +404,7 @@ class EvilPortal extends Module
      * @param $rules : The rules to save
      * @return array
      */
-    private function savePortalRules($name, $storage, $rules)
+    public function savePortalRules($name, $storage, $rules)
     {
         $storage = ($storage == "internal" || $storage == "sd") ? $storage : "internal";
         $path = $this->STORAGE_LOCATIONS[$storage];
@@ -508,7 +425,7 @@ class EvilPortal extends Module
      * Check if Evil Portal is currently running or not be checking iptables.
      * @return bool
      */
-    private function checkEvilPortalRunning()
+    public function checkEvilPortalRunning()
     {
         return exec("iptables -t nat -L PREROUTING | grep 172.16.42.1") != '';
     }
@@ -526,7 +443,7 @@ class EvilPortal extends Module
      * Grant a client access to the internet and stop blocking them with the captive portal
      * @param $client: The IP address of the client to authorize
      */
-    private function authorizeClient($client)
+    public function authorizeClient($client)
     {
         exec("iptables -t nat -I PREROUTING -s {$client} -j ACCEPT");
 //        exec("{$this->BASE_EP_COMMAND} add {$client}");
@@ -537,7 +454,7 @@ class EvilPortal extends Module
      * Revoke a clients access to the internet and start blocking them with the captive portal
      * @param $client: The IP address of the client to revoke
      */
-    private function revokeClient($client)
+    public function revokeClient($client)
     {
 //        exec("{$this->BASE_EP_COMMAND} remove {$client}");
         exec("iptables -t nat -D PREROUTING -s {$client}");
@@ -551,7 +468,7 @@ class EvilPortal extends Module
      *
      * @return array
      */
-    private function startEvilPortal()
+    public function startEvilPortal()
     {
         // Delete client tracking file if it exists
         if (file_exists($this->CLIENTS_FILE)) {
@@ -601,7 +518,7 @@ class EvilPortal extends Module
      * Stop the captive portal portion of Evil Portal from running
      * @return mixed
      */
-    private function stopEvilPortal()
+    public function stopEvilPortal()
     {
         if (file_exists($this->CLIENTS_FILE)) {
             $lines = file($this->CLIENTS_FILE);
@@ -627,7 +544,7 @@ class EvilPortal extends Module
     /**
      * If Evil Portal is running then stop it, otherwise start it.
      */
-    private function toggleCaptivePortal() {
+    public function toggleCaptivePortal() {
         // Make the file executable. In the future the `module` command should do this for us.
         chmod("/pineapple/modules/EvilPortal/executable/executable", 0755);
 
@@ -643,7 +560,7 @@ class EvilPortal extends Module
      *
      * @return array
      */
-    private function autoStartEvilPortal()
+    public function autoStartEvilPortal()
     {
         // if EvilPortal is not set to start on startup then set that shit
         if (!$this->checkAutoStart()) {
@@ -675,7 +592,7 @@ class EvilPortal extends Module
      * @param $listName: The name of the list to remove the client from
      * @return array
      */
-    private function removeFromList($clientIP, $listName)
+    public function removeFromList($clientIP, $listName)
     {
         $valid = preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/', $clientIP);
 
@@ -714,7 +631,7 @@ class EvilPortal extends Module
      * @param $keyValueArray: The data to add to the file
      * @param $file: The file to write the content to.
      */
-    private function updateJSONFile($keyValueArray, $file) {
+    public function updateJSONFile($keyValueArray, $file) {
         $data = json_decode(file_get_contents($file), true);
         foreach ($data as $key => $value) {
             if (isset($keyValueArray[$key])) {
@@ -730,7 +647,7 @@ class EvilPortal extends Module
      * @param $file: The file to that contains the JSON data.
      * @return array
      */
-    private function getValueFromJSONFile($keys, $file) {
+    public function getValueFromJSONFile($keys, $file) {
         $data = json_decode(file_get_contents($file), true);
         $values = array();
         foreach ($data as $key => $value) {
@@ -746,7 +663,7 @@ class EvilPortal extends Module
      * @param $file: The file to get size of
      * @return string: File size plus unit. Exp: 3.14M
      */
-    private function readableFileSize($file) {
+    public function readableFileSize($file) {
         $size = filesize($file);
 
         if ($size == null)

+ 1 - 0
modules/src/EvilPortal/includes/api/API.php

@@ -1,5 +1,6 @@
 <?php namespace evilportal;
 
+/* Code modified by Frieren Auto Refactor */
 class API
 {
     private $request;

+ 4 - 3
modules/src/EvilPortal/includes/api/Portal.php

@@ -1,5 +1,6 @@
 <?php namespace evilportal;
 
+/* Code modified by Frieren Auto Refactor */
 abstract class Portal
 {
     protected $request;
@@ -40,7 +41,7 @@ abstract class Portal
      */
     protected final function notify($message)
     {
-        $this->execBackground("notify {$message}");
+        $this->systemHelper->execBackground("notify {$message}");
     }
 
     /**
@@ -83,7 +84,7 @@ abstract class Portal
      */
     protected function handleAuthorization()
     {
-        if (isset($this->request->target)) {
+        if (isset($this->request['target'])) {
             $this->authorizeClient($_SERVER['REMOTE_ADDR']);
             $this->onSuccess();
             $this->redirect();
@@ -99,7 +100,7 @@ abstract class Portal
      */
     protected function redirect()
     {
-        header("Location: {$this->request->target}", true, 302);
+        header("Location: {$this->request['target']}", true, 302);
     }
 
     /**

+ 2 - 0
modules/src/EvilPortal/includes/api/index.php

@@ -1,5 +1,7 @@
 <?php namespace evilportal;
 
+/* Code modified by Frieren Auto Refactor */
+
 header('Content-Type: application/json');
 
 require_once("API.php");

+ 1 - 0
modules/src/EvilPortal/includes/skeleton/MyPortal.php

@@ -1,5 +1,6 @@
 <?php namespace evilportal;
 
+/* Code modified by Frieren Auto Refactor */
 class MyPortal extends Portal
 {
 

+ 1 - 0
modules/src/EvilPortal/includes/targeted_skeleton/MyPortal.php

@@ -1,5 +1,6 @@
 <?php namespace evilportal;
 
+/* Code modified by Frieren Auto Refactor */
 class MyPortal extends Portal
 {
 

+ 28 - 82
modules/src/HTTPProxy/api/module.php

@@ -1,68 +1,11 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class HTTPProxy extends Module
+/* Code modified by Frieren Auto Refactor */
+class HTTPProxy extends Controller
 {
 
 
-    // CONSTANTS
-
-    public function route()
-    {
-
-        switch ($this->request->action) {
-
-            case 'Start':
-            $this->start();
-            break;
-
-            case 'Stop':
-            $this->stop();
-            break;
-
-            case 'save':
-            $this->saveHTML($this->request->htmlvalue);
-            break;
-
-            case 'getHtml':
-            $this->GetHtml();
-            break;
-
-            case 'viewResponsePage':
-            $this->viewResponsePage();
-            break;
-
-            case 'updateResponsePage':
-            $this->updateResponsePage($this->request->phpCode);
-            break;
-
-            case 'viewLog':
-            $this->viewLog();
-            break;
-
-            case 'enableKeyLogger':
-            $this->enableKeyLogger();
-            break;
-
-            case 'disableKeyLogger':
-            $this->disableKeyLogger();
-            break;
-
-            case 'viewKeyLoggerLog':
-            $this->viewKeyLoggerLog();
-            break;
-
-            case 'viewHTTPProxyHandler':
-            $this->viewHTTPProxyHandler();
-            break;
-
-            case 'updateHTTPProxyHandlerPage':
-            $this->updateHTTPProxyHandlerPage($this->request->HTTPProxyHandlerCode);
-            break;
-
-
-        }
-    }
-
+    protected $endpointRoutes = ['start', 'stop', 'save', 'getHtml', 'viewResponsePage', 'updateResponsePage', 'viewLog', 'enableKeyLogger', 'disableKeyLogger', 'viewKeyLoggerLog', 'viewHTTPProxyHandler', 'updateHTTPProxyHandlerPage'];
 
 
 
@@ -91,7 +34,7 @@ class HTTPProxy extends Module
 
         }
 
-            $this->response = $message ;
+            $this->responseHandler->setData($message) ;
      }
 
          public function stop(){
@@ -116,10 +59,13 @@ class HTTPProxy extends Module
                 "control_message" => $message
             );*/
 
-              $this->response = $message ;
+              $this->responseHandler->setData($message) ;
 
          }
 
+    public function save($html){
+        $this->saveHTML($this->request['htmlvalue']);
+    }
 
         public function saveHTML($html){
 
@@ -129,10 +75,10 @@ class HTTPProxy extends Module
         if($out>0){
 
 
-         $this->response = "Saved!";
+         $this->responseHandler->setData("Saved!");
         }
         else{
-         $this->response = "Error.Not Saved!";
+         $this->responseHandler->setData("Error.Not Saved!");
         }
 
         }
@@ -178,27 +124,27 @@ class HTTPProxy extends Module
     {
         $htmlFile = fopen("/pineapple/modules/HTTPProxy/assets/HTML/htmlFile.txt", "r") ;
         $HTTPProxy=fread($htmlFile,10000);
-        $this->response = $HTTPProxy;
+        $this->responseHandler->setData($HTTPProxy);
       }
 
      public function viewResponsePage(){
 
        $phpCode = fopen("/pineapple/modules/HTTPProxy/assets/response/responsePage.php", "r") ;
        $phpCode=fread($phpCode,10000);
-       $this->response = $phpCode;
+       $this->responseHandler->setData($phpCode);
 
       }
 
-      public function updateResponsePage($phpCode){
+      public function updateResponsePage(){
 
        $phpFile = fopen("/pineapple/modules/HTTPProxy/assets/response/responsePage.php", "w") ;
-       $out=fwrite($phpFile, $phpCode);
+       $out=fwrite($phpFile, $this->request['phpCode']);
        fclose($phpFile);
         if($out>0){
-        $this->response = "Saved!";
+        $this->responseHandler->setData("Saved!");
         }
         else{
-         $this->response = "Error.Not Saved!";
+         $this->responseHandler->setData("Error.Not Saved!");
         }
 
 
@@ -209,10 +155,10 @@ class HTTPProxy extends Module
         $logFile = fopen("/pineapple/modules/HTTPProxy/assets/logFile.txt", "r") ;
         $logFile=fread($logFile,10000);
         if($logFile!=""){
-         $this->response = $logFile;
+         $this->responseHandler->setData($logFile);
          }
          else{
-             $this->response="Empty Logs!";
+             $this->responseHandler->setData("Empty Logs!");
          }
 
       }
@@ -240,7 +186,7 @@ class HTTPProxy extends Module
         ";
 
         $this->saveHTML($keyLoggerJavaScript);
-         $this->response =$keyLoggerJavaScript;
+         $this->responseHandler->setData($keyLoggerJavaScript);
 
       }
 
@@ -272,7 +218,7 @@ class HTTPProxy extends Module
         ";
 
         $this->saveHTML($normalHTML);
-        $this->response =$normalHTML;
+        $this->responseHandler->setData($normalHTML);
 
 
 }
@@ -284,10 +230,10 @@ class HTTPProxy extends Module
           $logFile=fread($logFile,1000);
 
             if($logFile!=""){
-         $this->response = $logFile;
+         $this->responseHandler->setData($logFile);
          }
          else{
-             $this->response="Empty Logs!";
+             $this->responseHandler->setData("Empty Logs!");
          }
 
 
@@ -314,23 +260,23 @@ class HTTPProxy extends Module
 
            $viewHTTPProxyHandlerCode = fopen("/pineapple/modules/HTTPProxy/assets/index/index.php", "r") ;
            $viewHTTPProxyHandlerCode=fread($viewHTTPProxyHandlerCode,10000);
-           $this->response = $viewHTTPProxyHandlerCode;
+           $this->responseHandler->setData($viewHTTPProxyHandlerCode);
           }
 
 
 
-       public function updateHTTPProxyHandlerPage($HTTPProxyHandlerCode){
+       public function updateHTTPProxyHandlerPage(){
 
        $phpFile = fopen("/pineapple/modules/HTTPProxy/assets/index/index.php", "w") ;
-       $out=fwrite($phpFile, $HTTPProxyHandlerCode);
+       $out=fwrite($phpFile, $this->request['HTTPProxyHandlerCode']);
        fclose($phpFile);
         if($out>0){
-        $this->response = "Saved!";
+        $this->responseHandler->setData("Saved!");
 
         exec("cp /pineapple/modules/HTTPProxy/assets/index/index.php  /www/index.php") ;
         }
         else{
-         $this->response = "Error.Not Saved!";
+         $this->responseHandler->setData("Error.Not Saved!");
         }
 
 

+ 46 - 75
modules/src/HackRF/api/module.php

@@ -1,105 +1,76 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class HackRF extends Module
+/* Code modified by Frieren Auto Refactor */
+
+class HackRF extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'hackrfInfo':
-            $this->hackrfInfo();
-            break;
-
-            case 'hackrfInstall':
-            $this->hackrfInstall();
-            break;
-
-            case 'hackrfUninstall':
-            $this->hackrfUninstall();
-            break;
-
-            case 'hackrfChecker':
-            $this->hackrfChecker();
-            break;
-
-            case 'hackrfTransfer':
-            $this->hackrfTransfer();
-            break;
-
-            case 'hackrfStop':
-            $this->hackrfStop();
-            break;
-
-            case 'hackrfLog':
-            $this->hackrfLog();
-            break;
-        }
-    }
+    protected $endpointRoutes = ['hackrfInfo', 'hackrfInstall', 'hackrfUninstall', 'hackrfChecker', 'hackrfTransfer', 'hackrfStop', 'hackrfLog'];
 
-    private function hackrfInfo()
+    public function hackrfInfo()
     {
         exec('hackrf_info', $message);
         $message = implode("\n", $message);
 
         if ($message == "No HackRF boards found.") {
-            $this->response = array("foundBoard" => false);
-        } else if ($this->checkDependency('hackrf_info') == false) {
-            $this->response = array("foundBoard" => false);
+            $this->responseHandler->setData(array("foundBoard" => false));
+        } else if ($this->systemHelper->checkDependency('hackrf_info') == false) {
+            $this->responseHandler->setData(array("foundBoard" => false));
         } else {
-            $this->response = array("foundBoard" => true,
-                "availableHackRFs" => $message);
+            $this->responseHandler->setData(array("foundBoard" => true,
+                "availableHackRFs" => $message));
         }
     }
 
-    private function hackrfChecker()
+    public function hackrfChecker()
     {
-        if ($this->checkDependency('hackrf_info')) {
-            $this->response = array("installed" => true);
+        if ($this->systemHelper->checkDependency('hackrf_info')) {
+            $this->responseHandler->setData(array("installed" => true));
         } else {
-            $this->response = array("installed" => false);
+            $this->responseHandler->setData(array("installed" => false));
         }
     }
 
-    private function hackrfInstall()
+    public function hackrfInstall()
     {
-        if ($this->getDevice() == 'tetra') {
-            $this->execBackground('opkg update && opkg install hackrf-mini');    
+        if ($this->systemHelper->getDevice() == 'tetra') {
+            $this->systemHelper->execBackground('opkg update && opkg install hackrf-mini');    
         } else {
-            $this->execBackground('opkg update && opkg install hackrf-mini --dest sd');
+            $this->systemHelper->execBackground('opkg update && opkg install hackrf-mini --dest sd');
         }
         exec('echo "Welcome to HackRF!" > /tmp/hackrf_log');
 
-        $this->response = array("installing" => true);
+        $this->responseHandler->setData(array("installing" => true));
     }
 
-    private function hackrfUninstall()
+    public function hackrfUninstall()
     {
         exec('opkg remove hackrf-mini');
         unlink('/tmp/hackrf_log');
-        $this->response = array("success" => true);
+        $this->responseHandler->setData(array("success" => true));
     }
 
-    private function hackrfTransfer()
+    public function hackrfTransfer()
     {
-        $mode         = $this->request->mode;
-        $sampleRate   = $this->request->sampleRate;
-        $centerFreq   = $this->request->centerFreq;
-        $filename     = $this->request->filename;
-        $amp          = $this->request->amp;
-        $antPower     = $this->request->antpower;
-        $txRepeat     = $this->request->txRepeat;
-        $txIfCheckbox = $this->request->txIfCheckbox;
-        $txIfGain     = $this->request->txIfGain;
-        $rxIfCheckbox = $this->request->rxIfCheckbox;
-        $rxBbCheckbox = $this->request->rxBbCheckbox;
-        $rxIfGain     = $this->request->rxIfGain;
-        $rxBbGain     = $this->request->rxBbGain;
+        $mode         = $this->request['mode'];
+        $sampleRate   = $this->request['sampleRate'];
+        $centerFreq   = $this->request['centerFreq'];
+        $filename     = $this->request['filename'];
+        $amp          = $this->request['amp'];
+        $antPower     = $this->request['antpower'];
+        $txRepeat     = $this->request['txRepeat'];
+        $txIfCheckbox = $this->request['txIfCheckbox'];
+        $txIfGain     = $this->request['txIfGain'];
+        $rxIfCheckbox = $this->request['rxIfCheckbox'];
+        $rxBbCheckbox = $this->request['rxBbCheckbox'];
+        $rxIfGain     = $this->request['rxIfGain'];
+        $rxBbGain     = $this->request['rxBbGain'];
 
         if(!$sampleRate) {
-            $this->response = array("success" => false, "error" => "samplerate");
+            $this->responseHandler->setData(array("success" => false, "error" => "samplerate"));
         } else if(!$centerFreq) {
-            $this->response = array("success" => false, "error" => "centerfreq");
+            $this->responseHandler->setData(array("success" => false, "error" => "centerfreq"));
         } else if(!$filename) {
-            $this->response = array("success" => false, "error" => "filename");
+            $this->responseHandler->setData(array("success" => false, "error" => "filename"));
         } else {
             if ($mode == "rx") {
                 $mode = "-r";
@@ -154,26 +125,26 @@ class HackRF extends Module
             }
 
             unlink("/tmp/hackrf_log");
-            $this->execBackground("$command > /tmp/hackrf_log 2>&1");
-            $this->response = array("success" => true);
+            $this->systemHelper->execBackground("$command > /tmp/hackrf_log 2>&1");
+            $this->responseHandler->setData(array("success" => true));
         }
     }
 
-    private function hackrfStop()
+    public function hackrfStop()
     {
         exec("killall hackrf_transfer");
 
-        $this->response = array("success" => true);
+        $this->responseHandler->setData(array("success" => true));
     }
 
-    private function hackrfLog()
+    public function hackrfLog()
     {
         $log  = '/tmp/hackrf_log';
         if(file_exists($log)) {
             $log = file_get_contents($log);
-            $this->response = array("success" => true, "log" => $log);
+            $this->responseHandler->setData(array("success" => true, "log" => $log));
         } else {
-            $this->response = array("success" => true, "log" => "Welcome to HackRF!");
+            $this->responseHandler->setData(array("success" => true, "log" => "Welcome to HackRF!"));
         }
     }
 }

+ 13 - 33
modules/src/InternetSpeedTest/api/module.php

@@ -1,42 +1,22 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
+/* Code modified by Frieren Auto Refactor */
 /*
  * Author: trashbo4t (github.com/trashbo4t)
  */
-
-class InternetSpeedTest extends Module
+class InternetSpeedTest extends Controller
 {
-	// CONSTANTS
+	protected $endpointRoutes = ['clearTests', 'clearLogFile', 'startSpeedTest', 'getSpeedTestFromFile', 'getPreviousTests'];
+ // CONSTANTS
 	private $SPEED_TEST_DIR = '/pineapple/modules/InternetSpeedTest/tests';
 	private $ALL_TESTS_FILE = '/pineapple/modules/InternetSpeedTest/tests/all';
 	private $LOG_FILE = '/pineapple/modules/InternetSpeedTest/log.txt';
-	
-	public function route()
-	{
-		switch ($this->request->action) {
-			case 'clearTests':
-				$this->clearTests();
-				break;
-			case 'clearLogFile':
-				$this->clearLogFile();
-				break;
-			case 'startSpeedTest':
-				$this->startSpeedTest();
-				break;
-			case 'getSpeedTestFromFile':
-				$this->getSpeedTestFromFile();
-				break;
-			case 'getPreviousTests':
-				$this->getPreviousTests();
-				break;
-		}
-	}
 
 	//
 	// log
 	// this function will write to the log file inside the IST directory
 	//
-	private function log($msg)
+	public function log($msg)
 	{
 		exec("echo {$msg} >> {$this->LOG_FILE}");
 	}
@@ -45,7 +25,7 @@ class InternetSpeedTest extends Module
 	// clearLogFile
 	// this function will wipe the log file inside the IST directory
 	//
-	private function clearLogFile()
+	public function clearLogFile()
 	{
 		exec("echo '' > {$this->LOG_FILE}");
 	}
@@ -80,7 +60,7 @@ class InternetSpeedTest extends Module
 	// clearTests
 	// this function will wipe all of the tests and test file inside the IST directory
 	//
-	private function clearTests()
+	public function clearTests()
 	{
 		exec("rm  {$this->ALL_TESTS_FILE}");
 		exec("rm -rf {$this->SPEED_TEST_DIR}");
@@ -134,12 +114,12 @@ class InternetSpeedTest extends Module
 	public function getSpeedTestFromFile()
 	{
 		$this->log("requesting file");
-		$this->log($this->request->file);
+		$this->log($this->request['file']);
 
 		$this->makeSpeedTestsDir();
-		$file = $this->touchSpeedTestFile($this->request->file);
+		$file = $this->touchSpeedTestFile($this->request['file']);
 		$output = $this->getSpeedTestFile($file);
-		$this->response = $output;
+		$this->responseHandler->setData($output);
 
 		$this->log($output);
 	}
@@ -165,7 +145,7 @@ class InternetSpeedTest extends Module
 	
 		$this->addToSpeedTestFile($file);
 
-		$this->response = $output;
+		$this->responseHandler->setData($output);
 	}
 	
 	//
@@ -178,7 +158,7 @@ class InternetSpeedTest extends Module
 		$this->makeSpeedTestsDir();
 		$this->touchSpeedTestFile();
 
-		$this->response = array();
+		$this->responseHandler->setData(array());
 		
 		$lines = file($this->ALL_TESTS_FILE);
 		foreach ($lines as $line) 

+ 56 - 104
modules/src/KeyManager/api/module.php

@@ -1,61 +1,13 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class KeyManager extends Module
+/* Code modified by Frieren Auto Refactor */
+class KeyManager extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'refreshInfo':
-                $this->refreshInfo();
-                break;
-            case 'refreshOutput':
-                $this->refreshOutput();
-                break;
-            case 'clearOutput':
-                $this->clearOutput();
-                break;
-            case 'refreshStatus':
-                $this->refreshStatus();
-                break;
-            case 'handleDependencies':
-                $this->handleDependencies();
-                break;
-            case 'handleDependenciesStatus':
-                $this->handleDependenciesStatus();
-                break;
-            case 'handleKey':
-                $this->handleKey();
-                break;
-            case 'handleKeyStatus':
-                $this->handleKeyStatus();
-                break;
-            case 'saveKnownHostsData':
-                $this->saveKnownHostsData();
-                break;
-            case 'getKnownHostsData':
-                $this->getKnownHostsData();
-                break;
-            case 'addToKnownHosts':
-                $this->addToKnownHosts();
-                break;
-            case 'addToKnownHostsStatus':
-                $this->addToKnownHostsStatus();
-                break;
-            case 'copyToRemoteHost':
-                $this->copyToRemoteHost();
-                break;
-            case 'copyToRemoteHostStatus':
-                $this->copyToRemoteHostStatus();
-                break;
-            case 'getSettings':
-                $this->getSettings();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['refreshInfo', 'refreshOutput', 'clearOutput', 'refreshStatus', 'handleDependencies', 'handleDependenciesStatus', 'handleKey', 'handleKeyStatus', 'saveKnownHostsData', 'getKnownHostsData', 'addToKnownHosts', 'addToKnownHostsStatus', 'copyToRemoteHost', 'copyToRemoteHostStatus', 'getSettings'];
 
     protected function checkDep($dependencyName)
     {
-        return ($this->checkDependency($dependencyName) && ($this->uciGet("keymanager.module.installed")));
+        return ($this->systemHelper->checkDependency($dependencyName) && ($this->systemHelper->uciGet("keymanager.module.installed")));
     }
 
     protected function getDevice()
@@ -66,50 +18,50 @@ class KeyManager extends Module
     protected function refreshInfo()
     {
         $moduleInfo = @json_decode(file_get_contents("/pineapple/modules/KeyManager/module.info"));
-        $this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
+        $this->responseHandler->setData(array('title' => $moduleInfo->title, 'version' => $moduleInfo->version));
     }
 
-    private function handleKey()
+    public function handleKey()
     {
         if (!file_exists("/root/.ssh/id_rsa")) {
-            $this->execBackground("/pineapple/modules/KeyManager/scripts/generate_key.sh");
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/KeyManager/scripts/generate_key.sh");
+            $this->responseHandler->setData(array('success' => true));
         } else {
             exec("rm -rf /root/.ssh/id_rsa*");
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         }
     }
 
-    private function handleKeyStatus()
+    public function handleKeyStatus()
     {
         if (!file_exists('/tmp/KeyManager_key.progress')) {
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function handleDependencies()
+    public function handleDependencies()
     {
         if (!$this->checkDep("ssh-keyscan")) {
-            $this->execBackground("/pineapple/modules/KeyManager/scripts/dependencies.sh install " . $this->request->destination);
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/KeyManager/scripts/dependencies.sh install " . $this->request['destination']);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->execBackground("/pineapple/modules/KeyManager/scripts/dependencies.sh remove");
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/KeyManager/scripts/dependencies.sh remove");
+            $this->responseHandler->setData(array('success' => true));
         }
     }
 
-    private function handleDependenciesStatus()
+    public function handleDependenciesStatus()
     {
         if (!file_exists('/tmp/KeyManager.progress')) {
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function refreshStatus()
+    public function refreshStatus()
     {
         if (!file_exists('/tmp/KeyManager.progress')) {
             if (!$this->checkDep("ssh-keyscan")) {
@@ -153,87 +105,87 @@ class KeyManager extends Module
             $generating = false;
         }
 
-        $device = $this->getDevice();
-        $sdAvailable = $this->isSDAvailable();
+        $device = $this->systemHelper->getDevice();
+        $sdAvailable = $this->systemHelper->isSDAvailable();
 
-        $this->response = array("device" => $device, "sdAvailable" => $sdAvailable, "installed" => $installed, "key" => $key, "keyLabel" => $keyLabel, "generating" => $generating, "generated" => $generated, "install" => $install, "installLabel" => $installLabel, "processing" => $processing);
+        $this->responseHandler->setData(array("device" => $device, "sdAvailable" => $sdAvailable, "installed" => $installed, "key" => $key, "keyLabel" => $keyLabel, "generating" => $generating, "generated" => $generated, "install" => $install, "installLabel" => $installLabel, "processing" => $processing));
     }
 
-    private function refreshOutput()
+    public function refreshOutput()
     {
         if (file_exists("/tmp/keymanager.log")) {
             $output = file_get_contents("/tmp/keymanager.log");
             if (!empty($output))
-                $this->response = $output;
+                $this->responseHandler->setData($output);
             else
-                $this->response = " ";
+                $this->responseHandler->setData(" ");
         } else {
-            $this->response = " ";
+            $this->responseHandler->setData(" ");
         }
     }
 
-    private function clearOutput()
+    public function clearOutput()
     {
         exec("rm -rf /tmp/keymanager.log");
     }
 
-    private function saveKnownHostsData()
+    public function saveKnownHostsData()
     {
         $filename = '/root/.ssh/known_hosts';
-        file_put_contents($filename, $this->request->knownHostsData);
+        file_put_contents($filename, $this->request['knownHostsData']);
     }
 
-    private function getKnownHostsData()
+    public function getKnownHostsData()
     {
         $knownHostsData = file_get_contents('/root/.ssh/known_hosts');
-        $this->response = array("knownHostsData" => $knownHostsData);
+        $this->responseHandler->setData(array("knownHostsData" => $knownHostsData));
     }
 
-    private function addToKnownHostsStatus()
+    public function addToKnownHostsStatus()
     {
         if (!file_exists('/tmp/KeyManager.progress')) {
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function addToKnownHosts()
+    public function addToKnownHosts()
     {
-        $this->uciSet("keymanager.settings.host", $this->request->host);
-        $this->uciSet("keymanager.settings.port", $this->request->port);
+        $this->systemHelper->uciSet("keymanager.settings.host", $this->request['host']);
+        $this->systemHelper->uciSet("keymanager.settings.port", $this->request['port']);
 
-        $this->execBackground("/pineapple/modules/KeyManager/scripts/add_host.sh");
-        $this->response = array('success' => true);
+        $this->systemHelper->execBackground("/pineapple/modules/KeyManager/scripts/add_host.sh");
+        $this->responseHandler->setData(array('success' => true));
     }
 
-    private function copyToRemoteHostStatus()
+    public function copyToRemoteHostStatus()
     {
         if (!file_exists('/tmp/KeyManager.progress')) {
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function copyToRemoteHost()
+    public function copyToRemoteHost()
     {
-        $this->uciSet("keymanager.settings.host", $this->request->host);
-        $this->uciSet("keymanager.settings.port", $this->request->port);
-        $this->uciSet("keymanager.settings.user", $this->request->user);
+        $this->systemHelper->uciSet("keymanager.settings.host", $this->request['host']);
+        $this->systemHelper->uciSet("keymanager.settings.port", $this->request['port']);
+        $this->systemHelper->uciSet("keymanager.settings.user", $this->request['user']);
 
-        $this->execBackground("/pineapple/modules/KeyManager/scripts/copy_key.sh " . $this->request->password);
-        $this->response = array('success' => true);
+        $this->systemHelper->execBackground("/pineapple/modules/KeyManager/scripts/copy_key.sh " . $this->request['password']);
+        $this->responseHandler->setData(array('success' => true));
     }
 
-    private function getSettings()
+    public function getSettings()
     {
         $settings = array(
-            'host' => $this->uciGet("keymanager.settings.host"),
-            'port' => $this->uciGet("keymanager.settings.port"),
-            'user' => $this->uciGet("keymanager.settings.user")
+            'host' => $this->systemHelper->uciGet("keymanager.settings.host"),
+            'port' => $this->systemHelper->uciGet("keymanager.settings.port"),
+            'user' => $this->systemHelper->uciGet("keymanager.settings.user")
         );
-        $this->response = $settings;
+        $this->responseHandler->setData($settings);
     }
 
 }

+ 173 - 206
modules/src/LEDController/api/module.php

@@ -1,361 +1,328 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class LEDController extends Module
+/* Code modified by Frieren Auto Refactor */
+class LEDController extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'getDeviceType':
-                $this->getDeviceType();
-                break;
-            case 'resetLEDs':
-                $this->resetLEDs();
-                break;
-            case 'getTetraYellow':
-                $this->getTetraYellow();
-                break;
-            case 'setTetraYellow':
-                $this->setTetraYellow();
-                break;
-            case 'getTetraBlue':
-                $this->getTetraBlue();
-                break;
-            case 'setTetraBlue':
-                $this->setTetraBlue();
-                break;
-            case 'getTetraRed':
-                $this->getTetraRed();
-                break;
-            case 'setTetraRed':
-                $this->setTetraRed();
-                break;
-            case 'getNanoBlue':
-                $this->getNanoBlue();
-                break;
-            case 'setNanoBlue':
-                $this->setNanoBlue();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['getDeviceType', 'resetLEDs', 'getTetraYellow', 'setTetraYellow', 'getTetraBlue', 'setTetraBlue', 'getTetraRed', 'setTetraRed', 'getNanoBlue', 'setNanoBlue'];
 
-    private function restartLEDs()
+    public function restartLEDs()
     {
         exec('/etc/init.d/led restart');
     }
 
-    private function getDeviceType()
+    public function getDeviceType()
     {
-        $device = $this->getDevice();
+        $device = $this->systemHelper->getDevice();
 
         if ($device == 'tetra') {
-            $this->response = 'tetra';
+            $this->responseHandler->setData('tetra');
         } else {
-            $this->response = 'nano';
+            $this->responseHandler->setData('nano');
         }
     }
 
-    private function getTetraYellow()
+    public function getTetraYellow()
     {
-        $trigger = $this->uciGet('system.led_eth0.trigger');
+        $trigger = $this->systemHelper->uciGet('system.led_eth0.trigger');
 
         if ($trigger == 'none') {
-            $default = $this->uciGet('system.led_eth0.default');
+            $default = $this->systemHelper->uciGet('system.led_eth0.default');
             if ($default == 0) {
-                $this->response = array('enabled' => false, 'trigger' => $trigger);
+                $this->responseHandler->setData(array('enabled' => false, 'trigger' => $trigger));
             } elseif ($default == 1) {
-                $this->response = array('enabled' => true, 'trigger' => $trigger);
+                $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger));
             }
         } elseif ($trigger == 'netdev') {
-            $mode = $this->uciGet('system.led_eth0.mode');
-            $interface = $this->uciGet('system.led_eth0.dev');
+            $mode = $this->systemHelper->uciGet('system.led_eth0.mode');
+            $interface = $this->systemHelper->uciGet('system.led_eth0.dev');
             if ($mode == 'link tx rx') {
-                $this->response = array('enabled' => true, 'trigger' => $trigger,
-                                        'mode' => 'link tx rx', 'interface' => $interface);
+                $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger,
+                                        'mode' => 'link tx rx', 'interface' => $interface));
             } elseif ($mode == 'link tx') {
-                $this->response = array('enabled' => true, 'trigger' => $trigger,
-                                        'mode' => 'link tx', 'interface' => $interface);
+                $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger,
+                                        'mode' => 'link tx', 'interface' => $interface));
             } elseif ($mode == 'link rx') {
-                $this->response = array('enabled' => true, 'trigger' => $trigger,
-                                        'mode' => 'link rx', 'interface' => $interface);
+                $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger,
+                                        'mode' => 'link rx', 'interface' => $interface));
             }
         } elseif ($trigger == 'timer') {
-            $delayOn = $this->uciGet('system.led_eth0.delayon');
-            $delayOff = $this->uciGet('system.led_eth0.delayoff');
-            $this->response = array('enabled' => true, 'trigger' => $trigger,
-                                    'delayOn' => $delayOn, 'delayOff' => $delayOff);
+            $delayOn = $this->systemHelper->uciGet('system.led_eth0.delayon');
+            $delayOff = $this->systemHelper->uciGet('system.led_eth0.delayoff');
+            $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger,
+                                    'delayOn' => $delayOn, 'delayOff' => $delayOff));
         } else {
-            $this->response = array('enabled' => true, 'trigger' => $trigger);
+            $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger));
         }
     }
 
-    private function setTetraYellow()
+    public function setTetraYellow()
     {
-        $enabled = $this->request->enabled;
-        $trigger = $this->request->trigger;
-        $mode = $this->request->mode;
-        $delayOn = $this->request->delayOn;
-        $delayOff = $this->request->delayOff;
-        $interface = $this->request->interface;
+        $enabled = $this->request['enabled'];
+        $trigger = $this->request['trigger'];
+        $mode = $this->request['mode'];
+        $delayOn = $this->request['delayOn'];
+        $delayOff = $this->request['delayOff'];
+        $interface = $this->request['interface'];
 
         if ($enabled == true) {
             if ($trigger == 'none') {
-                $this->uciSet('system.led_eth0.trigger', 'none');
-                $this->uciSet('system.led_eth0.default', '1');
+                $this->systemHelper->uciSet('system.led_eth0.trigger', 'none');
+                $this->systemHelper->uciSet('system.led_eth0.default', '1');
                 $this->restartLEDs();
             } elseif ($trigger == 'netdev') {
-                $this->uciSet('system.led_eth0.trigger', 'netdev');
-                $this->uciSet('system.led_eth0.mode', "$mode");
-                $this->uciSet('system.led_eth0.dev', "$interface");
+                $this->systemHelper->uciSet('system.led_eth0.trigger', 'netdev');
+                $this->systemHelper->uciSet('system.led_eth0.mode', "$mode");
+                $this->systemHelper->uciSet('system.led_eth0.dev', "$interface");
                 $this->restartLEDs();
             } elseif ($trigger == 'timer') {
-                $this->uciSet('system.led_eth0.trigger', 'timer');
-                $this->uciSet('system.led_eth0.delayon', "$delayOn");
-                $this->uciSet('system.led_eth0.delayoff', "$delayOff");
+                $this->systemHelper->uciSet('system.led_eth0.trigger', 'timer');
+                $this->systemHelper->uciSet('system.led_eth0.delayon', "$delayOn");
+                $this->systemHelper->uciSet('system.led_eth0.delayoff', "$delayOff");
                 $this->restartLEDs();
             }
         } elseif ($enabled == false) {
-            $this->uciSet('system.led_eth0.trigger', 'none');
-            $this->uciSet('system.led_eth0.default', '0');
+            $this->systemHelper->uciSet('system.led_eth0.trigger', 'none');
+            $this->systemHelper->uciSet('system.led_eth0.default', '0');
             $this->restartLEDs();
         }
 
-        $this->response = array('enabled' => $enabled, 'trigger' => $trigger,
+        $this->responseHandler->setData(array('enabled' => $enabled, 'trigger' => $trigger,
         'mode' => $mode, 'delayOn' => $delayOn,
-        'delayOff' => $delayOff, 'interface' => $interface, 'success' => true);
+        'delayOff' => $delayOff, 'interface' => $interface, 'success' => true));
     }
 
-    private function getTetraBlue()
+    public function getTetraBlue()
     {
-        $trigger = $this->uciGet('system.led_wlan0.trigger');
+        $trigger = $this->systemHelper->uciGet('system.led_wlan0.trigger');
 
         if ($trigger == 'none') {
-            $default = $this->uciGet('system.led_wlan0.default');
+            $default = $this->systemHelper->uciGet('system.led_wlan0.default');
             if ($default == 0) {
-                $this->response = array('enabled' => false, 'trigger' => $trigger);
+                $this->responseHandler->setData(array('enabled' => false, 'trigger' => $trigger));
             } elseif ($default == 1) {
-                $this->response = array('enabled' => true, 'trigger' => $trigger);
+                $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger));
             }
         } elseif ($trigger == 'netdev') {
-            $mode = $this->uciGet('system.led_wlan0.mode');
-            $interface = $this->uciGet('system.led_wlan0.dev');
+            $mode = $this->systemHelper->uciGet('system.led_wlan0.mode');
+            $interface = $this->systemHelper->uciGet('system.led_wlan0.dev');
             if ($mode == 'link tx rx') {
-                $this->response = array('enabled' => true, 'trigger' => $trigger,
-                                        'mode' => 'link tx rx', 'interface' => $interface);
+                $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger,
+                                        'mode' => 'link tx rx', 'interface' => $interface));
             } elseif ($mode == 'link tx') {
-                $this->response = array('enabled' => true, 'trigger' => $trigger,
-                                        'mode' => 'link tx', 'interface' => $interface);
+                $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger,
+                                        'mode' => 'link tx', 'interface' => $interface));
             } elseif ($mode == 'link rx') {
-                $this->response = array('enabled' => true, 'trigger' => $trigger,
-                                        'mode' => 'link rx', 'interface' => $interface);
+                $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger,
+                                        'mode' => 'link rx', 'interface' => $interface));
             }
         } elseif ($trigger == 'timer') {
-            $delayOn = $this->uciGet('system.led_wlan0.delayon');
-            $delayOff = $this->uciGet('system.led_wlan0.delayoff');
-            $this->response = array('enabled' => true, 'trigger' => $trigger,
-                                    'delayOn' => $delayOn, 'delayOff' => $delayOff);
+            $delayOn = $this->systemHelper->uciGet('system.led_wlan0.delayon');
+            $delayOff = $this->systemHelper->uciGet('system.led_wlan0.delayoff');
+            $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger,
+                                    'delayOn' => $delayOn, 'delayOff' => $delayOff));
         } else {
-            $this->response = array('enabled' => true, 'trigger' => $trigger);
+            $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger));
         }
     }
 
-    private function setTetraBlue()
+    public function setTetraBlue()
     {
-        $enabled = $this->request->enabled;
-        $trigger = $this->request->trigger;
-        $mode = $this->request->mode;
-        $delayOn = $this->request->delayOn;
-        $delayOff = $this->request->delayOff;
-        $interface = $this->request->interface;
+        $enabled = $this->request['enabled'];
+        $trigger = $this->request['trigger'];
+        $mode = $this->request['mode'];
+        $delayOn = $this->request['delayOn'];
+        $delayOff = $this->request['delayOff'];
+        $interface = $this->request['interface'];
 
         if ($enabled == true) {
             if ($trigger == 'none') {
-                $this->uciSet('system.led_wlan0.trigger', 'none');
-                $this->uciSet('system.led_wlan0.default', '1');
+                $this->systemHelper->uciSet('system.led_wlan0.trigger', 'none');
+                $this->systemHelper->uciSet('system.led_wlan0.default', '1');
                 $this->restartLEDs();
             } elseif ($trigger == 'netdev') {
-                $this->uciSet('system.led_wlan0.trigger', 'netdev');
-                $this->uciSet('system.led_wlan0.mode', "$mode");
-                $this->uciSet('system.led_wlan0.dev', "$interface");
+                $this->systemHelper->uciSet('system.led_wlan0.trigger', 'netdev');
+                $this->systemHelper->uciSet('system.led_wlan0.mode', "$mode");
+                $this->systemHelper->uciSet('system.led_wlan0.dev', "$interface");
                 $this->restartLEDs();
             } elseif ($trigger == 'timer') {
-                $this->uciSet('system.led_wlan0.trigger', 'timer');
-                $this->uciSet('system.led_wlan0.delayon', "$delayOn");
-                $this->uciSet('system.led_wlan0.delayoff', "$delayOff");
+                $this->systemHelper->uciSet('system.led_wlan0.trigger', 'timer');
+                $this->systemHelper->uciSet('system.led_wlan0.delayon', "$delayOn");
+                $this->systemHelper->uciSet('system.led_wlan0.delayoff', "$delayOff");
                 $this->restartLEDs();
             }
         } elseif ($enabled == false) {
-            $this->uciSet('system.led_wlan0.trigger', 'none');
-            $this->uciSet('system.led_wlan0.default', '0');
+            $this->systemHelper->uciSet('system.led_wlan0.trigger', 'none');
+            $this->systemHelper->uciSet('system.led_wlan0.default', '0');
             $this->restartLEDs();
         }
 
-        $this->response = array('enabled' => $enabled, 'trigger' => $trigger,
+        $this->responseHandler->setData(array('enabled' => $enabled, 'trigger' => $trigger,
         'mode' => $mode, 'delayOn' => $delayOn,
-        'delayOff' => $delayOff, 'interface' => $interface, 'success' => true);
+        'delayOff' => $delayOff, 'interface' => $interface, 'success' => true));
     }
 
-    private function getTetraRed()
+    public function getTetraRed()
     {
-        $trigger = $this->uciGet('system.led_wlan1mon.trigger');
+        $trigger = $this->systemHelper->uciGet('system.led_wlan1mon.trigger');
 
         if ($trigger == 'none') {
-            $default = $this->uciGet('system.led_wlan1mon.default');
+            $default = $this->systemHelper->uciGet('system.led_wlan1mon.default');
             if ($default == 0) {
-                $this->response = array('enabled' => false, 'trigger' => $trigger);
+                $this->responseHandler->setData(array('enabled' => false, 'trigger' => $trigger));
             } elseif ($default == 1) {
-                $this->response = array('enabled' => true, 'trigger' => $trigger);
+                $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger));
             }
         } elseif ($trigger == 'netdev') {
-            $mode = $this->uciGet('system.led_wlan1mon.mode');
-            $interface = $this->uciGet('system.led_wlan1mon.dev');
+            $mode = $this->systemHelper->uciGet('system.led_wlan1mon.mode');
+            $interface = $this->systemHelper->uciGet('system.led_wlan1mon.dev');
             if ($mode == 'link tx rx') {
-                $this->response = array('enabled' => true, 'trigger' => $trigger,
-                                        'mode' => 'link tx rx', 'interface' => $interface);
+                $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger,
+                                        'mode' => 'link tx rx', 'interface' => $interface));
             } elseif ($mode == 'link tx') {
-                $this->response = array('enabled' => true, 'trigger' => $trigger,
-                                        'mode' => 'link tx', 'interface' => $interface);
+                $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger,
+                                        'mode' => 'link tx', 'interface' => $interface));
             } elseif ($mode == 'link rx') {
-                $this->response = array('enabled' => true, 'trigger' => $trigger,
-                                        'mode' => 'link rx', 'interface' => $interface);
+                $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger,
+                                        'mode' => 'link rx', 'interface' => $interface));
             }
         } elseif ($trigger == 'timer') {
-            $delayOn = $this->uciGet('system.led_wlan1mon.delayon');
-            $delayOff = $this->uciGet('system.led_wlan1mon.delayoff');
-            $this->response = array('enabled' => true, 'trigger' => $trigger,
-                                    'delayOn' => $delayOn, 'delayOff' => $delayOff);
+            $delayOn = $this->systemHelper->uciGet('system.led_wlan1mon.delayon');
+            $delayOff = $this->systemHelper->uciGet('system.led_wlan1mon.delayoff');
+            $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger,
+                                    'delayOn' => $delayOn, 'delayOff' => $delayOff));
         } else {
-            $this->response = array('enabled' => true, 'trigger' => $trigger);
+            $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger));
         }
     }
 
-    private function setTetraRed()
+    public function setTetraRed()
     {
-        $enabled = $this->request->enabled;
-        $trigger = $this->request->trigger;
-        $mode = $this->request->mode;
-        $delayOn = $this->request->delayOn;
-        $delayOff = $this->request->delayOff;
-        $interface = $this->request->interface;
+        $enabled = $this->request['enabled'];
+        $trigger = $this->request['trigger'];
+        $mode = $this->request['mode'];
+        $delayOn = $this->request['delayOn'];
+        $delayOff = $this->request['delayOff'];
+        $interface = $this->request['interface'];
 
         if ($enabled == true) {
             if ($trigger == 'none') {
-                $this->uciSet('system.led_wlan1mon.trigger', 'none');
-                $this->uciSet('system.led_wlan1mon.default', '1');
+                $this->systemHelper->uciSet('system.led_wlan1mon.trigger', 'none');
+                $this->systemHelper->uciSet('system.led_wlan1mon.default', '1');
                 $this->restartLEDs();
             } elseif ($trigger == 'netdev') {
-                $this->uciSet('system.led_wlan1mon.trigger', 'netdev');
-                $this->uciSet('system.led_wlan1mon.mode', "$mode");
-                $this->uciSet('system.led_wlan1mon.dev', "$interface");
+                $this->systemHelper->uciSet('system.led_wlan1mon.trigger', 'netdev');
+                $this->systemHelper->uciSet('system.led_wlan1mon.mode', "$mode");
+                $this->systemHelper->uciSet('system.led_wlan1mon.dev', "$interface");
                 $this->restartLEDs();
             } elseif ($trigger == 'timer') {
-                $this->uciSet('system.led_wlan1mon.trigger', 'timer');
-                $this->uciSet('system.led_wlan1mon.delayon', "$delayOn");
-                $this->uciSet('system.led_wlan1mon.delayoff', "$delayOff");
+                $this->systemHelper->uciSet('system.led_wlan1mon.trigger', 'timer');
+                $this->systemHelper->uciSet('system.led_wlan1mon.delayon', "$delayOn");
+                $this->systemHelper->uciSet('system.led_wlan1mon.delayoff', "$delayOff");
                 $this->restartLEDs();
             }
         } elseif ($enabled == false) {
-            $this->uciSet('system.led_wlan1mon.trigger', 'none');
-            $this->uciSet('system.led_wlan1mon.default', '0');
+            $this->systemHelper->uciSet('system.led_wlan1mon.trigger', 'none');
+            $this->systemHelper->uciSet('system.led_wlan1mon.default', '0');
             $this->restartLEDs();
         }
 
-        $this->response = array('enabled' => $enabled, 'trigger' => $trigger,
+        $this->responseHandler->setData(array('enabled' => $enabled, 'trigger' => $trigger,
         'mode' => $mode, 'delayOn' => $delayOn,
-        'delayOff' => $delayOff, 'interface' => $interface, 'success' => true);
+        'delayOff' => $delayOff, 'interface' => $interface, 'success' => true));
     }
 
-    private function getNanoBlue()
+    public function getNanoBlue()
     {
-        $trigger = $this->uciGet('system.led_wlan0.trigger');
+        $trigger = $this->systemHelper->uciGet('system.led_wlan0.trigger');
 
         if ($trigger == 'none') {
-            $default = $this->uciGet('system.led_wlan0.default');
+            $default = $this->systemHelper->uciGet('system.led_wlan0.default');
             if ($default == 0) {
-                $this->response = array('enabled' => false, 'trigger' => $trigger);
+                $this->responseHandler->setData(array('enabled' => false, 'trigger' => $trigger));
             } elseif ($default == 1) {
-                $this->response = array('enabled' => true, 'trigger' => $trigger);
+                $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger));
             }
         } elseif ($trigger == 'netdev') {
-            $mode = $this->uciGet('system.led_wlan0.mode');
-            $interface = $this->uciGet('system.led_wlan0.dev');
+            $mode = $this->systemHelper->uciGet('system.led_wlan0.mode');
+            $interface = $this->systemHelper->uciGet('system.led_wlan0.dev');
             if ($mode == 'link tx rx') {
-                $this->response = array('enabled' => true, 'trigger' => $trigger,
-                                        'mode' => 'link tx rx', 'interface' => $interface);
+                $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger,
+                                        'mode' => 'link tx rx', 'interface' => $interface));
             } elseif ($mode == 'link tx') {
-                $this->response = array('enabled' => true, 'trigger' => $trigger,
-                                        'mode' => 'link tx', 'interface' => $interface);
+                $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger,
+                                        'mode' => 'link tx', 'interface' => $interface));
             } elseif ($mode == 'link rx') {
-                $this->response = array('enabled' => true, 'trigger' => $trigger,
-                                        'mode' => 'link rx', 'interface' => $interface);
+                $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger,
+                                        'mode' => 'link rx', 'interface' => $interface));
             }
         } elseif ($trigger == 'timer') {
-            $delayOn = $this->uciGet('system.led_wlan0.delayon');
-            $delayOff = $this->uciGet('system.led_wlan0.delayoff');
-            $this->response = array('enabled' => true, 'trigger' => $trigger,
-                                    'delayOn' => $delayOn, 'delayOff' => $delayOff);
+            $delayOn = $this->systemHelper->uciGet('system.led_wlan0.delayon');
+            $delayOff = $this->systemHelper->uciGet('system.led_wlan0.delayoff');
+            $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger,
+                                    'delayOn' => $delayOn, 'delayOff' => $delayOff));
         } else {
-            $this->response = array('enabled' => true, 'trigger' => $trigger);
+            $this->responseHandler->setData(array('enabled' => true, 'trigger' => $trigger));
         }
     }
 
-    private function setNanoBlue()
+    public function setNanoBlue()
     {
-        $enabled = $this->request->enabled;
-        $trigger = $this->request->trigger;
-        $mode = $this->request->mode;
-        $delayOn = $this->request->delayOn;
-        $delayOff = $this->request->delayOff;
-        $interface = $this->request->interface;
+        $enabled = $this->request['enabled'];
+        $trigger = $this->request['trigger'];
+        $mode = $this->request['mode'];
+        $delayOn = $this->request['delayOn'];
+        $delayOff = $this->request['delayOff'];
+        $interface = $this->request['interface'];
 
         if ($enabled == true) {
             if ($trigger == 'none') {
-                $this->uciSet('system.led_wlan0.trigger', 'none');
-                $this->uciSet('system.led_wlan0.default', '1');
+                $this->systemHelper->uciSet('system.led_wlan0.trigger', 'none');
+                $this->systemHelper->uciSet('system.led_wlan0.default', '1');
                 $this->restartLEDs();
             } elseif ($trigger == 'netdev') {
-                $this->uciSet('system.led_wlan0.trigger', 'netdev');
-                $this->uciSet('system.led_wlan0.mode', "$mode");
-                $this->uciSet('system.led_wlan0.dev', "$interface");
+                $this->systemHelper->uciSet('system.led_wlan0.trigger', 'netdev');
+                $this->systemHelper->uciSet('system.led_wlan0.mode', "$mode");
+                $this->systemHelper->uciSet('system.led_wlan0.dev', "$interface");
                 $this->restartLEDs();
             } elseif ($trigger == 'timer') {
-                $this->uciSet('system.led_wlan0.trigger', 'timer');
-                $this->uciSet('system.led_wlan0.delayon', "$delayOn");
-                $this->uciSet('system.led_wlan0.delayoff', "$delayOff");
+                $this->systemHelper->uciSet('system.led_wlan0.trigger', 'timer');
+                $this->systemHelper->uciSet('system.led_wlan0.delayon', "$delayOn");
+                $this->systemHelper->uciSet('system.led_wlan0.delayoff', "$delayOff");
                 $this->restartLEDs();
             }
         } elseif ($enabled == false) {
-            $this->uciSet('system.led_wlan0.trigger', 'none');
-            $this->uciSet('system.led_wlan0.default', '0');
+            $this->systemHelper->uciSet('system.led_wlan0.trigger', 'none');
+            $this->systemHelper->uciSet('system.led_wlan0.default', '0');
             $this->restartLEDs();
         }
 
-        $this->response = array('enabled' => $enabled, 'trigger' => $trigger,
+        $this->responseHandler->setData(array('enabled' => $enabled, 'trigger' => $trigger,
         'mode' => $mode, 'delayOn' => $delayOn,
-        'delayOff' => $delayOff, 'interface' => $interface, 'success' => true);
+        'delayOff' => $delayOff, 'interface' => $interface, 'success' => true));
     }
 
-    private function resetLEDs()
+    public function resetLEDs()
     {
-        $device = $this->getDevice();
+        $device = $this->systemHelper->getDevice();
 
         if ($device == 'tetra') {
-            $this->uciSet('system.led_wlan0.trigger', 'netdev');
-            $this->uciSet('system.led_wlan0.mode', 'link tx rx');
-            $this->uciSet('system.led_wlan0.dev', 'wlan0');
-            $this->uciSet('system.led_wlan1mon.trigger', 'netdev');
-            $this->uciSet('system.led_wlan1mon.mode', 'link tx rx');
-            $this->uciSet('system.led_wlan1mon.dev', 'wlan1mon');
-            $this->uciSet('system.led_eth0.trigger', 'netdev');
-            $this->uciSet('system.led_eth0.mode', 'link tx rx');
-            $this->uciSet('system.led_eth0.dev', 'eth0');
+            $this->systemHelper->uciSet('system.led_wlan0.trigger', 'netdev');
+            $this->systemHelper->uciSet('system.led_wlan0.mode', 'link tx rx');
+            $this->systemHelper->uciSet('system.led_wlan0.dev', 'wlan0');
+            $this->systemHelper->uciSet('system.led_wlan1mon.trigger', 'netdev');
+            $this->systemHelper->uciSet('system.led_wlan1mon.mode', 'link tx rx');
+            $this->systemHelper->uciSet('system.led_wlan1mon.dev', 'wlan1mon');
+            $this->systemHelper->uciSet('system.led_eth0.trigger', 'netdev');
+            $this->systemHelper->uciSet('system.led_eth0.mode', 'link tx rx');
+            $this->systemHelper->uciSet('system.led_eth0.dev', 'eth0');
             $this->restartLEDs();
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->uciSet('system.led_wlan0.trigger', 'netdev');
-            $this->uciSet('system.led_wlan0.mode', 'link tx rx');
-            $this->uciSet('system.led_wlan0.dev', 'wlan0');
+            $this->systemHelper->uciSet('system.led_wlan0.trigger', 'netdev');
+            $this->systemHelper->uciSet('system.led_wlan0.mode', 'link tx rx');
+            $this->systemHelper->uciSet('system.led_wlan0.dev', 'wlan0');
             $this->restartLEDs();
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         }
     }
 }

+ 12 - 26
modules/src/Locate/api/module.php

@@ -1,29 +1,15 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
+/* Code modified by Frieren Auto Refactor */
 /*
  * Author: trashbo4t (github.com/trashbo4t)
  */
-
-class Locate extends Module
+class Locate extends Controller
 {
-	// CONSTANTS
+	protected $endpointRoutes = ['lookupIP', 'getIPFromFile', 'getIPs'];
+ // CONSTANTS
 	private $IP_DIR = '/pineapple/modules/Locate/ips';
 	private $ALL_IP_FILE = '/pineapple/modules/Locate/ips/all';
-	
-	public function route()
-	{
-		switch ($this->request->action) {
-			case 'lookupIP':
-				$this->lookupIP();
-				break;
-			case 'getIPFromFile':
-				$this->getIPFromFile();
-				break;
-			case 'getIPs':
-				$this->getIPs();
-				break;
-		}
-	}
 	public function getJson($link, $file)
 	{
 		$cmd = "wget -q $link -O $file";
@@ -67,9 +53,9 @@ class Locate extends Module
 	public function getIPFromFile()
 	{
 		$this->makeIPDir();
-		$file = $this->touchIPFile($this->request->ip);
+		$file = $this->touchIPFile($this->request['ip']);
 		$json = $this->getIPFile($file);
-		$this->response = $json;
+		$this->responseHandler->setData($json);
 	}
 	/*
 	*  lookupIP
@@ -79,13 +65,13 @@ class Locate extends Module
 	{
 		$this->makeIPDir();
 
-		$file = $this->touchIPFile($this->request->ip);
-		$link = $this->makeLink($this->request->ip);
+		$file = $this->touchIPFile($this->request['ip']);
+		$link = $this->makeLink($this->request['ip']);
 
 		$json = $this->getJson($link, $file);
 	
-		$this->addToIpFile($this->request->ip);
-		$this->response = $json;
+		$this->addToIpFile($this->request['ip']);
+		$this->responseHandler->setData($json);
 	}
 	/*
 	*  getIPs
@@ -96,7 +82,7 @@ class Locate extends Module
 		$this->makeIPDir();
 		$this->touchIPFile();
 
-		$this->response = array();
+		$this->responseHandler->setData(array());
 		
 		$lines = file($this->ALL_IP_FILE);
 		foreach ($lines as $line) 

+ 22 - 48
modules/src/LogManager/api/module.php

@@ -1,37 +1,11 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-
-
-class LogManager extends Module
+/* Code modified by Frieren Auto Refactor */
+class LogManager extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'refreshInfo':
-                $this->refreshInfo();
-                break;
-            case 'refreshFilesList':
-                $this->refreshFilesList();
-                break;
-            case 'downloadFilesList':
-                $this->downloadFilesList();
-                break;
-            case 'deleteFilesList':
-                $this->deleteFilesList();
-                break;
-            case 'viewModuleFile':
-                $this->viewModuleFile();
-                break;
-            case 'deleteModuleFile':
-                $this->deleteModuleFile();
-                break;
-            case 'downloadModuleFile':
-                $this->downloadModuleFile();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['refreshInfo', 'refreshFilesList', 'downloadFilesList', 'deleteFilesList', 'viewModuleFile', 'deleteModuleFile', 'downloadModuleFile'];
 
-    private function dataSize($path)
+    public function dataSize($path)
     {
         $blah = exec("/usr/bin/du -sch $path | tail -1 | awk {'print $1'}");
         return $blah;
@@ -40,12 +14,12 @@ class LogManager extends Module
     protected function refreshInfo()
     {
         $moduleInfo = @json_decode(file_get_contents("/pineapple/modules/LogManager/module.info"));
-        $this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
+        $this->responseHandler->setData(array('title' => $moduleInfo->title, 'version' => $moduleInfo->version));
     }
 
-    private function downloadFilesList()
+    public function downloadFilesList()
     {
-        $files = $this->request->files;
+        $files = $this->request['files'];
 
         exec("mkdir /tmp/dl/");
         foreach ($files as $file) {
@@ -54,19 +28,19 @@ class LogManager extends Module
         exec("cd /tmp/dl/ && tar -czf /tmp/files.tar.gz *");
         exec("rm -rf /tmp/dl/");
 
-        $this->response = array("download" => $this->downloadFile("/tmp/files.tar.gz"));
+        $this->responseHandler->setData(array("download" => $this->systemHelper->downloadFile("/tmp/files.tar.gz")));
     }
 
-    private function deleteFilesList()
+    public function deleteFilesList()
     {
-        $files = $this->request->files;
+        $files = $this->request['files'];
 
         foreach ($files as $file) {
             exec("rm -rf ".$file);
         }
     }
 
-    private function refreshFilesList()
+    public function refreshFilesList()
     {
         $modules = array();
         foreach (glob('/pineapple/modules/*/log/*') as $file) {
@@ -115,28 +89,28 @@ class LogManager extends Module
 
         usort($modules, create_function('$a, $b', 'if($a["timestamp"] == $b["timestamp"]) return 0; return ($a["timestamp"] > $b["timestamp"]) ? -1 : 1;'));
 
-        $this->response = array("files" => $modules);
+        $this->responseHandler->setData(array("files" => $modules));
     }
 
-    private function viewModuleFile()
+    public function viewModuleFile()
     {
-        $log_date = gmdate("F d Y H:i:s", filemtime($this->request->file));
-        exec("strings ".$this->request->file, $output);
+        $log_date = gmdate("F d Y H:i:s", filemtime($this->request['file']));
+        exec("strings ".$this->request['file'], $output);
 
         if (!empty($output)) {
-            $this->response = array("output" => implode("\n", $output), "date" => $log_date, "name" => basename($this->request->file));
+            $this->responseHandler->setData(array("output" => implode("\n", $output), "date" => $log_date, "name" => basename($this->request['file'])));
         } else {
-            $this->response = array("output" => "Empty file...", "date" => $log_date, "name" => basename($this->request->file));
+            $this->responseHandler->setData(array("output" => "Empty file...", "date" => $log_date, "name" => basename($this->request['file'])));
         }
     }
 
-    private function deleteModuleFile()
+    public function deleteModuleFile()
     {
-        exec("rm -rf ".$this->request->file);
+        exec("rm -rf ".$this->request['file']);
     }
 
-    private function downloadModuleFile()
+    public function downloadModuleFile()
     {
-        $this->response = array("download" => $this->downloadFile($this->request->file));
+        $this->responseHandler->setData(array("download" => $this->systemHelper->downloadFile($this->request['file'])));
     }
 }

+ 12 - 18
modules/src/MACInfo/api/module.php

@@ -1,44 +1,38 @@
-<?php namespace pineapple;
-
+<?php namespace frieren\core;
 
+/* Code modified by Frieren Auto Refactor */
 /* The class name must be the name of your module, without spaces. */
 /* It must also extend the "Module" class. This gives your module access to API functions */
-class MACInfo extends Module
+class MACInfo extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'getMACInfo':
-            $this->getMACInfo($this->request->moduleMAC);
-            break;
-        }
-    }
+    protected $endpointRoutes = ['getMACInfo'];
 
-    private function getMACInfo($mac)
+    public function getMACInfo($mac)
     {
+        $mac = $this->request['moduleMAC'];
         if($this->IsValidMAC($mac)){
             $url = "https://macvendors.co/api/" . $mac . "/JSON";
             $retJSON = file_get_contents($url);
             if($retJSON != false){
                 $mInfo = json_decode($retJSON);
                 if(isset($mInfo) && isset($mInfo->result) && $mInfo->result->error != ""){
-                    $this->response = array("success" => false, "error" => $mInfo->result->error);
+                    $this->responseHandler->setData(array("success" => false, "error" => $mInfo->result->error));
                 }
                 else{
-                    $this->response = array("success" => true,
+                    $this->responseHandler->setData(array("success" => true,
                                             "company" => $mInfo->result->company,
                                             "macprefix" => $mInfo->result->mac_prefix,
                                             "address" => $mInfo->result->address,
                                             "country" => $mInfo->result->country,
                                             "type" => $mInfo->result->type
-                    );
+                    ));
                 }
             }
-            else{ $this->response = array("success" => false, "error" => "Error reading contents from: " . $url); }
+            else{ $this->responseHandler->setData(array("success" => false, "error" => "Error reading contents from: " . $url)); }
         }
-        else{ $this->response = array("success" => false, "error" => "Invalid MAC Address format"); }
+        else{ $this->responseHandler->setData(array("success" => false, "error" => "Invalid MAC Address format")); }
     }
-    private function IsValidMAC($mac) {
+    public function IsValidMAC($mac) {
         $pregResult = preg_match('/([a-fA-F0-9]{2}[:|\-]?){6}/', $mac);
         return ($pregResult != 0 && $pregResult != NULL);
     }

+ 34 - 60
modules/src/Meterpreter/api/module.php

@@ -1,100 +1,74 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class Meterpreter extends Module
+/* Code modified by Frieren Auto Refactor */
+class Meterpreter extends Controller
 {
-  public function route()
-  {
-    switch ($this->request->action) {
-      case 'getState':
-      $this->getState();
-      break;
-
-      case 'startMeterpreter':
-      $this->startMeterpreter();
-      break;
-
-      case 'stopMeterpreter':
-      $this->stopMeterpreter();
-      break;
+  protected $endpointRoutes = ['getState', 'startMeterpreter', 'stopMeterpreter', 'enableMeterpreter', 'disableMeterpreter', 'saveConfig'];
 
-      case 'enableMeterpreter':
-      $this->enableMeterpreter();
-      break;
-
-      case 'disableMeterpreter':
-      $this->disableMeterpreter();
-      break;
-
-      case 'saveConfig':
-      $this->saveConfig();
-      break;
-    }
-  }
-
-  private function getState()
+  public function getState()
   {
     if (!file_exists("/etc/config/meterpreter")) {
       exec("touch /etc/config/meterpreter");
     }
 
-    $this->response = array(
+    $this->responseHandler->setData(array(
       "success" => true,
-      "running" => $this->checkRunning('meterpreter'),
-      "enabled" => $this->uciGet("meterpreter.autostart"),
+      "running" => $this->systemHelper->checkRunning('meterpreter'),
+      "enabled" => $this->systemHelper->uciGet("meterpreter.autostart"),
       "config" => $this->getConfig()
-    );
+    ));
   }
 
-  private function startMeterpreter()
+  public function startMeterpreter()
   {
-    $host = $this->uciGet("meterpreter.host");
-    $port = $this->uciGet("meterpreter.port");
-    $this->execBackground("meterpreter $host $port");
-    $this->response = array("success" => true);
+    $host = $this->systemHelper->uciGet("meterpreter.host");
+    $port = $this->systemHelper->uciGet("meterpreter.port");
+    $this->systemHelper->execBackground("meterpreter $host $port");
+    $this->responseHandler->setData(array("success" => true));
   }
 
-  private function stopMeterpreter()
+  public function stopMeterpreter()
   {
     exec("killall meterpreter");
-    $this->response = array("success" => true);
+    $this->responseHandler->setData(array("success" => true));
   }
 
-  private function enableMeterpreter()
+  public function enableMeterpreter()
   {
-    $host = $this->uciGet("meterpreter.host");
-    $port = $this->uciGet("meterpreter.port");
+    $host = $this->systemHelper->uciGet("meterpreter.host");
+    $port = $this->systemHelper->uciGet("meterpreter.port");
     exec("sed -i '1i /usr/bin/pineapple/meterpreter $host $port & # inserted by meterpreter module' /etc/rc.local");
-    $this->uciSet("meterpreter.autostart", true);
-    $this->response = array("success" => true);
+    $this->systemHelper->uciSet("meterpreter.autostart", true);
+    $this->responseHandler->setData(array("success" => true));
   }
 
-  private function disableMeterpreter()
+  public function disableMeterpreter()
   {
     exec("sed -i '/meterpreter/d' /etc/rc.local");
-    $this->uciSet("meterpreter.autostart", false);
-    $this->response = array("success" => true);
+    $this->systemHelper->uciSet("meterpreter.autostart", false);
+    $this->responseHandler->setData(array("success" => true));
   }
 
-  private function getConfig()
+  public function getConfig()
   {
     return array(
-      "host" => $this->uciGet("meterpreter.host"),
-      "port" => $this->uciGet("meterpreter.port")
+      "host" => $this->systemHelper->uciGet("meterpreter.host"),
+      "port" => $this->systemHelper->uciGet("meterpreter.port")
     );
   }
 
-  private function saveConfig()
+  public function saveConfig()
   {
-    $args = $this->request->params;
-    $this->uciSet("meterpreter.host", $args->host);
-    $this->uciSet("meterpreter.port", $args->port);
+    $args = $this->request['params'];
+    $this->systemHelper->uciSet("meterpreter.host", $args->host);
+    $this->systemHelper->uciSet("meterpreter.port", $args->port);
     $this->toggleMeterpreter(); //resets rc.local to new settings in autostart is enabled
-    $this->response = array("success" => true, "args"=> $args);
+    $this->responseHandler->setData(array("success" => true, "args"=> $args));
   }
 
-  private function toggleMeterpreter()
+  public function toggleMeterpreter()
   {
-    $enabled = $this->uciGet("meterpreter.autostart");
+    $enabled = $this->systemHelper->uciGet("meterpreter.autostart");
     if ($enabled == "1") {
       $this->disableMeterpreter();
       $this->enableMeterpreter();

+ 83 - 130
modules/src/ModemManager/api/module.php

@@ -1,163 +1,116 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
+/* Code modified by Frieren Auto Refactor */
 /***
 Modem Manager <api/module.php>
 Written by Foxtrot <foxtrot@realloc.me>
 Distributed under the MIT Licence <https://opensource.org/licenses/MIT>
 ***/
-
-class ModemManager extends Module
+class ModemManager extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'checkDepends':
-                $this->checkDepends();
-                break;
-
-            case 'installDepends':
-                $this->installDepends();
-                break;
-
-            case 'removeDepends':
-                $this->removeDepends();
-                break;
-
-            case 'getUSB':
-                $this->getUSB();
-                break;
-
-            case 'getTTYs':
-                $this->getTTYs();
-                break;
-
-            case 'checkConnection':
-                $this->checkConnection();
-                break;
-
-            case 'setConnection':
-                $this->setConnection();
-                break;
-
-            case 'unsetConnection':
-                $this->unsetConnection();
-                break;
-
-            case 'loadConfiguration':
-                $this->loadConfiguration();
-                break;
-
-            case 'saveConfiguration':
-                $this->saveConfiguration();
-                break;
-
-            case 'resetConfiguration':
-                $this->resetConfiguration();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['checkDepends', 'installDepends', 'removeDepends', 'getUSB', 'getTTYs', 'checkConnection', 'setConnection', 'unsetConnection', 'loadConfiguration', 'saveConfiguration', 'resetConfiguration'];
 
-    private function checkDepends()
+    public function checkDepends()
     {
         /* Check dependencies */
-        if(empty($this->checkDependency('comgt'))) {
-            $this->response = array('installed' => false);
+        if(empty($this->systemHelper->checkDependency('comgt'))) {
+            $this->responseHandler->setData(array('installed' => false));
         } else {
-            $this->response = array('installed' => true);
+            $this->responseHandler->setData(array('installed' => true));
         }
     }
 
-    private function installDepends()
+    public function installDepends()
     {
         /* Install dependencies */
-        $this->execBackground('opkg update && opkg install comgt wwan uqmi');    
-        $this->response = array("installing" => true);
+        $this->systemHelper->execBackground('opkg update && opkg install comgt wwan uqmi');    
+        $this->responseHandler->setData(array("installing" => true));
 
     }
 
-    private function removeDepends()
+    public function removeDepends()
     {
         /* Remove dependencies */
-        $this->execBackground('opkg remove comgt wwan uqmi');
-        $this->response = array('success' => true);
+        $this->systemHelper->execBackground('opkg remove comgt wwan uqmi');
+        $this->responseHandler->setData(array('success' => true));
     }
 
-    private function getUSB()
+    public function getUSB()
     {
         /* Execute 'lsusb' and capture its output in the $lsusb variable.
            Then split the output by its newlines. */
         exec('lsusb', $lsusb);
         $lsusb = implode("\n", $lsusb);
 
-        $this->response = array('lsusb' => $lsusb);
+        $this->responseHandler->setData(array('lsusb' => $lsusb));
     }
 
-    private function getTTYs()
+    public function getTTYs()
     {
         exec('ls /dev/ttyUSB* && ls /dev/cdc-wdm* && ls /dev/ttyACM*', $TTYs);
 
         if (empty($TTYs)) {
-            $this->response = array('success' => false,
-                                    'availableTTYs' => false);
+            $this->responseHandler->setData(array('success' => false,
+                                    'availableTTYs' => false));
         } else {
             $TTYs = implode("\n", $TTYs);
-            $this->response = array('success' => true,
-                                    'availableTTYs' => $TTYs);
+            $this->responseHandler->setData(array('success' => true,
+                                    'availableTTYs' => $TTYs));
         }
     }
 
-    private function checkConnection()
+    public function checkConnection()
     {
         /* Check the connection of the wan2 interface. */
         if(file_exists('/sys/class/net/3g-wan2/carrier')) {
-            $this->response = array('status' => 'connected');
+            $this->responseHandler->setData(array('status' => 'connected'));
             exec('iptables -t nat -A POSTROUTING -s 172.16.42.0/24 -o 3g-wan2 -j MASQUERADE');
             exec('iptables -A FORWARD -s 172.16.42.0/24 -o 3g-wan2 -j ACCEPT');
             exec('iptables -A FORWARD -d 172.16.42.0/24 -m state --state ESTABLISHED,RELATED -i 3g-wan2 -j ACCEPT');
         } else {
-            $this->response = array('status' => 'disconnected');
+            $this->responseHandler->setData(array('status' => 'disconnected'));
         }
 
     }
 
-    private function setConnection()
+    public function setConnection()
     {
         /* Set the connection of the wan2 interface. */
-        $this->execBackground('ifup wan2');
-        $this->response = array('status' => 'connecting');
+        $this->systemHelper->execBackground('ifup wan2');
+        $this->responseHandler->setData(array('status' => 'connecting'));
     }
 
-    private function unsetConnection()
+    public function unsetConnection()
     {
         /* Unset the connection of the wan2 interface. */
-        $this->execBackground('ifdown wan2');
-        $this->response = array('status' => 'disconnected');
+        $this->systemHelper->execBackground('ifdown wan2');
+        $this->responseHandler->setData(array('status' => 'disconnected'));
     }
 
-    private function loadConfiguration()
+    public function loadConfiguration()
     {
         /* For easier code reading, assign a variable for each bit of information we require from the system.
            Read more about UCI at https://wiki.openwrt.org/doc/uci.
            For more information about the WiFi Pineapple API, visit https://wiki.wifipineapple.com. */
-        $interface     = $this->uciGet('network.wan2.ifname');
-        $protocol      = $this->uciGet('network.wan2.proto');
-        $service       = $this->uciGet('network.wan2.service');
-        $vendorid      = $this->uciGet('network.wan2.currentVID');
-        $productid     = $this->uciGet('network.wan2.currentPID');
-        $device        = $this->uciGet('network.wan2.device');
-        $apn           = $this->uciGet('network.wan2.apn');
-        $username      = $this->uciGet('network.wan2.username');
-        $password      = $this->uciGet('network.wan2.password');
-        $dns           = $this->uciGet('network.wan2.dns');
-        $peerdns       = $this->uciGet('network.wan2.peerdns');
-        $pppredial     = $this->uciGet('network.wan2.ppp_redial');
-        $defaultroute  = $this->uciGet('network.wan2.defaultroute');
-        $keepalive     = $this->uciGet('network.wan2.keepalive');
-        $pppdoptions   = $this->uciGet('network.wan2.pppd_options');
+        $interface     = $this->systemHelper->uciGet('network.wan2.ifname');
+        $protocol      = $this->systemHelper->uciGet('network.wan2.proto');
+        $service       = $this->systemHelper->uciGet('network.wan2.service');
+        $vendorid      = $this->systemHelper->uciGet('network.wan2.currentVID');
+        $productid     = $this->systemHelper->uciGet('network.wan2.currentPID');
+        $device        = $this->systemHelper->uciGet('network.wan2.device');
+        $apn           = $this->systemHelper->uciGet('network.wan2.apn');
+        $username      = $this->systemHelper->uciGet('network.wan2.username');
+        $password      = $this->systemHelper->uciGet('network.wan2.password');
+        $dns           = $this->systemHelper->uciGet('network.wan2.dns');
+        $peerdns       = $this->systemHelper->uciGet('network.wan2.peerdns');
+        $pppredial     = $this->systemHelper->uciGet('network.wan2.ppp_redial');
+        $defaultroute  = $this->systemHelper->uciGet('network.wan2.defaultroute');
+        $keepalive     = $this->systemHelper->uciGet('network.wan2.keepalive');
+        $pppdoptions   = $this->systemHelper->uciGet('network.wan2.pppd_options');
 
         /* Now send a response inside of an array, with keys being 'interface', 'protocol' etc
            and their values being those we obtained from uciGet(). */
-        $this->response = array('success'      => true,
+        $this->responseHandler->setData(array('success'      => true,
                                 'interface'    => $interface,
                                 'protocol'     => $protocol,
                                 'service'      => $service,
@@ -172,68 +125,68 @@ class ModemManager extends Module
                                 'pppredial'    => $pppredial,
                                 'defaultroute' => $defaultroute,
                                 'keepalive'    => $keepalive,
-                                'pppdoptions'  => $pppdoptions);
+                                'pppdoptions'  => $pppdoptions));
     }
 
-    private function saveConfiguration()
+    public function saveConfiguration()
     {
         /* In the same way as loadConfiguration(), get the desired information and assign it to a variable.
            However this time get the data that was sent with the request from the JS. */
-        $interface     = $this->request->interface;
-        $protocol      = $this->request->protocol;
-        $service       = $this->request->service;
-        $vendorid      = $this->request->vendorid;
-        $productid     = $this->request->productid;
-        $device        = $this->request->device;
-        $apn           = $this->request->apn;
-        $username      = $this->request->username;
-        $password      = $this->request->password;
-        $dns           = $this->request->dns;
-        $peerdns       = $this->request->peerdns;
-        $pppredial     = $this->request->pppredial;
-        $defaultroute  = $this->request->defaultroute;
-        $keepalive     = $this->request->keepalive;
-        $pppdoptions   = $this->request->pppdoptions;
+        $interface     = $this->request['interface'];
+        $protocol      = $this->request['protocol'];
+        $service       = $this->request['service'];
+        $vendorid      = $this->request['vendorid'];
+        $productid     = $this->request['productid'];
+        $device        = $this->request['device'];
+        $apn           = $this->request['apn'];
+        $username      = $this->request['username'];
+        $password      = $this->request['password'];
+        $dns           = $this->request['dns'];
+        $peerdns       = $this->request['peerdns'];
+        $pppredial     = $this->request['pppredial'];
+        $defaultroute  = $this->request['defaultroute'];
+        $keepalive     = $this->request['keepalive'];
+        $pppdoptions   = $this->request['pppdoptions'];
 
         /* Using the APIs uciSet() function, set the UCI properties to
            what the JS request gave us. */
-        $this->uciSet('network.wan2',              'interface');
-        $this->uciSet('network.wan2.ifname',       $interface);
-        $this->uciSet('network.wan2.proto',        $protocol);
-        $this->uciSet('network.wan2.service',      $service);
-        $this->uciSet('network.wan2.currentVID',   $vendorid);
-        $this->uciSet('network.wan2.currentPID',   $productid);
-        $this->uciSet('network.wan2.device',       $device);
-        $this->uciSet('network.wan2.apn',          $apn);
-        $this->uciSet('network.wan2.peerdns',      $peerdns);
-        $this->uciSet('network.wan2.ppp_redial',   $pppredial);
-        $this->uciSet('network.wan2.defaultroute', $defaultroute);
-        $this->uciSet('network.wan2.keepalive',    $keepalive);
-        $this->uciSet('network.wan2.pppd_options', $pppdoptions);
+        $this->systemHelper->uciSet('network.wan2',              'interface');
+        $this->systemHelper->uciSet('network.wan2.ifname',       $interface);
+        $this->systemHelper->uciSet('network.wan2.proto',        $protocol);
+        $this->systemHelper->uciSet('network.wan2.service',      $service);
+        $this->systemHelper->uciSet('network.wan2.currentVID',   $vendorid);
+        $this->systemHelper->uciSet('network.wan2.currentPID',   $productid);
+        $this->systemHelper->uciSet('network.wan2.device',       $device);
+        $this->systemHelper->uciSet('network.wan2.apn',          $apn);
+        $this->systemHelper->uciSet('network.wan2.peerdns',      $peerdns);
+        $this->systemHelper->uciSet('network.wan2.ppp_redial',   $pppredial);
+        $this->systemHelper->uciSet('network.wan2.defaultroute', $defaultroute);
+        $this->systemHelper->uciSet('network.wan2.keepalive',    $keepalive);
+        $this->systemHelper->uciSet('network.wan2.pppd_options', $pppdoptions);
 
         if(!empty($username)) {
-            $this->uciSet('network.wan2.username', $username);
+            $this->systemHelper->uciSet('network.wan2.username', $username);
         }
         if (!empty($password)) {
-            $this->uciSet('network.wan2.password', $password);
+            $this->systemHelper->uciSet('network.wan2.password', $password);
         }
         if(!empty($dns)) {
-            $this->uciSet('network.wan2.dns', $dns);
+            $this->systemHelper->uciSet('network.wan2.dns', $dns);
         }
 
         unlink("/etc/modules.d/60-usb-serial");
         exec("echo 'usbserial vendor=0x$vendorid product=0x$productid maxSize=4096' > /etc/modules.d/60-usb-serial");
 
-        $this->response = array('success' => true);
+        $this->responseHandler->setData(array('success' => true));
     }
 
-    private function resetConfiguration()
+    public function resetConfiguration()
     {
         /* Delete the network.wan2 section */
         exec('uci del network.wan2');
         exec('uci commit');
         unlink('/etc/modules.d/60-usb-serial');
 
-        $this->response = array('success' => true);
+        $this->responseHandler->setData(array('success' => true));
     }
 }

+ 7 - 14
modules/src/ModuleMaker/Extra/module.php

@@ -1,24 +1,17 @@
-<?php namespace pineapple;
-
+<?php namespace frieren\core;
 
+/* Code modified by Frieren Auto Refactor */
 /* The class name must be the name of your module, without spaces. */
 /* It must also extend the "Module" class. This gives your module access to API functions */
-class _MODULE_NAME extends Module
+class _MODULE_NAME extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'getContents':    // If you request the action "getContents" from your Javascript, this is where the PHP will see it, and use the correct function
-            $this->getContents();  // $this->getContents(); refers to your private function that contains all of the code for your request.
-            break;                 // Break here, and add more cases after that for different requests.
-        }
-    }
+    protected $endpointRoutes = ['getContents'];
 
-    private function getContents()  // This is the function that will be executed when you send the request "getContents".
+    public function getContents()  // This is the function that will be executed when you send the request "getContents".
     {
-        $this->response = array("success" => true,    // define $this->response. We can use an array to set multiple responses.
+        $this->responseHandler->setData(array("success" => true,    // define $this->response. We can use an array to set multiple responses.
                                 "greeting" => "Hey there!",
-                                "content" => "This is the HTML template for your new module! The example shows you the basics of using HTML, AngularJS and PHP to seamlessly pass information to and from Javascript and PHP and output it to HTML.");
+                                "content" => "This is the HTML template for your new module! The example shows you the basics of using HTML, AngularJS and PHP to seamlessly pass information to and from Javascript and PHP and output it to HTML."));
     }
 }
 

+ 18 - 33
modules/src/ModuleMaker/api/module.php

@@ -1,52 +1,37 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
+/* Code modified by Frieren Auto Refactor */
 /**
 * Foxtrot (C) 2016 <foxtrotnull@gmail.com>
 **/
-
-class ModuleMaker extends Module
+class ModuleMaker extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'generateModule':
-            $this->generateModule();
-            break;
-
-            case 'getInstalledModules':
-            $this->getInstalledModules();
-            break;
-
-            case 'removeModule':
-            $this->removeModule();
-            break;
-        }
-    }
+    protected $endpointRoutes = ['generateModule', 'getInstalledModules', 'removeModule'];
 
-    private function generateModule()
+    public function generateModule()
     {
         /* Make life easier */
-        $moduleTitle = $this->request->moduleTitle;
-        $moduleDescription = $this->request->moduleDesc;
-        $moduleVersion = $this->request->moduleVersion;
-        $moduleAuthor = str_replace(' ', '', $this->request->moduleAuthor);
+        $moduleTitle = $this->request['moduleTitle'];
+        $moduleDescription = $this->request['moduleDesc'];
+        $moduleVersion = $this->request['moduleVersion'];
+        $moduleAuthor = str_replace(' ', '', $this->request['moduleAuthor']);
         $moduleName = str_replace(' ', '', $moduleTitle);
         $modulePath = "/pineapple/modules/{$moduleName}";
         $templates = "/pineapple/modules/ModuleMaker/Extra";
 
         /* Check whether the user has acceptable input and check if the module already exists */
         if(empty($moduleTitle)){
-            $this->error = "The module name cannot be empty.";
+            $this->responseHandler->setError("The module name cannot be empty.");
         } elseif (file_exists($modulePath)) {
-            $this->error = "A module with this name already exists.";
+            $this->responseHandler->setError("A module with this name already exists.");
         } elseif(empty($moduleDescription)){
-            $this->error = "You must specify a description.";
+            $this->responseHandler->setError("You must specify a description.");
         } elseif(!is_numeric($moduleVersion)){
-            $this->error = "Module version must be in the form of X.X";
+            $this->responseHandler->setError("Module version must be in the form of X.X");
         } elseif(substr_count($moduleVersion, '.') <1 || substr_count($moduleVersion, '.') >1){
-            $this->error = "Module version must only contain one period.";
+            $this->responseHandler->setError("Module version must only contain one period.");
         } elseif(empty($moduleAuthor)){
-            $this->error = "You must supply an Author.";
+            $this->responseHandler->setError("You must supply an Author.");
         }
 
         /* If an error is set, return early */
@@ -73,11 +58,11 @@ class ModuleMaker extends Module
 
 
         /* Once the module has been created, set the response to success */
-        $this->response = array("success" => true);
+        $this->responseHandler->setData(array("success" => true));
 
     }
 
-    private function getInstalledModules()
+    public function getInstalledModules()
     {
         $modules = array();
         $modulesDirectories = scandir('/pineapple/modules');
@@ -103,7 +88,7 @@ class ModuleMaker extends Module
                 $modules[$moduleDirectory] = $module;
             }
         }
-        $this->response = array("installedModules" => $modules);
+        $this->responseHandler->setData(array("installedModules" => $modules));
     }
 }
 

+ 73 - 121
modules/src/Occupineapple/api/module.php

@@ -1,61 +1,13 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class Occupineapple extends Module
+/* Code modified by Frieren Auto Refactor */
+class Occupineapple extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'refreshInfo':
-                $this->refreshInfo();
-                break;
-            case 'refreshOutput':
-                $this->refreshOutput();
-                break;
-            case 'refreshStatus':
-                $this->refreshStatus();
-                break;
-            case 'togglemdk3':
-                $this->togglemdk3();
-                break;
-            case 'handleDependencies':
-                $this->handleDependencies();
-                break;
-            case 'handleDependenciesStatus':
-                $this->handleDependenciesStatus();
-                break;
-            case 'getInterfaces':
-                $this->getInterfaces();
-                break;
-            case 'getLists':
-                $this->getLists();
-                break;
-            case 'showList':
-                $this->showList();
-                break;
-            case 'deleteList':
-                $this->deleteList();
-                break;
-            case 'saveListData':
-                $this->saveListData();
-                break;
-            case 'getSettings':
-                $this->getSettings();
-                break;
-            case 'setSettings':
-                $this->setSettings();
-                break;
-            case 'saveAutostartSettings':
-                $this->saveAutostartSettings();
-                break;
-            case 'togglemdk3OnBoot':
-                $this->togglemdk3OnBoot();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['refreshInfo', 'refreshOutput', 'refreshStatus', 'togglemdk3', 'handleDependencies', 'handleDependenciesStatus', 'getInterfaces', 'getLists', 'showList', 'deleteList', 'saveListData', 'getSettings', 'setSettings', 'saveAutostartSettings', 'togglemdk3OnBoot'];
 
     protected function checkDeps($dependencyName)
     {
-        return ($this->checkDependency($dependencyName) && ($this->uciGet("occupineapple.module.installed")));
+        return ($this->systemHelper->checkDependency($dependencyName) && ($this->systemHelper->uciGet("occupineapple.module.installed")));
     }
 
     protected function getDevice()
@@ -66,21 +18,21 @@ class Occupineapple extends Module
     protected function refreshInfo()
     {
         $moduleInfo = @json_decode(file_get_contents("/pineapple/modules/Occupineapple/module.info"));
-        $this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
+        $this->responseHandler->setData(array('title' => $moduleInfo->title, 'version' => $moduleInfo->version));
     }
 
-    private function handleDependencies()
+    public function handleDependencies()
     {
         if (!$this->checkDeps("mdk3")) {
-            $this->execBackground("/pineapple/modules/Occupineapple/scripts/dependencies.sh install ".$this->request->destination);
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/Occupineapple/scripts/dependencies.sh install ".$this->request['destination']);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->execBackground("/pineapple/modules/Occupineapple/scripts/dependencies.sh remove");
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/Occupineapple/scripts/dependencies.sh remove");
+            $this->responseHandler->setData(array('success' => true));
         }
     }
 
-    private function togglemdk3OnBoot()
+    public function togglemdk3OnBoot()
     {
         if (exec("cat /etc/rc.local | grep Occupineapple/scripts/autostart_occupineapple.sh") == "") {
             exec("sed -i '/exit 0/d' /etc/rc.local");
@@ -91,31 +43,31 @@ class Occupineapple extends Module
         }
     }
 
-    private function handleDependenciesStatus()
+    public function handleDependenciesStatus()
     {
         if (!file_exists('/tmp/Occupineapple.progress')) {
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function togglemdk3()
+    public function togglemdk3()
     {
-        if (!$this->checkRunning("mdk3")) {
-            $this->uciSet("occupineapple.run.interface", $this->request->interface);
-            $this->uciSet("occupineapple.run.list", $this->request->list);
+        if (!$this->systemHelper->checkRunning("mdk3")) {
+            $this->systemHelper->uciSet("occupineapple.run.interface", $this->request['interface']);
+            $this->systemHelper->uciSet("occupineapple.run.list", $this->request['list']);
 
-            $this->execBackground("/pineapple/modules/Occupineapple/scripts/occupineapple.sh start");
+            $this->systemHelper->execBackground("/pineapple/modules/Occupineapple/scripts/occupineapple.sh start");
         } else {
-            $this->uciSet("occupineapple.run.interface", '');
-            $this->uciSet("occupineapple.run.list", '');
+            $this->systemHelper->uciSet("occupineapple.run.interface", '');
+            $this->systemHelper->uciSet("occupineapple.run.list", '');
 
-            $this->execBackground("/pineapple/modules/Occupineapple/scripts/occupineapple.sh stop");
+            $this->systemHelper->execBackground("/pineapple/modules/Occupineapple/scripts/occupineapple.sh stop");
         }
     }
 
-    private function refreshStatus()
+    public function refreshStatus()
     {
         if (!file_exists('/tmp/Occupineapple.progress')) {
             if (!$this->checkDeps("mdk3")) {
@@ -135,7 +87,7 @@ class Occupineapple extends Module
                 $installLabel = "success";
                 $processing = false;
 
-                if ($this->checkRunning("mdk3")) {
+                if ($this->systemHelper->checkRunning("mdk3")) {
                     $status = "Stop";
                     $statusLabel = "danger";
                 } else {
@@ -164,38 +116,38 @@ class Occupineapple extends Module
             $bootLabelOFF = "danger";
         }
 
-        $device = $this->getDevice();
-        $sdAvailable = $this->isSDAvailable();
+        $device = $this->systemHelper->getDevice();
+        $sdAvailable = $this->systemHelper->isSDAvailable();
 
-        $this->response = array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "bootLabelON" => $bootLabelON, "bootLabelOFF" => $bootLabelOFF, "processing" => $processing);
+        $this->responseHandler->setData(array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "bootLabelON" => $bootLabelON, "bootLabelOFF" => $bootLabelOFF, "processing" => $processing));
     }
 
-    private function refreshOutput()
+    public function refreshOutput()
     {
         if ($this->checkDeps("mdk3")) {
-            if ($this->checkRunning("mdk3")) {
+            if ($this->systemHelper->checkRunning("mdk3")) {
                 exec("cat /tmp/occupineapple.log", $output);
                 if (!empty($output)) {
-                    $this->response = implode("\n", array_reverse($output));
+                    $this->responseHandler->setData(implode("\n", array_reverse($output)));
                 } else {
-                    $this->response = "Empty log...";
+                    $this->responseHandler->setData("Empty log...");
                 }
             } else {
-                $this->response = "Occupineapple is not running...";
+                $this->responseHandler->setData("Occupineapple is not running...");
             }
         } else {
-            $this->response = "mdk3 is not installed...";
+            $this->responseHandler->setData("mdk3 is not installed...");
         }
     }
 
-    private function getInterfaces()
+    public function getInterfaces()
     {
         exec("iwconfig 2> /dev/null | grep \"wlan*\" | awk '{print $1}'", $interfaceArray);
 
-        $this->response = array("interfaces" => $interfaceArray, "selected" => $this->uciGet("occupineapple.run.interface"));
+        $this->responseHandler->setData(array("interfaces" => $interfaceArray, "selected" => $this->systemHelper->uciGet("occupineapple.run.interface")));
     }
 
-    private function getLists()
+    public function getLists()
     {
         $listArray = array();
         $listList = array_reverse(glob("/pineapple/modules/Occupineapple/lists/*"));
@@ -203,76 +155,76 @@ class Occupineapple extends Module
         foreach ($listList as $list) {
             array_push($listArray, basename($list));
         }
-        $this->response = array("lists" => $listArray, "selected" => $this->uciGet("occupineapple.run.list"));
+        $this->responseHandler->setData(array("lists" => $listArray, "selected" => $this->systemHelper->uciGet("occupineapple.run.list")));
     }
 
-    private function showList()
+    public function showList()
     {
-        $listData = file_get_contents('/pineapple/modules/Occupineapple/lists/'.$this->request->list);
-        $this->response = array("listData" => $listData);
+        $listData = file_get_contents('/pineapple/modules/Occupineapple/lists/'.$this->request['list']);
+        $this->responseHandler->setData(array("listData" => $listData));
     }
 
-    private function deleteList()
+    public function deleteList()
     {
-        exec("rm -rf /pineapple/modules/Occupineapple/lists/".$this->request->list);
+        exec("rm -rf /pineapple/modules/Occupineapple/lists/".$this->request['list']);
     }
 
-    private function saveListData()
+    public function saveListData()
     {
-        $filename = "/pineapple/modules/Occupineapple/lists/".$this->request->list;
-        file_put_contents($filename, $this->request->listData);
+        $filename = "/pineapple/modules/Occupineapple/lists/".$this->request['list'];
+        file_put_contents($filename, $this->request['listData']);
     }
 
-    private function getSettings()
+    public function getSettings()
     {
         $settings = array(
-                    'speed' => $this->uciGet("occupineapple.settings.speed"),
-                    'channel' => $this->uciGet("occupineapple.settings.channel"),
-                    'adHoc' => $this->uciGet("occupineapple.settings.adHoc"),
-                    'wepBit' => $this->uciGet("occupineapple.settings.wepBit"),
-                    'wpaTKIP' => $this->uciGet("occupineapple.settings.wpaTKIP"),
-                    'wpaAES' => $this->uciGet("occupineapple.settings.wpaAES"),
-                    'validMAC' => $this->uciGet("occupineapple.settings.validMAC")
+                    'speed' => $this->systemHelper->uciGet("occupineapple.settings.speed"),
+                    'channel' => $this->systemHelper->uciGet("occupineapple.settings.channel"),
+                    'adHoc' => $this->systemHelper->uciGet("occupineapple.settings.adHoc"),
+                    'wepBit' => $this->systemHelper->uciGet("occupineapple.settings.wepBit"),
+                    'wpaTKIP' => $this->systemHelper->uciGet("occupineapple.settings.wpaTKIP"),
+                    'wpaAES' => $this->systemHelper->uciGet("occupineapple.settings.wpaAES"),
+                    'validMAC' => $this->systemHelper->uciGet("occupineapple.settings.validMAC")
                     );
-        $this->response = array('settings' => $settings);
+        $this->responseHandler->setData(array('settings' => $settings));
     }
 
-    private function setSettings()
+    public function setSettings()
     {
-        $settings = $this->request->settings;
-        $this->uciSet("occupineapple.settings.speed", $settings->speed);
-        $this->uciSet("occupineapple.settings.channel", $settings->channel);
+        $settings = $this->request['settings'];
+        $this->systemHelper->uciSet("occupineapple.settings.speed", $settings->speed);
+        $this->systemHelper->uciSet("occupineapple.settings.channel", $settings->channel);
         if ($settings->adHoc) {
-            $this->uciSet("occupineapple.settings.adHoc", 1);
+            $this->systemHelper->uciSet("occupineapple.settings.adHoc", 1);
         } else {
-            $this->uciSet("occupineapple.settings.adHoc", 0);
+            $this->systemHelper->uciSet("occupineapple.settings.adHoc", 0);
         }
         if ($settings->wepBit) {
-            $this->uciSet("occupineapple.settings.wepBit", 1);
+            $this->systemHelper->uciSet("occupineapple.settings.wepBit", 1);
         } else {
-            $this->uciSet("occupineapple.settings.wepBit", 0);
+            $this->systemHelper->uciSet("occupineapple.settings.wepBit", 0);
         }
         if ($settings->wpaTKIP) {
-            $this->uciSet("occupineapple.settings.wpaTKIP", 1);
+            $this->systemHelper->uciSet("occupineapple.settings.wpaTKIP", 1);
         } else {
-            $this->uciSet("occupineapple.settings.wpaTKIP", 0);
+            $this->systemHelper->uciSet("occupineapple.settings.wpaTKIP", 0);
         }
         if ($settings->wpaAES) {
-            $this->uciSet("occupineapple.settings.wpaAES", 1);
+            $this->systemHelper->uciSet("occupineapple.settings.wpaAES", 1);
         } else {
-            $this->uciSet("occupineapple.settings.wpaAES", 0);
+            $this->systemHelper->uciSet("occupineapple.settings.wpaAES", 0);
         }
         if ($settings->validMAC) {
-            $this->uciSet("occupineapple.settings.validMAC", 1);
+            $this->systemHelper->uciSet("occupineapple.settings.validMAC", 1);
         } else {
-            $this->uciSet("occupineapple.settings.validMAC", 0);
+            $this->systemHelper->uciSet("occupineapple.settings.validMAC", 0);
         }
     }
 
-    private function saveAutostartSettings()
+    public function saveAutostartSettings()
     {
-        $settings = $this->request->settings;
-        $this->uciSet("occupineapple.autostart.interface", $settings->interface);
-        $this->uciSet("occupineapple.autostart.list", $settings->list);
+        $settings = $this->request['settings'];
+        $this->systemHelper->uciSet("occupineapple.autostart.interface", $settings->interface);
+        $this->systemHelper->uciSet("occupineapple.autostart.list", $settings->list);
     }
 }

+ 37 - 73
modules/src/OnlineHashCrack/api/module.php

@@ -1,49 +1,13 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class OnlineHashCrack extends Module
+/* Code modified by Frieren Auto Refactor */
+class OnlineHashCrack extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'refreshInfo':
-                $this->refreshInfo();
-                break;
-            case 'refreshOutput':
-                $this->refreshOutput();
-                break;
-            case 'clearOutput':
-                $this->clearOutput();
-                break;
-            case 'refreshStatus':
-                $this->refreshStatus();
-                break;
-            case 'handleDependencies':
-                $this->handleDependencies();
-                break;
-            case 'handleDependenciesStatus':
-                $this->handleDependenciesStatus();
-                break;
-            case 'submitWPAOnline':
-                $this->submitWPAOnline();
-                break;
-            case 'submitWPAOnlineStatus':
-                $this->submitWPAOnlineStatus();
-                break;
-            case 'getSettings':
-                $this->getSettings();
-                break;
-            case 'setSettings':
-                $this->setSettings();
-                break;
-            case 'getCapFiles':
-                $this->getCapFiles();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['refreshInfo', 'refreshOutput', 'clearOutput', 'refreshStatus', 'handleDependencies', 'handleDependenciesStatus', 'submitWPAOnline', 'submitWPAOnlineStatus', 'getSettings', 'setSettings', 'getCapFiles'];
 
     protected function checkDeps($dependencyName)
     {
-        return ($this->checkDependency($dependencyName) && ($this->uciGet("onlinehashcrack.module.installed")));
+        return ($this->systemHelper->checkDependency($dependencyName) && ($this->systemHelper->uciGet("onlinehashcrack.module.installed")));
     }
 
     protected function getDevice()
@@ -54,36 +18,36 @@ class OnlineHashCrack extends Module
     protected function refreshInfo()
     {
         $moduleInfo = @json_decode(file_get_contents("/pineapple/modules/OnlineHashCrack/module.info"));
-        $this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
+        $this->responseHandler->setData(array('title' => $moduleInfo->title, 'version' => $moduleInfo->version));
     }
 
-    private function handleDependencies()
+    public function handleDependencies()
     {
         if(!$this->checkDeps("curl"))
         {
-            $this->execBackground("/pineapple/modules/OnlineHashCrack/scripts/dependencies.sh install " . $this->request->destination);
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/OnlineHashCrack/scripts/dependencies.sh install " . $this->request['destination']);
+            $this->responseHandler->setData(array('success' => true));
         }
         else
         {
-            $this->execBackground("/pineapple/modules/OnlineHashCrack/scripts/dependencies.sh remove");
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/OnlineHashCrack/scripts/dependencies.sh remove");
+            $this->responseHandler->setData(array('success' => true));
         }
     }
 
-    private function handleDependenciesStatus()
+    public function handleDependenciesStatus()
     {
         if (!file_exists('/tmp/OnlineHashCrack.progress'))
         {
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         }
         else
         {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function refreshStatus()
+    public function refreshStatus()
     {
         if (!file_exists('/tmp/OnlineHashCrack.progress'))
         {
@@ -110,68 +74,68 @@ class OnlineHashCrack extends Module
             $processing = true;
         }
 
-        $device = $this->getDevice();
-        $sdAvailable = $this->isSDAvailable();
+        $device = $this->systemHelper->getDevice();
+        $sdAvailable = $this->systemHelper->isSDAvailable();
 
-        $this->response = array("device" => $device, "sdAvailable" => $sdAvailable, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "processing" => $processing);
+        $this->responseHandler->setData(array("device" => $device, "sdAvailable" => $sdAvailable, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "processing" => $processing));
     }
 
-    private function refreshOutput()
+    public function refreshOutput()
     {
         if (file_exists("/tmp/onlinehashcrack.log"))
         {
             $output = file_get_contents("/tmp/onlinehashcrack.log");
             if(!empty($output))
-                $this->response = $output;
+                $this->responseHandler->setData($output);
             else
-                $this->response = " ";
+                $this->responseHandler->setData(" ");
         }
         else
         {
-             $this->response = " ";
+             $this->responseHandler->setData(" ");
         }
     }
 
-    private function clearOutput()
+    public function clearOutput()
     {
         exec("rm -rf /tmp/onlinehashcrack.log");
     }
 
-    private function submitWPAOnlineStatus()
+    public function submitWPAOnlineStatus()
     {
         if (!file_exists('/tmp/OnlineHashCrack.progress'))
         {
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         }
         else
         {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function submitWPAOnline()
+    public function submitWPAOnline()
     {
-        $this->execBackground("/pineapple/modules/OnlineHashCrack/scripts/submit_wpa.sh ".$this->request->file);
-        $this->response = array('success' => true);
+        $this->systemHelper->execBackground("/pineapple/modules/OnlineHashCrack/scripts/submit_wpa.sh ".$this->request['file']);
+        $this->responseHandler->setData(array('success' => true));
     }
 
-    private function getSettings()
+    public function getSettings()
     {
         $settings = array(
-                    'email' => $this->uciGet("onlinehashcrack.settings.email")
+                    'email' => $this->systemHelper->uciGet("onlinehashcrack.settings.email")
                     );
-        $this->response = array('settings' => $settings);
+        $this->responseHandler->setData(array('settings' => $settings));
     }
 
-    private function setSettings()
+    public function setSettings()
     {
-        $settings = $this->request->settings;
-        $this->uciSet("onlinehashcrack.settings.email", $settings->email);
+        $settings = $this->request['settings'];
+        $this->systemHelper->uciSet("onlinehashcrack.settings.email", $settings->email);
     }
 
-    private function getCapFiles()
+    public function getCapFiles()
     {
         exec("find -L /pineapple/modules/ -type f -name \"*.**cap\" -o -name \"*.**pcap\" -o -name \"*.**pcapng\" -o -name \"*.**hccapx\" 2>&1", $filesArray);
-        $this->response = array("files" => $filesArray);
+        $this->responseHandler->setData(array("files" => $filesArray));
     }
 }

+ 53 - 81
modules/src/OpenVPNConnect/api/module.php

@@ -1,51 +1,23 @@
 <?php 
 
 // Define the pineapple namespace
-namespace pineapple;
+namespace frieren\core;
+
+/* Code modified by Frieren Auto Refactor */
 
 // Upload Directory where we store vpn_configs
 define('__UPLOAD__', "/root/vpn_config/");
 
 /* Main module class for OpenVPNConnect */
-class OpenVPNConnect extends Module{
-
-    // Set up our routes for our angular functions to call
-    public function route(){
-
-        switch ($this->request->action) {
-
-            case 'startVPN':
-                $this->startVPN();
-                break;
-            case 'stopVPN':
-                $this->stopVPN();
-                break;
-            case 'checkVPNStatus':
-                $this->checkVPNStatus();
-                break;
-            case 'initializeModule':
-                $this->initializeModule();
-                break;
-            case 'handleDependencies':
-                $this->handleDependencies(false);
-                break;
-            case 'handleDependenciesSDCard':
-                $this->handleDependenciesSDCard();
-                break;
-            case 'checkDependencies':
-                $this->checkDependencies();
-                break;
-            case 'uploadFile':
-                $this->uploadFile();
-                break;
-        }
-    }
+class OpenVPNConnect extends Controller{
+
+    protected $endpointRoutes = ['startVPN', 'stopVPN', 'checkVPNStatus', 'initializeModule', 'handleDependencies', 'handleDependenciesSDCard', 'checkDependencies', 'uploadFile'];
 
 
     // Checks the dependencies using the pineapple API functions 
-    private function checkDependencies(){
+    public function checkDependencies(){
         $installedFlag = false;
-        if($this->checkDependency('openvpn')){
+        if($this->systemHelper->checkDependency('openvpn')){
             $installLabel = 'success';
             $installLabelText = 'Installed';
             $installButtonWidth = "90px";
@@ -58,24 +30,24 @@ class OpenVPNConnect extends Module{
             $installLabelSDText = "Not Installed (SD Card)";
         }
          
-        $this->response = array("success" => true,
+        $this->responseHandler->setData(array("success" => true,
                                 "label" => $installLabel,
                                 "text"  => $installLabelText,
                                 "buttonWidth" => $installButtonWidth,
                                 "textSD" => $installLabelSDText,
-                                "installed" => $installedFlag);
+                                "installed" => $installedFlag));
 
     }
 
     // Initializes the module by checking for/creating the required vpn_config directory in /root
-    private function initializeModule(){
+    public function initializeModule(){
 
         $result = exec('cd /root && ls | grep vpn_config');
 
         if($result == 'vpn_config'){
             $result = "VPN Connect is ready!";
         }else{
-            $this->execBackground('cd /root && mkdir vpn_config');
+            $this->systemHelper->execBackground('cd /root && mkdir vpn_config');
 
             $result = exec('cd /root && ls | grep vpn_config');
 
@@ -95,22 +67,22 @@ class OpenVPNConnect extends Module{
             array_push($cert_arr, (object)array('name' => $cert));
         }
 
-        $this->response = array("success" => true,
+        $this->responseHandler->setData(array("success" => true,
                                 "content" => $result,
-                                "certs" => $cert_arr);
+                                "certs" => $cert_arr));
 
     }
 
     // Handles dependency installation and removal
-    private function handleDependencies($sd){
+    public function handleDependencies($sd){
 
-        if($this->checkDependency('openvpn')){
-            $this->execBackground('opkg remove openvpn-openssl');
+        if($this->systemHelper->checkDependency('openvpn')){
+            $this->systemHelper->execBackground('opkg remove openvpn-openssl');
             $messsage = "Dependencies should now be removed! Note: the vpn_config directory is NOT removed in this process. Please wait for the page to refresh...";
         }else{
             if($sd){
-                $this->execBackground('opkg update');
-                $this->execBackground('opkg install openvpn-openssl --dest sd');
+                $this->systemHelper->execBackground('opkg update');
+                $this->systemHelper->execBackground('opkg install openvpn-openssl --dest sd');
                 $messsage = "Depedencies should now be installed! (Installed to SD card) Please wait for the page to refresh...";
             }else{
                 $this->installDependency('openvpn-openssl');
@@ -119,13 +91,13 @@ class OpenVPNConnect extends Module{
 
         }
          
-        $this->response = array("success" => true,
+        $this->responseHandler->setData(array("success" => true,
                                 "content" => $messsage,
-                                "test" => $sd);
+                                "test" => $sd));
     }
 
     // Helper function to handle dependency installation and removal for sd card. Passes the SD flag to the real handleDependencies() function
-    private function handleDependenciesSDCard(){
+    public function handleDependenciesSDCard(){
 
         $sd = true;
 
@@ -135,24 +107,24 @@ class OpenVPNConnect extends Module{
 
 
     // Checks whether or not OpenVPN is currently running
-    private function checkVPNStatus(){
+    public function checkVPNStatus(){
         $result = exec("pgrep openvpn");
 
         if($result){
-            $this->response = array("success" => true,
-            "content" => "VPN Running...");
+            $this->responseHandler->setData(array("success" => true,
+            "content" => "VPN Running..."));
             return;
         }
 
-        $this->response = array("success" => true,
-        "content" => "VPN Stopped...");
+        $this->responseHandler->setData(array("success" => true,
+        "content" => "VPN Stopped..."));
 
     }
 
     // Builds the openvpn command string and calls it to start the VPN
-    private function startVPN(){
+    public function startVPN(){
 
-        $inputData = $this->request->data;
+        $inputData = $this->request['data'];
 
         $open_vpn_cmd = "openvpn --log /pineapple/modules/OpenVPNConnect/log/vpn.log --status /pineapple/modules/OpenVPNConnect/log/status.log --config ";
         
@@ -160,8 +132,8 @@ class OpenVPNConnect extends Module{
             $config_name = escapeshellcmd($inputData[0]);
             $open_vpn_cmd .= "/root/vpn_config/" . $config_name . " ";
         }else{
-            $this->response = array("success" => false,
-                                    "content" => "Please specify a VPN config name..");
+            $this->responseHandler->setData(array("success" => false,
+                                    "content" => "Please specify a VPN config name.."));
             return;
         }
 
@@ -195,47 +167,47 @@ class OpenVPNConnect extends Module{
         
         if($inputData[4] == true){
         //Share VPN With Clients Connecting
-            $gateway = $this->uciGet("network.lan.gateway");
-            $netmask = $this->uciGet("network.lan.netmask");
+            $gateway = $this->systemHelper->uciGet("network.lan.gateway");
+            $netmask = $this->systemHelper->uciGet("network.lan.netmask");
 
-            $this->execBackground("iptables -t nat -A POSTROUTING -s ". $gateway ."/". $netmask. " -o tun0 -j MASQUERADE");
-            $this->execBackground("iptables -A FORWARD -s ". $gateway ."/". $netmask . " -o tun0 -j ACCEPT");
-            $this->execBackground("iptables -A FORWARD -d ". $gateway ."/". $netmask ." -m state --state ESTABLISHED,RELATED -i tun0 -j ACCEPT");
+            $this->systemHelper->execBackground("iptables -t nat -A POSTROUTING -s ". $gateway ."/". $netmask. " -o tun0 -j MASQUERADE");
+            $this->systemHelper->execBackground("iptables -A FORWARD -s ". $gateway ."/". $netmask . " -o tun0 -j ACCEPT");
+            $this->systemHelper->execBackground("iptables -A FORWARD -d ". $gateway ."/". $netmask ." -m state --state ESTABLISHED,RELATED -i tun0 -j ACCEPT");
         }
 
-        $result = $this->execBackground($open_vpn_cmd);
+        $result = $this->systemHelper->execBackground($open_vpn_cmd);
         
-        $this->response = array("success" => true,
-                                "content" => "VPN Running... ");
+        $this->responseHandler->setData(array("success" => true,
+                                "content" => "VPN Running... "));
     }
 
 
     // Calls pkill to kill the OpenVPN process and stop the VPN
-    private function stopVPN(){
+    public function stopVPN(){
 
         //Remove any creds files that could have been created, don't want any creds lying around ;)
         unlink("/tmp/vpn_auth.txt");
         unlink("/tmp/vpn_pass.txt");
 
         //Delete any iptable rules that may have been created for sharing connection with clients                
-        $gateway = $this->uciGet("network.lan.gateway");
-        $netmask = $this->uciGet("network.lan.netmask");
+        $gateway = $this->systemHelper->uciGet("network.lan.gateway");
+        $netmask = $this->systemHelper->uciGet("network.lan.netmask");
 
-        $this->execBackground("iptables -t nat -D POSTROUTING -s ". $gateway ."/". $netmask. " -o tun0 -j MASQUERADE");
-        $this->execBackground("iptables -D FORWARD -s ". $gateway ."/". $netmask . " -o tun0 -j ACCEPT");
-        $this->execBackground("iptables -D FORWARD -d ". $gateway ."/". $netmask ." -m state --state ESTABLISHED,RELATED -i tun0 -j ACCEPT");
+        $this->systemHelper->execBackground("iptables -t nat -D POSTROUTING -s ". $gateway ."/". $netmask. " -o tun0 -j MASQUERADE");
+        $this->systemHelper->execBackground("iptables -D FORWARD -s ". $gateway ."/". $netmask . " -o tun0 -j ACCEPT");
+        $this->systemHelper->execBackground("iptables -D FORWARD -d ". $gateway ."/". $netmask ." -m state --state ESTABLISHED,RELATED -i tun0 -j ACCEPT");
         
         //Kill openvpn
-        $this->execBackground("pkill openvpn");
+        $this->systemHelper->execBackground("pkill openvpn");
 
-        $this->response = array("success" => true,
-                                "content" => "VPN Stopped...");
+        $this->responseHandler->setData(array("success" => true,
+                                "content" => "VPN Stopped..."));
     }
 
     // Uploads the .ovnp recieved from the service
-    private function uploadFile(){
+    public function uploadFile(){
                    
-            $inputData = $this->request->file;
+            $inputData = $this->request['file'];
 
             $fileName = $inputData[0];
 
@@ -248,7 +220,7 @@ class OpenVPNConnect extends Module{
                     
             // Do not accept any file other than .ovpn
             if ($type != "ovpn") {
-                $this->response = array("success" => false);
+                $this->responseHandler->setData(array("success" => false));
                 return;
             }
                     
@@ -256,7 +228,7 @@ class OpenVPNConnect extends Module{
             if (!file_exists(__UPLOAD__)) {
                 if (!mkdir(__UPLOAD__, 0755, true)) {
                     $response[$name] = "Failed. Unable to upload because vpn_certs directory does not exist/could not be created!";
-                        $this->response = array("success" => false);
+                        $this->responseHandler->setData(array("success" => false));
                         return;
                     }
                 }
@@ -271,7 +243,7 @@ class OpenVPNConnect extends Module{
             }
         
 
-            $this->response = array("success" => $response[$name]);
+            $this->responseHandler->setData(array("success" => $response[$name]));
                 
     }
     

+ 44 - 86
modules/src/PMKIDAttack/api/module.php

@@ -1,11 +1,14 @@
 <?php
 
-namespace pineapple;
+namespace frieren\core;
+
+/* Code modified by Frieren Auto Refactor */
 
 require_once("/pineapple/modules/PineAP/api/PineAPHelper.php");
 
-class PMKIDAttack extends Module
+class PMKIDAttack extends Controller
 {
+    protected $endpointRoutes = ['clearLog', 'getLog', 'getDependenciesStatus', 'managerDependencies', 'getDependenciesInstallStatus', 'startAttack', 'stopAttack', 'catchPMKID', 'getPMKIDFiles', 'downloadPMKID', 'deletePMKID', 'viewAttackLog', 'getStatusAttack'];
     const MODULE_PATH = "/pineapple/modules/PMKIDAttack";
     const LOG_PATH = "/pineapple/modules/PMKIDAttack/log/module.log";
     const CAPTURE_PATH = "/pineapple/modules/PMKIDAttack/pcapng";
@@ -14,54 +17,9 @@ class PMKIDAttack extends Module
     const TOOLS_PATH = "/sbin/";
     const TOOLS_SD_PATH = "/sd/sbin/";
 
-    public function route()
-    {
-        switch ($this->request->action) {
-            case "clearLog":
-                $this->clearLog();
-                break;
-            case "getLog":
-                $this->getLog();
-                break;
-            case "getDependenciesStatus":
-                $this->getDependenciesStatus();
-                break;
-            case "managerDependencies":
-                $this->managerDependencies();
-                break;
-            case "getDependenciesInstallStatus":
-                $this->getDependenciesInstallStatus();
-                break;
-            case "startAttack":
-                $this->startAttack();
-                break;
-            case "stopAttack":
-                $this->stopAttack();
-                break;
-            case "catchPMKID":
-                $this->catchPMKID();
-                break;
-            case "getPMKIDFiles":
-                $this->getPMKIDFiles();
-                break;
-            case "downloadPMKID":
-                $this->downloadPMKID();
-                break;
-            case "deletePMKID":
-                $this->deletePMKID();
-                break;
-            case "viewAttackLog":
-                $this->viewAttackLog();
-                break;
-            case "getStatusAttack":
-                $this->getStatusAttack();
-                break;
-        }
-    }
-
     protected function getToolPath($tool)
     {
-        if ($this->isSDAvailable() && file_exists(self::TOOLS_SD_PATH . $tool)) {
+        if ($this->systemHelper->isSDAvailable() && file_exists(self::TOOLS_SD_PATH . $tool)) {
             return self::TOOLS_SD_PATH . $tool;
         }
 
@@ -86,7 +44,7 @@ class PMKIDAttack extends Module
             touch(self::LOG_PATH);
         }
 
-        $this->response = ["moduleLog" => file_get_contents(self::LOG_PATH)];
+        $this->responseHandler->setData(["moduleLog" => file_get_contents(self::LOG_PATH)]);
     }
 
     protected function addLog($massage)
@@ -117,12 +75,12 @@ class PMKIDAttack extends Module
             $response["installed"] = true;
         }
 
-        $this->response = $response;
+        $this->responseHandler->setData($response);
     }
 
     protected function checkPanelVersion()
     {
-        $version = \helper\getFirmwareVersion();
+        $version = $this->systemHelper->getFirmwareVersion();
         $version = str_replace("+", "", $version);
 
         return version_compare($version, "2.8.0") >= 0;
@@ -130,12 +88,12 @@ class PMKIDAttack extends Module
 
     protected function checkDependencyInstalled()
     {      
-        if ($this->uciGet("pmkidattack.@config[0].installed")) {
+        if ($this->systemHelper->uciGet("pmkidattack.@config[0].installed")) {
             return true; 
         }
 
-        if ($this->checkDependency("hcxdumptool")) {
-            $this->uciSet("pmkidattack.@config[0].installed", "1");
+        if ($this->systemHelper->checkDependency("hcxdumptool")) {
+            $this->systemHelper->uciSet("pmkidattack.@config[0].installed", "1");
             return true; 
         }
 
@@ -148,42 +106,42 @@ class PMKIDAttack extends Module
         $command = self::MODULE_PATH . "/scripts/dependencies.sh";
 
         $this->stopAttack();
-        $this->execBackground("{$command} {$action}");
+        $this->systemHelper->execBackground("{$command} {$action}");
 
-        $this->response = ["success" => true];
+        $this->responseHandler->setData(["success" => true]);
     }
 
     protected function getDependenciesInstallStatus()
     {
-        $this->response = ["success" => !file_exists(self::DEPS_FLAG)];
+        $this->responseHandler->setData(["success" => !file_exists(self::DEPS_FLAG)]);
     }
 
     protected function getMonitorInterface()
     {
-        return $this->uciGet("pineap.@config[0].pineap_interface");
+        return $this->systemHelper->uciGet("pineap.@config[0].pineap_interface");
     }
 
     protected function getBSSID($clean = false)
     {
-        $bssid = $this->uciGet("pmkidattack.@config[0].bssid");
+        $bssid = $this->systemHelper->uciGet("pmkidattack.@config[0].bssid");
 
         return $clean ? str_replace(":", "", $bssid) : $bssid;
     }
 
     protected function getProcessStatus()
     {
-        return \helper\checkRunning($this->getToolPath("hcxdumptool"));
+        return $this->systemHelper->heckRunning($this->getToolPath("hcxdumptool"));
     }
 
     protected function startAttack()
     {
-        $ssid = $this->request->ssid;
-        $bssid = $this->request->bssid;
+        $ssid = $this->request['ssid'];
+        $bssid = $this->request['bssid'];
 
         //$this->execBackground("{$this->moduleFolder}/scripts/PMKIDAttack.sh start " . $this->request->bssid);
-        $this->uciSet("pmkidattack.@config[0].ssid", $ssid);
-        $this->uciSet("pmkidattack.@config[0].bssid", $bssid);
-        $this->uciSet("pmkidattack.@config[0].attack", "1");
+        $this->systemHelper->uciSet("pmkidattack.@config[0].ssid", $ssid);
+        $this->systemHelper->uciSet("pmkidattack.@config[0].bssid", $bssid);
+        $this->systemHelper->uciSet("pmkidattack.@config[0].attack", "1");
 
         $pineAPHelper = new PineAPHelper();
         $pineAPHelper->disablePineAP();
@@ -202,11 +160,11 @@ class PMKIDAttack extends Module
 
         exec("echo {$cleanBSSID} > {$filterPath}");
         $command = "{$hcxdumptoolPath} -o {$capPath} -i {$interface} --filterlist_ap={$filterPath} --filtermode=2 --enable_status=1";
-        $this->execBackground($command);
+        $this->systemHelper->execBackground($command);
         $this->addLog("Start attack {$bssid}");
         $this->addLog($command);
 
-        $this->response = ["success" => true];
+        $this->responseHandler->setData(["success" => true]);
     }
 
     protected function stopAttack()
@@ -218,12 +176,12 @@ class PMKIDAttack extends Module
         exec("/usr/bin/pkill hcxdumptool");
         exec("rm {$capPath}");
 
-        $this->uciSet("pmkidattack.@config[0].ssid", "");
-        $this->uciSet("pmkidattack.@config[0].bssid", "");
-        $this->uciSet("pmkidattack.@config[0].attack", "0");
+        $this->systemHelper->uciSet("pmkidattack.@config[0].ssid", "");
+        $this->systemHelper->uciSet("pmkidattack.@config[0].bssid", "");
+        $this->systemHelper->uciSet("pmkidattack.@config[0].attack", "0");
         $this->addLog("Stop attack {$BSSIDFormatted}");
 
-        $this->response = ["success" => true];
+        $this->responseHandler->setData(["success" => true]);
     }
 
 
@@ -238,18 +196,18 @@ class PMKIDAttack extends Module
 
             $this->addLog("PMKID {$BSSIDFormatted} intercepted!");
             $metadata = json_encode([
-                'ssid' => $this->uciGet("pmkidattack.@config[0].ssid"),
+                'ssid' => $this->systemHelper->uciGet("pmkidattack.@config[0].ssid"),
                 'bssid' => $BSSIDFormatted
             ]);
             file_put_contents("{$captureFolder}/{$BSSID}.data", $metadata);
             exec("cp {$capPath} {$captureFolder}/");
         }
 
-        $this->response = [
+        $this->responseHandler->setData([
             "pmkidLog" => $check['log'],
             "process" => $check['process'],
             "success" => $check['status'],
-        ];
+        ]);
     }
 
     protected function checkPMKID()
@@ -299,12 +257,12 @@ class PMKIDAttack extends Module
             ];
         }
 
-        $this->response = ["pmkids" => $pmkids];
+        $this->responseHandler->setData(["pmkids" => $pmkids]);
     }
 
     protected function downloadPMKID()
     {
-        $file = $this->request->file;
+        $file = $this->request['file'];
         $workingDir = "/tmp/PMKIDAttack";
         $captureFolder = self::CAPTURE_PATH;
         $hcxpcaptoolPath = $this->getToolPath("hcxpcapngtool");
@@ -315,21 +273,21 @@ class PMKIDAttack extends Module
         exec("cd {$workingDir}/ && tar -czf /tmp/{$file}.tar.gz *");
         exec("rm -rf {$workingDir}/");
 
-        $this->response = ["download" => $this->downloadFile("/tmp/{$file}.tar.gz")];
+        $this->responseHandler->setData(["download" => $this->systemHelper->downloadFile("/tmp/{$file}.tar.gz")]);
     }
 
     protected function deletePMKID()
     {
-        $file = escapeshellarg($this->request->file);
+        $file = escapeshellarg($this->request['file']);
         $captureFolder = self::CAPTURE_PATH;
         exec("rm {$captureFolder}/{$file}.pcapng {$captureFolder}/{$file}.data");
 
-        $this->response = ["success" => true];
+        $this->responseHandler->setData(["success" => true]);
     }
 
     protected function viewAttackLog()
     {
-        $file = $this->request->file;
+        $file = $this->request['file'];
         $exportPath = self::EXPORT_PATH;
         $captureFolder = self::CAPTURE_PATH;
         $hcxpcaptoolPath = $this->getToolPath("hcxpcapngtool");
@@ -337,16 +295,16 @@ class PMKIDAttack extends Module
         $capPath = empty($file) ? $this->getCapPath() : escapeshellarg("{$captureFolder}/{$file}.pcapng");
         exec("{$hcxpcaptoolPath} -o {$exportPath} {$capPath}", $result);
 
-        $this->response = ["pmkidLog" => implode("\n", $result)];
+        $this->responseHandler->setData(["pmkidLog" => implode("\n", $result)]);
     }
 
     protected function getStatusAttack()
     {
-        $this->response = [
+        $this->responseHandler->setData([
             "process" => $this->getProcessStatus(),
-            "ssid" => $this->uciGet("pmkidattack.@config[0].ssid"),
-            "bssid" => $this->uciGet("pmkidattack.@config[0].bssid"),
-            "attack" => $this->uciGet("pmkidattack.@config[0].attack") === true,
-        ];
+            "ssid" => $this->systemHelper->uciGet("pmkidattack.@config[0].ssid"),
+            "bssid" => $this->systemHelper->uciGet("pmkidattack.@config[0].bssid"),
+            "attack" => $this->systemHelper->uciGet("pmkidattack.@config[0].attack") === true,
+        ]);
     }
 }

+ 40 - 104
modules/src/Papers/api/module.php

@@ -1,6 +1,8 @@
 <?php
 
-namespace pineapple;
+namespace frieren\core;
+/* Code modified by Frieren Auto Refactor */
+
 define('__INCLUDES__', "/pineapple/modules/Papers/includes/");
 define('__SCRIPTS__', __INCLUDES__ . "scripts/");
 define('__SSLSTORE__', __INCLUDES__ . "ssl/");
@@ -50,76 +52,10 @@ if (!empty($_FILES)) {
 }
 
 
-class Papers extends Module
+class Papers extends Controller
 {
-	public function route() {
-		switch ($this->request->action) {
-			case 'init':
-				$this->init();
-				break;
-			case 'checkDepends':
-				$this->checkDepends();
-				break;
-			case 'installDepends':
-				$this->installDepends();
-				break;
-			case 'removeDepends':
-				$this->removeDepends();
-				break;
-			case 'buildCert':
-				$this->buildCert($this->request->parameters);
-				break;
-			case 'encryptKey':
-				$this->respond($this->encryptKey($this->request->keyName, $this->request->keyType, $this->request->keyAlgo, $this->request->keyPass));
-				break;
-			case 'decryptKey':
-				$this->respond($this->decryptKey($this->request->keyName, $this->request->keyType, $this->request->keyPass));
-				break;
-			case 'genSSHKeys':
-				$this->genSSHKeys($this->request->parameters);
-				break;
-			case 'loadCertificates':
-				$this->loadCertificates();
-				break;
-			case 'loadCertProps':
-				$this->loadCertificateProperties($this->request->certName);
-        break;
-      case 'loadSSHKeys':
-        $this->loadSSHKeys($this->request->keyName);
-        break;
-			case 'downloadKeys':
-				$this->downloadKeys($this->request->parameters->name, $this->request->parameters->type);
-				break;
-			case 'clearDownloadArchive':
-				$this->clearDownloadArchive();
-				break;
-			case 'removeCertificate':
-				$this->removeCertificate($this->request->params->cert, $this->request->params->type);
-				break;
-			case 'securePineapple':
-				$this->securePineapple($this->request->params->cert, $this->request->params->type);
-				break;
-			case 'getNginxSSLCerts':
-				$this->getNginxSSLCerts();
-				break;
-			case 'unSSLPineapple':
-				$this->unSSLPineapple();
-				break;
-			case 'revokeSSHKey':
-				$this->revokeSSHKey($this->request->key);
-				break;
-			case 'getLogs':
-				$this->getLogs($this->request->type);
-				break;
-			case 'readLog':
-				$this->retrieveLog($this->request->parameters, $this->request->type);
-				break;
-			case 'deleteLog':
-				$this->deleteLog($this->request->parameters);
-				break;
-		}
-	}
-	private function init() {
+	protected $endpointRoutes = ['init', 'checkDepends', 'installDepends', 'removeDepends', 'buildCert', 'encryptKey', 'decryptKey', 'genSSHKeys', 'loadCertificates', 'loadCertProps', 'loadSSHKeys', 'downloadKeys', 'clearDownloadArchive', 'removeCertificate', 'securePineapple', 'getNginxSSLCerts', 'unSSLPineapple', 'revokeSSHKey', 'getLogs', 'readLog', 'deleteLog'];
+	public function init() {
 		if (!file_exists(__LOGS__)) {
 			if (!mkdir(__LOGS__, 0755, true)) {
 				$this->respond(false, "Failed to create logs directory");
@@ -151,7 +87,7 @@ class Papers extends Module
 			}
 		}
 	}
-	private function checkDepends() {
+	public function checkDepends() {
 		$retData = array();
 		exec(__SCRIPTS__ . "checkDepends.sh", $retData);
 		if (implode(" ", $retData) == "Installed") {
@@ -160,7 +96,7 @@ class Papers extends Module
 			$this->respond(false);
 		}
 	}
-	private function installDepends() {
+	public function installDepends() {
 		$retData = array();
 		exec(__SCRIPTS__ . "installDepends.sh", $retData);
 		if (implode(" ", $retData) == "Complete") {
@@ -169,12 +105,12 @@ class Papers extends Module
 			$this->respond(false);
 		}
 	}
-	private function removeDepends() {
+	public function removeDepends() {
 		// removeDepends.sh doesn't return anything whether successful or not
 		exec(__SCRIPTS__ . "removeDepends.sh");
 		$this->respond(true);
 	}
-	private function genSSHKeys($paramsObj) {
+	public function genSSHKeys($paramsObj) {
 		$keyInfo = array();
 		$params = (array)$paramsObj;
 		
@@ -203,7 +139,7 @@ class Papers extends Module
 		}
 		$this->respond(true);
 	}
-	private function buildCert($paramsObj) {
+	public function buildCert($paramsObj) {
 		$certInfo = array();
 		$req = array();
 		$params = (array)$paramsObj;
@@ -291,7 +227,7 @@ class Papers extends Module
 		$this->respond(true, "Keys created successfully!");
 	}
 	
-	private function encryptKey($keyName, $keyType, $algo, $pass) {
+	public function encryptKey($keyName, $keyType, $algo, $pass) {
     $retData = array();
     $cmdString = "encryptRSAKeys.sh --encrypt -k {$keyName}.key -a {$algo}";
 
@@ -308,7 +244,7 @@ class Papers extends Module
 		return true;
 	}
 	
-	private function decryptKey($keyName, $keyType, $pass) {
+	public function decryptKey($keyName, $keyType, $pass) {
     $retData = array();
     $cmdString = "decryptRSAKeys.sh -k {$keyName}.key";
 
@@ -329,7 +265,7 @@ class Papers extends Module
 		Generates an OpenSSL config file based on the passed in requirements ($req)
 		and returns the path to the file.
 	*/
-	private function generateSSLConfig($keyName, $req) {
+	public function generateSSLConfig($keyName, $req) {
 		$conf = file_get_contents(__SSL_TEMPLATE__);
 		
 		foreach ($req as $k => $v) {
@@ -358,13 +294,13 @@ class Papers extends Module
 		return $path;
 	}
 
-	private function loadCertificates() {
+	public function loadCertificates() {
 		$certs = $this->getKeys(__SSLSTORE__);
 		$certs = array_merge($certs, $this->getKeys(__SSHSTORE__));
 		$this->respond(true,null,$certs);
 	}
 	
-	private function loadCertificateProperties($cert) {
+	public function loadCertificateProperties($cert) {
 		$retData = array();
 		$res = [];
 		
@@ -390,7 +326,7 @@ class Papers extends Module
 		return true;
   }
   
-  private function loadSSHKeys($name) {
+  public function loadSSHKeys($name) {
     $this->respond(true, null, array(
       "privkey" => file_get_contents(__SSHSTORE__ . "{$name}.key"),
       "pubkey" => file_get_contents(__SSHSTORE__ . "{$name}.pub"))
@@ -398,7 +334,7 @@ class Papers extends Module
     return true;
   }
 	
-	private function getKeys($dir) {
+	public function getKeys($dir) {
 		$keyType = ($dir == __SSLSTORE__) ? "TLS/SSL" : "SSH";
 		$keys = scandir($dir);
 		$certs = array();
@@ -425,7 +361,7 @@ class Papers extends Module
 		return $certs;
 	}
 	
-	private function checkSSHKeyAuth($keyName, $keyType) {
+	public function checkSSHKeyAuth($keyName, $keyType) {
 		if ($keyType != "SSH") {return false;}
 		$res = exec(__SCRIPTS__ . "checkSSHKey.sh -k " . $keyName);
 		if ($res == "TRUE") {
@@ -434,12 +370,12 @@ class Papers extends Module
 		return false;
 	}
 	
-	private function revokeSSHKey($keyName) {
+	public function revokeSSHKey($keyName) {
 		exec(__SCRIPTS__ . "revokeSSHKey.sh -k " . $keyName);
 		$this->respond(true);
 	}
 
-	private function keyIsEncrypted($keyName, $keyType) {
+	public function keyIsEncrypted($keyName, $keyType) {
 		$data = array();
     $keyDir = ($keyType == "SSH") ? __SSHSTORE__ : __SSLSTORE__;
     $type = ($keyType == "SSH") ? "SSH" : "RSA";
@@ -451,7 +387,7 @@ class Papers extends Module
 		}
 	}
 
-	private function downloadKeys($keyName, $keyType) {
+	public function downloadKeys($keyName, $keyType) {
 		$argString = "-o " . $keyName . ".zip -f \"";
 
 		// Grab all of the keys, certs, and containers
@@ -484,13 +420,13 @@ class Papers extends Module
 
 		// Begin downloading the archive
 		if ($archiveExists) {
-			$this->respond(true, null, $this->downloadFile(__DOWNLOAD__ . $keyName . ".zip"));
+			$this->respond(true, null, $this->systemHelper->downloadFile(__DOWNLOAD__ . $keyName . ".zip"));
 		} else {
 			$this->respond(false, "Failed to create archive.");
 		}
 	}
 
-	private function clearDownloadArchive() {
+	public function clearDownloadArchive() {
 		foreach (scandir(__DOWNLOAD__) as $file) {
 			if (substr($file, 0, 1) == ".") {continue;}
 			unlink(__DOWNLOAD__ . $file);
@@ -502,7 +438,7 @@ class Papers extends Module
 		$this->respond(true);
 	}
 
-	private function objNameExistsInArray($name, $arr) {
+	public function objNameExistsInArray($name, $arr) {
 		foreach ($arr as $x) {
 			if ($x->Name == $name) {
 				return True;
@@ -511,7 +447,7 @@ class Papers extends Module
 		return False;
 	}
 
-	private function removeCertificate($delCert, $keyType) {
+	public function removeCertificate($delCert, $keyType) {
 		$res = True;
 		$msg = "Failed to delete the following files:";
 		$keyDir = ($keyType == "SSH") ? __SSHSTORE__ : __SSLSTORE__;
@@ -527,11 +463,11 @@ class Papers extends Module
 		$this->respond($res, $msg);
 	}
 
-	private function respond($success, $msg = null, $data = null, $error = null) {
-		$this->response = array("success" => $success,"message" => $msg, "data" => $data, "error" => $error);
+	public function respond($success, $msg = null, $data = null, $error = null) {
+		$this->responseHandler->setData(array("success" => $success,"message" => $msg, "data" => $data, "error" => $error));
 	}
 
-	private function getNginxSSLCerts() {
+	public function getNginxSSLCerts() {
 		$res = $this->checkSSLConfig();
 		if ($res == "") {
 			$this->respond(false, array("[!] SSL keys not configured in nginx.conf"));
@@ -540,13 +476,13 @@ class Papers extends Module
 		}
 	}
 
-	private function checkSSLConfig() {
+	public function checkSSLConfig() {
 		$retData = array();
 		exec(__SCRIPTS__ . "cfgNginx.py --getSSLCerts", $retData);
 		return implode(" ", $retData);
 	}
 
-	private function unSSLPineapple() {
+	public function unSSLPineapple() {
 		// First check if SSL is configured
 		if ($this->checkSSLConfig() == "") {
 			$this->respond(true);
@@ -570,7 +506,7 @@ class Papers extends Module
 		$this->respond($status);
 	}
 
-	private function securePineapple($certName, $keyType) {
+	public function securePineapple($certName, $keyType) {
 		// Check the key type to determine whether we are adding an SSH key or SSL keys
 		if ($keyType == "SSH") {
 			// Modify authorized_keys file
@@ -582,7 +518,7 @@ class Papers extends Module
 		}
 	}
 	
-	private function SSLPineapple($certName) {
+	public function SSLPineapple($certName) {
 		// Check if nginx SSL directory exists
 		$nginx_ssl_dir = "/etc/nginx/ssl/";
 		if (!file_exists($nginx_ssl_dir)) {
@@ -619,7 +555,7 @@ class Papers extends Module
 		$this->respond(false, "An error occurred.  Check the logs for details.");
 	}
 
-	private function replaceSSLCerts($certName) {
+	public function replaceSSLCerts($certName) {
 		// Remove the old keys from the SSL store
 		$this->removeKeysFromNginx();
 
@@ -639,7 +575,7 @@ class Papers extends Module
 		$this->respond(false);
 		return;
 	}
-	private function copyKeysToNginx($certName) {
+	public function copyKeysToNginx($certName) {
 		// Copy selected key pair to the SSL directory
 		$retData = array();
 		$res = exec(__SCRIPTS__ . "copyKeys.sh " . __SSLSTORE__ . $certName, $retData);
@@ -649,7 +585,7 @@ class Papers extends Module
 		}
 		return True;
 	}
-	private function removeKeysFromNginx() {
+	public function removeKeysFromNginx() {
 		$keys = $this->checkSSLConfig();
 		$retData = array();
 		$res = exec(__SCRIPTS__ . "removeKeys.sh {$keys}", $retData);
@@ -659,7 +595,7 @@ class Papers extends Module
 		}
 		return True;
 	}
-	private function getLogs($type) {
+	public function getLogs($type) {
 		$dir = ($type == "error") ? __LOGS__ : __CHANGELOGS__;
 		$contents = array();
 		foreach (scandir($dir) as $log) {
@@ -668,13 +604,13 @@ class Papers extends Module
 		}
 		$this->respond(true, null, $contents);
 	}
-	private function logError($filename, $data) {
+	public function logError($filename, $data) {
 		$time = exec("date +'%H_%M_%S'");
 		$fh = fopen(__LOGS__ . str_replace(" ","_",$filename) . "_" . $time . ".txt", "w+");
 		fwrite($fh, $data);
 		fclose($fh);
 	}
-	private function retrieveLog($logname, $type) {
+	public function retrieveLog($logname, $type) {
 		switch($type) {
                 case "error":
                     $dir = __LOGS__;
@@ -693,7 +629,7 @@ class Papers extends Module
 		}
 		$this->respond(true, null, $data);
 	}
-	private function deleteLog($logname) {
+	public function deleteLog($logname) {
 		$data = unlink(__LOGS__ . $logname);
 		if (!$data) {
 			$this->respond(false, "Failed to delete log.");

+ 49 - 180
modules/src/PortalAuth/api/module.php

@@ -1,6 +1,8 @@
 <?php
 
-namespace pineapple;
+namespace frieren\core;
+
+/* Code modified by Frieren Auto Refactor */
 
 define('__INCLUDES__', "/pineapple/modules/PortalAuth/includes/");
 define('__CONFIG__', __INCLUDES__ . "config");
@@ -97,148 +99,15 @@ if (!empty($_FILES)) {
 }
 
 
-class PortalAuth extends Module
+class PortalAuth extends Controller
 {
-	public function route() {
-		switch($this->request->action) {
-			case 'init':
-				$this->init();
-				break;
-			case 'depends':
-				$this->depends($this->request->params);
-				break;
-			case 'getConfigs':
-				$this->getConfigs();
-				break;
-			case 'updateConfigs':
-				$this->saveConfigData($this->request->params);
-				break;
-			case 'checkTestServerConfig':
-				$this->tserverConfigured();
-				break;
-			case 'readLog':
-				$this->retrieveLog($this->request->file, $this->request->type);
-				break;
-			case 'deleteLog':
-				$this->deleteLog($this->request->file);
-				break;
-			case 'isOnline':
-				$this->checkIsOnline();
-				break;
-			case 'checkPortalExists':
-				$this->portalExists();
-				break;
-			case 'getLogs':
-				$this->getLogs($this->request->type);
-				break;
-			case 'getInjectionSets':
-				$this->getInjectionSets();
-				break;
-			case 'clonedPortalExists':
-				$this->clonedPortalExists($this->request->name);
-				break;
-			case 'clonePortal':
-				$this->clonePortal($this->request->name, $this->request->options, $this->request->inject, $this->request->payloads);
-				break;
-			case 'checkPASSRunning':
-				$this->getPID();
-				break;
-			case 'startServer':
-				$this->startServer();
-				break;
-			case 'stopServer':
-				$this->stopServer();
-				break;
-			case 'getCode':
-				$this->loadPASSCode();
-				break;
-			case 'restoreCode':
-				switch($this->request->file) {
-					case 'pass':
-						$this->restoreFile(__PASSSRV__, __PASSBAK__);
-						break;
-					default:
-						$base = __INJECTS__ . $this->request->set . "/";
-						$ext = ($this->request->file == "MyPortal") ? ".php" : ".txt";
-						$path = $base . $this->request->file . $ext;
-						$pathBak = $base . "backups/" . $this->request->file . $ext;
-						$this->restoreFile($path, $pathBak);
-						break;
-				}
-				break;
-			case 'saveCode':
-				switch($this->request->file) {
-					case 'pass':
-						$this->saveClonerFile(__PASSSRV__, $this->request->data);
-						break;
-					default:
-						$base = __INJECTS__ . $this->request->set . "/";
-						$ext = ($this->request->file == "MyPortal") ? ".php" : ".txt";
-						$path = $base . $this->request->file . $ext;
-						$this->saveClonerFile($path, $this->request->data);
-						break;
-				}
-				break;
-			case 'backupCode':
-				switch($this->request->file) {
-					case 'pass':
-						$this->saveClonerFile(__PASSSRV__, $this->request->data);
-						$this->backupFile(__PASSSRV__, __PASSBAK__);
-						break;
-					default:
-						$base = __INJECTS__ . $this->request->set . "/";
-						$ext = ($this->request->file == "MyPortal") ? ".php" : ".txt";
-						$path = $base . $this->request->file . $ext;
-						$pathBak = $base . "backups/" . $this->request->file . $ext;
-						$this->saveClonerFile($path, $this->request->data);
-						$this->backupFile($path, $pathBak);
-						break;
-				}
-				break;
-			case 'clearLog':
-				$this->clearLog($this->request->file);
-				break;
-			case 'download':
-				$this->download($this->request->file);
-				break;
-			case 'getInjectCode':
-				$this->getInjectCode($this->request->injectSet);
-				break;
-			case 'downloadInjectSet':
-				$this->exportInjectionSet($this->request->set);
-				break;
-			case 'deleteInjectSet':
-				$this->deleteInjectionSet($this->request->set);
-				break;
-			case 'createInjectionSet':
-				$this->createInjectionSet($this->request->name);
-				break;
-			case 'getCapturedCreds':
-				$this->getCapturedCreds();
-				break;
-			case 'clearCapturedCreds':
-				$this->clearCapturedCreds();
-				break;
-			case 'getPayloads':
-				$this->getPayloads();
-				break;
-			case 'deletePayload':
-				$this->deletePayload($this->request->filePath);
-				break;
-			case 'cfgUploadLimit':
-				$this->cfgUploadLimit();
-				break;
-			case 'clearDownloads':
-				$this->clearDownloads();
-				break;
-		}
-	}
+	protected $endpointRoutes = ['init', 'depends', 'getConfigs', 'updateConfigs', 'checkTestServerConfig', 'readLog', 'deleteLog', 'isOnline', 'checkPortalExists', 'getLogs', 'getInjectionSets', 'clonedPortalExists', 'clonePortal', 'checkPASSRunning', 'startServer', 'stopServer', 'getCode', 'restoreCode', 'saveCode', 'backupCode', 'clearLog', 'download', 'getInjectCode', 'downloadInjectSet', 'deleteInjectSet', 'createInjectionSet', 'getCapturedCreds', 'clearCapturedCreds', 'getPayloads', 'deletePayload', 'cfgUploadLimit', 'clearDownloads'];
 	
 	/* ============================ */
 	/*        INIT FUNCTIONS        */
 	/* ============================ */
 	
-	private function init() {
+	public function init() {
 		if (!file_exists(__LOGS__)) {
 			if (!mkdir(__LOGS__, 0755, true)) {
 				$this->respond(false, "Failed to create logs directory at " . __LOGS__);
@@ -258,7 +127,7 @@ class PortalAuth extends Module
 	//    DEPENDENCY FUNCTIONS    //
 	//============================//
 	
-	private function tserverConfigured() {
+	public function tserverConfigured() {
 		$configs = $this->loadConfigData();
 		if (empty($configs['testSite']) || empty($configs['dataExpected'])) {
 			$this->respond(false);
@@ -267,12 +136,12 @@ class PortalAuth extends Module
 		$this->respond(true);
 	}
 	
-	private function getConfigs() {
+	public function getConfigs() {
 			$configs = $this->loadConfigData();
 			$this->respond(true, null, $configs);
 	}
 	
-	private function depends($action) {
+	public function depends($action) {
 		$retData = array();
 		exec(__SCRIPTS__ . "depends.sh " . $action, $retData);
 		switch (implode(" ", $retData)) {
@@ -291,7 +160,7 @@ class PortalAuth extends Module
 	//    MISC FUNCTIONS    //
 	//======================//
 	
-	private function checkIsOnline() {
+	public function checkIsOnline() {
 		$connected = @fsockopen("www.wifipineapple.com", 443);
 		if ($connected) {
 			fclose($connected);
@@ -300,7 +169,7 @@ class PortalAuth extends Module
 		}
 		$this->respond(false);
 	}
-	private function getCapturedCreds() {
+	public function getCapturedCreds() {
 		if (file_exists(__AUTHLOG__)) {
 			$this->respond(true, null, file_get_contents(__AUTHLOG__));
 			return;
@@ -308,7 +177,7 @@ class PortalAuth extends Module
 		$this->respond(false);
 	}
 	
-	private function clearCapturedCreds() {
+	public function clearCapturedCreds() {
 		$res = true;
 		if (file_exists(__AUTHLOG__)) {
 			$fh = fopen(__AUTHLOG__, "w");
@@ -319,15 +188,15 @@ class PortalAuth extends Module
 		return $res;
 	}
 
-	private function respond($success, $msg = null, $data = null) {
-		$this->response = array("success" => $success,"message" => $msg, "data" => $data);
+	public function respond($success, $msg = null, $data = null) {
+		$this->responseHandler->setData(array("success" => $success,"message" => $msg, "data" => $data));
 	}
 	
 	//========================//
 	//    PORTAL FUNCTIONS    //
 	//========================//
 	
-	private function portalExists() {
+	public function portalExists() {
 		$configs = $this->loadConfigData();
 		$pageData = [];
 		exec("curl " . $configs['testSite'], $pageData);
@@ -338,7 +207,7 @@ class PortalAuth extends Module
 		}
 	}
 	
-	private function clonePortal($name, $opts, $injectionSet, $payloads) {
+	public function clonePortal($name, $opts, $injectionSet, $payloads) {
 		
 		$configs = $this->loadConfigData();
 		if ($this->clonedPortalExists($name)) {
@@ -436,7 +305,7 @@ class PortalAuth extends Module
 		$this->respond(false);
 	}
 	
-	private function clonedPortalExists($name) {
+	public function clonedPortalExists($name) {
 		$configs = $this->loadConfigData();
 		if (file_exists($configs['p_archive'] . $name)) {
 			$this->respond(true);
@@ -450,7 +319,7 @@ class PortalAuth extends Module
 	//    PASS FUNCTIONS    //
 	//======================//
 	
-	private function startServer() {
+	public function startServer() {
 		$ret = exec("python " . __PASSSRV__ . " > /dev/null 2>&1 &");
 		if ($this->getPID() != false) {
 			$dt = array();
@@ -466,7 +335,7 @@ class PortalAuth extends Module
 		return false;
 	}
 	
-	private function stopServer() {
+	public function stopServer() {
 		$pid = $this->getPID();
 		if ($pid != false) {
 			$ret = exec("kill " . $pid);
@@ -485,7 +354,7 @@ class PortalAuth extends Module
 		return true;
 	}
 	
-	private function getPID() {
+	public function getPID() {
 		$data = array();
 		$ret = exec("pgrep -lf pass.py", $data);
 		$output = explode(" ", $data[0]);
@@ -497,7 +366,7 @@ class PortalAuth extends Module
 		return false;
 	}
 	
-	private function loadPASSCode() {
+	public function loadPASSCode() {
 		$data = file_get_contents(__PASSSRV__);
 		if (!$data) {
 			$this->respond(false);
@@ -511,7 +380,7 @@ class PortalAuth extends Module
 	//    FILE SAVE FUNCTIONS    //
 	//===========================//
 	
-	private function saveClonerFile($filename, $data) {
+	public function saveClonerFile($filename, $data) {
 		$fh = fopen($filename, "w+");
 		if ($fh) {
 			fwrite($fh, $data);
@@ -523,7 +392,7 @@ class PortalAuth extends Module
 		return false;
 	}
 	
-	private function saveConfigData($data) {
+	public function saveConfigData($data) {
 		$fh = fopen(__CONFIG__, "w+");
 		if ($fh) {
 			foreach ($data as $key => $value) {
@@ -537,7 +406,7 @@ class PortalAuth extends Module
 		return false;
 	}
 	
-	private function loadConfigData() {
+	public function loadConfigData() {
 		$configs = array();
 		$config_file = fopen(__CONFIG__, "r");
 		if ($config_file) {
@@ -551,7 +420,7 @@ class PortalAuth extends Module
 		return $configs;
 	}
 	
-	private function backupFile($fileName, $backupFile) {
+	public function backupFile($fileName, $backupFile) {
 		// Attempt to create a backups directory in case it doesn't exist
 		mkdir(dirname($backupFile));
 		if (copy($fileName, $backupFile)) {
@@ -566,7 +435,7 @@ class PortalAuth extends Module
 	//    FILE RESTORATION FUNCTIONS    //
 	//==================================//
 	
-	private function restoreFile($oldFile, $newFile) {
+	public function restoreFile($oldFile, $newFile) {
 		$fileData = file_get_contents($newFile);
 		if ($fileData) {
 			$this->saveClonerFile($oldFile, $fileData);
@@ -581,7 +450,7 @@ class PortalAuth extends Module
 	//    INJECTION SET FUNCTIONS    //
 	//===============================//
 	
-	private function createInjectionSet($setName) {
+	public function createInjectionSet($setName) {
 		// Check if the directory exists
 		if (file_exists(__INJECTS__ . $setName)) {
 			$this->logError("New_Injection_Set", "Failed to create new injection set because the name provided is already in use.");
@@ -607,7 +476,7 @@ class PortalAuth extends Module
 		return true;
 	}
 	
-	private function cloneInjectionSet($set) {
+	public function cloneInjectionSet($set) {
 		
 		// Create a random name for the cloned directory
 		do {
@@ -639,7 +508,7 @@ class PortalAuth extends Module
 		return $newDir;
 	}
 	
-	private function exportInjectionSet($setName) {
+	public function exportInjectionSet($setName) {
 		
 		if (!file_exists(__INCLUDES__ . "downloads")) {
 			mkdir(__INCLUDES__ . "downloads");
@@ -653,18 +522,18 @@ class PortalAuth extends Module
 			return false;
 		}
 		$file = __INCLUDES__ . "downloads/" . $setName . ".tar.gz";
-		$this->respond(true, null, $this->downloadFile($file));
+		$this->respond(true, null, $this->systemHelper->downloadFile($file));
 		return true;
 	}
 	
-	private function getInjectionSets() {
+	public function getInjectionSets() {
 		$dirs = scandir(__INJECTS__);
 		array_shift($dirs); array_shift($dirs);
 		array_unshift($dirs, "Select...");
 		$this->respond(true, null, $dirs);
 	}
 	
-	private function getInjectCode($set) {
+	public function getInjectCode($set) {
 		$failed = false;
 		$injectFiles = array();
 		if (!$injectFiles['injectjs'] = $this->getInjectionFile("injectJS.txt", $set)){
@@ -689,14 +558,14 @@ class PortalAuth extends Module
 		return true;
 	}
 	
-	private function getInjectionFile($fileName, $setName) {
+	public function getInjectionFile($fileName, $setName) {
 		if (file_exists(__INJECTS__ . $setName . "/" . $fileName)) {
 			return file_get_contents(__INJECTS__ . $setName . "/" . $fileName);
 		}
 		return false;
 	}
 	
-	private function deleteInjectionSet($setName) {
+	public function deleteInjectionSet($setName) {
 		$this->rrmdir(__INJECTS__ . $setName);
 		if (is_dir(__INJECTS__ . $setName)) {
 			$this->respond(false);
@@ -710,7 +579,7 @@ class PortalAuth extends Module
 	//    PAYLOAD FUNCTIONS    //
 	//=========================//
 	
-	private function getPayloads() {
+	public function getPayloads() {
 		$files = [];
 		
 		foreach ([__WINDL__, __OSXDL__, __ANDROIDDL__, __IOSDL__] as $dir) {
@@ -723,7 +592,7 @@ class PortalAuth extends Module
 		return $files;
 	}
 	
-	private function deletePayload($filePath) {
+	public function deletePayload($filePath) {
 		if (!unlink($filePath)) {
 			$this->logError("Delete Payload", "Failed to delete payload at path " . $filePath);
 			$this->respond(false);
@@ -733,7 +602,7 @@ class PortalAuth extends Module
 		return true;
 	}
 	
-	private function cfgUploadLimit() {
+	public function cfgUploadLimit() {
 		$data = array();
 		$res = exec("python " . __SCRIPTS__ . "cfgUploadLimit.py > /dev/null 2>&1 &", $data);
 		if ($res != "") {
@@ -749,7 +618,7 @@ class PortalAuth extends Module
 	//    ACTIVITY AND TARGET LOG FUNCTIONS    //
 	//=========================================//
 	
-	private function clearLog($log) {
+	public function clearLog($log) {
 		if ($log == "activity") {
 			$fh = fopen(__PASSLOG__, "w+");
 			fclose($fh);
@@ -763,21 +632,21 @@ class PortalAuth extends Module
 		}
 	}
 	
-	private function download($file) {
+	public function download($file) {
 		if ($file == "activity") {
-			$this->respond(true, null, $this->downloadFile(__PASSLOG__));
+			$this->respond(true, null, $this->systemHelper->downloadFile(__PASSLOG__));
 		} else if ($file == "targets") {
-			$this->respond(true, null, $this->downloadFile(__TARGETLOG__));
+			$this->respond(true, null, $this->systemHelper->downloadFile(__TARGETLOG__));
 		} else if ($file == "networkclient_windows") {
-			$this->respond(true, null, $this->downloadFile(__COMPILEWIN__));
+			$this->respond(true, null, $this->systemHelper->downloadFile(__COMPILEWIN__));
 		} else if ($file == "networkclient_osx") {
-			$this->respond(true, null, $this->downloadFile(__COMPILEOSX__));
+			$this->respond(true, null, $this->systemHelper->downloadFile(__COMPILEOSX__));
 		} else if ($file == "networkclient_cs_api") {
-			$this->respond(true, null, $this->downloadFile(__CSAPI__));
+			$this->respond(true, null, $this->systemHelper->downloadFile(__CSAPI__));
 		}
 	}
 	
-	private function clearDownloads() {
+	public function clearDownloads() {
 		$files = scandir(__INCLUDES__ . "downloads/");
 		foreach ($files as $file) {
 			if ($file == "." || $file == "..") {continue;}
@@ -800,7 +669,7 @@ class PortalAuth extends Module
 		fclose($fh);
 	}
 
-	private function getLogs($type) {
+	public function getLogs($type) {
 		$dir = ($type == "error") ? __LOGS__ : __CHANGELOGS__;
 		$contents = array();
 		foreach (scandir($dir) as $log) {
@@ -810,7 +679,7 @@ class PortalAuth extends Module
 		$this->respond(true, null, $contents);
 	}
 
-	private function retrieveLog($logname, $type) {
+	public function retrieveLog($logname, $type) {
         switch($type) {
                 case "error":
                     $dir = __LOGS__;
@@ -833,13 +702,13 @@ class PortalAuth extends Module
 		$this->respond(true, null, $data);
 	}
 
-	private function deleteLog($logname) {
+	public function deleteLog($logname) {
 		$res = unlink(__LOGS__ . $logname);
 		$this->respond($res);
 		return $res;
 	}
 
-	private function rrmdir($dir) {
+	public function rrmdir($dir) {
 		if (is_dir($dir)) {
 			$objects = scandir($dir);
 			foreach ($objects as $object) {

+ 1 - 0
modules/src/PortalAuth/includes/scripts/injects/Blank/MyPortal.php

@@ -1,5 +1,6 @@
 <?php namespace evilportal;
 
+/* Code modified by Frieren Auto Refactor */
 class MyPortal extends Portal
 {
 

+ 1 - 0
modules/src/PortalAuth/includes/scripts/injects/Blank/backups/MyPortal.php

@@ -1,5 +1,6 @@
 <?php namespace evilportal;
 
+/* Code modified by Frieren Auto Refactor */
 class MyPortal extends Portal
 {
 

+ 1 - 0
modules/src/PortalAuth/includes/scripts/injects/Free_WiFi_Week/MyPortal.php

@@ -1,6 +1,7 @@
 <?php
 namespace evilportal;
 
+/* Code modified by Frieren Auto Refactor */
 class MyPortal extends Portal
 {
 

+ 1 - 0
modules/src/PortalAuth/includes/scripts/injects/Free_WiFi_Week/backups/MyPortal.php

@@ -1,6 +1,7 @@
 <?php
 namespace evilportal;
 
+/* Code modified by Frieren Auto Refactor */
 class MyPortal extends Portal
 {
 

+ 1 - 0
modules/src/PortalAuth/includes/scripts/injects/Harvester/MyPortal.php

@@ -1,6 +1,7 @@
 <?php
 namespace evilportal;
 
+/* Code modified by Frieren Auto Refactor */
 class MyPortal extends Portal
 {
 

+ 1 - 0
modules/src/PortalAuth/includes/scripts/injects/Harvester/backups/MyPortal.php

@@ -1,6 +1,7 @@
 <?php
 namespace evilportal;
 
+/* Code modified by Frieren Auto Refactor */
 class MyPortal extends Portal
 {
 

+ 1 - 0
modules/src/PortalAuth/includes/scripts/injects/Payloader/MyPortal.php

@@ -1,6 +1,7 @@
 <?php
 namespace evilportal;
 
+/* Code modified by Frieren Auto Refactor */
 class MyPortal extends Portal
 {
 

+ 1 - 0
modules/src/PortalAuth/includes/scripts/injects/Payloader/backups/MyPortal.php

@@ -1,6 +1,7 @@
 <?php
 namespace evilportal;
 
+/* Code modified by Frieren Auto Refactor */
 class MyPortal extends Portal
 {
 

+ 1 - 0
modules/src/PortalAuth/includes/scripts/skeleton/MyPortal.php

@@ -1,5 +1,6 @@
 <?php namespace evilportal;
 
+/* Code modified by Frieren Auto Refactor */
 class MyPortal extends Portal
 {
 	

+ 17 - 42
modules/src/RandomRoll/api/module.php

@@ -1,51 +1,26 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class RandomRoll extends Module
+/* Code modified by Frieren Auto Refactor */
+class RandomRoll extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'checkStatus':
-                $this->checkStatus();
-                break;
-            case 'startRandomRoll':
-                $this->startRandomRoll();
-                break;
-
-            case 'stopRandomRoll':
-                $this->stopRandomRoll();
-                break;
-
-            case 'getRandomRollRolls':
-                $this->getRandomRollRolls();
-                break;
-
-            case 'getRandomRollLogs':
-                $this->getRandomRollLogs();
-                break;
-
-            case 'clearRandomRollLogs':
-                $this->clearRandomRollLogs();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['checkStatus', 'startRandomRoll', 'stopRandomRoll', 'getRandomRollRolls', 'getRandomRollLogs', 'clearRandomRollLogs'];
 
-    private function checkStatus()
+    public function checkStatus()
     {
         $running = file_get_contents('/pineapple/modules/RandomRoll/assets/running');
         if($running == 1){
-            $this->response = array("running" => true);
+            $this->responseHandler->setData(array("running" => true));
         } else {
-            $this->response = array("running" => false);
+            $this->responseHandler->setData(array("running" => false));
         }
     }
 
-    private function startRandomRoll()
+    public function startRandomRoll()
     {
         $date = date("Ymd H:i:s -- ");
         file_put_contents("/pineapple/modules/RandomRoll/assets/logs/randomroll.log", $date . "RandomRoll Started\n", FILE_APPEND);
 
-        foreach($this->request->selected as $roll){
+        foreach($this->request['selected'] as $roll){
             $title = $roll->randomRollTitle;
             $checked = $roll->randomRollChecked;
             if ($checked){
@@ -60,10 +35,10 @@ class RandomRoll extends Module
 
         file_put_contents('/pineapple/modules/RandomRoll/assets/running', '1');
 
-        $this->response = array("success" => true);
+        $this->responseHandler->setData(array("success" => true));
     }
 
-    private function stopRandomRoll()
+    public function stopRandomRoll()
     {
         $date = date("Ymd H:i:s -- ");
         file_put_contents("/pineapple/modules/RandomRoll/assets/logs/randomroll.log", $date . "RandomRoll Stopped\n\n", FILE_APPEND);
@@ -75,10 +50,10 @@ class RandomRoll extends Module
 
         file_put_contents('/pineapple/modules/RandomRoll/assets/running', '0');
 
-        $this->response = array("success" => true);
+        $this->responseHandler->setData(array("success" => true));
     }
 
-    private function getRandomRollRolls()
+    public function getRandomRollRolls()
     {
         $rolls = array();
         
@@ -87,16 +62,16 @@ class RandomRoll extends Module
             array_push($rolls, array("randomRollTitle" => $rollname, "randomRollChecked" => false));
         }
 
-        $this->response = $rolls;
+        $this->responseHandler->setData($rolls);
     }
 
-    private function getRandomRollLogs()
+    public function getRandomRollLogs()
     {
         $randomRollLogOutput = file_get_contents('/pineapple/modules/RandomRoll/assets/logs/randomroll.log');
-        $this->response = array("randomRollLogOutput" => $randomRollLogOutput);
+        $this->responseHandler->setData(array("randomRollLogOutput" => $randomRollLogOutput));
     }
 
-    private function clearRandomRollLogs()
+    public function clearRandomRollLogs()
     {
         file_put_contents("/pineapple/modules/RandomRoll/assets/logs/randomroll.log", "");
     }

+ 98 - 146
modules/src/Responder/api/module.php

@@ -1,61 +1,13 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class Responder extends Module
+/* Code modified by Frieren Auto Refactor */
+class Responder extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'refreshInfo':
-                $this->refreshInfo();
-                break;
-            case 'refreshOutput':
-                $this->refreshOutput();
-                break;
-            case 'refreshStatus':
-                $this->refreshStatus();
-                break;
-            case 'toggleResponder':
-                $this->toggleResponder();
-                break;
-            case 'handleDependencies':
-                $this->handleDependencies();
-                break;
-            case 'handleDependenciesStatus':
-                $this->handleDependenciesStatus();
-                break;
-            case 'refreshHistory':
-                $this->refreshHistory();
-                break;
-            case 'viewHistory':
-                $this->viewHistory();
-                break;
-            case 'deleteHistory':
-                $this->deleteHistory();
-                break;
-            case 'downloadHistory':
-                $this->downloadHistory();
-                break;
-            case 'toggleResponderOnBoot':
-                $this->toggleResponderOnBoot();
-                break;
-            case 'getInterfaces':
-                $this->getInterfaces();
-                break;
-            case 'saveAutostartSettings':
-                $this->saveAutostartSettings();
-                break;
-            case 'getSettings':
-                $this->getSettings();
-                break;
-            case 'setSettings':
-                $this->setSettings();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['refreshInfo', 'refreshOutput', 'refreshStatus', 'toggleResponder', 'handleDependencies', 'handleDependenciesStatus', 'refreshHistory', 'viewHistory', 'deleteHistory', 'downloadHistory', 'toggleResponderOnBoot', 'getInterfaces', 'saveAutostartSettings', 'getSettings', 'setSettings'];
 
     protected function checkDeps($dependencyName)
     {
-        return ($this->checkDependency($dependencyName) && ($this->uciGet("responder.module.installed")));
+        return ($this->systemHelper->checkDependency($dependencyName) && ($this->systemHelper->uciGet("responder.module.installed")));
     }
 
     protected function checkRunning($processName)
@@ -71,30 +23,30 @@ class Responder extends Module
     protected function refreshInfo()
     {
         $moduleInfo = @json_decode(file_get_contents("/pineapple/modules/Responder/module.info"));
-        $this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
+        $this->responseHandler->setData(array('title' => $moduleInfo->title, 'version' => $moduleInfo->version));
     }
 
-    private function handleDependencies()
+    public function handleDependencies()
     {
         if (!$this->checkDeps("python")) {
-            $this->execBackground("/pineapple/modules/Responder/scripts/dependencies.sh install ".$this->request->destination);
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/Responder/scripts/dependencies.sh install ".$this->request['destination']);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->execBackground("/pineapple/modules/Responder/scripts/dependencies.sh remove");
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/Responder/scripts/dependencies.sh remove");
+            $this->responseHandler->setData(array('success' => true));
         }
     }
 
-    private function handleDependenciesStatus()
+    public function handleDependenciesStatus()
     {
         if (!file_exists('/tmp/Responder.progress')) {
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function toggleResponderOnBoot()
+    public function toggleResponderOnBoot()
     {
         if (exec("cat /etc/rc.local | grep Responder/scripts/autostart_responder.sh") == "") {
             exec("sed -i '/exit 0/d' /etc/rc.local");
@@ -105,27 +57,27 @@ class Responder extends Module
         }
     }
 
-    private function toggleResponder()
+    public function toggleResponder()
     {
-        if (!$this->checkRunning("Responder.py")) {
-            $this->uciSet("responder.run.interface", $this->request->interface);
+        if (!$this->systemHelper->checkRunning("Responder.py")) {
+            $this->systemHelper->uciSet("responder.run.interface", $this->request['interface']);
 
-            $this->execBackground("/pineapple/modules/Responder/scripts/responder.sh start");
+            $this->systemHelper->execBackground("/pineapple/modules/Responder/scripts/responder.sh start");
         } else {
-            $this->uciSet("responder.run.interface", '');
+            $this->systemHelper->uciSet("responder.run.interface", '');
 
-            $this->execBackground("/pineapple/modules/Responder/scripts/responder.sh stop");
+            $this->systemHelper->execBackground("/pineapple/modules/Responder/scripts/responder.sh stop");
         }
     }
 
-    private function getInterfaces()
+    public function getInterfaces()
     {
         exec("cat /proc/net/dev | tail -n +3 | cut -f1 -d: | sed 's/ //g'", $interfaceArray);
 
-        $this->response = array("interfaces" => $interfaceArray, "selected" => $this->uciGet("responder.run.interface"));
+        $this->responseHandler->setData(array("interfaces" => $interfaceArray, "selected" => $this->systemHelper->uciGet("responder.run.interface")));
     }
 
-    private function refreshStatus()
+    public function refreshStatus()
     {
         if (!file_exists('/tmp/Responder.progress')) {
             if (!$this->checkDeps("python")) {
@@ -145,7 +97,7 @@ class Responder extends Module
                 $installLabel = "success";
                 $processing = false;
 
-                if ($this->checkRunning("Responder.py")) {
+                if ($this->systemHelper->checkRunning("Responder.py")) {
                     $status = "Stop";
                     $statusLabel = "danger";
                 } else {
@@ -175,19 +127,19 @@ class Responder extends Module
             $bootLabelOFF = "danger";
         }
 
-        $device = $this->getDevice();
-        $sdAvailable = $this->isSDAvailable();
+        $device = $this->systemHelper->getDevice();
+        $sdAvailable = $this->systemHelper->isSDAvailable();
 
-        $this->response = array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "bootLabelON" => $bootLabelON, "bootLabelOFF" => $bootLabelOFF, "processing" => $processing);
+        $this->responseHandler->setData(array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "bootLabelON" => $bootLabelON, "bootLabelOFF" => $bootLabelOFF, "processing" => $processing));
     }
 
-    private function refreshOutput()
+    public function refreshOutput()
     {
         if ($this->checkDeps("python")) {
-            if ($this->checkRunning("Responder.py")) {
+            if ($this->systemHelper->checkRunning("Responder.py")) {
                 if (file_exists("/pineapple/modules/Responder/dep/responder/logs/Responder-Session.log")) {
-                    if ($this->request->filter != "") {
-                        $filter = $this->request->filter;
+                    if ($this->request['filter'] != "") {
+                        $filter = $this->request['filter'];
 
                         $cmd = "strings /pineapple/modules/Responder/dep/responder/logs/Responder-Session.log | ".$filter;
                     } else {
@@ -196,22 +148,22 @@ class Responder extends Module
 
                     exec($cmd, $output);
                     if (!empty($output)) {
-                        $this->response = implode("\n", array_reverse($output));
+                        $this->responseHandler->setData(implode("\n", array_reverse($output)));
                     } else {
-                        $this->response = "Empty log...";
+                        $this->responseHandler->setData("Empty log...");
                     }
                 } else {
-                    $this->response = "Empty log...";
+                    $this->responseHandler->setData("Empty log...");
                 }
             } else {
-                $this->response = "Responder is not running...";
+                $this->responseHandler->setData("Responder is not running...");
             }
         } else {
-            $this->response = "Responder is not installed...";
+            $this->responseHandler->setData("Responder is not installed...");
         }
     }
 
-    private function refreshHistory()
+    public function refreshHistory()
     {
         $this->streamFunction = function () {
             $log_list = array_reverse(glob("/pineapple/modules/Responder/log/*"));
@@ -232,65 +184,65 @@ class Responder extends Module
         };
     }
 
-    private function viewHistory()
+    public function viewHistory()
     {
-        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/Responder/log/".$this->request->file));
-        exec("strings /pineapple/modules/Responder/log/".$this->request->file, $output);
+        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/Responder/log/".$this->request['file']));
+        exec("strings /pineapple/modules/Responder/log/".$this->request['file'], $output);
 
         if (!empty($output)) {
-            $this->response = array("output" => implode("\n", $output), "date" => $log_date);
+            $this->responseHandler->setData(array("output" => implode("\n", $output), "date" => $log_date));
         } else {
-            $this->response = array("output" => "Empty log...", "date" => $log_date);
+            $this->responseHandler->setData(array("output" => "Empty log...", "date" => $log_date));
         }
     }
 
-    private function deleteHistory()
+    public function deleteHistory()
     {
-        exec("rm -rf /pineapple/modules/Responder/log/".$this->request->file);
+        exec("rm -rf /pineapple/modules/Responder/log/".$this->request['file']);
     }
 
-    private function downloadHistory()
+    public function downloadHistory()
     {
-        $this->response = array("download" => $this->downloadFile("/pineapple/modules/Responder/log/".$this->request->file));
+        $this->responseHandler->setData(array("download" => $this->systemHelper->downloadFile("/pineapple/modules/Responder/log/".$this->request['file'])));
     }
 
-    private function saveAutostartSettings()
+    public function saveAutostartSettings()
     {
-        $settings = $this->request->settings;
-        $this->uciSet("responder.autostart.interface", $settings->interface);
+        $settings = $this->request['settings'];
+        $this->systemHelper->uciSet("responder.autostart.interface", $settings->interface);
     }
 
-    private function getSettings()
+    public function getSettings()
     {
         $settings = array(
-                    'SQL' => $this->uciGet("responder.settings.SQL"),
-                    'SMB' => $this->uciGet("responder.settings.SMB"),
-                    'Kerberos' => $this->uciGet("responder.settings.Kerberos"),
-                    'FTP' => $this->uciGet("responder.settings.FTP"),
-                    'POP' => $this->uciGet("responder.settings.POP"),
-                    'SMTP' => $this->uciGet("responder.settings.SMTP"),
-                    'IMAP' => $this->uciGet("responder.settings.IMAP"),
-                    'HTTP' => $this->uciGet("responder.settings.HTTP"),
-                    'HTTPS' => $this->uciGet("responder.settings.HTTPS"),
-                    'DNS' => $this->uciGet("responder.settings.DNS"),
-                    'LDAP' => $this->uciGet("responder.settings.LDAP"),
-                    'basic' => $this->uciGet("responder.settings.basic"),
-                    'wredir' => $this->uciGet("responder.settings.wredir"),
-                    'NBTNS' => $this->uciGet("responder.settings.NBTNS"),
-                    'fingerprint' => $this->uciGet("responder.settings.fingerprint"),
-                    'wpad' => $this->uciGet("responder.settings.wpad"),
-                    'forceWpadAuth' => $this->uciGet("responder.settings.forceWpadAuth"),
-                    'proxyAuth' => $this->uciGet("responder.settings.proxyAuth"),
-                    'forceLmDowngrade' => $this->uciGet("responder.settings.forceLmDowngrade"),
-                    'verbose' => $this->uciGet("responder.settings.verbose"),
-                    'analyse' => $this->uciGet("responder.settings.analyse")
+                    'SQL' => $this->systemHelper->uciGet("responder.settings.SQL"),
+                    'SMB' => $this->systemHelper->uciGet("responder.settings.SMB"),
+                    'Kerberos' => $this->systemHelper->uciGet("responder.settings.Kerberos"),
+                    'FTP' => $this->systemHelper->uciGet("responder.settings.FTP"),
+                    'POP' => $this->systemHelper->uciGet("responder.settings.POP"),
+                    'SMTP' => $this->systemHelper->uciGet("responder.settings.SMTP"),
+                    'IMAP' => $this->systemHelper->uciGet("responder.settings.IMAP"),
+                    'HTTP' => $this->systemHelper->uciGet("responder.settings.HTTP"),
+                    'HTTPS' => $this->systemHelper->uciGet("responder.settings.HTTPS"),
+                    'DNS' => $this->systemHelper->uciGet("responder.settings.DNS"),
+                    'LDAP' => $this->systemHelper->uciGet("responder.settings.LDAP"),
+                    'basic' => $this->systemHelper->uciGet("responder.settings.basic"),
+                    'wredir' => $this->systemHelper->uciGet("responder.settings.wredir"),
+                    'NBTNS' => $this->systemHelper->uciGet("responder.settings.NBTNS"),
+                    'fingerprint' => $this->systemHelper->uciGet("responder.settings.fingerprint"),
+                    'wpad' => $this->systemHelper->uciGet("responder.settings.wpad"),
+                    'forceWpadAuth' => $this->systemHelper->uciGet("responder.settings.forceWpadAuth"),
+                    'proxyAuth' => $this->systemHelper->uciGet("responder.settings.proxyAuth"),
+                    'forceLmDowngrade' => $this->systemHelper->uciGet("responder.settings.forceLmDowngrade"),
+                    'verbose' => $this->systemHelper->uciGet("responder.settings.verbose"),
+                    'analyse' => $this->systemHelper->uciGet("responder.settings.analyse")
                     );
-        $this->response = array('settings' => $settings);
+        $this->responseHandler->setData(array('settings' => $settings));
     }
 
-    private function setSettings()
+    public function setSettings()
     {
-        $settings = $this->request->settings;
+        $settings = $this->request['settings'];
         if ($settings->SQL) {
             $this->updateSetting("SQL", 1);
         } else {
@@ -348,64 +300,64 @@ class Responder extends Module
         }
 
         if ($settings->basic) {
-            $this->uciSet("responder.settings.basic", 1);
+            $this->systemHelper->uciSet("responder.settings.basic", 1);
         } else {
-            $this->uciSet("responder.settings.basic", 0);
+            $this->systemHelper->uciSet("responder.settings.basic", 0);
         }
         if ($settings->wredir) {
-            $this->uciSet("responder.settings.wredir", 1);
+            $this->systemHelper->uciSet("responder.settings.wredir", 1);
         } else {
-            $this->uciSet("responder.settings.wredir", 0);
+            $this->systemHelper->uciSet("responder.settings.wredir", 0);
         }
         if ($settings->NBTNS) {
-            $this->uciSet("responder.settings.NBTNS", 1);
+            $this->systemHelper->uciSet("responder.settings.NBTNS", 1);
         } else {
-            $this->uciSet("responder.settings.NBTNS", 0);
+            $this->systemHelper->uciSet("responder.settings.NBTNS", 0);
         }
         if ($settings->fingerprint) {
-            $this->uciSet("responder.settings.fingerprint", 1);
+            $this->systemHelper->uciSet("responder.settings.fingerprint", 1);
         } else {
-            $this->uciSet("responder.settings.fingerprint", 0);
+            $this->systemHelper->uciSet("responder.settings.fingerprint", 0);
         }
         if ($settings->wpad) {
-            $this->uciSet("responder.settings.wpad", 1);
+            $this->systemHelper->uciSet("responder.settings.wpad", 1);
         } else {
-            $this->uciSet("responder.settings.wpad", 0);
+            $this->systemHelper->uciSet("responder.settings.wpad", 0);
         }
         if ($settings->forceWpadAuth) {
-            $this->uciSet("responder.settings.forceWpadAuth", 1);
+            $this->systemHelper->uciSet("responder.settings.forceWpadAuth", 1);
         } else {
-            $this->uciSet("responder.settings.forceWpadAuth", 0);
+            $this->systemHelper->uciSet("responder.settings.forceWpadAuth", 0);
         }
         if ($settings->proxyAuth) {
-            $this->uciSet("responder.settings.proxyAuth", 1);
+            $this->systemHelper->uciSet("responder.settings.proxyAuth", 1);
         } else {
-            $this->uciSet("responder.settings.proxyAuth", 0);
+            $this->systemHelper->uciSet("responder.settings.proxyAuth", 0);
         }
         if ($settings->forceLmDowngrade) {
-            $this->uciSet("responder.settings.forceLmDowngrade", 1);
+            $this->systemHelper->uciSet("responder.settings.forceLmDowngrade", 1);
         } else {
-            $this->uciSet("responder.settings.forceLmDowngrade", 0);
+            $this->systemHelper->uciSet("responder.settings.forceLmDowngrade", 0);
         }
         if ($settings->verbose) {
-            $this->uciSet("responder.settings.verbose", 1);
+            $this->systemHelper->uciSet("responder.settings.verbose", 1);
         } else {
-            $this->uciSet("responder.settings.verbose", 0);
+            $this->systemHelper->uciSet("responder.settings.verbose", 0);
         }
         if ($settings->analyse) {
-            $this->uciSet("responder.settings.analyse", 1);
+            $this->systemHelper->uciSet("responder.settings.analyse", 1);
         } else {
-            $this->uciSet("responder.settings.analyse", 0);
+            $this->systemHelper->uciSet("responder.settings.analyse", 0);
         }
     }
 
-    private function updateSetting($setting, $value)
+    public function updateSetting($setting, $value)
     {
         if ($value) {
-            $this->uciSet("responder.settings.".$setting, 1);
+            $this->systemHelper->uciSet("responder.settings.".$setting, 1);
             exec("/bin/sed -i 's/^".$setting." .*/".$setting." = On/g' /pineapple/modules/Responder/dep/responder/Responder.conf");
         } else {
-            $this->uciSet("responder.settings.".$setting, 0);
+            $this->systemHelper->uciSet("responder.settings.".$setting, 0);
             exec("/bin/sed -i 's/^".$setting." .*/".$setting." = Off/g' /pineapple/modules/Responder/dep/responder/Responder.conf");
         }
     }

+ 24 - 49
modules/src/SSIDManager/api/module.php

@@ -1,4 +1,6 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
+
+/* Code modified by Frieren Auto Refactor */
 
 define('__MODULE_LOCATION__', "/pineapple/modules/SSIDManager/");
 define('__SSID_FILES__', __MODULE_LOCATION__ . "SSID_Files/");
@@ -6,39 +8,12 @@ define('__MODULE_INFO__', __MODULE_LOCATION__ . "module.info");
 
 /* The class name must be the name of your module, without spaces. */
 /* It must also extend the "Module" class. This gives your module access to API functions */
-class SSIDManager extends Module
+class SSIDManager extends Controller
 {
 
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'getContents':
-                $this->getContents();
-                break;
-
-            case 'getSSIDFilesList':
-                $this->getSSIDFilesList();
-                break;
-
-            case 'deleteSSIDFile':
-                $this->deleteSSIDFile();
-                break;
-
-            case 'archivePool':
-                $this->saveSSIDFile();
-                break;
-
-            case 'getSSIDFile':
-                $this->loadSSIDFile();
-                break;
-
-            case 'downloadSSIDFile':
-                $this->downloadSSIDFile();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['getContents', 'getSSIDFilesList', 'deleteSSIDFile', 'archivePool', 'getSSIDFile', 'downloadSSIDFile'];
 
-    private function SSIDDirectoryPath()
+    public function SSIDDirectoryPath()
     {
         if (!file_exists(__SSID_FILES__)) {
             mkdir(__SSID_FILES__, 0755, true);
@@ -46,17 +21,17 @@ class SSIDManager extends Module
         return __SSID_FILES__;
     }
 
-    private function getContents()
+    public function getContents()
     {
         $moduleInfo = @json_decode(file_get_contents(__MODULE_INFO__));
 
-        $this->response = array("success" => true,
+        $this->responseHandler->setData(array("success" => true,
                     "version" => "version " . $moduleInfo->version,
-                    "content" => "");
+                    "content" => ""));
     }
 
 
-    private function getSSIDFilesList()
+    public function getSSIDFilesList()
     {
         $SSIDFilesPath = $this->SSIDDirectoryPath();
         $files_list =  glob($SSIDFilesPath . '*')  ;
@@ -64,32 +39,32 @@ class SSIDManager extends Module
         for ($i=0; $i<count($files_list); $i++) {
             $files_list[$i] = basename($files_list[$i]);
         }
-        $this->response = array("success"=>true, "filesList"=>$files_list);
+        $this->responseHandler->setData(array("success"=>true, "filesList"=>$files_list));
     }
 
-    private function saveSSIDFile()
+    public function saveSSIDFile()
     {
-        $filename = $this->SSIDDirectoryPath().$this->request->storeFileName;
-        file_put_contents($filename, $this->request->ssidPool);
-        $this->response = array("success" => true);
+        $filename = $this->SSIDDirectoryPath().$this->request['storeFileName'];
+        file_put_contents($filename, $this->request['ssidPool']);
+        $this->responseHandler->setData(array("success" => true));
     }
 
-    private function downloadSSIDFile()
+    public function downloadSSIDFile()
     {
-        $filename = $this->SSIDDirectoryPath().$this->request->file;
-        $this->response = array("download" => $this->downloadFile($filename));
+        $filename = $this->SSIDDirectoryPath().$this->request['file'];
+        $this->responseHandler->setData(array("download" => $this->systemHelper->downloadFile($filename)));
     }
 
-    private function deleteSSIDFile()
+    public function deleteSSIDFile()
     {
-        unlink($this->SSIDDirectoryPath() . $this->request->file);
-        $this->response = array("success" => true);
+        unlink($this->SSIDDirectoryPath() . $this->request['file']);
+        $this->responseHandler->setData(array("success" => true));
     }
 
-    private function loadSSIDFile()
+    public function loadSSIDFile()
     {
-        $filename = $this->SSIDDirectoryPath() . $this->request->file;
+        $filename = $this->SSIDDirectoryPath() . $this->request['file'];
         $fileContent = file_get_contents($filename);
-        $this->response = array("success" => true,"content"=>$fileContent,"fileName"=>$filename);
+        $this->responseHandler->setData(array("success" => true,"content"=>$fileContent,"fileName"=>$filename));
     }
 }

+ 55 - 105
modules/src/SSLsplit/api/module.php

@@ -1,63 +1,13 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-
-
-class SSLsplit extends Module
+/* Code modified by Frieren Auto Refactor */
+class SSLsplit extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'refreshInfo':
-                $this->refreshInfo();
-                break;
-            case 'refreshOutput':
-                $this->refreshOutput();
-                break;
-            case 'refreshStatus':
-                $this->refreshStatus();
-                break;
-            case 'toggleSSLsplit':
-                $this->toggleSSLsplit();
-                break;
-            case 'handleDependencies':
-                $this->handleDependencies();
-                break;
-            case 'handleDependenciesStatus':
-                $this->handleDependenciesStatus();
-                break;
-            case 'refreshHistory':
-                $this->refreshHistory();
-                break;
-            case 'viewHistory':
-                $this->viewHistory();
-                break;
-            case 'deleteHistory':
-                $this->deleteHistory();
-                break;
-            case 'downloadHistory':
-                $this->downloadHistory();
-                break;
-            case 'toggleSSLsplitOnBoot':
-                $this->toggleSSLsplitOnBoot();
-                break;
-            case 'handleCertificate':
-                $this->handleCertificate();
-                break;
-            case 'handleCertificateStatus':
-                $this->handleCertificateStatus();
-                break;
-            case 'saveConfigurationData':
-                $this->saveConfigurationData();
-                break;
-            case 'getConfigurationData':
-                $this->getConfigurationData();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['refreshInfo', 'refreshOutput', 'refreshStatus', 'toggleSSLsplit', 'handleDependencies', 'handleDependenciesStatus', 'refreshHistory', 'viewHistory', 'deleteHistory', 'downloadHistory', 'toggleSSLsplitOnBoot', 'handleCertificate', 'handleCertificateStatus', 'saveConfigurationData', 'getConfigurationData'];
 
     protected function checkDeps($dependencyName)
     {
-        return ($this->checkDependency($dependencyName) && ($this->uciGet("sslsplit.module.installed")));
+        return ($this->systemHelper->checkDependency($dependencyName) && ($this->systemHelper->uciGet("sslsplit.module.installed")));
     }
 
     protected function getDevice()
@@ -68,50 +18,50 @@ class SSLsplit extends Module
     protected function refreshInfo()
     {
         $moduleInfo = @json_decode(file_get_contents("/pineapple/modules/SSLsplit/module.info"));
-        $this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
+        $this->responseHandler->setData(array('title' => $moduleInfo->title, 'version' => $moduleInfo->version));
     }
 
-    private function handleCertificate()
+    public function handleCertificate()
     {
         if (!file_exists("/pineapple/modules/SSLsplit/cert/certificate.crt")) {
-            $this->execBackground("/pineapple/modules/SSLsplit/scripts/generate_certificate.sh");
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/SSLsplit/scripts/generate_certificate.sh");
+            $this->responseHandler->setData(array('success' => true));
         } else {
             exec("rm -rf /pineapple/modules/SSLsplit/cert/certificate.*");
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         }
     }
 
-    private function handleCertificateStatus()
+    public function handleCertificateStatus()
     {
         if (!file_exists('/tmp/SSLsplit_certificate.progress')) {
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function handleDependencies()
+    public function handleDependencies()
     {
         if (!$this->checkDeps("sslsplit")) {
-            $this->execBackground("/pineapple/modules/SSLsplit/scripts/dependencies.sh install ".$this->request->destination);
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/SSLsplit/scripts/dependencies.sh install ".$this->request['destination']);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->execBackground("/pineapple/modules/SSLsplit/scripts/dependencies.sh remove");
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/SSLsplit/scripts/dependencies.sh remove");
+            $this->responseHandler->setData(array('success' => true));
         }
     }
 
-    private function handleDependenciesStatus()
+    public function handleDependenciesStatus()
     {
         if (!file_exists('/tmp/SSLsplit.progress')) {
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function toggleSSLsplitOnBoot()
+    public function toggleSSLsplitOnBoot()
     {
         if (exec("cat /etc/rc.local | grep SSLsplit/scripts/autostart_sslsplit.sh") == "") {
             exec("sed -i '/exit 0/d' /etc/rc.local");
@@ -122,16 +72,16 @@ class SSLsplit extends Module
         }
     }
 
-    private function toggleSSLsplit()
+    public function toggleSSLsplit()
     {
-        if (!$this->checkRunning("sslsplit")) {
-            $this->execBackground("/pineapple/modules/SSLsplit/scripts/sslsplit.sh start");
+        if (!$this->systemHelper->checkRunning("sslsplit")) {
+            $this->systemHelper->execBackground("/pineapple/modules/SSLsplit/scripts/sslsplit.sh start");
         } else {
-            $this->execBackground("/pineapple/modules/SSLsplit/scripts/sslsplit.sh stop");
+            $this->systemHelper->execBackground("/pineapple/modules/SSLsplit/scripts/sslsplit.sh stop");
         }
     }
 
-    private function refreshStatus()
+    public function refreshStatus()
     {
         if (!file_exists('/tmp/SSLsplit.progress')) {
             if (!$this->checkDeps("sslsplit")) {
@@ -151,7 +101,7 @@ class SSLsplit extends Module
                 $installLabel = "success";
                 $processing = false;
 
-                if ($this->checkRunning("sslsplit")) {
+                if ($this->systemHelper->checkRunning("sslsplit")) {
                     $status = "Stop";
                     $statusLabel = "danger";
                 } else {
@@ -203,22 +153,22 @@ class SSLsplit extends Module
             $generating = false;
         }
 
-        $device = $this->getDevice();
-        $sdAvailable = $this->isSDAvailable();
+        $device = $this->systemHelper->getDevice();
+        $sdAvailable = $this->systemHelper->isSDAvailable();
 
-        $this->response = array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed,
+        $this->responseHandler->setData(array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed,
                                 "certificate" => $certificate, "certificateLabel" => $certificateLabel, "generating" => $generating, "generated" => $generated,
                                 "install" => $install, "installLabel" => $installLabel,
-                                "bootLabelON" => $bootLabelON, "bootLabelOFF" => $bootLabelOFF, "processing" => $processing);
+                                "bootLabelON" => $bootLabelON, "bootLabelOFF" => $bootLabelOFF, "processing" => $processing));
     }
 
-    private function refreshOutput()
+    public function refreshOutput()
     {
         if ($this->checkDeps("sslsplit")) {
-            if ($this->checkRunning("sslsplit")) {
+            if ($this->systemHelper->checkRunning("sslsplit")) {
                 if (file_exists("/pineapple/modules/SSLsplit/connections.log")) {
-                    if ($this->request->filter != "") {
-                        $filter = $this->request->filter;
+                    if ($this->request['filter'] != "") {
+                        $filter = $this->request['filter'];
 
                         $cmd = "cat /pineapple/modules/SSLsplit/connections.log"." | ".$filter;
                     } else {
@@ -227,22 +177,22 @@ class SSLsplit extends Module
 
                     exec($cmd, $output);
                     if (!empty($output)) {
-                        $this->response = implode("\n", array_reverse($output));
+                        $this->responseHandler->setData(implode("\n", array_reverse($output)));
                     } else {
-                        $this->response = "Empty connections log...";
+                        $this->responseHandler->setData("Empty connections log...");
                     }
                 } else {
-                    $this->response =  "No connections log...";
+                    $this->responseHandler->setData("No connections log...");
                 }
             } else {
-                $this->response = "SSLsplit is not running...";
+                $this->responseHandler->setData("SSLsplit is not running...");
             }
         } else {
-            $this->response = "SSLsplit is not installed...";
+            $this->responseHandler->setData("SSLsplit is not installed...");
         }
     }
 
-    private function refreshHistory()
+    public function refreshHistory()
     {
         $this->streamFunction = function () {
             $log_list = array_reverse(glob("/pineapple/modules/SSLsplit/log/*"));
@@ -263,37 +213,37 @@ class SSLsplit extends Module
         };
     }
 
-    private function viewHistory()
+    public function viewHistory()
     {
-        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/SSLsplit/log/".$this->request->file));
-        exec("cat /pineapple/modules/SSLsplit/log/".$this->request->file, $output);
+        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/SSLsplit/log/".$this->request['file']));
+        exec("cat /pineapple/modules/SSLsplit/log/".$this->request['file'], $output);
 
         if (!empty($output)) {
-            $this->response = array("output" => implode("\n", $output), "date" => $log_date);
+            $this->responseHandler->setData(array("output" => implode("\n", $output), "date" => $log_date));
         } else {
-            $this->response = array("output" => "Empty log...", "date" => $log_date);
+            $this->responseHandler->setData(array("output" => "Empty log...", "date" => $log_date));
         }
     }
 
-    private function deleteHistory()
+    public function deleteHistory()
     {
-        exec("rm -rf /pineapple/modules/SSLsplit/log/".$this->request->file);
+        exec("rm -rf /pineapple/modules/SSLsplit/log/".$this->request['file']);
     }
 
-    private function downloadHistory()
+    public function downloadHistory()
     {
-        $this->response = array("download" => $this->downloadFile("/pineapple/modules/SSLsplit/log/".$this->request->file));
+        $this->responseHandler->setData(array("download" => $this->systemHelper->downloadFile("/pineapple/modules/SSLsplit/log/".$this->request['file'])));
     }
 
-    private function saveConfigurationData()
+    public function saveConfigurationData()
     {
         $filename = '/pineapple/modules/SSLsplit/rules/iptables';
-        file_put_contents($filename, $this->request->configurationData);
+        file_put_contents($filename, $this->request['configurationData']);
     }
 
-    private function getConfigurationData()
+    public function getConfigurationData()
     {
         $configurationData = file_get_contents('/pineapple/modules/SSLsplit/rules/iptables');
-        $this->response = array("configurationData" => $configurationData);
+        $this->responseHandler->setData(array("configurationData" => $configurationData));
     }
 }

+ 11 - 29
modules/src/SignalStrength/api/module.php

@@ -1,34 +1,16 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class SignalStrength extends Module {
-	public function route()
-	{
-		switch ($this->request->action) {
-			case 'getVersionInfo':
-			$this->getVersionInfo();
-			break;
-			case 'getWirelessInterfaces':
-			$this->getWirelessInterfaces();
-			break;
-			case 'getInterfaceScan':
-			$this->getInterfaceScan();
-			break;
-			case 'getInterfaceStatus':
-			$this->getInterfaceStatus();
-			break;
-			case 'toggleInterface':
-			$this->toggleInterface();
-			break;
-		}
-	}
+/* Code modified by Frieren Auto Refactor */
+class SignalStrength extends Controller {
+	protected $endpointRoutes = ['getVersionInfo', 'getWirelessInterfaces', 'getInterfaceScan', 'getInterfaceStatus', 'toggleInterface'];
 
 	protected function getVersionInfo() {
 		$moduleInfo = @json_decode(file_get_contents("/pineapple/modules/SignalStrength/module.info"));
-		$this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
+		$this->responseHandler->setData(array('title' => $moduleInfo->title, 'version' => $moduleInfo->version));
 	}
 
 	protected function getInterfaceScan() {
-		exec('iwlist "'.$this->request->selectedInterface.'" scanning | egrep "Cell |Channel|Quality|ESSID"', $interfaceScan);
+		exec('iwlist "'.$this->request['selectedInterface'].'" scanning | egrep "Cell |Channel|Quality|ESSID"', $interfaceScan);
 		$interfaceScanArray = array();
 		for($x=0;$x<count($interfaceScan);$x+=5) {                                             
 			$bssid = substr($interfaceScan[$x], strpos($wlan0ScanOutput[$x], ":") +29);     
@@ -38,12 +20,12 @@ class SignalStrength extends Module {
 			$essid = substr($interfaceScan[$x+4], strpos($interfaceScan[$x+4], ":") +1); 
 			array_push($interfaceScanArray, array("bssid" => $bssid, "channel" => $channel, "quality" => $quality, "strength" => $strength, "essid" => $essid));
                 }                                                                                        
-                $this->response = array('interfaceScan' => $interfaceScanArray);
+                $this->responseHandler->setData(array('interfaceScan' => $interfaceScanArray));
 	}
 
 	protected function getWirelessInterfaces() {
 		exec("iwconfig 2> /dev/null | grep \"wlan*\" | awk '{print $1}'", $interfaces);
-		$this->response = array('interfaces' => $interfaces);
+		$this->responseHandler->setData(array('interfaces' => $interfaces));
 	}
 
 	protected function getInterfaceStatus() {
@@ -55,11 +37,11 @@ class SignalStrength extends Module {
 			if ($interfaceStatus[$y+1] == "UP") { $status = "Up"; }
 			array_push($interfaceStatusArray, array("interface" => $interface, "status" => $status));
 		}
-		$this->response = array('interfaceStatus' => $interfaceStatusArray);
+		$this->responseHandler->setData(array('interfaceStatus' => $interfaceStatusArray));
 	}
 
 	protected function toggleInterface() {
-		$toggle = ($this->request->status == "Down") ? 'up' : 'down';
-		exec('ifconfig "'.$this->request->interface.'" "'.$toggle.'"', $toggleResponse);
+		$toggle = ($this->request['status'] == "Down") ? 'up' : 'down';
+		exec('ifconfig "'.$this->request['interface'].'" "'.$toggle.'"', $toggleResponse);
 	}
 }

+ 2 - 1
modules/src/SiteSurvey/api/iwlist_parser.php

@@ -1,5 +1,6 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
+/* Code modified by Frieren Auto Refactor */
 class iwlist_parser
 {
     public function iwlist_parser()

+ 72 - 126
modules/src/SiteSurvey/api/module.php

@@ -1,75 +1,21 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
+
+/* Code modified by Frieren Auto Refactor */
 
 require_once('/pineapple/modules/SiteSurvey/api/iwlist_parser.php');
 
-class SiteSurvey extends Module
+class SiteSurvey extends Controller
 {
+    protected $endpointRoutes = ['refreshInfo', 'refreshStatus', 'handleDependencies', 'handleDependenciesStatus', 'getInterfaces', 'getMonitors', 'startMonitor', 'stopMonitor', 'scanForNetworks', 'getMACInfo', 'refreshCapture', 'viewCapture', 'deleteCapture', 'downloadCapture', 'toggleCapture', 'toggleDeauth', 'getProcesses'];
     public function __construct($request)
     {
-        parent::__construct($request, __CLASS__);
         $this->iwlistparse = new iwlist_parser();
-    }
-
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'refreshInfo':
-                $this->refreshInfo();
-                break;
-            case 'refreshStatus':
-                $this->refreshStatus();
-                break;
-            case 'handleDependencies':
-                $this->handleDependencies();
-                break;
-            case 'handleDependenciesStatus':
-                $this->handleDependenciesStatus();
-                break;
-            case 'getInterfaces':
-                $this->getInterfaces();
-                break;
-            case 'getMonitors':
-                $this->getMonitors();
-                break;
-            case 'startMonitor':
-                $this->startMonitor();
-                break;
-            case 'stopMonitor':
-                $this->stopMonitor();
-                break;
-            case 'scanForNetworks':
-                $this->scanForNetworks();
-                break;
-            case 'getMACInfo':
-                $this->getMACInfo();
-                break;
-            case 'refreshCapture':
-                $this->refreshCapture();
-                break;
-            case 'viewCapture':
-                $this->viewCapture();
-                break;
-            case 'deleteCapture':
-                $this->deleteCapture();
-                break;
-            case 'downloadCapture':
-                $this->downloadCapture();
-                break;
-            case 'toggleCapture':
-                $this->toggleCapture();
-                break;
-            case 'toggleDeauth':
-                $this->toggleDeauth();
-                break;
-            case 'getProcesses':
-                $this->getProcesses();
-                break;
-        }
+        parent::__construct($request);
     }
 
     protected function checkDeps($dependencyName)
     {
-        return ($this->checkDependency($dependencyName) && ($this->uciGet("sitesurvey.module.installed")));
+        return ($this->systemHelper->checkDependency($dependencyName) && ($this->systemHelper->uciGet("sitesurvey.module.installed")));
     }
 
     protected function getDevice()
@@ -85,30 +31,30 @@ class SiteSurvey extends Module
     protected function refreshInfo()
     {
         $moduleInfo = @json_decode(file_get_contents("/pineapple/modules/SiteSurvey/module.info"));
-        $this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
+        $this->responseHandler->setData(array('title' => $moduleInfo->title, 'version' => $moduleInfo->version));
     }
 
-    private function handleDependencies()
+    public function handleDependencies()
     {
         if (!$this->checkDeps("mdk3")) {
-            $this->execBackground("/pineapple/modules/SiteSurvey/scripts/dependencies.sh install ".$this->request->destination);
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/SiteSurvey/scripts/dependencies.sh install ".$this->request['destination']);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->execBackground("/pineapple/modules/SiteSurvey/scripts/dependencies.sh remove");
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/SiteSurvey/scripts/dependencies.sh remove");
+            $this->responseHandler->setData(array('success' => true));
         }
     }
 
-    private function handleDependenciesStatus()
+    public function handleDependenciesStatus()
     {
         if (!file_exists('/tmp/SiteSurvey.progress')) {
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function refreshStatus()
+    public function refreshStatus()
     {
         if (!file_exists('/tmp/SiteSurvey.progress')) {
             if (!$this->checkDeps("iwlist")) {
@@ -129,74 +75,74 @@ class SiteSurvey extends Module
             $processing = true;
         }
 
-        if (file_exists("/tmp/SiteSurvey.log") && (!$this->checkRunning("airodump-ng") || !$this->checkRunning("aireplay-ng"))) {
+        if (file_exists("/tmp/SiteSurvey.log") && (!$this->systemHelper->checkRunning("airodump-ng") || !$this->systemHelper->checkRunning("aireplay-ng"))) {
             exec("rm -rf /tmp/SiteSurvey.log");
         }
-        if (file_exists("/tmp/SiteSurvey_deauth.lock") && !$this->checkRunning("aireplay-ng")) {
+        if (file_exists("/tmp/SiteSurvey_deauth.lock") && !$this->systemHelper->checkRunning("aireplay-ng")) {
             exec("rm -rf /tmp/SiteSurvey_deauth.lock");
         }
-        if (file_exists("/tmp/SiteSurvey_capture.lock") && !$this->checkRunning("airodump-ng")) {
+        if (file_exists("/tmp/SiteSurvey_capture.lock") && !$this->systemHelper->checkRunning("airodump-ng")) {
             exec("rm -rf /tmp/SiteSurvey_capture.lock");
         }
 
-        $device = $this->getDevice();
-        $sdAvailable = $this->isSDAvailable();
+        $device = $this->systemHelper->getDevice();
+        $sdAvailable = $this->systemHelper->isSDAvailable();
 
-        $this->response = array("device" => $device, "sdAvailable" => $sdAvailable, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "processing" => $processing);
+        $this->responseHandler->setData(array("device" => $device, "sdAvailable" => $sdAvailable, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "processing" => $processing));
     }
 
-    private function toggleCapture()
+    public function toggleCapture()
     {
-        $ap = $this->request->ap;
+        $ap = $this->request['ap'];
 
-        if (!$this->checkRunning("airodump-ng")) {
-            $this->execBackground("/pineapple/modules/SiteSurvey/scripts/capture.sh start ".$this->request->interface." ".$ap->mac." ".$ap->channel);
+        if (!$this->systemHelper->checkRunning("airodump-ng")) {
+            $this->systemHelper->execBackground("/pineapple/modules/SiteSurvey/scripts/capture.sh start ".$this->request['interface']." ".$ap->mac." ".$ap->channel);
         } else {
-            $this->execBackground("/pineapple/modules/SiteSurvey/scripts/capture.sh stop");
+            $this->systemHelper->execBackground("/pineapple/modules/SiteSurvey/scripts/capture.sh stop");
         }
     }
 
-    private function toggleDeauth()
+    public function toggleDeauth()
     {
-        $ap = $this->request->ap;
-        $client = $this->request->client;
+        $ap = $this->request['ap'];
+        $client = $this->request['client'];
 
-        if (!$this->checkRunning("aireplay-ng")) {
+        if (!$this->systemHelper->checkRunning("aireplay-ng")) {
             if (!empty($client)) {
-                $this->execBackground("/pineapple/modules/SiteSurvey/scripts/deauth.sh start ".$this->request->interface." ".$ap->mac." ".$client);
+                $this->systemHelper->execBackground("/pineapple/modules/SiteSurvey/scripts/deauth.sh start ".$this->request['interface']." ".$ap->mac." ".$client);
             } else {
-                $this->execBackground("/pineapple/modules/SiteSurvey/scripts/deauth.sh start ".$this->request->interface." ".$ap->mac);
+                $this->systemHelper->execBackground("/pineapple/modules/SiteSurvey/scripts/deauth.sh start ".$this->request['interface']." ".$ap->mac);
             }
         } else {
-            $this->execBackground("/pineapple/modules/SiteSurvey/scripts/deauth.sh stop");
+            $this->systemHelper->execBackground("/pineapple/modules/SiteSurvey/scripts/deauth.sh stop");
         }
     }
 
-    private function getInterfaces()
+    public function getInterfaces()
     {
         exec("iwconfig 2> /dev/null | grep \"wlan*\" | grep -v \"mon*\" | awk '{print $1}'", $interfaceArray);
 
-        $this->response = array("interfaces" => $interfaceArray);
+        $this->responseHandler->setData(array("interfaces" => $interfaceArray));
     }
 
-    private function getMonitors()
+    public function getMonitors()
     {
         exec("iwconfig 2> /dev/null | grep \"mon*\" | awk '{print $1}'", $monitorArray);
 
-        $this->response = array("monitors" => $monitorArray);
+        $this->responseHandler->setData(array("monitors" => $monitorArray));
     }
 
-    private function startMonitor()
+    public function startMonitor()
     {
-        exec("airmon-ng start ".$this->request->interface);
+        exec("airmon-ng start ".$this->request['interface']);
     }
 
-    private function stopMonitor()
+    public function stopMonitor()
     {
-        exec("airmon-ng stop ".$this->request->monitor);
+        exec("airmon-ng stop ".$this->request['monitor']);
     }
 
-    private function refreshCapture()
+    public function refreshCapture()
     {
         $this->streamFunction = function () {
             $log_list = array_reverse(glob("/pineapple/modules/SiteSurvey/capture/*.cap"));
@@ -228,51 +174,51 @@ class SiteSurvey extends Module
         };
     }
 
-    private function downloadCapture()
+    public function downloadCapture()
     {
-        $file = basename($this->request->file, ".cap");
+        $file = basename($this->request['file'], ".cap");
 
         exec("mkdir /tmp/dl/");
         exec("cp /pineapple/modules/SiteSurvey/capture/".$file.".* /tmp/dl/");
         exec("cd /tmp/dl/ && tar -czf /tmp/".$file.".tar.gz *");
         exec("rm -rf /tmp/dl/");
 
-        $this->response = array("download" => $this->downloadFile("/tmp/".$file.".tar.gz"));
+        $this->responseHandler->setData(array("download" => $this->systemHelper->downloadFile("/tmp/".$file.".tar.gz")));
     }
 
-    private function viewCapture()
+    public function viewCapture()
     {
-        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/SiteSurvey/capture/".$this->request->file));
-        exec("strings /pineapple/modules/SiteSurvey/capture/".basename($this->request->file, ".cap").".csv", $output);
+        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/SiteSurvey/capture/".$this->request['file']));
+        exec("strings /pineapple/modules/SiteSurvey/capture/".basename($this->request['file'], ".cap").".csv", $output);
 
         if (!empty($output)) {
-            $this->response = array("output" => implode("\n", $output), "date" => $log_date);
+            $this->responseHandler->setData(array("output" => implode("\n", $output), "date" => $log_date));
         } else {
-            $this->response = array("output" => "Empty dump...", "date" => $log_date);
+            $this->responseHandler->setData(array("output" => "Empty dump...", "date" => $log_date));
         }
     }
 
-    private function deleteCapture()
+    public function deleteCapture()
     {
-        $file = basename($this->request->file, ".cap");
+        $file = basename($this->request['file'], ".cap");
         exec("rm -rf /pineapple/modules/SiteSurvey/capture/".$file.".*");
     }
 
-    private function scanForNetworks()
+    public function scanForNetworks()
     {
-        if (file_exists("/tmp/SiteSurvey_deauth.lock") && !$this->checkRunning("aireplay-ng")) {
+        if (file_exists("/tmp/SiteSurvey_deauth.lock") && !$this->systemHelper->checkRunning("aireplay-ng")) {
             exec("rm -rf /tmp/SiteSurvey_deauth.lock");
         }
-        if (file_exists("/tmp/SiteSurvey_capture.lock") && !$this->checkRunning("airodump-ng")) {
+        if (file_exists("/tmp/SiteSurvey_capture.lock") && !$this->systemHelper->checkRunning("airodump-ng")) {
             exec("rm -rf /tmp/SiteSurvey_capture.lock");
         }
 
         $clientArray = array();
-        if ($this->request->duration && $this->request->monitor != "" && $this->request->type == 'clientAP') {
+        if ($this->request['duration'] && $this->request['monitor'] != "" && $this->request['type'] == 'clientAP') {
             exec("killall -9 airodump-ng && rm -rf /tmp/sitesurvey-*");
 
-            $this->execBackground("airodump-ng --write /tmp/sitesurvey ".$this->request->monitor." &> /dev/null ");
-            sleep($this->request->duration);
+            $this->systemHelper->execBackground("airodump-ng --write /tmp/sitesurvey ".$this->request['monitor']." &> /dev/null ");
+            sleep($this->request['duration']);
 
             exec("cat /tmp/sitesurvey-01.csv | tail -n +$(($(cat /tmp/sitesurvey-01.csv | grep -n \"Station MAC\" | cut -f1 -d:)+1)) | tr '\r' '\n' > /tmp/sitesurvey-01.tmp");
             exec("sed '/^$/d' < /tmp/sitesurvey-01.tmp > /tmp/sitesurvey-01.clients");
@@ -288,8 +234,8 @@ class SiteSurvey extends Module
             exec("killall -9 airodump-ng");
         }
 
-        $p = $this->iwlistparse->parseScanDev($this->request->interface);
-        $apArray = $p[$this->request->interface];
+        $p = $this->iwlistparse->parseScanDev($this->request['interface']);
+        $apArray = $p[$this->request['interface']];
 
         $returnArray = array();
         foreach ($apArray as $apData) {
@@ -322,7 +268,7 @@ class SiteSurvey extends Module
                 $accessPoint['captureOnSelected'] = 0;
             }
 
-            if ($this->checkRunning("airodump-ng")) {
+            if ($this->systemHelper->checkRunning("airodump-ng")) {
                 $accessPoint['captureRunning'] = 1;
             } else {
                 $accessPoint['captureRunning'] = 0;
@@ -339,7 +285,7 @@ class SiteSurvey extends Module
                 $accessPoint['deauthOnSelected'] = 0;
             }
 
-            if ($this->checkRunning("aireplay-ng")) {
+            if ($this->systemHelper->checkRunning("aireplay-ng")) {
                 $accessPoint['deauthRunning'] = 1;
             } else {
                 $accessPoint['deauthRunning'] = 0;
@@ -386,21 +332,21 @@ class SiteSurvey extends Module
             array_push($returnArray, $accessPoint);
         }
 
-        $this->response = $returnArray;
+        $this->responseHandler->setData($returnArray);
     }
 
-    private function getMACInfo()
+    public function getMACInfo()
     {
-        $content = file_get_contents("https://api.macvendors.com/".$this->request->mac);
-        $this->response = array('title' => $this->request->mac, "output" => $content);
+        $content = file_get_contents("https://api.macvendors.com/".$this->request['mac']);
+        $this->responseHandler->setData(array('title' => $this->request['mac'], "output" => $content));
     }
 
-    private function getProcesses()
+    public function getProcesses()
     {
         $returnArray = array();
 
         $process = array();
-        if (file_exists("/tmp/SiteSurvey_deauth.lock") && $this->checkRunning("aireplay-ng")) {
+        if (file_exists("/tmp/SiteSurvey_deauth.lock") && $this->systemHelper->checkRunning("aireplay-ng")) {
             $targetArray = explode("\n", file_get_contents("/tmp/SiteSurvey_deauth.lock"));
 
             $process['target'] = $targetArray[0];
@@ -411,13 +357,13 @@ class SiteSurvey extends Module
         }
 
         $process = array();
-        if (file_exists("/tmp/SiteSurvey_capture.lock") && $this->checkRunning("airodump-ng")) {
+        if (file_exists("/tmp/SiteSurvey_capture.lock") && $this->systemHelper->checkRunning("airodump-ng")) {
             $process['target'] = exec("cat /tmp/SiteSurvey_capture.lock");
             $process['name'] = "airodump-ng";
 
             array_push($returnArray, $process);
         }
 
-        $this->response = $returnArray;
+        $this->responseHandler->setData($returnArray);
     }
 }

+ 30 - 68
modules/src/Status/api/module.php

@@ -1,55 +1,17 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-
-
-class Status extends Module
+/* Code modified by Frieren Auto Refactor */
+class Status extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'refreshInfo':
-                $this->refreshInfo();
-                break;
-            case 'getSystem':
-                $this->getSystem();
-                break;
-            case 'getCPU':
-                $this->getCPU();
-                break;
-            case 'getDHCP':
-                $this->getDHCP();
-                break;
-            case 'getMemory':
-                $this->getMemory();
-                break;
-            case 'getWiFi':
-                $this->getWiFi();
-                break;
-            case 'getSwap':
-                $this->getSwap();
-                break;
-            case 'getStorage':
-                $this->getStorage();
-                break;
-            case 'getInterfaces':
-                $this->getInterfaces();
-                break;
-            case 'getMACInfo':
-                $this->getMACInfo();
-                break;
-            case 'getPingInfo':
-                $this->getPingInfo();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['refreshInfo', 'getSystem', 'getCPU', 'getDHCP', 'getMemory', 'getWiFi', 'getSwap', 'getStorage', 'getInterfaces', 'getMACInfo', 'getPingInfo'];
 
     protected function refreshInfo()
     {
         $moduleInfo = @json_decode(file_get_contents("/pineapple/modules/Status/module.info"));
-        $this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
+        $this->responseHandler->setData(array('title' => $moduleInfo->title, 'version' => $moduleInfo->version));
     }
 
-    private function getSystem()
+    public function getSystem()
     {
         $current_time = exec("date");
         $up_time = exec("uptime | awk -F, '{sub(\".*up \",x,$1);print $1}'");
@@ -63,10 +25,10 @@ class Status extends Module
                     'machine' => $machine
                     );
 
-        $this->response = array('info' => $info);
+        $this->responseHandler->setData(array('info' => $info));
     }
 
-    private function getCPU()
+    public function getCPU()
     {
         $cpu = trim(exec("cat /proc/cpuinfo | grep cpu | awk -F: '{print $2}'"));
         $bogo = trim(exec("cat /proc/cpuinfo | grep Bogo | awk -F: '{print $2}'"));
@@ -87,10 +49,10 @@ class Status extends Module
                     'loadAverageAll' =>  $cpu_load_all
                     );
 
-        $this->response = array('info' => $info);
+        $this->responseHandler->setData(array('info' => $info));
     }
 
-    private function getDHCP()
+    public function getDHCP()
     {
         $dhcpClients = explode("\n", trim(shell_exec("cat /tmp/dhcp.leases")));
         $clientsList = array();
@@ -109,10 +71,10 @@ class Status extends Module
                     'clientsList' =>  $clientsList
                     );
 
-        $this->response = array('info' => $info);
+        $this->responseHandler->setData(array('info' => $info));
     }
 
-    private function getMemory()
+    public function getMemory()
     {
         $mem_total = exec("free | grep \"Mem:\" | awk '{ print $2 }'");
         $mem_used = exec("free | grep \"Mem:\" | awk '{ print $3 }'");
@@ -133,10 +95,10 @@ class Status extends Module
                     'memoryUsedPourcentage' =>  $mem_used_ptg
                     );
 
-        $this->response = array('info' => $info);
+        $this->responseHandler->setData(array('info' => $info));
     }
 
-    private function getWiFi()
+    public function getWiFi()
     {
         $wifiClients = explode("\n", trim(shell_exec("iw dev wlan0 station dump | grep \"Station\"")));
         $wifiClientsList = array();
@@ -155,10 +117,10 @@ class Status extends Module
                     'wifiClientsList' =>  $wifiClientsList
                     );
 
-        $this->response = array('info' => $info);
+        $this->responseHandler->setData(array('info' => $info));
     }
 
-    private function getSwap()
+    public function getSwap()
     {
         $swap_total = exec("free | grep \"Swap:\" | awk '{ print $2 }'");
         $swap_used = exec("free | grep \"Swap:\" | awk '{ print $3 }'");
@@ -190,10 +152,10 @@ class Status extends Module
                     'swapUsedPourcentage' =>  $swap_used_ptg
                     );
 
-        $this->response = array('info' => $info);
+        $this->responseHandler->setData(array('info' => $info));
     }
 
-    private function getStorage()
+    public function getStorage()
     {
         $dfAll = explode("\n", trim(shell_exec("df | grep -v \"Filesystem\"")));
         $dfList = array();
@@ -211,10 +173,10 @@ class Status extends Module
                     'storagesList' => $dfList
                     );
 
-        $this->response = array('info' => $info);
+        $this->responseHandler->setData(array('info' => $info));
     }
 
-    private function getInterfaces()
+    public function getInterfaces()
     {
         $interfaces = explode("\n", trim(shell_exec("ifconfig | grep  'encap:Ethernet'  | cut -d' ' -f1")));
         $interfacesList = array();
@@ -253,22 +215,22 @@ class Status extends Module
                     'interfacesList' => $interfacesList
                     );
 
-        $this->response = array('info' => $info);
+        $this->responseHandler->setData(array('info' => $info));
     }
 
-    private function getMACInfo()
+    public function getMACInfo()
     {
-        $content = file_get_contents("https://api.macvendors.com/".$this->request->mac);
-        $this->response = array('title' => $this->request->mac, "output" => $content);
+        $content = file_get_contents("https://api.macvendors.com/".$this->request['mac']);
+        $this->responseHandler->setData(array('title' => $this->request['mac'], "output" => $content));
     }
 
-    private function getPingInfo()
+    public function getPingInfo()
     {
-        exec("ping -c4 ".$this->request->ip, $output);
-        $this->response = array('title' => $this->request->ip, "output" => implode("\n", array_reverse($output)));
+        exec("ping -c4 ".$this->request['ip'], $output);
+        $this->responseHandler->setData(array('title' => $this->request['ip'], "output" => implode("\n", array_reverse($output))));
     }
 
-    private function kbytesToString($kb)
+    public function kbytesToString($kb)
     {
         $units = array('TB','GB','MB','KB');
         $scale = 1024*1024*1024;
@@ -281,7 +243,7 @@ class Status extends Module
         return sprintf("%0.2f %s", ($kb/$scale), $units[$ui]);
     }
 
-    private function getCoreInformation()
+    public function getCoreInformation()
     {
         $data = file('/proc/stat');
         $cores = array();
@@ -301,7 +263,7 @@ class Status extends Module
         return $cores;
     }
 
-    private function getCpuPercentages($stat1, $stat2)
+    public function getCpuPercentages($stat1, $stat2)
     {
         if (count($stat1) !== count($stat2)) {
             return;

+ 22 - 47
modules/src/Terminal/api/module.php

@@ -1,40 +1,15 @@
 <?php
 
-namespace pineapple;
+namespace frieren\core;
 
-class Terminal extends Module
+/* Code modified by Frieren Auto Refactor */
+class Terminal extends Controller
 {
+    protected $endpointRoutes = ['getDependenciesStatus', 'managerDependencies', 'getDependenciesInstallStatus', 'startTerminal', 'stopTerminal', 'getStatus', 'getLog'];
     const TTYD_PATH = "/usr/bin/ttyd";
     const TTYD_SD_PATH = "/sd/usr/bin/ttyd";
     const LOG_PATH = "/pineapple/modules/Terminal/module.log";
 
-    public function route()
-    {
-        switch ($this->request->action) {
-            case "getDependenciesStatus":
-                $this->getDependenciesStatus();
-                break;
-            case "managerDependencies":
-                $this->managerDependencies();
-                break;
-            case "getDependenciesInstallStatus":
-                $this->getDependenciesInstallStatus();
-                break;
-            case "startTerminal":
-                $this->startTerminal();
-                break;
-            case "stopTerminal":
-                $this->stopTerminal();
-                break;
-            case "getStatus":
-                $this->getStatus();
-                break;
-            case "getLog":
-                $this->getLog();
-                break;
-        }
-    }
-
     protected function addLog($massage)
     {
         $entry = "[" . date("Y-m-d H:i:s") . "] {$massage}\n";
@@ -43,7 +18,7 @@ class Terminal extends Module
 
     protected function getTerminalPath()
     {
-        if ($this->isSDAvailable() && file_exists(self::TTYD_SD_PATH)) {
+        if ($this->systemHelper->isSDAvailable() && file_exists(self::TTYD_SD_PATH)) {
             return self::TTYD_SD_PATH;
         }
 
@@ -72,12 +47,12 @@ class Terminal extends Module
             $response["installed"] = true;
         }
 
-        $this->response = $response;
+        $this->responseHandler->setData($response);
     }
 
     protected function checkPanelVersion()
     {
-        $version = \helper\getFirmwareVersion();
+        $version = $this->systemHelper->getFirmwareVersion();
         $version = str_replace("+", "", $version);
 
         return version_compare($version, "2.8.0") >= 0;
@@ -85,9 +60,9 @@ class Terminal extends Module
 
     protected function checkDependencyInstalled()
     {
-       if ($this->checkDependency("ttyd")) {
-            if (!$this->uciGet("ttyd.@ttyd[0].port")) {
-                $this->uciSet("ttyd.@ttyd[0].port", "1477");
+       if ($this->systemHelper->checkDependency("ttyd")) {
+            if (!$this->systemHelper->uciGet("ttyd.@ttyd[0].port")) {
+                $this->systemHelper->uciSet("ttyd.@ttyd[0].port", "1477");
                 //$this->uciSet("ttyd.@ttyd[0].index", "/pineapple/modules/Terminal/ttyd/iframe.html");
                 exec("/etc/init.d/ttyd disable");
             }
@@ -101,18 +76,18 @@ class Terminal extends Module
     protected function managerDependencies()
     {
         if (!$this->checkPanelVersion()) {
-            $this->response = ["success" => true];
+            $this->responseHandler->setData(["success" => true]);
             return true;    
         }
 
         $action = $this->checkDependencyInstalled() ? "remove" : "install";
-        $this->execBackground("/pineapple/modules/Terminal/scripts/dependencies.sh {$action}");
-        $this->response = ["success" => true];
+        $this->systemHelper->execBackground("/pineapple/modules/Terminal/scripts/dependencies.sh {$action}");
+        $this->responseHandler->setData(["success" => true]);
     }
 
     protected function getDependenciesInstallStatus()
     {
-        $this->response = ["success" => !file_exists("/tmp/terminal.progress")];
+        $this->responseHandler->setData(["success" => !file_exists("/tmp/terminal.progress")]);
     }
 
     protected function startTerminal()
@@ -126,19 +101,19 @@ class Terminal extends Module
         ];
         */
         $terminal = $this->getTerminalPath();
-        $status = \helper\checkRunning($terminal);
+        $status = $this->systemHelper->checkRunning($terminal);
         if (!$status) {
             $command = "{$terminal} -p 1477 -i br-lan /bin/login";
-            $this->execBackground($command);
+            $this->systemHelper->execBackground($command);
 
             sleep(1);
-            $status = \helper\checkRunning($terminal);
+            $status = $this->systemHelper->checkRunning($terminal);
             if (!$status) {
                 $this->addLog("Terminal could not be run! command: {$command}");
             }
         }
 
-        $this->response = ["success" => $status];
+        $this->responseHandler->setData(["success" => $status]);
     }
 
     protected function stopTerminal()
@@ -152,16 +127,16 @@ class Terminal extends Module
         ];
         */
         exec("/usr/bin/pkill ttyd");
-        $status = \helper\checkRunning($this->getTerminalPath());
+        $status = $this->systemHelper->checkRunning($this->getTerminalPath());
         if ($status) {
             $this->addLog("Terminal could not be stop! command: /usr/bin/pkill ttyd");
         }
-        $this->response = ["success" => !$status];
+        $this->responseHandler->setData(["success" => !$status]);
     }
 
     protected function getStatus()
     {
-        $this->response = ["status" => \helper\checkRunning($this->getTerminalPath())];
+        $this->responseHandler->setData(["status" => $this->systemHelper->checkRunning($this->getTerminalPath())]);
     }
 
     protected function getLog()
@@ -170,6 +145,6 @@ class Terminal extends Module
             touch(self::LOG_PATH);
         }
 
-        $this->response = ["moduleLog" => file_get_contents(self::LOG_PATH)];
+        $this->responseHandler->setData(["moduleLog" => file_get_contents(self::LOG_PATH)]);
     }
 }

+ 48 - 86
modules/src/Themes/api/module.php

@@ -1,11 +1,12 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
+/* Code modified by Frieren Auto Refactor */
 /*
  * Author: trashbo4t (github.com/trashbo4t)
  */
-
-class Themes extends Module
+class Themes extends Controller
 {
+    protected $endpointRoutes = ['getThemeList', 'themeFields', 'deleteTheme', 'activateTheme', 'getThemeCode', 'submitThemeCode', 'getCurrentTheme', 'createNewTheme', 'restoreDefault', 'backupFiles', 'replaceImage'];
     // CONSTANTS
     private $MODULE_DIR = '/pineapple/modules/Themes/';
     private $CSS_DIR = '/pineapple/modules/Themes/css/';
@@ -75,45 +76,6 @@ class Themes extends Module
         "yellow" => "cccc00",
         "pink"   => "99003d",
     );
-
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'getThemeList':
-                $this->handleGetThemeList();
-                break;
-            case 'themeFields':
-                $this->getThemeFields();
-                break;
-            case 'deleteTheme':
-                $this->handleDeleteTheme();
-                break;
-            case 'activateTheme':
-                $this->activateTheme();
-                break;
-            case 'getThemeCode':
-                $this->getThemeCode();
-                break;
-            case 'submitThemeCode':
-                $this->submitThemeCode();
-                break;
-            case 'getCurrentTheme':
-	            $this->getCurrentTheme();
-		        break;
-            case 'createNewTheme':
-                $this->handleCreateNewTheme();
-                break;
-            case 'restoreDefault':
-                $this->restoreDefault();
-                break;
-            case 'backupFiles':
-                $this->backupFiles();
-		        break;
-	        case 'replaceImage':
-    	    	$this->replaceImage();
-	    	    break;
-	    }
-    }
     // Get the CURRENT_<MODULE_ICON> file, which is 1 line with the current color of the icon
     public function currentFile($name)
     {
@@ -123,13 +85,13 @@ class Themes extends Module
     // Move an image from light->dark or vice versa
     public function replaceImage() 
     {
-        $img = $this->request->img;
+        $img = $this->request['img'];
 	    switch ($img) 
 	    {
             // Pineapple Logo
 	        case 'Logo':
-		        $this->response = array("message" => "Logo Changed");
-		        if ($this->request->light) {
+		        $this->responseHandler->setData(array("message" => "Logo Changed"));
+		        if ($this->request['light']) {
         			exec("cp $this->BACKUP_LOGO /pineapple/img/logo.png");
                     exec("echo light > $this->CURRENT_LOGO");
                 }
@@ -138,12 +100,12 @@ class Themes extends Module
                     exec("echo dark > $this->CURRENT_LOGO");
                     exec('cp /pineapple/modules/Themes/img/logo-dark.png /pineapple/img/logo.png');
                 }
-                $this->response = array("message" => "Logo Changed");
+                $this->responseHandler->setData(array("message" => "Logo Changed"));
                 break;
 
                 // Pineapple favicon.ico Image
             case 'Icon':
-                if ($this->request->light) {
+                if ($this->request['light']) {
                     exec("echo light > $this->CURRENT_FAVICON");
                     exec("cp $this->BACKUP_FAVICON /pineapple/img/favicon.ico");
                 }
@@ -152,12 +114,12 @@ class Themes extends Module
                     exec("echo dark > $this->CURRENT_FAVICON");
                     exec('cp /pineapple/modules/Themes/img/favicon-dark.ico /pineapple/img/favicon.ico');
                 }
-                $this->response = array("message" => "Icon Changed");
+                $this->responseHandler->setData(array("message" => "Icon Changed"));
                 break;
 
             // Pineapple Throbber gif
             case 'Throbber':
-                if ($this->request->light) {
+                if ($this->request['light']) {
                     exec("echo light > $this->CURRENT_THROBBER");
                     exec("cp $this->BACKUP_THROBBER /pineapple/img/throbber.gif");
                 }
@@ -166,7 +128,7 @@ class Themes extends Module
                     exec("echo dark > $this->CURRENT_THROBBER");
                     exec('cp /pineapple/modules/Themes/img/throbber-dark.gif /pineapple/img/throbber.gif');
                 }
-                $this->response = array("message" => "Throbber Changed");
+                $this->responseHandler->setData(array("message" => "Throbber Changed"));
                 break;
 
             // Modify all of the module Icons
@@ -176,26 +138,26 @@ class Themes extends Module
                     $current = $this->currentFile($module);
                     $success = $this->replaceModuleImage(
                         $module,
-                        $this->request->color,
-                        $this->request->brightness
+                        $this->request['color'],
+                        $this->request['brightness']
                     );
                 }
-                $this->response = array(
+                $this->responseHandler->setData(array(
                     "success" => true,
-                    "message" => "All module icons changed to {$this->request->color}-{$this->request->brightness}"
-                );
+                    "message" => "All module icons changed to {$this->request['color']}-{$this->request['brightness']}"
+                ));
                 break;
             // Assume module Icon
             default:
                 $success = $this->replaceModuleImage(
-                    $this->request->img,
-                    $this->request->color,
-                    $this->request->brightness
+                    $this->request['img'],
+                    $this->request['color'],
+                    $this->request['brightness']
                 );
-                $this->response = array(
+                $this->responseHandler->setData(array(
                     "success" => $success,
-                    "message" => "{$this->request->img} icon changed to {$this->request->color}-{$this->request->brightness}"
-                );
+                    "message" => "{$this->request['img']} icon changed to {$this->request['color']}-{$this->request['brightness']}"
+                ));
                 break;
         }
     }
@@ -290,12 +252,12 @@ class Themes extends Module
 
 	    $throbber = file('/pineapple/modules/Themes/img/CURRENT_THROBBER')[0];
         $throbber = trim(preg_replace('/\s+/', ' ', $throbber));
-        $this->response = array(
+        $this->responseHandler->setData(array(
             "current" => $line, 
             "logo" => $logo, 
             "icon" => $icon, 
             "throbber" => $throbber,
-        );
+        ));
         foreach ($this->ALL_MODULES as $module) 
         {
             $current = $this->currentFile($module);
@@ -348,10 +310,10 @@ class Themes extends Module
                 $module
             );
         }
-        $this->response = array(
+        $this->responseHandler->setData(array(
             "success" => $success, 
             "message" => "Restored all files"
-        );
+        ));
     }
     /* 
     *  restoreModuleIcon
@@ -392,8 +354,8 @@ class Themes extends Module
     */
     public function getThemeCode()
     {
-        $code = file_get_contents($this->CSS_DIR . $this->request->name);
-        $this->response = array("code" => $code, "file" => $this->CSS_DIR . $this->request->name);
+        $code = file_get_contents($this->CSS_DIR . $this->request['name']);
+        $this->responseHandler->setData(array("code" => $code, "file" => $this->CSS_DIR . $this->request['name']));
     }
     /*
     *  getThemeFields
@@ -402,8 +364,8 @@ class Themes extends Module
     public function getThemeFields()
     {
 	    $allFields = array();
-        $code = file_get_contents($this->CSS_DIR . $this->request->name);
-        $this->response = array("code" => $code);
+        $code = file_get_contents($this->CSS_DIR . $this->request['name']);
+        $this->responseHandler->setData(array("code" => $code));
     }
     /*
     *  activateTheme
@@ -411,21 +373,21 @@ class Themes extends Module
     */
     public function activateTheme()
     {
-        $themeName = $this->request->name;
+        $themeName = $this->request['name'];
         $cmd = exec("cp {$this->CSS_DIR}{$themeName} /pineapple/css/main.css");
 	    if ($cmd == 0) {
     		$this->setCurrentTheme($themeName);
 		    $message = $themeName . " is now active.";
-        	$this->response = array("return" => true, "message" => $message);
+        	$this->responseHandler->setData(array("return" => true, "message" => $message));
 	    }
 	    else
 	    {
     		$message = "Could not move theme" . $themeName . "(Something is wrong..)";
-        	$this->response = array("return" => false,"message" => $message);
+        	$this->responseHandler->setData(array("return" => false,"message" => $message));
 	    }
     }
     /* Credits to SteveRusin at http://php.net/manual/en/ref.strings.php */
-    private function endsWith($str, $sub)
+    public function endsWith($str, $sub)
     {
         return (substr($str, strlen($str) - strlen($sub)) === $sub);
     }
@@ -435,14 +397,14 @@ class Themes extends Module
     */
     public function handleDeleteTheme()
     {
-        $themeName = $this->request->name;
+        $themeName = $this->request['name'];
 	    exec("rm {$this->CSS_DIR}{$themeName}");
 	    if (!file_exists("/pineapple/modules/Themes/css/" . $themeName)) {
             $message = "Deleted " . $themeName;
         } else {
             $message = "Error deleting " . $themeName;
         }
-        $this->response = array("message" => $message);
+        $this->responseHandler->setData(array("message" => $message));
     }
     /*
     *  submitThemeCode
@@ -450,16 +412,16 @@ class Themes extends Module
     */
     public function submitThemeCode()
     {
-	$code = $this->request->themeCode;
-        $themeName = $this->request->name;
-        $fileName = $this->request->fileName;
+	$code = $this->request['themeCode'];
+        $themeName = $this->request['name'];
+        $fileName = $this->request['fileName'];
         file_put_contents($this->CSS_DIR . $themeName, $code);
         $message = (!file_exists($this->CSS_DIR . $themeName)) ? "Created " . $themeName : "Updated " . $themeName;
         
-        $this->response = array(
+        $this->responseHandler->setData(array(
             "message" => $message,
 	    "filename" => $fileName
-        );
+        ));
    }
    /*
    *  handleGetThemeList
@@ -477,7 +439,7 @@ class Themes extends Module
                 array_push($all_themes, $obj);
             }
         }
-        $this->response = $all_themes;
+        $this->responseHandler->setData($all_themes);
     }
     /*
     *  handleCreateNewTheme
@@ -486,16 +448,16 @@ class Themes extends Module
     public function handleCreateNewTheme()
     {
     	$themePath = $this->CSS_DIR;
-        $themeName = str_replace(' ', '_', $this->request->themeName);
+        $themeName = str_replace(' ', '_', $this->request['themeName']);
 	    if (!$this->endswith($themeName, '.css')) {
     		$themeName = $themeName . ".css";
 	    }
         if (file_exists($themePath . $themeName)) {
-            $this->response = array("create_success" => false, "create_message" => "A theme named {$themeName} already exists.");
+            $this->responseHandler->setData(array("create_success" => false, "create_message" => "A theme named {$themeName} already exists."));
 	    return;
         }
         exec("cp {$this->SKELETON_CSS} {$themePath}{$themeName}");
-        $this->response = array("create_success" => true, "create_message" => "Created {$themeName}");
+        $this->responseHandler->setData(array("create_success" => true, "create_message" => "Created {$themeName}"));
     }
     /*
     * backupFiles
@@ -550,13 +512,13 @@ class Themes extends Module
                 array_push($modules, "Wrote to {$current}.");
             }
         }
-        $this->response = array(
+        $this->responseHandler->setData(array(
             "success" => $success, 
             "message" => $success ? 
                 "Created a backup file for all files" : 
                     "Failed to backup files! Tread lightly",
             "modules" => $modules
-        );
+        ));
     }
     public function backupModuleIcon($currentFile) {
         if (!file_exists($currentFile)) {

+ 28 - 71
modules/src/ZeroTier/api/module.php

@@ -1,53 +1,10 @@
-<?php namespace pineapple;
-// 2023 - m5kro
+<?php namespace frieren\core;
 
-class ZeroTier extends Module
+/* Code modified by Frieren Auto Refactor */
+// 2023 - m5kro
+class ZeroTier extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-
-            case "getDependenciesStatus":
-                $this->getDependenciesStatus();
-                break;
-
-            case "managerDependencies":
-                $this->managerDependencies();
-                break;
-
-            case "getDependenciesInstallStatus":
-                $this->getDependenciesInstallStatus();
-                break;
-            
-            case "getZeroTierStatus":
-                $this->getZeroTierStatus();
-                break;
-
-            case "zerotierSwitch":
-                $this->zerotierSwitch();
-                break;
-
-            case "zerotierBootSwitch":
-                $this->zerotierBootSwitch();
-                break;
-
-            case "zerotierSetID":
-                $this->zerotierSetID();
-                break;
-
-            case "zerotierGetID":
-                $this->zerotierGetID();
-                break;
-
-            case "zerotierNewIdentity":
-                $this->zerotierNewIdentity();
-                break;
-
-            case "zerotierGetIdentity":
-                $this->zerotierGetIdentity();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['getDependenciesStatus', 'managerDependencies', 'getDependenciesInstallStatus', 'getZeroTierStatus', 'zerotierSwitch', 'zerotierBootSwitch', 'zerotierSetID', 'zerotierGetID', 'zerotierNewIdentity', 'zerotierGetIdentity'];
 
     // Thanks to xchwarze (DSR) for most of the dependencies code
     protected function getDependenciesStatus()
@@ -70,12 +27,12 @@ class ZeroTier extends Module
             $response["installed"] = true;
         }
 
-        $this->response = $response;
+        $this->responseHandler->setData($response);
     }
 
     protected function checkDependencyInstalled()
     {      
-        if ($this->checkDependency("zerotier-cli")) {
+        if ($this->systemHelper->checkDependency("zerotier-cli")) {
             return true; 
         }
 
@@ -86,13 +43,13 @@ class ZeroTier extends Module
     {
         $action = $this->checkDependencyInstalled() ? "remove" : "install";
         $command = "/pineapple/modules/ZeroTier/scripts/dependencies.sh";
-        $this->execBackground("{$command} {$action} {$this->request->where}");
-        $this->response = ["success" => true];
+        $this->systemHelper->execBackground("{$command} {$action} {$this->request['where']}");
+        $this->responseHandler->setData(["success" => true]);
     }
 
     protected function getDependenciesInstallStatus()
     {
-        $this->response = ["success" => !file_exists("/tmp/zerotier.progress")];
+        $this->responseHandler->setData(["success" => !file_exists("/tmp/zerotier.progress")]);
     }
 
     protected function getZeroTierStatus()
@@ -105,12 +62,12 @@ class ZeroTier extends Module
             "ip" => ""
         ];
 
-        if ($this->checkRunning("zerotier-one")) {
+        if ($this->systemHelper->checkRunning("zerotier-one")) {
             $response["running"] = "Stop";
             $response["runningLabel"] = "danger";
-            $interface = exec("/usr/bin/zerotier-cli get {$this->uciGet("zerotier.openwrt_network.join")} portDeviceName");
+            $interface = exec("/usr/bin/zerotier-cli get {$this->systemHelper->uciGet("zerotier.openwrt_network.join")} portDeviceName");
             $response["ip"] = exec("/sbin/ifconfig {$interface} | /bin/grep 'inet addr' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{print $1}'");
-            $this->execBackground("rm /tmp/zerotier.process");
+            $this->systemHelper->execBackground("rm /tmp/zerotier.process");
         } else if (file_exists("/tmp/zerotier.process")) {
             $response["running"] = "Starting...";
             $response["runningLabel"] = "warning";
@@ -124,15 +81,15 @@ class ZeroTier extends Module
             $response["bootLabel"] = "success";
         }
 
-        $this->response = $response;
+        $this->responseHandler->setData($response);
     }
 
     protected function zerotierSwitch()
     {
-        if ($this->checkRunning("zerotier-one")) {
-            $this->execBackground("/etc/init.d/zerotier stop && rm /tmp/zerotier.process");
+        if ($this->systemHelper->checkRunning("zerotier-one")) {
+            $this->systemHelper->execBackground("/etc/init.d/zerotier stop && rm /tmp/zerotier.process");
         } else {
-            $this->execBackground("touch /tmp/zerotier.process && /etc/init.d/zerotier start");
+            $this->systemHelper->execBackground("touch /tmp/zerotier.process && /etc/init.d/zerotier start");
         }
 
     }
@@ -140,37 +97,37 @@ class ZeroTier extends Module
     protected function zerotierBootSwitch()
     {
         if (file_exists("/pineapple/modules/ZeroTier/zerotier.boot")) {
-            $this->execBackground("/etc/init.d/zerotier disable && rm /pineapple/modules/ZeroTier/zerotier.boot");
+            $this->systemHelper->execBackground("/etc/init.d/zerotier disable && rm /pineapple/modules/ZeroTier/zerotier.boot");
         } else {
-            $this->execBackground("/etc/init.d/zerotier enable && touch /pineapple/modules/ZeroTier/zerotier.boot");
+            $this->systemHelper->execBackground("/etc/init.d/zerotier enable && touch /pineapple/modules/ZeroTier/zerotier.boot");
         }
     }
 
     protected function zerotierSetID()
     {
-        if($this->request->ID === ""){
-            $this->uciSet("zerotier.openwrt_network.join", null);
+        if($this->request['ID'] === ""){
+            $this->systemHelper->uciSet("zerotier.openwrt_network.join", null);
         } else {
-            $this->uciSet("zerotier.openwrt_network.join", null);
-            $this->uciAddList("zerotier.openwrt_network.join", $this->request->ID);
+            $this->systemHelper->uciSet("zerotier.openwrt_network.join", null);
+            $this->systemHelper->uciSet("zerotier.openwrt_network.join", $this->request['ID'], true);
         }
-        $this->response = ["confirm" => "Success"];
+        $this->responseHandler->setData(["confirm" => "Success"]);
     }
 
     protected function zerotierGetID()
     {
-        $this->response = ["ID" => $this->uciGet("zerotier.openwrt_network.join")];
+        $this->responseHandler->setData(["ID" => $this->systemHelper->uciGet("zerotier.openwrt_network.join")]);
     }
 
     protected function zerotierNewIdentity()
     {
-        $this->uciSet("zerotier.openwrt_network.secret", null);
-        $this->execBackground("rm -rf /var/lib/zerotier-one && /etc/init.d/zerotier restart && /etc/init.d/zerotier stop");
+        $this->systemHelper->uciSet("zerotier.openwrt_network.secret", null);
+        $this->systemHelper->execBackground("rm -rf /var/lib/zerotier-one && /etc/init.d/zerotier restart && /etc/init.d/zerotier stop");
     }
 
     protected function zerotierGetIdentity()
     {
-        $this->response = ["identity" => $this->uciGet("zerotier.openwrt_network.secret")];
+        $this->responseHandler->setData(["identity" => $this->systemHelper->uciGet("zerotier.openwrt_network.secret")]);
     }
 
 }

+ 40 - 89
modules/src/autossh/api/module.php

@@ -1,91 +1,42 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class autossh extends Module
+/* Code modified by Frieren Auto Refactor */
+class autossh extends Controller
 {
-  public function route()
-  {
-
-    switch ($this->request->action) {
-      case 'status':
-      $this->status();
-      break;
-
-      case 'getInfo':
-      $this->getInfo();
-      break;
-
-      case 'stopAutossh':
-      $this->stopAutossh();
-      break;
-
-      case 'startAutossh':
-      $this->startAutossh();
-      break;
-
-      case 'enableAutossh':
-      $this->enableAutossh();
-      break;
-
-      case 'disableAutossh':
-      $this->disableAutossh();
-      break;
-
-      case 'readConf':
-      $this->readConf();
-      break;
-
-      case 'writeConf':
-      $this->writeConf();
-      break;
-
-      case 'resetConf':
-      $this->resetConf();
-      break;
-
-      case 'createSshKey':
-      $this->createSshKey();
-      break;
-
-      case 'deleteKey':
-      $this->deleteKey();
-      break;
-
-    }
-
-  }
+  protected $endpointRoutes = ['status', 'getInfo', 'stopAutossh', 'startAutossh', 'enableAutossh', 'disableAutossh', 'readConf', 'writeConf', 'resetConf', 'createSshKey', 'deleteKey'];
 
 // Initial Setup
-  private function createSshKey()
+  public function createSshKey()
   {
     $path = "/root/.ssh/id_rsa.autossh";
     exec("ssh-keygen -f $path -t rsa -N ''");
     if (file_exists($path)) {
-      $this->response = array("success" => true);
+      $this->responseHandler->setData(array("success" => true));
     }
   }
 
-  private function deleteKey()
+  public function deleteKey()
   {
     exec('rm /root/.ssh/id_rsa.autossh*');
-    $this->response = array("success" => true);
+    $this->responseHandler->setData(array("success" => true));
   }
 
-  private function ensureKnownHosts($args)
+  public function ensureKnownHosts($args)
   {
     $cmd = "ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no -p $args->port $args->user@$args->host exit";
-    $this->execBackground($cmd);
+    $this->systemHelper->execBackground($cmd);
   }
 
-  private function getInfo()
+  public function getInfo()
   {
-    $this->response = array(
+    $this->responseHandler->setData(array(
       "success" => true,
       "pubKey" => $this->safeRead('/root/.ssh/id_rsa.autossh.pub'),
       "knownHosts" => shell_exec("awk '{print $1}' /root/.ssh/known_hosts")
-    );
+    ));
   }
 
-  private function safeRead($file)
+  public function safeRead($file)
   {
     return file_exists($file) ? file_get_contents($file) : "";
   }
@@ -93,42 +44,42 @@ class autossh extends Module
 
 
 // Configuration
-  private function readConf()
+  public function readConf()
   {
     $conf = $this->parsedConfig() + array("success" => true);
-    $this->response = $conf;
+    $this->responseHandler->setData($conf);
   }
 
-  private function resetConf()
+  public function resetConf()
   {
     exec("cp /rom/etc/config/autossh /etc/config/autossh");
-    return $this->response = $this->parsedConfig() + array("success" => true);
+    return $this->responseHandler->setData($this->parsedConfig() + array("success" => true));
   }
 
-  private function parsedConfig()
+  public function parsedConfig()
   {
     $uciString = "autossh.@autossh[0].ssh";
-    $contents = $this->uciGet($uciString);
+    $contents = $this->systemHelper->uciGet($uciString);
     $args = preg_split("/\s|\t|:|@|'/", $contents);
     return $this->parseArguments(array_filter($args));
   }
 
-  private function writeConf()
+  public function writeConf()
   {
-    $args = $this->request->data;
+    $args = $this->request['data'];
     $uciString = "autossh.@autossh[0].ssh";
     $option = $this->buildOptionString($args);
     $this->ensureKnownHosts($args);
-    $this->uciSet($uciString, $option);
-    $this->response = array("success" => true);
+    $this->systemHelper->uciSet($uciString, $option);
+    $this->responseHandler->setData(array("success" => true));
   }
 
-  private function buildOptionString($args)
+  public function buildOptionString($args)
   {
     return "-i /root/.ssh/id_rsa.autossh -N -T -R $args->rport:localhost:$args->lport $args->user@$args->host -p $args->port";
   }
 
-  private function parseArguments($args)
+  public function parseArguments($args)
   {
     return array(
       "user" => $args[8],
@@ -142,48 +93,48 @@ class autossh extends Module
 
   // Management
 
-  private function status()
+  public function status()
   {
-    $this->response = array(
+    $this->responseHandler->setData(array(
       "success" => true,
       "isRunning" => $this->isRunning(),
       "isEnabled" => $this->isEnabled()
-    );
+    ));
   }
 
-  private function isRunning()
+  public function isRunning()
   {
-    return $this->checkRunning("autossh");
+    return $this->systemHelper->checkRunning("autossh");
   }
 
-  private function isEnabled()
+  public function isEnabled()
   {
     $rcFile = "/etc/rc.d/S80autossh";
     return file_exists($rcFile);
   }
 
-  private function startAutossh()
+  public function startAutossh()
   {
     exec("/etc/init.d/autossh start");
-    $this->response = array("success" => true);
+    $this->responseHandler->setData(array("success" => true));
   }
 
-  private function stopAutossh()
+  public function stopAutossh()
   {
     exec("/etc/init.d/autossh stop");
-    $this->response = array("success" => true);
+    $this->responseHandler->setData(array("success" => true));
   }
 
-  private function enableAutossh()
+  public function enableAutossh()
   {
     exec("/etc/init.d/autossh enable");
-    $this->response = array("success" => true);
+    $this->responseHandler->setData(array("success" => true));
   }
 
-  private function disableAutossh()
+  public function disableAutossh()
   {
     exec("/etc/init.d/autossh disable");
-    $this->response = array("success" => true);
+    $this->responseHandler->setData(array("success" => true));
   }
 
 }

+ 15 - 31
modules/src/base64encdec/api/module.php

@@ -1,53 +1,37 @@
-<?php namespace pineapple;
-
+<?php namespace frieren\core;
 
+/* Code modified by Frieren Auto Refactor */
 /* The class name must be the name of your module, without spaces. */
 /* It must also extend the "Module" class. This gives your module access to API functions */
-class base64encdec extends Module
+class base64encdec extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'getContents':    // If you request the action "getContents" from your Javascript, this is where the PHP will see it, and use the correct function
-                $this->getContents();  // $this->getContents(); refers to your private function that contains all of the code for your request.
-                break;                 // Break here, and add more cases after that for different requests.
-
-            case 'encode':
-                $this->encode();
-                break;
-
-            case 'decode':
-                $this->decode();
-                break;
-
-        }
-    }
+    protected $endpointRoutes = ['getContents', 'encode', 'decode'];
 
-    private function getContents()  // This is the function that will be executed when you send the request "getContents".
+    public function getContents()  // This is the function that will be executed when you send the request "getContents".
     {
-        $this->response = array("success" => true,    // define $this->response. We can use an array to set multiple responses.
+        $this->responseHandler->setData(array("success" => true,    // define $this->response. We can use an array to set multiple responses.
                                 "greeting" => "Hey there!",
-                                "content" => "This is the HTML template for your new module! The example shows you the basics of using HTML, AngularJS and PHP to seamlessly pass information to and from Javascript and PHP and output it to HTML.");
+                                "content" => "This is the HTML template for your new module! The example shows you the basics of using HTML, AngularJS and PHP to seamlessly pass information to and from Javascript and PHP and output it to HTML."));
     }
 
-    private function encode()  
+    public function encode()  
     {
-        $inputContent = $this->request->data;
+        $inputContent = $this->request['data'];
         
         $result = base64_encode( $inputContent );
         
-        $this->response = array("success" => true,
-                                "content" => $result);
+        $this->responseHandler->setData(array("success" => true,
+                                "content" => $result));
     }
 
-   private function decode()  
+   public function decode()  
     {
-        $inputContent = $this->request->data;
+        $inputContent = $this->request['data'];
         
         $result = base64_decode( $inputContent );
         
-        $this->response = array("success" => true,
-                                "content" => $result);
+        $this->responseHandler->setData(array("success" => true,
+                                "content" => $result));
     }
 
 }

+ 62 - 107
modules/src/dump1090/api/module.php

@@ -1,58 +1,13 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class dump1090 extends Module
+/* Code modified by Frieren Auto Refactor */
+class dump1090 extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'refreshInfo':
-                $this->refreshInfo();
-                break;
-            case 'refreshOutput':
-                $this->refreshOutput();
-                break;
-            case 'clearOutput':
-                $this->clearOutput();
-                break;
-            case 'refreshStatus':
-                $this->refreshStatus();
-                break;
-            case 'toggledump1090':
-                $this->toggledump1090();
-                break;
-            case 'handleDependencies':
-                $this->handleDependencies();
-                break;
-            case 'handleDependenciesStatus':
-                $this->handleDependenciesStatus();
-                break;
-            case 'refreshHistory':
-                $this->refreshHistory();
-                break;
-            case 'deleteHistory':
-                $this->deleteHistory();
-                break;
-            case 'downloadHistory':
-                $this->downloadHistory();
-                break;
-            case 'viewHistory':
-                $this->viewHistory();
-                break;
-            case 'getSettings':
-                $this->getSettings();
-                break;
-            case 'setSettings':
-                $this->setSettings();
-                break;
-            case 'refreshList':
-                $this->refreshList();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['refreshInfo', 'refreshOutput', 'clearOutput', 'refreshStatus', 'toggledump1090', 'handleDependencies', 'handleDependenciesStatus', 'refreshHistory', 'deleteHistory', 'downloadHistory', 'viewHistory', 'getSettings', 'setSettings', 'refreshList'];
 
     protected function checkDep($dependencyName)
     {
-        return ($this->checkDependency($dependencyName) && ($this->uciGet("dump1090.module.installed")));
+        return ($this->systemHelper->checkDependency($dependencyName) && ($this->systemHelper->uciGet("dump1090.module.installed")));
     }
 
     protected function getDevice()
@@ -63,42 +18,42 @@ class dump1090 extends Module
     protected function refreshInfo()
     {
         $moduleInfo = @json_decode(file_get_contents("/pineapple/modules/dump1090/module.info"));
-        $this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
+        $this->responseHandler->setData(array('title' => $moduleInfo->title, 'version' => $moduleInfo->version));
     }
 
-    private function handleDependencies()
+    public function handleDependencies()
     {
         if (!$this->checkDep("dump1090")) {
-            $this->execBackground("/pineapple/modules/dump1090/scripts/dependencies.sh install ".$this->request->destination);
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/dump1090/scripts/dependencies.sh install ".$this->request['destination']);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->execBackground("/pineapple/modules/dump1090/scripts/dependencies.sh remove");
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/dump1090/scripts/dependencies.sh remove");
+            $this->responseHandler->setData(array('success' => true));
         }
     }
 
-    private function handleDependenciesStatus()
+    public function handleDependenciesStatus()
     {
         if (!file_exists('/tmp/dump1090.progress')) {
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function toggledump1090()
+    public function toggledump1090()
     {
-        if (!$this->checkRunning("dump1090")) {
-            $this->execBackground("/pineapple/modules/dump1090/scripts/dump1090.sh start");
+        if (!$this->systemHelper->checkRunning("dump1090")) {
+            $this->systemHelper->execBackground("/pineapple/modules/dump1090/scripts/dump1090.sh start");
         } else {
-            $this->execBackground("/pineapple/modules/dump1090/scripts/dump1090.sh stop");
+            $this->systemHelper->execBackground("/pineapple/modules/dump1090/scripts/dump1090.sh stop");
         }
     }
 
-    private function refreshStatus()
+    public function refreshStatus()
     {
         if (!file_exists('/tmp/dump1090.progress')) {
-            if (!$this->checkDependency("dump1090")) {
+            if (!$this->systemHelper->checkDependency("dump1090")) {
                 $installed = false;
                 $install = "Not installed";
                 $installLabel = "danger";
@@ -113,7 +68,7 @@ class dump1090 extends Module
                 $installLabel = "success";
                 $processing = false;
 
-                if ($this->checkRunning("dump1090")) {
+                if ($this->systemHelper->checkRunning("dump1090")) {
                     $status = "Stop";
                     $statusLabel = "danger";
                     $running = true;
@@ -134,36 +89,36 @@ class dump1090 extends Module
             $running = false;
         }
 
-        $device = $this->getDevice();
-        $sdAvailable = $this->isSDAvailable();
+        $device = $this->systemHelper->getDevice();
+        $sdAvailable = $this->systemHelper->isSDAvailable();
 
-        $this->response = array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "processing" => $processing, "running" => $running);
+        $this->responseHandler->setData(array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "processing" => $processing, "running" => $running));
     }
 
-    private function refreshOutput()
+    public function refreshOutput()
     {
-        if ($this->checkDependency("dump1090")) {
+        if ($this->systemHelper->checkDependency("dump1090")) {
             if (file_exists("/tmp/dump1090_capture.log")) {
                 $output = file_get_contents("/tmp/dump1090_capture.log");
                 if (!empty($output)) {
-                    $this->response = $output;
+                    $this->responseHandler->setData($output);
                 } else {
-                    $this->response = "dump1090 is running...";
+                    $this->responseHandler->setData("dump1090 is running...");
                 }
             } else {
-                $this->response = "dump1090 is not running...";
+                $this->responseHandler->setData("dump1090 is not running...");
             }
         } else {
-            $this->response = "dump1090 is not installed...";
+            $this->responseHandler->setData("dump1090 is not installed...");
         }
     }
 
-    private function clearOutput()
+    public function clearOutput()
     {
         exec("rm -rf /tmp/dump1090_capture.log");
     }
 
-    private function refreshHistory()
+    public function refreshHistory()
     {
         $this->streamFunction = function () {
             $log_list = array_reverse(glob("/pineapple/modules/dump1090/log/*.log"));
@@ -188,70 +143,70 @@ class dump1090 extends Module
         };
     }
 
-    private function downloadHistory()
+    public function downloadHistory()
     {
-        $this->response = array("download" => $this->downloadFile("/pineapple/modules/dump1090/log/".$this->request->file));
+        $this->responseHandler->setData(array("download" => $this->systemHelper->downloadFile("/pineapple/modules/dump1090/log/".$this->request['file'])));
     }
 
-    private function viewHistory()
+    public function viewHistory()
     {
-        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/dump1090/log/".$this->request->file));
-        exec("strings /pineapple/modules/dump1090/log/".$this->request->file, $output);
+        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/dump1090/log/".$this->request['file']));
+        exec("strings /pineapple/modules/dump1090/log/".$this->request['file'], $output);
 
         if (!empty($output)) {
-            $this->response = array("output" => implode("\n", $output), "date" => $log_date);
+            $this->responseHandler->setData(array("output" => implode("\n", $output), "date" => $log_date));
         } else {
-            $this->response = array("output" => "Empty log...", "date" => $log_date);
+            $this->responseHandler->setData(array("output" => "Empty log...", "date" => $log_date));
         }
     }
 
-    private function deleteHistory()
+    public function deleteHistory()
     {
-        $file = basename($this->request->file, ".log");
+        $file = basename($this->request['file'], ".log");
         exec("rm -rf /pineapple/modules/dump1090/log/".$file.".*");
     }
 
-    private function getSettings()
+    public function getSettings()
     {
         $settings = array(
-                    'csv' => $this->uciGet("dump1090.settings.csv"),
-                    'gain' => $this->uciGet("dump1090.settings.gain"),
-                    'frequency' => $this->uciGet("dump1090.settings.frequency"),
-                    'metrics' => $this->uciGet("dump1090.settings.metrics"),
-                    'agc' => $this->uciGet("dump1090.settings.agc"),
-                    'aggressive' => $this->uciGet("dump1090.settings.aggressive")
+                    'csv' => $this->systemHelper->uciGet("dump1090.settings.csv"),
+                    'gain' => $this->systemHelper->uciGet("dump1090.settings.gain"),
+                    'frequency' => $this->systemHelper->uciGet("dump1090.settings.frequency"),
+                    'metrics' => $this->systemHelper->uciGet("dump1090.settings.metrics"),
+                    'agc' => $this->systemHelper->uciGet("dump1090.settings.agc"),
+                    'aggressive' => $this->systemHelper->uciGet("dump1090.settings.aggressive")
                     );
-        $this->response = array('settings' => $settings);
+        $this->responseHandler->setData(array('settings' => $settings));
     }
 
-    private function setSettings()
+    public function setSettings()
     {
-        $settings = $this->request->settings;
-        $this->uciSet("dump1090.settings.gain", $settings->gain);
-        $this->uciSet("dump1090.settings.frequency", $settings->frequency);
+        $settings = $this->request['settings'];
+        $this->systemHelper->uciSet("dump1090.settings.gain", $settings->gain);
+        $this->systemHelper->uciSet("dump1090.settings.frequency", $settings->frequency);
         if ($settings->csv) {
-            $this->uciSet("dump1090.settings.csv", 1);
+            $this->systemHelper->uciSet("dump1090.settings.csv", 1);
         } else {
-            $this->uciSet("dump1090.settings.csv", 0);
+            $this->systemHelper->uciSet("dump1090.settings.csv", 0);
         }
         if ($settings->metrics) {
-            $this->uciSet("dump1090.settings.metrics", 1);
+            $this->systemHelper->uciSet("dump1090.settings.metrics", 1);
         } else {
-            $this->uciSet("dump1090.settings.metrics", 0);
+            $this->systemHelper->uciSet("dump1090.settings.metrics", 0);
         }
         if ($settings->agc) {
-            $this->uciSet("dump1090.settings.agc", 1);
+            $this->systemHelper->uciSet("dump1090.settings.agc", 1);
         } else {
-            $this->uciSet("dump1090.settings.agc", 0);
+            $this->systemHelper->uciSet("dump1090.settings.agc", 0);
         }
         if ($settings->aggressive) {
-            $this->uciSet("dump1090.settings.aggressive", 1);
+            $this->systemHelper->uciSet("dump1090.settings.aggressive", 1);
         } else {
-            $this->uciSet("dump1090.settings.aggressive", 0);
+            $this->systemHelper->uciSet("dump1090.settings.aggressive", 0);
         }
     }
 
-    private function refreshList()
+    public function refreshList()
     {
         $this->streamFunction = function () {
             echo file_get_contents("http://127.0.0.1:9090/data.json");

+ 54 - 94
modules/src/get/api/module.php

@@ -1,87 +1,47 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-require_once('DatabaseConnection.php');
+/* Code modified by Frieren Auto Refactor */
+
+'';
 
 define('__INCLUDES__', $pineapple->directory . "/includes/");
 define('__LOGS__', __INCLUDES__ . "logs/");
 
-class get extends Module
+class get extends Controller
 {
+    protected $endpointRoutes = ['getControlValues', 'handleIFrame', 'handleInfoGetter', 'handleDBLocation', 'getClientProfiles', 'viewInformation', 'deleteProfile', 'getComments', 'saveComments'];
     private $dbConnection;
     private $dbPath;
     const DATABASE = "/etc/pineapple/get.db";
     
-    private function prepareDatabase()
+    public function prepareDatabase()
     {
         if ( $this->doesLocationFileExist("/etc/pineapple/get_database_location") )
         {
             $dbPath = trim(file_get_contents("/etc/pineapple/get_database_location")) . "get.db";
-            $this->dbConnection = new DatabaseConnection($dbPath);
+            $this->dbConnection = new \frieren\orm\SQLite($dbPath);
         }
         else
         {
-            $this->dbConnection = new DatabaseConnection(self::DATABASE);
+            $this->dbConnection = new \frieren\orm\SQLite(self::DATABASE);
         }
         
-        $this->dbConnection->exec("CREATE TABLE IF NOT EXISTS info (id INTEGER NOT NULL, mac TEXT NOT NULL, ip TEXT, hostname TEXT, info TEXT NOT NULL, timestamp TEXT NOT NULL, PRIMARY KEY(id) );");
-        $this->dbConnection->exec("CREATE TABLE IF NOT EXISTS comments (id INTEGER NOT NULL, info_id INTEGER NOT NULL, mac TEXT NOT NULL, comments TEXT, PRIMARY KEY(id) );");
-    }
-    
-    public function route()
-    {
-        $this->prepareDatabase();
-
-        switch($this->request->action) {
-            case 'getControlValues':
-                $this->getControlValues();
-                break;
-
-            case 'handleIFrame':
-                $this->handleIFrame();
-                break;
-
-            case 'handleInfoGetter':
-                $this->handleInfoGetter();
-                break;
-
-            case 'handleDBLocation':
-                $this->handleDBLocation();
-                break;
-
-            case 'getClientProfiles':
-                $this->handlegetClientProfiles();
-                break;
-
-            case 'viewInformation':
-                $this->handleviewInformation();
-                break;
-
-            case 'deleteProfile':
-                $this->handledeleteProfile();
-                break;
-
-            case 'getComments':
-                $this->handlegetComments();
-                break;
-
-            case 'saveComments':
-                $this->handlesaveComments();
-                break;
-        }
+        $this->dbConnection->execLegacy("CREATE TABLE IF NOT EXISTS info (id INTEGER NOT NULL, mac TEXT NOT NULL, ip TEXT, hostname TEXT, info TEXT NOT NULL, timestamp TEXT NOT NULL, PRIMARY KEY(id) );");
+        $this->dbConnection->execLegacy("CREATE TABLE IF NOT EXISTS comments (id INTEGER NOT NULL, info_id INTEGER NOT NULL, mac TEXT NOT NULL, comments TEXT, PRIMARY KEY(id) );");
     }
 
 
     public function handlesaveComments()
     {
         $this->prepareDatabase();
-        $id  = $this->request->id;
-        $comments = $this->request->comments;
-        $mac = $this->request->mac;
-        $info_id = $this->request->id;
+        $id  = $this->request['id'];
+        $comments = $this->request['comments'];
+        $mac = $this->request['mac'];
+        $info_id = $this->request['id'];
         $record_needs_to_be_updated = false;
 
         // lets first try to query for the info. If it exists, we will have a row, and the loop will set the flag to true
-        $result = $this->dbConnection->query("SELECT * FROM comments WHERE info_id = '%s';", $info_id);
+        $result = $this->dbConnection->queryLegacy("SELECT * FROM comments WHERE info_id = '%s';", $info_id);
 
         foreach($result as $row) {
             $count = $row['mac'];
@@ -106,77 +66,77 @@ class get extends Module
 
         if ( $record_needs_to_be_updated == true )
         {
-            $this->dbConnection->exec("UPDATE comments SET mac = '%s', comments = '%s' WHERE info_id = '%s';", $mac, $comments, $info_id);
+            $this->dbConnection->execLegacy("UPDATE comments SET mac = '%s', comments = '%s' WHERE info_id = '%s';", $mac, $comments, $info_id);
             $message = "Updated comments for mac [" . $mac . "]";
             #$this->logError("mylog.txt", $message);
         }   
         else
         {
-            $this->dbConnection->exec("INSERT INTO comments (info_id, mac, comments) VALUES('%s','%s','%s');", $info_id, $mac, $comments);
+            $this->dbConnection->execLegacy("INSERT INTO comments (info_id, mac, comments) VALUES('%s','%s','%s');", $info_id, $mac, $comments);
             $message = "Saved comments for mac [" . $mac . "]";
             #$this->logError("mylog.txt", $message);
         }
         
         $control_message = $message;
-        $this->response = array("message" => $message, 
+        $this->responseHandler->setData(array("message" => $message, 
                                 "control_message" => $control_message
-                                );
+                                ));
     }
 
     public function handlegetComments() {
         $this->prepareDatabase();
-        $id  = $this->request->id;
-        $mac = $this->request->mac;
+        $id  = $this->request['id'];
+        $mac = $this->request['mac'];
         
-        $result = $this->dbConnection->query("SELECT comments FROM comments WHERE id = '%s';", $id);
+        $result = $this->dbConnection->queryLegacy("SELECT comments FROM comments WHERE id = '%s';", $id);
 
         $message = "Comments Section displaying info for [" . $mac . "]";
         $control_message = $message;
         $comments = $result[0]["comments"];
-        $this->response = array("message" => $message, 
+        $this->responseHandler->setData(array("message" => $message, 
                                 "control_message" => $control_message,
                                 "mac" => $mac,
                                 "comments" => $comments
-                                );
+                                ));
     }
 
 
     public function handledeleteProfile() {
         $this->prepareDatabase();
-        $id  = $this->request->id;
-        $mac = $this->request->mac;
+        $id  = $this->request['id'];
+        $mac = $this->request['mac'];
         
-        $result = $this->dbConnection->query("DELETE FROM info WHERE id = '%s';", $id);
+        $result = $this->dbConnection->queryLegacy("DELETE FROM info WHERE id = '%s';", $id);
 
         $message = "Deleted information for [" . $mac . "]";
         $control_message = $message;
 
-        $this->response = array("message" => $message, 
+        $this->responseHandler->setData(array("message" => $message, 
                                 "control_message" => $control_message
-                                );
+                                ));
     }
 
     public function handleviewInformation() {
         $this->prepareDatabase();
-        $id  = $this->request->id;
-        $mac = $this->request->mac;
+        $id  = $this->request['id'];
+        $mac = $this->request['mac'];
         
-        $result = $this->dbConnection->query("SELECT info FROM info WHERE id = '%s';", $id);
+        $result = $this->dbConnection->queryLegacy("SELECT info FROM info WHERE id = '%s';", $id);
 
         $message = "Information Section displaying info for [" . $mac . "]";
         $control_message = $message;
         $info = $result[0]["info"];
-        $this->response = array("message" => $message, 
+        $this->responseHandler->setData(array("message" => $message, 
                                 "control_message" => $control_message,
                                 "info" => $info
-                                );
+                                ));
     }
 
     public function handlegetClientProfiles() {
         $this->prepareDatabase();
 
         $all_profiles = array();
-        $result = $this->dbConnection->query("SELECT a.id, a.mac, ip, hostname, timestamp, comments FROM info a left join comments b on a.id = b.info_id WHERE a.mac != '';");
+        $result = $this->dbConnection->queryLegacy("SELECT a.id, a.mac, ip, hostname, timestamp, comments FROM info a left join comments b on a.id = b.info_id WHERE a.mac != '';");
 
         foreach($result as $row) {
             $obj = array("mac"      => $row["mac"],
@@ -189,11 +149,11 @@ class get extends Module
             array_push($all_profiles, $obj);
         }
 
-        $this->response = $all_profiles;
+        $this->responseHandler->setData($all_profiles);
     }
 
     public function handleDBLocation() {
-        $data = $this->request->data;
+        $data = $this->request['data'];
         
          /* Check whether the user has acceptable input and check if the module already exists * /
         if(empty($data)){
@@ -221,14 +181,14 @@ class get extends Module
         }
 
         $control_message = $message;
-        $this->response = array("message" => $message, 
+        $this->responseHandler->setData(array("message" => $message, 
                                 "control_message" => $control_message,
                                 "dbonsd_status" => $dbonsd_status
-                                );
+                                ));
     }
 
     public function handleInfoGetter() {
-        $data = $this->request->data;
+        $data = $this->request['data'];
 
         //if ( strcmp("false", $data) ) 
         if ( $data == false ) 
@@ -245,14 +205,14 @@ class get extends Module
         }
 
         $control_message = $message;
-        $this->response = array("message" => $message, 
+        $this->responseHandler->setData(array("message" => $message, 
                                 "control_message" => $control_message,
                                 "running_status" => $running_status
-                                );
+                                ));
     }
 
     public function handleIFrame() {
-        $data = $this->request->data;        
+        $data = $this->request['data'];        
         if ( strcmp("false", $data) )
         {
             $message = "called handle iFrame [false]";
@@ -267,21 +227,21 @@ class get extends Module
         }
         
         $control_message = $message;
-        $this->response = array("message" => $message, 
+        $this->responseHandler->setData(array("message" => $message, 
                                 "control_message" => $control_message,
                                 "hidden_status" => $hidden_status
-                                );
+                                ));
     }
 
     // this method runs first. This method loads an array of name value pairs
     // the name is defined by the author. The value is populated based on the 
     // response of the methods that are in this class.
     public function getControlValues() {
-        $this->response = array(
+        $this->responseHandler->setData(array(
                 "enabled" => $this->checkEnabled(),
                 "hidden" => $this->checkHiddenIframe(),
                 "dbonsd" => $this->checkDBonSD()
-            );
+            ));
 
         // running => infogetter
         // hidden => hidden iframe
@@ -345,7 +305,7 @@ class get extends Module
 // ===========================================================================================================
 // ===========================================================================================================
 
-    private function doesLocationFileExist($path)
+    public function doesLocationFileExist($path)
     {
         $filename = $path;
         $found = false;
@@ -362,7 +322,7 @@ class get extends Module
 // ===========================================================================================================
 // ===========================================================================================================
 
-    private function moveToInternal()
+    public function moveToInternal()
     {
         exec("cp /sd/get/get.db /etc/pineapple/get.db.tmp");
         exec("rm /sd/get/get.db");
@@ -386,7 +346,7 @@ class get extends Module
 // ===========================================================================================================
 // ===========================================================================================================
 
-    private function moveToSD()
+    public function moveToSD()
     {
         /*
         // when the db was in a text file.....
@@ -420,7 +380,7 @@ class get extends Module
 // ===========================================================================================================
 // ===========================================================================================================
 
-    private function installGet()
+    public function installGet()
     {
         exec('mv /www/ /www-getbackup/');
         exec('cp -r /pineapple/modules/get/includes/unprotected/ /www/');
@@ -432,7 +392,7 @@ class get extends Module
 // ===========================================================================================================
 // ===========================================================================================================
 
-    private function uninstallGet()
+    public function uninstallGet()
     {
         exec('rm -rf /www/');
         exec('mv /www-getbackup/ /www');
@@ -444,7 +404,7 @@ class get extends Module
 // ===========================================================================================================
 // ===========================================================================================================
 
-    private function installRedirect()
+    public function installRedirect()
     {
         //if ($_GET['action'] == "redirect"){ exec('echo \'<iframe style="display:none;" src="/get/get.php"></iframe>\' | tee -a /www/redirect.php');} 
         //elseif ($_GET['action'] == "unredirect") { exec(' cat /www/redirect.php | sed \'s/<iframe style="display:none;" src="\/get\/get.php"><\/iframe>//\' -i /www/redirect.php');}

+ 7 - 6
modules/src/get/includes/unprotected/get/get.php

@@ -1,7 +1,6 @@
-<?php namespace pineapple;
-    
-    require_once("/pineapple/api/DatabaseConnection.php");
+<?php namespace frieren\core;
     
+    /* Code modified by Frieren Auto Refactor */
     $dbConnection = "";
     $dbPath = "";
     $report = "";
@@ -11,11 +10,11 @@
     if ( doesLocationFileExist("/etc/pineapple/get_database_location") )
     {
         $dbPath = trim(file_get_contents("/etc/pineapple/get_database_location")) . "get.db";
-        $dbConnection = new DatabaseConnection($dbPath);
+        $dbConnection = new \frieren\orm\SQLite($dbPath);
     }
     else
     {
-        $dbConnection = new DatabaseConnection(self::DATABASE);
+        $dbConnection = new \frieren\orm\SQLite(self::DATABASE);
     }
     
     // Run the client report and then parse it for our current client's info...
@@ -213,7 +212,9 @@ if ( mac.length > 0 )
 }
 </script>
 
-<?php namespace pineapple;
+<?php namespace frieren\core;
+
+/* Code modified by Frieren Auto Refactor */
 
 function doesLocationFileExist($path)
 {

+ 8 - 7
modules/src/get/includes/unprotected/get/get_write.php

@@ -1,7 +1,6 @@
-<?php namespace pineapple;
-    
-    require_once("/pineapple/api/DatabaseConnection.php");
+<?php namespace frieren\core;
     
+    /* Code modified by Frieren Auto Refactor */
     $dbConnection = "";
     $dbPath = "";
     $report = "";
@@ -11,11 +10,11 @@
     if ( doesLocationFileExist("/etc/pineapple/get_database_location") )
     {
         $dbPath = trim(file_get_contents("/etc/pineapple/get_database_location")) . "get.db";
-        $dbConnection = new DatabaseConnection($dbPath);
+        $dbConnection = new \frieren\orm\SQLite($dbPath);
     }
     else
     {
-        $dbConnection = new DatabaseConnection(self::DATABASE);
+        $dbConnection = new \frieren\orm\SQLite(self::DATABASE);
         $dbPath = trim(self::DATABASE);
     }
     
@@ -52,7 +51,9 @@ tr:nth-child(odd) {background-color: #333; }
 tr:nth-child(1) {background-color: #DDD; color:#000;}
 </style>
 
-<?php namespace pineapple;
+<?php namespace frieren\core;
+    /* Code modified by Frieren Auto Refactor */
+
     function doesLocationFileExist($path)
     {
         $filename = $path;
@@ -67,7 +68,7 @@ tr:nth-child(1) {background-color: #DDD; color:#000;}
 
     function saveDataToDatabase($dbConnection, $dbPath, $mac, $ip, $hostname, $code, $timestamp)
     {
-        $dbConnection->exec("INSERT INTO info (mac, ip, hostname, info, timestamp) VALUES('%s','%s','%s','%s', '%s');", $mac, $ip, $hostname, $code, $timestamp);
+        $dbConnection->execLegacy("INSERT INTO info (mac, ip, hostname, info, timestamp) VALUES('%s','%s','%s','%s', '%s');", $mac, $ip, $hostname, $code, $timestamp);
     }
 
 ?>

+ 54 - 102
modules/src/ngrep/api/module.php

@@ -1,61 +1,13 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class ngrep extends Module
+/* Code modified by Frieren Auto Refactor */
+class ngrep extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'refreshInfo':
-                $this->refreshInfo();
-                break;
-            case 'refreshOutput':
-                $this->refreshOutput();
-                break;
-            case 'refreshStatus':
-                $this->refreshStatus();
-                break;
-            case 'togglengrep':
-                $this->togglengrep();
-                break;
-            case 'handleDependencies':
-                $this->handleDependencies();
-                break;
-            case 'handleDependenciesStatus':
-                $this->handleDependenciesStatus();
-                break;
-            case 'refreshHistory':
-                $this->refreshHistory();
-                break;
-            case 'viewHistory':
-                $this->viewHistory();
-                break;
-            case 'deleteHistory':
-                $this->deleteHistory();
-                break;
-            case 'downloadHistory':
-                $this->downloadHistory();
-                break;
-            case 'getInterfaces':
-                $this->getInterfaces();
-                break;
-            case 'getProfiles':
-                $this->getProfiles();
-                break;
-            case 'showProfile':
-                $this->showProfile();
-                break;
-            case 'deleteProfile':
-                $this->deleteProfile();
-                break;
-            case 'saveProfileData':
-                $this->saveProfileData();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['refreshInfo', 'refreshOutput', 'refreshStatus', 'togglengrep', 'handleDependencies', 'handleDependenciesStatus', 'refreshHistory', 'viewHistory', 'deleteHistory', 'downloadHistory', 'getInterfaces', 'getProfiles', 'showProfile', 'deleteProfile', 'saveProfileData'];
 
     protected function checkDeps($dependencyName)
     {
-        return ($this->checkDependency($dependencyName) && ($this->uciGet("ngrep.module.installed")));
+        return ($this->systemHelper->checkDependency($dependencyName) && ($this->systemHelper->uciGet("ngrep.module.installed")));
     }
 
     protected function getDevice()
@@ -66,42 +18,42 @@ class ngrep extends Module
     protected function refreshInfo()
     {
         $moduleInfo = @json_decode(file_get_contents("/pineapple/modules/ngrep/module.info"));
-        $this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
+        $this->responseHandler->setData(array('title' => $moduleInfo->title, 'version' => $moduleInfo->version));
     }
 
-    private function handleDependencies()
+    public function handleDependencies()
     {
         if (!$this->checkDeps("ngrep")) {
-            $this->execBackground("/pineapple/modules/ngrep/scripts/dependencies.sh install ".$this->request->destination);
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/ngrep/scripts/dependencies.sh install ".$this->request['destination']);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->execBackground("/pineapple/modules/ngrep/scripts/dependencies.sh remove");
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/ngrep/scripts/dependencies.sh remove");
+            $this->responseHandler->setData(array('success' => true));
         }
     }
 
-    private function handleDependenciesStatus()
+    public function handleDependenciesStatus()
     {
         if (!file_exists('/tmp/ngrep.progress')) {
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function togglengrep()
+    public function togglengrep()
     {
-        if (!$this->checkRunning("ngrep")) {
-            $full_cmd = $this->request->command . " -O /pineapple/modules/ngrep/log/log_".time().".pcap >> /pineapple/modules/ngrep/log/log_".time().".log";
+        if (!$this->systemHelper->checkRunning("ngrep")) {
+            $full_cmd = $this->request['command'] . " -O /pineapple/modules/ngrep/log/log_".time().".pcap >> /pineapple/modules/ngrep/log/log_".time().".log";
             shell_exec("echo -e \"{$full_cmd}\" > /tmp/ngrep.run");
 
-            $this->execBackground("/pineapple/modules/ngrep/scripts/ngrep.sh start");
+            $this->systemHelper->execBackground("/pineapple/modules/ngrep/scripts/ngrep.sh start");
         } else {
-            $this->execBackground("/pineapple/modules/ngrep/scripts/ngrep.sh stop");
+            $this->systemHelper->execBackground("/pineapple/modules/ngrep/scripts/ngrep.sh stop");
         }
     }
 
-    private function refreshStatus()
+    public function refreshStatus()
     {
         if (!file_exists('/tmp/ngrep.progress')) {
             if (!$this->checkDeps("ngrep")) {
@@ -118,7 +70,7 @@ class ngrep extends Module
                 $installLabel = "success";
                 $processing = false;
 
-                if ($this->checkRunning("ngrep")) {
+                if ($this->systemHelper->checkRunning("ngrep")) {
                     $status = "Stop";
                     $statusLabel = "danger";
                 } else {
@@ -136,16 +88,16 @@ class ngrep extends Module
             $statusLabel = "success";
         }
 
-        $device = $this->getDevice();
-        $sdAvailable = $this->isSDAvailable();
+        $device = $this->systemHelper->getDevice();
+        $sdAvailable = $this->systemHelper->isSDAvailable();
 
-        $this->response = array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "processing" => $processing);
+        $this->responseHandler->setData(array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "processing" => $processing));
     }
 
-    private function refreshOutput()
+    public function refreshOutput()
     {
         if ($this->checkDeps("ngrep")) {
-            if ($this->checkRunning("ngrep")) {
+            if ($this->systemHelper->checkRunning("ngrep")) {
                 $path = "/pineapple/modules/ngrep/log";
 
                 $latest_ctime = 0;
@@ -163,8 +115,8 @@ class ngrep extends Module
                 if ($latest_filename != "") {
                     $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/ngrep/log/".$latest_filename));
 
-                    if ($this->request->filter != "") {
-                        $filter = $this->request->filter;
+                    if ($this->request['filter'] != "") {
+                        $filter = $this->request['filter'];
 
                         $cmd = "cat /pineapple/modules/ngrep/log/".$latest_filename." | ".$filter;
                     } else {
@@ -173,22 +125,22 @@ class ngrep extends Module
 
                     exec($cmd, $output);
                     if (!empty($output)) {
-                        $this->response = implode("\n", array_reverse($output));
+                        $this->responseHandler->setData(implode("\n", array_reverse($output)));
                     } else {
-                        $this->response = "Empty log...";
+                        $this->responseHandler->setData("Empty log...");
                     }
                 }
             } else {
-                $this->response = "ngrep is not running...";
+                $this->responseHandler->setData("ngrep is not running...");
             }
         } else {
-            $this->response = "ngrep is not installed...";
+            $this->responseHandler->setData("ngrep is not installed...");
         }
     }
 
-    private function getInterfaces()
+    public function getInterfaces()
     {
-        $this->response = array();
+        $this->responseHandler->setData(array());
         exec("cat /proc/net/dev | tail -n +3 | cut -f1 -d: | sed 's/ //g'", $interfaceArray);
 
         foreach ($interfaceArray as $interface) {
@@ -196,7 +148,7 @@ class ngrep extends Module
         }
     }
 
-    private function refreshHistory()
+    public function refreshHistory()
     {
         $this->streamFunction = function () {
             $log_list = array_reverse(glob("/pineapple/modules/ngrep/log/*.pcap"));
@@ -217,32 +169,32 @@ class ngrep extends Module
         };
     }
 
-    private function downloadHistory()
+    public function downloadHistory()
     {
-        $this->response = array("download" => $this->downloadFile("/pineapple/modules/ngrep/log/".$this->request->file));
+        $this->responseHandler->setData(array("download" => $this->systemHelper->downloadFile("/pineapple/modules/ngrep/log/".$this->request['file'])));
     }
 
-    private function viewHistory()
+    public function viewHistory()
     {
-        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/ngrep/log/".$this->request->file));
-        exec("strings /pineapple/modules/ngrep/log/".$this->request->file, $output);
+        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/ngrep/log/".$this->request['file']));
+        exec("strings /pineapple/modules/ngrep/log/".$this->request['file'], $output);
 
         if (!empty($output)) {
-            $this->response = array("output" => implode("\n", $output), "date" => $log_date);
+            $this->responseHandler->setData(array("output" => implode("\n", $output), "date" => $log_date));
         } else {
-            $this->response = array("output" => "Empty log...", "date" => $log_date);
+            $this->responseHandler->setData(array("output" => "Empty log...", "date" => $log_date));
         }
     }
 
-    private function deleteHistory()
+    public function deleteHistory()
     {
-        $file = basename($this->request->file, ".pcap");
+        $file = basename($this->request['file'], ".pcap");
         exec("rm -rf /pineapple/modules/ngrep/log/".$file.".*");
     }
 
-    private function getProfiles()
+    public function getProfiles()
     {
-        $this->response = array();
+        $this->responseHandler->setData(array());
         $profileList = array_reverse(glob("/pineapple/modules/ngrep/profiles/*"));
         array_push($this->response, array("text" => "--", "value" => "--"));
         foreach ($profileList as $profile) {
@@ -251,20 +203,20 @@ class ngrep extends Module
         }
     }
 
-    private function showProfile()
+    public function showProfile()
     {
-        $profileData = file_get_contents('/pineapple/modules/ngrep/profiles/'.$this->request->profile);
-        $this->response = array("profileData" => $profileData);
+        $profileData = file_get_contents('/pineapple/modules/ngrep/profiles/'.$this->request['profile']);
+        $this->responseHandler->setData(array("profileData" => $profileData));
     }
 
-    private function deleteProfile()
+    public function deleteProfile()
     {
-        exec("rm -rf /pineapple/modules/ngrep/profiles/".$this->request->profile);
+        exec("rm -rf /pineapple/modules/ngrep/profiles/".$this->request['profile']);
     }
 
-    private function saveProfileData()
+    public function saveProfileData()
     {
-        $filename = "/pineapple/modules/ngrep/profiles/".$this->request->profile;
-        file_put_contents($filename, $this->request->profileData);
+        $filename = "/pineapple/modules/ngrep/profiles/".$this->request['profile'];
+        file_put_contents($filename, $this->request['profileData']);
     }
 }

+ 47 - 84
modules/src/nmap/api/module.php

@@ -1,52 +1,15 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
+/* Code modified by Frieren Auto Refactor */
 //putenv('LD_LIBRARY_PATH='.getenv('LD_LIBRARY_PATH').':/sd/lib:/sd/usr/lib');
 //putenv('PATH='.getenv('PATH').':/sd/usr/bin:/sd/usr/sbin');
-
-class nmap extends Module
+class nmap extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'refreshInfo':
-                $this->refreshInfo();
-                break;
-            case 'refreshOutput':
-                $this->refreshOutput();
-                break;
-            case 'refreshStatus':
-                $this->refreshStatus();
-                break;
-            case 'togglenmap':
-                $this->togglenmap();
-                break;
-            case 'scanStatus':
-                $this->scanStatus();
-                break;
-            case 'handleDependencies':
-                $this->handleDependencies();
-                break;
-            case 'handleDependenciesStatus':
-                $this->handleDependenciesStatus();
-                break;
-            case 'refreshHistory':
-                $this->refreshHistory();
-                break;
-            case 'viewHistory':
-                $this->viewHistory();
-                break;
-            case 'deleteHistory':
-                $this->deleteHistory();
-                break;
-            case 'downloadHistory':
-                $this->downloadHistory();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['refreshInfo', 'refreshOutput', 'refreshStatus', 'togglenmap', 'scanStatus', 'handleDependencies', 'handleDependenciesStatus', 'refreshHistory', 'viewHistory', 'deleteHistory', 'downloadHistory'];
 
     protected function checkDep($dependencyName)
     {
-        return ($this->checkDependency($dependencyName) && ($this->uciGet("nmap.module.installed")));
+        return ($this->systemHelper->checkDependency($dependencyName) && ($this->systemHelper->uciGet("nmap.module.installed")));
     }
 
 //    protected function getDevice()
@@ -57,57 +20,57 @@ class nmap extends Module
     protected function refreshInfo()
     {
         $moduleInfo = @json_decode(file_get_contents("/pineapple/modules/nmap/module.info"));
-        $this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
+        $this->responseHandler->setData(array('title' => $moduleInfo->title, 'version' => $moduleInfo->version));
     }
 
-    private function handleDependencies()
+    public function handleDependencies()
     {
         error_log("handleDependencies()");
-        if (!$this->checkDependency("nmap")) {
-            $this->execBackground("/pineapple/modules/nmap/scripts/dependencies.sh install ".$this->request->destination);
-            $this->response = array('success' => true);
+        if (!$this->systemHelper->checkDependency("nmap")) {
+            $this->systemHelper->execBackground("/pineapple/modules/nmap/scripts/dependencies.sh install ".$this->request['destination']);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->execBackground("/pineapple/modules/nmap/scripts/dependencies.sh remove");
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/nmap/scripts/dependencies.sh remove");
+            $this->responseHandler->setData(array('success' => true));
         }
     }
 
-    private function handleDependenciesStatus()
+    public function handleDependenciesStatus()
     {
         if (!file_exists('/tmp/nmap.progress')) {
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function scanStatus()
+    public function scanStatus()
     {
-        if (!$this->checkRunning("nmap")) {
-            $this->response = array('success' => true);
+        if (!$this->systemHelper->checkRunning("nmap")) {
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function togglenmap()
+    public function togglenmap()
     {
-        if (!$this->checkRunning("nmap")) {
+        if (!$this->systemHelper->checkRunning("nmap")) {
             error_log("nmap not running");
-            $full_cmd = $this->request->command . " -oN /tmp/nmap.scan 2>&1";
+            $full_cmd = $this->request['command'] . " -oN /tmp/nmap.scan 2>&1";
             shell_exec("echo -e \"{$full_cmd}\" > /tmp/nmap.run");
 
             error_log("calling run script");
-            $this->execBackground("/pineapple/modules/nmap/scripts/nmap.sh start");
+            $this->systemHelper->execBackground("/pineapple/modules/nmap/scripts/nmap.sh start");
         } else {
-            $this->execBackground("/pineapple/modules/nmap/scripts/nmap.sh stop");
+            $this->systemHelper->execBackground("/pineapple/modules/nmap/scripts/nmap.sh stop");
         }
     }
 
-    private function refreshStatus()
+    public function refreshStatus()
     {
         if (!file_exists('/tmp/nmap.progress')) {
-            if (!$this->checkDependency("nmap")) {
+            if (!$this->systemHelper->checkDependency("nmap")) {
                 $installed = false;
                 $install = "Not installed";
                 $installLabel = "danger";
@@ -121,7 +84,7 @@ class nmap extends Module
                 $installLabel = "success";
                 $processing = false;
 
-                if ($this->checkRunning("nmap")) {
+                if ($this->systemHelper->checkRunning("nmap")) {
                     $status = "Stop";
                     $statusLabel = "danger";
                 } else {
@@ -139,34 +102,34 @@ class nmap extends Module
             $statusLabel = "success";
         }
 
-        $device = $this->getDevice();
-        $sdAvailable = $this->isSDAvailable();
+        $device = $this->systemHelper->getDevice();
+        $sdAvailable = $this->systemHelper->isSDAvailable();
 
         // 2143000 is the installed size of nmap.
         $internalAvailable = (disk_free_space("/") - 64000) > 2143000;
 
-        $this->response = array("device" => $device, "internalAvailable" => $internalAvailable, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "processing" => $processing);
+        $this->responseHandler->setData(array("device" => $device, "internalAvailable" => $internalAvailable, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "processing" => $processing));
     }
 
-    private function refreshOutput()
+    public function refreshOutput()
     {
-        if ($this->checkDependency("nmap")) {
-            if ($this->checkRunning("nmap") && file_exists("/tmp/nmap.scan")) {
+        if ($this->systemHelper->checkDependency("nmap")) {
+            if ($this->systemHelper->checkRunning("nmap") && file_exists("/tmp/nmap.scan")) {
                 $output = file_get_contents("/tmp/nmap.scan");
                 if (!empty($output)) {
-                    $this->response = $output;
+                    $this->responseHandler->setData($output);
                 } else {
-                    $this->response = "Empty log...";
+                    $this->responseHandler->setData("Empty log...");
                 }
             } else {
-                $this->response = "nmap is not running...";
+                $this->responseHandler->setData("nmap is not running...");
             }
         } else {
-            $this->response = "nmap is not installed...";
+            $this->responseHandler->setData("nmap is not installed...");
         }
     }
 
-    private function refreshHistory()
+    public function refreshHistory()
     {
         $this->streamFunction = function () {
             $log_list = array_reverse(glob("/pineapple/modules/nmap/scan/*"));
@@ -187,25 +150,25 @@ class nmap extends Module
         };
     }
 
-    private function viewHistory()
+    public function viewHistory()
     {
-        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/nmap/scan/".$this->request->file));
-        exec("cat /pineapple/modules/nmap/scan/".$this->request->file, $output);
+        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/nmap/scan/".$this->request['file']));
+        exec("cat /pineapple/modules/nmap/scan/".$this->request['file'], $output);
 
         if (!empty($output)) {
-            $this->response = array("output" => implode("\n", $output), "date" => $log_date);
+            $this->responseHandler->setData(array("output" => implode("\n", $output), "date" => $log_date));
         } else {
-            $this->response = array("output" => "Empty scan...", "date" => $log_date);
+            $this->responseHandler->setData(array("output" => "Empty scan...", "date" => $log_date));
         }
     }
 
-    private function deleteHistory()
+    public function deleteHistory()
     {
-        exec("rm -rf /pineapple/modules/nmap/scan/".$this->request->file);
+        exec("rm -rf /pineapple/modules/nmap/scan/".$this->request['file']);
     }
 
-    private function downloadHistory()
+    public function downloadHistory()
     {
-        $this->response = array("download" => $this->downloadFile("/pineapple/modules/nmap/scan/".$this->request->file));
+        $this->responseHandler->setData(array("download" => $this->systemHelper->downloadFile("/pineapple/modules/nmap/scan/".$this->request['file'])));
     }
 }

+ 49 - 91
modules/src/p0f/api/module.php

@@ -1,55 +1,13 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class p0f extends Module
+/* Code modified by Frieren Auto Refactor */
+class p0f extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'refreshInfo':
-                $this->refreshInfo();
-                break;
-            case 'refreshOutput':
-                $this->refreshOutput();
-                break;
-            case 'refreshStatus':
-                $this->refreshStatus();
-                break;
-            case 'togglep0f':
-                $this->togglep0f();
-                break;
-            case 'handleDependencies':
-                $this->handleDependencies();
-                break;
-            case 'handleDependenciesStatus':
-                $this->handleDependenciesStatus();
-                break;
-            case 'refreshHistory':
-                $this->refreshHistory();
-                break;
-            case 'viewHistory':
-                $this->viewHistory();
-                break;
-            case 'deleteHistory':
-                $this->deleteHistory();
-                break;
-            case 'downloadHistory':
-                $this->downloadHistory();
-                break;
-            case 'togglep0fOnBoot':
-                $this->togglep0fOnBoot();
-                break;
-            case 'getInterfaces':
-                $this->getInterfaces();
-                break;
-            case 'saveAutostartSettings':
-                $this->saveAutostartSettings();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['refreshInfo', 'refreshOutput', 'refreshStatus', 'togglep0f', 'handleDependencies', 'handleDependenciesStatus', 'refreshHistory', 'viewHistory', 'deleteHistory', 'downloadHistory', 'togglep0fOnBoot', 'getInterfaces', 'saveAutostartSettings'];
 
     protected function checkDeps($dependencyName)
     {
-        return ($this->checkDependency($dependencyName) && ($this->uciGet("p0f.module.installed")));
+        return ($this->systemHelper->checkDependency($dependencyName) && ($this->systemHelper->uciGet("p0f.module.installed")));
     }
 
     protected function getDevice()
@@ -60,30 +18,30 @@ class p0f extends Module
     protected function refreshInfo()
     {
         $moduleInfo = @json_decode(file_get_contents("/pineapple/modules/p0f/module.info"));
-        $this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
+        $this->responseHandler->setData(array('title' => $moduleInfo->title, 'version' => $moduleInfo->version));
     }
 
-    private function handleDependencies()
+    public function handleDependencies()
     {
         if (!$this->checkDeps("p0f")) {
-            $this->execBackground("/pineapple/modules/p0f/scripts/dependencies.sh install ".$this->request->destination);
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/p0f/scripts/dependencies.sh install ".$this->request['destination']);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->execBackground("/pineapple/modules/p0f/scripts/dependencies.sh remove");
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/p0f/scripts/dependencies.sh remove");
+            $this->responseHandler->setData(array('success' => true));
         }
     }
 
-    private function handleDependenciesStatus()
+    public function handleDependenciesStatus()
     {
         if (!file_exists('/tmp/p0f.progress')) {
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function togglep0fOnBoot()
+    public function togglep0fOnBoot()
     {
         if (exec("cat /etc/rc.local | grep p0f/scripts/autostart_p0f.sh") == "") {
             exec("sed -i '/exit 0/d' /etc/rc.local");
@@ -94,27 +52,27 @@ class p0f extends Module
         }
     }
 
-    private function togglep0f()
+    public function togglep0f()
     {
-        if (!$this->checkRunning("p0f")) {
-            $this->uciSet("p0f.run.interface", $this->request->interface);
+        if (!$this->systemHelper->checkRunning("p0f")) {
+            $this->systemHelper->uciSet("p0f.run.interface", $this->request['interface']);
 
-            $this->execBackground("/pineapple/modules/p0f/scripts/p0f.sh start");
+            $this->systemHelper->execBackground("/pineapple/modules/p0f/scripts/p0f.sh start");
         } else {
-            $this->uciSet("p0f.run.interface", '');
+            $this->systemHelper->uciSet("p0f.run.interface", '');
 
-            $this->execBackground("/pineapple/modules/p0f/scripts/p0f.sh stop");
+            $this->systemHelper->execBackground("/pineapple/modules/p0f/scripts/p0f.sh stop");
         }
     }
 
-    private function getInterfaces()
+    public function getInterfaces()
     {
         exec("cat /proc/net/dev | tail -n +3 | cut -f1 -d: | sed 's/ //g'", $interfaceArray);
 
-        $this->response = array("interfaces" => $interfaceArray, "selected" => $this->uciGet("p0f.run.interface"));
+        $this->responseHandler->setData(array("interfaces" => $interfaceArray, "selected" => $this->systemHelper->uciGet("p0f.run.interface")));
     }
 
-    private function refreshStatus()
+    public function refreshStatus()
     {
         if (!file_exists('/tmp/p0f.progress')) {
             if (!$this->checkDeps("p0f")) {
@@ -134,7 +92,7 @@ class p0f extends Module
                 $installLabel = "success";
                 $processing = false;
 
-                if ($this->checkRunning("p0f")) {
+                if ($this->systemHelper->checkRunning("p0f")) {
                     $status = "Stop";
                     $statusLabel = "danger";
                 } else {
@@ -164,16 +122,16 @@ class p0f extends Module
             $bootLabelOFF = "danger";
         }
 
-        $device = $this->getDevice();
-        $sdAvailable = $this->isSDAvailable();
+        $device = $this->systemHelper->getDevice();
+        $sdAvailable = $this->systemHelper->isSDAvailable();
 
-        $this->response = array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "bootLabelON" => $bootLabelON, "bootLabelOFF" => $bootLabelOFF, "processing" => $processing);
+        $this->responseHandler->setData(array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "bootLabelON" => $bootLabelON, "bootLabelOFF" => $bootLabelOFF, "processing" => $processing));
     }
 
-    private function refreshOutput()
+    public function refreshOutput()
     {
         if ($this->checkDeps("p0f")) {
-            if ($this->checkRunning("p0f")) {
+            if ($this->systemHelper->checkRunning("p0f")) {
                 $path = "/pineapple/modules/p0f/log";
 
                 $latest_ctime = 0;
@@ -191,8 +149,8 @@ class p0f extends Module
                 if ($latest_filename != "") {
                     $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/p0f/log/".$latest_filename));
 
-                    if ($this->request->filter != "") {
-                        $filter = $this->request->filter;
+                    if ($this->request['filter'] != "") {
+                        $filter = $this->request['filter'];
 
                         $cmd = "cat /pineapple/modules/p0f/log/".$latest_filename." | ".$filter;
                     } else {
@@ -201,20 +159,20 @@ class p0f extends Module
 
                     exec($cmd, $output);
                     if (!empty($output)) {
-                        $this->response = implode("\n", array_reverse($output));
+                        $this->responseHandler->setData(implode("\n", array_reverse($output)));
                     } else {
-                        $this->response = "Empty log...";
+                        $this->responseHandler->setData("Empty log...");
                     }
                 }
             } else {
-                $this->response = "p0f is not running...";
+                $this->responseHandler->setData("p0f is not running...");
             }
         } else {
-            $this->response = "p0f is not installed...";
+            $this->responseHandler->setData("p0f is not installed...");
         }
     }
 
-    private function refreshHistory()
+    public function refreshHistory()
     {
         $this->streamFunction = function () {
             $log_list = array_reverse(glob("/pineapple/modules/p0f/log/*"));
@@ -235,31 +193,31 @@ class p0f extends Module
         };
     }
 
-    private function viewHistory()
+    public function viewHistory()
     {
-        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/p0f/log/".$this->request->file));
-        exec("cat /pineapple/modules/p0f/log/".$this->request->file, $output);
+        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/p0f/log/".$this->request['file']));
+        exec("cat /pineapple/modules/p0f/log/".$this->request['file'], $output);
 
         if (!empty($output)) {
-            $this->response = array("output" => implode("\n", $output), "date" => $log_date);
+            $this->responseHandler->setData(array("output" => implode("\n", $output), "date" => $log_date));
         } else {
-            $this->response = array("output" => "Empty log...", "date" => $log_date);
+            $this->responseHandler->setData(array("output" => "Empty log...", "date" => $log_date));
         }
     }
 
-    private function deleteHistory()
+    public function deleteHistory()
     {
-        exec("rm -rf /pineapple/modules/p0f/log/".$this->request->file);
+        exec("rm -rf /pineapple/modules/p0f/log/".$this->request['file']);
     }
 
-    private function downloadHistory()
+    public function downloadHistory()
     {
-        $this->response = array("download" => $this->downloadFile("/pineapple/modules/p0f/log/".$this->request->file));
+        $this->responseHandler->setData(array("download" => $this->systemHelper->downloadFile("/pineapple/modules/p0f/log/".$this->request['file'])));
     }
 
-    private function saveAutostartSettings()
+    public function saveAutostartSettings()
     {
-        $settings = $this->request->settings;
-        $this->uciSet("p0f.autostart.interface", $settings->interface);
+        $settings = $this->request['settings'];
+        $this->systemHelper->uciSet("p0f.autostart.interface", $settings->interface);
     }
 }

+ 42 - 83
modules/src/tcpdump/api/module.php

@@ -1,54 +1,13 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-
-
-class tcpdump extends Module
+/* Code modified by Frieren Auto Refactor */
+class tcpdump extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'refreshInfo':
-                $this->refreshInfo();
-                break;
-            case 'refreshOutput':
-                $this->refreshOutput();
-                break;
-            case 'clearOutput':
-                $this->clearOutput();
-                break;
-            case 'refreshStatus':
-                $this->refreshStatus();
-                break;
-            case 'toggletcpdump':
-                $this->toggletcpdump();
-                break;
-            case 'handleDependencies':
-                $this->handleDependencies();
-                break;
-            case 'handleDependenciesStatus':
-                $this->handleDependenciesStatus();
-                break;
-            case 'refreshHistory':
-                $this->refreshHistory();
-                break;
-            case 'viewHistory':
-                $this->viewHistory();
-                break;
-            case 'deleteHistory':
-                $this->deleteHistory();
-                break;
-            case 'downloadHistory':
-                $this->downloadHistory();
-                break;
-            case 'getInterfaces':
-                $this->getInterfaces();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['refreshInfo', 'refreshOutput', 'clearOutput', 'refreshStatus', 'toggletcpdump', 'handleDependencies', 'handleDependenciesStatus', 'refreshHistory', 'viewHistory', 'deleteHistory', 'downloadHistory', 'getInterfaces'];
 
     protected function checkDeps($dependencyName)
     {
-        return ($this->checkDependency($dependencyName) && ($this->uciGet("tcpdump.module.installed")));
+        return ($this->systemHelper->checkDependency($dependencyName) && ($this->systemHelper->uciGet("tcpdump.module.installed")));
     }
 
     protected function getDevice()
@@ -59,42 +18,42 @@ class tcpdump extends Module
     protected function refreshInfo()
     {
         $moduleInfo = @json_decode(file_get_contents("/pineapple/modules/tcpdump/module.info"));
-        $this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
+        $this->responseHandler->setData(array('title' => $moduleInfo->title, 'version' => $moduleInfo->version));
     }
 
-    private function handleDependencies()
+    public function handleDependencies()
     {
         if (!$this->checkDeps("tcpdump")) {
-            $this->execBackground("/pineapple/modules/tcpdump/scripts/dependencies.sh install ".$this->request->destination);
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/tcpdump/scripts/dependencies.sh install ".$this->request['destination']);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->execBackground("/pineapple/modules/tcpdump/scripts/dependencies.sh remove");
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/tcpdump/scripts/dependencies.sh remove");
+            $this->responseHandler->setData(array('success' => true));
         }
     }
 
-    private function handleDependenciesStatus()
+    public function handleDependenciesStatus()
     {
         if (!file_exists('/tmp/tcpdump.progress')) {
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function toggletcpdump()
+    public function toggletcpdump()
     {
-        if (!$this->checkRunning("tcpdump")) {
-            $full_cmd = $this->request->command . " -w /pineapple/modules/tcpdump/dump/dump_".time().".pcap 2> /tmp/tcpdump_capture.log";
+        if (!$this->systemHelper->checkRunning("tcpdump")) {
+            $full_cmd = $this->request['command'] . " -w /pineapple/modules/tcpdump/dump/dump_".time().".pcap 2> /tmp/tcpdump_capture.log";
             shell_exec("echo -e \"{$full_cmd}\" > /tmp/tcpdump.run");
 
-            $this->execBackground("/pineapple/modules/tcpdump/scripts/tcpdump.sh start");
+            $this->systemHelper->execBackground("/pineapple/modules/tcpdump/scripts/tcpdump.sh start");
         } else {
-            $this->execBackground("/pineapple/modules/tcpdump/scripts/tcpdump.sh stop");
+            $this->systemHelper->execBackground("/pineapple/modules/tcpdump/scripts/tcpdump.sh stop");
         }
     }
 
-    private function refreshStatus()
+    public function refreshStatus()
     {
         if (!file_exists('/tmp/tcpdump.progress')) {
             if (!$this->checkDeps("tcpdump")) {
@@ -111,7 +70,7 @@ class tcpdump extends Module
                 $installLabel = "success";
                 $processing = false;
 
-                if ($this->checkRunning("tcpdump")) {
+                if ($this->systemHelper->checkRunning("tcpdump")) {
                     $status = "Stop";
                     $statusLabel = "danger";
                 } else {
@@ -129,38 +88,38 @@ class tcpdump extends Module
             $statusLabel = "success";
         }
 
-        $device = $this->getDevice();
-        $sdAvailable = $this->isSDAvailable();
+        $device = $this->systemHelper->getDevice();
+        $sdAvailable = $this->systemHelper->isSDAvailable();
 
-        $this->response = array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "processing" => $processing);
+        $this->responseHandler->setData(array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "processing" => $processing));
     }
 
-    private function refreshOutput()
+    public function refreshOutput()
     {
         if ($this->checkDeps("tcpdump")) {
             if (file_exists("/tmp/tcpdump_capture.log")) {
                 $output = file_get_contents("/tmp/tcpdump_capture.log");
                 if (!empty($output)) {
-                    $this->response = $output;
+                    $this->responseHandler->setData($output);
                 } else {
-                    $this->response = "tcpdump is running...";
+                    $this->responseHandler->setData("tcpdump is running...");
                 }
             } else {
-                $this->response = "tcpdump is not running...";
+                $this->responseHandler->setData("tcpdump is not running...");
             }
         } else {
-            $this->response = "tcpdump is not installed...";
+            $this->responseHandler->setData("tcpdump is not installed...");
         }
     }
 
-    private function clearOutput()
+    public function clearOutput()
     {
         exec("rm -rf /tmp/tcpdump_capture.log");
     }
 
-    private function getInterfaces()
+    public function getInterfaces()
     {
-        $this->response = array();
+        $this->responseHandler->setData(array());
         exec("cat /proc/net/dev | tail -n +3 | cut -f1 -d: | sed 's/ //g'", $interfaceArray);
 
         foreach ($interfaceArray as $interface) {
@@ -168,7 +127,7 @@ class tcpdump extends Module
         }
     }
 
-    private function refreshHistory()
+    public function refreshHistory()
     {
         $this->streamFunction = function () {
             $log_list = array_reverse(glob("/pineapple/modules/tcpdump/dump/*.pcap"));
@@ -189,25 +148,25 @@ class tcpdump extends Module
         };
     }
 
-    private function downloadHistory()
+    public function downloadHistory()
     {
-        $this->response = array("download" => $this->downloadFile("/pineapple/modules/tcpdump/dump/".$this->request->file));
+        $this->responseHandler->setData(array("download" => $this->systemHelper->downloadFile("/pineapple/modules/tcpdump/dump/".$this->request['file'])));
     }
 
-    private function viewHistory()
+    public function viewHistory()
     {
-        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/tcpdump/dump/".$this->request->file));
-        exec("strings /pineapple/modules/tcpdump/dump/".$this->request->file, $output);
+        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/tcpdump/dump/".$this->request['file']));
+        exec("strings /pineapple/modules/tcpdump/dump/".$this->request['file'], $output);
 
         if (!empty($output)) {
-            $this->response = array("output" => implode("\n", $output), "date" => $log_date);
+            $this->responseHandler->setData(array("output" => implode("\n", $output), "date" => $log_date));
         } else {
-            $this->response = array("output" => "Empty dump...", "date" => $log_date);
+            $this->responseHandler->setData(array("output" => "Empty dump...", "date" => $log_date));
         }
     }
 
-    private function deleteHistory()
+    public function deleteHistory()
     {
-        exec("rm -rf /pineapple/modules/tcpdump/dump/".$this->request->file);
+        exec("rm -rf /pineapple/modules/tcpdump/dump/".$this->request['file']);
     }
 }

+ 44 - 80
modules/src/tor/api/module.php

@@ -1,7 +1,9 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-class Tor extends Module
+/* Code modified by Frieren Auto Refactor */
+class Tor extends Controller
 {
+    protected $endpointRoutes = ['refreshInfo', 'refreshStatus', 'handleDependencies', 'handleDependenciesStatus', 'toggletor', 'refreshHiddenServices', 'addHiddenService', 'removeHiddenService', 'addServiceForward', 'removeServiceForward'];
     private $progressFile = '/tmp/tor.progress';
     private $moduleConfigFile = '/etc/config/tor/config';
     private $dependenciesScriptFile = '/pineapple/modules/tor/scripts/dependencies.sh';
@@ -16,65 +18,27 @@ class Tor extends Module
     const WARNING = 'warning';
     const SUCCESS = 'success';
 
-    public function route()
+    public function success($value)
     {
-        switch ($this->request->action) {
-            case 'refreshInfo':
-                $this->refreshInfo();
-                break;
-            case 'refreshStatus':
-                $this->refreshStatus();
-                break;
-            case 'handleDependencies':
-                $this->handleDependencies();
-                break;
-            case 'handleDependenciesStatus':
-                $this->handleDependenciesStatus();
-                break;
-            case 'toggletor':
-                $this->toggletor();
-                break;
-            case 'refreshHiddenServices':
-                $this->refreshHiddenServices();
-                break;
-            case 'addHiddenService':
-                $this->addHiddenService();
-                break;
-            case 'removeHiddenService':
-                $this->removeHiddenService();
-                break;
-            case 'addServiceForward':
-                $this->addServiceForward();
-                break;
-            case 'removeServiceForward':
-                $this->removeServiceForward();
-                break;
-            default:
-                break;
-        }
-    }
-
-    private function success($value)
-    {
-        $this->response = array('success' => $value);
+        $this->responseHandler->setData(array('success' => $value));
     }
 
-    private function error($message)
+    public function error($message)
     {
-        $this->response = array('error' => $message);
+        $this->responseHandler->setData(array('error' => $message));
     }
 
-    private function isValidName($name)
+    public function isValidName($name)
     {
         return preg_match('/^[a-zA-Z0-9_]+$/', $name) === 1;
     }
 
-    private function isValidPort($port)
+    public function isValidPort($port)
     {
         return preg_match('/^[0-9]+$/', $port) === 1;
     }
 
-    private function isValidRedirectTo($redirect_to)
+    public function isValidRedirectTo($redirect_to)
     {
         return preg_match('/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+$/', $redirect_to) === 1;
     }
@@ -87,7 +51,7 @@ class Tor extends Module
     protected function refreshInfo()
     {
         $moduleInfo = @json_decode(file_get_contents("/pineapple/modules/tor/module.info"));
-        $this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
+        $this->responseHandler->setData(array('title' => $moduleInfo->title, 'version' => $moduleInfo->version));
     }
 
     protected function checkRunning($processName)
@@ -95,26 +59,26 @@ class Tor extends Module
         return (exec("pgrep '{$processName}$'") != '');
     }
 
-    private function handleDependencies()
+    public function handleDependencies()
     {
         $destination = "";
-        if (isset($this->request->destination)) {
-            $destination = $this->request->destination;
+        if (isset($this->request['destination'])) {
+            $destination = $this->request['destination'];
             if ($destination != "internal" && $destination != "sd") {
                 $this->error(self::INVALID_DESTINATION);
                 return;
             }
         }
 
-        if (!$this->checkDependency("tor")) {
-            $this->execBackground($this->dependenciesScriptFile . " install " . $destination);
+        if (!$this->systemHelper->checkDependency("tor")) {
+            $this->systemHelper->execBackground($this->dependenciesScriptFile . " install " . $destination);
         } else {
-            $this->execBackground($this->dependenciesScriptFile . " remove");
+            $this->systemHelper->execBackground($this->dependenciesScriptFile . " remove");
         }
         $this->success(true);
     }
 
-    private function handleDependenciesStatus()
+    public function handleDependenciesStatus()
     {
         if (file_exists($this->progressFile)) {
             $this->success(false);
@@ -123,20 +87,20 @@ class Tor extends Module
         }
     }
 
-    private function toggletor()
+    public function toggletor()
     {
-        if ($this->checkRunning("tor")) {
+        if ($this->systemHelper->checkRunning("tor")) {
             exec("/etc/init.d/tor stop");
         } else {
             exec("/etc/init.d/tor start");
         }
     }
 
-    private function refreshStatus()
+    public function refreshStatus()
     {
 
-        $device = $this->getDevice();
-        $sdAvailable = $this->isSDAvailable();
+        $device = $this->systemHelper->getDevice();
+        $sdAvailable = $this->systemHelper->isSDAvailable();
         $installed = false;
         $install = "Not Installed";
         $processing = false;
@@ -149,7 +113,7 @@ class Tor extends Module
 
             $status = "Not running";
             $statusLabel = self::DANGER;
-        } elseif (!$this->checkDependency("tor")) {
+        } elseif (!$this->systemHelper->checkDependency("tor")) {
             // TOR is not installed, please install.
             $installLabel = self::DANGER;
 
@@ -161,7 +125,7 @@ class Tor extends Module
             $install = "Installed";
             $installLabel = self::SUCCESS;
 
-            if ($this->checkRunning("tor")) {
+            if ($this->systemHelper->checkRunning("tor")) {
                 $status = "Started";
                 $statusLabel = self::SUCCESS;
             } else {
@@ -170,17 +134,17 @@ class Tor extends Module
             }
         }
 
-        $this->response = array("device" => $device,
+        $this->responseHandler->setData(array("device" => $device,
                                 "sdAvailable" => $sdAvailable,
                                 "status" => $status,
                                 "statusLabel" => $statusLabel,
                                 "installed" => $installed,
                                 "install" => $install,
                                 "installLabel" => $installLabel,
-                                "processing" => $processing);
+                                "processing" => $processing));
     }
 
-    private function generateConfig()
+    public function generateConfig()
     {
         $output = file_get_contents("/etc/config/tor/torrc");
         $output .= "\n";
@@ -195,14 +159,14 @@ class Tor extends Module
         file_put_contents("/etc/tor/torrc", $output);
     }
 
-    private function reloadTor()
+    public function reloadTor()
     {
         $this->generateConfig();
         //Sending SIGHUP to tor process cause config reload.
         exec("pkill -sighup tor$");
     }
 
-    private function refreshHiddenServices()
+    public function refreshHiddenServices()
     {
         $hiddenServices = @json_decode(file_get_contents($this->moduleConfigFile));
         foreach ($hiddenServices as $hiddenService) {
@@ -211,12 +175,12 @@ class Tor extends Module
                 $hiddenService->hostname = trim($hostname);
             }
         }
-        $this->response = array("hiddenServices" => $hiddenServices);
+        $this->responseHandler->setData(array("hiddenServices" => $hiddenServices));
     }
 
-    private function addHiddenService()
+    public function addHiddenService()
     {
-        $name = $this->request->name;
+        $name = $this->request['name'];
         if (!$this->isValidName($name)) {
             $this->error(self::INVALID_NAME);
             return;
@@ -232,11 +196,11 @@ class Tor extends Module
         $this->reloadTor();
     }
 
-    private function removeHiddenService()
+    public function removeHiddenService()
     {
         $hiddenServices = @json_decode(file_get_contents($this->moduleConfigFile));
         foreach ($hiddenServices as $key => $hiddenService) {
-            if ($hiddenService->name == $this->request->name) {
+            if ($hiddenService->name == $this->request['name']) {
                 unset($hiddenServices[$key]);
             }
         }
@@ -244,11 +208,11 @@ class Tor extends Module
         $this->reloadTor();
     }
 
-    private function addServiceForward()
+    public function addServiceForward()
     {
-        $name = $this->request->name;
-        $port = $this->request->port;
-        $redirect_to = $this->request->redirect_to;
+        $name = $this->request['name'];
+        $port = $this->request['port'];
+        $redirect_to = $this->request['redirect_to'];
 
         if (!$this->isValidName($name)) {
             $this->error(self::INVALID_NAME);
@@ -277,11 +241,11 @@ class Tor extends Module
         $this->reloadTor();
     }
 
-    private function removeServiceForward()
+    public function removeServiceForward()
     {
-        $name = $this->request->name;
-        $port = $this->request->port;
-        $redirect_to = $this->request->redirect_to;
+        $name = $this->request['name'];
+        $port = $this->request['port'];
+        $redirect_to = $this->request['redirect_to'];
 
         $hiddenServices = @json_decode(file_get_contents($this->moduleConfigFile));
         foreach ($hiddenServices as $hiddenService) {

+ 49 - 93
modules/src/urlsnarf/api/module.php

@@ -1,57 +1,13 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
-
-
-class urlsnarf extends Module
+/* Code modified by Frieren Auto Refactor */
+class urlsnarf extends Controller
 {
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'refreshInfo':
-                $this->refreshInfo();
-                break;
-            case 'refreshOutput':
-                $this->refreshOutput();
-                break;
-            case 'refreshStatus':
-                $this->refreshStatus();
-                break;
-            case 'toggleurlsnarf':
-                $this->toggleurlsnarf();
-                break;
-            case 'handleDependencies':
-                $this->handleDependencies();
-                break;
-            case 'handleDependenciesStatus':
-                $this->handleDependenciesStatus();
-                break;
-            case 'refreshHistory':
-                $this->refreshHistory();
-                break;
-            case 'viewHistory':
-                $this->viewHistory();
-                break;
-            case 'deleteHistory':
-                $this->deleteHistory();
-                break;
-            case 'downloadHistory':
-                $this->downloadHistory();
-                break;
-            case 'toggleurlsnarfOnBoot':
-                $this->toggleurlsnarfOnBoot();
-                break;
-            case 'getInterfaces':
-                $this->getInterfaces();
-                break;
-            case 'saveAutostartSettings':
-                $this->saveAutostartSettings();
-                break;
-        }
-    }
+    protected $endpointRoutes = ['refreshInfo', 'refreshOutput', 'refreshStatus', 'toggleurlsnarf', 'handleDependencies', 'handleDependenciesStatus', 'refreshHistory', 'viewHistory', 'deleteHistory', 'downloadHistory', 'toggleurlsnarfOnBoot', 'getInterfaces', 'saveAutostartSettings'];
 
     protected function checkDep($dependencyName)
     {
-        return ($this->checkDependency($dependencyName) && ($this->uciGet("urlsnarf.module.installed")));
+        return ($this->systemHelper->checkDependency($dependencyName) && ($this->systemHelper->uciGet("urlsnarf.module.installed")));
     }
 
     protected function getDevice()
@@ -62,30 +18,30 @@ class urlsnarf extends Module
     protected function refreshInfo()
     {
         $moduleInfo = @json_decode(file_get_contents("/pineapple/modules/urlsnarf/module.info"));
-        $this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
+        $this->responseHandler->setData(array('title' => $moduleInfo->title, 'version' => $moduleInfo->version));
     }
 
-    private function handleDependencies()
+    public function handleDependencies()
     {
         if (!$this->checkDep("urlsnarf")) {
-            $this->execBackground("/pineapple/modules/urlsnarf/scripts/dependencies.sh install ".$this->request->destination);
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/urlsnarf/scripts/dependencies.sh install ".$this->request['destination']);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->execBackground("/pineapple/modules/urlsnarf/scripts/dependencies.sh remove");
-            $this->response = array('success' => true);
+            $this->systemHelper->execBackground("/pineapple/modules/urlsnarf/scripts/dependencies.sh remove");
+            $this->responseHandler->setData(array('success' => true));
         }
     }
 
-    private function handleDependenciesStatus()
+    public function handleDependenciesStatus()
     {
         if (!file_exists('/tmp/urlsnarf.progress')) {
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function toggleurlsnarfOnBoot()
+    public function toggleurlsnarfOnBoot()
     {
         if (exec("cat /etc/rc.local | grep urlsnarf/scripts/autostart_urlsnarf.sh") == "") {
             exec("sed -i '/exit 0/d' /etc/rc.local");
@@ -96,27 +52,27 @@ class urlsnarf extends Module
         }
     }
 
-    private function toggleurlsnarf()
+    public function toggleurlsnarf()
     {
-        if (!$this->checkRunning("urlsnarf")) {
-            $this->uciSet("urlsnarf.run.interface", $this->request->interface);
+        if (!$this->systemHelper->checkRunning("urlsnarf")) {
+            $this->systemHelper->uciSet("urlsnarf.run.interface", $this->request['interface']);
 
-            $this->execBackground("/pineapple/modules/urlsnarf/scripts/urlsnarf.sh start");
+            $this->systemHelper->execBackground("/pineapple/modules/urlsnarf/scripts/urlsnarf.sh start");
         } else {
-            $this->uciSet("urlsnarf.run.interface", '');
+            $this->systemHelper->uciSet("urlsnarf.run.interface", '');
 
-            $this->execBackground("/pineapple/modules/urlsnarf/scripts/urlsnarf.sh stop");
+            $this->systemHelper->execBackground("/pineapple/modules/urlsnarf/scripts/urlsnarf.sh stop");
         }
     }
 
-    private function getInterfaces()
+    public function getInterfaces()
     {
         exec("cat /proc/net/dev | tail -n +3 | cut -f1 -d: | sed 's/ //g'", $interfaceArray);
 
-        $this->response = array("interfaces" => $interfaceArray, "selected" => $this->uciGet("urlsnarf.run.interface"));
+        $this->responseHandler->setData(array("interfaces" => $interfaceArray, "selected" => $this->systemHelper->uciGet("urlsnarf.run.interface")));
     }
 
-    private function refreshStatus()
+    public function refreshStatus()
     {
         if (!file_exists('/tmp/urlsnarf.progress')) {
             if (!$this->checkDep("urlsnarf")) {
@@ -136,7 +92,7 @@ class urlsnarf extends Module
                 $installLabel = "success";
                 $processing = false;
 
-                if ($this->checkRunning("urlsnarf")) {
+                if ($this->systemHelper->checkRunning("urlsnarf")) {
                     $status = "Stop";
                     $statusLabel = "danger";
                 } else {
@@ -165,16 +121,16 @@ class urlsnarf extends Module
             $bootLabelOFF = "danger";
         }
 
-        $device = $this->getDevice();
-        $sdAvailable = $this->isSDAvailable();
+        $device = $this->systemHelper->getDevice();
+        $sdAvailable = $this->systemHelper->isSDAvailable();
 
-        $this->response = array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "bootLabelON" => $bootLabelON, "bootLabelOFF" => $bootLabelOFF, "processing" => $processing);
+        $this->responseHandler->setData(array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "bootLabelON" => $bootLabelON, "bootLabelOFF" => $bootLabelOFF, "processing" => $processing));
     }
 
-    private function refreshOutput()
+    public function refreshOutput()
     {
         if ($this->checkDep("urlsnarf")) {
-            if ($this->checkRunning("urlsnarf")) {
+            if ($this->systemHelper->checkRunning("urlsnarf")) {
                 $path = "/pineapple/modules/urlsnarf/log";
 
                 $latest_ctime = 0;
@@ -192,8 +148,8 @@ class urlsnarf extends Module
                 if ($latest_filename != "") {
                     $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/urlsnarf/log/".$latest_filename));
 
-                    if ($this->request->filter != "") {
-                        $filter = $this->request->filter;
+                    if ($this->request['filter'] != "") {
+                        $filter = $this->request['filter'];
 
                         $cmd = "cat /pineapple/modules/urlsnarf/log/".$latest_filename." | ".$filter;
                     } else {
@@ -202,20 +158,20 @@ class urlsnarf extends Module
 
                     exec($cmd, $output);
                     if (!empty($output)) {
-                        $this->response = implode("\n", array_reverse($output));
+                        $this->responseHandler->setData(implode("\n", array_reverse($output)));
                     } else {
-                        $this->response = "Empty log...";
+                        $this->responseHandler->setData("Empty log...");
                     }
                 }
             } else {
-                $this->response = "urlsnarf is not running...";
+                $this->responseHandler->setData("urlsnarf is not running...");
             }
         } else {
-            $this->response = "urlsnarf is not installed...";
+            $this->responseHandler->setData("urlsnarf is not installed...");
         }
     }
 
-    private function refreshHistory()
+    public function refreshHistory()
     {
         $this->streamFunction = function () {
             $log_list = array_reverse(glob("/pineapple/modules/urlsnarf/log/*"));
@@ -236,31 +192,31 @@ class urlsnarf extends Module
         };
     }
 
-    private function viewHistory()
+    public function viewHistory()
     {
-        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/urlsnarf/log/".$this->request->file));
-        exec("cat /pineapple/modules/urlsnarf/log/".$this->request->file, $output);
+        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/urlsnarf/log/".$this->request['file']));
+        exec("cat /pineapple/modules/urlsnarf/log/".$this->request['file'], $output);
 
         if (!empty($output)) {
-            $this->response = array("output" => implode("\n", $output), "date" => $log_date);
+            $this->responseHandler->setData(array("output" => implode("\n", $output), "date" => $log_date));
         } else {
-            $this->response = array("output" => "Empty log...", "date" => $log_date);
+            $this->responseHandler->setData(array("output" => "Empty log...", "date" => $log_date));
         }
     }
 
-    private function deleteHistory()
+    public function deleteHistory()
     {
-        exec("rm -rf /pineapple/modules/urlsnarf/log/".$this->request->file);
+        exec("rm -rf /pineapple/modules/urlsnarf/log/".$this->request['file']);
     }
 
-    private function downloadHistory()
+    public function downloadHistory()
     {
-        $this->response = array("download" => $this->downloadFile("/pineapple/modules/urlsnarf/log/".$this->request->file));
+        $this->responseHandler->setData(array("download" => $this->systemHelper->downloadFile("/pineapple/modules/urlsnarf/log/".$this->request['file'])));
     }
 
-    private function saveAutostartSettings()
+    public function saveAutostartSettings()
     {
-        $settings = $this->request->settings;
-        $this->uciSet("urlsnarf.autostart.interface", $settings->interface);
+        $settings = $this->request['settings'];
+        $this->systemHelper->uciSet("urlsnarf.autostart.interface", $settings->interface);
     }
 }

+ 2 - 1
modules/src/wps/api/iwlist_parser.php

@@ -1,5 +1,6 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
+/* Code modified by Frieren Auto Refactor */
 class iwlist_parser
 {
     public function iwlist_parser()

+ 75 - 129
modules/src/wps/api/module.php

@@ -1,76 +1,22 @@
-<?php namespace pineapple;
+<?php namespace frieren\core;
 
 
+/* Code modified by Frieren Auto Refactor */
+
 require_once('/pineapple/modules/wps/api/iwlist_parser.php');
 
-class wps extends Module
+class wps extends Controller
 {
+    protected $endpointRoutes = ['refreshInfo', 'refreshStatus', 'refreshOutput', 'handleDependencies', 'handleDependenciesStatus', 'getInterfaces', 'getMonitors', 'startMonitor', 'stopMonitor', 'scanForNetworks', 'getMACInfo', 'togglewps', 'getProcesses', 'refreshHistory', 'viewHistory', 'deleteHistory', 'downloadHistory'];
     public function __construct($request)
     {
-        parent::__construct($request, __CLASS__);
         $this->iwlistparse = new iwlist_parser();
-    }
-
-    public function route()
-    {
-        switch ($this->request->action) {
-            case 'refreshInfo':
-                $this->refreshInfo();
-                break;
-            case 'refreshStatus':
-                $this->refreshStatus();
-                break;
-            case 'refreshOutput':
-                $this->refreshOutput();
-                break;
-            case 'handleDependencies':
-                $this->handleDependencies();
-                break;
-            case 'handleDependenciesStatus':
-                $this->handleDependenciesStatus();
-                break;
-            case 'getInterfaces':
-                $this->getInterfaces();
-                break;
-            case 'getMonitors':
-                $this->getMonitors();
-                break;
-            case 'startMonitor':
-                $this->startMonitor();
-                break;
-            case 'stopMonitor':
-                $this->stopMonitor();
-                break;
-            case 'scanForNetworks':
-                $this->scanForNetworks();
-                break;
-            case 'getMACInfo':
-                $this->getMACInfo();
-                break;
-            case 'togglewps':
-                $this->togglewps();
-                break;
-            case 'getProcesses':
-                $this->getProcesses();
-                break;
-            case 'refreshHistory':
-                $this->refreshHistory();
-                break;
-            case 'viewHistory':
-                $this->viewHistory();
-                break;
-            case 'deleteHistory':
-                $this->deleteHistory();
-                break;
-            case 'downloadHistory':
-                $this->downloadHistory();
-                break;
-        }
+        parent::__construct($request);
     }
 
     protected function checkDeps($dependencyName)
     {
-        return ($this->checkDependency($dependencyName) && ($this->uciGet("wps.module.installed")));
+        return ($this->systemHelper->checkDependency($dependencyName) && ($this->systemHelper->uciGet("wps.module.installed")));
     }
 
     protected function getDevice()
@@ -86,40 +32,40 @@ class wps extends Module
     protected function refreshInfo()
     {
         $moduleInfo = @json_decode(file_get_contents("/pineapple/modules/wps/module.info"));
-        $this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
+        $this->responseHandler->setData(array('title' => $moduleInfo->title, 'version' => $moduleInfo->version));
     }
 
-    private function handleDependencies()
+    public function handleDependencies()
     {
         if (!$this->checkDeps("reaver")) {
             if (file_exists('/sd/modules/wps/scripts/dependencies.sh')) {
-                $this->execBackground("bash /sd/modules/wps/scripts/dependencies.sh install ".$this->request->destination);
-                $this->response = array('success' => true);
+                $this->systemHelper->execBackground("bash /sd/modules/wps/scripts/dependencies.sh install ".$this->request['destination']);
+                $this->responseHandler->setData(array('success' => true));
             } else {
-                $this->execBackground("bash /pineapple/modules/wps/scripts/dependencies.sh install ".$this->request->destination);
-                $this->response = array('success' => true);
+                $this->systemHelper->execBackground("bash /pineapple/modules/wps/scripts/dependencies.sh install ".$this->request['destination']);
+                $this->responseHandler->setData(array('success' => true));
             }
         } else {
             if (file_exists('/sd/modules/wps/scripts/dependencies.sh')) {
-                $this->execBackground("bash /sd/modules/wps/scripts/dependencies.sh remove");
-                $this->response = array('success' => true);
+                $this->systemHelper->execBackground("bash /sd/modules/wps/scripts/dependencies.sh remove");
+                $this->responseHandler->setData(array('success' => true));
             } else {
-                $this->execBackground("bash /pineapple/modules/wps/scripts/dependencies.sh remove");
-                $this->response = array('success' => true);
+                $this->systemHelper->execBackground("bash /pineapple/modules/wps/scripts/dependencies.sh remove");
+                $this->responseHandler->setData(array('success' => true));
             }
         }
     }
 
-    private function handleDependenciesStatus()
+    public function handleDependenciesStatus()
     {
         if (!file_exists('/tmp/wps.progress')) {
-            $this->response = array('success' => true);
+            $this->responseHandler->setData(array('success' => true));
         } else {
-            $this->response = array('success' => false);
+            $this->responseHandler->setData(array('success' => false));
         }
     }
 
-    private function refreshStatus()
+    public function refreshStatus()
     {
         if (!file_exists('/tmp/wps.progress')) {
             if (!$this->checkDeps("iwlist")) {
@@ -136,7 +82,7 @@ class wps extends Module
                 $installLabel = "success";
                 $processing = false;
 
-                if ($this->checkRunning("reaver") || $this->checkRunning("bully")) {
+                if ($this->systemHelper->checkRunning("reaver") || $this->systemHelper->checkRunning("bully")) {
                     $status = "Stop";
                     $statusLabel = "danger";
                 } else {
@@ -154,30 +100,30 @@ class wps extends Module
             $statusLabel = "success";
         }
 
-        $device = $this->getDevice();
-        $sdAvailable = $this->isSDAvailable();
+        $device = $this->systemHelper->getDevice();
+        $sdAvailable = $this->systemHelper->isSDAvailable();
 
-        $this->response = array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "processing" => $processing);
+        $this->responseHandler->setData(array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "processing" => $processing));
     }
 
-    private function togglewps()
+    public function togglewps()
     {
-        if (!($this->checkRunning("reaver") || $this->checkRunning("bully"))) {
-            $full_cmd = $this->request->command . " &> /pineapple/modules/wps/log/log_".time().".log";
-            $lazy = $this->request->command;
+        if (!($this->systemHelper->checkRunning("reaver") || $this->systemHelper->checkRunning("bully"))) {
+            $full_cmd = $this->request['command'] . " &> /pineapple/modules/wps/log/log_".time().".log";
+            $lazy = $this->request['command'];
             shell_exec("echo -e \"{$full_cmd}\" > /tmp/wps.run");
             shell_exec("echo -e \"{$lazy}\" > /tmp/lazy.read");
 
-            $this->execBackground("/pineapple/modules/wps/scripts/wps.sh start");
+            $this->systemHelper->execBackground("/pineapple/modules/wps/scripts/wps.sh start");
         } else {
-            $this->execBackground("/pineapple/modules/wps/scripts/wps.sh stop");
+            $this->systemHelper->execBackground("/pineapple/modules/wps/scripts/wps.sh stop");
         }
     }
 
-    private function refreshOutput()
+    public function refreshOutput()
     {
         if ($this->checkDeps("reaver") && $this->checkDeps("bully")) {
-            if ($this->checkRunning("reaver") || $this->checkRunning("bully")) {
+            if ($this->systemHelper->checkRunning("reaver") || $this->systemHelper->checkRunning("bully")) {
                 $path = "/pineapple/modules/wps/log";
 
                 $latest_ctime = 0;
@@ -199,63 +145,63 @@ class wps extends Module
 
                     exec($cmd, $output);
                     if (!empty($output)) {
-                        $this->response = implode("\n", $output);
+                        $this->responseHandler->setData(implode("\n", $output));
                     } else {
-                        $this->response = "Empty log...";
+                        $this->responseHandler->setData("Empty log...");
                     }
                 }
             } else {
-                $this->response = "wps is not running...";
+                $this->responseHandler->setData("wps is not running...");
             }
         } else {
-            $this->response = "wps is not installed...";
+            $this->responseHandler->setData("wps is not installed...");
         }
     }
 
-    private function getInterfaces()
+    public function getInterfaces()
     {
         exec("iwconfig 2> /dev/null | grep \"wlan*\" | grep -v \"mon*\" | awk '{print $1}'", $interfaceArray);
 
-        $this->response = array("interfaces" => array_reverse($interfaceArray));
+        $this->responseHandler->setData(array("interfaces" => array_reverse($interfaceArray)));
     }
 
-    private function getMonitors()
+    public function getMonitors()
     {
         exec("iwconfig 2> /dev/null | grep \"mon*\" | awk '{print $1}'", $monitorArray);
 
-        $this->response = array("monitors" => $monitorArray);
+        $this->responseHandler->setData(array("monitors" => $monitorArray));
     }
 
-    private function startMonitor()
+    public function startMonitor()
     {
-        exec("airmon-ng start ".$this->request->interface);
+        exec("airmon-ng start ".$this->request['interface']);
     }
 
-    private function stopMonitor()
+    public function stopMonitor()
     {
-        exec("airmon-ng stop ".$this->request->monitor);
+        exec("airmon-ng stop ".$this->request['monitor']);
     }
 
-    private function scanForNetworks()
+    public function scanForNetworks()
     {
-        if ($this->request->duration && $this->request->monitor != "") {
+        if ($this->request['duration'] && $this->request['monitor'] != "") {
             exec("killall airodump-ng && rm -rf /tmp/wps-*");
-            $this->execBackground("airodump-ng -a --wps --output-format cap -w /tmp/wps ".$this->request->monitor." &> /dev/null");
-            sleep($this->request->duration);
+            $this->systemHelper->execBackground("airodump-ng -a --wps --output-format cap -w /tmp/wps ".$this->request['monitor']." &> /dev/null");
+            sleep($this->request['duration']);
             exec("killall airodump-ng");
             exec("wash -f /tmp/wps-01.cap > /tmp/wps-01.wash");
         }
         
         $apArray;
-        if($this->request->monitor != null){
-            $tempStation = substr($this->request->monitor, 0, -3);
-            exec("airmon-ng stop ".$this->request->monitor);
+        if($this->request['monitor'] != null){
+            $tempStation = substr($this->request['monitor'], 0, -3);
+            exec("airmon-ng stop ".$this->request['monitor']);
             $p = $this->iwlistparse->parseScanDev($tempStation);
             $apArray = $p[$tempStation];
             exec("airmon-ng start ".$tempStation);
         } else {
-            $p = $this->iwlistparse->parseScanDev($this->request->interface);
-            $apArray = $p[$this->request->interface];
+            $p = $this->iwlistparse->parseScanDev($this->request['interface']);
+            $apArray = $p[$this->request['interface']];
         }
 
         $returnArray = array();
@@ -285,7 +231,7 @@ class wps extends Module
                 $accessPoint['captureOnSelected'] = 0;
             }
 
-            if ($this->checkRunning("airodump-ng")) {
+            if ($this->systemHelper->checkRunning("airodump-ng")) {
                 $accessPoint['captureRunning'] = 1;
             } else {
                 $accessPoint['captureRunning'] = 0;
@@ -297,7 +243,7 @@ class wps extends Module
                 $accessPoint['deauthOnSelected'] = 0;
             }
 
-            if ($this->checkRunning("aireplay-ng")) {
+            if ($this->systemHelper->checkRunning("aireplay-ng")) {
                 $accessPoint['deauthRunning'] = 1;
             } else {
                 $accessPoint['deauthRunning'] = 0;
@@ -332,7 +278,7 @@ class wps extends Module
                 $accessPoint['auth'] = '';
             }
 
-            if ($this->request->duration && $this->request->monitor != "") {
+            if ($this->request['duration'] && $this->request['monitor'] != "") {
                 $accessPoint['wps'] = trim(exec("cat /tmp/wps-01.wash | tail -n +3 | grep ".$accessPoint['mac']." | awk '{ print $4; }'"));
                 $accessPoint['wpsLabel'] = "success";
                 
@@ -348,21 +294,21 @@ class wps extends Module
 
         exec("rm -rf /tmp/wps-*");
 
-        $this->response = $returnArray;
+        $this->responseHandler->setData($returnArray);
     }
 
-    private function getMACInfo()
+    public function getMACInfo()
     {
-        $content = file_get_contents("https://api.macvendors.com/".$this->request->mac);
-        $this->response = array('title' => $this->request->mac, "output" => $content);
+        $content = file_get_contents("https://api.macvendors.com/".$this->request['mac']);
+        $this->responseHandler->setData(array('title' => $this->request['mac'], "output" => $content));
     }
 
-    private function getProcesses()
+    public function getProcesses()
     {
         $returnArray = array();
 
         $process = array();
-        if (file_exists("/tmp/wps.run") && ($this->checkRunning("reaver") || $this->checkRunning("bully"))) {
+        if (file_exists("/tmp/wps.run") && ($this->systemHelper->checkRunning("reaver") || $this->systemHelper->checkRunning("bully"))) {
             $args = $this->parse_args(file_get_contents("/tmp/lazy.read"));
 
             $process['ssid'] = $args["e"];
@@ -378,10 +324,10 @@ class wps extends Module
             array_push($returnArray, $process);
         }
 
-        $this->response = $returnArray;
+        $this->responseHandler->setData($returnArray);
     }
 
-    private function parse_args($args)
+    public function parse_args($args)
     {
         if (is_string($args)) {
             $args = str_replace(array('=', "\'", '\"'), array('= ', '&#39;', '&#34;'), $args);
@@ -434,7 +380,7 @@ class wps extends Module
         return $out;
     }
 
-    private function refreshHistory()
+    public function refreshHistory()
     {
         $this->streamFunction = function () {
             $log_list = array_reverse(glob("/pineapple/modules/wps/log/*"));
@@ -455,25 +401,25 @@ class wps extends Module
         };
     }
 
-    private function downloadHistory()
+    public function downloadHistory()
     {
-        $this->response = array("download" => $this->downloadFile("/pineapple/modules/wps/log/".$this->request->file));
+        $this->responseHandler->setData(array("download" => $this->systemHelper->downloadFile("/pineapple/modules/wps/log/".$this->request['file'])));
     }
 
-    private function viewHistory()
+    public function viewHistory()
     {
-        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/wps/log/".$this->request->file));
-        exec("cat /pineapple/modules/wps/log/".$this->request->file, $output);
+        $log_date = gmdate("F d Y H:i:s", filemtime("/pineapple/modules/wps/log/".$this->request['file']));
+        exec("cat /pineapple/modules/wps/log/".$this->request['file'], $output);
 
         if (!empty($output)) {
-            $this->response = array("output" => implode("\n", $output), "date" => $log_date);
+            $this->responseHandler->setData(array("output" => implode("\n", $output), "date" => $log_date));
         } else {
-            $this->response = array("output" => "Empty log...", "date" => $log_date);
+            $this->responseHandler->setData(array("output" => "Empty log...", "date" => $log_date));
         }
     }
 
-    private function deleteHistory()
+    public function deleteHistory()
     {
-        exec("rm -rf /pineapple/modules/wps/log/".$this->request->file);
+        exec("rm -rf /pineapple/modules/wps/log/".$this->request['file']);
     }
 }