From a3234d1306e2f6e9b3b60b46b98cc20242d48ee5 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Mon, 1 Aug 2022 01:28:30 -0300 Subject: [PATCH] Replacing tabs with 4 spaces Signed-off-by: RD WebDesign --- api.php | 12 +- db_lists.php | 4 +- network.php | 2 +- queries.php | 96 +-- scripts/pi-hole/php/api_token.php | 16 +- scripts/pi-hole/php/auth.php | 8 +- scripts/pi-hole/php/database.php | 484 ++++++------- scripts/pi-hole/php/func.php | 102 +-- scripts/pi-hole/php/gravity.php | 90 +-- scripts/pi-hole/php/savesettings.php | 266 +++---- scripts/pi-hole/php/teleporter.php | 990 +++++++++++++-------------- settings.php | 12 +- 12 files changed, 1041 insertions(+), 1041 deletions(-) diff --git a/api.php b/api.php index 0673ad28..ba638f5d 100644 --- a/api.php +++ b/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); diff --git a/db_lists.php b/db_lists.php index a49da502..47f5a8e5 100644 --- a/db_lists.php +++ b/db_lists.php @@ -51,11 +51,11 @@ require "scripts/pi-hole/php/header.php";
diff --git a/network.php b/network.php index 10d58109..f6b0ed5b 100644 --- a/network.php +++ b/network.php @@ -12,7 +12,7 @@ require "scripts/pi-hole/php/header.php";
-
+

Network overview

diff --git a/queries.php b/queries.php index 6bf92326..63d4a675 100644 --- a/queries.php +++ b/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 .= ", show all"; - } - else - { - // Show All queries for this client + link to show only blocked - $showing .= " all queries for client ".htmlentities($_GET["client"]); - $showing .= ", show blocked only"; - } + // 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 .= ", show all"; + } + else + { + // Show All queries for this client + link to show only blocked + $showing .= " all queries for client ".htmlentities($_GET["client"]); + $showing .= ", show blocked only"; + } } 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 .= ", show all"; + $showing = "(".$showing.")"; + if($showall) + $showing .= ", show all"; } ?> diff --git a/scripts/pi-hole/php/api_token.php b/scripts/pi-hole/php/api_token.php index a878e0ab..a8893442 100644 --- a/scripts/pi-hole/php/api_token.php +++ b/scripts/pi-hole/php/api_token.php @@ -8,23 +8,23 @@ check_cors(); diff --git a/scripts/pi-hole/php/auth.php b/scripts/pi-hole/php/auth.php index b234a555..44b2bc76 100644 --- a/scripts/pi-hole/php/auth.php +++ b/scripts/pi-hole/php/auth.php @@ -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'; + } } } diff --git a/scripts/pi-hole/php/database.php b/scripts/pi-hole/php/database.php index 01ec0d48..5fdc32c9 100644 --- a/scripts/pi-hole/php/database.php +++ b/scripts/pi-hole/php/database.php @@ -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; + } } diff --git a/scripts/pi-hole/php/func.php b/scripts/pi-hole/php/func.php index 6b8d6e68..38d294f1 100644 --- a/scripts/pi-hole/php/func.php +++ b/scripts/pi-hole/php/func.php @@ -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']; diff --git a/scripts/pi-hole/php/gravity.php b/scripts/pi-hole/php/gravity.php index 2dd7e6ae..232c6291 100644 --- a/scripts/pi-hole/php/gravity.php +++ b/scripts/pi-hole/php/gravity.php @@ -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"); } ?> diff --git a/scripts/pi-hole/php/savesettings.php b/scripts/pi-hole/php/savesettings.php index 35a63bae..3dcfb97a 100644 --- a/scripts/pi-hole/php/savesettings.php +++ b/scripts/pi-hole/php/savesettings.php @@ -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!
", 0); - } - $mac = strtoupper($mac); + try { + if(!validMAC($mac)) + { + throw new Exception("MAC address (".htmlspecialchars($mac).") is invalid!
", 0); + } + $mac = strtoupper($mac); - if(!validIP($ip) && strlen($ip) > 0) - { - throw new Exception("IP address (".htmlspecialchars($ip).") is invalid!
", 1); - } + if(!validIP($ip) && strlen($ip) > 0) + { + throw new Exception("IP address (".htmlspecialchars($ip).") is invalid!
", 1); + } - if(!validDomain($hostname) && strlen($hostname) > 0) - { - throw new Exception("Host name (".htmlspecialchars($hostname).") is invalid!
", 2); - } + if(!validDomain($hostname) && strlen($hostname) > 0) + { + throw new Exception("Host name (".htmlspecialchars($hostname).") is invalid!
", 2); + } - if(strlen($hostname) == 0 && strlen($ip) == 0) - { - throw new Exception("You can not omit both the IP address and the host name!
", 3); - } + if(strlen($hostname) == 0 && strlen($ip) == 0) + { + throw new Exception("You can not omit both the IP address and the host name!
", 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!
", 4); - } - if($ip !== "noip" && $lease["IP"] === $ip) - { - throw new Exception("Static lease for IP address (".htmlspecialchars($ip).") already defined!
", 5); - } - if($lease["host"] === $hostname) - { - throw new Exception("Static lease for hostname (".htmlspecialchars($hostname).") already defined!
", 6); - } - } + foreach($dhcp_static_leases as $lease) { + if($lease["hwaddr"] === $mac) + { + throw new Exception("Static lease for MAC address (".htmlspecialchars($mac).") already defined!
", 4); + } + if($ip !== "noip" && $lease["IP"] === $ip) + { + throw new Exception("Static lease for IP address (".htmlspecialchars($ip).") already defined!
", 5); + } + if($lease["host"] === $hostname) + { + throw new Exception("Static lease for hostname (".htmlspecialchars($hostname).") already defined!
", 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 diff --git a/scripts/pi-hole/php/teleporter.php b/scripts/pi-hole/php/teleporter.php index f859aa39..fb7cf4da 100644 --- a/scripts/pi-hole/php/teleporter.php +++ b/scripts/pi-hole/php/teleporter.php @@ -13,8 +13,8 @@ require "database.php"; require "savesettings.php"; if (php_sapi_name() !== "cli") { - if(!$auth) die("Not authorized"); - check_csrf(isset($_POST["token"]) ? $_POST["token"] : ""); + if(!$auth) die("Not authorized"); + check_csrf(isset($_POST["token"]) ? $_POST["token"] : ""); } $db = SQLite3_connect(getGravityDBFilename(), SQLITE3_OPEN_READWRITE); @@ -23,9 +23,9 @@ $flushed_tables = array(); function archive_add_file($path,$name,$subdir="") { - global $archive; - if(file_exists($path.$name)) - $archive[$subdir.$name] = file_get_contents($path.$name); + global $archive; + if(file_exists($path.$name)) + $archive[$subdir.$name] = file_get_contents($path.$name); } /** @@ -37,30 +37,30 @@ function archive_add_file($path,$name,$subdir="") */ function archive_add_table($name, $table, $type=-1) { - global $archive, $db; + global $archive, $db; - if($type > -1) - { - $querystr = "SELECT * FROM \"$table\" WHERE type = $type;"; - } - else - { - $querystr = "SELECT * FROM \"$table\";"; - } - $results = $db->query($querystr); + if($type > -1) + { + $querystr = "SELECT * FROM \"$table\" WHERE type = $type;"; + } + else + { + $querystr = "SELECT * FROM \"$table\";"; + } + $results = $db->query($querystr); - // Return early without creating a file if the - // requested table cannot be accessed - if(is_null($results)) - return; + // Return early without creating a file if the + // requested table cannot be accessed + if(is_null($results)) + return; - $content = array(); - while ($row = $results->fetchArray(SQLITE3_ASSOC)) - { - array_push($content, $row); - } + $content = array(); + while ($row = $results->fetchArray(SQLITE3_ASSOC)) + { + array_push($content, $row); + } - $archive[$name] = json_encode($content); + $archive[$name] = json_encode($content); } /** @@ -73,149 +73,149 @@ function archive_add_table($name, $table, $type=-1) */ function archive_restore_table($file, $table, $flush=false) { - global $db, $flushed_tables; + global $db, $flushed_tables; - $json_string = file_get_contents($file); - // Return early if we cannot extract the JSON string - if(is_null($json_string)) - return 0; + $json_string = file_get_contents($file); + // Return early if we cannot extract the JSON string + if(is_null($json_string)) + return 0; - $contents = json_decode($json_string, true); - // Return early if we cannot decode the JSON string - if(is_null($contents)) - return 0; + $contents = json_decode($json_string, true); + // Return early if we cannot decode the JSON string + if(is_null($contents)) + return 0; - // Flush table if requested. Only flush each table once, and only if it exists - if($flush && !in_array($table, $flushed_tables)) - { - $tableExists = $db->querySingle("SELECT name FROM sqlite_master WHERE type='table' AND name='".$table."';"); - if ($tableExists) - { - $db->exec("DELETE FROM \"".$table."\""); - array_push($flushed_tables, $table); - } - } + // Flush table if requested. Only flush each table once, and only if it exists + if($flush && !in_array($table, $flushed_tables)) + { + $tableExists = $db->querySingle("SELECT name FROM sqlite_master WHERE type='table' AND name='".$table."';"); + if ($tableExists) + { + $db->exec("DELETE FROM \"".$table."\""); + array_push($flushed_tables, $table); + } + } - // Prepare fields depending on the table we restore to - if($table === "adlist") - { - $sql = "INSERT OR IGNORE INTO adlist"; - $sql .= " (id,address,enabled,date_added,comment)"; - $sql .= " VALUES (:id,:address,:enabled,:date_added,:comment);"; - } - elseif($table === "domain_audit") - { - $sql = "INSERT OR IGNORE INTO domain_audit"; - $sql .= " (id,domain,date_added)"; - $sql .= " VALUES (:id,:domain,:date_added);"; - } - elseif($table === "domainlist") - { - $sql = "INSERT OR IGNORE INTO domainlist"; - $sql .= " (id,domain,enabled,date_added,comment,type)"; - $sql .= " VALUES (:id,:domain,:enabled,:date_added,:comment,:type);"; - } - elseif($table === "group") - { - $sql = "INSERT OR IGNORE INTO \"group\""; - $sql .= " (id,name,date_added,description)"; - $sql .= " VALUES (:id,:name,:date_added,:description);"; - } - elseif($table === "client") - { - $sql = "INSERT OR IGNORE INTO client"; - $sql .= " (id,ip,date_added,comment)"; - $sql .= " VALUES (:id,:ip,:date_added,:comment);"; - } - elseif($table === "domainlist_by_group") - { - $sql = "INSERT OR IGNORE INTO domainlist_by_group"; - $sql .= " (domainlist_id,group_id)"; - $sql .= " VALUES (:domainlist_id,:group_id);"; - } - elseif($table === "client_by_group") - { - $sql = "INSERT OR IGNORE INTO client_by_group"; - $sql .= " (client_id,group_id)"; - $sql .= " VALUES (:client_id,:group_id);"; - } - elseif($table === "adlist_by_group") - { - $sql = "INSERT OR IGNORE INTO adlist_by_group"; - $sql .= " (adlist_id,group_id)"; - $sql .= " VALUES (:adlist_id,:group_id);"; - } - else - { - if($table === "whitelist") - $type = 0; - elseif($table === "blacklist") - $type = 1; - elseif($table === "regex_whitelist") - $type = 2; - elseif($table === "regex_blacklist") - $type = 3; + // Prepare fields depending on the table we restore to + if($table === "adlist") + { + $sql = "INSERT OR IGNORE INTO adlist"; + $sql .= " (id,address,enabled,date_added,comment)"; + $sql .= " VALUES (:id,:address,:enabled,:date_added,:comment);"; + } + elseif($table === "domain_audit") + { + $sql = "INSERT OR IGNORE INTO domain_audit"; + $sql .= " (id,domain,date_added)"; + $sql .= " VALUES (:id,:domain,:date_added);"; + } + elseif($table === "domainlist") + { + $sql = "INSERT OR IGNORE INTO domainlist"; + $sql .= " (id,domain,enabled,date_added,comment,type)"; + $sql .= " VALUES (:id,:domain,:enabled,:date_added,:comment,:type);"; + } + elseif($table === "group") + { + $sql = "INSERT OR IGNORE INTO \"group\""; + $sql .= " (id,name,date_added,description)"; + $sql .= " VALUES (:id,:name,:date_added,:description);"; + } + elseif($table === "client") + { + $sql = "INSERT OR IGNORE INTO client"; + $sql .= " (id,ip,date_added,comment)"; + $sql .= " VALUES (:id,:ip,:date_added,:comment);"; + } + elseif($table === "domainlist_by_group") + { + $sql = "INSERT OR IGNORE INTO domainlist_by_group"; + $sql .= " (domainlist_id,group_id)"; + $sql .= " VALUES (:domainlist_id,:group_id);"; + } + elseif($table === "client_by_group") + { + $sql = "INSERT OR IGNORE INTO client_by_group"; + $sql .= " (client_id,group_id)"; + $sql .= " VALUES (:client_id,:group_id);"; + } + elseif($table === "adlist_by_group") + { + $sql = "INSERT OR IGNORE INTO adlist_by_group"; + $sql .= " (adlist_id,group_id)"; + $sql .= " VALUES (:adlist_id,:group_id);"; + } + else + { + if($table === "whitelist") + $type = 0; + elseif($table === "blacklist") + $type = 1; + elseif($table === "regex_whitelist") + $type = 2; + elseif($table === "regex_blacklist") + $type = 3; - $sql = "INSERT OR IGNORE INTO domainlist"; - $sql .= " (id,domain,enabled,date_added,comment,type)"; - $sql .= " VALUES (:id,:domain,:enabled,:date_added,:comment,$type);"; - $field = "domain"; - } + $sql = "INSERT OR IGNORE INTO domainlist"; + $sql .= " (id,domain,enabled,date_added,comment,type)"; + $sql .= " VALUES (:id,:domain,:enabled,:date_added,:comment,$type);"; + $field = "domain"; + } - // Prepare SQLite statement - $stmt = $db->prepare($sql); + // Prepare SQLite statement + $stmt = $db->prepare($sql); - // Return early if we fail to prepare the SQLite statement - if(!$stmt) - { - echo "Failed to prepare statement for ".$table." table."; - echo $sql; - return 0; - } + // Return early if we fail to prepare the SQLite statement + if(!$stmt) + { + echo "Failed to prepare statement for ".$table." table."; + echo $sql; + return 0; + } - // Loop over rows and inject the entries into the database - $num = 0; - foreach($contents as $row) - { - // Limit max length for a domain entry to 253 chars - if(isset($field) && strlen($row[$field]) > 253) - continue; + // Loop over rows and inject the entries into the database + $num = 0; + foreach($contents as $row) + { + // Limit max length for a domain entry to 253 chars + if(isset($field) && strlen($row[$field]) > 253) + continue; - // Bind properties from JSON data - // Note that only defined above are actually used - // so even maliciously modified Teleporter files - // cannot be dangerous in any way - foreach($row as $key => $value) { - $type = gettype($value); - $sqltype=NULL; - switch($type) { - case "integer": - $sqltype = SQLITE3_INTEGER; - break; - case "string": - $sqltype = SQLITE3_TEXT; - break; - case "NULL": - $sqltype = SQLITE3_NULL; - break; - default: - $sqltype = "UNK"; - } - $stmt->bindValue(":".$key, htmlentities($value), $sqltype); - } + // Bind properties from JSON data + // Note that only defined above are actually used + // so even maliciously modified Teleporter files + // cannot be dangerous in any way + foreach($row as $key => $value) { + $type = gettype($value); + $sqltype=NULL; + switch($type) { + case "integer": + $sqltype = SQLITE3_INTEGER; + break; + case "string": + $sqltype = SQLITE3_TEXT; + break; + case "NULL": + $sqltype = SQLITE3_NULL; + break; + default: + $sqltype = "UNK"; + } + $stmt->bindValue(":".$key, htmlentities($value), $sqltype); + } - if($stmt->execute() && $stmt->reset() && $stmt->clear()) - $num++; - else - { - $stmt->close(); - return $num; - } - } + if($stmt->execute() && $stmt->reset() && $stmt->clear()) + $num++; + else + { + $stmt->close(); + return $num; + } + } - // Close database connection and return number or processed rows - $stmt->close(); - return $num; + // Close database connection and return number or processed rows + $stmt->close(); + return $num; } /** @@ -229,46 +229,46 @@ function archive_restore_table($file, $table, $flush=false) */ function archive_insert_into_table($file, $table, $flush=false, $wildcardstyle=false) { - global $db; + global $db; - $domains = array_filter(explode("\n",file_get_contents($file))); - // Return early if we cannot extract the lines in the file - if(is_null($domains)) - return 0; + $domains = array_filter(explode("\n",file_get_contents($file))); + // Return early if we cannot extract the lines in the file + if(is_null($domains)) + return 0; - // Generate comment - $prefix = "phar:///tmp/"; - if (substr($file, 0, strlen($prefix)) == $prefix) { - $file = substr($file, strlen($prefix)); - } - $comment = "Imported from ".$file; + // Generate comment + $prefix = "phar:///tmp/"; + if (substr($file, 0, strlen($prefix)) == $prefix) { + $file = substr($file, strlen($prefix)); + } + $comment = "Imported from ".$file; - // Determine table and type to import to - $type = null; - if($table === "whitelist") { - $table = "domainlist"; - $type = ListType::whitelist; - } else if($table === "blacklist") { - $table = "domainlist"; - $type = ListType::blacklist; - } else if($table === "regex_blacklist") { - $table = "domainlist"; - $type = ListType::regex_blacklist; - } else if($table === "domain_audit") { - $table = "domain_audit"; - $type = -1; // -1 -> not used inside add_to_table() - } else if($table === "adlist") { - $table = "adlist"; - $type = -1; // -1 -> not used inside add_to_table() - } + // Determine table and type to import to + $type = null; + if($table === "whitelist") { + $table = "domainlist"; + $type = ListType::whitelist; + } else if($table === "blacklist") { + $table = "domainlist"; + $type = ListType::blacklist; + } else if($table === "regex_blacklist") { + $table = "domainlist"; + $type = ListType::regex_blacklist; + } else if($table === "domain_audit") { + $table = "domain_audit"; + $type = -1; // -1 -> not used inside add_to_table() + } else if($table === "adlist") { + $table = "adlist"; + $type = -1; // -1 -> not used inside add_to_table() + } - // Flush table if requested - if($flush) { - flush_table($table, $type); - } + // Flush table if requested + if($flush) { + flush_table($table, $type); + } - // Add domains to requested table - return add_to_table($db, $table, $domains, $comment, $wildcardstyle, true, $type); + // Add domains to requested table + return add_to_table($db, $table, $domains, $comment, $wildcardstyle, true, $type); } /** @@ -279,377 +279,377 @@ function archive_insert_into_table($file, $table, $flush=false, $wildcardstyle=f */ function flush_table($table, $type=null) { - global $db, $flushed_tables; + global $db, $flushed_tables; - if(!in_array($table, $flushed_tables)) - { - if($type !== null) { - $sql = "DELETE FROM \"".$table."\" WHERE type = ".$type; - array_push($flushed_tables, $table.$type); - } else { - $sql = "DELETE FROM \"".$table."\""; - array_push($flushed_tables, $table); - } - $db->exec($sql); - } + if(!in_array($table, $flushed_tables)) + { + if($type !== null) { + $sql = "DELETE FROM \"".$table."\" WHERE type = ".$type; + array_push($flushed_tables, $table.$type); + } else { + $sql = "DELETE FROM \"".$table."\""; + array_push($flushed_tables, $table); + } + $db->exec($sql); + } } function archive_add_directory($path,$subdir="") { - if($dir = opendir($path)) - { - while(false !== ($entry = readdir($dir))) - { - if($entry !== "." && $entry !== "..") - { - archive_add_file($path,$entry,$subdir); - } - } - closedir($dir); - } + if($dir = opendir($path)) + { + while(false !== ($entry = readdir($dir))) + { + if($entry !== "." && $entry !== "..") + { + archive_add_file($path,$entry,$subdir); + } + } + closedir($dir); + } } function limit_length(&$item, $key) { - // limit max length for a domain entry to 253 chars - // return only a part of the string if it is longer - $item = substr($item, 0, 253); + // limit max length for a domain entry to 253 chars + // return only a part of the string if it is longer + $item = substr($item, 0, 253); } function process_file($contents) { - $domains = array_filter(explode("\n",$contents)); - // Walk array and apply a max string length - // function to every member of the array of domains - array_walk($domains, "limit_length"); - return $domains; + $domains = array_filter(explode("\n",$contents)); + // Walk array and apply a max string length + // function to every member of the array of domains + array_walk($domains, "limit_length"); + return $domains; } function noun($num) { - if($num === 1) - { - return " entry"; - } - return " entries"; + if($num === 1) + { + return " entry"; + } + return " entries"; } if(isset($_POST["action"])) { - if($_FILES["zip_file"]["name"] && $_POST["action"] == "in") - { - $filename = $_FILES["zip_file"]["name"]; - $source = $_FILES["zip_file"]["tmp_name"]; - $type = mime_content_type($source); + if($_FILES["zip_file"]["name"] && $_POST["action"] == "in") + { + $filename = $_FILES["zip_file"]["name"]; + $source = $_FILES["zip_file"]["tmp_name"]; + $type = mime_content_type($source); - // verify the file mime type - $accepted_types = array('application/gzip', 'application/tar', 'application/x-compressed', 'application/x-gzip'); - $mime_valid = in_array($type, $accepted_types); + // verify the file mime type + $accepted_types = array('application/gzip', 'application/tar', 'application/x-compressed', 'application/x-gzip'); + $mime_valid = in_array($type, $accepted_types); - // verify the file extension (Looking for ".tar.gz" at the end of the file name) - $ext = array_slice(explode(".", $filename), -2, 2); - $ext_valid = strtolower($ext[0]) == "tar" && strtolower($ext[1]) == "gz" ? true : false; + // verify the file extension (Looking for ".tar.gz" at the end of the file name) + $ext = array_slice(explode(".", $filename), -2, 2); + $ext_valid = strtolower($ext[0]) == "tar" && strtolower($ext[1]) == "gz" ? true : false; - if(!$ext_valid || !$mime_valid) { - die("The file you are trying to upload is not a .tar.gz file (filename: ".htmlentities($filename).", type: ".htmlentities($type)."). Please try again."); - } + if(!$ext_valid || !$mime_valid) { + die("The file you are trying to upload is not a .tar.gz file (filename: ".htmlentities($filename).", type: ".htmlentities($type)."). Please try again."); + } - $fullfilename = sys_get_temp_dir()."/".$filename; + $fullfilename = sys_get_temp_dir()."/".$filename; - if(!move_uploaded_file($source, $fullfilename)) - { - die("Failed moving ".htmlentities($source)." to ".htmlentities($fullfilename)); - } + if(!move_uploaded_file($source, $fullfilename)) + { + die("Failed moving ".htmlentities($source)." to ".htmlentities($fullfilename)); + } - $archive = new PharData($fullfilename); + $archive = new PharData($fullfilename); - $importedsomething = false; - $fullpiholerestart = false; - $reloadsettingspage = false; + $importedsomething = false; + $fullpiholerestart = false; + $reloadsettingspage = false; - $flushtables = isset($_POST["flushtables"]); + $flushtables = isset($_POST["flushtables"]); - foreach(new RecursiveIteratorIterator($archive) as $file) - { - if(isset($_POST["blacklist"]) && $file->getFilename() === "blacklist.txt") - { - $num = archive_insert_into_table($file, "blacklist", $flushtables); - echo "Processed blacklist (exact) (".$num.noun($num).")
\n"; - $importedsomething = true; - } + foreach(new RecursiveIteratorIterator($archive) as $file) + { + if(isset($_POST["blacklist"]) && $file->getFilename() === "blacklist.txt") + { + $num = archive_insert_into_table($file, "blacklist", $flushtables); + echo "Processed blacklist (exact) (".$num.noun($num).")
\n"; + $importedsomething = true; + } - if(isset($_POST["whitelist"]) && $file->getFilename() === "whitelist.txt") - { - $num = archive_insert_into_table($file, "whitelist", $flushtables); - echo "Processed whitelist (exact) (".$num.noun($num).")
\n"; - $importedsomething = true; - } + if(isset($_POST["whitelist"]) && $file->getFilename() === "whitelist.txt") + { + $num = archive_insert_into_table($file, "whitelist", $flushtables); + echo "Processed whitelist (exact) (".$num.noun($num).")
\n"; + $importedsomething = true; + } - if(isset($_POST["regexlist"]) && $file->getFilename() === "regex.list") - { - $num = archive_insert_into_table($file, "regex_blacklist", $flushtables); - echo "Processed blacklist (regex) (".$num.noun($num).")
\n"; - $importedsomething = true; - } + if(isset($_POST["regexlist"]) && $file->getFilename() === "regex.list") + { + $num = archive_insert_into_table($file, "regex_blacklist", $flushtables); + echo "Processed blacklist (regex) (".$num.noun($num).")
\n"; + $importedsomething = true; + } - // Also try to import legacy wildcard list if found - if(isset($_POST["regexlist"]) && $file->getFilename() === "wildcardblocking.txt") - { - $num = archive_insert_into_table($file, "regex_blacklist", $flushtables, true); - echo "Processed blacklist (regex, wildcard style) (".$num.noun($num).")
\n"; - $importedsomething = true; - } + // Also try to import legacy wildcard list if found + if(isset($_POST["regexlist"]) && $file->getFilename() === "wildcardblocking.txt") + { + $num = archive_insert_into_table($file, "regex_blacklist", $flushtables, true); + echo "Processed blacklist (regex, wildcard style) (".$num.noun($num).")
\n"; + $importedsomething = true; + } - if(isset($_POST["auditlog"]) && $file->getFilename() === "auditlog.list") - { - $num = archive_insert_into_table($file, "domain_audit", $flushtables); - echo "Processed audit log (".$num.noun($num).")
\n"; - $importedsomething = true; - } + if(isset($_POST["auditlog"]) && $file->getFilename() === "auditlog.list") + { + $num = archive_insert_into_table($file, "domain_audit", $flushtables); + echo "Processed audit log (".$num.noun($num).")
\n"; + $importedsomething = true; + } - if(isset($_POST["adlist"]) && $file->getFilename() === "adlists.list") - { - $num = archive_insert_into_table($file, "adlist", $flushtables); - echo "Processed adlists (".$num.noun($num).")
\n"; - $importedsomething = true; - } + if(isset($_POST["adlist"]) && $file->getFilename() === "adlists.list") + { + $num = archive_insert_into_table($file, "adlist", $flushtables); + echo "Processed adlists (".$num.noun($num).")
\n"; + $importedsomething = true; + } - if(isset($_POST["blacklist"]) && $file->getFilename() === "blacklist.exact.json") - { - $num = archive_restore_table($file, "blacklist", $flushtables); - echo "Processed blacklist (exact) (".$num.noun($num).")
\n"; - $importedsomething = true; - } + if(isset($_POST["blacklist"]) && $file->getFilename() === "blacklist.exact.json") + { + $num = archive_restore_table($file, "blacklist", $flushtables); + echo "Processed blacklist (exact) (".$num.noun($num).")
\n"; + $importedsomething = true; + } - if(isset($_POST["regexlist"]) && $file->getFilename() === "blacklist.regex.json") - { - $num = archive_restore_table($file, "regex_blacklist", $flushtables); - echo "Processed blacklist (regex) (".$num.noun($num).")
\n"; - $importedsomething = true; - } + if(isset($_POST["regexlist"]) && $file->getFilename() === "blacklist.regex.json") + { + $num = archive_restore_table($file, "regex_blacklist", $flushtables); + echo "Processed blacklist (regex) (".$num.noun($num).")
\n"; + $importedsomething = true; + } - if(isset($_POST["whitelist"]) && $file->getFilename() === "whitelist.exact.json") - { - $num = archive_restore_table($file, "whitelist", $flushtables); - echo "Processed whitelist (exact) (".$num.noun($num).")
\n"; - $importedsomething = true; - } + if(isset($_POST["whitelist"]) && $file->getFilename() === "whitelist.exact.json") + { + $num = archive_restore_table($file, "whitelist", $flushtables); + echo "Processed whitelist (exact) (".$num.noun($num).")
\n"; + $importedsomething = true; + } - if(isset($_POST["regex_whitelist"]) && $file->getFilename() === "whitelist.regex.json") - { - $num = archive_restore_table($file, "regex_whitelist", $flushtables); - echo "Processed whitelist (regex) (".$num.noun($num).")
\n"; - $importedsomething = true; - } + if(isset($_POST["regex_whitelist"]) && $file->getFilename() === "whitelist.regex.json") + { + $num = archive_restore_table($file, "regex_whitelist", $flushtables); + echo "Processed whitelist (regex) (".$num.noun($num).")
\n"; + $importedsomething = true; + } - if(isset($_POST["adlist"]) && $file->getFilename() === "adlist.json") - { - $num = archive_restore_table($file, "adlist", $flushtables); - echo "Processed adlist (".$num.noun($num).")
\n"; - $importedsomething = true; - } + if(isset($_POST["adlist"]) && $file->getFilename() === "adlist.json") + { + $num = archive_restore_table($file, "adlist", $flushtables); + echo "Processed adlist (".$num.noun($num).")
\n"; + $importedsomething = true; + } - if(isset($_POST["auditlog"]) && $file->getFilename() === "domain_audit.json") - { - $num = archive_restore_table($file, "domain_audit", $flushtables); - echo "Processed domain_audit (".$num.noun($num).")
\n"; - $importedsomething = true; - } + if(isset($_POST["auditlog"]) && $file->getFilename() === "domain_audit.json") + { + $num = archive_restore_table($file, "domain_audit", $flushtables); + echo "Processed domain_audit (".$num.noun($num).")
\n"; + $importedsomething = true; + } - if(isset($_POST["group"]) && $file->getFilename() === "group.json") - { - $num = archive_restore_table($file, "group", $flushtables); - echo "Processed group (".$num.noun($num).")
\n"; - $importedsomething = true; - } + if(isset($_POST["group"]) && $file->getFilename() === "group.json") + { + $num = archive_restore_table($file, "group", $flushtables); + echo "Processed group (".$num.noun($num).")
\n"; + $importedsomething = true; + } - if(isset($_POST["client"]) && $file->getFilename() === "client.json") - { - $num = archive_restore_table($file, "client", $flushtables); - echo "Processed client (".$num.noun($num).")
\n"; - $importedsomething = true; - } + if(isset($_POST["client"]) && $file->getFilename() === "client.json") + { + $num = archive_restore_table($file, "client", $flushtables); + echo "Processed client (".$num.noun($num).")
\n"; + $importedsomething = true; + } - if(isset($_POST["client"]) && $file->getFilename() === "client_by_group.json") - { - $num = archive_restore_table($file, "client_by_group", $flushtables); - echo "Processed client group assignments (".$num.noun($num).")
\n"; - $importedsomething = true; - } + if(isset($_POST["client"]) && $file->getFilename() === "client_by_group.json") + { + $num = archive_restore_table($file, "client_by_group", $flushtables); + echo "Processed client group assignments (".$num.noun($num).")
\n"; + $importedsomething = true; + } - if((isset($_POST["whitelist"]) || isset($_POST["regex_whitelist"]) || - isset($_POST["blacklist"]) || isset($_POST["regex_blacklist"])) && - $file->getFilename() === "domainlist_by_group.json") - { - $num = archive_restore_table($file, "domainlist_by_group", $flushtables); - echo "Processed black-/whitelist group assignments (".$num.noun($num).")
\n"; - $importedsomething = true; - } + if((isset($_POST["whitelist"]) || isset($_POST["regex_whitelist"]) || + isset($_POST["blacklist"]) || isset($_POST["regex_blacklist"])) && + $file->getFilename() === "domainlist_by_group.json") + { + $num = archive_restore_table($file, "domainlist_by_group", $flushtables); + echo "Processed black-/whitelist group assignments (".$num.noun($num).")
\n"; + $importedsomething = true; + } - if(isset($_POST["adlist"]) && $file->getFilename() === "adlist_by_group.json") - { - $num = archive_restore_table($file, "adlist_by_group", $flushtables); - echo "Processed adlist group assignments (".$num.noun($num).")
\n"; - $importedsomething = true; - } + if(isset($_POST["adlist"]) && $file->getFilename() === "adlist_by_group.json") + { + $num = archive_restore_table($file, "adlist_by_group", $flushtables); + echo "Processed adlist group assignments (".$num.noun($num).")
\n"; + $importedsomething = true; + } - if(isset($_POST["staticdhcpleases"]) && $file->getFilename() === "04-pihole-static-dhcp.conf") - { - if($flushtables) { - $local_file = @fopen("/etc/dnsmasq.d/04-pihole-static-dhcp.conf", "r+"); - if ($local_file !== false) { - ftruncate($local_file, 0); - fclose($local_file); - } - } - $num = 0; - $staticdhcpleases = process_file(file_get_contents($file)); - foreach($staticdhcpleases as $lease) { - list($mac,$ip,$hostname) = explode(",",$lease); - $mac = formatMAC($mac); - if(addStaticDHCPLease($mac,$ip,$hostname)) - $num++; - } + if(isset($_POST["staticdhcpleases"]) && $file->getFilename() === "04-pihole-static-dhcp.conf") + { + if($flushtables) { + $local_file = @fopen("/etc/dnsmasq.d/04-pihole-static-dhcp.conf", "r+"); + if ($local_file !== false) { + ftruncate($local_file, 0); + fclose($local_file); + } + } + $num = 0; + $staticdhcpleases = process_file(file_get_contents($file)); + foreach($staticdhcpleases as $lease) { + list($mac,$ip,$hostname) = explode(",",$lease); + $mac = formatMAC($mac); + if(addStaticDHCPLease($mac,$ip,$hostname)) + $num++; + } - readStaticLeasesFile(); - echo "Processed static DHCP leases (".$num.noun($num).")
\n"; - if($num > 0) { - $importedsomething = true; - $reloadsettingspage = true; - } - } + readStaticLeasesFile(); + echo "Processed static DHCP leases (".$num.noun($num).")
\n"; + if($num > 0) { + $importedsomething = true; + $reloadsettingspage = true; + } + } - if(isset($_POST["localdnsrecords"]) && $file->getFilename() === "custom.list") - { - ob_start(); - $reload="false"; - if($flushtables) { - // Defined in func.php included via auth.php - // passing reload="false" will not restart Pi-hole - deleteAllCustomDNSEntries($reload); - } - $num = 0; - $localdnsrecords = process_file(file_get_contents($file)); - foreach($localdnsrecords as $record) { - list($ip,$domain) = explode(" ",$record); - if(addCustomDNSEntry($ip, $domain, $reload, false)) - $num++; - } - ob_end_clean(); - echo "Processed local DNS records (".$num.noun($num).")
\n"; - if($num > 0) { - // we need a full pihole restart - $fullpiholerestart = true; - } - } + if(isset($_POST["localdnsrecords"]) && $file->getFilename() === "custom.list") + { + ob_start(); + $reload="false"; + if($flushtables) { + // Defined in func.php included via auth.php + // passing reload="false" will not restart Pi-hole + deleteAllCustomDNSEntries($reload); + } + $num = 0; + $localdnsrecords = process_file(file_get_contents($file)); + foreach($localdnsrecords as $record) { + list($ip,$domain) = explode(" ",$record); + if(addCustomDNSEntry($ip, $domain, $reload, false)) + $num++; + } + ob_end_clean(); + echo "Processed local DNS records (".$num.noun($num).")
\n"; + if($num > 0) { + // we need a full pihole restart + $fullpiholerestart = true; + } + } - if(isset($_POST["localcnamerecords"]) && $file->getFilename() === "05-pihole-custom-cname.conf") - { - ob_start(); - $reload="false"; - if($flushtables) { - // Defined in func.php included via auth.php - //passing reload="false" will not restart Pi-hole - deleteAllCustomCNAMEEntries($reload); - } + if(isset($_POST["localcnamerecords"]) && $file->getFilename() === "05-pihole-custom-cname.conf") + { + ob_start(); + $reload="false"; + if($flushtables) { + // Defined in func.php included via auth.php + //passing reload="false" will not restart Pi-hole + deleteAllCustomCNAMEEntries($reload); + } - $num = 0; - $localcnamerecords = process_file(file_get_contents($file)); - foreach($localcnamerecords as $record) { - $line = str_replace("cname=","", $record); - $line = str_replace("\r","", $line); - $line = str_replace("\n","", $line); - $explodedLine = explode (",", $line); + $num = 0; + $localcnamerecords = process_file(file_get_contents($file)); + foreach($localcnamerecords as $record) { + $line = str_replace("cname=","", $record); + $line = str_replace("\r","", $line); + $line = str_replace("\n","", $line); + $explodedLine = explode (",", $line); - $domain = implode(",", array_slice($explodedLine, 0, -1)); - $target = $explodedLine[count($explodedLine)-1]; + $domain = implode(",", array_slice($explodedLine, 0, -1)); + $target = $explodedLine[count($explodedLine)-1]; - if(addCustomCNAMEEntry($domain, $target, $reload, false)) - $num++; - } - ob_end_clean(); - echo "Processed local CNAME records (".$num.noun($num).")
\n"; - if($num > 0) { - // we need a full pihole restart - $fullpiholerestart = true; - } - } - } + if(addCustomCNAMEEntry($domain, $target, $reload, false)) + $num++; + } + ob_end_clean(); + echo "Processed local CNAME records (".$num.noun($num).")
\n"; + if($num > 0) { + // we need a full pihole restart + $fullpiholerestart = true; + } + } + } - // do we need a full restart of Pi-hole or reloading the lists? - if($fullpiholerestart) - { - pihole_execute("restartdns"); - } else { - if($importedsomething) - { - pihole_execute("restartdns reload"); - } - } + // do we need a full restart of Pi-hole or reloading the lists? + if($fullpiholerestart) + { + pihole_execute("restartdns"); + } else { + if($importedsomething) + { + pihole_execute("restartdns reload"); + } + } - unlink($fullfilename); - echo "OK"; - if($reloadsettingspage) - { - echo "
\n"; - } - } - else - { - die("No file transmitted or parameter error."); - } + unlink($fullfilename); + echo "OK"; + if($reloadsettingspage) + { + echo "
\n"; + } + } + else + { + die("No file transmitted or parameter error."); + } } else { - $hostname = gethostname() ? str_replace(".", "_", gethostname())."-" : ""; - $tarname = "pi-hole-".$hostname."teleporter_".date("Y-m-d_H-i-s").".tar"; - $filename = $tarname.".gz"; + $hostname = gethostname() ? str_replace(".", "_", gethostname())."-" : ""; + $tarname = "pi-hole-".$hostname."teleporter_".date("Y-m-d_H-i-s").".tar"; + $filename = $tarname.".gz"; $archive_file_name = tempnam(sys_get_temp_dir(), 'pihole_teleporter_'); //create a random file name in the system's tmp dir for the intermediat archive unlink($archive_file_name); //remove intermediate file created by tempnam() $archive_file_name .= ".tar"; // Append ".tar" extension - $archive = new PharData($archive_file_name); + $archive = new PharData($archive_file_name); - if ($archive->isWritable() !== TRUE) { - exit("cannot open/create ".htmlentities($archive_file_name)."
\nPHP user: ".exec('whoami')."\n"); - } + if ($archive->isWritable() !== TRUE) { + exit("cannot open/create ".htmlentities($archive_file_name)."
\nPHP user: ".exec('whoami')."\n"); + } - archive_add_table("whitelist.exact.json", "domainlist", ListType::whitelist); - archive_add_table("whitelist.regex.json", "domainlist", ListType::regex_whitelist); - archive_add_table("blacklist.exact.json", "domainlist", ListType::blacklist); - archive_add_table("blacklist.regex.json", "domainlist", ListType::regex_blacklist); - archive_add_table("adlist.json", "adlist"); - archive_add_table("domain_audit.json", "domain_audit"); - archive_add_table("group.json", "group"); - archive_add_table("client.json", "client"); + archive_add_table("whitelist.exact.json", "domainlist", ListType::whitelist); + archive_add_table("whitelist.regex.json", "domainlist", ListType::regex_whitelist); + archive_add_table("blacklist.exact.json", "domainlist", ListType::blacklist); + archive_add_table("blacklist.regex.json", "domainlist", ListType::regex_blacklist); + archive_add_table("adlist.json", "adlist"); + archive_add_table("domain_audit.json", "domain_audit"); + archive_add_table("group.json", "group"); + archive_add_table("client.json", "client"); - // Group linking tables - archive_add_table("domainlist_by_group.json", "domainlist_by_group"); - archive_add_table("adlist_by_group.json", "adlist_by_group"); - archive_add_table("client_by_group.json", "client_by_group"); + // Group linking tables + archive_add_table("domainlist_by_group.json", "domainlist_by_group"); + archive_add_table("adlist_by_group.json", "adlist_by_group"); + archive_add_table("client_by_group.json", "client_by_group"); - archive_add_file("/etc/pihole/","setupVars.conf"); - archive_add_file("/etc/pihole/","dhcp.leases"); - archive_add_file("/etc/pihole/","custom.list"); - archive_add_file("/etc/pihole/","pihole-FTL.conf"); - archive_add_file("/etc/","hosts","etc/"); - archive_add_directory("/etc/dnsmasq.d/","dnsmasq.d/"); + archive_add_file("/etc/pihole/","setupVars.conf"); + archive_add_file("/etc/pihole/","dhcp.leases"); + archive_add_file("/etc/pihole/","custom.list"); + archive_add_file("/etc/pihole/","pihole-FTL.conf"); + archive_add_file("/etc/","hosts","etc/"); + archive_add_directory("/etc/dnsmasq.d/","dnsmasq.d/"); - $archive->compress(Phar::GZ); // Creates a gzipped copy - unlink($archive_file_name); // Unlink original tar file as it is not needed anymore - $archive_file_name .= ".gz"; // Append ".gz" extension to ".tar" + $archive->compress(Phar::GZ); // Creates a gzipped copy + unlink($archive_file_name); // Unlink original tar file as it is not needed anymore + $archive_file_name .= ".gz"; // Append ".gz" extension to ".tar" - header("Content-type: application/gzip"); - header('Content-Transfer-Encoding: binary'); - header("Content-Disposition: attachment; filename=".$filename); - header("Content-length: " . filesize($archive_file_name)); - header("Pragma: no-cache"); - header("Expires: 0"); - if(ob_get_length() > 0) ob_end_clean(); - readfile($archive_file_name); - ignore_user_abort(true); - unlink($archive_file_name); - exit; + header("Content-type: application/gzip"); + header('Content-Transfer-Encoding: binary'); + header("Content-Disposition: attachment; filename=".$filename); + header("Content-length: " . filesize($archive_file_name)); + header("Pragma: no-cache"); + header("Expires: 0"); + if(ob_get_length() > 0) ob_end_clean(); + readfile($archive_file_name); + ignore_user_abort(true); + unlink($archive_file_name); + exit; } ?> diff --git a/settings.php b/settings.php index 1f064f0e..47ccbfb1 100644 --- a/settings.php +++ b/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.
Debugging information:
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.
Debugging information:
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'"); } ?>