Detect ${OVER} and mirror its effect properly on the web interface

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2017-09-21 20:23:38 +02:00
parent bf29f8ebac
commit a18a45e6b8
2 changed files with 23 additions and 6 deletions

View File

@@ -16,15 +16,22 @@ header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
function echoEvent($datatext) {
echo "data: ".implode("\ndata: ", explode("\n", $datatext))."\n\n";
// Detect ${OVER} and replace it with something we can safely transmit
$datatext = str_replace("\r","<------",$datatext);
$pos = strpos($datatext,"<------");
// Detect if the ${OVER} line is within this line, e.g.
// "Pending: String to replace${OVER}Done: String has been replaced"
// If this is the case, we have to remove everything before ${OVER}
// and return only the text thereafter
if($pos !== false && $pos !== 0)
{
$datatext = substr($datatext, $pos);
}
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("***END***");
?>