From 2c2a091b03052d3eedf909354c7835391f73d24a Mon Sep 17 00:00:00 2001 From: Walter Date: Mon, 23 Apr 2018 20:32:38 +0200 Subject: [PATCH 1/4] Changes concerning the date the gravity list was last changed. Used in the webinterface dashboard as a tooltip, and now also available in the API (both PHP and FTL). Function was moved to new file /scripts/pi-hole/php/gravity.php to keep things neat and to avoid duplicate code. --- api_FTL.php | 2 ++ api_PHP.php | 2 ++ index.php | 24 +++------------- scripts/pi-hole/php/gravity.php | 51 +++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 scripts/pi-hole/php/gravity.php diff --git a/api_FTL.php b/api_FTL.php index 14602e2a..e67405dc 100644 --- a/api_FTL.php +++ b/api_FTL.php @@ -31,6 +31,7 @@ else if (isset($_GET['summary']) || isset($_GET['summaryRaw']) || !count($_GET)) { + require_once("scripts/pi-hole/php/gravity.php"); sendRequestFTL("stats"); $return = getResponseFTL(); @@ -61,6 +62,7 @@ else $stats[$tmp[0]] = floatval($tmp[1]); } } + $stats['gravity_last_updated'] = gravity_last_update(true); $data = array_merge($data,$stats); } diff --git a/api_PHP.php b/api_PHP.php index dc7a1d2b..52bbd613 100644 --- a/api_PHP.php +++ b/api_PHP.php @@ -13,6 +13,7 @@ } include('scripts/pi-hole/php/data.php'); + include_once('scripts/pi-hole/php/gravity.php'); // Non-Auth @@ -34,6 +35,7 @@ $sum['dns_queries_today'] = number_format( $sum['dns_queries_today']); $sum['ads_percentage_today'] = number_format( $sum['ads_percentage_today'], 1, '.', ''); $sum['domains_being_blocked'] = number_format( $sum['domains_being_blocked']); + $sum['gravity_last_updated'] = gravity_last_update(true); $data = array_merge($data, $sum); } diff --git a/index.php b/index.php index da1bec33..18984ff2 100644 --- a/index.php +++ b/index.php @@ -7,6 +7,7 @@ * Please see LICENSE file for your rights under this license. */ $indexpage = true; require "scripts/pi-hole/php/header.php"; + require_once("scripts/pi-hole/php/gravity.php"); ?>
@@ -48,27 +49,10 @@
-d > 1) - $gravitydate = $gravitydiff->format("Blocking list updated %a days, %H:%I ago"); - elseif($gravitydiff->d == 1) - $gravitydate = $gravitydiff->format("Blocking list updated one day, %H:%I ago"); - else - $gravitydate = $gravitydiff->format("Blocking list updated %H:%I ago"); -} -else -{ - $gravitydate = "Blocking list not found"; -} -?>
-
+

Domains on Blocklist

---

@@ -229,11 +213,11 @@ else
diff --git a/scripts/pi-hole/php/gravity.php b/scripts/pi-hole/php/gravity.php new file mode 100644 index 00000000..4ce5e5bf --- /dev/null +++ b/scripts/pi-hole/php/gravity.php @@ -0,0 +1,51 @@ + true, + "absolute" => $date_file_created_unix, + "relative" => array( + "days" => $gravitydiff->format("%a"), + "hours" => $gravitydiff->format("%H"), + "minutes" => $gravitydiff->format("%I"), + ) + ); + }else{ + if($gravitydiff->d > 1){ + $output = $gravitydiff->format("Blocking list updated %a days, %H:%I ago"); + }elseif($gravitydiff->d == 1){ + $output = $gravitydiff->format("Blocking list updated one day, %H:%I ago"); + }else{ + $output = $gravitydiff->format("Blocking list updated %H:%I ago"); + } + } + }else{ + if($raw){ + $output = array("file_exists"=>false); + }else{ + $output = "Blocking list not found"; + } + } + return $output; +} + +?> \ No newline at end of file From 983966da04f9607ffc70d89dcf51b0597c803e3f Mon Sep 17 00:00:00 2001 From: Walter Date: Wed, 2 May 2018 11:01:38 +0200 Subject: [PATCH 2/4] Changed indentation from spaces and tabs to only tabs --- scripts/pi-hole/php/gravity.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/pi-hole/php/gravity.php b/scripts/pi-hole/php/gravity.php index 4ce5e5bf..7b55a8a8 100644 --- a/scripts/pi-hole/php/gravity.php +++ b/scripts/pi-hole/php/gravity.php @@ -18,8 +18,8 @@ function gravity_last_update($raw = false){ $date_file_created_unix = filemtime($gravitylist); $date_file_created = date_create("@".$date_file_created_unix); $date_now = date_create("now"); - $gravitydiff = date_diff($date_file_created,$date_now); - if($raw){ + $gravitydiff = date_diff($date_file_created,$date_now); + if($raw){ $output = array( "file_exists"=> true, "absolute" => $date_file_created_unix, @@ -31,12 +31,12 @@ function gravity_last_update($raw = false){ ); }else{ if($gravitydiff->d > 1){ - $output = $gravitydiff->format("Blocking list updated %a days, %H:%I ago"); - }elseif($gravitydiff->d == 1){ - $output = $gravitydiff->format("Blocking list updated one day, %H:%I ago"); - }else{ - $output = $gravitydiff->format("Blocking list updated %H:%I ago"); - } + $output = $gravitydiff->format("Blocking list updated %a days, %H:%I ago"); + }elseif($gravitydiff->d == 1){ + $output = $gravitydiff->format("Blocking list updated one day, %H:%I ago"); + }else{ + $output = $gravitydiff->format("Blocking list updated %H:%I ago"); + } } }else{ if($raw){ From 49190f8a620021d5472956bdb5176ce8d3d88899 Mon Sep 17 00:00:00 2001 From: Walter Date: Wed, 2 May 2018 11:07:28 +0200 Subject: [PATCH 3/4] Changed indentation from all tabs to all spaces (misread preference, my bad) --- scripts/pi-hole/php/gravity.php | 78 ++++++++++++++++----------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/scripts/pi-hole/php/gravity.php b/scripts/pi-hole/php/gravity.php index 7b55a8a8..407b8ab6 100644 --- a/scripts/pi-hole/php/gravity.php +++ b/scripts/pi-hole/php/gravity.php @@ -7,45 +7,45 @@ * Please see LICENSE file for your rights under this license. */ function gravity_last_update($raw = false){ - /* - @walter-exit | April 23rd, 2018: - Checks when the gravity list was last updated, if it exists at all. - Returns the info in human-readable format for use on the dashboard, - or raw for use by the API. - */ - $gravitylist = "/etc/pihole/gravity.list"; - if (file_exists($gravitylist)){ - $date_file_created_unix = filemtime($gravitylist); - $date_file_created = date_create("@".$date_file_created_unix); - $date_now = date_create("now"); - $gravitydiff = date_diff($date_file_created,$date_now); - if($raw){ - $output = array( - "file_exists"=> true, - "absolute" => $date_file_created_unix, - "relative" => array( - "days" => $gravitydiff->format("%a"), - "hours" => $gravitydiff->format("%H"), - "minutes" => $gravitydiff->format("%I"), - ) - ); - }else{ - if($gravitydiff->d > 1){ - $output = $gravitydiff->format("Blocking list updated %a days, %H:%I ago"); - }elseif($gravitydiff->d == 1){ - $output = $gravitydiff->format("Blocking list updated one day, %H:%I ago"); - }else{ - $output = $gravitydiff->format("Blocking list updated %H:%I ago"); - } - } - }else{ - if($raw){ - $output = array("file_exists"=>false); - }else{ - $output = "Blocking list not found"; - } - } - return $output; + /* + @walter-exit | April 23rd, 2018: + Checks when the gravity list was last updated, if it exists at all. + Returns the info in human-readable format for use on the dashboard, + or raw for use by the API. + */ + $gravitylist = "/etc/pihole/gravity.list"; + if (file_exists($gravitylist)){ + $date_file_created_unix = filemtime($gravitylist); + $date_file_created = date_create("@".$date_file_created_unix); + $date_now = date_create("now"); + $gravitydiff = date_diff($date_file_created,$date_now); + if($raw){ + $output = array( + "file_exists"=> true, + "absolute" => $date_file_created_unix, + "relative" => array( + "days" => $gravitydiff->format("%a"), + "hours" => $gravitydiff->format("%H"), + "minutes" => $gravitydiff->format("%I"), + ) + ); + }else{ + if($gravitydiff->d > 1){ + $output = $gravitydiff->format("Blocking list updated %a days, %H:%I ago"); + }elseif($gravitydiff->d == 1){ + $output = $gravitydiff->format("Blocking list updated one day, %H:%I ago"); + }else{ + $output = $gravitydiff->format("Blocking list updated %H:%I ago"); + } + } + }else{ + if($raw){ + $output = array("file_exists"=>false); + }else{ + $output = "Blocking list not found"; + } + } + return $output; } ?> \ No newline at end of file From 967216ca7492f37f0ee009b1733b5383f08480b0 Mon Sep 17 00:00:00 2001 From: Walter Date: Wed, 2 May 2018 20:12:15 +0200 Subject: [PATCH 4/4] Signed-off-by: Walter --- scripts/pi-hole/php/gravity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pi-hole/php/gravity.php b/scripts/pi-hole/php/gravity.php index 407b8ab6..cb3c3404 100644 --- a/scripts/pi-hole/php/gravity.php +++ b/scripts/pi-hole/php/gravity.php @@ -8,7 +8,7 @@ function gravity_last_update($raw = false){ /* - @walter-exit | April 23rd, 2018: + @walter-exit | April 23rd, 2018: Checks when the gravity list was last updated, if it exists at all. Returns the info in human-readable format for use on the dashboard, or raw for use by the API.