Add colors to debug log

- Add function and CSS to show colorful debug log
- Adjusts to #output element

Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
This commit is contained in:
RD WebDesign
2022-03-11 20:08:47 -03:00
parent fa2df45ba6
commit ea24655a7b
6 changed files with 141 additions and 16 deletions
+34 -13
View File
@@ -8,7 +8,7 @@ header('Cache-Control: no-cache');
require "password.php";
require "auth.php";
if(!$auth) {
if (!$auth) {
die("Unauthorized");
}
@@ -18,22 +18,43 @@ $token = isset($_GET["token"]) ? $_GET["token"] : "";
check_csrf($token);
function echoEvent($datatext) {
$data = htmlspecialchars($datatext);
$ANSIcolors = array(
chr(27)."[1;91m" => '<span class="log-red">',
chr(27)."[1;32m" => '<span class="log-green">',
chr(27)."[1;33m" => '<span class="log-yellow">',
chr(27)."[1;34m" => '<span class="log-blue">',
chr(27)."[1;35m" => '<span class="log-purple">',
chr(27)."[1;36m" => '<span class="log-cyan">',
if(!isset($_GET["IE"]))
echo "data: ".implode("\ndata: ", explode("\n", $data))."\n\n";
else
echo $data;
chr(27)."[90m" => '<span class="log-gray">',
chr(27)."[91m" => '<span class="log-red">',
chr(27)."[32m" => '<span class="log-green">',
chr(27)."[33m" => '<span class="log-yellow">',
chr(27)."[94m" => '<span class="log-blue">',
chr(27)."[95m" => '<span class="log-purple">',
chr(27)."[96m" => '<span class="log-cyan">',
chr(27)."[1m" => '<span class="text-bold">',
chr(27)."[4m" => '<span class="text-underline">',
chr(27)."[0m" => '</span>',
);
$data = str_replace(array_keys($ANSIcolors), $ANSIcolors, htmlspecialchars($datatext));
if (!isset($_GET["IE"])) {
echo "data: ".implode("\ndata: ", explode("\n", $data))."\n\n";
} else {
echo $data;
}
}
if(isset($_GET["upload"]))
{
$proc = popen("sudo pihole -d -a -w", "r");
}
else
{
$proc = popen("sudo pihole -d -w", "r");
if (isset($_GET["upload"])) {
$proc = popen("sudo pihole -d -a -w", "r");
} else {
$proc = popen("sudo pihole -d -w", "r");
}
while (!feof($proc)) {
echoEvent(fread($proc, 4096));
}