From 9765b38ec2c768c65ef71f7ea36caff48d10d4d9 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 10 Feb 2017 12:22:59 +0100 Subject: [PATCH 1/8] Added online debug log creator --- debug.php | 17 +++++++++ scripts/pi-hole/js/debug.js | 64 ++++++++++++++++++++++++++++++++++ scripts/pi-hole/php/debug.php | 19 ++++++++++ scripts/pi-hole/php/header.php | 8 ++++- 4 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 debug.php create mode 100644 scripts/pi-hole/js/debug.js create mode 100644 scripts/pi-hole/php/debug.php diff --git a/debug.php b/debug.php new file mode 100644 index 00000000..90139a0a --- /dev/null +++ b/debug.php @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/scripts/pi-hole/js/debug.js b/scripts/pi-hole/js/debug.js new file mode 100644 index 00000000..51c7d334 --- /dev/null +++ b/scripts/pi-hole/js/debug.js @@ -0,0 +1,64 @@ +// Credit: http://stackoverflow.com/a/10642418/2087442 +function httpGet(ta,quiet,theUrl) +{ + var xmlhttp; + if (window.XMLHttpRequest) + { + // code for IE7+ + xmlhttp = new XMLHttpRequest(); + } + else + { + // code for IE6, IE5 + xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); + } + xmlhttp.onreadystatechange=function() + { + if (xmlhttp.readyState === 4 && xmlhttp.status === 200) + { + ta.show(); + ta.empty(); + if(!quiet) + { + ta.append(xmlhttp.responseText); + } + else + { + quietfilter(ta,xmlhttp.responseText); + } + } + }; + xmlhttp.open("GET", theUrl, false); + xmlhttp.send(); +} + +function eventsource() { + var ta = $("#output"); + + // IE does not support EventSource - load whole content at once + if (typeof EventSource !== "function") { + httpGet(ta,quiet,"/admin/scripts/pi-hole/php/debug.php"); + return; + } + + var host = window.location.host; + var source = new EventSource("/admin/scripts/pi-hole/php/debug.php"); + + // Reset and show field + ta.empty(); + ta.show(); + + source.addEventListener("message", function(e) { + ta.append(e.data); + }, false); + + // Will be called when script has finished + source.addEventListener("error", function(e) { + source.close(); + }, false); +} + +$("#debugBtn").on("click", function(){ + $("#debugBtn").attr("disabled", true); + eventsource(); +}); diff --git a/scripts/pi-hole/php/debug.php b/scripts/pi-hole/php/debug.php new file mode 100644 index 00000000..d57fddae --- /dev/null +++ b/scripts/pi-hole/php/debug.php @@ -0,0 +1,19 @@ + diff --git a/scripts/pi-hole/php/header.php b/scripts/pi-hole/php/header.php index 91a56f7d..85c6a276 100644 --- a/scripts/pi-hole/php/header.php +++ b/scripts/pi-hole/php/header.php @@ -405,7 +405,7 @@ Enable    -
  • active"> +
  • active"> Tools @@ -431,6 +431,12 @@ Tail pihole.log
  • + + class="active"> + + Generate debug log + + From cc13cf5e33d1cb21e96efe1ddbdb6742a9d27121 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 10 Feb 2017 12:26:20 +0100 Subject: [PATCH 2/8] Internet explorer + Windows Edge compatibility --- scripts/pi-hole/js/debug.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pi-hole/js/debug.js b/scripts/pi-hole/js/debug.js index 51c7d334..15a2521b 100644 --- a/scripts/pi-hole/js/debug.js +++ b/scripts/pi-hole/js/debug.js @@ -37,7 +37,7 @@ function eventsource() { // IE does not support EventSource - load whole content at once if (typeof EventSource !== "function") { - httpGet(ta,quiet,"/admin/scripts/pi-hole/php/debug.php"); + httpGet(ta,quiet,"/admin/scripts/pi-hole/php/debug.php?IE"); return; } From d4fa69afaf3ae0fb84ba5d87c4d27b2fe08c3843 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 10 Feb 2017 16:42:28 +0100 Subject: [PATCH 3/8] Add notice that we are going to automatically upload the log once the user clicks on the big button --- debug.php | 1 + 1 file changed, 1 insertion(+) diff --git a/debug.php b/debug.php index 90139a0a..e148c033 100644 --- a/debug.php +++ b/debug.php @@ -6,6 +6,7 @@

    Generate debug log

    +

    Once you click this button a debug log will be generated and automatically uploaded if we detect a working internet connection

    From 4cc917dd91c62f9313fc24e34db30886aa349e6c Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 22 Feb 2017 15:07:02 +0100 Subject: [PATCH 4/8] Codacy --- scripts/pi-hole/js/debug.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/scripts/pi-hole/js/debug.js b/scripts/pi-hole/js/debug.js index 15a2521b..dbdadb79 100644 --- a/scripts/pi-hole/js/debug.js +++ b/scripts/pi-hole/js/debug.js @@ -1,5 +1,5 @@ // Credit: http://stackoverflow.com/a/10642418/2087442 -function httpGet(ta,quiet,theUrl) +function httpGet(ta,theUrl) { var xmlhttp; if (window.XMLHttpRequest) @@ -18,14 +18,7 @@ function httpGet(ta,quiet,theUrl) { ta.show(); ta.empty(); - if(!quiet) - { - ta.append(xmlhttp.responseText); - } - else - { - quietfilter(ta,xmlhttp.responseText); - } + ta.append(xmlhttp.responseText); } }; xmlhttp.open("GET", theUrl, false); From 71672319af81472eb575463d2319824c8de50b39 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 22 Feb 2017 18:07:12 +0100 Subject: [PATCH 5/8] Another codacy commit --- scripts/pi-hole/js/debug.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pi-hole/js/debug.js b/scripts/pi-hole/js/debug.js index dbdadb79..c529f2f7 100644 --- a/scripts/pi-hole/js/debug.js +++ b/scripts/pi-hole/js/debug.js @@ -30,7 +30,7 @@ function eventsource() { // IE does not support EventSource - load whole content at once if (typeof EventSource !== "function") { - httpGet(ta,quiet,"/admin/scripts/pi-hole/php/debug.php?IE"); + httpGet(ta,"/admin/scripts/pi-hole/php/debug.php?IE"); return; } From 20ce214c9f06483d65a8d7ec9871efd85269f8df Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 22 Feb 2017 19:47:58 +0100 Subject: [PATCH 6/8] Add checkbox if the user wants his debug log to be uploaded automatically --- debug.php | 3 ++- scripts/pi-hole/js/debug.js | 11 +++++++++-- scripts/pi-hole/php/debug.php | 9 ++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/debug.php b/debug.php index e148c033..84416cff 100644 --- a/debug.php +++ b/debug.php @@ -6,7 +6,8 @@

    Generate debug log

    -

    Once you click this button a debug log will be generated and automatically uploaded if we detect a working internet connection

    +

    Upload debug log and provide token once finished

    +

    Once you click this button a debug log will be generated and can automatically be uploaded if we detect a working internet connection.

    diff --git a/scripts/pi-hole/js/debug.js b/scripts/pi-hole/js/debug.js index c529f2f7..6508dfbe 100644 --- a/scripts/pi-hole/js/debug.js +++ b/scripts/pi-hole/js/debug.js @@ -27,15 +27,22 @@ function httpGet(ta,theUrl) function eventsource() { var ta = $("#output"); + var upload = $( "#upload" ); + var checked = ""; + + if(upload.prop("checked")) + { + checked = "upload"; + } // IE does not support EventSource - load whole content at once if (typeof EventSource !== "function") { - httpGet(ta,"/admin/scripts/pi-hole/php/debug.php?IE"); + httpGet(ta,"/admin/scripts/pi-hole/php/debug.php?IE&"+checked); return; } var host = window.location.host; - var source = new EventSource("/admin/scripts/pi-hole/php/debug.php"); + var source = new EventSource("/admin/scripts/pi-hole/php/debug.php?"+checked); // Reset and show field ta.empty(); diff --git a/scripts/pi-hole/php/debug.php b/scripts/pi-hole/php/debug.php index d57fddae..996966a7 100644 --- a/scripts/pi-hole/php/debug.php +++ b/scripts/pi-hole/php/debug.php @@ -12,7 +12,14 @@ function echoEvent($datatext) { echo $datatext; } -$proc = popen("sudo pihole -d -a", "r"); +if(isset($_GET["upload"])) +{ + $proc = popen("sudo pihole -d -a", "r"); +} +else +{ + $proc = popen("sudo pihole -d", "r"); +} while (!feof($proc)) { echoEvent(fread($proc, 4096)); } From ab974f3f03475e14e7ee48b408b8d9570abc350b Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 23 Feb 2017 12:22:03 +0100 Subject: [PATCH 7/8] Disable checkbox after starting generation of debug log since the action can not be changed afterwards --- scripts/pi-hole/js/debug.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/pi-hole/js/debug.js b/scripts/pi-hole/js/debug.js index 6508dfbe..c0db2ce0 100644 --- a/scripts/pi-hole/js/debug.js +++ b/scripts/pi-hole/js/debug.js @@ -60,5 +60,6 @@ function eventsource() { $("#debugBtn").on("click", function(){ $("#debugBtn").attr("disabled", true); + $("#upload").attr("disabled", true); eventsource(); }); From 5a1939497703112d93a2d484b66681b39604bb20 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 27 Feb 2017 11:12:18 -0800 Subject: [PATCH 8/8] Add undocumented -w flag to alter the countdown behavior. Signed-off-by: Dan Schaper --- scripts/pi-hole/php/debug.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/pi-hole/php/debug.php b/scripts/pi-hole/php/debug.php index 996966a7..93ae3166 100644 --- a/scripts/pi-hole/php/debug.php +++ b/scripts/pi-hole/php/debug.php @@ -14,11 +14,11 @@ function echoEvent($datatext) { if(isset($_GET["upload"])) { - $proc = popen("sudo pihole -d -a", "r"); + $proc = popen("sudo pihole -d -a -w", "r"); } else { - $proc = popen("sudo pihole -d", "r"); + $proc = popen("sudo pihole -d -w", "r"); } while (!feof($proc)) { echoEvent(fread($proc, 4096));