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:
@@ -3,10 +3,22 @@
|
||||
$setupVars = parse_ini_file("/etc/pihole/setupVars.conf");
|
||||
|
||||
$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');
|
||||
|
||||
// Check if pihole.log exists and is readable
|
||||
$logListName = checkfile("/var/log/pihole.log");
|
||||
$log = new \SplFileObject($logListName);
|
||||
|
||||
// Check if preEventHorizon exists and is readable
|
||||
$gravityListName = checkfile("/etc/pihole/list.preEventHorizon");
|
||||
$gravity = new \SplFileObject($gravityListName);
|
||||
|
||||
// whitelist.txt is optional and might not be there
|
||||
$whiteListFile = checkfile("/etc/pihole/whitelist.txt");
|
||||
$whitelist = new \SplFileObject($whiteListFile);
|
||||
|
||||
// blacklist.txt is optional and might not be there
|
||||
$blackListFile = checkfile("/etc/pihole/blacklist.txt");
|
||||
$blacklist = new \SplFileObject($blackListFile);
|
||||
|
||||
/******* Public Members ********/
|
||||
function getSummaryData() {
|
||||
@@ -238,8 +250,9 @@
|
||||
|
||||
/******** Private Members ********/
|
||||
function gravityCount() {
|
||||
$preEventHorizon = exec("grep -c ^ /etc/pihole/list.preEventHorizon");
|
||||
$blacklist = exec("grep -c ^ /etc/pihole/blacklist.txt");
|
||||
global $gravityListName,$blackListFile;
|
||||
$preEventHorizon = exec("grep -c ^ $gravityListName");
|
||||
$blacklist = exec("grep -c ^ $blackListFile");
|
||||
return ($preEventHorizon + $blacklist);
|
||||
}
|
||||
|
||||
@@ -255,7 +268,8 @@
|
||||
}
|
||||
|
||||
function countDnsQueries() {
|
||||
return exec("grep -c \": query\\[\" /var/log/pihole.log");
|
||||
global $logListName;
|
||||
return exec("grep -c \": query\\[\" $logListName");
|
||||
}
|
||||
|
||||
function getDnsQueriesAll(\SplFileObject $log) {
|
||||
@@ -350,7 +364,8 @@
|
||||
}
|
||||
|
||||
function countBlockedQueries() {
|
||||
return exec("grep \"gravity.list\" /var/log/pihole.log | grep -c \" is \"");
|
||||
global $logListName;
|
||||
return exec("grep \"gravity.list\" $logListName | grep -c \" is \"");
|
||||
}
|
||||
|
||||
function getForwards(\SplFileObject $log) {
|
||||
|
||||
+14
-3
@@ -15,9 +15,12 @@ function log_and_die($message) {
|
||||
}
|
||||
|
||||
function check_cors() {
|
||||
$setupVars = parse_ini_file("/etc/pihole/setupVars.conf");
|
||||
$ipv4 = isset($setupVars["IPV4_ADDRESS"]) ? explode("/", $setupVars["IPV4_ADDRESS"])[0] : $_SERVER['SERVER_ADDR'];
|
||||
|
||||
// Check CORS
|
||||
$AUTHORIZED_HOSTNAMES = array(
|
||||
'http://' . $_SERVER['SERVER_ADDR'],
|
||||
'http://' . $ipv4,
|
||||
'http://' . $_SERVER['SERVER_NAME'],
|
||||
'http://pi.hole',
|
||||
'http://localhost'
|
||||
@@ -30,8 +33,16 @@ function check_cors() {
|
||||
|
||||
// Since the Host header is easily manipulated, we can only check if it's wrong and can't use it
|
||||
// to validate that the client is authorized, only unauthorized.
|
||||
if(isset($_SERVER['HTTP_HOST']) && !in_array("http://".$_SERVER['HTTP_HOST'], $AUTHORIZED_HOSTNAMES)) {
|
||||
log_and_die("Failed Host Check: " . $_SERVER['HTTP_HOST'] .' vs '. join(', ', $AUTHORIZED_HOSTNAMES));
|
||||
$server_host = $_SERVER['HTTP_HOST'];
|
||||
|
||||
// If HTTP_HOST contains a non-standard port (!= 80) we have to strip the port
|
||||
if(strpos($server_host,":"))
|
||||
{
|
||||
$server_host = parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST);
|
||||
}
|
||||
|
||||
if(isset($_SERVER['HTTP_HOST']) && !in_array("http://".$server_host, $AUTHORIZED_HOSTNAMES)) {
|
||||
log_and_die("Failed Host Check: " . $server_host .' vs '. join(', ', $AUTHORIZED_HOSTNAMES));
|
||||
}
|
||||
|
||||
if(isset($_SERVER['HTTP_ORIGIN'])) {
|
||||
|
||||
+13
-1
@@ -7,4 +7,16 @@ function is_valid_domain_name($domain_name)
|
||||
preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name)); //length of each label
|
||||
}
|
||||
|
||||
?>
|
||||
function checkfile($filename) {
|
||||
if(is_readable($filename))
|
||||
{
|
||||
return $filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
// substitute dummy file
|
||||
return "/dev/null";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
+3
-1
@@ -7,7 +7,9 @@ $type = $_GET['list'];
|
||||
if($type !== "white" && $type !== "black")
|
||||
die("Invalid list parameter");
|
||||
|
||||
$rawList = file_get_contents("/etc/pihole/${type}list.txt");
|
||||
require "func.php";
|
||||
|
||||
$rawList = file_get_contents(checkfile("/etc/pihole/${type}list.txt"));
|
||||
$list = explode("\n", $rawList);
|
||||
|
||||
// Get rid of empty lines
|
||||
|
||||
+13
-6
@@ -106,10 +106,17 @@
|
||||
{
|
||||
$DHCP = false;
|
||||
// Try to guess initial settings
|
||||
$DHCPdomain = explode(".",$piHoleIPv4);
|
||||
$DHCPstart = $DHCPdomain[0].".".$DHCPdomain[1].".".$DHCPdomain[2].".201";
|
||||
$DHCPend = $DHCPdomain[0].".".$DHCPdomain[1].".".$DHCPdomain[2].".251";
|
||||
$DHCProuter = $DHCPdomain[0].".".$DHCPdomain[1].".".$DHCPdomain[2].".1";
|
||||
if($piHoleIPv4 !== "unknown") {
|
||||
$DHCPdomain = explode(".",$piHoleIPv4);
|
||||
$DHCPstart = $DHCPdomain[0].".".$DHCPdomain[1].".".$DHCPdomain[2].".201";
|
||||
$DHCPend = $DHCPdomain[0].".".$DHCPdomain[1].".".$DHCPdomain[2].".251";
|
||||
$DHCProuter = $DHCPdomain[0].".".$DHCPdomain[1].".".$DHCPdomain[2].".1";
|
||||
}
|
||||
else {
|
||||
$DHCPstart = "";
|
||||
$DHCPend = "";
|
||||
$DHCProuter = "";
|
||||
}
|
||||
}
|
||||
if(isset($setupVars["PIHOLE_DOMAIN"])){
|
||||
$piHoleDomain = $setupVars["PIHOLE_DOMAIN"];
|
||||
@@ -361,7 +368,7 @@
|
||||
{
|
||||
$excludedDomains = explode(",", $setupVars["API_EXCLUDE_DOMAINS"]);
|
||||
} else {
|
||||
$excludedDomains = "";
|
||||
$excludedDomains = [];
|
||||
}
|
||||
|
||||
// Exluded clients in API Query Log call
|
||||
@@ -369,7 +376,7 @@
|
||||
{
|
||||
$excludedClients = explode(",", $setupVars["API_EXCLUDE_CLIENTS"]);
|
||||
} else {
|
||||
$excludedClients = "";
|
||||
$excludedClients = [];
|
||||
}
|
||||
|
||||
// Exluded clients
|
||||
|
||||
Reference in New Issue
Block a user