Run gravity.sh from the web UI

This commit is contained in:
DL6ER
2016-11-18 13:43:05 +01:00
parent d3fce57e58
commit 66e4da7724
4 changed files with 92 additions and 0 deletions

33
gravity.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
require "header.php";
?>
<!-- Send PHP info to JS -->
<div id="token" hidden><?php echo $token ?></div>
<!-- Title -->
<div class="page-header">
<h1>Update list of ad-serving domains</h1>
</div>
<!-- Alerts -->
<div id="alInfo" class="alert alert-info alert-dismissible fade in" role="alert" hidden="true">
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
Updating...
</div>
<div id="alSuccess" class="alert alert-success alert-dismissible fade in" role="alert" hidden="true">
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
Success!
</div>
<div id="alFailure" class="alert alert-danger alert-dismissible fade in" role="alert" hidden="true">
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
Failure! Something went wrong.
</div>
<pre id="output" style="width: 100%; height: 100%;"></pre>
<?php
require "footer.php";
?>
<script src="js/pihole/gravity.js"></script>

View File

@@ -235,6 +235,12 @@
<i class="fa fa-ban"></i> <span>Blacklist</span>
</a>
</li>
<!-- Run gravity.sh -->
<li>
<a href="gravity.php">
<i class="fa fa-arrow-circle-down"></i> <span>Update lists</span>
</a>
</li>
<!-- Toggle -->
<?php
if ($pistatus == "1") {

34
js/pihole/gravity.js Normal file
View File

@@ -0,0 +1,34 @@
function eventsourcetest() {
var alInfo = $("#alInfo");
var alSuccess = $("#alSuccess");
var alFailure = $("#alFailure");
var ta = document.getElementById('output');
var source = new EventSource('php/gravity.sh.php');
alInfo.show();
alSuccess.hide();
alFailure.hide();
source.addEventListener('message', function(e) {
if(e.data == "START"){
alInfo.show();
}
else if(e.data == "SUCCESS"){
alSuccess.show();
alInfo.delay(5000).fadeOut(2000, function() { alInfo.hide(); });
}
else if (e.data !== '')
{
ta.innerHTML += e.data;
}
}, false);
source.addEventListener('error', function(e) {
source.close();
alFailure.show();
alInfo.delay(5000).fadeOut(2000, function() { alInfo.hide(); });
}, false);
}
$(function(){
eventsourcetest();
});

19
php/gravity.sh.php Normal file
View File

@@ -0,0 +1,19 @@
<?php
ob_end_flush();
ini_set("output_buffering", "0");
ob_implicit_flush(true);
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
function echoEvent($datatext) {
echo "data: ".implode("\ndata: ", explode("\n", $datatext))."\n\n";
}
echoEvent("START");
$proc = popen("sudo pihole -g", 'r');
while (!feof($proc)) {
echoEvent(fread($proc, 4096));
}
echoEvent("SUCCESS");