mirror of
https://github.com/pi-hole/web.git
synced 2026-02-15 07:25:39 +00:00
Replacing tabs with 4 spaces
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
This commit is contained in:
12
api.php
12
api.php
@@ -73,17 +73,17 @@ elseif (isset($_GET['versions']))
|
||||
// suppressed if on development branches)
|
||||
require "scripts/pi-hole/php/update_checker.php";
|
||||
$updates = array("core_update" => $core_update,
|
||||
"web_update" => $web_update,
|
||||
"FTL_update" => $FTL_update);
|
||||
"web_update" => $web_update,
|
||||
"FTL_update" => $FTL_update);
|
||||
$current = array("core_current" => $core_current,
|
||||
"web_current" => $web_current,
|
||||
"FTL_current" => $FTL_current);
|
||||
"web_current" => $web_current,
|
||||
"FTL_current" => $FTL_current);
|
||||
$latest = array("core_latest" => $core_latest,
|
||||
"web_latest" => $web_latest,
|
||||
"FTL_latest" => $FTL_latest);
|
||||
$branches = array("core_branch" => $core_branch,
|
||||
"web_branch" => $web_branch,
|
||||
"FTL_branch" => $FTL_branch);
|
||||
"web_branch" => $web_branch,
|
||||
"FTL_branch" => $FTL_branch);
|
||||
$data = array_merge($data, $updates);
|
||||
$data = array_merge($data, $current);
|
||||
$data = array_merge($data, $latest);
|
||||
|
||||
@@ -51,11 +51,11 @@ require "scripts/pi-hole/php/header.php";
|
||||
<?php
|
||||
if($boxedlayout)
|
||||
{
|
||||
$tablelayout = "col-md-6";
|
||||
$tablelayout = "col-md-6";
|
||||
}
|
||||
else
|
||||
{
|
||||
$tablelayout = "col-md-6 col-lg-4";
|
||||
$tablelayout = "col-md-6 col-lg-4";
|
||||
}
|
||||
?>
|
||||
<div class="row">
|
||||
|
||||
@@ -12,7 +12,7 @@ require "scripts/pi-hole/php/header.php";
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="box" id="network-details">
|
||||
<div class="box" id="network-details">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">Network overview</h3>
|
||||
</div>
|
||||
|
||||
96
queries.php
96
queries.php
@@ -14,87 +14,87 @@ $showing = "";
|
||||
|
||||
if(isset($setupVars["API_QUERY_LOG_SHOW"]))
|
||||
{
|
||||
if($setupVars["API_QUERY_LOG_SHOW"] === "all")
|
||||
{
|
||||
$showing = "showing";
|
||||
}
|
||||
elseif($setupVars["API_QUERY_LOG_SHOW"] === "permittedonly")
|
||||
{
|
||||
$showing = "showing permitted";
|
||||
}
|
||||
elseif($setupVars["API_QUERY_LOG_SHOW"] === "blockedonly")
|
||||
{
|
||||
$showing = "showing blocked";
|
||||
}
|
||||
elseif($setupVars["API_QUERY_LOG_SHOW"] === "nothing")
|
||||
{
|
||||
$showing = "showing no queries (due to setting)";
|
||||
}
|
||||
if($setupVars["API_QUERY_LOG_SHOW"] === "all")
|
||||
{
|
||||
$showing = "showing";
|
||||
}
|
||||
elseif($setupVars["API_QUERY_LOG_SHOW"] === "permittedonly")
|
||||
{
|
||||
$showing = "showing permitted";
|
||||
}
|
||||
elseif($setupVars["API_QUERY_LOG_SHOW"] === "blockedonly")
|
||||
{
|
||||
$showing = "showing blocked";
|
||||
}
|
||||
elseif($setupVars["API_QUERY_LOG_SHOW"] === "nothing")
|
||||
{
|
||||
$showing = "showing no queries (due to setting)";
|
||||
}
|
||||
}
|
||||
else if(isset($_GET["type"]) && $_GET["type"] === "blocked")
|
||||
{
|
||||
$showing = "showing blocked";
|
||||
$showing = "showing blocked";
|
||||
}
|
||||
else
|
||||
{
|
||||
// If filter variable is not set, we
|
||||
// automatically show all queries
|
||||
$showing = "showing";
|
||||
// If filter variable is not set, we
|
||||
// automatically show all queries
|
||||
$showing = "showing";
|
||||
}
|
||||
|
||||
$showall = false;
|
||||
if(isset($_GET["all"]))
|
||||
{
|
||||
$showing .= " all queries within the Pi-hole log";
|
||||
$showing .= " all queries within the Pi-hole log";
|
||||
}
|
||||
else if(isset($_GET["client"]))
|
||||
{
|
||||
// Add switch between showing all queries and blocked only
|
||||
if (isset($_GET["type"]) && $_GET["type"] === "blocked")
|
||||
{
|
||||
// Show blocked queries for this client + link to all
|
||||
$showing .= " blocked queries for client ".htmlentities($_GET["client"]);
|
||||
$showing .= ", <a href=\"?client=".htmlentities($_GET["client"])."\">show all</a>";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Show All queries for this client + link to show only blocked
|
||||
$showing .= " all queries for client ".htmlentities($_GET["client"]);
|
||||
$showing .= ", <a href=\"?client=".htmlentities($_GET["client"])."&type=blocked\">show blocked only</a>";
|
||||
}
|
||||
// Add switch between showing all queries and blocked only
|
||||
if (isset($_GET["type"]) && $_GET["type"] === "blocked")
|
||||
{
|
||||
// Show blocked queries for this client + link to all
|
||||
$showing .= " blocked queries for client ".htmlentities($_GET["client"]);
|
||||
$showing .= ", <a href=\"?client=".htmlentities($_GET["client"])."\">show all</a>";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Show All queries for this client + link to show only blocked
|
||||
$showing .= " all queries for client ".htmlentities($_GET["client"]);
|
||||
$showing .= ", <a href=\"?client=".htmlentities($_GET["client"])."&type=blocked\">show blocked only</a>";
|
||||
}
|
||||
}
|
||||
else if(isset($_GET["forwarddest"]))
|
||||
{
|
||||
if($_GET["forwarddest"] === "blocked")
|
||||
$showing .= " queries blocked by Pi-hole";
|
||||
elseif($_GET["forwarddest"] === "cached")
|
||||
$showing .= " queries answered from cache";
|
||||
else
|
||||
$showing .= " queries for upstream destination ".htmlentities($_GET["forwarddest"]);
|
||||
if($_GET["forwarddest"] === "blocked")
|
||||
$showing .= " queries blocked by Pi-hole";
|
||||
elseif($_GET["forwarddest"] === "cached")
|
||||
$showing .= " queries answered from cache";
|
||||
else
|
||||
$showing .= " queries for upstream destination ".htmlentities($_GET["forwarddest"]);
|
||||
}
|
||||
else if(isset($_GET["querytype"]))
|
||||
{
|
||||
$showing .= " type ".getQueryTypeStr($_GET["querytype"])." queries";
|
||||
$showing .= " type ".getQueryTypeStr($_GET["querytype"])." queries";
|
||||
}
|
||||
else if(isset($_GET["domain"]))
|
||||
{
|
||||
$showing .= " queries for domain ".htmlentities($_GET["domain"]);
|
||||
$showing .= " queries for domain ".htmlentities($_GET["domain"]);
|
||||
}
|
||||
else if(isset($_GET["from"]) || isset($_GET["until"]))
|
||||
{
|
||||
$showing .= " queries within specified time interval";
|
||||
$showing .= " queries within specified time interval";
|
||||
}
|
||||
else
|
||||
{
|
||||
$showing .= " up to 100 queries";
|
||||
$showall = true;
|
||||
$showing .= " up to 100 queries";
|
||||
$showall = true;
|
||||
}
|
||||
|
||||
if(strlen($showing) > 0)
|
||||
{
|
||||
$showing = "(".$showing.")";
|
||||
if($showall)
|
||||
$showing .= ", <a href=\"?all\">show all</a>";
|
||||
$showing = "(".$showing.")";
|
||||
if($showall)
|
||||
$showing .= ", <a href=\"?all\">show all</a>";
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
@@ -8,23 +8,23 @@ check_cors();
|
||||
<head>
|
||||
<style>
|
||||
body {
|
||||
background: #fff;
|
||||
margin: 10px 0;
|
||||
background: #fff;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.qrcode {
|
||||
text-align: center;
|
||||
margin: 0 0 1em;
|
||||
text-align: center;
|
||||
margin: 0 0 1em;
|
||||
}
|
||||
|
||||
.qrcode svg {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.token {
|
||||
font-size: 14px;
|
||||
word-break: break-word;
|
||||
font-size: 14px;
|
||||
word-break: break-word;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
@@ -14,11 +14,11 @@ if (empty($ERRORLOG)) {
|
||||
$ERRORLOG = '/var/log/lighttpd/error-pihole.log';
|
||||
|
||||
if (!file_exists($ERRORLOG) || !is_writable($ERRORLOG)) {
|
||||
$ERRORLOG = '/var/log/apache2/error.log';
|
||||
$ERRORLOG = '/var/log/apache2/error.log';
|
||||
|
||||
if (!file_exists($ERRORLOG) || !is_writable($ERRORLOG)) {
|
||||
$ERRORLOG = '/tmp/pi-hole-error.log';
|
||||
}
|
||||
if (!file_exists($ERRORLOG) || !is_writable($ERRORLOG)) {
|
||||
$ERRORLOG = '/tmp/pi-hole-error.log';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,75 +9,75 @@
|
||||
|
||||
function getGravityDBFilename()
|
||||
{
|
||||
// Get possible non-standard location of FTL's database
|
||||
$FTLsettings = parse_ini_file("/etc/pihole/pihole-FTL.conf");
|
||||
if(isset($FTLsettings["GRAVITYDB"]))
|
||||
{
|
||||
return $FTLsettings["GRAVITYDB"];
|
||||
}
|
||||
else
|
||||
{
|
||||
return "/etc/pihole/gravity.db";
|
||||
}
|
||||
// Get possible non-standard location of FTL's database
|
||||
$FTLsettings = parse_ini_file("/etc/pihole/pihole-FTL.conf");
|
||||
if(isset($FTLsettings["GRAVITYDB"]))
|
||||
{
|
||||
return $FTLsettings["GRAVITYDB"];
|
||||
}
|
||||
else
|
||||
{
|
||||
return "/etc/pihole/gravity.db";
|
||||
}
|
||||
}
|
||||
|
||||
function getQueriesDBFilename()
|
||||
{
|
||||
// Get possible non-standard location of FTL's database
|
||||
$FTLsettings = parse_ini_file("/etc/pihole/pihole-FTL.conf");
|
||||
if(isset($FTLsettings["DBFILE"]))
|
||||
{
|
||||
return $FTLsettings["DBFILE"];
|
||||
}
|
||||
else
|
||||
{
|
||||
return "/etc/pihole/pihole-FTL.db";
|
||||
}
|
||||
// Get possible non-standard location of FTL's database
|
||||
$FTLsettings = parse_ini_file("/etc/pihole/pihole-FTL.conf");
|
||||
if(isset($FTLsettings["DBFILE"]))
|
||||
{
|
||||
return $FTLsettings["DBFILE"];
|
||||
}
|
||||
else
|
||||
{
|
||||
return "/etc/pihole/pihole-FTL.db";
|
||||
}
|
||||
}
|
||||
|
||||
function SQLite3_connect_try($filename, $mode, $trytoreconnect)
|
||||
{
|
||||
try
|
||||
{
|
||||
// connect to database
|
||||
return new SQLite3($filename, $mode);
|
||||
}
|
||||
catch (Exception $exception)
|
||||
{
|
||||
// sqlite3 throws an exception when it is unable to connect, try to reconnect after 3 seconds
|
||||
if($trytoreconnect)
|
||||
{
|
||||
sleep(3);
|
||||
return SQLite3_connect_try($filename, $mode, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we should not try again (or are already trying again!), we return the exception string
|
||||
// so the user gets it on the dashboard
|
||||
return $filename.": ".$exception->getMessage();
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
// connect to database
|
||||
return new SQLite3($filename, $mode);
|
||||
}
|
||||
catch (Exception $exception)
|
||||
{
|
||||
// sqlite3 throws an exception when it is unable to connect, try to reconnect after 3 seconds
|
||||
if($trytoreconnect)
|
||||
{
|
||||
sleep(3);
|
||||
return SQLite3_connect_try($filename, $mode, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we should not try again (or are already trying again!), we return the exception string
|
||||
// so the user gets it on the dashboard
|
||||
return $filename.": ".$exception->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function SQLite3_connect($filename, $mode=SQLITE3_OPEN_READONLY)
|
||||
{
|
||||
if(strlen($filename) > 0)
|
||||
{
|
||||
$db = SQLite3_connect_try($filename, $mode, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
die("No database available");
|
||||
}
|
||||
if(is_string($db))
|
||||
{
|
||||
die("Error connecting to database\n".$db);
|
||||
}
|
||||
if(strlen($filename) > 0)
|
||||
{
|
||||
$db = SQLite3_connect_try($filename, $mode, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
die("No database available");
|
||||
}
|
||||
if(is_string($db))
|
||||
{
|
||||
die("Error connecting to database\n".$db);
|
||||
}
|
||||
|
||||
// Add busy timeout so methods don't fail immediately when, e.g., FTL is currently reading from the DB
|
||||
$db->busyTimeout(5000);
|
||||
// Add busy timeout so methods don't fail immediately when, e.g., FTL is currently reading from the DB
|
||||
$db->busyTimeout(5000);
|
||||
|
||||
return $db;
|
||||
return $db;
|
||||
}
|
||||
|
||||
|
||||
@@ -94,125 +94,125 @@ function SQLite3_connect($filename, $mode=SQLITE3_OPEN_READONLY)
|
||||
*/
|
||||
function add_to_table($db, $table, $domains, $comment=null, $wildcardstyle=false, $returnnum=false, $type=-1)
|
||||
{
|
||||
if(!is_int($type))
|
||||
{
|
||||
return "Error: Argument type has to be of type integer (is ".gettype($type).")";
|
||||
}
|
||||
if(!is_int($type))
|
||||
{
|
||||
return "Error: Argument type has to be of type integer (is ".gettype($type).")";
|
||||
}
|
||||
|
||||
// Begin transaction
|
||||
if(!$db->exec("BEGIN TRANSACTION;"))
|
||||
{
|
||||
if($returnnum)
|
||||
return 0;
|
||||
else
|
||||
return "Error: Unable to begin transaction for $table table.";
|
||||
}
|
||||
// Begin transaction
|
||||
if(!$db->exec("BEGIN TRANSACTION;"))
|
||||
{
|
||||
if($returnnum)
|
||||
return 0;
|
||||
else
|
||||
return "Error: Unable to begin transaction for $table table.";
|
||||
}
|
||||
|
||||
// To which column should the record be added to?
|
||||
if ($table === "adlist")
|
||||
{
|
||||
$field = "address";
|
||||
}
|
||||
else
|
||||
{
|
||||
$field = "domain";
|
||||
}
|
||||
// To which column should the record be added to?
|
||||
if ($table === "adlist")
|
||||
{
|
||||
$field = "address";
|
||||
}
|
||||
else
|
||||
{
|
||||
$field = "domain";
|
||||
}
|
||||
|
||||
// Get initial count of domains in this table
|
||||
if($type === -1)
|
||||
{
|
||||
$countquery = "SELECT COUNT(*) FROM $table;";
|
||||
}
|
||||
else
|
||||
{
|
||||
$countquery = "SELECT COUNT(*) FROM $table WHERE type = $type;";
|
||||
}
|
||||
$initialcount = intval($db->querySingle($countquery));
|
||||
// Get initial count of domains in this table
|
||||
if($type === -1)
|
||||
{
|
||||
$countquery = "SELECT COUNT(*) FROM $table;";
|
||||
}
|
||||
else
|
||||
{
|
||||
$countquery = "SELECT COUNT(*) FROM $table WHERE type = $type;";
|
||||
}
|
||||
$initialcount = intval($db->querySingle($countquery));
|
||||
|
||||
// Prepare INSERT SQLite statement
|
||||
$bindcomment = false;
|
||||
if($table === "domain_audit") {
|
||||
$querystr = "INSERT OR IGNORE INTO $table ($field) VALUES (:$field);";
|
||||
} elseif($type === -1) {
|
||||
$querystr = "INSERT OR IGNORE INTO $table ($field,comment) VALUES (:$field, :comment);";
|
||||
$bindcomment = true;
|
||||
} else {
|
||||
$querystr = "REPLACE INTO $table ($field,comment,type) VALUES (:$field, :comment, $type);";
|
||||
$bindcomment = true;
|
||||
}
|
||||
$stmt = $db->prepare($querystr);
|
||||
// Prepare INSERT SQLite statement
|
||||
$bindcomment = false;
|
||||
if($table === "domain_audit") {
|
||||
$querystr = "INSERT OR IGNORE INTO $table ($field) VALUES (:$field);";
|
||||
} elseif($type === -1) {
|
||||
$querystr = "INSERT OR IGNORE INTO $table ($field,comment) VALUES (:$field, :comment);";
|
||||
$bindcomment = true;
|
||||
} else {
|
||||
$querystr = "REPLACE INTO $table ($field,comment,type) VALUES (:$field, :comment, $type);";
|
||||
$bindcomment = true;
|
||||
}
|
||||
$stmt = $db->prepare($querystr);
|
||||
|
||||
// Return early if we failed to prepare the SQLite statement
|
||||
if(!$stmt)
|
||||
{
|
||||
if($returnnum)
|
||||
return 0;
|
||||
else
|
||||
return "Error: Failed to prepare statement for $table table (type = $type, field = $field).";
|
||||
}
|
||||
// Return early if we failed to prepare the SQLite statement
|
||||
if(!$stmt)
|
||||
{
|
||||
if($returnnum)
|
||||
return 0;
|
||||
else
|
||||
return "Error: Failed to prepare statement for $table table (type = $type, field = $field).";
|
||||
}
|
||||
|
||||
// Loop over domains and inject the lines into the database
|
||||
$num = 0;
|
||||
foreach($domains as $domain)
|
||||
{
|
||||
// Limit max length for a domain entry to 253 chars
|
||||
if(strlen($domain) > 253)
|
||||
continue;
|
||||
// Loop over domains and inject the lines into the database
|
||||
$num = 0;
|
||||
foreach($domains as $domain)
|
||||
{
|
||||
// Limit max length for a domain entry to 253 chars
|
||||
if(strlen($domain) > 253)
|
||||
continue;
|
||||
|
||||
if($wildcardstyle)
|
||||
$domain = "(\\.|^)".str_replace(".","\\.",$domain)."$";
|
||||
if($wildcardstyle)
|
||||
$domain = "(\\.|^)".str_replace(".","\\.",$domain)."$";
|
||||
|
||||
$stmt->bindValue(":$field", htmlentities($domain), SQLITE3_TEXT);
|
||||
if($bindcomment) {
|
||||
$stmt->bindValue(":comment", htmlentities($comment), SQLITE3_TEXT);
|
||||
}
|
||||
$stmt->bindValue(":$field", htmlentities($domain), SQLITE3_TEXT);
|
||||
if($bindcomment) {
|
||||
$stmt->bindValue(":comment", htmlentities($comment), SQLITE3_TEXT);
|
||||
}
|
||||
|
||||
if($stmt->execute() && $stmt->reset())
|
||||
$num++;
|
||||
else
|
||||
{
|
||||
$stmt->close();
|
||||
if($returnnum)
|
||||
return $num;
|
||||
else
|
||||
{
|
||||
if($num === 1)
|
||||
$plural = "";
|
||||
else
|
||||
$plural = "s";
|
||||
return "Error: ".$db->lastErrorMsg().", added ".$num." domain".$plural;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($stmt->execute() && $stmt->reset())
|
||||
$num++;
|
||||
else
|
||||
{
|
||||
$stmt->close();
|
||||
if($returnnum)
|
||||
return $num;
|
||||
else
|
||||
{
|
||||
if($num === 1)
|
||||
$plural = "";
|
||||
else
|
||||
$plural = "s";
|
||||
return "Error: ".$db->lastErrorMsg().", added ".$num." domain".$plural;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close prepared statement and return number of processed rows
|
||||
$stmt->close();
|
||||
$db->exec("COMMIT;");
|
||||
// Close prepared statement and return number of processed rows
|
||||
$stmt->close();
|
||||
$db->exec("COMMIT;");
|
||||
|
||||
if($returnnum)
|
||||
return $num;
|
||||
else
|
||||
{
|
||||
$finalcount = intval($db->querySingle($countquery));
|
||||
$modified = $finalcount - $initialcount;
|
||||
if($returnnum)
|
||||
return $num;
|
||||
else
|
||||
{
|
||||
$finalcount = intval($db->querySingle($countquery));
|
||||
$modified = $finalcount - $initialcount;
|
||||
|
||||
// If we add less domains than the user specified, then they wanted to add duplicates
|
||||
if($modified !== $num)
|
||||
{
|
||||
$delta = $num - $modified;
|
||||
$extra = " (skipped ".$delta." duplicates)";
|
||||
}
|
||||
else
|
||||
{
|
||||
$extra = "";
|
||||
}
|
||||
// If we add less domains than the user specified, then they wanted to add duplicates
|
||||
if($modified !== $num)
|
||||
{
|
||||
$delta = $num - $modified;
|
||||
$extra = " (skipped ".$delta." duplicates)";
|
||||
}
|
||||
else
|
||||
{
|
||||
$extra = "";
|
||||
}
|
||||
|
||||
if($num === 1)
|
||||
$plural = "";
|
||||
else
|
||||
$plural = "s";
|
||||
return "Success, added ".$modified." of ".$num." domain".$plural.$extra;
|
||||
}
|
||||
if($num === 1)
|
||||
$plural = "";
|
||||
else
|
||||
$plural = "s";
|
||||
return "Success, added ".$modified." of ".$num." domain".$plural.$extra;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,96 +227,96 @@ function add_to_table($db, $table, $domains, $comment=null, $wildcardstyle=false
|
||||
*/
|
||||
function remove_from_table($db, $table, $domains, $returnnum=false, $type=-1)
|
||||
{
|
||||
if(!is_int($type))
|
||||
{
|
||||
return "Error: Argument type has to be of type integer (is ".gettype($type).")";
|
||||
}
|
||||
if(!is_int($type))
|
||||
{
|
||||
return "Error: Argument type has to be of type integer (is ".gettype($type).")";
|
||||
}
|
||||
|
||||
// Begin transaction
|
||||
if(!$db->exec("BEGIN TRANSACTION;"))
|
||||
{
|
||||
if($returnnum)
|
||||
return 0;
|
||||
else
|
||||
return "Error: Unable to begin transaction for domainlist table.";
|
||||
}
|
||||
// Begin transaction
|
||||
if(!$db->exec("BEGIN TRANSACTION;"))
|
||||
{
|
||||
if($returnnum)
|
||||
return 0;
|
||||
else
|
||||
return "Error: Unable to begin transaction for domainlist table.";
|
||||
}
|
||||
|
||||
// Get initial count of domains in this table
|
||||
if($type === -1)
|
||||
{
|
||||
$countquery = "SELECT COUNT(*) FROM $table;";
|
||||
}
|
||||
else
|
||||
{
|
||||
$countquery = "SELECT COUNT(*) FROM $table WHERE type = $type;";
|
||||
}
|
||||
$initialcount = intval($db->querySingle($countquery));
|
||||
// Get initial count of domains in this table
|
||||
if($type === -1)
|
||||
{
|
||||
$countquery = "SELECT COUNT(*) FROM $table;";
|
||||
}
|
||||
else
|
||||
{
|
||||
$countquery = "SELECT COUNT(*) FROM $table WHERE type = $type;";
|
||||
}
|
||||
$initialcount = intval($db->querySingle($countquery));
|
||||
|
||||
// Prepare SQLite statement
|
||||
if($type === -1)
|
||||
{
|
||||
$querystr = "DELETE FROM $table WHERE domain = :domain AND type = $type;";
|
||||
}
|
||||
else
|
||||
{
|
||||
$querystr = "DELETE FROM $table WHERE domain = :domain;";
|
||||
}
|
||||
$stmt = $db->prepare($querystr);
|
||||
// Prepare SQLite statement
|
||||
if($type === -1)
|
||||
{
|
||||
$querystr = "DELETE FROM $table WHERE domain = :domain AND type = $type;";
|
||||
}
|
||||
else
|
||||
{
|
||||
$querystr = "DELETE FROM $table WHERE domain = :domain;";
|
||||
}
|
||||
$stmt = $db->prepare($querystr);
|
||||
|
||||
// Return early if we failed to prepare the SQLite statement
|
||||
if(!$stmt)
|
||||
{
|
||||
if($returnnum)
|
||||
return 0;
|
||||
else
|
||||
return "Error: Failed to prepare statement for ".$table." table (type = ".$type.").";
|
||||
}
|
||||
// Return early if we failed to prepare the SQLite statement
|
||||
if(!$stmt)
|
||||
{
|
||||
if($returnnum)
|
||||
return 0;
|
||||
else
|
||||
return "Error: Failed to prepare statement for ".$table." table (type = ".$type.").";
|
||||
}
|
||||
|
||||
// Loop over domains and remove the lines from the database
|
||||
$num = 0;
|
||||
foreach($domains as $domain)
|
||||
{
|
||||
$stmt->bindValue(":domain", $domain, SQLITE3_TEXT);
|
||||
// Loop over domains and remove the lines from the database
|
||||
$num = 0;
|
||||
foreach($domains as $domain)
|
||||
{
|
||||
$stmt->bindValue(":domain", $domain, SQLITE3_TEXT);
|
||||
|
||||
if($stmt->execute() && $stmt->reset())
|
||||
$num++;
|
||||
else
|
||||
{
|
||||
$stmt->close();
|
||||
if($returnnum)
|
||||
return $num;
|
||||
else
|
||||
{
|
||||
if($num === 1)
|
||||
$plural = "";
|
||||
else
|
||||
$plural = "s";
|
||||
return "Error: ".$db->lastErrorMsg().", removed ".$num." domain".$plural;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($stmt->execute() && $stmt->reset())
|
||||
$num++;
|
||||
else
|
||||
{
|
||||
$stmt->close();
|
||||
if($returnnum)
|
||||
return $num;
|
||||
else
|
||||
{
|
||||
if($num === 1)
|
||||
$plural = "";
|
||||
else
|
||||
$plural = "s";
|
||||
return "Error: ".$db->lastErrorMsg().", removed ".$num." domain".$plural;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close prepared statement and return number or processed rows
|
||||
$stmt->close();
|
||||
$db->exec("COMMIT;");
|
||||
// Close prepared statement and return number or processed rows
|
||||
$stmt->close();
|
||||
$db->exec("COMMIT;");
|
||||
|
||||
if($returnnum)
|
||||
return $num;
|
||||
else
|
||||
{
|
||||
if($num === 1)
|
||||
$plural = "";
|
||||
else
|
||||
$plural = "s";
|
||||
return "Success, removed ".$num." domain".$plural;
|
||||
}
|
||||
if($returnnum)
|
||||
return $num;
|
||||
else
|
||||
{
|
||||
if($num === 1)
|
||||
$plural = "";
|
||||
else
|
||||
$plural = "s";
|
||||
return "Success, removed ".$num." domain".$plural;
|
||||
}
|
||||
}
|
||||
|
||||
if (!class_exists("ListType")) {
|
||||
class ListType{
|
||||
const whitelist = 0;
|
||||
const blacklist = 1;
|
||||
const regex_whitelist = 2;
|
||||
const regex_blacklist = 3;
|
||||
}
|
||||
class ListType{
|
||||
const whitelist = 0;
|
||||
const blacklist = 1;
|
||||
const regex_whitelist = 2;
|
||||
const regex_blacklist = 3;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,61 +12,61 @@
|
||||
ini_set("pcre.recursion_limit", 1500);
|
||||
function validDomain($domain_name, &$message = NULL)
|
||||
{
|
||||
if(!preg_match("/^((-|_)*[a-z\d]((-|_)*[a-z\d])*(-|_)*)(\.(-|_)*([a-z\d]((-|_)*[a-z\d])*))*$/i", $domain_name)) {
|
||||
if($message !== NULL)
|
||||
$message = "it contains invalid characters";
|
||||
return false;
|
||||
}
|
||||
if(!preg_match("/^.{1,253}$/", $domain_name)) {
|
||||
if($message !== NULL)
|
||||
$message = "its length is invalid";
|
||||
return false;
|
||||
}
|
||||
if(!preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name)) {
|
||||
if($message !== NULL)
|
||||
$message = "at least one label is of invalid length";
|
||||
return false;
|
||||
}
|
||||
if(!preg_match("/^((-|_)*[a-z\d]((-|_)*[a-z\d])*(-|_)*)(\.(-|_)*([a-z\d]((-|_)*[a-z\d])*))*$/i", $domain_name)) {
|
||||
if($message !== NULL)
|
||||
$message = "it contains invalid characters";
|
||||
return false;
|
||||
}
|
||||
if(!preg_match("/^.{1,253}$/", $domain_name)) {
|
||||
if($message !== NULL)
|
||||
$message = "its length is invalid";
|
||||
return false;
|
||||
}
|
||||
if(!preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name)) {
|
||||
if($message !== NULL)
|
||||
$message = "at least one label is of invalid length";
|
||||
return false;
|
||||
}
|
||||
|
||||
// everything is okay
|
||||
return true;
|
||||
// everything is okay
|
||||
return true;
|
||||
}
|
||||
|
||||
function validDomainWildcard($domain_name)
|
||||
{
|
||||
// There has to be either no or at most one "*" at the beginning of a line
|
||||
$validChars = preg_match("/^((\*\.)?[_a-z\d](-*[_a-z\d])*)(\.([_a-z\d](-*[a-z\d])*))*(\.([_a-z\d])*)*$/i", $domain_name);
|
||||
$lengthCheck = preg_match("/^.{1,253}$/", $domain_name);
|
||||
$labelLengthCheck = preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name);
|
||||
return ( $validChars && $lengthCheck && $labelLengthCheck ); //length of each label
|
||||
// There has to be either no or at most one "*" at the beginning of a line
|
||||
$validChars = preg_match("/^((\*\.)?[_a-z\d](-*[_a-z\d])*)(\.([_a-z\d](-*[a-z\d])*))*(\.([_a-z\d])*)*$/i", $domain_name);
|
||||
$lengthCheck = preg_match("/^.{1,253}$/", $domain_name);
|
||||
$labelLengthCheck = preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name);
|
||||
return ( $validChars && $lengthCheck && $labelLengthCheck ); //length of each label
|
||||
}
|
||||
|
||||
function validIP($address){
|
||||
if (preg_match('/[.:0]/', $address) && !preg_match('/[1-9a-f]/', $address)) {
|
||||
// Test if address contains either `:` or `0` but not 1-9 or a-f
|
||||
return false;
|
||||
}
|
||||
return !filter_var($address, FILTER_VALIDATE_IP) === false;
|
||||
if (preg_match('/[.:0]/', $address) && !preg_match('/[1-9a-f]/', $address)) {
|
||||
// Test if address contains either `:` or `0` but not 1-9 or a-f
|
||||
return false;
|
||||
}
|
||||
return !filter_var($address, FILTER_VALIDATE_IP) === false;
|
||||
}
|
||||
|
||||
function validCIDRIP($address){
|
||||
// This validation strategy has been taken from ../js/groups-common.js
|
||||
$isIPv6 = strpos($address, ":") !== false;
|
||||
if($isIPv6) {
|
||||
// One IPv6 element is 16bit: 0000 - FFFF
|
||||
$v6elem = "[0-9A-Fa-f]{1,4}";
|
||||
// dnsmasq allows arbitrary prefix-length since https://thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=commit;h=35f93081dc9a52e64ac3b7196ad1f5c1106f8932
|
||||
$v6cidr = "([1-9]|[1-9][0-9]|1[01][0-9]|12[0-8])";
|
||||
$validator = "/^(((?:$v6elem))((?::$v6elem))*::((?:$v6elem))((?::$v6elem))*|((?:$v6elem))((?::$v6elem)){7})\/$v6cidr$/";
|
||||
return preg_match($validator, $address);
|
||||
} else {
|
||||
// One IPv4 element is 8bit: 0 - 256
|
||||
$v4elem = "(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]?|0)";
|
||||
// dnsmasq allows arbitrary prefix-length
|
||||
$allowedv4cidr = "(([1-9]|[12][0-9]|3[0-2]))";
|
||||
$validator = "/^$v4elem\.$v4elem\.$v4elem\.$v4elem\/$allowedv4cidr$/";
|
||||
return preg_match($validator, $address);
|
||||
}
|
||||
// This validation strategy has been taken from ../js/groups-common.js
|
||||
$isIPv6 = strpos($address, ":") !== false;
|
||||
if($isIPv6) {
|
||||
// One IPv6 element is 16bit: 0000 - FFFF
|
||||
$v6elem = "[0-9A-Fa-f]{1,4}";
|
||||
// dnsmasq allows arbitrary prefix-length since https://thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=commit;h=35f93081dc9a52e64ac3b7196ad1f5c1106f8932
|
||||
$v6cidr = "([1-9]|[1-9][0-9]|1[01][0-9]|12[0-8])";
|
||||
$validator = "/^(((?:$v6elem))((?::$v6elem))*::((?:$v6elem))((?::$v6elem))*|((?:$v6elem))((?::$v6elem)){7})\/$v6cidr$/";
|
||||
return preg_match($validator, $address);
|
||||
} else {
|
||||
// One IPv4 element is 8bit: 0 - 256
|
||||
$v4elem = "(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]?|0)";
|
||||
// dnsmasq allows arbitrary prefix-length
|
||||
$allowedv4cidr = "(([1-9]|[12][0-9]|3[0-2]))";
|
||||
$validator = "/^$v4elem\.$v4elem\.$v4elem\.$v4elem\/$allowedv4cidr$/";
|
||||
return preg_match($validator, $address);
|
||||
}
|
||||
}
|
||||
|
||||
function validMAC($mac_addr)
|
||||
@@ -77,12 +77,12 @@ function validMAC($mac_addr)
|
||||
|
||||
function validEmail($email)
|
||||
{
|
||||
return filter_var($email, FILTER_VALIDATE_EMAIL)
|
||||
// Make sure that the email does not contain special characters which
|
||||
// may be used to execute shell commands, even though they may be valid
|
||||
// in an email address. If the escaped email does not equal the original
|
||||
// email, it is not safe to store in setupVars.
|
||||
&& escapeshellcmd($email) === $email;
|
||||
return filter_var($email, FILTER_VALIDATE_EMAIL)
|
||||
// Make sure that the email does not contain special characters which
|
||||
// may be used to execute shell commands, even though they may be valid
|
||||
// in an email address. If the escaped email does not equal the original
|
||||
// email, it is not safe to store in setupVars.
|
||||
&& escapeshellcmd($email) === $email;
|
||||
}
|
||||
|
||||
function get_ip_type($ip)
|
||||
@@ -281,7 +281,7 @@ function deleteCustomDNSEntry()
|
||||
function deleteAllCustomDNSEntries($reload="")
|
||||
{
|
||||
try
|
||||
{
|
||||
{
|
||||
if(isset($_REQUEST['reload']))
|
||||
$reload = $_REQUEST['reload'];
|
||||
|
||||
|
||||
@@ -11,52 +11,52 @@ require_once("scripts/pi-hole/php/database.php");
|
||||
|
||||
function gravity_last_update($raw = false)
|
||||
{
|
||||
$db = SQLite3_connect(getGravityDBFilename());
|
||||
$date_file_created_unix = $db->querySingle("SELECT value FROM info WHERE property = 'updated';");
|
||||
if($date_file_created_unix === false)
|
||||
{
|
||||
if($raw)
|
||||
{
|
||||
// Array output
|
||||
return array("file_exists" => false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// String output
|
||||
return "Gravity database not available";
|
||||
}
|
||||
}
|
||||
// Now that we know that $date_file_created_unix is a valid response, we can convert it to an integer
|
||||
$date_file_created_unix = intval($date_file_created_unix);
|
||||
$date_file_created = date_create("@".$date_file_created_unix);
|
||||
$date_now = date_create("now");
|
||||
$gravitydiff = date_diff($date_file_created,$date_now);
|
||||
if($raw)
|
||||
{
|
||||
// Array output
|
||||
return array(
|
||||
"file_exists"=> true,
|
||||
"absolute" => $date_file_created_unix,
|
||||
"relative" => array(
|
||||
"days" => intval($gravitydiff->format("%a")),
|
||||
"hours" => intval($gravitydiff->format("%H")),
|
||||
"minutes" => intval($gravitydiff->format("%I")),
|
||||
)
|
||||
);
|
||||
}
|
||||
$db = SQLite3_connect(getGravityDBFilename());
|
||||
$date_file_created_unix = $db->querySingle("SELECT value FROM info WHERE property = 'updated';");
|
||||
if($date_file_created_unix === false)
|
||||
{
|
||||
if($raw)
|
||||
{
|
||||
// Array output
|
||||
return array("file_exists" => false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// String output
|
||||
return "Gravity database not available";
|
||||
}
|
||||
}
|
||||
// Now that we know that $date_file_created_unix is a valid response, we can convert it to an integer
|
||||
$date_file_created_unix = intval($date_file_created_unix);
|
||||
$date_file_created = date_create("@".$date_file_created_unix);
|
||||
$date_now = date_create("now");
|
||||
$gravitydiff = date_diff($date_file_created,$date_now);
|
||||
if($raw)
|
||||
{
|
||||
// Array output
|
||||
return array(
|
||||
"file_exists"=> true,
|
||||
"absolute" => $date_file_created_unix,
|
||||
"relative" => array(
|
||||
"days" => intval($gravitydiff->format("%a")),
|
||||
"hours" => intval($gravitydiff->format("%H")),
|
||||
"minutes" => intval($gravitydiff->format("%I")),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if($gravitydiff->d > 1)
|
||||
{
|
||||
// String output (more than one day ago)
|
||||
return $gravitydiff->format("Adlists updated %a days, %H:%I (hh:mm) ago");
|
||||
}
|
||||
elseif($gravitydiff->d == 1)
|
||||
{
|
||||
// String output (one day ago)
|
||||
return $gravitydiff->format("Adlists updated one day, %H:%I (hh:mm) ago");
|
||||
}
|
||||
if($gravitydiff->d > 1)
|
||||
{
|
||||
// String output (more than one day ago)
|
||||
return $gravitydiff->format("Adlists updated %a days, %H:%I (hh:mm) ago");
|
||||
}
|
||||
elseif($gravitydiff->d == 1)
|
||||
{
|
||||
// String output (one day ago)
|
||||
return $gravitydiff->format("Adlists updated one day, %H:%I (hh:mm) ago");
|
||||
}
|
||||
|
||||
// String output (less than one day ago)
|
||||
return $gravitydiff->format("Adlists updated %H:%I (hh:mm) ago");
|
||||
// String output (less than one day ago)
|
||||
return $gravitydiff->format("Adlists updated %H:%I (hh:mm) ago");
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -11,181 +11,181 @@ require_once("func.php");
|
||||
|
||||
if(!in_array(basename($_SERVER['SCRIPT_FILENAME']), ["settings.php", "teleporter.php"], true))
|
||||
{
|
||||
die("Direct access to this script is forbidden!");
|
||||
die("Direct access to this script is forbidden!");
|
||||
}
|
||||
|
||||
// Check for existence of variable
|
||||
// and test it only if it exists
|
||||
function istrue(&$argument) {
|
||||
if(isset($argument))
|
||||
{
|
||||
if($argument)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
if(isset($argument))
|
||||
{
|
||||
if($argument)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function formatMAC($mac_addr)
|
||||
{
|
||||
preg_match("/([0-9a-fA-F]{2}[:]){5}([0-9a-fA-F]{2})/", $mac_addr, $matches);
|
||||
if(count($matches) > 0)
|
||||
return $matches[0];
|
||||
return null;
|
||||
preg_match("/([0-9a-fA-F]{2}[:]){5}([0-9a-fA-F]{2})/", $mac_addr, $matches);
|
||||
if(count($matches) > 0)
|
||||
return $matches[0];
|
||||
return null;
|
||||
}
|
||||
|
||||
$dhcp_static_leases = array();
|
||||
function readStaticLeasesFile($origin_file="/etc/dnsmasq.d/04-pihole-static-dhcp.conf")
|
||||
{
|
||||
global $dhcp_static_leases;
|
||||
$dhcp_static_leases = array();
|
||||
if(!file_exists($origin_file) || !is_readable($origin_file))
|
||||
return false;
|
||||
global $dhcp_static_leases;
|
||||
$dhcp_static_leases = array();
|
||||
if(!file_exists($origin_file) || !is_readable($origin_file))
|
||||
return false;
|
||||
|
||||
$dhcpstatic = @fopen($origin_file, 'r');
|
||||
if(!is_resource($dhcpstatic))
|
||||
return false;
|
||||
$dhcpstatic = @fopen($origin_file, 'r');
|
||||
if(!is_resource($dhcpstatic))
|
||||
return false;
|
||||
|
||||
while(!feof($dhcpstatic))
|
||||
{
|
||||
// Remove any possibly existing variable with this name
|
||||
$mac = ""; $one = ""; $two = "";
|
||||
sscanf(trim(fgets($dhcpstatic)),"dhcp-host=%[^,],%[^,],%[^,]",$mac,$one,$two);
|
||||
if(strlen($mac) > 0 && validMAC($mac))
|
||||
{
|
||||
if(validIP($one) && strlen($two) == 0)
|
||||
// dhcp-host=mac,IP - no HOST
|
||||
array_push($dhcp_static_leases,["hwaddr"=>$mac, "IP"=>$one, "host"=>""]);
|
||||
elseif(strlen($two) == 0)
|
||||
// dhcp-host=mac,hostname - no IP
|
||||
array_push($dhcp_static_leases,["hwaddr"=>$mac, "IP"=>"", "host"=>$one]);
|
||||
else
|
||||
// dhcp-host=mac,IP,hostname
|
||||
array_push($dhcp_static_leases,["hwaddr"=>$mac, "IP"=>$one, "host"=>$two]);
|
||||
}
|
||||
else if(validIP($one) && validDomain($mac))
|
||||
{
|
||||
// dhcp-host=hostname,IP - no MAC
|
||||
array_push($dhcp_static_leases,["hwaddr"=>"", "IP"=>$one, "host"=>$mac]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
while(!feof($dhcpstatic))
|
||||
{
|
||||
// Remove any possibly existing variable with this name
|
||||
$mac = ""; $one = ""; $two = "";
|
||||
sscanf(trim(fgets($dhcpstatic)),"dhcp-host=%[^,],%[^,],%[^,]",$mac,$one,$two);
|
||||
if(strlen($mac) > 0 && validMAC($mac))
|
||||
{
|
||||
if(validIP($one) && strlen($two) == 0)
|
||||
// dhcp-host=mac,IP - no HOST
|
||||
array_push($dhcp_static_leases,["hwaddr"=>$mac, "IP"=>$one, "host"=>""]);
|
||||
elseif(strlen($two) == 0)
|
||||
// dhcp-host=mac,hostname - no IP
|
||||
array_push($dhcp_static_leases,["hwaddr"=>$mac, "IP"=>"", "host"=>$one]);
|
||||
else
|
||||
// dhcp-host=mac,IP,hostname
|
||||
array_push($dhcp_static_leases,["hwaddr"=>$mac, "IP"=>$one, "host"=>$two]);
|
||||
}
|
||||
else if(validIP($one) && validDomain($mac))
|
||||
{
|
||||
// dhcp-host=hostname,IP - no MAC
|
||||
array_push($dhcp_static_leases,["hwaddr"=>"", "IP"=>$one, "host"=>$mac]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function isequal(&$argument, &$compareto) {
|
||||
if(isset($argument))
|
||||
{
|
||||
if($argument === $compareto)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
if(isset($argument))
|
||||
{
|
||||
if($argument === $compareto)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isinserverlist($addr) {
|
||||
global $DNSserverslist;
|
||||
foreach ($DNSserverslist as $key => $value) {
|
||||
if (isequal($value['v4_1'],$addr) || isequal($value['v4_2'],$addr))
|
||||
return true;
|
||||
if (isequal($value['v6_1'],$addr) || isequal($value['v6_2'],$addr))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
global $DNSserverslist;
|
||||
foreach ($DNSserverslist as $key => $value) {
|
||||
if (isequal($value['v4_1'],$addr) || isequal($value['v4_2'],$addr))
|
||||
return true;
|
||||
if (isequal($value['v6_1'],$addr) || isequal($value['v6_2'],$addr))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$DNSserverslist = [];
|
||||
function readDNSserversList()
|
||||
{
|
||||
// Reset list
|
||||
$list = [];
|
||||
$handle = @fopen("/etc/pihole/dns-servers.conf", "r");
|
||||
if ($handle)
|
||||
{
|
||||
while (($line = fgets($handle)) !== false)
|
||||
{
|
||||
$line = rtrim($line);
|
||||
$line = explode(';', $line);
|
||||
$name = $line[0];
|
||||
$values = [];
|
||||
if (!empty($line[1]) && validIP($line[1])) {
|
||||
$values["v4_1"] = $line[1];
|
||||
}
|
||||
if (!empty($line[2]) && validIP($line[2])) {
|
||||
$values["v4_2"] = $line[2];
|
||||
}
|
||||
if (!empty($line[3]) && validIP($line[3])) {
|
||||
$values["v6_1"] = $line[3];
|
||||
}
|
||||
if (!empty($line[4]) && validIP($line[4])) {
|
||||
$values["v6_2"] = $line[4];
|
||||
}
|
||||
// Reset list
|
||||
$list = [];
|
||||
$handle = @fopen("/etc/pihole/dns-servers.conf", "r");
|
||||
if ($handle)
|
||||
{
|
||||
while (($line = fgets($handle)) !== false)
|
||||
{
|
||||
$line = rtrim($line);
|
||||
$line = explode(';', $line);
|
||||
$name = $line[0];
|
||||
$values = [];
|
||||
if (!empty($line[1]) && validIP($line[1])) {
|
||||
$values["v4_1"] = $line[1];
|
||||
}
|
||||
if (!empty($line[2]) && validIP($line[2])) {
|
||||
$values["v4_2"] = $line[2];
|
||||
}
|
||||
if (!empty($line[3]) && validIP($line[3])) {
|
||||
$values["v6_1"] = $line[3];
|
||||
}
|
||||
if (!empty($line[4]) && validIP($line[4])) {
|
||||
$values["v6_2"] = $line[4];
|
||||
}
|
||||
$list[$name] = $values;
|
||||
}
|
||||
fclose($handle);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
fclose($handle);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
require_once("database.php");
|
||||
|
||||
function addStaticDHCPLease($mac, $ip, $hostname) {
|
||||
global $error, $success, $dhcp_static_leases;
|
||||
global $error, $success, $dhcp_static_leases;
|
||||
|
||||
try {
|
||||
if(!validMAC($mac))
|
||||
{
|
||||
throw new Exception("MAC address (".htmlspecialchars($mac).") is invalid!<br>", 0);
|
||||
}
|
||||
$mac = strtoupper($mac);
|
||||
try {
|
||||
if(!validMAC($mac))
|
||||
{
|
||||
throw new Exception("MAC address (".htmlspecialchars($mac).") is invalid!<br>", 0);
|
||||
}
|
||||
$mac = strtoupper($mac);
|
||||
|
||||
if(!validIP($ip) && strlen($ip) > 0)
|
||||
{
|
||||
throw new Exception("IP address (".htmlspecialchars($ip).") is invalid!<br>", 1);
|
||||
}
|
||||
if(!validIP($ip) && strlen($ip) > 0)
|
||||
{
|
||||
throw new Exception("IP address (".htmlspecialchars($ip).") is invalid!<br>", 1);
|
||||
}
|
||||
|
||||
if(!validDomain($hostname) && strlen($hostname) > 0)
|
||||
{
|
||||
throw new Exception("Host name (".htmlspecialchars($hostname).") is invalid!<br>", 2);
|
||||
}
|
||||
if(!validDomain($hostname) && strlen($hostname) > 0)
|
||||
{
|
||||
throw new Exception("Host name (".htmlspecialchars($hostname).") is invalid!<br>", 2);
|
||||
}
|
||||
|
||||
if(strlen($hostname) == 0 && strlen($ip) == 0)
|
||||
{
|
||||
throw new Exception("You can not omit both the IP address and the host name!<br>", 3);
|
||||
}
|
||||
if(strlen($hostname) == 0 && strlen($ip) == 0)
|
||||
{
|
||||
throw new Exception("You can not omit both the IP address and the host name!<br>", 3);
|
||||
}
|
||||
|
||||
if(strlen($hostname) == 0)
|
||||
$hostname = "nohost";
|
||||
if(strlen($hostname) == 0)
|
||||
$hostname = "nohost";
|
||||
|
||||
if(strlen($ip) == 0)
|
||||
$ip = "noip";
|
||||
if(strlen($ip) == 0)
|
||||
$ip = "noip";
|
||||
|
||||
// Test if this lease is already included
|
||||
readStaticLeasesFile();
|
||||
// Test if this lease is already included
|
||||
readStaticLeasesFile();
|
||||
|
||||
foreach($dhcp_static_leases as $lease) {
|
||||
if($lease["hwaddr"] === $mac)
|
||||
{
|
||||
throw new Exception("Static lease for MAC address (".htmlspecialchars($mac).") already defined!<br>", 4);
|
||||
}
|
||||
if($ip !== "noip" && $lease["IP"] === $ip)
|
||||
{
|
||||
throw new Exception("Static lease for IP address (".htmlspecialchars($ip).") already defined!<br>", 5);
|
||||
}
|
||||
if($lease["host"] === $hostname)
|
||||
{
|
||||
throw new Exception("Static lease for hostname (".htmlspecialchars($hostname).") already defined!<br>", 6);
|
||||
}
|
||||
}
|
||||
foreach($dhcp_static_leases as $lease) {
|
||||
if($lease["hwaddr"] === $mac)
|
||||
{
|
||||
throw new Exception("Static lease for MAC address (".htmlspecialchars($mac).") already defined!<br>", 4);
|
||||
}
|
||||
if($ip !== "noip" && $lease["IP"] === $ip)
|
||||
{
|
||||
throw new Exception("Static lease for IP address (".htmlspecialchars($ip).") already defined!<br>", 5);
|
||||
}
|
||||
if($lease["host"] === $hostname)
|
||||
{
|
||||
throw new Exception("Static lease for hostname (".htmlspecialchars($hostname).") already defined!<br>", 6);
|
||||
}
|
||||
}
|
||||
|
||||
pihole_execute("-a addstaticdhcp ".$mac." ".$ip." ".$hostname);
|
||||
$success .= "A new static address has been added";
|
||||
return true;
|
||||
} catch(Exception $exception) {
|
||||
$error .= $exception->getMessage();
|
||||
return false;
|
||||
}
|
||||
pihole_execute("-a addstaticdhcp ".$mac." ".$ip." ".$hostname);
|
||||
$success .= "A new static address has been added";
|
||||
return true;
|
||||
} catch(Exception $exception) {
|
||||
$error .= $exception->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Read available DNS server list
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
12
settings.php
12
settings.php
@@ -21,21 +21,21 @@ $piholeFTLConf = piholeFTLConfig(DEFAULT_FTLCONFFILE ,true);
|
||||
$last_error = error_get_last();
|
||||
if(isset($last_error) && ($last_error["type"] === E_WARNING || $last_error["type"] === E_ERROR))
|
||||
{
|
||||
$error .= "There was a problem applying your settings.<br>Debugging information:<br>PHP error (".htmlspecialchars($last_error["type"])."): ".htmlspecialchars($last_error["message"])." in ".htmlspecialchars($last_error["file"]).":".htmlspecialchars($last_error["line"]);
|
||||
$error .= "There was a problem applying your settings.<br>Debugging information:<br>PHP error (".htmlspecialchars($last_error["type"])."): ".htmlspecialchars($last_error["message"])." in ".htmlspecialchars($last_error["file"]).":".htmlspecialchars($last_error["line"]);
|
||||
}
|
||||
|
||||
# Timezone is set in docker via ENV otherwise get it from commandline
|
||||
$timezone=htmlspecialchars(getenv("TZ"));
|
||||
if (empty($timezone)) {
|
||||
$timezone=shell_exec("date +'%Z'");
|
||||
$timezone=shell_exec("date +'%Z'");
|
||||
}
|
||||
|
||||
?>
|
||||
<style>
|
||||
.tooltip-inner {
|
||||
max-width: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.tooltip-inner {
|
||||
max-width: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
|
||||
<?php // Check if ad lists should be updated after saving ...
|
||||
|
||||
Reference in New Issue
Block a user