mirror of
https://github.com/pi-hole/web.git
synced 2024-12-06 19:36:21 +01:00
Merge branch 'devel' into overhaulGetBlockesQueries
This commit is contained in:
@@ -77,7 +77,7 @@
|
||||
}
|
||||
|
||||
if (isset($_GET['getGravityDomains'])) {
|
||||
$data = array_merge($data, getGravityDomains($gravity));
|
||||
$data = array_merge($data, getGravity());
|
||||
}
|
||||
|
||||
function filterArray(&$inArray) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+66
-25
@@ -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 '<a href="#" id="temperature"><i class="fa fa-fire" style="color:';
|
||||
if ($celsius > "45") {
|
||||
echo '#FF0000';
|
||||
if ($celsius >= -273.15) {
|
||||
echo "<a href=\"#\" id=\"temperature\"><i class=\"fa fa-fire\" style=\"color:";
|
||||
if ($celsius > 45) {
|
||||
echo "#FF0000";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "#3366FF";
|
||||
}
|
||||
echo "\"></i> Temp: ";
|
||||
if($temperatureunit === "F")
|
||||
{
|
||||
echo round($fahrenheit,1) . "°F";
|
||||
}
|
||||
elseif($temperatureunit === "K")
|
||||
{
|
||||
echo round($kelvin,1) . "K";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo round($celsius,1) . "°C";
|
||||
}
|
||||
echo "</a>";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo '#3366FF';
|
||||
}
|
||||
echo '"></i> Temp: ';
|
||||
if($temperatureunit != "F")
|
||||
echo $celsius . '°C';
|
||||
else
|
||||
echo $fahrenheit . '°F';
|
||||
echo '</a>';
|
||||
?>
|
||||
<br/>
|
||||
<?php
|
||||
|
||||
@@ -282,6 +282,23 @@ $(document).ready(function() {
|
||||
var from = padNumber(h)+":"+padNumber(m)+":00";
|
||||
var to = padNumber(h)+":"+padNumber(m+9)+":59";
|
||||
return "Queries from "+from+" to "+to;
|
||||
},
|
||||
label(tooltipItems, data) {
|
||||
if(tooltipItems.datasetIndex === 1)
|
||||
{
|
||||
var percentage = 0.0;
|
||||
var total = parseInt(data.datasets[0].data[tooltipItems.index]);
|
||||
var blocked = parseInt(data.datasets[1].data[tooltipItems.index]);
|
||||
if(total > 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
+15
-5
@@ -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!<br>";
|
||||
}
|
||||
@@ -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":
|
||||
|
||||
@@ -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)";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
+2
-1
@@ -140,7 +140,7 @@
|
||||
<input type="text" class="form-control DHCPgroup" name="to" value="<?php echo $DHCPend; ?>" data-inputmask="'alias': 'ip'" data-mask <?php if(!$DHCP){ ?>disabled<?php } ?>>
|
||||
</div>
|
||||
</div>
|
||||
<label>Router IP address</label>
|
||||
<label>Router (gateway) IP address</label>
|
||||
<div class="col-md-12">
|
||||
<div class="input-group">
|
||||
<div class="input-group-addon">Router</div>
|
||||
@@ -452,6 +452,7 @@
|
||||
<h4>CPU Temperature Unit</h4>
|
||||
<div class="form-group">
|
||||
<div class="radio"><label><input type="radio" name="tempunit" value="C" <?php if($temperatureunit === "C"){ ?>checked<?php } ?> >Celsius</label></div>
|
||||
<div class="radio"><label><input type="radio" name="tempunit" value="K" <?php if($temperatureunit === "K"){ ?>checked<?php } ?> >Kelvin</label></div>
|
||||
<div class="radio"><label><input type="radio" name="tempunit" value="F" <?php if($temperatureunit === "F"){ ?>checked<?php } ?> >Fahrenheit</label></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user