first commit
parent
9aeeb4f9c5
commit
dbac4a8766
|
@ -0,0 +1,175 @@
|
|||
<?php namespace pineapple;
|
||||
|
||||
/*
|
||||
* Author: trashbo4t (github.com/trashbo4t)
|
||||
*/
|
||||
|
||||
class InternetSpeedTest extends Module
|
||||
{
|
||||
// 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 '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)
|
||||
{
|
||||
exec("echo {$msg} >> {$this->LOG_FILE}");
|
||||
}
|
||||
|
||||
//
|
||||
// clearLogFile
|
||||
// this function will wipe the log file inside the IST directory
|
||||
//
|
||||
private function clearLogFile()
|
||||
{
|
||||
exec("echo '' > {$this->LOG_FILE}");
|
||||
}
|
||||
|
||||
// makeSpeedTestDir
|
||||
// this function will create the directory for speed test outputs
|
||||
// IFF the directory does not exist
|
||||
public function makeSpeedTestsDir()
|
||||
{
|
||||
exec("mkdir {$this->SPEED_TEST_DIR}");
|
||||
}
|
||||
|
||||
//
|
||||
// touchSpeedTestFile
|
||||
// this function will create an empty speedtest file
|
||||
//
|
||||
public function touchSpeedTestFile($file)
|
||||
{
|
||||
if ($file == null)
|
||||
{
|
||||
exec("touch {$this->ALL_TESTS_FILE}");
|
||||
return "{$this->ALL_TESTS_FILE}";
|
||||
}
|
||||
else
|
||||
{
|
||||
exec("touch {$file}");
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// runSpeedTest
|
||||
// this function will execute the wget command download a 500mb file from softlayer.com
|
||||
// as and return the output of @getSpeedTestFile
|
||||
//
|
||||
public function runSpeedTest($file)
|
||||
{
|
||||
$firstcmd = "wget -a ".$file." --output-document=/dev/null https://www.wifipineapple.com/downloads/tetra/2.5.2";
|
||||
$secondcmd = "echo Downloading 50 MB of data finished on `tail -n 2 ".$file." | cut -d '-' -f 1,2,3` > ".$file;
|
||||
$this->log("running new test");
|
||||
$this->log("file: ".$file);
|
||||
$this->log("first command: ".$firstcmd);
|
||||
$this->log("second command: ".$secondcmd);
|
||||
|
||||
$tsStart = time();
|
||||
|
||||
// run the 25MB download twice
|
||||
exec($firstcmd);
|
||||
exec($firstcmd);
|
||||
exec($secondcmd);
|
||||
|
||||
$tsTook = time() - $tsStart;
|
||||
|
||||
exec("echo took ".$tsTook." seconds >> ".$file);
|
||||
|
||||
return $this->getSpeedTestFile($file);
|
||||
}
|
||||
|
||||
//
|
||||
// getSpeedTestFile
|
||||
// this function will return the contents of a speed tests file
|
||||
//
|
||||
public function getSpeedTestFile($file)
|
||||
{
|
||||
$this->log("getSpeedTestFile");
|
||||
$this->log($file);
|
||||
|
||||
return file_get_contents($file);
|
||||
}
|
||||
|
||||
//
|
||||
// getSpeedTestFromFile
|
||||
// return the wget output associated with a speed test via file contents
|
||||
//
|
||||
public function getSpeedTestFromFile()
|
||||
{
|
||||
$this->log("requesting file");
|
||||
$this->log($this->request->file);
|
||||
|
||||
$this->makeSpeedTestsDir();
|
||||
$file = $this->touchSpeedTestFile($this->request->file);
|
||||
$output = $this->getSpeedTestFile($file);
|
||||
$this->response = $output;
|
||||
|
||||
$this->log($output);
|
||||
}
|
||||
|
||||
//
|
||||
// addToSpeedTestFile
|
||||
// this function will add the results of a speedtest to a file
|
||||
//
|
||||
public function addToSpeedTestFile($file)
|
||||
{
|
||||
exec("echo {$file} >> {$this->ALL_TESTS_FILE}");
|
||||
}
|
||||
|
||||
//
|
||||
// startSpeedTest
|
||||
// return the output of wget speed test
|
||||
//
|
||||
public function startSpeedTest()
|
||||
{
|
||||
$this->makeSpeedTestsDir();
|
||||
$file = "{$this->SPEED_TEST_DIR}/".date("d-m-Y-h-i-s")."-speedtest";
|
||||
$output = $this->runSpeedTest($file);
|
||||
|
||||
$this->addToSpeedTestFile($file);
|
||||
|
||||
$this->response = $output;
|
||||
}
|
||||
|
||||
//
|
||||
// getPreviousTests
|
||||
// return the tests file as an array
|
||||
//
|
||||
public function getPreviousTests()
|
||||
{
|
||||
|
||||
$this->makeSpeedTestsDir();
|
||||
$this->touchSpeedTestFile();
|
||||
|
||||
$this->response = array();
|
||||
|
||||
$lines = file($this->ALL_TESTS_FILE);
|
||||
foreach ($lines as $line)
|
||||
{
|
||||
array_push($this->response, $line);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
registerController("InternetSpeedTestController", ['$api', '$scope','$window','$route', '$http', function ($api, $scope, $window, $route, $http) {
|
||||
|
||||
/*
|
||||
* Author: trashbo4t (github.com/trashbo4t)
|
||||
*/
|
||||
getPreviousTests();
|
||||
|
||||
$scope.previous = [];
|
||||
$scope.previousDisplay = [];
|
||||
$scope.throbber = true;
|
||||
$scope.loading = "Running";
|
||||
$scope.working = "Running speed test...";
|
||||
$scope.library = true;
|
||||
$scope.currentSpeedTest = false;
|
||||
$scope.currentSpeedTestData = {};
|
||||
$scope.fileToLookup = "";
|
||||
|
||||
function getPreviousTests() {
|
||||
$api.request({
|
||||
module: "InternetSpeedTest",
|
||||
action: "getPreviousTests"
|
||||
}, function (response) {
|
||||
console.log("getPreviousTests", response);
|
||||
|
||||
for (var i = 0; i < response.length; i++)
|
||||
{
|
||||
var ok = $scope.previous.includes(response[i])
|
||||
if (!ok)
|
||||
{
|
||||
var res = response[i].split("/");
|
||||
$scope.previous.push(response[i]);
|
||||
var res2 = res[5].split("-speedtest");
|
||||
$scope.previousDisplay.push(res2[0]);
|
||||
}
|
||||
}
|
||||
|
||||
$scope.previousDisplay.reverse();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.reloadPage = function () {
|
||||
$api.request({
|
||||
module: "InternetSpeedTest",
|
||||
action: "clearLogFile",
|
||||
}, function (response) {
|
||||
});
|
||||
|
||||
$scope.currentSpeedTest = false;
|
||||
$window.location.reload()
|
||||
};
|
||||
|
||||
$scope.getSpeedTestFromFile = function (file) {
|
||||
file = file.replace(/(\r\n\t|\n|\r\t)/gm,"");
|
||||
$scope.fileToLookup = "/pineapple/modules/InternetSpeedTest/tests/"+file+"-speedtest";
|
||||
|
||||
console.log("getSpeedTestFromFile", "looking up speed test file " + $scope.fileToLookup);
|
||||
|
||||
$api.request({
|
||||
module: "InternetSpeedTest",
|
||||
action: "getSpeedTestFromFile",
|
||||
file: $scope.fileToLookup
|
||||
}, function (response) {
|
||||
$scope.currentSpeedTest = $scope.speedTestToLookup;
|
||||
|
||||
if (response == false)
|
||||
{
|
||||
$scope.currentSpeedTest = "Failed";
|
||||
$scope.currentSpeedTestData = "Invalid filename..";
|
||||
}
|
||||
else
|
||||
{
|
||||
$scope.currentSpeedTest = "Success";
|
||||
$scope.currentSpeedTestData = response;
|
||||
}
|
||||
|
||||
console.log("getSpeedTestFromFile response:", $scope.currentSpeedTestData);
|
||||
$scope.library = false;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.startSpeedTest = function () {
|
||||
$scope.loading = "Loading";
|
||||
$scope.working = "Your Internet Speed Test is running. Please be patient, this may take a minute to finish depending on your internet speed.";
|
||||
$scope.throbber = true;
|
||||
|
||||
console.log("startSpeedTest", "starting test...");
|
||||
|
||||
$api.request({
|
||||
module: "InternetSpeedTest",
|
||||
action: "startSpeedTest",
|
||||
}, function (response) {
|
||||
console.log("startSpeedTest", response);
|
||||
|
||||
$scope.currentSpeedTest = "";
|
||||
if (response == false)
|
||||
{
|
||||
$scope.currentSpeedTest = "Failed";
|
||||
$scope.currentSpeedTestData = "Test failed. Verify you are connected to the internet.";
|
||||
}
|
||||
else
|
||||
{
|
||||
$scope.currentSpeedTest = "Success";
|
||||
$scope.currentSpeedTestData = response;
|
||||
$scope.fileToLookup = "Running speed test";
|
||||
}
|
||||
|
||||
// fire up the throbber
|
||||
$scope.working = "click anywhere to continue";
|
||||
$scope.loading = "Done";
|
||||
$scope.library = false;
|
||||
$scope.throbber = false;
|
||||
});
|
||||
|
||||
};
|
||||
}]);
|
|
@ -0,0 +1,107 @@
|
|||
<!-- Author -->
|
||||
<!-- trashbo4t -->
|
||||
<!-- (github.com/trashbo4t) -->
|
||||
|
||||
<div class="row" ng-controller="InternetSpeedTestController">
|
||||
<div class="panel-group" id="accordion">
|
||||
<div class="col-md-9">
|
||||
|
||||
<!-- Library panel -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h5 class="panel-title"><a href="javascript:;" data-toggle="collapse" data-parent="#accordion" data-target="#collapseLibrary" class="text-muted">Internet Speed Test</a></h5>
|
||||
</div>
|
||||
|
||||
<div id="collapseLibrary" class="panel-collapse collapse in">
|
||||
<div class="panel-body">
|
||||
<div class="input-group" ng-show="currentSpeedTest == false">
|
||||
<span class="input-group-btn">
|
||||
<button ng-disabled="fileToLookup != ''"
|
||||
data-toggle="modal"
|
||||
data-target="#loadingModal"
|
||||
class="btn btn-default"
|
||||
type="button"
|
||||
ng-click="startSpeedTest()">Start Test
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<hr ng-show="currentSpeedTest == false"/>
|
||||
|
||||
<div ng-show="previous.length > 0 && currentSpeedTest == false">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped" align="center">
|
||||
<thead>
|
||||
<th>History</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="file in previousDisplay">
|
||||
<td>
|
||||
<a href="javascript:;" ng-click="getSpeedTestFromFile(file)">
|
||||
Speed Test: {{ file }} <b>(Click to view)</b>
|
||||
</a>
|
||||
</td>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-hide="previous.length != 0">
|
||||
<p class="text-muted text-center">
|
||||
<i>Looks like there are no tests to display...</i>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div ng-show="currentSpeedTest != false">
|
||||
<button type="submit" class="btn btn-default btn-sm" ng-click="reloadPage()">Back</button>
|
||||
<hr/>
|
||||
<h3>Internet Speed Test Result: {{ currentSpeedTest }}</h3>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped" align="center">
|
||||
<thead>
|
||||
<th>Information</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Result</td>
|
||||
<td> {{ currentSpeedTestData }} </td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tr>
|
||||
<td>
|
||||
</td>
|
||||
</tr>
|
||||
</tr>
|
||||
|
||||
<div class="modal-footer">
|
||||
</div>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--- Loading -->
|
||||
<div id="loadingModal" class="modal fade" role="dialog" >
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title"> {{ loading }} </h4>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
<div class="panel-title">
|
||||
<img src="/img/throbber.gif" ng-show="throbber" align="middle" class="center"/>
|
||||
<p><b>{{ working }}</b></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"author": "trashbo4t",
|
||||
"devices": [
|
||||
"nano",
|
||||
"tetra"
|
||||
],
|
||||
"title": "Internet Speed Test",
|
||||
"description": "Test the download and upload speed of the network shared to your pineapple",
|
||||
"version": "1.0"
|
||||
}
|
Loading…
Reference in New Issue