Add modules to repository

This commit is contained in:
Sebastian Kinne
2017-11-16 16:42:22 +11:00
commit d0aa1e38ef
707 changed files with 96750 additions and 0 deletions

298
p0f/api/module.php Normal file
View File

@@ -0,0 +1,298 @@
<?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 p0f extends Module
{
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 function checkDependency($dependencyName)
{
return ((exec("which {$dependencyName}") == '' ? false : true) && ($this->uciGet("p0f.module.installed")));
}
protected function getDevice()
{
return trim(exec("cat /proc/cpuinfo | grep machine | awk -F: '{print $2}'"));
}
protected function refreshInfo()
{
$moduleInfo = @json_decode(file_get_contents("/pineapple/modules/p0f/module.info"));
$this->response = array('title' => $moduleInfo->title, 'version' => $moduleInfo->version);
}
private function handleDependencies()
{
if(!$this->checkDependency("p0f"))
{
$this->execBackground("/pineapple/modules/p0f/scripts/dependencies.sh install ".$this->request->destination);
$this->response = array('success' => true);
}
else
{
$this->execBackground("/pineapple/modules/p0f/scripts/dependencies.sh remove");
$this->response = array('success' => true);
}
}
private function handleDependenciesStatus()
{
if (!file_exists('/tmp/p0f.progress'))
{
$this->response = array('success' => true);
}
else
{
$this->response = array('success' => false);
}
}
private function togglep0fOnBoot()
{
if(exec("cat /etc/rc.local | grep p0f/scripts/autostart_p0f.sh") == "")
{
exec("sed -i '/exit 0/d' /etc/rc.local");
exec("echo /pineapple/modules/p0f/scripts/autostart_p0f.sh >> /etc/rc.local");
exec("echo exit 0 >> /etc/rc.local");
}
else
{
exec("sed -i '/p0f\/scripts\/autostart_p0f.sh/d' /etc/rc.local");
}
}
private function togglep0f()
{
if(!$this->checkRunning("p0f"))
{
$this->uciSet("p0f.run.interface", $this->request->interface);
$this->execBackground("/pineapple/modules/p0f/scripts/p0f.sh start");
}
else
{
$this->uciSet("p0f.run.interface", '');
$this->execBackground("/pineapple/modules/p0f/scripts/p0f.sh stop");
}
}
private 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"));
}
private function refreshStatus()
{
if (!file_exists('/tmp/p0f.progress'))
{
if (!$this->checkDependency("p0f"))
{
$installed = false;
$install = "Not installed";
$installLabel = "danger";
$processing = false;
$status = "Start";
$statusLabel = "success";
$bootLabelON = "default";
$bootLabelOFF = "danger";
}
else
{
$installed = true;
$install = "Installed";
$installLabel = "success";
$processing = false;
if($this->checkRunning("p0f"))
{
$status = "Stop";
$statusLabel = "danger";
}
else
{
$status = "Start";
$statusLabel = "success";
}
if(exec("cat /etc/rc.local | grep p0f/scripts/autostart_p0f.sh") == "")
{
$bootLabelON = "default";
$bootLabelOFF = "danger";
}
else
{
$bootLabelON = "success";
$bootLabelOFF = "default";
}
}
}
else
{
$installed = false;
$install = "Installing...";
$installLabel = "warning";
$processing = true;
$status = "Not running";
$statusLabel = "danger";
$verbose = false;
$bootLabelON = "default";
$bootLabelOFF = "danger";
}
$device = $this->getDevice();
$sdAvailable = $this->isSDAvailable();
$this->response = array("device" => $device, "sdAvailable" => $sdAvailable, "status" => $status, "statusLabel" => $statusLabel, "installed" => $installed, "install" => $install, "installLabel" => $installLabel, "bootLabelON" => $bootLabelON, "bootLabelOFF" => $bootLabelOFF, "processing" => $processing);
}
private function refreshOutput()
{
if ($this->checkDependency("p0f"))
{
if ($this->checkRunning("p0f"))
{
$path = "/pineapple/modules/p0f/log";
$latest_ctime = 0;
$latest_filename = '';
$d = dir($path);
while (false !== ($entry = $d->read())) {
$filepath = "{$path}/{$entry}";
if (is_file($filepath) && filectime($filepath) > $latest_ctime) {
$latest_ctime = filectime($filepath);
$latest_filename = $entry;
}
}
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;
$cmd = "cat /pineapple/modules/p0f/log/".$latest_filename." | ".$filter;
}
else
{
$cmd = "cat /pineapple/modules/p0f/log/".$latest_filename;
}
exec ($cmd, $output);
if(!empty($output))
$this->response = implode("\n", array_reverse($output));
else
$this->response = "Empty log...";
}
}
else
{
$this->response = "p0f is not running...";
}
}
else
{
$this->response = "p0f is not installed...";
}
}
private function refreshHistory()
{
$this->streamFunction = function () {
$log_list = array_reverse(glob("/pineapple/modules/p0f/log/*"));
echo '[';
for($i=0;$i<count($log_list);$i++)
{
$info = explode("_", basename($log_list[$i]));
$entryDate = gmdate('Y-m-d H-i-s', $info[1]);
$entryName = basename($log_list[$i]);
echo json_encode(array($entryDate, $entryName));
if($i!=count($log_list)-1) echo ',';
}
echo ']';
};
}
private 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);
if(!empty($output))
$this->response = array("output" => implode("\n", $output), "date" => $log_date);
else
$this->response = array("output" => "Empty log...", "date" => $log_date);
}
private function deleteHistory()
{
exec("rm -rf /pineapple/modules/p0f/log/".$this->request->file);
}
private function downloadHistory()
{
$this->response = array("download" => $this->downloadFile("/pineapple/modules/p0f/log/".$this->request->file));
}
private function saveAutostartSettings()
{
$settings = $this->request->settings;
$this->uciSet("p0f.autostart.interface", $settings->interface);
}
}

279
p0f/js/module.js Normal file
View File

@@ -0,0 +1,279 @@
registerController('p0f_Controller', ['$api', '$scope', '$rootScope', '$interval', '$timeout', function($api, $scope, $rootScope, $interval, $timeout) {
$scope.title = "Loading...";
$scope.version = "Loading...";
$scope.refreshInfo = (function() {
$api.request({
module: 'p0f',
action: "refreshInfo"
}, function(response) {
$scope.title = response.title;
$scope.version = "v"+response.version;
})
});
$scope.refreshInfo();
}]);
registerController('p0f_ControlsController', ['$api', '$scope', '$rootScope', '$interval', '$timeout', function($api, $scope, $rootScope, $interval, $timeout) {
$scope.status = "Loading...";
$scope.statusLabel = "default";
$scope.starting = false;
$scope.install = "Loading...";
$scope.installLabel = "default";
$scope.processing = false;
$scope.bootLabelON = "default";
$scope.bootLabelOFF = "default";
$scope.interfaces = [];
$scope.selectedInterface = "";
$scope.saveSettingsLabel = "default";
$scope.device = '';
$scope.sdAvailable = false;
$rootScope.status = {
installed : false,
refreshOutput : false,
refreshHistory : false
};
$scope.refreshStatus = (function() {
$api.request({
module: "p0f",
action: "refreshStatus"
}, function(response) {
$scope.status = response.status;
$scope.statusLabel = response.statusLabel;
$rootScope.status.installed = response.installed;
$scope.device = response.device;
$scope.sdAvailable = response.sdAvailable;
if(response.processing) $scope.processing = true;
$scope.install = response.install;
$scope.installLabel = response.installLabel;
$scope.bootLabelON = response.bootLabelON;
$scope.bootLabelOFF = response.bootLabelOFF;
})
});
$scope.togglep0f = (function() {
if($scope.status != "Stop")
$scope.status = "Starting...";
else
$scope.status = "Stopping...";
$scope.statusLabel = "warning";
$scope.starting = true;
$rootScope.status.refreshOutput = false;
$rootScope.status.refreshHistory = false;
$api.request({
module: 'p0f',
action: 'togglep0f',
interface: $scope.selectedInterface
}, function(response) {
$timeout(function(){
$rootScope.status.refreshOutput = true;
$rootScope.status.refreshHistory = true;
$scope.starting = false;
$scope.refreshStatus();
}, 2000);
})
});
$scope.saveAutostartSettings = (function() {
$api.request({
module: 'p0f',
action: 'saveAutostartSettings',
settings: { interface : $scope.selectedInterface }
}, function(response) {
$scope.saveSettingsLabel = "success";
$timeout(function(){
$scope.saveSettingsLabel = "default";
}, 2000);
})
});
$scope.togglep0fOnBoot = (function() {
if($scope.bootLabelON == "default")
{
$scope.bootLabelON = "success";
$scope.bootLabelOFF = "default";
}
else
{
$scope.bootLabelON = "default";
$scope.bootLabelOFF = "danger";
}
$api.request({
module: 'p0f',
action: 'togglep0fOnBoot',
}, function(response) {
$scope.refreshStatus();
})
});
$scope.handleDependencies = (function(param) {
if(!$rootScope.status.installed)
$scope.install = "Installing...";
else
$scope.install = "Removing...";
$api.request({
module: 'p0f',
action: 'handleDependencies',
destination: param
}, function(response){
if (response.success === true) {
$scope.installLabel = "warning";
$scope.processing = true;
$scope.handleDependenciesInterval = $interval(function(){
$api.request({
module: 'p0f',
action: 'handleDependenciesStatus'
}, function(response) {
if (response.success === true){
$scope.processing = false;
$interval.cancel($scope.handleDependenciesInterval);
$scope.refreshStatus();
}
});
}, 5000);
}
});
});
$scope.getInterfaces = (function() {
$api.request({
module: 'p0f',
action: 'getInterfaces'
}, function(response) {
$scope.interfaces = response.interfaces;
if(response.selected != "")
$scope.selectedInterface = response.selected;
else
$scope.selectedInterface = $scope.interfaces[0];
});
});
$scope.refreshStatus();
$scope.getInterfaces();
}]);
registerController('p0f_OutputController', ['$api', '$scope', '$rootScope', '$interval', function($api, $scope, $rootScope,$interval) {
$scope.output = 'Loading...';
$scope.filter = '';
$scope.refreshLabelON = "default";
$scope.refreshLabelOFF = "danger";
$scope.refreshOutput = (function() {
$api.request({
module: "p0f",
action: "refreshOutput",
filter: $scope.filter
}, function(response) {
$scope.output = response;
})
});
$scope.clearFilter = (function() {
$scope.filter = '';
$scope.refreshOutput();
});
$scope.toggleAutoRefresh = (function() {
if($scope.autoRefreshInterval)
{
$interval.cancel($scope.autoRefreshInterval);
$scope.autoRefreshInterval = null;
$scope.refreshLabelON = "default";
$scope.refreshLabelOFF = "danger";
}
else
{
$scope.refreshLabelON = "success";
$scope.refreshLabelOFF = "default";
$scope.autoRefreshInterval = $interval(function(){
$scope.refreshOutput();
}, 5000);
}
});
$scope.refreshOutput();
$rootScope.$watch('status.refreshOutput', function(param) {
if(param) {
$scope.refreshOutput();
}
});
}]);
registerController('p0f_HistoryController', ['$api', '$scope', '$rootScope', function($api, $scope, $rootScope) {
$scope.history = [];
$scope.historyOutput = 'Loading...';
$scope.historyDate = 'Loading...';
$scope.refreshHistory = (function() {
$api.request({
module: "p0f",
action: "refreshHistory"
}, function(response) {
$scope.history = response;
})
});
$scope.viewHistory = (function(param) {
$api.request({
module: "p0f",
action: "viewHistory",
file: param
}, function(response) {
$scope.historyOutput = response.output;
$scope.historyDate = response.date;
})
});
$scope.deleteHistory = (function(param) {
$api.request({
module: "p0f",
action: "deleteHistory",
file: param
}, function(response) {
$scope.refreshHistory();
})
});
$scope.downloadHistory = (function(param) {
$api.request({
module: 'p0f',
action: 'downloadHistory',
file: param
}, function(response) {
if (response.error === undefined) {
window.location = '/api/?download=' + response.download;
}
});
});
$scope.refreshHistory();
$rootScope.$watch('status.refreshHistory', function(param) {
if(param) {
$scope.refreshHistory();
}
});
}]);

163
p0f/module.html Normal file
View File

@@ -0,0 +1,163 @@
<div class="panel panel-default" ng-controller="p0f_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="row">
<div class="col-md-4">
<div class="panel panel-default" ng-controller="p0f_ControlsController">
<div class="panel-heading">
<h3 class="panel-title">
Controls
<span class="dropdown">
<ul class="dropdown-menu" aria-labelledby="poolDropdown">
<li ng-click="saveAutostartSettings()"><a>Save settings for start on boot</a></li>
</ul>
<button class="btn btn-xs btn-{{saveSettingsLabel}} dropdown-toggle" type="button" id="poolDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
</button>
</span>
</h3>
</div>
<div class="panel-body">
<table style="width:100%">
<tr>
<td style="padding-bottom: .5em;" class="text-muted">Dependencies</td>
<td ng-hide="$root.status.installed" style="text-align:right;padding-bottom: .5em;"><button type="button" style="width: 90px;" class="btn btn-{{installLabel}} btn-xs" data-toggle="modal" data-target="#dependenciesInstallModal" ng-disabled="processing">{{install}}</button></td>
<td ng-show="$root.status.installed" style="text-align:right;padding-bottom: .5em;"><button type="button" style="width: 90px;" class="btn btn-{{installLabel}} btn-xs" data-toggle="modal" data-target="#dependenciesRemoveModal" ng-disabled="processing">{{install}}</button></td>
</tr>
<tr class="form-inline" ng-show="$root.status.installed">
<td style="padding-bottom: .5em;" class="text-muted">p0f</td>
<td style="text-align:right;padding-bottom: .5em;">
<select class="form-control input-sm" ng-disabled="starting || status == 'Stop'" ng-model="selectedInterface">
<option ng-repeat="interface in interfaces">{{ interface }}</option>
</select>
<button type="button" style="width: 90px;" class="btn btn-{{statusLabel}} btn-xs" ng-disabled="starting" ng-click="togglep0f()">{{status}}</button>
</td>
</tr>
<tr ng-show="$root.status.installed">
<td style="padding-bottom: .5em;" class="text-muted">Start on boot</td>
<td style="text-align:right;padding-bottom: .5em;">
<div class="btn-group">
<button ng-click="togglep0fOnBoot()" class="btn btn-xs btn-{{bootLabelON}}">ON</button>
<button ng-click="togglep0fOnBoot()" class="btn btn-xs btn-{{bootLabelOFF}}">OFF</button>
</div>
</td>
</tr>
</table>
</div>
<div class="modal fade" id="dependenciesInstallModal" tabindex="-1" role="dialog" aria-labelledby="dependenciesModalLabel">
<div class="modal-dialog" 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">&times;</span></button>
<h4 class="modal-title" id="dependenciesInstallModalLabel">Install dependencies</h4>
</div>
<div class="modal-body">
All required dependencies have to be installed first. This may take a few minutes.<br /><br />
Please wait, do not leave or refresh this page. Once the install is complete, this page will refresh automatically.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info" ng-click="handleDependencies('internal')" data-dismiss="modal">Internal</button>
<button type="button" class="btn btn-info" ng-hide="device == 'tetra' || sdAvailable == false" ng-click="handleDependencies('sd')" data-dismiss="modal">SD Card</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="dependenciesRemoveModal" tabindex="-1" role="dialog" aria-labelledby="dependenciesModalLabel">
<div class="modal-dialog" 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">&times;</span></button>
<h4 class="modal-title" id="dependenciesRemoveModalLabel">Remove dependencies</h4>
</div>
<div class="modal-body">
All required dependencies will be removed. This may take a few minutes.<br /><br />
Please wait, do not leave or refresh this page. Once the remove is complete, this page will refresh automatically.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-info" ng-click="handleDependencies()" data-dismiss="modal">Confirm</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="panel panel-default" ng-show="$root.status.installed" ng-controller="p0f_OutputController">
<div class="panel-heading">
<h4 class="panel-title pull-left">Output</h4>
<div class="pull-right">
Auto-refresh <div class="btn-group">
<button ng-click="toggleAutoRefresh()" class="btn btn-xs btn-{{refreshLabelON}}">ON</button>
<button ng-click="toggleAutoRefresh()" class="btn btn-xs btn-{{refreshLabelOFF}}">OFF</button>
</div>
</div>
<div class="clearfix"></div>
</div>
<div class="panel-body">
<div class="input-group">
<span class="input-group-addon input-sm">Filter</span>
<input type="text" class="form-control input-sm" placeholder="Piped commands used to filter output (e.g. grep, awk)" ng-model="filter">
<div class="input-group-btn">
<button class="btn btn-default btn-sm" ng-click="clearFilter()">Clear Filter</button>
<button class="btn btn-primary btn-sm" ng-click="refreshOutput()">Refresh Log</button>
</div>
</div>
<pre class="scrollable-pre log-pre">{{output}}</pre>
</div>
</div>
<div class="panel panel-default" ng-show="$root.status.installed" ng-controller="p0f_HistoryController">
<div class="panel-heading pointer" data-toggle="collapse" data-target="#History">
<h4 class="panel-title">History <span class="badge">{{history.length}}</span></h4>
</div>
<div id="History" class="panel-collapse collapse">
<div class="panel-body">
<button class="btn btn-primary btn-sm pull-right" ng-click="refreshHistory()">Refresh History</button><div class="clearfix"></div>
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover" ng-hide="(history.length == 0)">
<thead>
<tr>
<th>Date</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="entry in history" ng-if="entry != ''">
<td>{{entry[0]}}</td>
<td>
<div class="btn-group">
<button type="button" class="btn btn-fixed-length btn-sm btn-default" data-toggle="modal" data-target="#historyModal" ng-click="viewHistory(entry[1])">View</button>
<button type="button" class="btn btn-sm btn-default" ng-click="downloadHistory(entry[1])">Download</button>
<button type="button" class="btn btn-fixed-length btn-sm btn-danger" ng-click="deleteHistory(entry[1])">Delete</button>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="well" ng-show="(history.length === 0)">No history...</div>
</div>
</div>
<div class="modal fade" id="historyModal" tabindex="-1" role="dialog" aria-labelledby="historyModalLabel">
<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">&times;</span></button>
<h4 class="modal-title" id="historyModalLabel">View History - {{historyDate}}</h4>
</div>
<div class="modal-body">
<pre class="scrollable-pre log-pre">{{historyOutput}}</pre>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>

10
p0f/module.info Normal file
View File

@@ -0,0 +1,10 @@
{
"author": "Whistle Master",
"description": "Passive traffic fingerprinting using p0f",
"devices": [
"nano",
"tetra"
],
"title": "p0f",
"version": "1.0"
}

17
p0f/scripts/autostart_p0f.sh Executable file
View File

@@ -0,0 +1,17 @@
#!/bin/sh
#2015 - Whistle Master
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/sd/lib:/sd/usr/lib
export PATH=$PATH:/sd/usr/bin:/sd/usr/sbin
MYTIME=`date +%s`
MYINTERFACE=`uci get p0f.autostart.interface`
if [ -z "$MYINTERFACE" ]; then
MYINTERFACE="br-lan"
fi
uci set p0f.run.interface=${MYINTERFACE}
uci commit p0f.run.interface
p0f -i ${MYINTERFACE} -o /pineapple/modules/p0f/log/output_${MYTIME}.log 2>&1 &

35
p0f/scripts/dependencies.sh Executable file
View File

@@ -0,0 +1,35 @@
#!/bin/sh
#2015 - Whistle Master
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/sd/lib:/sd/usr/lib
export PATH=$PATH:/sd/usr/bin:/sd/usr/sbin
[[ -f /tmp/p0f.progress ]] && {
exit 0
}
touch /tmp/p0f.progress
if [ "$1" = "install" ]; then
if [ "$2" = "internal" ]; then
opkg update
opkg install p0f
elif [ "$2" = "sd" ]; then
opkg update
opkg install p0f --dest sd
fi
touch /etc/config/p0f
echo "config p0f 'module'" > /etc/config/p0f
echo "config p0f 'run'" >> /etc/config/p0f
echo "config p0f 'autostart'" >> /etc/config/p0f
uci set p0f.module.installed=1
uci commit p0f.module.installed
elif [ "$1" = "remove" ]; then
opkg remove p0f
rm -rf /etc/config/p0f
fi
rm /tmp/p0f.progress

14
p0f/scripts/p0f.sh Executable file
View File

@@ -0,0 +1,14 @@
#!/bin/sh
#2015 - Whistle Master
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/sd/lib:/sd/usr/lib
export PATH=$PATH:/sd/usr/bin:/sd/usr/sbin
MYTIME=`date +%s`
MYINTERFACE=`uci get p0f.run.interface`
if [ "$1" = "start" ]; then
p0f -i ${MYINTERFACE} -o /pineapple/modules/p0f/log/output_${MYTIME}.log
elif [ "$1" = "stop" ]; then
killall -9 p0f
fi