diff --git a/api.php b/api.php
index 3c3ad7d1..150dc9e2 100644
--- a/api.php
+++ b/api.php
@@ -77,7 +77,7 @@
}
if (isset($_GET['getGravityDomains'])) {
- $data = array_merge($data, getGravityDomains($gravity));
+ $data = array_merge($data, getGravity());
}
function filterArray(&$inArray) {
diff --git a/data.php b/data.php
index e08b1ac0..23c48b02 100644
--- a/data.php
+++ b/data.php
@@ -5,6 +5,8 @@
$hosts = file_exists("/etc/hosts") ? file("/etc/hosts") : array();
$log = new \SplFileObject('/var/log/pihole.log');
$gravity = new \SplFileObject('/etc/pihole/list.preEventHorizon');
+ $whitelist = new \SplFileObject('/etc/pihole/whitelist.txt');
+ $blacklist = new \SplFileObject('/etc/pihole/blacklist.txt');
/******* Public Members ********/
function getSummaryData() {
@@ -163,7 +165,7 @@
$showBlocked = true;
$showPermitted = false;
}
- elseif($setupVars["API_QUERY_LOG_SHOW"] === "none")
+ elseif($setupVars["API_QUERY_LOG_SHOW"] === "nothing")
{
$showBlocked = false;
$showPermitted = false;
@@ -183,10 +185,12 @@
}
function getAllQueries($orderBy) {
- global $log,$gravity,$showBlocked,$showPermitted;
+ global $log,$showBlocked,$showPermitted;
$allQueries = array("data" => array());
$dns_queries = getDnsQueriesAll($log);
- $gravity_domains = getGravityDomains($gravity);
+
+ // Create empty array for gravity
+ $gravity_domains = getGravity();
foreach ($dns_queries as $query) {
$time = date_create(substr($query, 0, 16));
@@ -265,16 +269,41 @@
return $lines;
}
- function getGravityDomains($gravity){
- $gravity->rewind();
- $lines=[];
- foreach ($gravity as $line) {
- // Strip newline (and possibly carriage return) from end of string
- // using rtrim()
- $lines[rtrim($line)] = true;
+ function getDomains($file, &$array, $action){
+ $file->rewind();
+ foreach ($file as $line) {
+ // Strip newline (and possibly carriage return) from end of key
+ $key = rtrim($line);
+ // if $action = true -> we want that domain to be ADDED to the list
+ // doesn't harm to do this if it has already been set before
+ // (e.g. once in gravity list, once in blacklist)
+ if($action && strlen($key) > 0)
+ {
+ // $action is true (we want to add) *and* key is not empty
+ $array[$key] = true;
+ }
+ elseif(!$action && isset($array[$key]))
+ {
+ // $action is false (we want to remove) *and* key is set
+ unset($array[$key]);
+ }
}
+ }
- return $lines;
+ function getGravity() {
+ global $gravity,$whitelist,$blacklist;
+ $domains = [];
+
+ // ADD (true) preEventHorizon domains
+ getDomains($gravity, $domains, true);
+
+ // ADD (true) blacklist domains
+ getDomains($blacklist, $domains, true);
+
+ // REMOVE (false) whitelist domains
+ getDomains($whitelist, $domains, false);
+
+ return $domains;
}
function getBlockedQueries(\SplFileObject $log) {
diff --git a/header.php b/header.php
index ca688c30..39146967 100644
--- a/header.php
+++ b/header.php
@@ -4,18 +4,46 @@
check_cors();
- $cmd = "echo $((`cat /sys/class/thermal/thermal_zone0/temp | cut -c1-2`))";
- $output = shell_exec($cmd);
- $celsius = str_replace(array("\r\n","\r","\n"),"", $output);
- $fahrenheit = round(str_replace(["\r\n","\r","\n"],"", $output*9./5)+32);
-
- if(isset($setupVars['TEMPERATUREUNIT']))
+ // Try to get temperature value from different places (OS dependent)
+ if(file_exists("/sys/class/thermal/thermal_zone0/temp"))
{
- $temperatureunit = $setupVars['TEMPERATUREUNIT'];
+ $output = rtrim(file_get_contents("/sys/class/thermal/thermal_zone0/temp"));
+ }
+ elseif (file_exists("/sys/class/hwmon/hwmon0/temp1_input"))
+ {
+ $output = rtrim(file_get_contents("/sys/class/hwmon/hwmon0/temp1_input"));
}
else
{
- $temperatureunit = "C";
+ $output = "";
+ }
+
+ // Test if we succeeded in getting the temperature
+ if(is_numeric($output))
+ {
+ $celsius = intVal($output)*1e-3;
+ $kelvin = $celsius + 273.15;
+ $fahrenheit = ($celsius*9./5)+32.0;
+
+ if(isset($setupVars['TEMPERATUREUNIT']))
+ {
+ $temperatureunit = $setupVars['TEMPERATUREUNIT'];
+ }
+ else
+ {
+ $temperatureunit = "C";
+ }
+ // Override temperature unit setting if it is changed via Settings page
+ if(isset($_POST["tempunit"]))
+ {
+ $temperatureunit = $_POST["tempunit"];
+ }
+ }
+ else
+ {
+ // Nothing can be colder than -273.15 degree Celsius (= 0 Kelvin)
+ // This is the minimum temperature possible (AKA absolute zero)
+ $celsius = -273.16;
}
// Get load
@@ -30,9 +58,12 @@
if(count($data) > 0)
{
foreach ($data as $line) {
- list($key, $val) = explode(":", $line);
- // remove " kB" fron the end of the string and make an integer
- $meminfo[$key] = intVal(substr(trim($val),0, -3));
+ $expl = explode(":", trim($line));
+ if(count($expl) == 2)
+ {
+ // remove " kB" from the end of the string and make it an integer
+ $meminfo[$expl[0]] = intVal(substr($expl[1],0, -3));
+ }
}
$memory_used = $meminfo["MemTotal"]-$meminfo["MemFree"]-$meminfo["Buffers"]-$meminfo["Cached"];
$memory_total = $meminfo["MemTotal"];
@@ -69,7 +100,7 @@
$boxedlayout = true;
}
- // Override layout setting if layout is changed via Settings page3
+ // Override layout setting if layout is changed via Settings page
if(isset($_POST["field"]))
{
if($_POST["field"] === "webUI" && isset($_POST["boxedlayout"]))
@@ -224,20 +255,30 @@
}
// CPU Temp
- echo '= -273.15) {
+ echo " 45) {
+ echo "#FF0000";
+ }
+ else
+ {
+ echo "#3366FF";
+ }
+ echo "\"> Temp: ";
+ if($temperatureunit === "F")
+ {
+ echo round($fahrenheit,1) . "°F";
+ }
+ elseif($temperatureunit === "K")
+ {
+ echo round($kelvin,1) . "K";
+ }
+ else
+ {
+ echo round($celsius,1) . "°C";
+ }
+ echo "";
}
- else
- {
- echo '#3366FF';
- }
- echo '"> Temp: ';
- if($temperatureunit != "F")
- echo $celsius . '°C';
- else
- echo $fahrenheit . '°F';
- echo '';
?>
0)
+ {
+ percentage = 100.0*blocked/total;
+ }
+ return data.datasets[tooltipItems.datasetIndex].label + ": " + tooltipItems.yLabel + " (" + percentage.toFixed(1) + "%)";
+ }
+ else
+ {
+ return data.datasets[tooltipItems.datasetIndex].label + ": " + tooltipItems.yLabel;
+ }
}
}
},
diff --git a/php/savesettings.php b/php/savesettings.php
index 27fa763c..4dd357c5 100644
--- a/php/savesettings.php
+++ b/php/savesettings.php
@@ -65,7 +65,14 @@ function validDomain($domain_name)
// Get secondary DNS server IP address
if($secondaryDNS === "Custom")
{
- $secondaryIP = $_POST["DNS2IP"];
+ if(strlen($_POST["DNS2IP"]) > 0)
+ {
+ $secondaryIP = $_POST["DNS2IP"];
+ }
+ else
+ {
+ $secondaryIP = "none";
+ }
}
else
{
@@ -73,7 +80,7 @@ function validDomain($domain_name)
}
// Validate secondary IP
- if (!validIP($secondaryIP) && strlen($secondaryIP) > 0)
+ if (!validIP($secondaryIP) && $secondaryIP != "none" && strlen($secondaryIP) > 0)
{
$error .= "Secondary IP (".$secondaryIP.") is invalid!
";
}
@@ -205,7 +212,7 @@ function validDomain($domain_name)
}
else
{
- exec("sudo pihole -a setquerylog none");
+ exec("sudo pihole -a setquerylog nothing");
$success .= "No entries will be shown in Query Log";
}
@@ -215,12 +222,14 @@ function validDomain($domain_name)
if($_POST["tempunit"] == "F")
{
exec('sudo pihole -a -f');
- $success .= "The webUI settings have been updated";
+ }
+ elseif($_POST["tempunit"] == "K")
+ {
+ exec('sudo pihole -a -k');
}
else
{
exec('sudo pihole -a -c');
- $success .= "The webUI settings have been updated";
}
if(isset($_POST["boxedlayout"]))
{
@@ -230,6 +239,7 @@ function validDomain($domain_name)
{
exec('sudo pihole -a layout traditional');
}
+ $success .= "The webUI settings have been updated";
break;
case "reboot":
diff --git a/queries.php b/queries.php
index 153b5cbf..8907367f 100644
--- a/queries.php
+++ b/queries.php
@@ -23,6 +23,10 @@ if(isset($setupVars["API_QUERY_LOG_SHOW"]))
{
$showing = "(showing blocked queries only)";
}
+ elseif($setupVars["API_QUERY_LOG_SHOW"] === "nothing")
+ {
+ $showing = "(showing no queries at all)";
+ }
}
?>
diff --git a/settings.php b/settings.php
index ed2e7b0b..87bfc815 100644
--- a/settings.php
+++ b/settings.php
@@ -140,7 +140,7 @@
disabled>
-
+