Apply fixes from StyleCI (#12117)

* Apply fixes from StyleCI

* Disable style check
This commit is contained in:
Jellyfrog
2020-09-21 14:54:51 +02:00
committed by GitHub
parent 8ec9183df5
commit 77c531527c
752 changed files with 6238 additions and 5833 deletions

View File

@@ -1,18 +1,18 @@
<?php
$init_modules = array('web', 'auth');
$init_modules = ['web', 'auth'];
require realpath(__DIR__ . '/..') . '/includes/init.php';
if (!Auth::check()) {
die('Unauthorized');
if (! Auth::check()) {
exit('Unauthorized');
}
set_debug($_REQUEST['debug']);
$device = array();
$ports = array();
$bgp = array();
$limit = (int)\LibreNMS\Config::get('webui.global_search_result_limit');
$device = [];
$ports = [];
$bgp = [];
$limit = (int) \LibreNMS\Config::get('webui.global_search_result_limit');
if (isset($_REQUEST['search'])) {
$search = mres($_REQUEST['search']);
@@ -20,9 +20,9 @@ if (isset($_REQUEST['search'])) {
if (strlen($search) > 0) {
$found = 0;
if (!Auth::user()->hasGlobalRead()) {
if (! Auth::user()->hasGlobalRead()) {
$device_ids = Permissions::devicesForUser()->toArray() ?: [0];
$perms_sql = "`D`.`device_id` IN " .dbGenPlaceholders(count($device_ids));
$perms_sql = "`D`.`device_id` IN " . dbGenPlaceholders(count($device_ids));
} else {
$device_ids = [];
$perms_sql = "1";
@@ -31,22 +31,22 @@ if (isset($_REQUEST['search'])) {
if ($_REQUEST['type'] == 'group') {
foreach (dbFetchRows("SELECT id,name FROM device_groups WHERE name LIKE ?", ["%$search%"]) as $group) {
if ($_REQUEST['map']) {
$results[] = array(
'name' => 'g:'.$group['name'],
$results[] = [
'name' => 'g:' . $group['name'],
'group_id' => $group['id'],
);
];
} else {
$results[] = array('name' => $group['name']);
$results[] = ['name' => $group['name']];
}
}
die(json_encode($results));
exit(json_encode($results));
} elseif ($_REQUEST['type'] == 'alert-rules') {
foreach (dbFetchRows("SELECT name FROM alert_rules WHERE name LIKE ?", ["%$search%"]) as $rules) {
$results[] = array('name' => $rules['name']);
$results[] = ['name' => $rules['name']];
}
die(json_encode($results));
exit(json_encode($results));
} elseif ($_REQUEST['type'] == 'device') {
// Device search
@@ -69,26 +69,26 @@ if (isset($_REQUEST['search'])) {
OR `D`.`purpose` LIKE ?
OR `D`.`notes` LIKE ?";
$query_args_list = array_merge($query_args_list, ["%$search%", "%$search%", "%$search%",
"%$search%", "%$search%"]);
"%$search%", "%$search%", ]);
if (\LibreNMS\Util\IPv4::isValid($search, false)) {
$query .= " LEFT JOIN `ports` AS `P` ON `P`.`device_id` = `D`.`device_id`
$query .= " LEFT JOIN `ports` AS `P` ON `P`.`device_id` = `D`.`device_id`
LEFT JOIN `ipv4_addresses` AS `V4` ON `V4`.`port_id` = `P`.`port_id`";
$query_filter .= " OR `V4`.`ipv4_address` LIKE ?
$query_filter .= " OR `V4`.`ipv4_address` LIKE ?
OR `D`.`overwrite_ip` LIKE ?
OR `D`.`ip` = ? ";
$query_args_list = array_merge($query_args_list, ["%$search%", "%$search%", inet_pton($search)]);
$query_args_list = array_merge($query_args_list, ["%$search%", "%$search%", inet_pton($search)]);
} elseif (\LibreNMS\Util\IPv6::isValid($search, false)) {
$query .= " LEFT JOIN `ports` AS `P` ON `P`.`device_id` = `D`.`device_id`
$query .= " LEFT JOIN `ports` AS `P` ON `P`.`device_id` = `D`.`device_id`
LEFT JOIN `ipv6_addresses` AS `V6` ON `V6`.`port_id` = `P`.`port_id`";
$query_filter .= " OR `V6`.`ipv6_address` LIKE ?
$query_filter .= " OR `V6`.`ipv6_address` LIKE ?
OR `D`.`overwrite_ip` LIKE ?
OR `D`.`ip` = ? ";
$query_args_list = array_merge($query_args_list, ["%$search%", "%$search%", inet_pton($search)]);
$query_args_list = array_merge($query_args_list, ["%$search%", "%$search%", inet_pton($search)]);
} elseif (ctype_xdigit($mac_search = str_replace([':', '-', '.'], '', $search))) {
$query .= " LEFT JOIN `ports` as `M` on `M`.`device_id` = `D`.`device_id`";
$query_filter .= " OR `M`.`ifPhysAddress` LIKE ? ";
$query_args_list[] = "%$mac_search%";
$query .= " LEFT JOIN `ports` as `M` on `M`.`device_id` = `D`.`device_id`";
$query_filter .= " OR `M`.`ifPhysAddress` LIKE ? ";
$query_args_list[] = "%$mac_search%";
}
// result limitation
@@ -99,13 +99,13 @@ if (isset($_REQUEST['search'])) {
ORDER BY `D`.`hostname` LIMIT ?", $query_args_list);
if (count($results)) {
$found = 1;
$found = 1;
$devices = count($results);
foreach ($results as $result) {
$name = $result['hostname'];
if ($_REQUEST['map'] != 1 && $result['sysName'] != $name && !empty($result['sysName'])) {
$name .= ' ('.$result['sysName'].') ';
if ($_REQUEST['map'] != 1 && $result['sysName'] != $name && ! empty($result['sysName'])) {
$name .= ' (' . $result['sysName'] . ') ';
}
if ($result['disabled'] == 1) {
$highlight_colour = '#808080';
@@ -119,7 +119,7 @@ if (isset($_REQUEST['search'])) {
$num_ports = dbFetchCell('SELECT COUNT(*) FROM `ports` AS `I`, `devices` AS `D` WHERE ' . $perms_sql . ' AND `I`.`device_id` = `D`.`device_id` AND `I`.`ignore` = 0 AND `I`.`deleted` = 0 AND `D`.`device_id` = ?', array_merge($device_ids, [$result['device_id']]));
$device[] = array(
$device[] = [
'name' => $name,
'device_id' => $result['device_id'],
'url' => generate_device_url($result),
@@ -130,12 +130,12 @@ if (isset($_REQUEST['search'])) {
'device_os' => \LibreNMS\Config::getOsSetting($result['os'], 'text'),
'version' => $result['version'],
'location' => $result['location'],
);
];
}//end foreach
}//end if
$json = json_encode($device);
die($json);
exit($json);
} elseif ($_REQUEST['type'] == 'ports') {
// Search ports
if (Auth::user()->hasGlobalRead()) {
@@ -154,7 +154,7 @@ if (isset($_REQUEST['search'])) {
$found = 1;
foreach ($results as $result) {
$name = $result['ifDescr'] == $result['ifAlias'] ? $result['ifName'] : $result['ifDescr'];
$name = $result['ifDescr'] == $result['ifAlias'] ? $result['ifName'] : $result['ifDescr'];
$description = display($result['ifAlias']);
if ($result['deleted'] == 0 && ($result['ignore'] == 0 || $result['ignore'] == 0) && ($result['ifInErrors_delta'] > 0 || $result['ifOutErrors_delta'] > 0)) {
@@ -174,7 +174,7 @@ if (isset($_REQUEST['search'])) {
$port_colour = '#008000';
}//end if
$ports[] = array(
$ports[] = [
'count' => count($results),
'url' => generate_port_url($result),
'name' => $name,
@@ -182,12 +182,12 @@ if (isset($_REQUEST['search'])) {
'colours' => $port_colour,
'hostname' => format_hostname($result),
'port_id' => $result['port_id'],
);
];
}//end foreach
}//end if
$json = json_encode($ports);
die($json);
exit($json);
} elseif ($_REQUEST['type'] == 'bgp') {
// Search bgp peers
$results = dbFetchRows(
@@ -199,10 +199,10 @@ if (isset($_REQUEST['search'])) {
$found = 1;
foreach ($results as $result) {
$name = $result['bgpPeerIdentifier'];
$name = $result['bgpPeerIdentifier'];
$description = $result['astext'];
$remoteas = $result['bgpPeerRemoteAs'];
$localas = $result['bgpLocalAs'];
$remoteas = $result['bgpPeerRemoteAs'];
$localas = $result['bgpLocalAs'];
if ($result['bgpPeerAdminStatus'] == 'start' && $result['bgpPeerState'] != 'established') {
// Session active but errored
@@ -221,7 +221,7 @@ if (isset($_REQUEST['search'])) {
$bgp_image = 'fa fa-external-link-square fa-lg icon-theme';
}
$bgp[] = array(
$bgp[] = [
'count' => count($results),
'url' => generate_peer_url($result),
'name' => $name,
@@ -231,12 +231,12 @@ if (isset($_REQUEST['search'])) {
'remoteas' => $remoteas,
'colours' => $port_colour,
'hostname' => format_hostname($result),
);
];
}//end foreach
}//end if
$json = json_encode($bgp);
die($json);
exit($json);
} elseif ($_REQUEST['type'] == 'applications') {
// Device search
$results = dbFetchRows(
@@ -244,9 +244,8 @@ if (isset($_REQUEST['search'])) {
array_merge($device_ids, ["%$search%", "%$search%", $limit])
);
if (count($results)) {
$found = 1;
$found = 1;
$devices = count($results);
foreach ($results as $result) {
@@ -261,7 +260,7 @@ if (isset($_REQUEST['search'])) {
$highlight_colour = '#008000';
}
$device[] = array(
$device[] = [
'name' => $name,
'hostname' => format_hostname($result),
'app_id' => $result['app_id'],
@@ -272,12 +271,12 @@ if (isset($_REQUEST['search'])) {
'device_os' => \LibreNMS\Config::getOsSetting($result['os'], 'text'),
'version' => $result['version'],
'location' => $result['location'],
);
];
}//end foreach
}//end if
$json = json_encode($device);
die($json);
exit($json);
} elseif ($_REQUEST['type'] == 'munin') {
// Device search
$results = dbFetchRows(
@@ -285,9 +284,8 @@ if (isset($_REQUEST['search'])) {
array_merge($device_ids, ["%$search%", "%$search%", "%$search%", $limit])
);
if (count($results)) {
$found = 1;
$found = 1;
$devices = count($results);
foreach ($results as $result) {
@@ -302,7 +300,7 @@ if (isset($_REQUEST['search'])) {
$highlight_colour = '#008000';
}
$device[] = array(
$device[] = [
'name' => $name,
'hostname' => format_hostname($result),
'device_id' => $result['device_id'],
@@ -313,12 +311,12 @@ if (isset($_REQUEST['search'])) {
'version' => $result['version'],
'location' => $result['location'],
'plugin' => $result['mplug_type'],
);
];
}//end foreach
}//end if
$json = json_encode($device);
die($json);
exit($json);
} elseif ($_REQUEST['type'] == 'iftype') {
// Device search
$results = dbFetchRows(
@@ -327,18 +325,18 @@ if (isset($_REQUEST['search'])) {
);
if (count($results)) {
$found = 1;
$found = 1;
$devices = count($results);
foreach ($results as $result) {
$device[] = array(
$device[] = [
'filter' => $result['ifType'],
);
];
}//end foreach
}//end if
$json = json_encode($device);
die($json);
exit($json);
} elseif ($_REQUEST['type'] == 'bill') {
// Device search
if (Auth::user()->hasGlobalRead()) {
@@ -353,7 +351,7 @@ if (isset($_REQUEST['search'])) {
);
}
$json = json_encode($results);
die($json);
exit($json);
}//end if
}//end if
}//end if