From 6bcdc90fc690ae93f12791b1bd14d17bfd0a7e01 Mon Sep 17 00:00:00 2001 From: noncenz Date: Tue, 23 Jul 2019 19:39:04 -0400 Subject: [PATCH] Added module SSIDManager --- SSIDManager/LICENSE | 21 ++++++ SSIDManager/api/module.php | 92 ++++++++++++++++++++++++++ SSIDManager/js/module.js | 132 +++++++++++++++++++++++++++++++++++++ SSIDManager/module.html | 86 ++++++++++++++++++++++++ SSIDManager/module.info | 6 ++ 5 files changed, 337 insertions(+) create mode 100644 SSIDManager/LICENSE create mode 100644 SSIDManager/api/module.php create mode 100644 SSIDManager/js/module.js create mode 100644 SSIDManager/module.html create mode 100644 SSIDManager/module.info diff --git a/SSIDManager/LICENSE b/SSIDManager/LICENSE new file mode 100644 index 0000000..14c5be0 --- /dev/null +++ b/SSIDManager/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 noncenz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/SSIDManager/api/module.php b/SSIDManager/api/module.php new file mode 100644 index 0000000..8aebb6a --- /dev/null +++ b/SSIDManager/api/module.php @@ -0,0 +1,92 @@ +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; + } + } + + private function SSIDDirectoryPath() + { + $path = '/pineapple/modules/SSIDManager/SSID_Files/'; + if (!file_exists($path)) { + exec("mkdir ".$path); + } + return '/pineapple/modules/SSIDManager/SSID_Files/'; + } + + private function getContents() + { + $moduleInfo = @json_decode(file_get_contents("/pineapple/modules/SSIDManager/module.info")); + + $this->response = array("success" => true, + "version" => "version " . $moduleInfo->version, + "content" => ""); + } + + + private function getSSIDFilesList() + { + $SSIDFilesPath = $this->SSIDDirectoryPath(); + $files_list = glob($SSIDFilesPath . '*') ; + + for ($i=0; $iresponse = array("success"=>true, "filesList"=>$files_list); + } + + private function saveSSIDFile() + { + $filename = $this->SSIDDirectoryPath().$this->request->storeFileName; + file_put_contents($filename, $this->request->ssidPool); + $this->response = array("success" => true); + } + + private function downloadSSIDFile() + { + $filename = $this->SSIDDirectoryPath().$this->request->file; + $this->response = array("download" => $this->downloadFile($filename)); + } + + private function deleteSSIDFile() + { + exec("rm -rf " . $this->SSIDDirectoryPath() ."'" . $this->request->file . "'"); + $this->response = array("success" => true); + } + + private function loadSSIDFile() + { + $filename = $this->SSIDDirectoryPath() . $this->request->file; + $fileContent = file_get_contents($filename); + $this->response = array("success" => true,"content"=>$fileContent,"fileName"=>$filename); + } +} diff --git a/SSIDManager/js/module.js b/SSIDManager/js/module.js new file mode 100644 index 0000000..dfcab76 --- /dev/null +++ b/SSIDManager/js/module.js @@ -0,0 +1,132 @@ +registerController('SSIDManagerController', ['$api', '$scope', '$timeout',function($api, $scope, $timeout) { + /* It is good practice to 'initialize' your variables with nothing */ + $scope.currentSSIDs = ""; + $scope.pineAPssidPool = ""; + $scope.ssidPool = ""; + $scope.storeFileName = ""; + $scope.updatedPineAP = ""; + $scope.storedSSIDFile = ""; + $scope.deletedSSIDFile = ""; + + $scope.getPool = (function() { + $api.request({ + module: 'PineAP', + action: 'getPool' + }, function(response) { + $scope.ssidPool = response.ssidPool; + $scope.pineAPssidPool = response.ssidPool; + }); + }); + + $scope.clearPool = (function() { + $api.request({ + module: 'PineAP', + action: 'clearPool' + }, function(response) { + $scope.ssidPool = ''; + $scope.pineAPssidPool = ''; + }); + }); + + $scope.setPool = (function() { + $api.request({ + module: 'PineAP', + action: 'clearPool' + }, function(response) { + var newPool = $scope.ssidPool.split("\n"); + $api.request({ + module: 'PineAP', + action: 'addSSIDs', + ssids: newPool + }, function(response) { + if (response.error === undefined) { + $scope.updatedPineAP = true; + } else { + $scope.lengthError = true; + } + $timeout(function(){ + $scope.updatedPineAP = false; + }, 2000); + $scope.getPool(); + + }); + }); + }); + + $scope.archivePool = (function() { + $api.request({ + module: 'SSIDManager', + action: 'archivePool', + storeFileName: $scope.storeFileName, + ssidPool: $scope.ssidPool + }, function(response) { + $scope.storeFileName = ''; + $scope.getSSIDFilesList(); + $scope.storedSSIDFile = true; + $timeout(function(){ + $scope.storedSSIDFile = false; + }, 2000); + }); + }); + + $scope.deleteSSIDFile = (function() { + $api.request({ + module: 'SSIDManager', + action: 'deleteSSIDFile', + file: $scope.selectedFile + }, function(response) { + $scope.getSSIDFilesList(); + $scope.deletedSSIDFile = true; + $timeout(function(){ + $scope.deletedSSIDFile = false; + }, 2000); + }); + }); + + $scope.loadSSIDFile = (function() { + $api.request({ + module: 'SSIDManager', + action: 'getSSIDFile', + file: $scope.selectedFile + }, function(response) { + $scope.ssidPool = response.content; + }); + }); + + $scope.getSSIDFilesList = (function() { + $api.request({ + module: 'SSIDManager', + action: 'getSSIDFilesList' + }, function(response) { + $scope.ssidFilesList = response.filesList; + }); + }); + + $scope.downloadSSIDFile = (function() { + $api.request({ + module: 'SSIDManager', + action: 'downloadSSIDFile', + file: $scope.selectedFile + }, function(response) { + debugger; + if (response.error === undefined) { + window.location = '/api/?download=' + response.download; + } + }); + }); + + + $scope.getSSIDFilesList(); + $scope.getPool(); + + /* Use the API to send a request to your module.php */ + + $api.request({ + module: 'SSIDManager', //Your module name + action: 'getContents' //Your action defined in module.php + }, function(response) { + if (response.success === true) { //If the response has an index called "success" that returns the boolean "true", then: + $scope.version = response.version; + } + }); +}]); \ No newline at end of file diff --git a/SSIDManager/module.html b/SSIDManager/module.html new file mode 100644 index 0000000..646cbc1 --- /dev/null +++ b/SSIDManager/module.html @@ -0,0 +1,86 @@ + + + + + + + + + + + + +
+
+
+
+
+

SSID Manager

{{version}} + +
+
+
+
+
+ +
+
+
+
+

SSID File Editor

+
+ +
+ +
+
+ +
+ +
+ +
+
+

PineAP updated successfully

+
+ +
+
+ +
+
+
+

Store Pool

+
+ +
+ Filename:   + +

SSID file stored successfully

+
+
+ +
+
+

Stored SSID Files

+
+ +
+ + + + + +

SSID file deleted successfully

+
+
+
+
+
+
+ + diff --git a/SSIDManager/module.info b/SSIDManager/module.info new file mode 100644 index 0000000..98523e0 --- /dev/null +++ b/SSIDManager/module.info @@ -0,0 +1,6 @@ +{ + "title": "SSID Manager", + "description": "Manage SSID Pools for PineAP", + "version": "1.0", + "author": "noncenz" +} \ No newline at end of file