From 61a42111e495c0b08a534c05ac025271ee0a9b74 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 7 Mar 2016 20:58:00 -0500 Subject: [PATCH 1/7] Fix query log refresh --- queries.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queries.php b/queries.php index 9a47c9af..b77cdc7f 100644 --- a/queries.php +++ b/queries.php @@ -63,7 +63,7 @@ } ); function refreshData() { - tableApi.ajax.url("api.php?getAllQuerie").load(); + tableApi.ajax.url("api.php?getAllQueries").load(); } From 8d02575b1ae94362453ce439333f16cf0ea7fac4 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Tue, 8 Mar 2016 13:01:27 +0000 Subject: [PATCH 2/7] Fix divide-by-zero error as mentioned in #55 --- data.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data.php b/data.php index bafb62cc..c0eb6847 100644 --- a/data.php +++ b/data.php @@ -14,7 +14,7 @@ $ads_blocked_today = count(getBlockedQueries($log)); - $ads_percentage_today = $ads_blocked_today / $dns_queries_today * 100; + $ads_percentage_today = $dns_queries_today > 0 ? ($ads_blocked_today / $dns_queries_today * 100) : 0; return array( 'domains_being_blocked' => $domains_being_blocked, From 91f2514ea1891bfa3dc6207add47847782fb4b82 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Tue, 8 Mar 2016 15:34:26 +0000 Subject: [PATCH 3/7] Check gravity.list to see if domain is a pi-holed one --- data.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/data.php b/data.php index c0eb6847..3802707f 100644 --- a/data.php +++ b/data.php @@ -121,19 +121,32 @@ $allQueries = array("data" => array()); $log = readInLog(); $dns_queries = getDnsQueries($log); + + $fileName = '/etc/pihole/gravity.list'; + $file = file_get_contents($fileName); foreach ($dns_queries as $query) { $time = date_create(substr($query, 0, 16)); - $exploded = explode(" ", trim($query)); + + $searchString = " {$exploded[6]}\n"; + + if (strpos($file,$searchString)) { + $extra="Pi-holed"; + } + else { + $extra="OK"; + }; + array_push($allQueries['data'], array( $time->format('Y-m-d\TH:i:s'), substr($exploded[5], 6, -1), $exploded[6], $exploded[8], + $extra, )); } - + return $allQueries; } From f5eef05ac31d78b55743720232ea1dbe9b560538 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Tue, 8 Mar 2016 15:35:39 +0000 Subject: [PATCH 4/7] Add an extra column to table to show pi-holed status. Highlight green or red depending on status. --- queries.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/queries.php b/queries.php index b77cdc7f..485de2b8 100644 --- a/queries.php +++ b/queries.php @@ -24,6 +24,7 @@ Type Domain Client + Status @@ -32,6 +33,7 @@ Type Domain Client + Status @@ -50,6 +52,15 @@ - - + \ No newline at end of file From 9b8c92ed5d895268b88661127cdce310dc44f057 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Tue, 8 Mar 2016 15:51:58 +0000 Subject: [PATCH 5/7] Fix query type display on pi-chart as raised in #54 --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.php b/index.php index ef7bad78..32b7ce36 100644 --- a/index.php +++ b/index.php @@ -347,7 +347,7 @@ queryTypeChart.addData({ value: value, color: colors.shift(), - label: key + label: key.substr(6,key.length - 7) }); }); $('#query-types .overlay').remove(); From 951a28cb3689d84fe35c101d805d9f83810d0fc4 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Tue, 8 Mar 2016 12:30:35 -0500 Subject: [PATCH 6/7] Disable list editing --- header.html | 4 + list.php | 212 ---------------------------------------------- php/add.php | 17 ---- php/checkPass.php | 10 --- php/functions.php | 5 -- php/get.php | 15 ---- php/sub.php | 17 ---- 7 files changed, 4 insertions(+), 276 deletions(-) delete mode 100644 list.php delete mode 100644 php/add.php delete mode 100644 php/checkPass.php delete mode 100644 php/functions.php delete mode 100644 php/get.php delete mode 100644 php/sub.php diff --git a/header.html b/header.html index 9e904bea..49371f74 100644 --- a/header.html +++ b/header.html @@ -123,17 +123,21 @@ + +
  • diff --git a/list.php b/list.php deleted file mode 100644 index 8087f20f..00000000 --- a/list.php +++ /dev/null @@ -1,212 +0,0 @@ - - - - - - -
    - - - - - -
    - - - - - - - - - - -
      - - - - diff --git a/php/add.php b/php/add.php deleted file mode 100644 index c602119d..00000000 --- a/php/add.php +++ /dev/null @@ -1,17 +0,0 @@ -= 0; $i--) { - if($list[$i] == "") - unset($list[$i]); -} - -echo json_encode(array_values($list)); \ No newline at end of file diff --git a/php/sub.php b/php/sub.php deleted file mode 100644 index 9c5862e9..00000000 --- a/php/sub.php +++ /dev/null @@ -1,17 +0,0 @@ - Date: Tue, 8 Mar 2016 19:09:38 +0000 Subject: [PATCH 7/7] Vastly improve checking for domain in gravity.list (think 30+ seconds down to 1) --- data.php | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/data.php b/data.php index 3802707f..4fac0ad9 100644 --- a/data.php +++ b/data.php @@ -123,21 +123,26 @@ $dns_queries = getDnsQueries($log); $fileName = '/etc/pihole/gravity.list'; - $file = file_get_contents($fileName); - + //Turn gravity.list into an array + $lines = explode("\n", file_get_contents($fileName)); + + //Create a new array and set domain name as index instead of value, with value as 1 + foreach(array_values($lines) as $v){ + $new_lines[trim(strstr($v, ' '))] = 1; + } + foreach ($dns_queries as $query) { $time = date_create(substr($query, 0, 16)); $exploded = explode(" ", trim($query)); - - $searchString = " {$exploded[6]}\n"; - - if (strpos($file,$searchString)) { - $extra="Pi-holed"; - } - else { - $extra="OK"; - }; + //Is index of the domain name set? + if (isset($new_lines[$exploded[6]])){ + $extra = "Pi-holed"; + } + else + { + $extra = "OK"; + } array_push($allQueries['data'], array( $time->format('Y-m-d\TH:i:s'), substr($exploded[5], 6, -1),