diff --git a/api.php b/api.php index cadf27a9..0edea9cd 100644 --- a/api.php +++ b/api.php @@ -1,13 +1,18 @@ @@ -134,6 +139,7 @@
Updates
+
Session is valid for 0){echo $maxlifetime;}else{echo "0";} ?>
+
  • @@ -270,18 +277,41 @@ echo '
  • Enable
  • '; } ?> + + 0) { ?> +
  • + + Logout + +
  • + + + + 0 && !$auth) { ?> +
  • + + Login + +
  • +
  • Donate
  • +
  • Help
  • + @@ -290,3 +320,25 @@
    + + +
    + Password:   +
    + diff --git a/index.php b/index.php index 66cac0f8..e3f43a04 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,5 @@ @@ -75,7 +76,12 @@
    - +
    @@ -195,7 +201,7 @@
    - + diff --git a/js/pihole/footer.js b/js/pihole/footer.js index c47eb9ff..2f6a8758 100644 --- a/js/pihole/footer.js +++ b/js/pihole/footer.js @@ -55,3 +55,42 @@ $.getJSON("https://api.github.com/repos/pi-hole/AdminLTE/releases/latest", funct */ if(piholeVersion !== "vDev" && versionCompare(piholeVersion, "v2.7") < 0) alert("Pi-hole needs to be updated to at least v2.7 before you can use features such as whitelisting/blacklisting from this web interface!") + +// Session timer +var sessionvalidity = parseInt(document.getElementById("sessiontimercounter").textContent); +var start = new Date; + +function updateSessionTimer() +{ + start = new Date; + start.setSeconds(start.getSeconds() + sessionvalidity); +} + +if(sessionvalidity > 0) +{ + // setSeconds will correctly handle wrap-around cases + updateSessionTimer(); + + setInterval(function() { + var current = new Date; + var totalseconds = (start - current) / 1000; + + // var hours = Math.floor(totalseconds / 3600); + // totalseconds = totalseconds % 3600; + + var minutes = Math.floor(totalseconds / 60); + if(minutes < 10){ minutes = "0" + minutes; } + + var seconds = Math.floor(totalseconds % 60); + if(seconds < 10){ seconds = "0" + seconds; } + + if(totalseconds > 0) + document.getElementById("sessiontimercounter").textContent = minutes + ":" + seconds; + else + document.getElementById("sessiontimercounter").textContent = "-- : --"; + }, 1000); +} +else +{ + document.getElementById("sessiontimer").style.display = "none"; +} diff --git a/js/pihole/header.js b/js/pihole/header.js index 82d112db..132f4fa2 100644 --- a/js/pihole/header.js +++ b/js/pihole/header.js @@ -1,3 +1,3 @@ // Remove JS warning var jswarn = document.getElementById("js-warn-exit"); -jswarn.parentNode.removeChild(jswarn); \ No newline at end of file +jswarn.parentNode.removeChild(jswarn); diff --git a/js/pihole/index.js b/js/pihole/index.js index 5d22efdd..5588c24b 100644 --- a/js/pihole/index.js +++ b/js/pihole/index.js @@ -24,7 +24,7 @@ $(document).ready(function() { return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows()); } }; - var animate = false; + var ctx = document.getElementById("queryOverTimeChart").getContext("2d"); timeLineChart = new Chart(ctx, { type: "line", @@ -96,55 +96,70 @@ $(document).ready(function() { } }); - ctx = document.getElementById("queryTypeChart").getContext("2d"); - queryTypeChart = new Chart(ctx, { - type: "doughnut", - data: { - labels: [], - datasets: [{ data: [] }] - }, - options: { - legend: { - display: false - }, - animation: { - duration: 2000 - }, - cutoutPercentage: 0 - } - }); - - ctx = document.getElementById("forwardDestinationChart").getContext("2d"); - forwardDestinationChart = new Chart(ctx, { - type: "doughnut", - data: { - labels: [], - datasets: [{ data: [] }] - }, - options: { - legend: { - display: false - }, - animation: { - duration: 2000 - }, - cutoutPercentage: 0 - } - }); - // Pull in data via AJAX updateSummaryData(); updateQueriesOverTime(); - updateQueryTypes(); + // Create / load "Query Types" only if authorized + if(!!document.getElementById("queryTypeChart")) + { + ctx = document.getElementById("queryTypeChart").getContext("2d"); + queryTypeChart = new Chart(ctx, { + type: "doughnut", + data: { + labels: [], + datasets: [{ data: [] }] + }, + options: { + legend: { + display: false + }, + animation: { + duration: 2000 + }, + cutoutPercentage: 0 + } + }); + updateQueryTypes(); + } - updateTopClientsChart(); + // Create / load "Forward Destinations" only if authorized + if(!!document.getElementById("forwardDestinationChart")) + { + ctx = document.getElementById("forwardDestinationChart").getContext("2d"); + forwardDestinationChart = new Chart(ctx, { + type: "doughnut", + data: { + labels: [], + datasets: [{ data: [] }] + }, + options: { + legend: { + display: false + }, + animation: { + duration: 2000 + }, + cutoutPercentage: 0 + } + }); + updateForwardDestinations(); + } - updateForwardDestinations(); + // Create / load "Top Domains" and "Top Advertisers" only if authorized + if(!!document.getElementById("domain-frequency") + && !!document.getElementById("ad-frequency")) + { + updateTopLists(); + } - updateTopLists(); + // Create / load "Top Clients" only if authorized + if(!!document.getElementById("client-frequency")) + { + updateTopClientsChart(); + } }); // Functions to update data in page @@ -169,6 +184,8 @@ function updateSummaryData(runOnce) { $("h3#ads_percentage_today").text(data.ads_percentage_today + "%"); $("h3.statistic.glow").removeClass("glow") }, 500); + + updateSessionTimer(); }).done(function() { if (runOnce !== true) { setTimeout(updateSummaryData, 10000); diff --git a/js/pihole/queries.js b/js/pihole/queries.js index e8af78a8..c8225ab2 100644 --- a/js/pihole/queries.js +++ b/js/pihole/queries.js @@ -72,6 +72,7 @@ $(document).ready(function() { function refreshData() { tableApi.ajax.url("api.php?getAllQueries").load(); +// updateSessionTimer(); } function add(domain,list) { diff --git a/php/gravity.sh.php b/php/gravity.sh.php index 80dcb385..257cfa3c 100644 --- a/php/gravity.sh.php +++ b/php/gravity.sh.php @@ -1,4 +1,7 @@ 0) + { + // Compare doubly hashes password input with saved hash + if(isset($_POST["pw"])) + { + $postinput = hash('sha256',hash('sha256',$_POST["pw"])); + if($postinput == $pwhash) + { + $_SESSION["hash"] = $pwhash; + $auth = true; + } + } + // Compare auth hash with saved hash + else if (isset($_SESSION["hash"])) + { + if($_SESSION["hash"] == $pwhash) + $auth = true; + } + // API can use the hash to get data without logging in via plain-text password + else if (isset($api) && isset($_GET["auth"])) + { + if($_GET["auth"] == $pwhash) + $auth = true; + } + else + { + // Password or hash wrong + $auth = false; + } + } + else + { + // No password set + $auth = true; + } +?> diff --git a/php/queryads.php b/php/queryads.php index eedb4a22..e77ee223 100644 --- a/php/queryads.php +++ b/php/queryads.php @@ -1,4 +1,7 @@