From 118db849ced6878d5b5ea4045ca9867b322441a5 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 14 Nov 2016 12:47:10 +0100 Subject: [PATCH 01/12] Add option to show *all* queries at once --- js/pihole/queries.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/js/pihole/queries.js b/js/pihole/queries.js index d13008dc..aadd3912 100644 --- a/js/pihole/queries.js +++ b/js/pihole/queries.js @@ -18,10 +18,11 @@ $(document).ready(function() { { "width" : "40%" }, { "width" : "15%" }, { "width" : "15%" } - ] + ], + "lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]], }) } ); function refreshData() { tableApi.ajax.url("api.php?getAllQueries").load(); -} \ No newline at end of file +} From 66e4da7724fab6399f3c3efbc74aace07e97a42f Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 18 Nov 2016 13:43:05 +0100 Subject: [PATCH 02/12] Run gravity.sh from the web UI --- gravity.php | 33 +++++++++++++++++++++++++++++++++ header.php | 6 ++++++ js/pihole/gravity.js | 34 ++++++++++++++++++++++++++++++++++ php/gravity.sh.php | 19 +++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 gravity.php create mode 100644 js/pihole/gravity.js create mode 100644 php/gravity.sh.php diff --git a/gravity.php b/gravity.php new file mode 100644 index 00000000..d33055af --- /dev/null +++ b/gravity.php @@ -0,0 +1,33 @@ + + + + + + + + + + + + +

+
+
+
+
+
diff --git a/header.php b/header.php
index b42815ca..4412914f 100644
--- a/header.php
+++ b/header.php
@@ -235,6 +235,12 @@
                          Blacklist
                     
                 
+                
+                
  • + + Update lists + +
  • Date: Fri, 18 Nov 2016 13:45:11 +0100 Subject: [PATCH 03/12] Minor change --- gravity.php | 4 ---- js/pihole/gravity.js | 5 +---- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/gravity.php b/gravity.php index d33055af..047b2f79 100644 --- a/gravity.php +++ b/gravity.php @@ -18,10 +18,6 @@ Success! -
    
     
    diff --git a/js/pihole/gravity.js b/js/pihole/gravity.js
    index e3ce2f68..307a060b 100644
    --- a/js/pihole/gravity.js
    +++ b/js/pihole/gravity.js
    @@ -1,13 +1,11 @@
     function eventsourcetest() {
         var alInfo = $("#alInfo");
         var alSuccess = $("#alSuccess");
    -    var alFailure = $("#alFailure");
         var ta = document.getElementById('output');
         var source = new EventSource('php/gravity.sh.php');
     
         alInfo.show();
         alSuccess.hide();
    -    alFailure.hide();
     
         source.addEventListener('message', function(e) {
             if(e.data == "START"){
    @@ -23,10 +21,9 @@ function eventsourcetest() {
             }
         }, false);
     
    +    // Will be called when script has finished
         source.addEventListener('error', function(e) {
             source.close();
    -        alFailure.show();
    -        alInfo.delay(5000).fadeOut(2000, function() { alInfo.hide(); });
         }, false);
     }
     $(function(){
    
    From d33d53792e16dff797855c12b61af42d55a46a49 Mon Sep 17 00:00:00 2001
    From: DL6ER 
    Date: Fri, 18 Nov 2016 13:46:38 +0100
    Subject: [PATCH 04/12] Reduce timeout for hiding the info box
    
    ---
     js/pihole/gravity.js | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/js/pihole/gravity.js b/js/pihole/gravity.js
    index 307a060b..87978b87 100644
    --- a/js/pihole/gravity.js
    +++ b/js/pihole/gravity.js
    @@ -13,7 +13,7 @@ function eventsourcetest() {
             }
             else if(e.data == "SUCCESS"){
                alSuccess.show();
    -           alInfo.delay(5000).fadeOut(2000, function() { alInfo.hide(); });
    +           alInfo.delay(1000).fadeOut(2000, function() { alInfo.hide(); });
             }
             else if (e.data !== '')
             {
    
    From f777ba6735b3e941e33c4a44b93f64cec19f744a Mon Sep 17 00:00:00 2001
    From: DL6ER 
    Date: Fri, 18 Nov 2016 13:56:13 +0100
    Subject: [PATCH 05/12] Fixed codacy issue.
    
    ---
     js/pihole/gravity.js | 16 ++++++++--------
     1 file changed, 8 insertions(+), 8 deletions(-)
    
    diff --git a/js/pihole/gravity.js b/js/pihole/gravity.js
    index 87978b87..0ca3da16 100644
    --- a/js/pihole/gravity.js
    +++ b/js/pihole/gravity.js
    @@ -1,28 +1,28 @@
     function eventsourcetest() {
         var alInfo = $("#alInfo");
         var alSuccess = $("#alSuccess");
    -    var ta = document.getElementById('output');
    -    var source = new EventSource('php/gravity.sh.php');
    +    var ta = document.getElementById("output");
    +    var source = new EventSource("php/gravity.sh.php");
     
    -    alInfo.show();
    +    alInfo.hide();
         alSuccess.hide();
     
    -    source.addEventListener('message', function(e) {
    -        if(e.data == "START"){
    +    source.addEventListener("message", function(e) {
    +        if(e.data === "START"){
                alInfo.show();
             }
    -        else if(e.data == "SUCCESS"){
    +        else if(e.data === "SUCCESS"){
                alSuccess.show();
                alInfo.delay(1000).fadeOut(2000, function() { alInfo.hide(); });
             }
    -        else if (e.data !== '')
    +        else if (e.data !== "")
             {
                 ta.innerHTML += e.data;
             }
         }, false);
     
         // Will be called when script has finished
    -    source.addEventListener('error', function(e) {
    +    source.addEventListener("error", function(e) {
             source.close();
         }, false);
     }
    
    From f9b6d4d887203d3871d9dd45427428ae73f5833d Mon Sep 17 00:00:00 2001
    From: DL6ER 
    Date: Fri, 18 Nov 2016 15:04:46 +0100
    Subject: [PATCH 06/12] Make sure that the green "Success" box is only shown if
     gravity.sh returned "Pi-hole blocking is Enabled"
    
    ---
     js/pihole/gravity.js | 9 ++++++---
     php/gravity.sh.php   | 4 ++--
     2 files changed, 8 insertions(+), 5 deletions(-)
    
    diff --git a/js/pihole/gravity.js b/js/pihole/gravity.js
    index 0ca3da16..6ee2c2e0 100644
    --- a/js/pihole/gravity.js
    +++ b/js/pihole/gravity.js
    @@ -8,16 +8,19 @@ function eventsourcetest() {
         alSuccess.hide();
     
         source.addEventListener("message", function(e) {
    -        if(e.data === "START"){
    +        if(e.data === "***START***"){
                alInfo.show();
             }
    -        else if(e.data === "SUCCESS"){
    -           alSuccess.show();
    +        else if(e.data === "***END***"){
                alInfo.delay(1000).fadeOut(2000, function() { alInfo.hide(); });
             }
             else if (e.data !== "")
             {
                 ta.innerHTML += e.data;
    +            if(e.data.indexOf("Pi-hole blocking is Enabled") !== -1)
    +            {
    +                alSuccess.show();
    +            }
             }
         }, false);
     
    diff --git a/php/gravity.sh.php b/php/gravity.sh.php
    index f55a049a..553a579f 100644
    --- a/php/gravity.sh.php
    +++ b/php/gravity.sh.php
    @@ -9,11 +9,11 @@ function echoEvent($datatext) {
         echo "data: ".implode("\ndata: ", explode("\n", $datatext))."\n\n";
     }
     
    -echoEvent("START");
    +echoEvent("***START***");
     
     $proc = popen("sudo pihole -g", 'r');
     while (!feof($proc)) {
         echoEvent(fread($proc, 4096));
     }
     
    -echoEvent("SUCCESS");
    +echoEvent("***END***");
    
    From 8ce32d2ee2eda5a278593d9f61192ede2998a893 Mon Sep 17 00:00:00 2001
    From: DL6ER 
    Date: Fri, 18 Nov 2016 15:11:55 +0100
    Subject: [PATCH 07/12] Reduce complexity of code as requested by codacy...
    
    ---
     js/pihole/gravity.js | 17 +++++++++++++----
     1 file changed, 13 insertions(+), 4 deletions(-)
    
    diff --git a/js/pihole/gravity.js b/js/pihole/gravity.js
    index 6ee2c2e0..b04f5c5f 100644
    --- a/js/pihole/gravity.js
    +++ b/js/pihole/gravity.js
    @@ -14,13 +14,14 @@ function eventsourcetest() {
             else if(e.data === "***END***"){
                alInfo.delay(1000).fadeOut(2000, function() { alInfo.hide(); });
             }
    +        else if(e.data.indexOf("Pi-hole blocking is Enabled") !== -1)
    +        {
    +            alSuccess.show();
    +            ta.innerHTML += e.data;
    +        }
             else if (e.data !== "")
             {
                 ta.innerHTML += e.data;
    -            if(e.data.indexOf("Pi-hole blocking is Enabled") !== -1)
    -            {
    -                alSuccess.show();
    -            }
             }
         }, false);
     
    @@ -29,6 +30,14 @@ function eventsourcetest() {
             source.close();
         }, false);
     }
    +
     $(function(){
        eventsourcetest();
     });
    +
    +// Handle hiding of alerts
    +$(function(){
    +    $("[data-hide]").on("click", function(){
    +        $(this).closest("." + $(this).attr("data-hide")).hide();
    +    });
    +});
    
    From 7a1652c9593bc71de68f52491a277a41f9e23dfb Mon Sep 17 00:00:00 2001
    From: DL6ER 
    Date: Fri, 18 Nov 2016 15:18:15 +0100
    Subject: [PATCH 08/12] Trying one more to satisfy codacy
    
    ---
     js/pihole/gravity.js | 10 +++++-----
     1 file changed, 5 insertions(+), 5 deletions(-)
    
    diff --git a/js/pihole/gravity.js b/js/pihole/gravity.js
    index b04f5c5f..3fee4fdf 100644
    --- a/js/pihole/gravity.js
    +++ b/js/pihole/gravity.js
    @@ -14,15 +14,15 @@ function eventsourcetest() {
             else if(e.data === "***END***"){
                alInfo.delay(1000).fadeOut(2000, function() { alInfo.hide(); });
             }
    -        else if(e.data.indexOf("Pi-hole blocking is Enabled") !== -1)
    -        {
    -            alSuccess.show();
    -            ta.innerHTML += e.data;
    -        }
             else if (e.data !== "")
             {
                 ta.innerHTML += e.data;
             }
    +
    +        if(e.data.indexOf("Pi-hole blocking is Enabled") !== -1)
    +        {
    +            alSuccess.show();
    +        }
         }, false);
     
         // Will be called when script has finished
    
    From ba811544f8f7f1e5063232cca536aa4bff8893b9 Mon Sep 17 00:00:00 2001
    From: DL6ER 
    Date: Fri, 18 Nov 2016 15:25:32 +0100
    Subject: [PATCH 09/12] Okay, once more ...
    
    ---
     js/pihole/gravity.js | 17 +++++------------
     php/gravity.sh.php   |  5 +++--
     2 files changed, 8 insertions(+), 14 deletions(-)
    
    diff --git a/js/pihole/gravity.js b/js/pihole/gravity.js
    index 3fee4fdf..90b7d708 100644
    --- a/js/pihole/gravity.js
    +++ b/js/pihole/gravity.js
    @@ -4,25 +4,18 @@ function eventsourcetest() {
         var ta = document.getElementById("output");
         var source = new EventSource("php/gravity.sh.php");
     
    -    alInfo.hide();
    +    alInfo.show();
         alSuccess.hide();
     
         source.addEventListener("message", function(e) {
    -        if(e.data === "***START***"){
    -           alInfo.show();
    -        }
    -        else if(e.data === "***END***"){
    -           alInfo.delay(1000).fadeOut(2000, function() { alInfo.hide(); });
    -        }
    -        else if (e.data !== "")
    -        {
    -            ta.innerHTML += e.data;
    -        }
    -
             if(e.data.indexOf("Pi-hole blocking is Enabled") !== -1)
             {
                 alSuccess.show();
    +            alInfo.delay(1000).fadeOut(2000, function() { alInfo.hide(); });
             }
    +
    +        ta.innerHTML += e.data;
    +
         }, false);
     
         // Will be called when script has finished
    diff --git a/php/gravity.sh.php b/php/gravity.sh.php
    index 553a579f..80dcb385 100644
    --- a/php/gravity.sh.php
    +++ b/php/gravity.sh.php
    @@ -9,11 +9,12 @@ function echoEvent($datatext) {
         echo "data: ".implode("\ndata: ", explode("\n", $datatext))."\n\n";
     }
     
    -echoEvent("***START***");
    +// echoEvent("***START***");
     
     $proc = popen("sudo pihole -g", 'r');
     while (!feof($proc)) {
         echoEvent(fread($proc, 4096));
     }
     
    -echoEvent("***END***");
    +// echoEvent("***END***");
    +?>
    
    From 2b1c9b9f75317961c50a2f354a4782605edf76d1 Mon Sep 17 00:00:00 2001
    From: DL6ER 
    Date: Fri, 18 Nov 2016 15:29:22 +0100
    Subject: [PATCH 10/12] Removed (currently) unset token field
    
    ---
     gravity.php | 3 ---
     1 file changed, 3 deletions(-)
    
    diff --git a/gravity.php b/gravity.php
    index 047b2f79..ee606d56 100644
    --- a/gravity.php
    +++ b/gravity.php
    @@ -1,9 +1,6 @@
     
    -
    -
    -