diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php
index c1e2ed6b9..dfcb0c3ea 100644
--- a/.php-cs-fixer.dist.php
+++ b/.php-cs-fixer.dist.php
@@ -22,6 +22,7 @@
->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)
diff --git a/api_FTL.php b/api_FTL.php
index f1b7c237d..158ee08bf 100644
--- a/api_FTL.php
+++ b/api_FTL.php
@@ -43,12 +43,12 @@
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['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 @@
$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 ('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['getForwardDestinations']) && $auth) {
- if ('unsorted' === $_GET['getForwardDestinations']) {
+ if ($_GET['getForwardDestinations'] === 'unsorted') {
$return = callFTLAPI('forward-dest unsorted');
} else {
$return = callFTLAPI('forward-dest');
@@ -282,7 +282,7 @@
} 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'])) {
diff --git a/api_db.php b/api_db.php
index 1ab47ff1b..905b82d72 100644
--- a/api_db.php
+++ b/api_db.php
@@ -30,16 +30,16 @@
$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['getAllQueries']) && $auth) {
$allQueries = array();
- if ('empty' !== $_GET['getAllQueries']) {
+ if ($_GET['getAllQueries'] !== 'empty') {
$from = intval($_GET['from']);
$until = intval($_GET['until']);
@@ -77,7 +77,7 @@
$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 @@ function parseDBData($results, $interval, $from, $until)
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 @@ function parseDBData($results, $interval, $from, $until)
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 @@ function parseDBData($results, $interval, $from, $until)
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) {
diff --git a/queries.php b/queries.php
index 3c1c9252f..2dbea3796 100644
--- a/queries.php
+++ b/queries.php
@@ -13,16 +13,16 @@
$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 @@
$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 .= ', show all';
@@ -45,9 +45,9 @@
$showing .= ', show blocked only';
}
} 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']);
diff --git a/scripts/pi-hole/php/FTL.php b/scripts/pi-hole/php/FTL.php
index 4fa9366e9..ac7ecee8d 100644
--- a/scripts/pi-hole/php/FTL.php
+++ b/scripts/pi-hole/php/FTL.php
@@ -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;
}
diff --git a/scripts/pi-hole/php/auth.php b/scripts/pi-hole/php/auth.php
index a31209240..2c532c5f3 100644
--- a/scripts/pi-hole/php/auth.php
+++ b/scripts/pi-hole/php/auth.php
@@ -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)
diff --git a/scripts/pi-hole/php/database.php b/scripts/pi-hole/php/database.php
index 57efcf146..f3fe34874 100644
--- a/scripts/pi-hole/php/database.php
+++ b/scripts/pi-hole/php/database.php
@@ -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';
diff --git a/scripts/pi-hole/php/func.php b/scripts/pi-hole/php/func.php
index 11a1af726..cf43271c1 100644
--- a/scripts/pi-hole/php/func.php
+++ b/scripts/pi-hole/php/func.php
@@ -13,21 +13,21 @@
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;
}
diff --git a/scripts/pi-hole/php/gravity.php b/scripts/pi-hole/php/gravity.php
index c2d0ee82f..dc926394a 100644
--- a/scripts/pi-hole/php/gravity.php
+++ b/scripts/pi-hole/php/gravity.php
@@ -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');
}
diff --git a/scripts/pi-hole/php/gravity.sh.php b/scripts/pi-hole/php/gravity.sh.php
index 486e1ff31..e7c3323d3 100644
--- a/scripts/pi-hole/php/gravity.sh.php
+++ b/scripts/pi-hole/php/gravity.sh.php
@@ -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";
diff --git a/scripts/pi-hole/php/groups.php b/scripts/pi-hole/php/groups.php
index 34ce2cad4..7dc02cd94 100644
--- a/scripts/pi-hole/php/groups.php
+++ b/scripts/pi-hole/php/groups.php
@@ -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 @@ function verify_ID_array($arr)
} 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 @@ function verify_ID_array($arr)
}
$desc = $_POST['desc'];
- if (0 === strlen($desc)) {
+ if (strlen($desc) === 0) {
// Store NULL in database for empty descriptions
$desc = null;
}
@@ -77,7 +77,7 @@ function verify_ID_array($arr)
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 @@ function verify_ID_array($arr)
} 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 @@ function verify_ID_array($arr)
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 @@ function verify_ID_array($arr)
} 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 @@ function verify_ID_array($arr)
} 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 @@ function verify_ID_array($arr)
} 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 @@ function verify_ID_array($arr)
$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 @@ function verify_ID_array($arr)
// 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 @@ function verify_ID_array($arr)
}
// 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 @@ function verify_ID_array($arr)
} 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 @@ function verify_ID_array($arr)
// 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 @@ function verify_ID_array($arr)
}
$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 @@ function verify_ID_array($arr)
} 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 @@ function verify_ID_array($arr)
}
$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 @@ function verify_ID_array($arr)
} 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 @@ function verify_ID_array($arr)
} 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 @@ function verify_ID_array($arr)
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 @@ function verify_ID_array($arr)
} 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 @@ function verify_ID_array($arr)
$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 @@ function verify_ID_array($arr)
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 @@ function verify_ID_array($arr)
}
$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 @@ function verify_ID_array($arr)
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 @@ function verify_ID_array($arr)
// 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 @@ function verify_ID_array($arr)
}
}
- 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 @@ function verify_ID_array($arr)
// 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: '.$db->lastErrorMsg().'
Added '.$added.' out of '.$total.' domains');
}
@@ -637,7 +637,7 @@ function verify_ID_array($arr)
}
// 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.
Please modify the domain on the respective group management pages.');
}
@@ -678,8 +678,8 @@ function verify_ID_array($arr)
$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 @@ function verify_ID_array($arr)
} 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 @@ function verify_ID_array($arr)
}
$status = intval($_POST['status']);
- if (0 !== $status) {
+ if ($status !== 0) {
$status = 1;
}
@@ -716,7 +716,7 @@ function verify_ID_array($arr)
}
$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 @@ function verify_ID_array($arr)
} 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 @@ function verify_ID_array($arr)
} 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 @@ function verify_ID_array($arr)
} 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 @@ function verify_ID_array($arr)
} 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 @@ function verify_ID_array($arr)
}
$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 @@ function verify_ID_array($arr)
$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 @@ function verify_ID_array($arr)
// $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('Invalid adlist URL '.htmlentities($address).'
Added '.$added.' out of '.$total.' adlists');
}
@@ -945,7 +945,7 @@ function verify_ID_array($arr)
}
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 @@ function verify_ID_array($arr)
}
$reload = true;
- if ('' != $ignored_list) {
+ if ($ignored_list != '') {
// Send added and ignored lists
$msg = 'Ignored duplicated adlists: '.$ignored.'
'.$ignored_list;
- if ('' != $added_list) {
+ if ($added_list != '') {
$msg .= '
Added adlists: '.$added.'
'.$added_list;
}
$msg .= '
Total: '.$total.' adlist(s) processed.';
@@ -981,7 +981,7 @@ function verify_ID_array($arr)
} 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 @@ function verify_ID_array($arr)
}
$status = intval($_POST['status']);
- if (0 !== $status) {
+ if ($status !== 0) {
$status = 1;
}
@@ -1001,7 +1001,7 @@ function verify_ID_array($arr)
}
$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 @@ function verify_ID_array($arr)
} 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 @@ function verify_ID_array($arr)
} 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 @@ function verify_ID_array($arr)
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 @@ function verify_ID_array($arr)
$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));
diff --git a/scripts/pi-hole/php/header.php b/scripts/pi-hole/php/header.php
index b518352c5..91aee931a 100644
--- a/scripts/pi-hole/php/header.php
+++ b/scripts/pi-hole/php/header.php
@@ -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 @@ function getTemperature()
$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 @@ function getTemperature()
// 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 @@ function getTemperature()
-
+
-
+
-
+
-
+
diff --git a/scripts/pi-hole/php/message.php b/scripts/pi-hole/php/message.php
index fb919c2ec..7ecfccea6 100644
--- a/scripts/pi-hole/php/message.php
+++ b/scripts/pi-hole/php/message.php
@@ -27,7 +27,7 @@
$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)) {
diff --git a/scripts/pi-hole/php/network.php b/scripts/pi-hole/php/network.php
index 42335f855..4b570cea4 100644
--- a/scripts/pi-hole/php/network.php
+++ b/scripts/pi-hole/php/network.php
@@ -26,7 +26,7 @@
$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');
diff --git a/scripts/pi-hole/php/password.php b/scripts/pi-hole/php/password.php
index a8cf3a4ce..923ced7bb 100644
--- a/scripts/pi-hole/php/password.php
+++ b/scripts/pi-hole/php/password.php
@@ -73,7 +73,7 @@
}
// 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;
diff --git a/scripts/pi-hole/php/savesettings.php b/scripts/pi-hole/php/savesettings.php
index 73356175c..261317e16 100644
--- a/scripts/pi-hole/php/savesettings.php
+++ b/scripts/pi-hole/php/savesettings.php
@@ -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!
', 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!
', 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!
', 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!
', 5);
}
if ($lease['host'] === $hostname) {
@@ -306,11 +306,11 @@ function addStaticDHCPLease($mac, $ip, $hostname)
// 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 @@ function addStaticDHCPLease($mac, $ip, $hostname)
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 not been flushed';
} else {
@@ -417,7 +417,7 @@ function addStaticDHCPLease($mac, $ip, $hostname)
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 @@ function addStaticDHCPLease($mac, $ip, $hostname)
if (is_array($output)) {
$error = implode('
', $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';
diff --git a/scripts/pi-hole/php/sidebar.php b/scripts/pi-hole/php/sidebar.php
index cc05f43ed..28acf736c 100644
--- a/scripts/pi-hole/php/sidebar.php
+++ b/scripts/pi-hole/php/sidebar.php
@@ -11,13 +11,13 @@
Status
Active'; - } elseif (0 == $pistatus) { + } elseif ($pistatus == 0) { echo ' Blocking disabled'; - } elseif (-1 == $pistatus) { + } elseif ($pistatus == -1) { echo ' DNS service not running'; - } elseif (-2 == $pistatus) { + } elseif ($pistatus == -2) { echo ' Unknown'; } else { echo ' DNS service on port '.$pistatus.''; @@ -71,7 +71,7 @@