Merge pull request #2293 from pi-hole/tweak/no_yoda

To Yoda or Not to Yoda
This commit is contained in:
DL6ER
2022-08-12 19:05:30 +02:00
committed by GitHub
21 changed files with 257 additions and 256 deletions
+1
View File
@@ -22,6 +22,7 @@ $config
->setRules(array(
'@Symfony' => true,
'array_syntax' => array('syntax' => 'long'),
'yoda_style' => array('equal' => false, 'identical' => false, 'less_and_greater' => false, 'always_move_variable' => false),
))
->setLineEnding(PHP_EOL)
->setFinder($finder)
+7 -7
View File
@@ -43,12 +43,12 @@ if (isset($_GET['summary']) || isset($_GET['summaryRaw']) || !count($_GET)) {
foreach ($return as $line) {
$tmp = explode(' ', $line);
if ('domains_being_blocked' === $tmp[0] && !is_numeric($tmp[1]) || 'status' === $tmp[0]) {
if ($tmp[0] === 'domains_being_blocked' && !is_numeric($tmp[1]) || $tmp[0] === 'status') {
// Expect string response
$stats[$tmp[0]] = $tmp[1];
} elseif (isset($_GET['summary'])) {
// "summary" expects a formmated string response
if ('ads_percentage_today' !== $tmp[0]) {
if ($tmp[0] !== 'ads_percentage_today') {
$stats[$tmp[0]] = number_format($tmp[1]);
} else {
$stats[$tmp[0]] = number_format($tmp[1], 1, '.', '');
@@ -100,7 +100,7 @@ if (isset($_GET['overTimeData10mins'])) {
}
if (isset($_GET['topItems']) && $auth) {
if ('audit' === $_GET['topItems']) {
if ($_GET['topItems'] === 'audit') {
$return = callFTLAPI('top-domains for audit');
} elseif (is_numeric($_GET['topItems'])) {
$return = callFTLAPI('top-domains ('.$_GET['topItems'].')');
@@ -114,7 +114,7 @@ if (isset($_GET['topItems']) && $auth) {
$top_queries = array();
foreach ($return as $line) {
$tmp = explode(' ', $line);
if (2 == count($tmp)) {
if (count($tmp) == 2) {
$tmp[2] = '';
}
$domain = utf8_encode($tmp[2]);
@@ -122,7 +122,7 @@ if (isset($_GET['topItems']) && $auth) {
}
}
if ('audit' === $_GET['topItems']) {
if ($_GET['topItems'] === 'audit') {
$return = callFTLAPI('top-ads for audit');
} elseif (is_numeric($_GET['topItems'])) {
$return = callFTLAPI('top-ads ('.$_GET['topItems'].')');
@@ -216,7 +216,7 @@ if (isset($_GET['topClientsBlocked']) && $auth) {
}
if (isset($_GET['getForwardDestinations']) && $auth) {
if ('unsorted' === $_GET['getForwardDestinations']) {
if ($_GET['getForwardDestinations'] === 'unsorted') {
$return = callFTLAPI('forward-dest unsorted');
} else {
$return = callFTLAPI('forward-dest');
@@ -282,7 +282,7 @@ if (isset($_GET['getAllQueries']) && $auth) {
} elseif (isset($_GET['domain'])) {
// Get specific domain only
$return = callFTLAPI('getallqueries-domain '.$_GET['domain']);
} elseif (isset($_GET['client']) && (isset($_GET['type']) && 'blocked' === $_GET['type'])) {
} elseif (isset($_GET['client']) && (isset($_GET['type']) && $_GET['type'] === 'blocked')) {
// Get specific client only
$return = callFTLAPI('getallqueries-client-blocked '.$_GET['client']);
} elseif (isset($_GET['client'])) {
+9 -9
View File
@@ -30,16 +30,16 @@ if (isset($_GET['network']) && $auth) {
$network = array();
$results = $db->query('SELECT * FROM network');
while (false !== $results && $res = $results->fetchArray(SQLITE3_ASSOC)) {
while ($results !== false && $res = $results->fetchArray(SQLITE3_ASSOC)) {
$id = intval($res['id']);
// Get IP addresses and host names for this device
$res['ip'] = array();
$res['name'] = array();
$network_addresses = $db->query("SELECT ip,name FROM network_addresses WHERE network_id = {$id} ORDER BY lastSeen DESC");
while (false !== $network_addresses && $network_address = $network_addresses->fetchArray(SQLITE3_ASSOC)) {
while ($network_addresses !== false && $network_address = $network_addresses->fetchArray(SQLITE3_ASSOC)) {
array_push($res['ip'], $network_address['ip']);
if (null !== $network_address['name']) {
if ($network_address['name'] !== null) {
array_push($res['name'], utf8_encode($network_address['name']));
} else {
array_push($res['name'], '');
@@ -58,7 +58,7 @@ if (isset($_GET['network']) && $auth) {
if (isset($_GET['getAllQueries']) && $auth) {
$allQueries = array();
if ('empty' !== $_GET['getAllQueries']) {
if ($_GET['getAllQueries'] !== 'empty') {
$from = intval($_GET['from']);
$until = intval($_GET['until']);
@@ -77,7 +77,7 @@ if (isset($_GET['getAllQueries']) && $auth) {
$dbquery .= ' WHERE timestamp >= :from AND timestamp <= :until ';
if (isset($_GET['types'])) {
$types = $_GET['types'];
if (1 === preg_match('/^[0-9]+(?:,[0-9]+)*$/', $types)) {
if (preg_match('/^[0-9]+(?:,[0-9]+)*$/', $types) === 1) {
// Append selector to DB query. The used regex ensures
// that only numbers, separated by commas are accepted
// to avoid code injection and other malicious things
@@ -331,7 +331,7 @@ if (isset($_GET['getGraphData']) && $auth) {
while ($row = $results->fetchArray()) {
// $data[timestamp] = value_in_this_interval
$data[$row[0]] = intval($row[1]);
if (-1 === $first_db_timestamp) {
if ($first_db_timestamp === -1) {
$first_db_timestamp = intval($row[0]);
}
}
@@ -373,7 +373,7 @@ if (isset($_GET['getGraphData']) && $auth) {
if (isset($_GET['status']) && $auth) {
$extra = ';';
if (isset($_GET['ignore']) && 'DNSMASQ_WARN' === $_GET['ignore']) {
if (isset($_GET['ignore']) && $_GET['ignore'] === 'DNSMASQ_WARN') {
$extra = "WHERE type != 'DNSMASQ_WARN';";
}
$results = $db->query('SELECT COUNT(*) FROM message '.$extra);
@@ -389,14 +389,14 @@ if (isset($_GET['status']) && $auth) {
if (isset($_GET['messages']) && $auth) {
$extra = ';';
if (isset($_GET['ignore']) && 'DNSMASQ_WARN' === $_GET['ignore']) {
if (isset($_GET['ignore']) && $_GET['ignore'] === 'DNSMASQ_WARN') {
$extra = "WHERE type != 'DNSMASQ_WARN';";
}
$messages = array();
$results = $db->query('SELECT * FROM message '.$extra);
while (false !== $results && $res = $results->fetchArray(SQLITE3_ASSOC)) {
while ($results !== false && $res = $results->fetchArray(SQLITE3_ASSOC)) {
// Convert string to to UTF-8 encoding to ensure php-json can handle it.
// Furthermore, convert special characters to HTML entities to prevent XSS attacks.
foreach ($res as $key => $value) {
+8 -8
View File
@@ -13,16 +13,16 @@ require 'scripts/pi-hole/php/header.php';
$showing = '';
if (isset($setupVars['API_QUERY_LOG_SHOW'])) {
if ('all' === $setupVars['API_QUERY_LOG_SHOW']) {
if ($setupVars['API_QUERY_LOG_SHOW'] === 'all') {
$showing = 'showing';
} elseif ('permittedonly' === $setupVars['API_QUERY_LOG_SHOW']) {
} elseif ($setupVars['API_QUERY_LOG_SHOW'] === 'permittedonly') {
$showing = 'showing permitted';
} elseif ('blockedonly' === $setupVars['API_QUERY_LOG_SHOW']) {
} elseif ($setupVars['API_QUERY_LOG_SHOW'] === 'blockedonly') {
$showing = 'showing blocked';
} elseif ('nothing' === $setupVars['API_QUERY_LOG_SHOW']) {
} elseif ($setupVars['API_QUERY_LOG_SHOW'] === 'nothing') {
$showing = 'showing no queries (due to setting)';
}
} elseif (isset($_GET['type']) && 'blocked' === $_GET['type']) {
} elseif (isset($_GET['type']) && $_GET['type'] === 'blocked') {
$showing = 'showing blocked';
} else {
// If filter variable is not set, we
@@ -35,7 +35,7 @@ if (isset($_GET['all'])) {
$showing .= ' all queries within the Pi-hole log';
} elseif (isset($_GET['client'])) {
// Add switch between showing all queries and blocked only
if (isset($_GET['type']) && 'blocked' === $_GET['type']) {
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>';
@@ -45,9 +45,9 @@ if (isset($_GET['all'])) {
$showing .= ', <a href="?client='.htmlentities($_GET['client']).'&type=blocked">show blocked only</a>';
}
} elseif (isset($_GET['forwarddest'])) {
if ('blocked' === $_GET['forwarddest']) {
if ($_GET['forwarddest'] === 'blocked') {
$showing .= ' queries blocked by Pi-hole';
} elseif ('cached' === $_GET['forwarddest']) {
} elseif ($_GET['forwarddest'] === 'cached') {
$showing .= ' queries answered from cache';
} else {
$showing .= ' queries for upstream destination '.htmlentities($_GET['forwarddest']);
+4 -4
View File
@@ -31,11 +31,11 @@ function piholeFTLConfig($piholeFTLConfFile = DEFAULT_FTLCONFFILE, $force = fals
function connectFTL($address, $port)
{
if (DEFAULT_FTL_IP == $address) {
if ($address == DEFAULT_FTL_IP) {
$config = piholeFTLConfig();
// Read port
$portfileName = isset($config['PORTFILE']) ? $config['PORTFILE'] : DEFAULT_FTL_PORTFILE;
if ('' != $portfileName) {
if ($portfileName != '') {
$portfileContents = file_get_contents($portfileName);
if (is_numeric($portfileContents)) {
$port = intval($portfileContents);
@@ -60,7 +60,7 @@ function getResponseFTL($socket)
$errCount = 0;
while (true) {
$out = fgets($socket);
if ('' == $out) {
if ($out == '') {
++$errCount;
}
@@ -69,7 +69,7 @@ function getResponseFTL($socket)
exit('{"error":"Tried 100 times to connect to FTL server, but never got proper reply. Please check Port and logs!"}');
}
if (false !== strrpos($out, '---EOM---')) {
if (strrpos($out, '---EOM---') !== false) {
break;
}
+2 -2
View File
@@ -102,8 +102,8 @@ function check_csrf($token)
{
// Check CSRF token
$session_started = function_exists('session_status') ?
PHP_SESSION_ACTIVE == session_status() :
'' == session_id();
session_status() == PHP_SESSION_ACTIVE :
session_id() == '';
if (!$session_started) {
// Start a new PHP session (or continue an existing one)
+10 -10
View File
@@ -93,14 +93,14 @@ function add_to_table($db, $table, $domains, $comment = null, $wildcardstyle = f
}
// To which column should the record be added to?
if ('adlist' === $table) {
if ($table === 'adlist') {
$field = 'address';
} else {
$field = 'domain';
}
// Get initial count of domains in this table
if (-1 === $type) {
if ($type === -1) {
$countquery = "SELECT COUNT(*) FROM {$table};";
} else {
$countquery = "SELECT COUNT(*) FROM {$table} WHERE type = {$type};";
@@ -109,9 +109,9 @@ function add_to_table($db, $table, $domains, $comment = null, $wildcardstyle = f
// Prepare INSERT SQLite statement
$bindcomment = false;
if ('domain_audit' === $table) {
if ($table === 'domain_audit') {
$querystr = "INSERT OR IGNORE INTO {$table} ({$field}) VALUES (:{$field});";
} elseif (-1 === $type) {
} elseif ($type === -1) {
$querystr = "INSERT OR IGNORE INTO {$table} ({$field},comment) VALUES (:{$field}, :comment);";
$bindcomment = true;
} else {
@@ -153,7 +153,7 @@ function add_to_table($db, $table, $domains, $comment = null, $wildcardstyle = f
if ($returnnum) {
return $num;
}
if (1 === $num) {
if ($num === 1) {
$plural = '';
} else {
$plural = 's';
@@ -181,7 +181,7 @@ function add_to_table($db, $table, $domains, $comment = null, $wildcardstyle = f
$extra = '';
}
if (1 === $num) {
if ($num === 1) {
$plural = '';
} else {
$plural = 's';
@@ -217,7 +217,7 @@ function remove_from_table($db, $table, $domains, $returnnum = false, $type = -1
}
// Get initial count of domains in this table
if (-1 === $type) {
if ($type === -1) {
$countquery = "SELECT COUNT(*) FROM {$table};";
} else {
$countquery = "SELECT COUNT(*) FROM {$table} WHERE type = {$type};";
@@ -225,7 +225,7 @@ function remove_from_table($db, $table, $domains, $returnnum = false, $type = -1
$initialcount = intval($db->querySingle($countquery));
// Prepare SQLite statement
if (-1 === $type) {
if ($type === -1) {
$querystr = "DELETE FROM {$table} WHERE domain = :domain AND type = {$type};";
} else {
$querystr = "DELETE FROM {$table} WHERE domain = :domain;";
@@ -253,7 +253,7 @@ function remove_from_table($db, $table, $domains, $returnnum = false, $type = -1
if ($returnnum) {
return $num;
}
if (1 === $num) {
if ($num === 1) {
$plural = '';
} else {
$plural = 's';
@@ -270,7 +270,7 @@ function remove_from_table($db, $table, $domains, $returnnum = false, $type = -1
if ($returnnum) {
return $num;
}
if (1 === $num) {
if ($num === 1) {
$plural = '';
} else {
$plural = 's';
+8 -8
View File
@@ -13,21 +13,21 @@ 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 (null !== $message) {
if ($message !== null) {
$message = 'it contains invalid characters';
}
return false;
}
if (!preg_match('/^.{1,253}$/', $domain_name)) {
if (null !== $message) {
if ($message !== null) {
$message = 'its length is invalid';
}
return false;
}
if (!preg_match('/^[^\\.]{1,63}(\\.[^\\.]{1,63})*$/', $domain_name)) {
if (null !== $message) {
if ($message !== null) {
$message = 'at least one label is of invalid length';
}
@@ -55,13 +55,13 @@ function validIP($address)
return false;
}
return false === !filter_var($address, FILTER_VALIDATE_IP);
return !filter_var($address, FILTER_VALIDATE_IP) === false;
}
function validCIDRIP($address)
{
// This validation strategy has been taken from ../js/groups-common.js
$isIPv6 = false !== strpos($address, ':');
$isIPv6 = strpos($address, ':') !== false;
if ($isIPv6) {
// One IPv6 element is 16bit: 0000 - FFFF
$v6elem = '[0-9A-Fa-f]{1,4}';
@@ -83,7 +83,7 @@ function validCIDRIP($address)
function validMAC($mac_addr)
{
// Accepted input format: 00:01:02:1A:5F:FF (characters may be lower case)
return false === !filter_var($mac_addr, FILTER_VALIDATE_MAC);
return !filter_var($mac_addr, FILTER_VALIDATE_MAC) === false;
}
function validEmail($email)
@@ -155,7 +155,7 @@ function pihole_execute($argument_string)
$return_status = -1;
$command = 'sudo pihole '.$escaped;
exec($command, $output, $return_status);
if (0 !== $return_status) {
if ($return_status !== 0) {
trigger_error("Executing {$command} failed.", E_USER_WARNING);
}
@@ -190,7 +190,7 @@ function getCustomDNSEntries()
$line = str_replace("\n", '', $line);
$explodedLine = explode(' ', $line);
if (2 != count($explodedLine)) {
if (count($explodedLine) != 2) {
continue;
}
+2 -2
View File
@@ -13,7 +13,7 @@ function gravity_last_update($raw = false)
{
$db = SQLite3_connect(getGravityDBFilename());
$date_file_created_unix = $db->querySingle("SELECT value FROM info WHERE property = 'updated';");
if (false === $date_file_created_unix) {
if ($date_file_created_unix === false) {
if ($raw) {
// Array output
return array('file_exists' => false);
@@ -43,7 +43,7 @@ function gravity_last_update($raw = false)
// String output (more than one day ago)
return $gravitydiff->format('Adlists updated %a days, %H:%I (hh:mm) ago');
}
if (1 == $gravitydiff->d) {
if ($gravitydiff->d == 1) {
// String output (one day ago)
return $gravitydiff->format('Adlists updated one day, %H:%I (hh:mm) ago');
}
+1 -1
View File
@@ -28,7 +28,7 @@ function echoEvent($datatext)
// "Pending: String to replace${OVER}Done: String has been replaced"
// If this is the case, we have to remove everything before ${OVER}
// and return only the text thereafter
if (false !== $pos && 0 !== $pos) {
if ($pos !== false && $pos !== 0) {
$datatext = substr($datatext, $pos);
}
echo 'data: '.implode("\ndata: ", explode("\n", $datatext))."\n\n";
+54 -54
View File
@@ -40,7 +40,7 @@ function verify_ID_array($arr)
}
}
if ('get_groups' == $_POST['action']) {
if ($_POST['action'] == 'get_groups') {
// List all available groups
try {
$query = $db->query('SELECT * FROM "group";');
@@ -54,7 +54,7 @@ if ('get_groups' == $_POST['action']) {
} catch (\Exception $ex) {
JSON_error($ex->getMessage());
}
} elseif ('add_group' == $_POST['action']) {
} elseif ($_POST['action'] == 'add_group') {
// Add new group
try {
$input = html_entity_decode(trim($_POST['name']));
@@ -67,7 +67,7 @@ if ('get_groups' == $_POST['action']) {
}
$desc = $_POST['desc'];
if (0 === strlen($desc)) {
if (strlen($desc) === 0) {
// Store NULL in database for empty descriptions
$desc = null;
}
@@ -77,7 +77,7 @@ if ('get_groups' == $_POST['action']) {
foreach ($names as $name) {
// Silently skip this entry when it is empty or not a string (e.g. NULL)
if (!is_string($name) || 0 == strlen($name)) {
if (!is_string($name) || strlen($name) == 0) {
continue;
}
@@ -96,7 +96,7 @@ if ('get_groups' == $_POST['action']) {
} catch (\Exception $ex) {
JSON_error($ex->getMessage());
}
} elseif ('edit_group' == $_POST['action']) {
} elseif ($_POST['action'] == 'edit_group') {
// Edit group identified by ID
try {
$name = html_entity_decode($_POST['name']);
@@ -116,7 +116,7 @@ if ('get_groups' == $_POST['action']) {
throw new Exception('While binding name: '.$db->lastErrorMsg());
}
if (0 === strlen($desc)) {
if (strlen($desc) === 0) {
// Store NULL in database for empty descriptions
$desc = null;
}
@@ -137,7 +137,7 @@ if ('get_groups' == $_POST['action']) {
} catch (\Exception $ex) {
JSON_error($ex->getMessage());
}
} elseif ('delete_group' == $_POST['action']) {
} elseif ($_POST['action'] == 'delete_group') {
// Delete group identified by ID
try {
$ids = json_decode($_POST['id']);
@@ -170,7 +170,7 @@ if ('get_groups' == $_POST['action']) {
} catch (\Exception $ex) {
JSON_error($ex->getMessage());
}
} elseif ('get_clients' == $_POST['action']) {
} elseif ($_POST['action'] == 'get_clients') {
// List all available groups
try {
$QUERYDB = getQueriesDBFilename();
@@ -250,7 +250,7 @@ if ('get_groups' == $_POST['action']) {
} catch (\Exception $ex) {
JSON_error($ex->getMessage());
}
} elseif ('get_unconfigured_clients' == $_POST['action']) {
} elseif ($_POST['action'] == 'get_unconfigured_clients') {
// List all available clients WITHOUT already configured clients
try {
$QUERYDB = getQueriesDBFilename();
@@ -272,7 +272,7 @@ if ('get_groups' == $_POST['action']) {
$names = array();
while ($res_ips = $query_ips->fetchArray(SQLITE3_ASSOC)) {
array_push($addresses, utf8_encode($res_ips['ip']));
if (null !== $res_ips['name']) {
if ($res_ips['name'] !== null) {
array_push($names, utf8_encode($res_ips['name']));
}
}
@@ -281,7 +281,7 @@ if ('get_groups' == $_POST['action']) {
// Prepare extra information
$extrainfo = '';
// Add list of associated host names to info string (if available)
if (1 === count($names)) {
if (count($names) === 1) {
$extrainfo .= 'hostname: '.$names[0];
} elseif (count($names) > 0) {
$extrainfo .= 'hostnames: '.implode(', ', $names);
@@ -296,12 +296,12 @@ if ('get_groups' == $_POST['action']) {
}
// Add list of associated host names to info string (if available and if this is not a mock device)
if (false === stripos($res['hwaddr'], 'ip-')) {
if (stripos($res['hwaddr'], 'ip-') === false) {
if ((count($names) > 0 || strlen($res['macVendor']) > 0) && count($addresses) > 0) {
$extrainfo .= '; ';
}
if (1 === count($addresses)) {
if (count($addresses) === 1) {
$extrainfo .= 'address: '.$addresses[0];
} elseif (count($addresses) > 0) {
$extrainfo .= 'addresses: '.implode(', ', $addresses);
@@ -332,7 +332,7 @@ if ('get_groups' == $_POST['action']) {
} catch (\Exception $ex) {
JSON_error($ex->getMessage());
}
} elseif ('add_client' == $_POST['action']) {
} elseif ($_POST['action'] == 'add_client') {
// Add new client
try {
$ips = explode(' ', trim($_POST['ip']));
@@ -347,7 +347,7 @@ if ('get_groups' == $_POST['action']) {
// Encode $ip variable to prevent XSS
$ip = htmlspecialchars($ip);
// Silently skip this entry when it is empty or not a string (e.g. NULL)
if (!is_string($ip) || 0 == strlen($ip)) {
if (!is_string($ip) || strlen($ip) == 0) {
continue;
}
@@ -356,7 +356,7 @@ if ('get_groups' == $_POST['action']) {
}
$comment = html_entity_decode($_POST['comment']);
if (0 === strlen($comment)) {
if (strlen($comment) === 0) {
// Store NULL in database for empty comments
$comment = null;
}
@@ -375,7 +375,7 @@ if ('get_groups' == $_POST['action']) {
} catch (\Exception $ex) {
JSON_error($ex->getMessage());
}
} elseif ('edit_client' == $_POST['action']) {
} elseif ($_POST['action'] == 'edit_client') {
// Edit client identified by ID
try {
$db->query('BEGIN TRANSACTION;');
@@ -386,7 +386,7 @@ if ('get_groups' == $_POST['action']) {
}
$comment = html_entity_decode($_POST['comment']);
if (0 === strlen($comment)) {
if (strlen($comment) === 0) {
// Store NULL in database for empty comments
$comment = null;
}
@@ -446,7 +446,7 @@ if ('get_groups' == $_POST['action']) {
} catch (\Exception $ex) {
JSON_error($ex->getMessage());
}
} elseif ('delete_client' == $_POST['action']) {
} elseif ($_POST['action'] == 'delete_client') {
// Delete client identified by ID
try {
$ids = json_decode($_POST['id']);
@@ -484,7 +484,7 @@ if ('get_groups' == $_POST['action']) {
} catch (\Exception $ex) {
JSON_error($ex->getMessage());
}
} elseif ('get_domains' == $_POST['action']) {
} elseif ($_POST['action'] == 'get_domains') {
// List all available groups
try {
$limit = '';
@@ -508,7 +508,7 @@ if ('get_groups' == $_POST['action']) {
array_push($groups, $gres['group_id']);
}
$res['groups'] = $groups;
if (ListType::whitelist === $res['type'] || ListType::blacklist === $res['type']) {
if ($res['type'] === ListType::whitelist || $res['type'] === ListType::blacklist) {
// Convert domain name to international form
$utf8_domain = convertIDNAToUnicode($res['domain']);
@@ -528,7 +528,7 @@ if ('get_groups' == $_POST['action']) {
} catch (\Exception $ex) {
JSON_error($ex->getMessage());
}
} elseif ('add_domain' == $_POST['action'] || 'replace_domain' == $_POST['action']) {
} elseif ($_POST['action'] == 'add_domain' || $_POST['action'] == 'replace_domain') {
// Add new domain
try {
$domains = explode(' ', html_entity_decode(trim($_POST['domain'])));
@@ -552,7 +552,7 @@ if ('get_groups' == $_POST['action']) {
$check_stmt = null;
$delete_stmt = null;
if ('replace_domain' == $_POST['action']) {
if ($_POST['action'] == 'replace_domain') {
// Check statement will reveal any group associations for a given (domain,type) which do NOT belong to the default group
$check_stmt = $db->prepare('SELECT EXISTS(SELECT domain FROM domainlist_by_group dlbg JOIN domainlist dl on dlbg.domainlist_id = dl.id WHERE dl.domain = :domain AND dlbg.group_id != 0)');
if (!$check_stmt) {
@@ -567,9 +567,9 @@ if ('get_groups' == $_POST['action']) {
if (isset($_POST['type'])) {
$type = intval($_POST['type']);
} elseif (isset($_POST['list']) && 'white' === $_POST['list']) {
} elseif (isset($_POST['list']) && $_POST['list'] === 'white') {
$type = ListType::whitelist;
} elseif (isset($_POST['list']) && 'black' === $_POST['list']) {
} elseif (isset($_POST['list']) && $_POST['list'] === 'black') {
$type = ListType::blacklist;
}
@@ -579,7 +579,7 @@ if ('get_groups' == $_POST['action']) {
}
$comment = html_entity_decode($_POST['comment']);
if (0 === strlen($comment)) {
if (strlen($comment) === 0) {
// Store NULL in database for empty comments
$comment = null;
}
@@ -589,7 +589,7 @@ if ('get_groups' == $_POST['action']) {
foreach ($domains as $domain) {
// Silently skip this entry when it is empty or not a string (e.g. NULL)
if (!is_string($domain) || 0 == strlen($domain)) {
if (!is_string($domain) || strlen($domain) == 0) {
continue;
}
@@ -597,7 +597,7 @@ if ('get_groups' == $_POST['action']) {
// Convert domain name to IDNA ASCII form for international domains
$domain = convertUnicodeToIDNA($domain);
if ('2' != $_POST['type'] && '3' != $_POST['type']) {
if ($_POST['type'] != '2' && $_POST['type'] != '3') {
// If not adding a RegEx, we convert the domain lower case and check whether it is valid
$domain = strtolower($domain);
$msg = '';
@@ -615,7 +615,7 @@ if ('get_groups' == $_POST['action']) {
}
}
if (isset($_POST['type']) && 2 === strlen($_POST['type']) && 'W' === $_POST['type'][1]) {
if (isset($_POST['type']) && strlen($_POST['type']) === 2 && $_POST['type'][1] === 'W') {
// Apply wildcard-style formatting
$domain = '(\\.|^)'.str_replace('.', '\\.', $domain).'$';
}
@@ -626,7 +626,7 @@ if ('get_groups' == $_POST['action']) {
// just throw an error at the user to tell them to change this
// domain manually. This ensures user's will really get what they
// want from us.
if ('replace_domain' == $_POST['action']) {
if ($_POST['action'] == 'replace_domain') {
if (!$check_stmt->bindValue(':domain', $domain, SQLITE3_TEXT)) {
throw new Exception('While binding domain to check: <strong>'.$db->lastErrorMsg().'</strong><br>Added '.$added.' out of '.$total.' domains');
}
@@ -637,7 +637,7 @@ if ('get_groups' == $_POST['action']) {
}
// Check return value of CHECK query (0 = only default group, 1 = special group assignments)
$only_default_group = (0 == $check_result->fetchArray(SQLITE3_NUM)[0]) ? true : false;
$only_default_group = ($check_result->fetchArray(SQLITE3_NUM)[0] == 0) ? true : false;
if (!$only_default_group) {
throw new Exception('Domain '.$domain.' is configured with special group settings.<br>Please modify the domain on the respective group management pages.');
}
@@ -678,8 +678,8 @@ if ('get_groups' == $_POST['action']) {
$after = intval($db->querySingle('SELECT COUNT(*) FROM domainlist;'));
$difference = $after - $before;
if (1 === $total) {
if (1 !== $difference) {
if ($total === 1) {
if ($difference !== 1) {
$msg = 'Not adding '.htmlentities(utf8_encode($domain)).' as it is already on the list';
} else {
$msg = 'Added '.htmlentities(utf8_encode($domain));
@@ -696,7 +696,7 @@ if ('get_groups' == $_POST['action']) {
} catch (\Exception $ex) {
JSON_error($ex->getMessage());
}
} elseif ('edit_domain' == $_POST['action']) {
} elseif ($_POST['action'] == 'edit_domain') {
// Edit domain identified by ID
try {
$db->query('BEGIN TRANSACTION;');
@@ -707,7 +707,7 @@ if ('get_groups' == $_POST['action']) {
}
$status = intval($_POST['status']);
if (0 !== $status) {
if ($status !== 0) {
$status = 1;
}
@@ -716,7 +716,7 @@ if ('get_groups' == $_POST['action']) {
}
$comment = html_entity_decode($_POST['comment']);
if (0 === strlen($comment)) {
if (strlen($comment) === 0) {
// Store NULL in database for empty comments
$comment = null;
}
@@ -781,7 +781,7 @@ if ('get_groups' == $_POST['action']) {
} catch (\Exception $ex) {
JSON_error($ex->getMessage());
}
} elseif ('delete_domain' == $_POST['action']) {
} elseif ($_POST['action'] == 'delete_domain') {
// Delete domain identified by ID
try {
$ids = json_decode($_POST['id']);
@@ -820,7 +820,7 @@ if ('get_groups' == $_POST['action']) {
} catch (\Exception $ex) {
JSON_error($ex->getMessage());
}
} elseif ('delete_domain_string' == $_POST['action']) {
} elseif ($_POST['action'] == 'delete_domain_string') {
// Delete domain identified by the domain string itself
try {
$db->query('BEGIN TRANSACTION;');
@@ -872,7 +872,7 @@ if ('get_groups' == $_POST['action']) {
} catch (\Exception $ex) {
JSON_error($ex->getMessage());
}
} elseif ('get_adlists' == $_POST['action']) {
} elseif ($_POST['action'] == 'get_adlists') {
// List all available groups
try {
$query = $db->query('SELECT * FROM adlist;');
@@ -900,7 +900,7 @@ if ('get_groups' == $_POST['action']) {
} catch (\Exception $ex) {
JSON_error($ex->getMessage());
}
} elseif ('add_adlist' == $_POST['action']) {
} elseif ($_POST['action'] == 'add_adlist') {
// Add new adlist
try {
$db->query('BEGIN TRANSACTION;');
@@ -916,7 +916,7 @@ if ('get_groups' == $_POST['action']) {
}
$comment = html_entity_decode($_POST['comment']);
if (0 === strlen($comment)) {
if (strlen($comment) === 0) {
// Store NULL in database for empty comments
$comment = null;
}
@@ -928,7 +928,7 @@ if ('get_groups' == $_POST['action']) {
$ignored_list = '';
foreach ($addresses as $address) {
// Silently skip this entry when it is empty or not a string (e.g. NULL)
if (!is_string($address) || 0 == strlen($address)) {
if (!is_string($address) || strlen($address) == 0) {
continue;
}
@@ -936,7 +936,7 @@ if ('get_groups' == $_POST['action']) {
// $1 is optional schema, $2 is userinfo
$check_address = preg_replace('|([^:/]*://)?([^/]+)@|', '$1$2', $address, 1);
if (0 !== preg_match('/[^a-zA-Z0-9:\\/?&%=~._()-;]/', $check_address)) {
if (preg_match('/[^a-zA-Z0-9:\\/?&%=~._()-;]/', $check_address) !== 0) {
throw new Exception('<strong>Invalid adlist URL '.htmlentities($address).'</strong><br>Added '.$added.' out of '.$total.' adlists');
}
@@ -945,7 +945,7 @@ if ('get_groups' == $_POST['action']) {
}
if (!$stmt->execute()) {
if (19 == $db->lastErrorCode()) {
if ($db->lastErrorCode() == 19) {
// ErrorCode 19 is "Constraint violation", here the unique constraint of `address`
// is violated (https://www.sqlite.org/rescode.html#constraint).
// If the list is already in database, add to ignored list, but don't throw error
@@ -965,10 +965,10 @@ if ('get_groups' == $_POST['action']) {
}
$reload = true;
if ('' != $ignored_list) {
if ($ignored_list != '') {
// Send added and ignored lists
$msg = '<b>Ignored duplicated adlists: '.$ignored.'</b><br>'.$ignored_list;
if ('' != $added_list) {
if ($added_list != '') {
$msg .= '<br><b>Added adlists: '.$added.'</b><br>'.$added_list;
}
$msg .= '<br><b>Total: '.$total.' adlist(s) processed.</b>';
@@ -981,7 +981,7 @@ if ('get_groups' == $_POST['action']) {
} catch (\Exception $ex) {
JSON_error($ex->getMessage());
}
} elseif ('edit_adlist' == $_POST['action']) {
} elseif ($_POST['action'] == 'edit_adlist') {
// Edit adlist identified by ID
try {
$db->query('BEGIN TRANSACTION;');
@@ -992,7 +992,7 @@ if ('get_groups' == $_POST['action']) {
}
$status = intval($_POST['status']);
if (0 !== $status) {
if ($status !== 0) {
$status = 1;
}
@@ -1001,7 +1001,7 @@ if ('get_groups' == $_POST['action']) {
}
$comment = html_entity_decode($_POST['comment']);
if (0 === strlen($comment)) {
if (strlen($comment) === 0) {
// Store NULL in database for empty comments
$comment = null;
}
@@ -1062,7 +1062,7 @@ if ('get_groups' == $_POST['action']) {
} catch (\Exception $ex) {
JSON_error($ex->getMessage());
}
} elseif ('delete_adlist' == $_POST['action']) {
} elseif ($_POST['action'] == 'delete_adlist') {
// Delete adlist identified by ID
try {
// Accept only an array
@@ -1103,7 +1103,7 @@ if ('get_groups' == $_POST['action']) {
} catch (\Exception $ex) {
JSON_error($ex->getMessage());
}
} elseif ('add_audit' == $_POST['action']) {
} elseif ($_POST['action'] == 'add_audit') {
// Add new domain
try {
$domains = explode(' ', html_entity_decode(trim($_POST['domain'])));
@@ -1120,7 +1120,7 @@ if ('get_groups' == $_POST['action']) {
foreach ($domains as $domain) {
// Silently skip this entry when it is empty or not a string (e.g. NULL)
if (!is_string($domain) || 0 == strlen($domain)) {
if (!is_string($domain) || strlen($domain) == 0) {
continue;
}
@@ -1140,8 +1140,8 @@ if ('get_groups' == $_POST['action']) {
$after = intval($db->querySingle('SELECT COUNT(*) FROM domain_audit;'));
$difference = $after - $before;
if (1 === $total) {
if (1 !== $difference) {
if ($total === 1) {
if ($difference !== 1) {
$msg = 'Not adding '.htmlentities(utf8_encode($domain)).' as it is already on the list';
} else {
$msg = 'Added '.htmlentities(utf8_encode($domain));
+8 -8
View File
@@ -23,7 +23,7 @@ function getMemUsage()
if (count($data) > 0) {
foreach ($data as $line) {
$expl = explode(':', $line);
if (2 == count($expl)) {
if (count($expl) == 2) {
// remove " kB" from the end of the string and make it an integer
$meminfo[$expl[0]] = intval(trim(substr($expl[1], 0, -3)));
}
@@ -124,7 +124,7 @@ if (!is_numeric($nproc)) {
$memory_usage = getMemUsage();
// Retrieve layout setting from setupVars
if (isset($setupVars['WEBUIBOXEDLAYOUT']) && !('boxed' === $setupVars['WEBUIBOXEDLAYOUT'])) {
if (isset($setupVars['WEBUIBOXEDLAYOUT']) && !($setupVars['WEBUIBOXEDLAYOUT'] === 'boxed')) {
$boxedlayout = false;
} else {
$boxedlayout = true;
@@ -132,9 +132,9 @@ if (isset($setupVars['WEBUIBOXEDLAYOUT']) && !('boxed' === $setupVars['WEBUIBOXE
// Override layout setting if layout is changed via Settings page
if (isset($_POST['field'])) {
if ('webUI' === $_POST['field'] && isset($_POST['boxedlayout'])) {
if ($_POST['field'] === 'webUI' && isset($_POST['boxedlayout'])) {
$boxedlayout = true;
} elseif ('webUI' === $_POST['field'] && !isset($_POST['boxedlayout'])) {
} elseif ($_POST['field'] === 'webUI' && !isset($_POST['boxedlayout'])) {
$boxedlayout = false;
}
}
@@ -168,13 +168,13 @@ $piholeFTLConf = piholeFTLConfig();
<link rel="shortcut icon" href="img/favicons/favicon.ico">
<meta name="msapplication-TileColor" content="#367fa9">
<meta name="msapplication-TileImage" content="img/favicons/mstile-150x150.png">
<?php if ('default-light' == $theme) { ?>
<?php if ($theme == 'default-light') { ?>
<meta name="theme-color" content="#367fa9">
<?php } elseif ('default-dark' == $theme) { ?>
<?php } elseif ($theme == 'default-dark') { ?>
<meta name="theme-color" content="#272c30">
<?php } elseif ('default-darker' == $theme) { ?>
<?php } elseif ($theme == 'default-darker') { ?>
<meta name="theme-color" content="#2e6786">
<?php } elseif ('lcars' == $theme) { ?>
<?php } elseif ($theme == 'lcars') { ?>
<meta name="theme-color" content="#4488FF">
<link rel="stylesheet" href="style/vendor/fonts/ubuntu-mono/ubuntu-mono.css?v=<?php echo $cacheVer; ?>">
<link rel="stylesheet" href="style/vendor/fonts/antonio/antonio.css?v=<?php echo $cacheVer; ?>">
+1 -1
View File
@@ -27,7 +27,7 @@ $QueriesDB = getQueriesDBFilename();
$db = SQLite3_connect($QueriesDB, SQLITE3_OPEN_READWRITE);
// Delete message identified by IDs
if ('delete_message' == $_POST['action'] && isset($_POST['id'])) {
if ($_POST['action'] == 'delete_message' && isset($_POST['id'])) {
try {
$ids = json_decode($_POST['id']);
if (!is_array($ids)) {
+1 -1
View File
@@ -26,7 +26,7 @@ $reload = false;
$QueriesDB = getQueriesDBFilename();
$db = SQLite3_connect($QueriesDB, SQLITE3_OPEN_READWRITE);
if ('delete_network_entry' == $_POST['action'] && isset($_POST['id'])) {
if ($_POST['action'] == 'delete_network_entry' && isset($_POST['id'])) {
// Delete netwwork and network_addresses table entry identified by ID
try {
$stmt = $db->prepare('DELETE FROM network_addresses WHERE network_id=:id');
+1 -1
View File
@@ -73,7 +73,7 @@ if (strlen($pwhash) > 0) {
}
// Login successful, redirect the user to the homepage to discard the POST request
if ('POST' === $_SERVER['REQUEST_METHOD'] && 'login' === $_SERVER['QUERY_STRING']) {
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['QUERY_STRING'] === 'login') {
header('Location: index.php');
exit;
+14 -14
View File
@@ -57,10 +57,10 @@ function readStaticLeasesFile($origin_file = '/etc/dnsmasq.d/04-pihole-static-dh
$two = '';
sscanf(trim(fgets($dhcpstatic)), 'dhcp-host=%[^,],%[^,],%[^,]', $mac, $one, $two);
if (strlen($mac) > 0 && validMAC($mac)) {
if (validIP($one) && 0 == strlen($two)) {
if (validIP($one) && strlen($two) == 0) {
// dhcp-host=mac,IP - no HOST
array_push($dhcp_static_leases, array('hwaddr' => $mac, 'IP' => $one, 'host' => ''));
} elseif (0 == strlen($two)) {
} elseif (strlen($two) == 0) {
// dhcp-host=mac,hostname - no IP
array_push($dhcp_static_leases, array('hwaddr' => $mac, 'IP' => '', 'host' => $one));
} else {
@@ -154,15 +154,15 @@ function addStaticDHCPLease($mac, $ip, $hostname)
throw new Exception('Host name ('.htmlspecialchars($hostname).') is invalid!<br>', 2);
}
if (0 == strlen($hostname) && 0 == strlen($ip)) {
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 (0 == strlen($hostname)) {
if (strlen($hostname) == 0) {
$hostname = 'nohost';
}
if (0 == strlen($ip)) {
if (strlen($ip) == 0) {
$ip = 'noip';
}
@@ -173,7 +173,7 @@ function addStaticDHCPLease($mac, $ip, $hostname)
if ($lease['hwaddr'] === $mac) {
throw new Exception('Static lease for MAC address ('.htmlspecialchars($mac).') already defined!<br>', 4);
}
if ('noip' !== $ip && $lease['IP'] === $ip) {
if ($ip !== 'noip' && $lease['IP'] === $ip) {
throw new Exception('Static lease for IP address ('.htmlspecialchars($ip).') already defined!<br>', 5);
}
if ($lease['host'] === $hostname) {
@@ -306,11 +306,11 @@ if (isset($_POST['field'])) {
// Check if DNSinterface is set
if (isset($_POST['DNSinterface'])) {
if ('single' === $_POST['DNSinterface']) {
if ($_POST['DNSinterface'] === 'single') {
$DNSinterface = 'single';
} elseif ('bind' === $_POST['DNSinterface']) {
} elseif ($_POST['DNSinterface'] === 'bind') {
$DNSinterface = 'bind';
} elseif ('all' === $_POST['DNSinterface']) {
} elseif ($_POST['DNSinterface'] === 'all') {
$DNSinterface = 'all';
} else {
$DNSinterface = 'local';
@@ -340,10 +340,10 @@ if (isset($_POST['field'])) {
break;
// Set query logging
case 'Logging':
if ('Disable' === $_POST['action']) {
if ($_POST['action'] === 'Disable') {
pihole_execute('-l off');
$success .= 'Logging has been disabled and logs have been flushed';
} elseif ('Disable-noflush' === $_POST['action']) {
} elseif ($_POST['action'] === 'Disable-noflush') {
pihole_execute('-l off noflush');
$success .= 'Logging has been disabled, your logs have <strong>not</strong> been flushed';
} else {
@@ -417,7 +417,7 @@ if (isset($_POST['field'])) {
case 'webUI':
$adminemail = trim($_POST['adminemail']);
if (0 == strlen($adminemail) || !isset($adminemail)) {
if (strlen($adminemail) == 0 || !isset($adminemail)) {
$adminemail = '';
}
if (strlen($adminemail) > 0 && !validEmail($adminemail)) {
@@ -581,7 +581,7 @@ if (isset($_POST['field'])) {
if (is_array($output)) {
$error = implode('<br>', $output);
}
if (0 == strlen($error)) {
if (strlen($error) == 0) {
$success .= 'The network table has been flushed';
}
@@ -604,7 +604,7 @@ function formatSizeUnits($bytes)
$bytes = number_format($bytes / 1024, 2).' kB';
} elseif ($bytes > 1) {
$bytes = $bytes.' bytes';
} elseif (1 == $bytes) {
} elseif ($bytes == 1) {
$bytes = $bytes.' byte';
} else {
$bytes = '0 bytes';
+27 -27
View File
@@ -11,13 +11,13 @@
<p>Status</p>
<?php
$pistatus = piholeStatus();
if (53 == $pistatus) {
if ($pistatus == 53) {
echo '<span id="status"><i class="fa fa-w fa-circle text-green-light"></i> Active</span>';
} elseif (0 == $pistatus) {
} elseif ($pistatus == 0) {
echo '<span id="status"><i class="fa fa-w fa-circle text-red"></i> Blocking disabled</span>';
} elseif (-1 == $pistatus) {
} elseif ($pistatus == -1) {
echo '<span id="status"><i class="fa fa-w fa-circle text-red"></i> DNS service not running</span>';
} elseif (-2 == $pistatus) {
} elseif ($pistatus == -2) {
echo '<span id="status"><i class="fa fa-w fa-circle text-red"></i> Unknown</span>';
} else {
echo '<span id="status"><i class="fa fa-w fa-circle text-orange"></i> DNS service on port '.$pistatus.'</span>';
@@ -71,7 +71,7 @@
<ul class="sidebar-menu" data-widget="tree">
<li class="header text-uppercase">Main</li>
<!-- Home Page -->
<li<?php if ('index.php' === $scriptname) { ?> class="active"<?php } ?>>
<li<?php if ($scriptname === 'index.php') { ?> class="active"<?php } ?>>
<a href="index.php">
<i class="fa fa-fw menu-icon fa-home"></i> <span>Dashboard</span>
</a>
@@ -93,7 +93,7 @@
// Show Login button if $auth is *not* set and authorization is required
if (strlen($pwhash) > 0 && !$auth) {
?>
<li<?php if ('login' === $scriptname) { ?> class="active"<?php } ?>>
<li<?php if ($scriptname === 'login') { ?> class="active"<?php } ?>>
<a href="index.php?login">
<i class="fa fa-fw menu-icon fa-user"></i> <span>Login</span>
</a>
@@ -104,13 +104,13 @@
<li class="header text-uppercase">Analysis</li>
<!-- Query Log -->
<li<?php if ('queries.php' === $scriptname) { ?> class="active"<?php } ?>>
<li<?php if ($scriptname === 'queries.php') { ?> class="active"<?php } ?>>
<a href="queries.php">
<i class="fa fa-fw menu-icon fa-file-alt"></i> <span>Query Log</span>
</a>
</li>
<!-- Long-term database -->
<li class="treeview<?php if ('db_queries.php' === $scriptname || 'db_lists.php' === $scriptname || 'db_graph.php' === $scriptname) { ?> active<?php } ?>">
<li class="treeview<?php if ($scriptname === 'db_queries.php' || $scriptname === 'db_lists.php' || $scriptname === 'db_graph.php') { ?> active<?php } ?>">
<a href="#">
<i class="fa fa-fw menu-icon fa-history"></i> <span>Long-term Data</span>
<span class="pull-right-container">
@@ -118,17 +118,17 @@
</span>
</a>
<ul class="treeview-menu">
<li<?php if ('db_graph.php' === $scriptname) { ?> class="active"<?php } ?>>
<li<?php if ($scriptname === 'db_graph.php') { ?> class="active"<?php } ?>>
<a href="db_graph.php">
<i class="fa fa-fw menu-icon fa-chart-bar"></i> Graphics
</a>
</li>
<li<?php if ('db_queries.php' === $scriptname) { ?> class="active"<?php } ?>>
<li<?php if ($scriptname === 'db_queries.php') { ?> class="active"<?php } ?>>
<a href="db_queries.php">
<i class="fa fa-fw menu-icon fa-file-alt"></i> Query Log
</a>
</li>
<li<?php if ('db_lists.php' === $scriptname) { ?> class="active"<?php } ?>>
<li<?php if ($scriptname === 'db_lists.php') { ?> class="active"<?php } ?>>
<a href="db_lists.php">
<i class="fa fa-fw menu-icon fa-list"></i> Top Lists
</a>
@@ -138,22 +138,22 @@
<li class="header text-uppercase">Group Management</li>
<!-- Group Management -->
<li<?php if ('groups.php' === $scriptname) { ?> class="active"<?php } ?>>
<li<?php if ($scriptname === 'groups.php') { ?> class="active"<?php } ?>>
<a href="groups.php">
<i class="fa fa-fw menu-icon fa-user-friends"></i> <span>Groups</span>
</a>
</li>
<li<?php if ('groups-clients.php' === $scriptname) { ?> class="active"<?php } ?>>
<li<?php if ($scriptname === 'groups-clients.php') { ?> class="active"<?php } ?>>
<a href="groups-clients.php">
<i class="fa fa-fw menu-icon fa-laptop"></i> <span>Clients</span>
</a>
</li>
<li<?php if ('groups-domains.php' === $scriptname) { ?> class="active"<?php } ?>>
<li<?php if ($scriptname === 'groups-domains.php') { ?> class="active"<?php } ?>>
<a href="groups-domains.php">
<i class="fa fa-fw menu-icon fa-list"></i> <span>Domains</span>
</a>
</li>
<li<?php if ('groups-adlists.php' === $scriptname) { ?> class="active"<?php } ?>>
<li<?php if ($scriptname === 'groups-adlists.php') { ?> class="active"<?php } ?>>
<a href="groups-adlists.php">
<i class="fa fa-fw menu-icon fa-shield-alt"></i> <span>Adlists</span>
</a>
@@ -161,7 +161,7 @@
<li class="header text-uppercase">DNS Control</li>
<!-- Enable/Disable Blocking -->
<li id="pihole-disable" class="treeview"<?php if ('0' == $pistatus) { ?> hidden<?php } ?>>
<li id="pihole-disable" class="treeview"<?php if ($pistatus == '0') { ?> hidden<?php } ?>>
<a href="#">
<i class="fa fa-fw menu-icon fa-stop"></i> <span>Disable Blocking&nbsp;&nbsp;&nbsp;<span id="flip-status-disable"></span></span>
<span class="pull-right-container">
@@ -214,12 +214,12 @@
</span>
</a>
<ul class="treeview-menu">
<li<?php if ('dns_records.php' === $scriptname) { ?> class="active"<?php } ?>>
<li<?php if ($scriptname === 'dns_records.php') { ?> class="active"<?php } ?>>
<a href="dns_records.php">
<i class="fa fa-fw menu-icon fa-address-book"></i> DNS Records
</a>
</li>
<li<?php if ('cname_records.php' === $scriptname) { ?> class="active"<?php } ?>>
<li<?php if ($scriptname === 'cname_records.php') { ?> class="active"<?php } ?>>
<a href="cname_records.php">
<i class="fa fa-fw menu-icon fa-address-book"></i> CNAME Records
</a>
@@ -239,32 +239,32 @@
</a>
<ul class="treeview-menu">
<!-- Pi-hole diagnosis -->
<li<?php if ('messages.php' === $scriptname) { ?> class="active"<?php } ?>>
<li<?php if ($scriptname === 'messages.php') { ?> class="active"<?php } ?>>
<a href="messages.php">
<i class="fa fa-fw menu-icon fa-file-medical-alt"></i> Pi-hole diagnosis
<span class="pull-right-container warning-count hidden"></span>
</a>
</li>
<!-- Run gravity.sh -->
<li<?php if ('gravity.php' === $scriptname) { ?> class="active"<?php } ?>>
<li<?php if ($scriptname === 'gravity.php') { ?> class="active"<?php } ?>>
<a href="gravity.php">
<i class="fa fa-fw menu-icon fa-arrow-circle-down"></i> Update Gravity
</a>
</li>
<!-- Query Lists -->
<li<?php if ('queryads.php' === $scriptname) { ?> class="active"<?php } ?>>
<li<?php if ($scriptname === 'queryads.php') { ?> class="active"<?php } ?>>
<a href="queryads.php">
<i class="fa fa-fw menu-icon fa-search"></i> Search Adlists
</a>
</li>
<!-- Audit log -->
<li<?php if ('auditlog.php' === $scriptname) { ?> class="active"<?php } ?>>
<li<?php if ($scriptname === 'auditlog.php') { ?> class="active"<?php } ?>>
<a href="auditlog.php">
<i class="fa fa-fw menu-icon fa-balance-scale"></i> Audit log
</a>
</li>
<!-- Tail pihole.log -->
<li<?php if ('taillog.php' === $scriptname) { ?> class="active"<?php } ?>>
<li<?php if ($scriptname === 'taillog.php') { ?> class="active"<?php } ?>>
<a href="taillog.php">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" preserveAspectRatio="xMidYMid meet" height="14" viewBox="0 0 200 200" class="svg-inline--fa custom-menu-icon fa-w-20 fa-fw menu-icon">
<g>
@@ -283,7 +283,7 @@
</a>
</li>
<!-- Tail FTL.log -->
<li<?php if ('taillog-FTL.php' === $scriptname) { ?> class="active"<?php } ?>>
<li<?php if ($scriptname === 'taillog-FTL.php') { ?> class="active"<?php } ?>>
<a href="taillog-FTL.php">
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" preserveAspectRatio="xMidYMid meet" height="14" viewBox="0 0 400 340" class="svg-inline--fa custom-menu-icon fa-w-20 fa-fw menu-icon">
<g fill="currentColor">
@@ -296,13 +296,13 @@
</a>
</li>
<!-- Generate debug log -->
<li<?php if ('debug.php' === $scriptname) { ?> class="active"<?php } ?>>
<li<?php if ($scriptname === 'debug.php') { ?> class="active"<?php } ?>>
<a href="debug.php">
<i class="fa fa-fw menu-icon fa-ambulance"></i> Generate debug log
</a>
</li>
<!-- Network -->
<li<?php if ('network.php' === $scriptname) { ?> class="active"<?php } ?>>
<li<?php if ($scriptname === 'network.php') { ?> class="active"<?php } ?>>
<a href="network.php">
<i class="fa fa-fw menu-icon fa-network-wired"></i> Network
</a>
@@ -310,7 +310,7 @@
</ul>
</li>
<!-- Settings -->
<li<?php if ('settings.php' === $scriptname) { ?> class="active"<?php } ?>>
<li<?php if ($scriptname === 'settings.php') { ?> class="active"<?php } ?>>
<a href="settings.php">
<i class="fa fa-fw menu-icon fa-cog"></i> <span>Settings</span>
</a>
+45 -45
View File
@@ -12,7 +12,7 @@ require 'auth.php'; // Also imports func.php
require 'database.php';
require 'savesettings.php';
if ('cli' !== php_sapi_name()) {
if (php_sapi_name() !== 'cli') {
if (!$auth) {
exit('Not authorized');
}
@@ -98,46 +98,46 @@ function archive_restore_table($file, $table, $flush = false)
}
// Prepare fields depending on the table we restore to
if ('adlist' === $table) {
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 ('domain_audit' === $table) {
} elseif ($table === 'domain_audit') {
$sql = 'INSERT OR IGNORE INTO domain_audit';
$sql .= ' (id,domain,date_added)';
$sql .= ' VALUES (:id,:domain,:date_added);';
} elseif ('domainlist' === $table) {
} 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 ('group' === $table) {
} elseif ($table === 'group') {
$sql = 'INSERT OR IGNORE INTO "group"';
$sql .= ' (id,name,date_added,description)';
$sql .= ' VALUES (:id,:name,:date_added,:description);';
} elseif ('client' === $table) {
} elseif ($table === 'client') {
$sql = 'INSERT OR IGNORE INTO client';
$sql .= ' (id,ip,date_added,comment)';
$sql .= ' VALUES (:id,:ip,:date_added,:comment);';
} elseif ('domainlist_by_group' === $table) {
} 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 ('client_by_group' === $table) {
} 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 ('adlist_by_group' === $table) {
} 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 ('whitelist' === $table) {
if ($table === 'whitelist') {
$type = 0;
} elseif ('blacklist' === $table) {
} elseif ($table === 'blacklist') {
$type = 1;
} elseif ('regex_whitelist' === $table) {
} elseif ($table === 'regex_whitelist') {
$type = 2;
} elseif ('regex_blacklist' === $table) {
} elseif ($table === 'regex_blacklist') {
$type = 3;
}
@@ -240,19 +240,19 @@ function archive_insert_into_table($file, $table, $flush = false, $wildcardstyle
// Determine table and type to import to
$type = null;
if ('whitelist' === $table) {
if ($table === 'whitelist') {
$table = 'domainlist';
$type = ListType::whitelist;
} elseif ('blacklist' === $table) {
} elseif ($table === 'blacklist') {
$table = 'domainlist';
$type = ListType::blacklist;
} elseif ('regex_blacklist' === $table) {
} elseif ($table === 'regex_blacklist') {
$table = 'domainlist';
$type = ListType::regex_blacklist;
} elseif ('domain_audit' === $table) {
} elseif ($table === 'domain_audit') {
$table = 'domain_audit';
$type = -1; // -1 -> not used inside add_to_table()
} elseif ('adlist' === $table) {
} elseif ($table === 'adlist') {
$table = 'adlist';
$type = -1; // -1 -> not used inside add_to_table()
}
@@ -277,7 +277,7 @@ function flush_table($table, $type = null)
global $db, $flushed_tables;
if (!in_array($table, $flushed_tables)) {
if (null !== $type) {
if ($type !== null) {
$sql = 'DELETE FROM "'.$table.'" WHERE type = '.$type;
array_push($flushed_tables, $table.$type);
} else {
@@ -292,7 +292,7 @@ function archive_add_directory($path, $subdir = '')
{
if ($dir = opendir($path)) {
while (false !== ($entry = readdir($dir))) {
if ('.' !== $entry && '..' !== $entry) {
if ($entry !== '.' && $entry !== '..') {
archive_add_file($path, $entry, $subdir);
}
}
@@ -319,7 +319,7 @@ function process_file($contents)
function noun($num)
{
if (1 === $num) {
if ($num === 1) {
return ' entry';
}
@@ -327,7 +327,7 @@ function noun($num)
}
if (isset($_POST['action'])) {
if ($_FILES['zip_file']['name'] && 'in' == $_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);
@@ -338,7 +338,7 @@ if (isset($_POST['action'])) {
// verify the file extension (Looking for ".tar.gz" at the end of the file name)
$ext = array_slice(explode('.', $filename), -2, 2);
$ext_valid = 'tar' == strtolower($ext[0]) && 'gz' == strtolower($ext[1]) ? true : false;
$ext_valid = strtolower($ext[0]) == 'tar' && strtolower($ext[1]) == 'gz' ? true : false;
if (!$ext_valid || !$mime_valid) {
exit('The file you are trying to upload is not a .tar.gz file (filename: '.htmlentities($filename).', type: '.htmlentities($type).'). Please try again.');
@@ -359,92 +359,92 @@ if (isset($_POST['action'])) {
$flushtables = isset($_POST['flushtables']);
foreach (new RecursiveIteratorIterator($archive) as $file) {
if (isset($_POST['blacklist']) && 'blacklist.txt' === $file->getFilename()) {
if (isset($_POST['blacklist']) && $file->getFilename() === 'blacklist.txt') {
$num = archive_insert_into_table($file, 'blacklist', $flushtables);
echo 'Processed blacklist (exact) ('.$num.noun($num).")<br>\n";
$importedsomething = true;
}
if (isset($_POST['whitelist']) && 'whitelist.txt' === $file->getFilename()) {
if (isset($_POST['whitelist']) && $file->getFilename() === 'whitelist.txt') {
$num = archive_insert_into_table($file, 'whitelist', $flushtables);
echo 'Processed whitelist (exact) ('.$num.noun($num).")<br>\n";
$importedsomething = true;
}
if (isset($_POST['regexlist']) && 'regex.list' === $file->getFilename()) {
if (isset($_POST['regexlist']) && $file->getFilename() === 'regex.list') {
$num = archive_insert_into_table($file, 'regex_blacklist', $flushtables);
echo 'Processed blacklist (regex) ('.$num.noun($num).")<br>\n";
$importedsomething = true;
}
// Also try to import legacy wildcard list if found
if (isset($_POST['regexlist']) && 'wildcardblocking.txt' === $file->getFilename()) {
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).")<br>\n";
$importedsomething = true;
}
if (isset($_POST['auditlog']) && 'auditlog.list' === $file->getFilename()) {
if (isset($_POST['auditlog']) && $file->getFilename() === 'auditlog.list') {
$num = archive_insert_into_table($file, 'domain_audit', $flushtables);
echo 'Processed audit log ('.$num.noun($num).")<br>\n";
$importedsomething = true;
}
if (isset($_POST['adlist']) && 'adlists.list' === $file->getFilename()) {
if (isset($_POST['adlist']) && $file->getFilename() === 'adlists.list') {
$num = archive_insert_into_table($file, 'adlist', $flushtables);
echo 'Processed adlists ('.$num.noun($num).")<br>\n";
$importedsomething = true;
}
if (isset($_POST['blacklist']) && 'blacklist.exact.json' === $file->getFilename()) {
if (isset($_POST['blacklist']) && $file->getFilename() === 'blacklist.exact.json') {
$num = archive_restore_table($file, 'blacklist', $flushtables);
echo 'Processed blacklist (exact) ('.$num.noun($num).")<br>\n";
$importedsomething = true;
}
if (isset($_POST['regexlist']) && 'blacklist.regex.json' === $file->getFilename()) {
if (isset($_POST['regexlist']) && $file->getFilename() === 'blacklist.regex.json') {
$num = archive_restore_table($file, 'regex_blacklist', $flushtables);
echo 'Processed blacklist (regex) ('.$num.noun($num).")<br>\n";
$importedsomething = true;
}
if (isset($_POST['whitelist']) && 'whitelist.exact.json' === $file->getFilename()) {
if (isset($_POST['whitelist']) && $file->getFilename() === 'whitelist.exact.json') {
$num = archive_restore_table($file, 'whitelist', $flushtables);
echo 'Processed whitelist (exact) ('.$num.noun($num).")<br>\n";
$importedsomething = true;
}
if (isset($_POST['regex_whitelist']) && 'whitelist.regex.json' === $file->getFilename()) {
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).")<br>\n";
$importedsomething = true;
}
if (isset($_POST['adlist']) && 'adlist.json' === $file->getFilename()) {
if (isset($_POST['adlist']) && $file->getFilename() === 'adlist.json') {
$num = archive_restore_table($file, 'adlist', $flushtables);
echo 'Processed adlist ('.$num.noun($num).")<br>\n";
$importedsomething = true;
}
if (isset($_POST['auditlog']) && 'domain_audit.json' === $file->getFilename()) {
if (isset($_POST['auditlog']) && $file->getFilename() === 'domain_audit.json') {
$num = archive_restore_table($file, 'domain_audit', $flushtables);
echo 'Processed domain_audit ('.$num.noun($num).")<br>\n";
$importedsomething = true;
}
if (isset($_POST['group']) && 'group.json' === $file->getFilename()) {
if (isset($_POST['group']) && $file->getFilename() === 'group.json') {
$num = archive_restore_table($file, 'group', $flushtables);
echo 'Processed group ('.$num.noun($num).")<br>\n";
$importedsomething = true;
}
if (isset($_POST['client']) && 'client.json' === $file->getFilename()) {
if (isset($_POST['client']) && $file->getFilename() === 'client.json') {
$num = archive_restore_table($file, 'client', $flushtables);
echo 'Processed client ('.$num.noun($num).")<br>\n";
$importedsomething = true;
}
if (isset($_POST['client']) && 'client_by_group.json' === $file->getFilename()) {
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).")<br>\n";
$importedsomething = true;
@@ -452,22 +452,22 @@ if (isset($_POST['action'])) {
if ((isset($_POST['whitelist']) || isset($_POST['regex_whitelist'])
|| isset($_POST['blacklist']) || isset($_POST['regex_blacklist']))
&& 'domainlist_by_group.json' === $file->getFilename()) {
&& $file->getFilename() === 'domainlist_by_group.json') {
$num = archive_restore_table($file, 'domainlist_by_group', $flushtables);
echo 'Processed black-/whitelist group assignments ('.$num.noun($num).")<br>\n";
$importedsomething = true;
}
if (isset($_POST['adlist']) && 'adlist_by_group.json' === $file->getFilename()) {
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).")<br>\n";
$importedsomething = true;
}
if (isset($_POST['staticdhcpleases']) && '04-pihole-static-dhcp.conf' === $file->getFilename()) {
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 (false !== $local_file) {
if ($local_file !== false) {
ftruncate($local_file, 0);
fclose($local_file);
}
@@ -490,7 +490,7 @@ if (isset($_POST['action'])) {
}
}
if (isset($_POST['localdnsrecords']) && 'custom.list' === $file->getFilename()) {
if (isset($_POST['localdnsrecords']) && $file->getFilename() === 'custom.list') {
ob_start();
$reload = 'false';
if ($flushtables) {
@@ -514,7 +514,7 @@ if (isset($_POST['action'])) {
}
}
if (isset($_POST['localcnamerecords']) && '05-pihole-custom-cname.conf' === $file->getFilename()) {
if (isset($_POST['localcnamerecords']) && $file->getFilename() === '05-pihole-custom-cname.conf') {
ob_start();
$reload = 'false';
if ($flushtables) {
@@ -574,7 +574,7 @@ if (isset($_POST['action'])) {
$archive = new PharData($archive_file_name);
if (true !== $archive->isWritable()) {
if ($archive->isWritable() !== true) {
exit('cannot open/create '.htmlentities($archive_file_name)."<br>\nPHP user: ".exec('whoami')."\n");
}
+1 -1
View File
@@ -29,7 +29,7 @@ if (isset($setupVars['WEBTHEME'])) {
// May be overwritten by settings tab
if (isset($_POST['field'])
&& 'webUI' === $_POST['field']
&& $_POST['field'] === 'webUI'
&& isset($_POST['webtheme'])) {
$webtheme = $_POST['webtheme'];
}
+6 -6
View File
@@ -21,7 +21,7 @@ if (!is_readable($localversions) || !is_readable($localbranches) || !is_readable
// Get Pi-hole core branch / version / commit
// Check if on a dev branch
$core_branch = $branches[0];
if ('master' !== $core_branch) {
if ($core_branch !== 'master') {
$core_current = 'vDev';
$core_commit = $versions[0];
} else {
@@ -30,7 +30,7 @@ if (!is_readable($localversions) || !is_readable($localbranches) || !is_readable
// Get Pi-hole web branch / version / commit
$web_branch = $branches[1];
if ('master' !== $web_branch) {
if ($web_branch !== 'master') {
$web_current = 'vDev';
$web_commit = $versions[1];
} else {
@@ -39,7 +39,7 @@ if (!is_readable($localversions) || !is_readable($localbranches) || !is_readable
// Get Pi-hole FTL (not a git repository)
$FTL_branch = $branches[2];
if ('vDev' === substr($versions[2], 0, 4)) {
if (substr($versions[2], 0, 4) === 'vDev') {
$FTL_current = 'vDev';
$FTL_commit = $versions[2];
} else {
@@ -52,7 +52,7 @@ if (!is_readable($localversions) || !is_readable($localbranches) || !is_readable
$FTL_latest = $GitHubversions[2];
// Core version comparison
if ('vDev' !== $core_current) {
if ($core_current !== 'vDev') {
// This logic allows the local core version to be newer than the upstream version
// The update indicator is only shown if the upstream version is NEWER
$core_update = (version_compare($core_current, $core_latest) < 0);
@@ -61,7 +61,7 @@ if (!is_readable($localversions) || !is_readable($localbranches) || !is_readable
}
// Web version comparison
if ('vDev' !== $web_current) {
if ($web_current !== 'vDev') {
// This logic allows the local core version to be newer than the upstream version
// The update indicator is only shown if the upstream version is NEWER
$web_update = (version_compare($web_current, $web_latest) < 0);
@@ -72,7 +72,7 @@ if (!is_readable($localversions) || !is_readable($localbranches) || !is_readable
// FTL version comparison
// This logic allows the local core version to be newer than the upstream version
// The update indicator is only shown if the upstream version is NEWER
if ('vDev' !== $FTL_current) {
if ($FTL_current !== 'vDev') {
$FTL_update = (version_compare($FTL_current, $FTL_latest) < 0);
} else {
$FTL_update = false;
+47 -47
View File
@@ -19,7 +19,7 @@ $piholeFTLConf = piholeFTLConfig(DEFAULT_FTLCONFFILE, true);
// Handling of PHP internal errors
$last_error = error_get_last();
if (isset($last_error) && (E_WARNING === $last_error['type'] || E_ERROR === $last_error['type'])) {
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']);
}
@@ -39,7 +39,7 @@ if (empty($timezone)) {
<?php // Check if ad lists should be updated after saving ...
if (isset($_POST['submit'])) {
if ('saveupdate' == $_POST['submit']) {
if ($_POST['submit'] == 'saveupdate') {
// If that is the case -> refresh to the gravity page and start updating immediately
?>
<meta http-equiv="refresh" content="1;url=gravity.php?go">
@@ -77,7 +77,7 @@ if (isset($setupVars['PIHOLE_INTERFACE'])) {
$IPv4GW = getGateway()['ip'];
// if the default gateway address is unknown or FTL is not running
if ('0.0.0.0' == $IPv4GW || -1 == $IPv4GW) {
if ($IPv4GW == '0.0.0.0' || $IPv4GW == -1) {
$IPv4GW = 'unknown';
}
@@ -89,13 +89,13 @@ $i = 1;
while (isset($setupVars['PIHOLE_DNS_'.$i])) {
if (isinserverlist($setupVars['PIHOLE_DNS_'.$i])) {
array_push($DNSactive, $setupVars['PIHOLE_DNS_'.$i]);
} elseif (false !== strpos($setupVars['PIHOLE_DNS_'.$i], '.')) {
} elseif (strpos($setupVars['PIHOLE_DNS_'.$i], '.') !== false) {
if (!isset($custom1)) {
$custom1 = $setupVars['PIHOLE_DNS_'.$i];
} else {
$custom2 = $setupVars['PIHOLE_DNS_'.$i];
}
} elseif (false !== strpos($setupVars['PIHOLE_DNS_'.$i], ':')) {
} elseif (strpos($setupVars['PIHOLE_DNS_'.$i], ':') !== false) {
if (!isset($custom3)) {
$custom3 = $setupVars['PIHOLE_DNS_'.$i];
} else {
@@ -136,11 +136,11 @@ if (isset($setupVars['DNSSEC'])) {
}
if (isset($setupVars['DNSMASQ_LISTENING'])) {
if ('single' === $setupVars['DNSMASQ_LISTENING']) {
if ($setupVars['DNSMASQ_LISTENING'] === 'single') {
$DNSinterface = 'single';
} elseif ('bind' === $setupVars['DNSMASQ_LISTENING']) {
} elseif ($setupVars['DNSMASQ_LISTENING'] === 'bind') {
$DNSinterface = 'bind';
} elseif ('all' === $setupVars['DNSMASQ_LISTENING']) {
} elseif ($setupVars['DNSMASQ_LISTENING'] === 'all') {
$DNSinterface = 'all';
} else {
$DNSinterface = 'local';
@@ -148,7 +148,7 @@ if (isset($setupVars['DNSMASQ_LISTENING'])) {
} else {
$DNSinterface = 'single';
}
if (isset($setupVars['REV_SERVER']) && (1 == $setupVars['REV_SERVER'])) {
if (isset($setupVars['REV_SERVER']) && ($setupVars['REV_SERVER'] == 1)) {
$rev_server = true;
$rev_server_cidr = $setupVars['REV_SERVER_CIDR'];
$rev_server_target = $setupVars['REV_SERVER_TARGET'];
@@ -161,7 +161,7 @@ if (isset($setupVars['REV_SERVER']) && (1 == $setupVars['REV_SERVER'])) {
<?php
// Query logging
if (isset($setupVars['QUERY_LOGGING'])) {
if (1 == $setupVars['QUERY_LOGGING']) {
if ($setupVars['QUERY_LOGGING'] == 1) {
$piHoleLogging = true;
} else {
$piHoleLogging = false;
@@ -206,28 +206,28 @@ if (isset($_GET['tab']) && in_array($_GET['tab'], array('sysadmin', 'dns', 'piho
<div class="col-md-12">
<div class="nav-tabs-custom">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation"<?php if ('sysadmin' === $tab) { ?> class="active"<?php } ?>>
<a href="#sysadmin" aria-controls="sysadmin" aria-expanded="<?php echo 'sysadmin' === $tab ? 'true' : 'false'; ?>" role="tab" data-toggle="tab">System</a>
<li role="presentation"<?php if ($tab === 'sysadmin') { ?> class="active"<?php } ?>>
<a href="#sysadmin" aria-controls="sysadmin" aria-expanded="<?php echo $tab === 'sysadmin' ? 'true' : 'false'; ?>" role="tab" data-toggle="tab">System</a>
</li>
<li role="presentation"<?php if ('dns' === $tab) { ?> class="active"<?php } ?>>
<a href="#dns" aria-controls="dns" aria-expanded="<?php echo 'dns' === $tab ? 'true' : 'false'; ?>" role="tab" data-toggle="tab">DNS</a>
<li role="presentation"<?php if ($tab === 'dns') { ?> class="active"<?php } ?>>
<a href="#dns" aria-controls="dns" aria-expanded="<?php echo $tab === 'dns' ? 'true' : 'false'; ?>" role="tab" data-toggle="tab">DNS</a>
</li>
<li role="presentation"<?php if ('piholedhcp' === $tab) { ?> class="active"<?php } ?>>
<a href="#piholedhcp" aria-controls="piholedhcp" aria-expanded="<?php echo 'piholedhcp' === $tab ? 'true' : 'false'; ?>" role="tab" data-toggle="tab">DHCP</a>
<li role="presentation"<?php if ($tab === 'piholedhcp') { ?> class="active"<?php } ?>>
<a href="#piholedhcp" aria-controls="piholedhcp" aria-expanded="<?php echo $tab === 'piholedhcp' ? 'true' : 'false'; ?>" role="tab" data-toggle="tab">DHCP</a>
</li>
<li role="presentation"<?php if ('api' === $tab) { ?> class="active"<?php } ?>>
<a href="#api" aria-controls="api" aria-expanded="<?php echo 'api' === $tab ? 'true' : 'false'; ?>" role="tab" data-toggle="tab">API / Web interface</a>
<li role="presentation"<?php if ($tab === 'api') { ?> class="active"<?php } ?>>
<a href="#api" aria-controls="api" aria-expanded="<?php echo $tab === 'api' ? 'true' : 'false'; ?>" role="tab" data-toggle="tab">API / Web interface</a>
</li>
<li role="presentation"<?php if ('privacy' === $tab) { ?> class="active"<?php } ?>>
<a href="#privacy" aria-controls="privacy" aria-expanded="<?php echo 'privacy' === $tab ? 'true' : 'false'; ?>" role="tab" data-toggle="tab">Privacy</a>
<li role="presentation"<?php if ($tab === 'privacy') { ?> class="active"<?php } ?>>
<a href="#privacy" aria-controls="privacy" aria-expanded="<?php echo $tab === 'privacy' ? 'true' : 'false'; ?>" role="tab" data-toggle="tab">Privacy</a>
</li>
<li role="presentation"<?php if ('teleporter' === $tab) { ?> class="active"<?php } ?>>
<a href="#teleporter" aria-controls="teleporter" aria-expanded="<?php echo 'teleporter' === $tab ? 'true' : 'false'; ?>" role="tab" data-toggle="tab">Teleporter</a>
<li role="presentation"<?php if ($tab === 'teleporter') { ?> class="active"<?php } ?>>
<a href="#teleporter" aria-controls="teleporter" aria-expanded="<?php echo $tab === 'teleporter' ? 'true' : 'false'; ?>" role="tab" data-toggle="tab">Teleporter</a>
</li>
</ul>
<div class="tab-content">
<!-- ######################################################### System admin ######################################################### -->
<div id="sysadmin" class="tab-pane fade<?php if ('sysadmin' === $tab) { ?> in active<?php } ?>">
<div id="sysadmin" class="tab-pane fade<?php if ($tab === 'sysadmin') { ?> in active<?php } ?>">
<div class="row">
<div class="col-md-12">
<div class="box">
@@ -239,7 +239,7 @@ if (isset($_GET['tab']) && in_array($_GET['tab'], array('sysadmin', 'dns', 'piho
<div class="col-lg-12">
<?php
$FTLpid = intval(pidofFTL());
if (0 !== $FTLpid) {
if ($FTLpid !== 0) {
$FTLversion = exec('/usr/bin/pihole-FTL version'); ?>
<table class="table table-striped table-bordered nowrap">
<tbody>
@@ -377,11 +377,11 @@ if (0 !== $FTLpid) {
</div>
</div>
<!-- ######################################################### DHCP ######################################################### -->
<div id="piholedhcp" class="tab-pane fade<?php if ('piholedhcp' === $tab) { ?> in active<?php } ?>">
<div id="piholedhcp" class="tab-pane fade<?php if ($tab === 'piholedhcp') { ?> in active<?php } ?>">
<?php
// Pi-hole DHCP server
if (isset($setupVars['DHCP_ACTIVE'])) {
if (1 == $setupVars['DHCP_ACTIVE']) {
if ($setupVars['DHCP_ACTIVE'] == 1) {
$DHCP = true;
} else {
$DHCP = false;
@@ -426,7 +426,7 @@ if (0 !== $FTLpid) {
} else {
$DHCP = false;
// Try to guess initial settings
if ('unknown' !== $IPv4GW) {
if ($IPv4GW !== 'unknown') {
$DHCPparts = explode('.', $IPv4GW);
$DHCPstart = $DHCPparts[0].'.'.$DHCPparts[1].'.'.$DHCPparts[2].'.201';
$DHCPend = $DHCPparts[0].'.'.$DHCPparts[1].'.'.$DHCPparts[2].'.251';
@@ -573,9 +573,9 @@ if ($DHCP) {
while (!feof($dhcpleases) && $leasesfile) {
$line = explode(' ', trim(fgets($dhcpleases)));
if (5 == count($line)) {
if (count($line) == 5) {
$counter = intval($line[0]);
if (0 == $counter) {
if ($counter == 0) {
$time = 'Infinite';
} elseif ($counter <= 315360000) { // 10 years in seconds
$time = convertseconds($counter);
@@ -583,7 +583,7 @@ if ($DHCP) {
$time = convertseconds($counter - time());
}
if (false !== strpos($line[2], ':')) {
if (strpos($line[2], ':') !== false) {
// IPv6 address
$type = 6;
} else {
@@ -594,7 +594,7 @@ if ($DHCP) {
$host = htmlentities($line[3]);
$clid = $line[4];
if ('*' == $clid) {
if ($clid == '*') {
$clid = '<i>unknown</i>';
}
@@ -716,13 +716,13 @@ $rate_limit_interval = 60;
// Get rate limit from piholeFTL config array
if (isset($piholeFTLConf['RATE_LIMIT'])) {
$rl = explode('/', $piholeFTLConf['RATE_LIMIT']);
if (2 == count($rl)) {
if (count($rl) == 2) {
$rate_limit_count = intval($rl[0]);
$rate_limit_interval = intval($rl[1]);
}
}
?>
<div id="dns" class="tab-pane fade<?php if ('dns' === $tab) { ?> in active<?php } ?>">
<div id="dns" class="tab-pane fade<?php if ($tab === 'dns') { ?> in active<?php } ?>">
<form role="form" method="post">
<div class="row">
<div class="col-lg-6">
@@ -861,7 +861,7 @@ if (isset($piholeFTLConf['RATE_LIMIT'])) {
<h4>Recommended setting</h4>
<div>
<input type="radio" name="DNSinterface" id="DNSinterface1" value="local"
<?php if ('local' == $DNSinterface) { ?>checked<?php } ?>>
<?php if ($DNSinterface == 'local') { ?>checked<?php } ?>>
<label for="DNSinterface1"><strong>Allow only local requests</strong><br>Allows only queries from devices that are at most one hop away (local devices)</label>
</div>
</div>
@@ -869,17 +869,17 @@ if (isset($piholeFTLConf['RATE_LIMIT'])) {
<h4>Potentially dangerous options</h4>Make sure your Pi-hole is properly firewalled!
<div>
<input type="radio" name="DNSinterface" id="DNSinterface2" value="single"
<?php if ('single' == $DNSinterface) { ?>checked<?php } ?>>
<?php if ($DNSinterface == 'single') { ?>checked<?php } ?>>
<label for="DNSinterface2"><strong>Respond only on interface <?php echo htmlentities($piHoleInterface); ?></strong></label>
</div>
<div>
<input type="radio" name="DNSinterface" id="DNSinterface3" value="bind"
<?php if ('bind' == $DNSinterface) { ?>checked<?php } ?>>
<?php if ($DNSinterface == 'bind') { ?>checked<?php } ?>>
<label for="DNSinterface3"><strong>Bind only to interface <?php echo htmlentities($piHoleInterface); ?></strong></label>
</div>
<div>
<input type="radio" name="DNSinterface" id="DNSinterface4" value="all"
<?php if ('all' == $DNSinterface) { ?>checked<?php } ?>>
<?php if ($DNSinterface == 'all') { ?>checked<?php } ?>>
<label for="DNSinterface4"><strong>Permit all origins</strong></label>
</div>
<p>These options are dangerous on devices
@@ -981,7 +981,7 @@ if (isset($piholeFTLConf['RATE_LIMIT'])) {
when "Never forward non-FQDNs" is <em>not</em> enabled.</p>
<div class="form-group">
<div>
<input type="checkbox" name="rev_server" id="rev_server" value="rev_server" <?php if (isset($rev_server) && (true == $rev_server)) { ?>checked<?php } ?>>
<input type="checkbox" name="rev_server" id="rev_server" value="rev_server" <?php if (isset($rev_server) && ($rev_server == true)) { ?>checked<?php } ?>>
<label for="rev_server"><strong>Use Conditional Forwarding</strong></label>
</div>
<div class="input-group">
@@ -1035,7 +1035,7 @@ if (isset($setupVars['ADMIN_EMAIL'])) {
$adminemail = '';
}
?>
<div id="api" class="tab-pane fade<?php if ('api' === $tab) { ?> in active<?php } ?>">
<div id="api" class="tab-pane fade<?php if ($tab === 'api') { ?> in active<?php } ?>">
<div class="row">
<div class="col-md-6">
<form role="form" method="post">
@@ -1080,13 +1080,13 @@ if (isset($setupVars['ADMIN_EMAIL'])) {
<div class="row">
<div class="col-lg-6">
<div>
<input type="checkbox" name="querylog-permitted" id="querylog-permitted" <?php if ('permittedonly' === $queryLog || 'all' === $queryLog) { ?>checked<?php } ?>>
<input type="checkbox" name="querylog-permitted" id="querylog-permitted" <?php if ($queryLog === 'permittedonly' || $queryLog === 'all') { ?>checked<?php } ?>>
<label for="querylog-permitted"><strong>Show permitted domain entries</strong></label>
</div>
</div>
<div class="col-lg-6">
<div>
<input type="checkbox" name="querylog-blocked" id="querylog-blocked" <?php if ('blockedonly' === $queryLog || 'all' === $queryLog) { ?>checked<?php } ?>>
<input type="checkbox" name="querylog-blocked" id="querylog-blocked" <?php if ($queryLog === 'blockedonly' || $queryLog === 'all') { ?>checked<?php } ?>>
<label for="querylog-blocked"><strong>Show blocked domain entries</strong></label>
</div>
</div>
@@ -1264,7 +1264,7 @@ if (isset($setupVars['ADMIN_EMAIL'])) {
$privacylevel = 0;
}
?>
<div id="privacy" class="tab-pane fade<?php if ('privacy' === $tab) { ?> in active<?php } ?>">
<div id="privacy" class="tab-pane fade<?php if ($tab === 'privacy') { ?> in active<?php } ?>">
<div class="row">
<div class="col-md-12">
<form role="form" method="post">
@@ -1278,22 +1278,22 @@ if (isset($setupVars['ADMIN_EMAIL'])) {
<h4>DNS resolver privacy level</h4>
<p>Specify if DNS queries should be anonymized, available options are:</p>
<div>
<input type="radio" name="privacylevel" id="privacylevel_0" value="0" <?php if (0 === $privacylevel) { ?>checked<?php } ?>>
<input type="radio" name="privacylevel" id="privacylevel_0" value="0" <?php if ($privacylevel === 0) { ?>checked<?php } ?>>
<label for="privacylevel_0"><strong>Show everything and record everything</strong></label>
<p>Gives maximum amount of statistics</p>
</div>
<div>
<input type="radio" name="privacylevel" id="privacylevel_1" value="1" <?php if (1 === $privacylevel) { ?>checked<?php } ?>>
<input type="radio" name="privacylevel" id="privacylevel_1" value="1" <?php if ($privacylevel === 1) { ?>checked<?php } ?>>
<label for="privacylevel_1"><strong>Hide domains: Display and store all domains as "hidden"</strong></label>
<p>This disables the Top Permitted Domains and Top Blocked Domains tables on the dashboard</p>
</div>
<div>
<input type="radio" name="privacylevel" id="privacylevel_2" value="2" <?php if (2 === $privacylevel) { ?>checked<?php } ?>>
<input type="radio" name="privacylevel" id="privacylevel_2" value="2" <?php if ($privacylevel === 2) { ?>checked<?php } ?>>
<label for="privacylevel_2"><strong>Hide domains and clients: Display and store all domains as "hidden" and all clients as "0.0.0.0"</strong></label>
<p>This disables all tables on the dashboard</p>
</div>
<div>
<input type="radio" name="privacylevel" id="privacylevel_3" value="3" <?php if (3 === $privacylevel) { ?>checked<?php } ?>>
<input type="radio" name="privacylevel" id="privacylevel_3" value="3" <?php if ($privacylevel === 3) { ?>checked<?php } ?>>
<label for="privacylevel_3"><strong>Anonymous mode: This disables basically everything except the live anonymous statistics</strong></label>
<p>No history is saved at all to the database, and nothing is shown in the query log. Also, there are no top item lists.</p>
</div>
@@ -1315,7 +1315,7 @@ if (isset($setupVars['ADMIN_EMAIL'])) {
</div>
</div>
<!-- ######################################################### Teleporter ######################################################### -->
<div id="teleporter" class="tab-pane fade<?php if ('teleporter' === $tab) { ?> in active<?php } ?>">
<div id="teleporter" class="tab-pane fade<?php if ($tab === 'teleporter') { ?> in active<?php } ?>">
<div class="row">
<?php if (extension_loaded('Phar')) { ?>
<form role="form" method="post" id="takeoutform"