Add blocking version of pihole.log tailing

This commit is contained in:
DL6ER
2016-12-23 12:49:54 +01:00
parent 2b2c3bbf27
commit 0656526d43
4 changed files with 75 additions and 0 deletions
+6
View File
@@ -353,6 +353,12 @@
<i class="fa fa-search"></i> <span>Query adlists</span>
</a>
</li>
<!-- Query adlists -->
<li>
<a href="taillog.php">
<i class="fa fa-list-ul"></i> <span>Tail pihole.log</span>
</a>
</li>
<!-- Toggle -->
<?php
if ($pistatus == "1") {
+30
View File
@@ -0,0 +1,30 @@
var source;
function eventsource() {
var ta = $("#output");
source = new EventSource("php/taillog.php");
ta.html("");
ta.show();
source.addEventListener("message", function(e) {
if(e.data.indexOf("Ctrl-C") === -1)
{
// Hide the "Press Ctrl-C to exit" message
ta.append(e.data);
}
}, false);
// Will be called when script has finished
source.addEventListener("error", function(e) {
source.close();
}, false);
}
$(function(){
eventsource();
});
$(window).unload(function(){
source.close();
});
+23
View File
@@ -0,0 +1,23 @@
<?php
require "password.php";
if(!$auth) die("Not authorized");
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 -t", 'r');
while (!feof($proc)) {
echoEvent(fread($proc, 4096));
}
// echoEvent("***END***");
?>
+16
View File
@@ -0,0 +1,16 @@
<?php
require "header.php";
?>
<!-- Title -->
<div class="page-header">
<h1>Output the last lines of the pihole.log file (live)</h1>
</div>
<pre id="output" style="width: 100%; height: 100%;" hidden="true"></pre>
<?php
require "footer.php";
?>
<script src="js/pihole/taillog.js"></script>