From 57600b0e22fa9557217b6a2a2d99aa55b1a89d61 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Thu, 18 May 2023 19:11:35 -0300 Subject: [PATCH 1/3] Tweak gravity to show the new parse list output Replaces every `\r` returned by `pihole-FTL gravity parseList` with a known string to allow overwriting the previous line. Signed-off-by: RD WebDesign --- scripts/pi-hole/php/gravity.sh.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/pi-hole/php/gravity.sh.php b/scripts/pi-hole/php/gravity.sh.php index e7c3323d..0abf5ec8 100644 --- a/scripts/pi-hole/php/gravity.sh.php +++ b/scripts/pi-hole/php/gravity.sh.php @@ -22,7 +22,14 @@ header('Cache-Control: no-cache'); function echoEvent($datatext) { // Detect ${OVER} and replace it with something we can safely transmit + // This allows every line (including progress and error messages) to be shown on the page + + // Replace "\r" (generated by gravity.sh) with "<------" $datatext = str_replace("\r", '<------', $datatext); + + // Replace "\r" generated by "pihole-FTL gravity parseList" command + $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" From e6cc0ef44f3e3157bf78d2f43f80d252d7f0d409 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Thu, 18 May 2023 19:59:10 -0300 Subject: [PATCH 2/3] Replace the character with the `\e` escape sequence Signed-off-by: RD WebDesign --- scripts/pi-hole/php/gravity.sh.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/pi-hole/php/gravity.sh.php b/scripts/pi-hole/php/gravity.sh.php index 0abf5ec8..cd24090a 100644 --- a/scripts/pi-hole/php/gravity.sh.php +++ b/scripts/pi-hole/php/gravity.sh.php @@ -24,8 +24,8 @@ function echoEvent($datatext) // Detect ${OVER} and replace it with something we can safely transmit // This allows every line (including progress and error messages) to be shown on the page - // Replace "\r" (generated by gravity.sh) with "<------" - $datatext = str_replace("\r", '<------', $datatext); + // Replace "\r\e[K" ("CR+ESC+[" generated by gravity.sh) with "<------" + $datatext = str_replace("\r\e[K", '<------', $datatext); // Replace "\r" generated by "pihole-FTL gravity parseList" command $datatext = str_replace("\r", '<------', $datatext); From ee2dfe317316d956314bda1576838389e57a3ed0 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Mon, 22 May 2023 22:49:52 -0300 Subject: [PATCH 3/3] Adding more detailed description to the function Signed-off-by: RD WebDesign --- scripts/pi-hole/php/gravity.sh.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/pi-hole/php/gravity.sh.php b/scripts/pi-hole/php/gravity.sh.php index cd24090a..44a747a6 100644 --- a/scripts/pi-hole/php/gravity.sh.php +++ b/scripts/pi-hole/php/gravity.sh.php @@ -21,20 +21,20 @@ header('Cache-Control: no-cache'); function echoEvent($datatext) { - // Detect ${OVER} and replace it with something we can safely transmit + // "pihole -g" command uses an escape sequence to allow overwriting lines = ${OVER} + // The ${OVER} sequence is a Carriage Return ("\r") followed by "ESC+[+K" ("\e[K") // This allows every line (including progress and error messages) to be shown on the page - // Replace "\r\e[K" ("CR+ESC+[" generated by gravity.sh) with "<------" + // Replace ${OVER} with something we can safely transmit and use on the javascript code $datatext = str_replace("\r\e[K", '<------', $datatext); // Replace "\r" generated by "pihole-FTL gravity parseList" command $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 the "<------" string is in the middle of the line we remove everything before it + // Example: "Pending: String to replace<------Done: String has been replaced" + // After replacing: "<------Done: String has been replaced" if ($pos !== false && $pos !== 0) { $datatext = substr($datatext, $pos); }