diff --git a/api.php b/api.php index b8e0024c..128640f8 100644 --- a/api.php +++ b/api.php @@ -1,242 +1,242 @@ - - $domains_over_time, - 'ads_over_time' => $ads_over_time); - $data = array_merge($data, $result); - } - - if (isset($_GET['topItems']) && $auth) - { - if(is_numeric($_GET['topItems'])) - { - sendRequestFTL("top-domains ".$_GET['topItems']); - } else { - sendRequestFTL("top-domains"); + $stats[$tmp[0]] = $tmp[1]; } + } + $data = array_merge($data,$stats); +} - $return = getResponseFTL(); - $top_queries = array(); - foreach($return as $line) - { - $tmp = explode(" ",$line); - $top_queries[$tmp[2]] = $tmp[1]; - } +if (isset($_GET['overTimeData10mins'])) +{ + sendRequestFTL("overTime"); + $return = getResponseFTL(); - if(is_numeric($_GET['topItems'])) + $domains_over_time = array(); + $ads_over_time = array(); + foreach($return as $line) + { + $tmp = explode(" ",$line); + $domains_over_time[$tmp[0]] = $tmp[1]; + $ads_over_time[$tmp[0]] = $tmp[2]; + } + $result = array('domains_over_time' => $domains_over_time, + 'ads_over_time' => $ads_over_time); + $data = array_merge($data, $result); +} + +if (isset($_GET['topItems']) && $auth) +{ + if(is_numeric($_GET['topItems'])) + { + sendRequestFTL("top-domains ".$_GET['topItems']); + } + else + { + sendRequestFTL("top-domains"); + } + + $return = getResponseFTL(); + $top_queries = array(); + foreach($return as $line) + { + $tmp = explode(" ",$line); + $top_queries[$tmp[2]] = $tmp[1]; + } + + if(is_numeric($_GET['topItems'])) + { + sendRequestFTL("top-ads ".$_GET['topItems']); + } + else + { + sendRequestFTL("top-ads"); + } + + $return = getResponseFTL(); + $top_ads = array(); + foreach($return as $line) + { + $tmp = explode(" ",$line); + $top_ads[$tmp[2]] = $tmp[1]; + } + + $result = array('top_queries' => $top_queries, + 'top_ads' => $top_ads); + + $data = array_merge($data, $result); +} + +if ((isset($_GET['topClients']) || isset($_GET['getQuerySources'])) && $auth) +{ + sendRequestFTL("top-clients"); + $return = getResponseFTL(); + $top_clients = array(); + foreach($return as $line) + { + $tmp = explode(" ",$line); + if(count($tmp) == 4) { - sendRequestFTL("top-ads ".$_GET['topItems']); + $top_clients[$tmp[3]."|".$tmp[2]] = $tmp[1]; } else { - sendRequestFTL("top-ads"); + $top_clients[$tmp[2]] = $tmp[1]; } - - $return = getResponseFTL(); - $top_ads = array(); - foreach($return as $line) - { - $tmp = explode(" ",$line); - $top_ads[$tmp[2]] = $tmp[1]; - } - - $result = array('top_queries' => $top_queries, - 'top_ads' => $top_ads); - - $data = array_merge($data, $result); } - if ((isset($_GET['topClients']) || isset($_GET['getQuerySources'])) && $auth) + $result = array('top_sources' => $top_clients); + $data = array_merge($data, $result); +} + +if (isset($_GET['getForwardDestinations']) && $auth) +{ + sendRequestFTL("forward-dest"); + $return = getResponseFTL(); + $forward_dest = array(); + foreach($return as $line) { - sendRequestFTL("top-clients"); - $return = getResponseFTL(); - $top_clients = array(); - foreach($return as $line) + $tmp = explode(" ",$line); + if(count($tmp) == 4) { - $tmp = explode(" ",$line); - if(count($tmp) == 4) - { - $top_clients[$tmp[3]."|".$tmp[2]] = $tmp[1]; - } - else - { - $top_clients[$tmp[2]] = $tmp[1]; - } - } - - $result = array('top_sources' => $top_clients); - $data = array_merge($data, $result); - } - - if (isset($_GET['getForwardDestinations']) && $auth) - { - sendRequestFTL("forward-dest"); - $return = getResponseFTL(); - $forward_dest = array(); - foreach($return as $line) - { - $tmp = explode(" ",$line); - if(count($tmp) == 4) - { - $forward_dest[$tmp[3]."|".$tmp[2]] = $tmp[1]; - } - else - { - $forward_dest[$tmp[2]] = $tmp[1]; - } - } - - $result = array('forward_destinations' => $forward_dest); - $data = array_merge($data, $result); - } - - if (isset($_GET['getQueryTypes']) && $auth) - { - sendRequestFTL("querytypes"); - $return = getResponseFTL(); - $querytypes = array(); - foreach($return as $ret) - { - $tmp = explode(": ",$ret); - $querytypes[$tmp[0]] = $tmp[1]; - } - - $result = array('querytypes' => $querytypes); - $data = array_merge($data, $result); - } - - if (isset($_GET['getAllQueries']) && $auth) - { - if(isset($_GET['from']) && isset($_GET['until'])) - { - // Get limited time interval - sendRequestFTL("getallqueries-time ".$_GET['from']." ".$_GET['until']); - } - else if(isset($_GET['domain'])) - { - // Get specific domain only - sendRequestFTL("getallqueries-domain ".$_GET['domain']); - } - else if(isset($_GET['client'])) - { - // Get specific client only - sendRequestFTL("getallqueries-client ".$_GET['client']); + $forward_dest[$tmp[3]."|".$tmp[2]] = $tmp[1]; } else { - // Get all queries - sendRequestFTL("getallqueries"); + $forward_dest[$tmp[2]] = $tmp[1]; } - $return = getResponseFTL(); - $allQueries = array(); - foreach($return as $line) - { - $tmp = explode(" ",$line); - array_push($allQueries,$tmp); - } - - $result = array('data' => $allQueries); - $data = array_merge($data, $result); } - if (isset($_GET['enable'], $_GET['token']) && $auth) { - check_csrf($_GET['token']); - exec('sudo pihole enable'); - $data = array_merge($data, array("status" => "enabled")); - } - elseif (isset($_GET['disable'], $_GET['token']) && $auth) { - check_csrf($_GET['token']); - $disable = intval($_GET['disable']); - // intval returns the integer value on success, or 0 on failure - if($disable > 0) - { - exec("sudo pihole disable ".$disable."s"); - } - else - { - exec('sudo pihole disable'); - } - $data = array_merge($data, array("status" => "disabled")); - } + $result = array('forward_destinations' => $forward_dest); + $data = array_merge($data, $result); +} - if(isset($_GET["recentBlocked"])) +if (isset($_GET['getQueryTypes']) && $auth) +{ + sendRequestFTL("querytypes"); + $return = getResponseFTL(); + $querytypes = array(); + foreach($return as $ret) { - sendRequestFTL("recentBlocked"); - echo getResponseFTL()[0]; - unset($data); + $tmp = explode(": ",$ret); + $querytypes[$tmp[0]] = $tmp[1]; } - if(isset($data)) + $result = array('querytypes' => $querytypes); + $data = array_merge($data, $result); +} + +if (isset($_GET['getAllQueries']) && $auth) +{ + if(isset($_GET['from']) && isset($_GET['until'])) { - echo json_encode($data); + // Get limited time interval + sendRequestFTL("getallqueries-time ".$_GET['from']." ".$_GET['until']); + } + else if(isset($_GET['domain'])) + { + // Get specific domain only + sendRequestFTL("getallqueries-domain ".$_GET['domain']); + } + else if(isset($_GET['client'])) + { + // Get specific client only + sendRequestFTL("getallqueries-client ".$_GET['client']); + } + else + { + // Get all queries + sendRequestFTL("getallqueries"); + } + $return = getResponseFTL(); + $allQueries = array(); + foreach($return as $line) + { + $tmp = explode(" ",$line); + array_push($allQueries,$tmp); } - disconnectFTL(); + $result = array('data' => $allQueries); + $data = array_merge($data, $result); +} + +if (isset($_GET['enable'], $_GET['token']) && $auth) { + check_csrf($_GET['token']); + exec('sudo pihole enable'); + $data = array_merge($data, array("status" => "enabled")); +} +elseif (isset($_GET['disable'], $_GET['token']) && $auth) { + check_csrf($_GET['token']); + $disable = intval($_GET['disable']); + // intval returns the integer value on success, or 0 on failure + if($disable > 0) + { + exec("sudo pihole disable ".$disable."s"); + } + else + { + exec('sudo pihole disable'); + } + $data = array_merge($data, array("status" => "disabled")); +} + +if(isset($_GET["recentBlocked"])) +{ + sendRequestFTL("recentBlocked"); + echo getResponseFTL()[0]; + unset($data); +} + +if(isset($data)) +{ + echo json_encode($data); +} + +disconnectFTL(); ?> diff --git a/scripts/pi-hole/js/footer.js b/scripts/pi-hole/js/footer.js index 5cdd042e..3af5b3e7 100644 --- a/scripts/pi-hole/js/footer.js +++ b/scripts/pi-hole/js/footer.js @@ -22,17 +22,17 @@ function piholeChanged(action) switch(action) { case "enabled": - status.html(" Active"); - ena.hide(); - dis.show(); - dis.removeClass("active"); - break; + status.html(" Active"); + ena.hide(); + dis.show(); + dis.removeClass("active"); + break; case "disabled": - status.html(" Offline"); - ena.show(); - dis.hide(); - break; + status.html(" Offline"); + ena.show(); + dis.hide(); + break; } } @@ -44,32 +44,76 @@ function piholeChange(action, duration) switch(action) { case "enable": - btnStatus = $("#flip-status-enable"); - btnStatus.html(" "); - $.getJSON("api.php?enable&token=" + token, function(data) { - if(data.status === "enabled") { - btnStatus.html(""); - piholeChanged("enabled"); - } - }); - break; + btnStatus = $("#flip-status-enable"); + btnStatus.html(" "); + $.getJSON("api.php?enable&token=" + token, function(data) { + if(data.status === "enabled") { + btnStatus.html(""); + piholeChanged("enabled"); + } + }); + break; case "disable": - btnStatus = $("#flip-status-disable"); - btnStatus.html(" "); - $.getJSON("api.php?disable=" + duration + "&token=" + token, function(data) { - if(data.status === "disabled") { - btnStatus.html(""); - piholeChanged("disabled"); - } - }); - break; + btnStatus = $("#flip-status-disable"); + btnStatus.html(" "); + $.getJSON("api.php?disable=" + duration + "&token=" + token, function(data) { + if(data.status === "disabled") { + btnStatus.html(""); + piholeChanged("disabled"); + } + }); + break; } } +//The following three functions allow us to display time until pi-hole is enabled after disabling. +//Works between all pages + + +function setCountdownTarget(seconds){ + var target = new Date(); + target = new Date(target.getTime() + seconds * 1000); + localStorage.setItem("countDownTarget", target); +} + +function secondsTimeSpanToHMS(s) { + var h = Math.floor(s/3600); //Get whole hours + s -= h*3600; + var m = Math.floor(s/60); //Get remaining minutes + s -= m*60; + return h+":"+(m < 10 ? "0"+m : m)+":"+(s < 10 ? "0"+s : s); //zero padding on minutes and seconds +} + +function countDown(){ + var ena = $("#enableLabel"); + var target = new Date(localStorage.getItem("countDownTarget")); + var seconds = Math.round((target.getTime() - new Date().getTime()) / 1000); + + if(seconds > 0){ + setTimeout(countDown,1000); + ena.text("Enable (" + secondsTimeSpanToHMS(seconds) + ")"); + } + else + { + ena.text("Enable"); + piholeChanged("enabled"); + localStorage.removeItem("countDownTarget"); + } +} + +$( document ).ready(function() { + var countDownTarget = localStorage.getItem("countDownTarget"); + if (countDownTarget != null) + { + setTimeout(countDown,1000); + } +}); + // Handle Enable/Disable $("#pihole-enable").on("click", function(e){ e.preventDefault(); + localStorage.removeItem("countDownTarget"); piholeChange("enable",""); }); $("#pihole-disable-permanently").on("click", function(e){ @@ -79,18 +123,30 @@ $("#pihole-disable-permanently").on("click", function(e){ $("#pihole-disable-10s").on("click", function(e){ e.preventDefault(); piholeChange("disable","10"); - setTimeout(function(){piholeChanged("enabled");},10000); + setCountdownTarget(10); + setTimeout(countDown,1000); }); $("#pihole-disable-30s").on("click", function(e){ e.preventDefault(); piholeChange("disable","30"); - setTimeout(function(){piholeChanged("enabled");},30000); + setCountdownTarget(30); + setTimeout(countDown,1000); }); $("#pihole-disable-5m").on("click", function(e){ e.preventDefault(); piholeChange("disable","300"); - setTimeout(function(){piholeChanged("enabled");},300000); + setCountdownTarget(300); + setTimeout(countDown,1000); }); +$("#pihole-disable-custom").on("click", function(e){ + e.preventDefault(); + var custVal = $("#customTimeout").val(); + custVal = $("#btnMins").hasClass("active") ? custVal * 60 : custVal; + piholeChange("disable",custVal); + setCountdownTarget(custVal); + setTimeout(countDown,1000); +}); + var piholeVersion = $("#piholeVersion").html(); var webVersion = $("#webVersion").html(); @@ -200,15 +256,15 @@ else // Hide "exact match" button on queryads.php page if version is 2.9.5 or lower if(versionCompare(piholeVersion, "v2.9.5") < 1) { - $("#btnSearchExact").hide(); + $("#btnSearchExact").hide(); } // Handle Strg + Enter button on Login page $(document).keypress(function(e) { - if((e.keyCode === 10 || e.keyCode === 13) && e.ctrlKey && $("#loginpw").is(":focus")) { - $("#loginform").attr("action", "settings.php"); - $("#loginform").submit(); - } + if((e.keyCode === 10 || e.keyCode === 13) && e.ctrlKey && $("#loginpw").is(":focus")) { + $("#loginform").attr("action", "settings.php"); + $("#loginform").submit(); + } }); function testCookies() diff --git a/scripts/pi-hole/php/FTL.php b/scripts/pi-hole/php/FTL.php index 91cffdd2..c483ecba 100644 --- a/scripts/pi-hole/php/FTL.php +++ b/scripts/pi-hole/php/FTL.php @@ -1,4 +1,10 @@ diff --git a/scripts/pi-hole/php/auth.php b/scripts/pi-hole/php/auth.php index b1c22aea..77871e4d 100644 --- a/scripts/pi-hole/php/auth.php +++ b/scripts/pi-hole/php/auth.php @@ -4,9 +4,8 @@ * Network-wide ad blocking via your own hardware. * * This file is copyright under the latest version of the EUPL. -* Please see LICENSE file for your rights under this license. */ ?> +* Please see LICENSE file for your rights under this license. */ -format('Y-m-d\TH:i:s')] = $status; + $allQueries['data'][hasHostName($client)][$domain][$time->format('Y-m-d T H:i:s')] = $status; }elseif ($orderBy == "orderByClientTimeDomain"){ - $allQueries['data'][hasHostName($client)][$time->format('Y-m-d\TH:i:s')][$domain] = $status; + $allQueries['data'][hasHostName($client)][$time->format('Y-m-d T H:i:s')][$domain] = $status; }elseif ($orderBy == "orderByTimeClientDomain"){ - $allQueries['data'][$time->format('Y-m-d\TH:i:s')][hasHostName($client)][$domain] = $status; + $allQueries['data'][$time->format('Y-m-d T H:i:s')][hasHostName($client)][$domain] = $status; }elseif ($orderBy == "orderByTimeDomainClient"){ - $allQueries['data'][$time->format('Y-m-d\TH:i:s')][$domain][hasHostName($client)] = $status; + $allQueries['data'][$time->format('Y-m-d T H:i:s')][$domain][hasHostName($client)] = $status; }elseif ($orderBy == "orderByDomainClientTime"){ - $allQueries['data'][$domain][hasHostName($client)][$time->format('Y-m-d\TH:i:s')] = $status; + $allQueries['data'][$domain][hasHostName($client)][$time->format('Y-m-d T H:i:s')] = $status; }elseif ($orderBy == "orderByDomainTimeClient"){ - $allQueries['data'][$domain][$time->format('Y-m-d\TH:i:s')][hasHostName($client)] = $status; + $allQueries['data'][$domain][$time->format('Y-m-d T H:i:s')][hasHostName($client)] = $status; }else{ array_push($allQueries['data'], array( - $time->format('Y-m-d\TH:i:s'), + $time->format('Y-m-d T H:i:s'), $type, $domain, hasHostName($client), diff --git a/scripts/pi-hole/php/footer.php b/scripts/pi-hole/php/footer.php index 1633420b..34d7319f 100644 --- a/scripts/pi-hole/php/footer.php +++ b/scripts/pi-hole/php/footer.php @@ -9,6 +9,36 @@ + +