diff --git a/list.php b/list.php index 7b62afd9..3f720e78 100644 --- a/list.php +++ b/list.php @@ -29,10 +29,18 @@ function getFullName() {
+ + + + + + }
+ +

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

+ +

Exact blocking

+ + +

Wildcard blocking

+ + Your " + fullName + " is empty!"); + $("h3").hide(); + if(listw) + { + listw.html("
Your " + fullName + " is empty!
"); + } + else + { + list.html("
Your " + fullName + " is empty!
"); + } } else { + $("h3").show(); data.forEach(function (entry, index) { - list.append( + if(entry.substr(0,1) === "*") + { + // Wildcard entry + // remove leading * + entry = entry.substr(1, entry.length - 1); + listw.append( "
  • " + entry + "
  • " - ); + ""); + // Handle button + $("#list-wildcard #"+index+"").on("click", "button", function() { + sub(index, entry, "wild"); + }); + } + else + { + // Normal entry + list.append( + "
  • " + 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(); @@ -66,11 +114,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"); @@ -82,7 +135,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) { @@ -125,14 +178,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); }); diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index 0cdf53c5..56912249 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -85,6 +85,7 @@ function handleAjaxError( xhr, textStatus, error ) { } $(document).ready(function() { + var status; // Do we want to filter queries? var GETDict = {}; @@ -104,10 +105,15 @@ $(document).ready(function() { tableApi = $("#all-queries").DataTable( { "rowCallback": function( row, data, index ){ - if (data[4] === "Pi-holed") { + status = data[4]; + 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( "" ); @@ -139,7 +145,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"); } 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/data.php b/scripts/pi-hole/php/data.php index bb6e3666..f6914d78 100644 --- a/scripts/pi-hole/php/data.php +++ b/scripts/pi-hole/php/data.php @@ -333,6 +333,7 @@ // Create empty array for gravity $gravity_domains = getGravity(); + $wildcard_domains = getWildcardListContent(); if(isset($_GET["from"])) { @@ -381,8 +382,36 @@ $exploded = explode(" ", trim($query)); $domain = $exploded[count($exploded)-3]; - $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]; @@ -505,16 +534,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 = []; @@ -576,7 +622,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) { diff --git a/scripts/pi-hole/php/get.php b/scripts/pi-hole/php/get.php index fada75b9..043c8b87 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; } ?>