Added module SSIDManager
parent
ad51839173
commit
6bcdc90fc6
|
@ -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.
|
|
@ -0,0 +1,92 @@
|
||||||
|
<?php namespace pineapple;
|
||||||
|
|
||||||
|
/* 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
|
||||||
|
{
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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; $i<count($files_list); $i++) {
|
||||||
|
$files_list[$i] = basename($files_list[$i]);
|
||||||
|
}
|
||||||
|
$this->response = 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}]);
|
|
@ -0,0 +1,86 @@
|
||||||
|
<!-- This HTML has bootstrap classes such as "col-md-12" and "jumbotron". For more information, see http://getbootstrap.com/css/ -->
|
||||||
|
<!-- This HTML makes use of AngularJS data-bindings and controllers. For more information, see https://docs.angularjs.org/api/ -->
|
||||||
|
<!-- Don't forget to look at the module.js and module.php files too! -->
|
||||||
|
<!-- This HTML is a template for generated modules via the Module Maker. -->
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title></title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div ng-controller="SSIDManagerController">
|
||||||
|
<div class='col-md-12'>
|
||||||
|
<div class='row'>
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h4 class="panel-title pull-left">SSID Manager</h4><span class="pull-right">{{version}}</span>
|
||||||
|
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class='panel panel-default'>
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h4 class="panel-title">SSID File Editor</h4>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="panel-body">
|
||||||
|
<textarea ng-model="ssidPool" rows="12" style="width:100%"></textarea>
|
||||||
|
<div class="row">
|
||||||
|
<div class='col-md-6'>
|
||||||
|
<button class="btn btn-warning" ng-click="clearPool()" style="width: 100%; margin-top:5px">Clear Editor</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class='col-md-6'>
|
||||||
|
<button class="btn btn-success" ng-click="setPool()" ng-disabled="pineAPssidPool == ssidPool" style="width: 100%; margin-top:5px">Update PineAP</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="alert well-sm alert-success" style="margin-top: 8px" ng-show="updatedPineAP">PineAP updated successfully</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class='panel panel-default'>
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h4 class="panel-title">Store Pool</h4>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="panel-body">
|
||||||
|
Filename: <input style="margin: 10px" ng-model="storeFileName">
|
||||||
|
<button class="btn btn-primary" ng-click="archivePool()" ng-disabled="storeFileName=='' || ssidPool == ''">Store SSIDs</button>
|
||||||
|
<p class="alert well-sm alert-success" style="margin-top: 5px" ng-show="storedSSIDFile">SSID file stored successfully</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h4 class="panel-title">Stored SSID Files</h4>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="panel-body">
|
||||||
|
<select name="fileSelect" id="fileSelect" style="margin: 10px" ng-model="selectedFile" ng-disabled="ssidFilesList==''" size="1" style="width:40%">
|
||||||
|
<option ng-repeat="f in ssidFilesList" value="{{f}}">
|
||||||
|
{{f}}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
<span class="text-nowrap">
|
||||||
|
<button class="btn btn-primary" ng-click="loadSSIDFile()" ng-disabled="selectedFile==null">Load to Editor</button>
|
||||||
|
<button class="btn btn-secondary" ng-click="downloadSSIDFile()" ng-disabled="selectedFile==null">Download</button>
|
||||||
|
<button class="btn btn-danger" ng-click="deleteSSIDFile()" ng-disabled="selectedFile==null">Delete</button>
|
||||||
|
<p class="alert well-sm alert-success" style="margin-top: 5px" ng-show="deletedSSIDFile">SSID file deleted successfully</p>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"title": "SSID Manager",
|
||||||
|
"description": "Manage SSID Pools for PineAP",
|
||||||
|
"version": "1.0",
|
||||||
|
"author": "noncenz"
|
||||||
|
}
|
Loading…
Reference in New Issue