mirror of
https://github.com/hak5/nano-tetra-modules.git
synced 2025-10-29 16:58:09 +00:00
Add modules to repository
This commit is contained in:
147
LogManager/api/module.php
Normal file
147
LogManager/api/module.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php namespace pineapple;
|
||||
putenv('LD_LIBRARY_PATH='.getenv('LD_LIBRARY_PATH').':/sd/lib:/sd/usr/lib');
|
||||
putenv('PATH='.getenv('PATH').':/sd/usr/bin:/sd/usr/sbin');
|
||||
|
||||
class LogManager extends Module
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private function dataSize($path)
|
||||
{
|
||||
$blah = exec( "/usr/bin/du -sch $path | tail -1 | awk {'print $1'}" );
|
||||
return $blah;
|
||||
}
|
||||
|
||||
protected function refreshInfo()
|
||||
{
|
||||
$moduleInfo = @json_decode(file_get_contents("/pineapple/modules/LogManager/module.info"));
|
||||
$this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
|
||||
}
|
||||
|
||||
private function downloadFilesList()
|
||||
{
|
||||
$files = $this->request->files;
|
||||
|
||||
exec("mkdir /tmp/dl/");
|
||||
foreach($files as $file)
|
||||
{
|
||||
exec("cp ".$file." /tmp/dl/");
|
||||
}
|
||||
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"));
|
||||
}
|
||||
|
||||
private function deleteFilesList()
|
||||
{
|
||||
$files = $this->request->files;
|
||||
|
||||
foreach($files as $file)
|
||||
{
|
||||
exec("rm -rf ".$file);
|
||||
}
|
||||
}
|
||||
|
||||
private function refreshFilesList()
|
||||
{
|
||||
$modules = array();
|
||||
foreach(glob('/pineapple/modules/*/log/*') as $file)
|
||||
{
|
||||
$module = array();
|
||||
$module['file'] = basename($file);
|
||||
$module['path'] = $file;
|
||||
$module['size'] = $this->dataSize($file);
|
||||
$module['title'] = explode("/", dirname($file))[3];
|
||||
$module['date'] = gmdate("F d Y H:i:s", filemtime($file));
|
||||
$module['timestamp'] = filemtime($file);
|
||||
$modules[] = $module;
|
||||
}
|
||||
|
||||
foreach(glob('/pineapple/modules/*/dump/*') as $file)
|
||||
{
|
||||
$module = array();
|
||||
$module['file'] = basename($file);
|
||||
$module['path'] = $file;
|
||||
$module['size'] = $this->dataSize($file);
|
||||
$module['title'] = explode("/", dirname($file))[3];
|
||||
$module['date'] = gmdate("F d Y H:i:s", filemtime($file));
|
||||
$module['timestamp'] = filemtime($file);
|
||||
$modules[] = $module;
|
||||
}
|
||||
|
||||
foreach(glob('/pineapple/modules/*/scan/*') as $file)
|
||||
{
|
||||
$module = array();
|
||||
$module['file'] = basename($file);
|
||||
$module['path'] = $file;
|
||||
$module['size'] = $this->dataSize($file);
|
||||
$module['title'] = explode("/", dirname($file))[3];
|
||||
$module['date'] = gmdate("F d Y H:i:s", filemtime($file));
|
||||
$module['timestamp'] = filemtime($file);
|
||||
$modules[] = $module;
|
||||
}
|
||||
|
||||
foreach(glob('/pineapple/modules/*/capture/*') as $file)
|
||||
{
|
||||
$module = array();
|
||||
$module['file'] = basename($file);
|
||||
$module['path'] = $file;
|
||||
$module['size'] = $this->dataSize($file);
|
||||
$module['title'] = explode("/", dirname($file))[3];
|
||||
$module['date'] = gmdate("F d Y H:i:s", filemtime($file));
|
||||
$module['timestamp'] = filemtime($file);
|
||||
$modules[] = $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);
|
||||
}
|
||||
|
||||
private function viewModuleFile()
|
||||
{
|
||||
$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));
|
||||
else
|
||||
$this->response = array("output" => "Empty file...", "date" => $log_date, "name" => basename($this->request->file));
|
||||
}
|
||||
|
||||
private function deleteModuleFile()
|
||||
{
|
||||
exec("rm -rf ".$this->request->file);
|
||||
}
|
||||
|
||||
private function downloadModuleFile()
|
||||
{
|
||||
$this->response = array("download" => $this->downloadFile($this->request->file));
|
||||
}
|
||||
}
|
||||
116
LogManager/js/module.js
Normal file
116
LogManager/js/module.js
Normal file
@@ -0,0 +1,116 @@
|
||||
registerController('LogManager_Controller', ['$api', '$scope', '$rootScope', '$interval', '$timeout', function($api, $scope, $rootScope, $interval, $timeout) {
|
||||
$scope.title = "Loading...";
|
||||
$scope.version = "Loading...";
|
||||
|
||||
$scope.refreshInfo = (function() {
|
||||
$api.request({
|
||||
module: 'LogManager',
|
||||
action: "refreshInfo"
|
||||
}, function(response) {
|
||||
$scope.title = response.title;
|
||||
$scope.version = "v"+response.version;
|
||||
})
|
||||
});
|
||||
|
||||
$scope.refreshInfo();
|
||||
|
||||
}]);
|
||||
|
||||
registerController('LogManager_FilesController', ['$api', '$scope', '$rootScope', '$filter', function($api, $scope, $rootScope, $filter) {
|
||||
$scope.files = [];
|
||||
$scope.selectedFiles = {};
|
||||
$scope.selectedFilesArray = [];
|
||||
$scope.selectedAll = false;
|
||||
$scope.fileOutput = 'Loading...';
|
||||
$scope.fileDate = 'Loading...';
|
||||
$scope.fileName = 'Loading...';
|
||||
|
||||
$scope.updateSelectedFiles = (function() {
|
||||
$scope.selectedFilesArray = [];
|
||||
angular.forEach($scope.selectedFiles, function(key,value) { if(key) { $scope.selectedFilesArray.push(value); } });
|
||||
});
|
||||
|
||||
$scope.updateAllSelectedFiles = (function() {
|
||||
$scope.selectedFilesArray = [];
|
||||
if($scope.selectedAll)
|
||||
{
|
||||
angular.forEach($scope.files, function(key,value) { $scope.selectedFilesArray.push(key.path); $scope.selectedFiles[key.path] = true; });
|
||||
$scope.selectedAll = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$scope.selectedAll = false;
|
||||
$scope.selectedFiles = {};
|
||||
}
|
||||
});
|
||||
|
||||
$scope.refreshFilesList = (function() {
|
||||
$api.request({
|
||||
module: "LogManager",
|
||||
action: "refreshFilesList"
|
||||
}, function(response) {
|
||||
$scope.files = response.files;
|
||||
})
|
||||
});
|
||||
|
||||
$scope.downloadFilesList = (function() {
|
||||
$api.request({
|
||||
module: "LogManager",
|
||||
action: "downloadFilesList",
|
||||
files: $scope.selectedFilesArray
|
||||
}, function(response) {
|
||||
if (response.error === undefined) {
|
||||
window.location = '/api/?download=' + response.download;
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
$scope.deleteFilesList = (function() {
|
||||
$api.request({
|
||||
module: "LogManager",
|
||||
action: "deleteFilesList",
|
||||
files: $scope.selectedFilesArray
|
||||
}, function(response) {
|
||||
$scope.refreshFilesList();
|
||||
$scope.selectedFiles = {};
|
||||
$scope.updateSelectedFiles();
|
||||
})
|
||||
});
|
||||
|
||||
$scope.viewFile = (function(param) {
|
||||
$api.request({
|
||||
module: "LogManager",
|
||||
action: "viewModuleFile",
|
||||
file: param
|
||||
}, function(response) {
|
||||
$scope.fileOutput = response.output;
|
||||
$scope.fileDate = response.date;
|
||||
$scope.fileName = response.name;
|
||||
})
|
||||
});
|
||||
|
||||
$scope.deleteFile = (function(param) {
|
||||
$api.request({
|
||||
module: "LogManager",
|
||||
action: "deleteModuleFile",
|
||||
file: param
|
||||
}, function(response) {
|
||||
$scope.refreshFilesList();
|
||||
})
|
||||
});
|
||||
|
||||
$scope.downloadFile = (function(param) {
|
||||
$api.request({
|
||||
module: 'LogManager',
|
||||
action: 'downloadModuleFile',
|
||||
file: param
|
||||
}, function(response) {
|
||||
if (response.error === undefined) {
|
||||
window.location = '/api/?download=' + response.download;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$scope.refreshFilesList();
|
||||
|
||||
}]);
|
||||
71
LogManager/module.html
Normal file
71
LogManager/module.html
Normal file
@@ -0,0 +1,71 @@
|
||||
<div class="panel panel-default" ng-controller="LogManager_Controller"><div class="panel-heading"><h4 class="panel-title pull-left">{{title}}</h4><span class="pull-right">{{version}}</span><div class="clearfix"></div></div></div>
|
||||
|
||||
<div class="panel panel-default" ng-controller="LogManager_FilesController">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">Files <span class="badge">{{files.length}}</span></h4>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<button class="btn btn-primary btn-sm pull-right" ng-click="refreshFilesList()">Refresh</button><div class="clearfix"></div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-bordered table-hover" ng-hide="(files.length == 0)">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<div class="dropdown">
|
||||
<input type="checkbox" ng-model="selectedAll" ng-change="updateAllSelectedFiles()">
|
||||
<button ng-disabled="(selectedFilesArray.length === 0)" class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
||||
Actions
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
|
||||
<li ng-click="downloadFilesList()"><a>Download <span class="badge">{{selectedFilesArray.length}}</span></a></li>
|
||||
<li ng-click="deleteFilesList()"><a>Delete <span class="badge">{{selectedFilesArray.length}}</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</th>
|
||||
<th>Name</th>
|
||||
<th>Module</th>
|
||||
<th>Size</th>
|
||||
<th>Date</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="(fileName, file) in files">
|
||||
<td><input type="checkbox" ng-checked="selectedAll" ng-change="updateSelectedFiles()" ng-model="selectedFiles[file['path']]">
|
||||
<td>{{ file['file'] }}</td>
|
||||
<td>{{ file['title'] }}</td>
|
||||
<td>{{ file['size'] }}</td>
|
||||
<td>{{ file['date'] }}</td>
|
||||
<td>
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-fixed-length btn-sm btn-default" data-toggle="modal" data-target="#fileModal" ng-click="viewFile(file['path'])">View</button>
|
||||
<button type="button" class="btn btn-sm btn-default" ng-click="downloadFile(file['path'])">Download</button>
|
||||
<button type="button" class="btn btn-fixed-length btn-sm btn-danger" ng-click="deleteFile(file['path'])">Delete</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="well" ng-show="(files.length === 0)">No file...</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="fileModal" tabindex="-1" role="dialog" aria-labelledby="fileModalLabel">
|
||||
<div class="modal-dialog modal-lg" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title" id="fileModalLabel">View {{fileName}} - {{fileDate}}</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<pre class="scrollable-pre log-pre">{{fileOutput}}</pre>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
10
LogManager/module.info
Normal file
10
LogManager/module.info
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"author": "Whistle Master",
|
||||
"description": "Manage all modules logs",
|
||||
"devices": [
|
||||
"nano",
|
||||
"tetra"
|
||||
],
|
||||
"title": "Log Manager",
|
||||
"version": "1.2"
|
||||
}
|
||||
Reference in New Issue
Block a user