From 8080afadaccf0bbe409f3b2c6bdfe8f3d3d18ade Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 31 Dec 2016 15:36:47 +0000 Subject: [PATCH 01/79] Make ADD, SUB and GET compatible with the wildcard blocking list --- scripts/pi-hole/php/add.php | 3 ++ scripts/pi-hole/php/get.php | 56 +++++++++++++++++++++++++++++-------- scripts/pi-hole/php/sub.php | 3 ++ 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/scripts/pi-hole/php/add.php b/scripts/pi-hole/php/add.php index ffffccec..62c930ef 100644 --- a/scripts/pi-hole/php/add.php +++ b/scripts/pi-hole/php/add.php @@ -13,6 +13,9 @@ switch($type) { case "black": echo exec("sudo pihole -b -q ${_POST['domain']}"); break; + case "wild": + echo exec("sudo pihole -wild -q ${_POST['domain']}"); + break; } ?> diff --git a/scripts/pi-hole/php/get.php b/scripts/pi-hole/php/get.php index fada75b9..41bfe56b 100644 --- a/scripts/pi-hole/php/get.php +++ b/scripts/pi-hole/php/get.php @@ -1,21 +1,55 @@ = 0; $i--) { + if($list[$i] == "") + unset($list[$i]); + } + + return $list; + +} + +function getWildcardListContent() { + $rawList = file_get_contents(checkfile("/etc/dnsmasq.d/03-pihole-wildcard.conf")); + $wclist = explode("\n", $rawList); + $list = []; + + foreach ($wclist as $entry) { + $expl = explode("/", $entry); + if(count($expl) == 3) + { + array_push($list,"*${expl[1]}*"); + } + } + + return array_unique($list); -// Get rid of empty lines -for($i = sizeof($list)-1; $i >= 0; $i--) { - if($list[$i] == "") - unset($list[$i]); } function filterArray(&$inArray) { diff --git a/scripts/pi-hole/php/sub.php b/scripts/pi-hole/php/sub.php index fb670f3a..e09f2d0a 100644 --- a/scripts/pi-hole/php/sub.php +++ b/scripts/pi-hole/php/sub.php @@ -13,6 +13,9 @@ switch($type) { case "black": exec("sudo pihole -b -q -d ${_POST['domain']}"); break; + case "wild": + exec("sudo pihole -wild -q -d ${_POST['domain']}"); + break; } ?> From 754fa117ec0d627a758cac2dc30acd7f86892532 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 31 Dec 2016 15:45:12 +0000 Subject: [PATCH 02/79] Detect if wildcard blocking entry on Blacklists page --- scripts/pi-hole/js/list.js | 19 ++++++++++++++++--- scripts/pi-hole/php/get.php | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/pi-hole/js/list.js b/scripts/pi-hole/js/list.js index de2692ad..62a84313 100644 --- a/scripts/pi-hole/js/list.js +++ b/scripts/pi-hole/js/list.js @@ -43,11 +43,24 @@ function refresh(fade) { } else { data.forEach(function (entry, index) { - list.append( + if(entry.substr(0,1) === "*") + { + // Wildcard entry + // remove leading * + entry = entry.substr(1, entry.length - 1); + list.append( "
  • " + entry + "
  • " - ); + ""); + } + else + { + // Normal entry + list.append( + "
  • " + entry + + "
  • "); + } // Handle button $("#list #"+index+"").on("click", "button", function() { diff --git a/scripts/pi-hole/php/get.php b/scripts/pi-hole/php/get.php index 41bfe56b..8bf28fb2 100644 --- a/scripts/pi-hole/php/get.php +++ b/scripts/pi-hole/php/get.php @@ -44,7 +44,7 @@ function getWildcardListContent() { $expl = explode("/", $entry); if(count($expl) == 3) { - array_push($list,"*${expl[1]}*"); + array_push($list,"*${expl[1]}"); } } From 05f2df720e106f8359274796b2c06200f1049e32 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 31 Dec 2016 16:06:21 +0000 Subject: [PATCH 03/79] Put wildcard blocking entries into their own table --- list.php | 5 +++++ scripts/pi-hole/js/list.js | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/list.php b/list.php index dc8097c1..266a5b7f 100644 --- a/list.php +++ b/list.php @@ -49,7 +49,12 @@ function getFullName() { +

    Exactl blocking

      + +

      Wildcard blocking

      +
        + " + entry + ""); From a33301911abb3b57c91927b462bb6544ac8eda67 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 31 Dec 2016 16:24:10 +0000 Subject: [PATCH 04/79] Made everything working --- list.php | 10 ++++++- scripts/pi-hole/js/list.js | 54 ++++++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/list.php b/list.php index 266a5b7f..9d030936 100644 --- a/list.php +++ b/list.php @@ -29,8 +29,14 @@ function getFullName() {
        + + + + + + }
        @@ -49,7 +55,9 @@ function getFullName() { -

        Exactl blocking

        + +

        Exact blocking

        +

          Wildcard blocking

          diff --git a/scripts/pi-hole/js/list.js b/scripts/pi-hole/js/list.js index fc3ef773..bbb5cb60 100644 --- a/scripts/pi-hole/js/list.js +++ b/scripts/pi-hole/js/list.js @@ -6,13 +6,18 @@ var token = $("#token").html(); var listType = $("#list-type").html(); var fullName = listType === "white" ? "Whitelist" : "Blacklist"; -function sub(index, entry) { +function sub(index, entry, arg) { var domain = $("#"+index); + var locallistType = listType; domain.hide("highlight"); + if(arg === "wild") + { + locallistType = "wild"; + } $.ajax({ url: "scripts/pi-hole/php/sub.php", method: "post", - data: {"domain":entry, "list":listType, "token":token}, + data: {"domain":entry, "list":locallistType, "token":token}, success: function(response) { if(response.length !== 0){ return; @@ -34,6 +39,10 @@ function refresh(fade) { } if(fade) { list.fadeOut(100); + if(listw) + { + listw.fadeOut(100); + } } $.ajax({ url: "scripts/pi-hole/php/get.php", @@ -41,6 +50,10 @@ function refresh(fade) { data: {"list":listType}, success: function(response) { list.html(""); + if(listw) + { + listw.html(""); + } var data = JSON.parse(response); if(data.length === 0) { @@ -57,6 +70,11 @@ function refresh(fade) { "
        • " + entry + "
        • "); + // Handle button + $("#list-wildcard #"+index+"").on("click", "button", function() { + sub(index, entry, "wild"); + console.log("wild rm"); + }); } else { @@ -65,15 +83,19 @@ function refresh(fade) { "
        • " + entry + "
        • "); + // Handle button + $("#list #"+index+"").on("click", "button", function() { + sub(index, entry, "exact"); + }); } - // Handle button - $("#list #"+index+"").on("click", "button", function() { - sub(index, entry); - }); }); } - list.fadeIn("fast"); + list.fadeIn(100); + if(listw) + { + listw.fadeIn(100); + } }, error: function(jqXHR, exception) { $("#alFailure").show(); @@ -83,11 +105,16 @@ function refresh(fade) { window.onload = refresh(false); -function add() { +function add(arg) { + var locallistType = listType; var domain = $("#domain"); if(domain.val().length === 0){ return; } + if(arg === "wild") + { + locallistType = "wild"; + } var alInfo = $("#alInfo"); var alSuccess = $("#alSuccess"); @@ -98,7 +125,7 @@ function add() { $.ajax({ url: "scripts/pi-hole/php/add.php", method: "post", - data: {"domain":domain.val(), "list":listType, "token":token}, + data: {"domain":domain.val(), "list":locallistType, "token":token}, success: function(response) { if (response.indexOf("not a valid argument") >= 0 || response.indexOf("is not a valid domain") >= 0) { @@ -139,14 +166,19 @@ function add() { $(document).keypress(function(e) { if(e.which === 13 && $("#domain").is(":focus")) { // Enter was pressed, and the input has focus - add(); + add("exact"); } }); // Handle buttons $("#btnAdd").on("click", function() { - add(); + add("exact"); }); + +$("#btnAddWildcard").on("click", function() { + add("wild"); +}); + $("#btnRefresh").on("click", function() { refresh(true); }); From c409cf20bfb79439c8a9dabe894325a1a58d2654 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 31 Dec 2016 16:35:16 +0000 Subject: [PATCH 05/79] Hide h3 headings if list is empty --- scripts/pi-hole/js/list.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/pi-hole/js/list.js b/scripts/pi-hole/js/list.js index bbb5cb60..b3b82955 100644 --- a/scripts/pi-hole/js/list.js +++ b/scripts/pi-hole/js/list.js @@ -57,6 +57,7 @@ function refresh(fade) { var data = JSON.parse(response); if(data.length === 0) { + $("h3").hide(); list.html("
          Your " + fullName + " is empty!
          "); } else { From 33714c540c8c10d7e62fa5c903e160869cc1fed9 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 31 Dec 2016 16:44:03 +0000 Subject: [PATCH 06/79] codacy fixes --- scripts/pi-hole/js/list.js | 10 ++++++++-- scripts/pi-hole/php/get.php | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/pi-hole/js/list.js b/scripts/pi-hole/js/list.js index b3b82955..ea9e5f44 100644 --- a/scripts/pi-hole/js/list.js +++ b/scripts/pi-hole/js/list.js @@ -58,7 +58,14 @@ function refresh(fade) { if(data.length === 0) { $("h3").hide(); - list.html("
          Your " + fullName + " is empty!
          "); + if(listw) + { + listw.html("
          Your " + fullName + " is empty!
          "); + } + else + { + list.html("
          Your " + fullName + " is empty!
          "); + } } else { data.forEach(function (entry, index) { @@ -74,7 +81,6 @@ function refresh(fade) { // Handle button $("#list-wildcard #"+index+"").on("click", "button", function() { sub(index, entry, "wild"); - console.log("wild rm"); }); } else diff --git a/scripts/pi-hole/php/get.php b/scripts/pi-hole/php/get.php index 8bf28fb2..043c8b87 100644 --- a/scripts/pi-hole/php/get.php +++ b/scripts/pi-hole/php/get.php @@ -22,7 +22,7 @@ switch ($listtype) { function getListContent($type) { - $rawList = file_get_contents(checkfile("/etc/pihole/${type}list.txt")); + $rawList = file_get_contents(checkfile("/etc/pihole/".$type."list.txt")); $list = explode("\n", $rawList); // Get rid of empty lines From 28bea42f8899f22a1cffd6df24f56af4fe0aac36 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 31 Dec 2016 17:21:50 +0000 Subject: [PATCH 07/79] Implemented wildcard blocking in Query Log --- scripts/pi-hole/js/queries.js | 4 ++- scripts/pi-hole/php/data.php | 54 ++++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index c68b412a..cfcd92b1 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -71,9 +71,11 @@ function add(domain,list) { } $(document).ready(function() { + var status; tableApi = $("#all-queries").DataTable( { "rowCallback": function( row, data, index ){ - if (data[4] === "Pi-holed") { + status = data[4]; + if (status.substr(0,2) === "Pi") { $(row).css("color","red"); $("td:eq(5)", row).html( "" ); } diff --git a/scripts/pi-hole/php/data.php b/scripts/pi-hole/php/data.php index ad24e57e..607e5169 100644 --- a/scripts/pi-hole/php/data.php +++ b/scripts/pi-hole/php/data.php @@ -283,6 +283,7 @@ // Create empty array for gravity $gravity_domains = getGravity(); + $wildcard_domains = getWildcardListContent(); setShowBlockedPermitted(); @@ -304,8 +305,36 @@ $domain = $exploded[count($exploded)-3]; $tmp = $exploded[count($exploded)-4]; - $status = isset($gravity_domains[$domain]) ? "Pi-holed" : "OK"; - if(($status === "Pi-holed" && $showBlocked) || ($status === "OK" && $showPermitted)) + $status = ""; + + if(isset($gravity_domains[$domain])) + { + if($gravity_domains[$domain] > 0) + { + // Exact matching gravity domain + $status = "Pi-holed (exact)"; + } + else + { + // Explicitly whitelisted + $status = "OK (whitelisted)"; + } + } + else + { + // Test for wildcard blocking + foreach ($wildcard_domains as $entry) { + if(strpos($domain, $entry) !== false) + { + $status = "Pi-holed (wildcard)"; + } + } + if(!strlen($status)) + { + $status = "OK"; + } + } + if((substr($status,0,2) === "Pi" && $showBlocked) || (substr($status,0,2) === "OK" && $showPermitted)) { $type = substr($exploded[count($exploded)-4], 6, -1); $client = $exploded[count($exploded)-1]; @@ -410,16 +439,33 @@ if($action && strlen($key) > 0) { // $action is true (we want to add) *and* key is not empty - $array[$key] = true; + $array[$key] = 1; } elseif(!$action && isset($array[$key])) { // $action is false (we want to remove) *and* key is set - unset($array[$key]); + $array[$key] = -1; } } } + function getWildcardListContent() { + $rawList = file_get_contents(checkfile("/etc/dnsmasq.d/03-pihole-wildcard.conf")); + $wclist = explode("\n", $rawList); + $list = []; + + foreach ($wclist as $entry) { + $expl = explode("/", $entry); + if(count($expl) == 3) + { + array_push($list,$expl[1]); + } + } + + return array_unique($list); + + } + function getGravity() { global $gravity,$whitelist,$blacklist; $domains = []; From fd3022abb3a4b93d669bc5222788e743199cae6a Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 31 Dec 2016 18:11:31 +0000 Subject: [PATCH 08/79] Fix check for white/blacklist action on Query Log --- scripts/pi-hole/js/queries.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index cfcd92b1..a6b2a9fc 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -109,7 +109,8 @@ $(document).ready(function() { }); $("#all-queries tbody").on( "click", "button", function () { var data = tableApi.row( $(this).parents("tr") ).data(); - if (data[4] === "Pi-holed") + status = data[4]; + if (status.substr(0,2) === "Pi") { add(data[2],"white"); } From 2998e0b03abedfd9861a577e12f78a128c9e26b2 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 31 Dec 2016 21:10:02 +0000 Subject: [PATCH 09/79] Improved counting algorithm for blocked queries. Added couting of blocked DNS queries due to wildcard blocking --- scripts/pi-hole/php/data.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/pi-hole/php/data.php b/scripts/pi-hole/php/data.php index 607e5169..ab2de98c 100644 --- a/scripts/pi-hole/php/data.php +++ b/scripts/pi-hole/php/data.php @@ -527,7 +527,17 @@ function countBlockedQueries() { global $logListName; - return exec("grep \"gravity.list\" $logListName | grep -c \" is \""); + // Blocked due to gravity entries (ad lists + blacklist) + $gravityblocked = intval(exec("grep -c -e \"gravity\.list.*is\" $logListName")); + + // Blocked due to wildcard entries + $wildcard_domains = getWildcardListContent(); + $wildcardblocked = 0; + foreach ($wildcard_domains as $domain) { + $wildcardblocked += intval(exec("grep -c -e \"config.$domain is\" $logListName")); + } + + return $gravityblocked +$wildcardblocked; } function getForwards(\SplFileObject $log) { From 01d0f474a3a400cce91f0664981970f241d6b45d Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 31 Dec 2016 21:11:36 +0000 Subject: [PATCH 10/79] Minor improvement of couting regexp --- scripts/pi-hole/php/data.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pi-hole/php/data.php b/scripts/pi-hole/php/data.php index ab2de98c..aa619dad 100644 --- a/scripts/pi-hole/php/data.php +++ b/scripts/pi-hole/php/data.php @@ -534,7 +534,7 @@ $wildcard_domains = getWildcardListContent(); $wildcardblocked = 0; foreach ($wildcard_domains as $domain) { - $wildcardblocked += intval(exec("grep -c -e \"config.$domain is\" $logListName")); + $wildcardblocked += intval(exec("grep -c -e \"config.*$domain is\" $logListName")); } return $gravityblocked +$wildcardblocked; From e84f2e49a0d8fbe611ae95b4edcf24e99fc91496 Mon Sep 17 00:00:00 2001 From: The Codacy Badger Date: Tue, 3 Jan 2017 14:07:53 +0000 Subject: [PATCH 11/79] Add Codacy badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6e225856..c9770800 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ Pi-hole Admin Dashboard ============ +[![Codacy Badge](https://api.codacy.com/project/badge/Grade/938b4d9e61b7487da77cf63ba05c683d)](https://www.codacy.com/app/Pi-hole/AdminLTE?utm_source=github.com&utm_medium=referral&utm_content=pi-hole/AdminLTE&utm_campaign=badger) [![Join the chat at https://gitter.im/pi-hole/AdminLTE](https://badges.gitter.im/pi-hole/AdminLTE.svg)](https://gitter.im/pi-hole/AdminLTE?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif "AdminLTE Presentation")](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3J2L3Z4DHW9UY "Donate") From d7afada93c582611e9dfce25aacf4974548b478f Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 6 Jan 2017 10:19:41 +0100 Subject: [PATCH 12/79] Fix overTime algorithms --- scripts/pi-hole/php/data.php | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/scripts/pi-hole/php/data.php b/scripts/pi-hole/php/data.php index 73176ca0..562da5fc 100644 --- a/scripts/pi-hole/php/data.php +++ b/scripts/pi-hole/php/data.php @@ -623,14 +623,12 @@ $byTimeAds[$time] = 1; } } - else - { - if (isset($byTimeDomains[$time])) { - $byTimeDomains[$time]++; - } - else { - $byTimeDomains[$time] = 1; - } + + if (isset($byTimeDomains[$time])) { + $byTimeDomains[$time]++; + } + else { + $byTimeDomains[$time] = 1; } } return [$byTimeDomains,$byTimeAds]; @@ -665,14 +663,12 @@ $byTimeAds[$time] = 1; } } - else - { - if (isset($byTimeDomains[$time])) { - $byTimeDomains[$time]++; - } - else { - $byTimeDomains[$time] = 1; - } + + if (isset($byTimeDomains[$time])) { + $byTimeDomains[$time]++; + } + else { + $byTimeDomains[$time] = 1; } } return [$byTimeDomains,$byTimeAds]; From 7765eeea347dcc2ba68d15489cb608cafbfa52ee Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Fri, 6 Jan 2017 10:53:01 -0500 Subject: [PATCH 13/79] Only show token when authorized --- scripts/pi-hole/php/header.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/scripts/pi-hole/php/header.php b/scripts/pi-hole/php/header.php index f5b79528..029b08ab 100644 --- a/scripts/pi-hole/php/header.php +++ b/scripts/pi-hole/php/header.php @@ -83,15 +83,16 @@ $memory_usage = -1; } + if($auth) { + // For session timer + $maxlifetime = ini_get("session.gc_maxlifetime"); - // For session timer - $maxlifetime = ini_get("session.gc_maxlifetime"); - - // Generate CSRF token - if(empty($_SESSION['token'])) { - $_SESSION['token'] = base64_encode(openssl_random_pseudo_bytes(32)); + // Generate CSRF token + if(empty($_SESSION['token'])) { + $_SESSION['token'] = base64_encode(openssl_random_pseudo_bytes(32)); + } + $token = $_SESSION['token']; } - $token = $_SESSION['token']; if(isset($setupVars['WEBUIBOXEDLAYOUT'])) { @@ -171,7 +172,7 @@ - +
          @@ -215,7 +216,9 @@ +
          Session is valid for 0){echo $maxlifetime;}else{echo "0";} ?>
          +
          From bac5bd7fcda16b7dac1949385686f1aa43581aca Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Sat, 7 Jan 2017 19:03:37 -0500 Subject: [PATCH 20/79] Preserve but take off href Need the styling provided by --- scripts/pi-hole/php/header.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/scripts/pi-hole/php/header.php b/scripts/pi-hole/php/header.php index 04bc1adc..e554d76a 100644 --- a/scripts/pi-hole/php/header.php +++ b/scripts/pi-hole/php/header.php @@ -257,18 +257,18 @@ Active'; + echo ' Active'; } elseif ($pistatus == "0") { - echo ' Offline'; + echo ' Offline'; } elseif ($pistatus == "-1") { - echo ' DNS service not running'; + echo ' DNS service not running'; } else { - echo ' Unknown'; + echo ' Unknown'; } // CPU Temp if ($celsius >= -273.15) { - echo " 60) { echo "#FF0000"; } @@ -289,11 +289,12 @@ { echo round($celsius,1) . "°C"; } + echo ""; } ?>
          $nproc) { echo "#FF0000"; } @@ -301,11 +302,11 @@ { echo "#7FFF00"; } - echo "\"> Load:  " . $loaddata[0] . "  " . $loaddata[1] . "  ". $loaddata[2]; + echo "\">
          Load:  " . $loaddata[0] . "  " . $loaddata[1] . "  ". $loaddata[2] . ""; ?>
          0.75 || $memory_usage < 0.0) { echo "#FF0000"; } @@ -315,11 +316,11 @@ } if($memory_usage > 0.0) { - echo "\"> Memory usage:  " . sprintf("%.1f",100.0*$memory_usage) . "%"; + echo "\">
          Memory usage:  " . sprintf("%.1f",100.0*$memory_usage) . "%"; } else { - echo "\"> Memory usage:   N/A"; + echo "\"> Memory usage:   N/A"; } ?> From 066bb140444566e48bd5c0bb3d0f3c5606ae9337 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Sat, 7 Jan 2017 19:46:45 -0500 Subject: [PATCH 21/79] Add multiple domains separated by whitespace --- scripts/pi-hole/js/list.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/scripts/pi-hole/js/list.js b/scripts/pi-hole/js/list.js index de2692ad..35b6687d 100644 --- a/scripts/pi-hole/js/list.js +++ b/scripts/pi-hole/js/list.js @@ -65,9 +65,8 @@ function refresh(fade) { window.onload = refresh(false); -function add() { - var domain = $("#domain"); - if(domain.val().length === 0){ +function add(domain) { + if(domain.length === 0){ return; } @@ -80,7 +79,7 @@ function add() { $.ajax({ url: "scripts/pi-hole/php/add.php", method: "post", - data: {"domain":domain.val(), "list":listType, "token":token}, + data: {"domain":domain, "list":listType, "token":token}, success: function(response) { if (response.indexOf("not a valid argument") >= 0 || response.indexOf("is not a valid domain") >= 0) { @@ -99,7 +98,6 @@ function add() { alInfo.delay(1000).fadeOut(2000, function() { alInfo.hide(); }); - domain.val(""); refresh(true); } }, @@ -113,21 +111,26 @@ function add() { }); } }); + $("#domain").val(""); } - +function handleAdd() { + $("#domain").val().split(/\s+/).forEach(function (domain) { + add(domain); + }); +} // Handle enter button for adding domains $(document).keypress(function(e) { if(e.which === 13 && $("#domain").is(":focus")) { // Enter was pressed, and the input has focus - add(); + handleAdd(); } }); // Handle buttons $("#btnAdd").on("click", function() { - add(); + handleAdd(); }); $("#btnRefresh").on("click", function() { refresh(true); From f5ac5105e38ce7a3721d852342ea6c265630f057 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 8 Jan 2017 10:34:45 +0100 Subject: [PATCH 22/79] Revert "Add multiple domains separated by whitespace" This reverts commit 066bb140444566e48bd5c0bb3d0f3c5606ae9337. --- scripts/pi-hole/js/list.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/scripts/pi-hole/js/list.js b/scripts/pi-hole/js/list.js index 35b6687d..de2692ad 100644 --- a/scripts/pi-hole/js/list.js +++ b/scripts/pi-hole/js/list.js @@ -65,8 +65,9 @@ function refresh(fade) { window.onload = refresh(false); -function add(domain) { - if(domain.length === 0){ +function add() { + var domain = $("#domain"); + if(domain.val().length === 0){ return; } @@ -79,7 +80,7 @@ function add(domain) { $.ajax({ url: "scripts/pi-hole/php/add.php", method: "post", - data: {"domain":domain, "list":listType, "token":token}, + data: {"domain":domain.val(), "list":listType, "token":token}, success: function(response) { if (response.indexOf("not a valid argument") >= 0 || response.indexOf("is not a valid domain") >= 0) { @@ -98,6 +99,7 @@ function add(domain) { alInfo.delay(1000).fadeOut(2000, function() { alInfo.hide(); }); + domain.val(""); refresh(true); } }, @@ -111,26 +113,21 @@ function add(domain) { }); } }); - $("#domain").val(""); } -function handleAdd() { - $("#domain").val().split(/\s+/).forEach(function (domain) { - add(domain); - }); -} + // Handle enter button for adding domains $(document).keypress(function(e) { if(e.which === 13 && $("#domain").is(":focus")) { // Enter was pressed, and the input has focus - handleAdd(); + add(); } }); // Handle buttons $("#btnAdd").on("click", function() { - handleAdd(); + add(); }); $("#btnRefresh").on("click", function() { refresh(true); From 3808f74d4d40511981e9281e13085c25feccc240 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 8 Jan 2017 10:37:20 +0100 Subject: [PATCH 23/79] Change function check_domain() to validate multiple domains separated by spaces --- scripts/pi-hole/php/auth.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/pi-hole/php/auth.php b/scripts/pi-hole/php/auth.php index 3283bab5..188b47b6 100644 --- a/scripts/pi-hole/php/auth.php +++ b/scripts/pi-hole/php/auth.php @@ -103,9 +103,13 @@ function check_csrf($token) { function check_domain() { if(isset($_POST['domain'])){ - $validDomain = is_valid_domain_name($_POST['domain']); - if(!$validDomain){ - log_and_die(htmlspecialchars($_POST['domain']. ' is not a valid domain')); + $domains = explode(" ",$_POST['domain']); + foreach($domains as $domain) + { + $validDomain = is_valid_domain_name($domain); + if(!$validDomain){ + log_and_die(htmlspecialchars($domain. ' is not a valid domain')); + } } } } From b6695f98826cb2025f5233f5aef094c465f436ea Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 8 Jan 2017 10:40:21 +0100 Subject: [PATCH 24/79] Show failure response in error message (e.g. abd<>.de is not a valid domain) --- list.php | 2 +- scripts/pi-hole/js/list.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/list.php b/list.php index dc8097c1..7b62afd9 100644 --- a/list.php +++ b/list.php @@ -45,7 +45,7 @@ function getFullName() { diff --git a/scripts/pi-hole/js/list.js b/scripts/pi-hole/js/list.js index de2692ad..573cd499 100644 --- a/scripts/pi-hole/js/list.js +++ b/scripts/pi-hole/js/list.js @@ -74,6 +74,7 @@ function add() { var alInfo = $("#alInfo"); var alSuccess = $("#alSuccess"); var alFailure = $("#alFailure"); + var err = $("#err"); alInfo.show(); alSuccess.hide(); alFailure.hide(); @@ -85,10 +86,11 @@ function add() { if (response.indexOf("not a valid argument") >= 0 || response.indexOf("is not a valid domain") >= 0) { alFailure.show(); - alFailure.delay(1000).fadeOut(2000, function() { + err.html(response); + alFailure.delay(4000).fadeOut(2000, function() { alFailure.hide(); }); - alInfo.delay(1000).fadeOut(2000, function() { + alInfo.delay(4000).fadeOut(2000, function() { alInfo.hide(); }); } else { From 9db9eff3d833431bef00353cdb8e5e9c80487daa Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 8 Jan 2017 10:18:20 +0100 Subject: [PATCH 25/79] Ensure that $auth is always set --- scripts/pi-hole/php/password.php | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/pi-hole/php/password.php b/scripts/pi-hole/php/password.php index 1c1ce4c0..4abe9cfc 100644 --- a/scripts/pi-hole/php/password.php +++ b/scripts/pi-hole/php/password.php @@ -21,6 +21,7 @@ } $wrongpassword = false; + $auth = false; // Test if password is set if(strlen($pwhash) > 0) From 6fd6af5d624602f4a62824479244a09ac41da075 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 8 Jan 2017 14:32:36 +0100 Subject: [PATCH 26/79] Prevent query log action buttons from line breaking --- scripts/pi-hole/js/queries.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index 19aa2b53..ecc51b84 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -103,11 +103,11 @@ $(document).ready(function() { "rowCallback": function( row, data, index ){ if (data[4] === "Pi-holed") { $(row).css("color","red"); - $("td:eq(5)", row).html( "" ); + $("td:eq(5)", row).html( "" ); } else{ $(row).css("color","green"); - $("td:eq(5)", row).html( "" ); + $("td:eq(5)", row).html( "" ); } }, From a004b90ea169e7fd269025638fcc425adaa00efb Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 8 Jan 2017 16:23:54 +0100 Subject: [PATCH 27/79] Top Clients List: Show IP address of host name when hovering over the link --- scripts/pi-hole/js/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/pi-hole/js/index.js b/scripts/pi-hole/js/index.js index 5030af14..0c26b22d 100644 --- a/scripts/pi-hole/js/index.js +++ b/scripts/pi-hole/js/index.js @@ -132,7 +132,7 @@ function escapeHtml(text) { function updateTopClientsChart() { $.getJSON("api.php?summaryRaw&getQuerySources", function(data) { var clienttable = $("#client-frequency").find("tbody:last"); - var domain, percentage, domainname; + var domain, percentage, domainname, domainip; for (domain in data.top_sources) { if ({}.hasOwnProperty.call(data.top_sources, domain)){ @@ -140,14 +140,17 @@ function updateTopClientsChart() { domain = escapeHtml(domain); if(domain.indexOf("|") > -1) { - domainname = domain.substr(0, domain.indexOf("|")); + var idx = domain.indexOf("|"); + domainname = domain.substr(0, idx); + domainip = domain.substr(idx+1, domain.length-idx); } else { domainname = domain; + domainip = domain; } - var url = ""+domainname+""; + var url = ""+domainname+""; percentage = data.top_sources[domain] / data.dns_queries_today * 100; clienttable.append(" " + url + " " + data.top_sources[domain] + "
          Date: Sun, 8 Jan 2017 16:26:37 +0100 Subject: [PATCH 28/79] Show IP for forward destination (if available) --- scripts/pi-hole/js/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/pi-hole/js/index.js b/scripts/pi-hole/js/index.js index 0c26b22d..89b1d2ba 100644 --- a/scripts/pi-hole/js/index.js +++ b/scripts/pi-hole/js/index.js @@ -175,7 +175,8 @@ function updateForwardDestinations() { c.push(colors.shift()); if(key.indexOf("|") > -1) { - key = key.substr(0, key.indexOf("|")); + var idx = key.indexOf("|"); + key = key.substr(0, idx)+" ("+key.substr(idx+1, key.length-idx)+")"; } forwardDestinationChart.data.labels.push(key); }); From 8707e04c556fe80af44c83f71204dfd785f48d8d Mon Sep 17 00:00:00 2001 From: donmahallem Date: Sun, 8 Jan 2017 18:26:55 +0100 Subject: [PATCH 29/79] If domain removal fails unhide the domain Currently the domain keeps hidden if the domain removal fails. --- scripts/pi-hole/js/list.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/pi-hole/js/list.js b/scripts/pi-hole/js/list.js index de2692ad..9db85ffb 100644 --- a/scripts/pi-hole/js/list.js +++ b/scripts/pi-hole/js/list.js @@ -21,6 +21,7 @@ function sub(index, entry) { }, error: function(jqXHR, exception) { alert("Failed to remove the domain!"); + domain.show({queue:true}); } }); } From f8dc8f0ccbe0831d706a11c42dbe58e76b14ebd2 Mon Sep 17 00:00:00 2001 From: donmahallem Date: Sun, 8 Jan 2017 22:26:11 +0100 Subject: [PATCH 30/79] Unused variable $tmp This variable is in its current form never used --- scripts/pi-hole/php/data.php | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/pi-hole/php/data.php b/scripts/pi-hole/php/data.php index 562da5fc..bb6e3666 100644 --- a/scripts/pi-hole/php/data.php +++ b/scripts/pi-hole/php/data.php @@ -380,7 +380,6 @@ $exploded = explode(" ", trim($query)); $domain = $exploded[count($exploded)-3]; - $tmp = $exploded[count($exploded)-4]; $status = isset($gravity_domains[$domain]) ? "Pi-holed" : "OK"; if(($status === "Pi-holed" && $showBlocked) || ($status === "OK" && $showPermitted)) From 9eadc26d309c22594f8a226afc0d89b4f712df75 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 9 Jan 2017 14:40:40 +0100 Subject: [PATCH 31/79] Add more detailed error output recently added to the lists page to the query log action buttons --- queries.php | 2 +- scripts/pi-hole/js/list.js | 1 + scripts/pi-hole/js/queries.js | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/queries.php b/queries.php index 30fe7b3b..e466e825 100644 --- a/queries.php +++ b/queries.php @@ -61,7 +61,7 @@ if(isset($setupVars["API_PRIVACY_MODE"]))
          diff --git a/scripts/pi-hole/js/list.js b/scripts/pi-hole/js/list.js index 573cd499..6bc06377 100644 --- a/scripts/pi-hole/js/list.js +++ b/scripts/pi-hole/js/list.js @@ -107,6 +107,7 @@ function add() { }, error: function(jqXHR, exception) { alFailure.show(); + err.html(""); alFailure.delay(1000).fadeOut(2000, function() { alFailure.hide(); }); diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index ecc51b84..0cdf53c5 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -22,6 +22,7 @@ function add(domain,list) { alDomain.html(domain); var alSuccess = $("#alSuccess"); var alFailure = $("#alFailure"); + var err = $("#err"); if(list === "white") { @@ -43,7 +44,8 @@ function add(domain,list) { if (response.indexOf("not a valid argument") >= 0 || response.indexOf("is not a valid domain") >= 0) { alFailure.show(); - alFailure.delay(1000).fadeOut(2000, function() { alFailure.hide(); }); + err.html(response); + alFailure.delay(4000).fadeOut(2000, function() { alFailure.hide(); }); } else { @@ -58,6 +60,7 @@ function add(domain,list) { }, error: function(jqXHR, exception) { alFailure.show(); + err.html(""); alFailure.delay(1000).fadeOut(2000, function() { alFailure.hide(); }); From 3c0c92e8b1abe8a0485d8f6458159a67aeca4947 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 11 Jan 2017 12:41:35 +0100 Subject: [PATCH 32/79] Hide "Whitelist" button on wildcard blocked entries (Query Log page) --- scripts/pi-hole/js/queries.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index 428006c7..13a34730 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -103,10 +103,14 @@ $(document).ready(function() { tableApi = $("#all-queries").DataTable( { "rowCallback": function( row, data, index ){ status = data[4]; - if (status.substr(0,2) === "Pi") { + if (status === "Pi-holed (exact)") { $(row).css("color","red"); $("td:eq(5)", row).html( "" ); } + else if (status === "Pi-holed (wildcard)") { + $(row).css("color","red"); + $("td:eq(5)", row).html( "" ); + } else{ $(row).css("color","green"); $("td:eq(5)", row).html( "" ); From b521a8de960036fbd6d2fbcb33a752de5c8fc86c Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 11 Jan 2017 16:50:46 +0100 Subject: [PATCH 33/79] Show notice that whitelisting of wildcard blocking is not possible --- list.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/list.php b/list.php index da146258..3f720e78 100644 --- a/list.php +++ b/list.php @@ -39,6 +39,8 @@ function getFullName() { }
          + +

          Note that whitelisting domains which are blocked using the wildcard method won't work.

          From 225c2791fe2f6af4da9f9b0a2bbe2d7d02feeeaa Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 12 Jan 2017 16:30:18 +0100 Subject: [PATCH 38/79] Remove debug statement --- scripts/pi-hole/php/savesettings.php | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/pi-hole/php/savesettings.php b/scripts/pi-hole/php/savesettings.php index 763d2322..d9aadbce 100644 --- a/scripts/pi-hole/php/savesettings.php +++ b/scripts/pi-hole/php/savesettings.php @@ -134,7 +134,6 @@ function validDomain($domain_name) { exec("sudo pihole -a setdns ".$primaryIP." ".$secondaryIP." ".$extra); $success .= "The DNS settings have been updated"; - $success = "sudo pihole -a setdns ".$primaryIP." ".$secondaryIP." ".$extra; } else { From 8ff6c77ad47e68554ecb77433dc05907eebf13c9 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 12 Jan 2017 17:15:13 +0100 Subject: [PATCH 39/79] Make statistics not selectable --- scripts/pi-hole/php/header.php | 1 + style/pi-hole.css | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 style/pi-hole.css diff --git a/scripts/pi-hole/php/header.php b/scripts/pi-hole/php/header.php index e554d76a..91a56f7d 100644 --- a/scripts/pi-hole/php/header.php +++ b/scripts/pi-hole/php/header.php @@ -150,6 +150,7 @@ +