Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak the Update Gravity output #2589

Merged
merged 3 commits into from
May 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions scripts/pi-hole/php/gravity.sh.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@

function echoEvent($datatext)
{
// Detect ${OVER} and replace it with something we can safely transmit
$datatext = str_replace("\r", '<------', $datatext);
// "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 ${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);
}
Expand Down