Misc webui code cleanups (#14242)

* Misc webui cleanups

* Style

* More

* graphing fixes

* More graph cleanups

* more fixes, graphs and device pages

* style
This commit is contained in:
Tony Murray 2022-08-30 12:55:37 -05:00 committed by GitHub
parent 797d73ad16
commit 6f5cf7727a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
64 changed files with 343 additions and 324 deletions

View File

@ -240,11 +240,7 @@ class OS implements
if (isset($device['os'])) {
// load os definition and populate os_group
\LibreNMS\Util\OS::loadDefinition($device['os']);
if ($os_group = Config::get("os.{$device['os']}.group")) {
$device['os_group'] = $os_group;
} else {
$device['os_group'] = null;
}
$device['os_group'] = Config::get("os.{$device['os']}.group");
$class = StringHelpers::toClass($device['os'], 'LibreNMS\\OS\\');
d_echo('Attempting to initialize OS: ' . $device['os'] . PHP_EOL);

View File

@ -168,7 +168,7 @@ class ConnectivityHelper
public function ipFamily(): string
{
if ($this->family === null) {
$this->family = preg_match('/6$/', $this->device->transport) ? 'ipv6' : 'ipv4';
$this->family = preg_match('/6$/', $this->device->transport ?? '') ? 'ipv6' : 'ipv4';
}
return $this->family;

View File

@ -95,7 +95,7 @@ class Url
}
if ($device->location_id) {
$contents .= ' - ' . htmlentities($device->location);
$contents .= ' - ' . htmlentities($device->location ?? '');
}
$contents .= '</div>';
@ -332,7 +332,7 @@ class Url
{
$urlargs = [];
foreach ($args as $key => $arg) {
$urlargs[] = $key . '=' . urlencode($arg);
$urlargs[] = $key . '=' . ($arg === null ? '' : urlencode($arg));
}
return '<img src="' . url('graph.php') . '?' . implode('&amp;', $urlargs) . '" style="border:0;" />';
@ -372,7 +372,7 @@ class Url
$urlargs = [];
foreach ($args as $key => $arg) {
$urlargs[] = $key . '=' . urlencode($arg);
$urlargs[] = $key . '=' . ($arg === null ? '' : urlencode($arg));
}
$tag = '<img class="img-responsive" src="' . url('graph.php') . '?' . implode('&amp;', $urlargs) . '" style="border:0;"';

View File

@ -111,6 +111,7 @@ class DeviceController extends Controller
{
ob_start();
$device = $device->toArray();
$device['os_group'] = Config::get("os.{$device['os']}.group");
Debug::set(false);
chdir(base_path());
$init_modules = ['web', 'auth'];

View File

@ -279,9 +279,11 @@ class DeviceController extends TableController
*/
private function getLocation($device)
{
$location = $device->location ?? '';
return extension_loaded('mbstring')
? mb_substr($device->location, 0, 32, 'utf8')
: substr($device->location, 0, 32);
? mb_substr($location, 0, 32, 'utf8')
: substr($location, 0, 32);
}
private function getActions(Device $device): array

View File

@ -77,9 +77,9 @@ class FdbTablesController extends TableController
*/
protected function search($search, $query, $fields = [])
{
if ($search = trim(\Request::get('searchPhrase'))) {
if ($search = trim(\Request::get('searchPhrase') ?? '')) {
$mac_search = '%' . str_replace([':', ' ', '-', '.', '0x'], '', $search) . '%';
switch (\Request::get('searchby')) {
switch (\Request::get('searchby') ?? '') {
case 'mac':
return $query->where('ports_fdb.mac_address', 'like', $mac_search);
case 'vlan':

View File

@ -21,12 +21,13 @@ if (! Auth::check()) {
exit('Unauthorized');
}
Debug::set($_REQUEST['debug']);
Debug::set(! empty($_REQUEST['debug']));
$current = $_REQUEST['current'];
settype($current, 'integer');
$rowCount = $_REQUEST['rowCount'];
settype($rowCount, 'integer');
$sort = '';
if (isset($_REQUEST['sort']) && is_array($_REQUEST['sort'])) {
foreach ($_REQUEST['sort'] as $k => $v) {
$k = preg_replace('/[^A-Za-z0-9_]/', '', $k); // only allow plain columns

View File

@ -30,7 +30,7 @@ $ifnum = @$port['ifIndex']; // BSD / SNMP interface name / number
$ifname = $port['label']; //Interface name that will be showed on top right of graph
$hostname = shorthost($device['hostname']);
if ($_GET['title']) {
if (isset($_GET['title'])) {
$ifname = \LibreNMS\Util\Clean::html($_GET['title'], []);
}

View File

@ -147,7 +147,7 @@ function getImageTitle($device)
function getImageName($device, $use_database = true, $dir = 'images/os/')
{
return \LibreNMS\Util\Url::findOsImage($device['os'], $device['features'], $use_database ? $device['icon'] : null, $dir);
return \LibreNMS\Util\Url::findOsImage($device['os'], $device['features'] ?? '', $use_database ? $device['icon'] : null, $dir);
}
function renamehost($id, $new, $source = 'console')

View File

@ -166,13 +166,14 @@ if (defined('SHOW_SETTINGS')) {
} else {
$alert_id = $vars['alert_id'] ?? 0;
$device_id = $device['device_id'];
$acknowledged = $widget_settings['acknowledged'];
$fired = $widget_settings['fired'];
$state = $widget_settings['state'];
$min_severity = $widget_settings['min_severity'];
$group = $widget_settings['group'];
$proc = $widget_settings['proc'];
$sort = $widget_settings['sort'];
$acknowledged = $widget_settings['acknowledged'] ?? '';
$fired = $widget_settings['fired'] ?? '';
$state = $widget_settings['state'] ?? '';
$min_severity = $widget_settings['min_severity'] ?? '';
$group = $widget_settings['group'] ?? '';
$proc = $widget_settings['proc'] ?? '';
$sort = $widget_settings['sort'] ?? '';
$unique_id = $unique_id ?? '';
$title = 'Alerts';
@ -217,7 +218,7 @@ if (defined('SHOW_SETTINGS')) {
$widget_settings['title'] = $title;
$group = $widget_settings['group'];
$group = $widget_settings['group'] ?? '';
$common_output[] = '
<div class="row">

View File

@ -30,7 +30,7 @@ if (Config::get('webui.availability_map_compact') == 1) {
$compact_tile = $settings['tile_size'];
}
$show_disabled_ignored = $settings['show_disabled_and_ignored'];
$show_disabled_ignored = $settings['show_disabled_and_ignored'] ?? false;
if (defined('SHOW_SETTINGS')) {
$common_output[] = '
@ -380,11 +380,9 @@ if (defined('SHOW_SETTINGS')) {
$serviceClass = 'widget-availability-service';
}
if ($show_disabled_ignored == 1) {
$disabled_ignored_header = '
$disabled_ignored_header = $show_disabled_ignored == 1 ? '
<span class="label label-default label-font-border label-border">alert-disabled: ' . $host_disable_notify_count . '</span>
<span class="label blackbg label-font-border label-border">disabled: ' . $host_disabled_count . '</span>';
}
<span class="label blackbg label-font-border label-border">disabled: ' . $host_disabled_count . '</span>' : '';
if ($mode == 0 || $mode == 2) {
$temp_header[] = '

View File

@ -36,7 +36,7 @@ var eventlog_grid = $("#eventlog").bootgrid({
{
return {
device: ' . (empty($vars['device']) ? 'null' : (int) $vars['device']) . ',
eventtype: "' . addcslashes($vars['eventtype'], '"') . '",
eventtype: "' . addcslashes($vars['eventtype'] ?? '', '"') . '",
};
},
url: "' . url('/ajax/table/eventlog') . '"

View File

@ -37,11 +37,11 @@ var syslog_grid = $("#syslog").bootgrid({
post: function ()
{
return {
device: "' . addcslashes($vars['device'], '"') . '",
program: "' . addcslashes($vars['program'], '"') . '",
priority: "' . addcslashes($vars['priority'], '"') . '",
to: "' . addcslashes($vars['to'], '"') . '",
from: "' . addcslashes($vars['from'], '"') . '",
device: "' . addcslashes($vars['device'] ?? '', '"') . '",
program: "' . addcslashes($vars['program'] ?? '', '"') . '",
priority: "' . addcslashes($vars['priority'] ?? '', '"') . '",
to: "' . addcslashes($vars['to'] ?? '', '"') . '",
from: "' . addcslashes($vars['from'] ?? '', '"') . '",
};
},
url: "' . url('/ajax/table/syslog') . '"

View File

@ -233,7 +233,7 @@ function generate_graph_js_state($args)
$to = (is_numeric($args['to']) ? $args['to'] : 0);
$width = (is_numeric($args['width']) ? $args['width'] : 0);
$height = (is_numeric($args['height']) ? $args['height'] : 0);
$legend = str_replace("'", '', $args['legend']);
$legend = str_replace("'", '', $args['legend'] ?? '');
$state = <<<STATE
<script type="text/javascript" language="JavaScript">
@ -323,6 +323,10 @@ function generate_port_link($port, $text = null, $type = null, $overlib = 1, $si
$port = array_merge($port, device_by_id_cache($port['device_id']));
}
if (! isset($port['label'])) {
$port = cleanPort($port);
}
$content = '<div class=list-large>' . $port['hostname'] . ' - ' . Rewrite::normalizeIfName(addslashes(\LibreNMS\Util\Clean::html($port['label'], []))) . '</div>';
$content .= addslashes(\LibreNMS\Util\Clean::html($port['ifAlias'], [])) . '<br />';
@ -724,22 +728,24 @@ function get_url()
function alert_details($details)
{
if (! is_array($details)) {
if (is_string($details)) {
$details = json_decode(gzuncompress($details), true);
} elseif (! is_array($details)) {
$details = [];
}
$max_row_length = 0;
$all_fault_detail = '';
foreach ($details['rule'] as $o => $tmp_alerts) {
foreach ($details['rule'] ?? [] as $o => $tmp_alerts) {
$fault_detail = '';
$fallback = true;
$fault_detail .= '#' . ($o + 1) . ':&nbsp;';
if ($tmp_alerts['bill_id']) {
if (isset($tmp_alerts['bill_id'])) {
$fault_detail .= '<a href="' . \LibreNMS\Util\Url::generate(['page' => 'bill', 'bill_id' => $tmp_alerts['bill_id']], []) . '">' . $tmp_alerts['bill_name'] . '</a>;&nbsp;';
$fallback = false;
}
if ($tmp_alerts['port_id']) {
if (isset($tmp_alerts['port_id'])) {
if ($tmp_alerts['isisISAdjState']) {
$fault_detail .= 'Adjacent ' . $tmp_alerts['isisISAdjIPAddrAddress'];
$port = \App\Models\Port::find($tmp_alerts['port_id']);
@ -751,12 +757,12 @@ function alert_details($details)
$fallback = false;
}
if ($tmp_alerts['accesspoint_id']) {
if (isset($tmp_alerts['accesspoint_id'])) {
$fault_detail .= generate_ap_link($tmp_alerts, $tmp_alerts['name']) . ';&nbsp;';
$fallback = false;
}
if ($tmp_alerts['sensor_id']) {
if (isset($tmp_alerts['sensor_id'])) {
if ($tmp_alerts['sensor_class'] == 'state') {
// Give more details for a state (textual form)
$details = 'State: ' . $tmp_alerts['state_descr'] . ' (numerical ' . $tmp_alerts['sensor_current'] . ')<br> ';
@ -784,7 +790,7 @@ function alert_details($details)
$fallback = false;
}
if ($tmp_alerts['bgpPeer_id']) {
if (isset($tmp_alerts['bgpPeer_id'])) {
// If we have a bgpPeer_id, we format the data accordingly
$fault_detail .= "BGP peer <a href='" .
\LibreNMS\Util\Url::generate([
@ -799,7 +805,7 @@ function alert_details($details)
$fallback = false;
}
if ($tmp_alerts['type'] && $tmp_alerts['label']) {
if ($tmp_alerts['type'] && isset($tmp_alerts['label'])) {
if ($tmp_alerts['error'] == '') {
$fault_detail .= ' ' . $tmp_alerts['type'] . ' - ' . $tmp_alerts['label'] . ';&nbsp;';
} else {

View File

@ -7,7 +7,7 @@ if (is_numeric($vars['id'])) {
$device = device_by_id_cache($data['device_id']);
$title = generate_device_link($device);
$title .= ' :: BGP :: ' . htmlentities($data['bgp_peerid']);
$title .= ' :: BGP :: ' . htmlentities($data['bgpPeerIdentifier']);
$auth = true;
}
}

View File

@ -3,23 +3,23 @@
use LibreNMS\Config;
use LibreNMS\Util\Clean;
if ($_GET['from']) {
if (isset($_GET['from']) && $_GET['from']) {
$from = parse_at_time($_GET['from']);
}
if ($_GET['to']) {
if (isset($_GET['to']) && $_GET['to']) {
$to = parse_at_time($_GET['to']);
}
if ($_GET['width']) {
if (isset($_GET['width']) && $_GET['width']) {
$width = (int) $_GET['width'];
}
if ($_GET['height']) {
if (isset($_GET['height']) && $_GET['height']) {
$height = (int) $_GET['height'];
}
if ($_GET['inverse']) {
if (! empty($_GET['inverse'])) {
$in = 'out';
$out = 'in';
$inverse = true;
@ -28,7 +28,7 @@ if ($_GET['inverse']) {
$out = 'out';
}
if ($_GET['legend'] == 'no') {
if (isset($_GET['legend']) && $_GET['legend'] == 'no') {
$rrd_options .= ' -g';
}
@ -50,7 +50,7 @@ if (isset($_GET['noagg'])) {
$noagg = true;
}
if ($_GET['title'] == 'yes') {
if (isset($_GET['title']) && $_GET['title'] == 'yes') {
$rrd_options .= " --title='" . $graph_title . "' ";
}
@ -90,15 +90,15 @@ if (Config::get('applied_site_style') == 'dark') {
$rrd_options .= \LibreNMS\Config::get('rrdgraph_def_text') . ' -c FONT#' . ltrim(\LibreNMS\Config::get('rrdgraph_def_text_color'), '#');
}
if ($_GET['bg']) {
if (! empty($_GET['bg'])) {
$rrd_options .= ' -c CANVAS#' . Clean::alphaDash($_GET['bg']) . ' ';
}
if ($_GET['bbg']) {
if (! empty($_GET['bbg'])) {
$rrd_options .= ' -c BACK#' . Clean::alphaDash($_GET['bbg']) . ' ';
}
if ($_GET['font']) {
if (! empty($_GET['font'])) {
$rrd_options .= ' -c FONT#' . Clean::alphaDash($_GET['font']) . ' ';
}

View File

@ -43,7 +43,7 @@ if (! $swap_present) {
}
$colors = \LibreNMS\Config::get('graph_colours.varied');
$legend_sections = [0 => '', 1 => ''];
$legend_sections = [0 => '', 1 => '', 2 => ''];
$section = 0;
$free_indexes = [];
$rrd_options .= " COMMENT:' Min Max Cur \\n'";
@ -120,6 +120,6 @@ if (! empty($free_indexes)) {
}
}
$rrd_options .= implode(" COMMENT:' \\l'", $legend_sections);
$rrd_options .= implode(" COMMENT:' \\l'", array_filter($legend_sections));
$rrd_options .= ' HRULE:0#999999';

View File

@ -19,6 +19,10 @@ use LibreNMS\Util\Number;
require 'includes/html/graphs/common.inc.php';
$stacked = generate_stacked_graphs();
$inverse = $inverse ?? false;
$multiplier = $multiplier ?? false;
$format = $format ?? '';
$previous = $_GET['previous'] ?? 'no';
if ($rrd_filename) {
$rrd_filename_out = $rrd_filename;
@ -49,7 +53,7 @@ if ($multiplier) {
$rrd_options .= ' DEF:' . $in . 'octets_max=' . $rrd_filename_in . ':' . $ds_in . ':MAX';
}
if ($_GET['previous'] == 'yes') {
if ($previous == 'yes') {
if ($multiplier) {
$rrd_options .= ' DEF:p' . $out . 'octetsX=' . $rrd_filename_out . ':' . $ds_out . ':AVERAGE:start=' . $prev_from . ':end=' . $from;
$rrd_options .= ' DEF:p' . $in . 'octetsX=' . $rrd_filename_in . ':' . $ds_in . ':AVERAGE:start=' . $prev_from . ':end=' . $from;
@ -101,7 +105,7 @@ $rrd_options .= ' CDEF:inbits_max=inoctets_max,8,*';
if (Config::get('rrdgraph_real_percentile')) {
$rrd_options .= ' CDEF:highbits=inoctets,outoctets,MAX,8,*';
$rrd_options .= ' VDEF:percentilehigh=highbits,' . Config::get('percentile_value') . ',PERCENT';
if ($_GET['previous'] == 'yes') {
if ($previous == 'yes') {
$rrd_options .= ' CDEF:highbitsX=inoctetsX,outoctetsX,MAX,8,*';
$rrd_options .= ' VDEF:percentilehighX=highbitsX,' . Config::get('percentile_value') . ',PERCENT';
}
@ -118,7 +122,7 @@ $rrd_options .= ' VDEF:dpercentile_out=dpercentile_outnpn,FIRST';
if ($format == 'octets' || $format == 'bytes') {
$rrd_options .= ' VDEF:percentile_in=inoctets,' . Config::get('percentile_value') . ',PERCENT';
$rrd_options .= ' VDEF:percentile_out=outoctets,' . Config::get('percentile_value') . ',PERCENT';
if ($_GET['previous'] == 'yes') {
if ($previous == 'yes') {
$rrd_options .= ' VDEF:percentile_inX=inoctetsX,' . Config::get('percentile_value') . ',PERCENT';
$rrd_options .= ' VDEF:percentile_outX=outoctetsX,' . Config::get('percentile_value') . ',PERCENT';
}
@ -127,7 +131,7 @@ if ($format == 'octets' || $format == 'bytes') {
} else {
$rrd_options .= ' VDEF:percentile_in=inbits,' . Config::get('percentile_value') . ',PERCENT';
$rrd_options .= ' VDEF:percentile_out=outbits,' . Config::get('percentile_value') . ',PERCENT';
if ($_GET['previous'] == 'yes') {
if ($previous == 'yes') {
$rrd_options .= ' VDEF:percentile_inX=inbitsX,' . Config::get('percentile_value') . ',PERCENT';
$rrd_options .= ' VDEF:percentile_outX=outbitsX,' . Config::get('percentile_value') . ',PERCENT';
}
@ -182,7 +186,7 @@ if ($to > time()) {
$rrd_options .= " LINE2:olsl#4400dd:'Out Linear Prediction\\n':dashes=8";
}
if ($_GET['previous'] == 'yes') {
if ($previous == 'yes') {
$rrd_options .= " COMMENT:' \\n'";
$rrd_options .= ' LINE1.25:in' . $format . "X#333300:'Prev In '\t";
$rrd_options .= ' GPRINT:in' . $format . 'X:AVERAGE:%6.' . $float_precision . 'lf%s';

View File

@ -17,10 +17,12 @@ require 'includes/html/graphs/common.inc.php';
$stacked = generate_stacked_graphs();
$length = '10';
$length = 10;
$percentile = $percentile ?? false;
$print_total = $print_total ?? false;
if (! isset($percentile)) {
$length += '2';
$length += 2;
}
if (! isset($out_text)) {
@ -54,12 +56,12 @@ if ($percentile) {
$rrd_options .= ' VDEF:dpercentile_out=dout,' . $percentile . ',PERCENT';
}
if ($graph_max) {
if (! empty($graph_max)) {
$rrd_options .= ' AREA:in_max#' . $colour_area_in_max . $stacked['transparency'] . ':';
$rrd_options .= ' AREA:dout_max#' . $colour_area_out_max . $stacked['transparency'] . ':';
}
if ($_GET['previous'] == 'yes') {
if (isset($_GET['previous']) && $_GET['previous'] == 'yes') {
$rrd_options .= ' DEF:' . $out . 'X=' . $rrd_filename . ':' . $ds_out . ':AVERAGE:start=' . $prev_from . ':end=' . $from;
$rrd_options .= ' DEF:' . $in . 'X=' . $rrd_filename . ':' . $ds_in . ':AVERAGE:start=' . $prev_from . ':end=' . $from;
$rrd_options .= ' DEF:' . $out . '_maxX=' . $rrd_filename . ':' . $ds_out . ':MAX:start=' . $prev_from . ':end=' . $from;
@ -131,7 +133,7 @@ if ($percentile) {
$rrd_options .= ' LINE1:dpercentile_out#aa0000';
}
if ($_GET['previous'] == 'yes') {
if (isset($_GET['previous']) && $_GET['previous'] == 'yes') {
$rrd_options .= ' LINE1.25:in' . $format . "X#666666:'Prev In \\\\n'";
$rrd_options .= ' AREA:in' . $format . 'X#99999966' . $stacked['transparency'] . ':';
$rrd_options .= ' LINE1.25:dout' . $format . "X#666666:'Prev Out'";

View File

@ -17,6 +17,15 @@ use LibreNMS\Config;
require 'includes/html/graphs/common.inc.php';
$format = $format ?? '';
$previous = $_GET['previous'] ?? 'no';
$transparency = $transparency ?? false;
$stack = $stack ?? '';
$rrd_optionsb = '';
$in_thingX = '';
$out_thingX = '';
$plusesX = '';
$rrddescr_len = 14; // length of the padded rrd_descr in legend
if ($width > '1500') {
@ -63,7 +72,7 @@ if ($width > '500') {
$rrd_options .= sprintf(" COMMENT:'%10s'", 'Max');
}
if ($_GET['previous']) {
if ($previous) {
$rrd_options .= sprintf(" COMMENT:'\t'", '');
$rrd_options .= sprintf(" COMMENT:'%10s'", 'P Avg');
$rrd_options .= sprintf(" COMMENT:'%10s'", 'P Max');
@ -74,6 +83,7 @@ if ($_GET['previous']) {
$rrd_options .= " COMMENT:'\\n'";
$iter = 0;
foreach ($rrd_list ?? [] as $rrd) {
if (! Config::get("graph_colours.$colours_in.$iter") || ! Config::get("graph_colours.$colours_out.$iter")) {
$iter = 0;
@ -98,9 +108,9 @@ foreach ($rrd_list ?? [] as $rrd) {
$rrd_options .= ' CDEF:outbits' . $i . '_neg=outbits' . $i . ',' . $stacked['stacked'] . ',*';
$rrd_options .= ' CDEF:bits' . $i . '=inbits' . $i . ',outbits' . $i . ',+';
if ($_GET['previous']) {
$rrd_options .= ' DEF:inB' . $i . 'X=' . $rrd['filename'] . ':' . $ds_in . ':AVERAGE:start=' . $prev_from . ':end=' . $from;
$rrd_options .= ' DEF:outB' . $i . 'X=' . $rrd['filename'] . ':' . $ds_out . ':AVERAGE:start=' . $prev_from . ':end=' . $from;
if ($previous) {
$rrd_options .= ' DEF:inB' . $i . 'X=' . $rrd['filename'] . ':' . $rrd['ds_in'] . ':AVERAGE:start=' . $prev_from . ':end=' . $from;
$rrd_options .= ' DEF:outB' . $i . 'X=' . $rrd['filename'] . ':' . $rrd['ds_out'] . ':AVERAGE:start=' . $prev_from . ':end=' . $from;
$rrd_options .= ' CDEF:octets' . $i . 'X=inB' . $i . 'X,outB' . $i . 'X,+';
$rrd_options .= ' CDEF:inbits' . $i . 'X=inB' . $i . 'X' . ",$multiplier,* ";
$rrd_options .= ' CDEF:outbits' . $i . 'X=outB' . $i . 'X' . ",$multiplier,*";
@ -120,7 +130,7 @@ foreach ($rrd_list ?? [] as $rrd) {
$rrd_options .= ' VDEF:totinB' . $i . '=inB' . $i . ',TOTAL';
$rrd_options .= ' VDEF:totoutB' . $i . '=outB' . $i . ',TOTAL';
$rrd_options .= ' VDEF:tot' . $i . '=octets' . $i . ',TOTAL';
if ($_GET['previous']) {
if ($previous) {
$in_thingX .= $seperatorX . 'inB' . $i . 'X,UN,0,' . 'inB' . $i . 'X,IF';
$out_thingX .= $seperatorX . 'outB' . $i . 'X,UN,0,' . 'outB' . $i . 'X,IF';
$plusesX .= $plusX;
@ -150,7 +160,7 @@ foreach ($rrd_list ?? [] as $rrd) {
$rrd_options .= ' GPRINT:totinB' . $i . ':%6.' . $float_precision . "lf%s$total_units";
}
if ($_GET['previous'] == 'yes') {
if ($previous == 'yes') {
$rrd_options .= " COMMENT:' \t'";
$rrd_options .= ' GPRINT:inbits' . $i . 'X:AVERAGE:%6.' . $float_precision . "lf%s$units";
$rrd_options .= ' GPRINT:inbits' . $i . 'X:MAX:%6.' . $float_precision . "lf%s$units";
@ -170,7 +180,7 @@ foreach ($rrd_list ?? [] as $rrd) {
$rrd_options .= ' GPRINT:totoutB' . $i . ':%6.' . $float_precision . "lf%s$total_units";
}
if ($_GET['previous'] == 'yes') {
if ($previous == 'yes') {
$rrd_options .= " COMMENT:' \t'";
$rrd_options .= ' GPRINT:outbits' . $i . 'X:AVERAGE:%6.' . $float_precision . "lf%s$units";
$rrd_options .= ' GPRINT:outbits' . $i . 'X:MAX:%6.' . $float_precision . "lf%s$units";
@ -184,7 +194,7 @@ foreach ($rrd_list ?? [] as $rrd) {
$iter++;
}
if ($_GET['previous'] == 'yes') {
if ($previous == 'yes') {
$rrd_options .= ' CDEF:inBX=' . $in_thingX . $plusesX;
$rrd_options .= ' CDEF:outBX=' . $out_thingX . $plusesX;
$rrd_options .= ' CDEF:octetsX=inBX,outBX,+';
@ -206,7 +216,7 @@ if ($_GET['previous'] == 'yes') {
$rrd_options .= ' VDEF:totX=octetsX,TOTAL';
}
if ($_GET['previous'] == 'yes') {
if ($previous == 'yes') {
$rrd_options .= ' AREA:in' . $format . 'X#99999999' . $stacked['transparency'] . ':';
$rrd_optionsb .= ' AREA:dout' . $format . 'X#99999999' . $transparency . ':';
$rrd_options .= ' LINE1.25:in' . $format . 'X#666666:';
@ -241,7 +251,7 @@ if (! $nototal) {
$rrd_options .= ' GPRINT:inbits:AVERAGE:%6.' . $float_precision . "lf%s$units";
$rrd_options .= ' GPRINT:inbits:MAX:%6.' . $float_precision . "lf%s$units";
$rrd_options .= ' GPRINT:totin:%6.' . $float_precision . "lf%s$total_units";
if ($_GET['previous'] == 'yes') {
if ($previous == 'yes') {
$rrd_options .= " COMMENT:' \t'";
$rrd_options .= ' GPRINT:inbitsX:AVERAGE:%6.' . $float_precision . "lf%s$units";
$rrd_options .= ' GPRINT:inbitsX:MAX:%6.' . $float_precision . "lf%s$units";
@ -254,7 +264,7 @@ if (! $nototal) {
$rrd_options .= ' GPRINT:outbits:AVERAGE:%6.' . $float_precision . "lf%s$units";
$rrd_options .= ' GPRINT:outbits:MAX:%6.' . $float_precision . "lf%s$units";
$rrd_options .= ' GPRINT:totout:%6.' . $float_precision . "lf%s$total_units";
if ($_GET['previous'] == 'yes') {
if ($previous == 'yes') {
$rrd_options .= " COMMENT:' \t'";
$rrd_options .= ' GPRINT:outbitsX:AVERAGE:%6.' . $float_precision . "lf%s$units";
$rrd_options .= ' GPRINT:outbitsX:MAX:%6.' . $float_precision . "lf%s$units";
@ -267,7 +277,7 @@ if (! $nototal) {
$rrd_options .= ' GPRINT:bits:AVERAGE:%6.' . $float_precision . "lf%s$units";
$rrd_options .= ' GPRINT:bits:MAX:%6.' . $float_precision . "lf%s$units";
$rrd_options .= ' GPRINT:tot:%6.' . $float_precision . "lf%s$total_units";
if ($_GET['previous'] == 'yes') {
if ($previous == 'yes') {
$rrd_options .= " COMMENT:' \t'";
$rrd_options .= ' GPRINT:bitsX:AVERAGE:%6.' . $float_precision . "lf%s$units";
$rrd_options .= ' GPRINT:bitsX:MAX:%6.' . $float_precision . "lf%s$units";

View File

@ -2,28 +2,39 @@
require 'includes/html/graphs/common.inc.php';
$unitlen = $unitlen ?? 0;
$descr_len = $descr_len ?? 0;
$multiplier = $multiplier ?? false;
$previous = $_GET['previous'] ?? 'no';
$stack = $stack ?? '';
$seperatorX = '';
$thingX = '';
$plusX = '';
$plusesX = '';
if (! isset($descr_len)) {
$descr_len = 12;
}
if ($nototal) {
$descr_len += '2';
$unitlen += '2';
$descr_len += 2;
$unitlen += 2;
}
$rrd_options .= " COMMENT:'" . \LibreNMS\Data\Store\Rrd::fixedSafeDescr($unit_text, $descr_len) . " Now Min Max Avg\l'";
$unitlen = '10';
if ($nototal) {
$descr_len += '2';
$unitlen += '2';
$descr_len += 2;
$unitlen += 2;
}
$unit_text = str_pad(truncate($unit_text, $unitlen), $unitlen);
$colour_iter = 0;
foreach ($rrd_list as $i => $rrd) {
if ($rrd['colour']) {
if (isset($rrd['colour'])) {
$colour = $rrd['colour'];
} else {
if (! \LibreNMS\Config::get("graph_colours.$colours.$colour_iter")) {
@ -38,7 +49,7 @@ foreach ($rrd_list as $i => $rrd) {
$rrd_options .= ' DEF:' . $rrd['ds'] . $i . '=' . $rrd['filename'] . ':' . $rrd['ds'] . ':AVERAGE ';
if ($simple_rrd) {
if (isset($simple_rrd)) {
$rrd_options .= ' CDEF:' . $rrd['ds'] . $i . 'min=' . $rrd['ds'] . $i . ' ';
$rrd_options .= ' CDEF:' . $rrd['ds'] . $i . 'max=' . $rrd['ds'] . $i . ' ';
} else {
@ -46,7 +57,7 @@ foreach ($rrd_list as $i => $rrd) {
$rrd_options .= ' DEF:' . $rrd['ds'] . $i . 'max=' . $rrd['filename'] . ':' . $rrd['ds'] . ':MAX ';
}
if ($_GET['previous']) {
if ($previous) {
$rrd_options .= ' DEF:' . $i . 'X=' . $rrd['filename'] . ':' . $rrd['ds'] . ':AVERAGE:start=' . $prev_from . ':end=' . $from;
$rrd_options .= ' SHIFT:' . $i . "X:$period";
$thingX .= $seperatorX . $i . 'X,UN,0,' . $i . 'X,IF';
@ -100,7 +111,7 @@ foreach ($rrd_list as $i => $rrd) {
$rrd_options .= " COMMENT:'\\n'";
}//end foreach
if ($_GET['previous'] == 'yes') {
if ($previous == 'yes') {
if (is_numeric($multiplier)) {
$rrd_options .= ' CDEF:X=' . $thingX . $plusesX . ',' . $multiplier . ',*';
} elseif (is_numeric($divider)) {

View File

@ -11,27 +11,28 @@ foreach ($_GET as $name => $value) {
[$type, $subtype] = extract_graph_type($vars['type']);
if (is_numeric($vars['device'])) {
$device = device_by_id_cache($vars['device']);
} elseif (! empty($vars['device'])) {
$device = device_by_name($vars['device']);
if (isset($vars['device'])) {
$device = is_numeric($vars['device'])
? device_by_id_cache($vars['device'])
: device_by_name($vars['device']);
}
// FIXME -- remove these
$width = $vars['width'];
$height = $vars['height'];
$title = $vars['title'];
$vertical = $vars['vertical'];
$legend = $vars['legend'];
$title = $vars['title'] ?? '';
$vertical = $vars['vertical'] ?? '';
$legend = $vars['legend'] ?? false;
$output = (! empty($vars['output']) ? $vars['output'] : 'default');
$from = parse_at_time($_GET['from']) ?: Config::get('time.day');
$to = parse_at_time($_GET['to']) ?: Config::get('time.now');
$from = empty($_GET['from']) ? Config::get('time.day') : parse_at_time($_GET['from']);
$to = empty($_GET['to']) ? Config::get('time.now') : parse_at_time($_GET['to']);
$period = ($to - $from);
$prev_from = ($from - $period);
$graph_image_type = $vars['graph_type'] ?? Config::get('webui.graph_type');
$rrd_options = '';
$auth = false;
require Config::get('install_dir') . "/includes/html/graphs/$type/auth.inc.php";
//set default graph title

View File

@ -2,6 +2,7 @@
require 'includes/html/graphs/common.inc.php';
$unit_text = $unit_text ?? '';
$rrd_options .= ' -u 100 -l 0 -E -b 1024 ';
$iter = '1';

View File

@ -4,6 +4,13 @@
// args: ds_in, ds_out, rrd_filename, bg, legend, from, to, width, height, inverse, percentile
require 'includes/html/graphs/common.inc.php';
$multiplier = $multiplier ?? false;
$print_total = $print_total ?? false;
$percentile = $percentile ?? false;
$unit_text = $unit_text ?? '';
$line_text = $line_text ?? '';
$previous = $_GET['previous'] ?? 'no';
$unit_text = str_pad(substr($unit_text, 0, 18), 18);
$line_text = str_pad(substr($line_text, 0, 12), 12);
@ -26,7 +33,7 @@ if ($percentile) {
$rrd_options .= ' VDEF:' . $ds . '_percentile=' . $ds . ',' . $percentile . ',PERCENT';
}
if ($_GET['previous'] == 'yes') {
if ($previous == 'yes') {
if ($multiplier) {
if (empty($multiplier_action)) {
$multiplier_action = '*';
@ -83,7 +90,7 @@ if ($percentile) {
$rrd_options .= ' LINE1:' . $ds . '_percentile#aa0000';
}
if ($_GET['previous'] == 'yes') {
if ($previous == 'yes') {
$rrd_options .= ' LINE1.25:' . $ds . "X#666666:'Prev \\n'";
$rrd_options .= ' AREA:' . $ds . 'X#99999966:';
}

View File

@ -1,7 +1,7 @@
<?php
$rrd_list[1]['filename'] = $rrd_filename;
$rrd_list[1]['descr'] = $int['ifDescr'];
$rrd_list[1]['descr'] = $port['ifDescr'];
$rrd_list[1]['ds_in'] = 'INERRORS';
$rrd_list[1]['ds_out'] = 'OUTERRORS';
$rrd_list[1]['descr'] = 'Errors';
@ -9,7 +9,7 @@ $rrd_list[1]['colour_area_in'] = 'FF3300';
$rrd_list[1]['colour_area_out'] = 'FF6633';
$rrd_list[4]['filename'] = $rrd_filename;
$rrd_list[4]['descr'] = $int['ifDescr'];
$rrd_list[4]['descr'] = $port['ifDescr'];
$rrd_list[4]['ds_in'] = 'INDISCARDS';
$rrd_list[4]['ds_out'] = 'OUTDISCARDS';
$rrd_list[4]['descr'] = 'Discards';

View File

@ -3,7 +3,7 @@
$rrd_file = get_port_rrdfile_path($device['hostname'], $port['port_id']);
$rrd_list[2]['filename'] = $rrd_file;
$rrd_list[2]['descr'] = $int['ifDescr'];
$rrd_list[2]['descr'] = $port['ifDescr'];
$rrd_list[2]['ds_in'] = 'INBROADCASTPKTS';
$rrd_list[2]['ds_out'] = 'OUTBROADCASTPKTS';
$rrd_list[2]['descr'] = 'Broadcast';
@ -11,7 +11,7 @@ $rrd_list[2]['colour_area_in'] = '085F63';
$rrd_list[2]['colour_area_out'] = '49BEB7';
$rrd_list[4]['filename'] = $rrd_file;
$rrd_list[4]['descr'] = $int['ifDescr'];
$rrd_list[4]['descr'] = $port['ifDescr'];
$rrd_list[4]['ds_in'] = 'INMULTICASTPKTS';
$rrd_list[4]['ds_out'] = 'OUTMULTICASTPKTS';
$rrd_list[4]['descr'] = 'Multicast';

View File

@ -5,6 +5,8 @@ $scale_max = '100';
require 'includes/html/graphs/common.inc.php';
$previous = $_GET['previous'] ?? 'no';
$rrd_options .= ' -b 1024';
$iter = '1';
@ -32,7 +34,7 @@ $rrd_options .= ' GPRINT:size:LAST:%6.2lf%sB';
$rrd_options .= ' GPRINT:free:LAST:%6.2lf%sB';
$rrd_options .= ' GPRINT:perc:LAST:%5.2lf%%\\n';
if ($_GET['previous']) {
if ($previous) {
$descr = \LibreNMS\Data\Store\Rrd::fixedSafeDescr('Prev ' . $storage['storage_descr'], 16);
$colour = '99999999';

View File

@ -77,8 +77,8 @@ if (! empty($_POST['hostname'])) {
print_error('Unsupported SNMP Version. There was a dropdown menu, how did you reach this error ?');
}//end if
$poller_group = strip_tags($_POST['poller_group']);
$force_add = ($_POST['force_add'] == 'on');
$poller_group = strip_tags($_POST['poller_group'] ?? '');
$force_add = (isset($_POST['force_add']) && $_POST['force_add'] == 'on');
$port_assoc_mode = strip_tags($_POST['port_assoc_mode']);
try {
@ -165,12 +165,7 @@ $pagetitle[] = 'Add host';
<select name="transport" id="transport" class="form-control input-sm">
<?php
foreach (Config::get('snmp.transports') as $transport) {
echo "<option value='" . $transport . "'";
if ($transport == $device['transport']) {
echo " selected='selected'";
}
echo '>' . $transport . '</option>';
echo "<option value='" . $transport . "'>" . $transport . '</option>';
}
?>
</select>

View File

@ -58,7 +58,7 @@ if (! Auth::user()->hasGlobalAdmin()) {
print_optionbar_start();
unset($sep);
$sep = '';
foreach ($panes as $type => $text) {
if (! isset($vars['section'])) {
$vars['section'] = $type;

View File

@ -6,7 +6,7 @@ require_once 'includes/html/modal/device_maintenance.inc.php';
$device_model = Device::find($device['device_id']);
if ($_POST['editing']) {
if (! empty($_POST['editing'])) {
if (Auth::user()->hasGlobalAdmin()) {
$reload = false;
if (isset($_POST['parent_id'])) {
@ -92,7 +92,7 @@ if ($_POST['editing']) {
}
$override_sysContact_bool = get_dev_attrib($device, 'override_sysContact_bool');
$override_sysContact_string = get_dev_attrib($device, 'override_sysContact_string');
$override_sysContact_string = get_dev_attrib($device, 'override_sysContact_string') ?? '';
$disable_notify = get_dev_attrib($device, 'disable_notify');
?>
@ -135,13 +135,13 @@ $disable_notify = get_dev_attrib($device, 'disable_notify');
<div class="form-group" data-toggle="tooltip" data-container="body" data-placement="bottom" title="Display Name for this device. Keep short. Available placeholders: hostname, sysName, sysName_fallback, ip (e.g. '{{ $sysName }}')" >
<label for="edit-display-input" class="col-sm-2 control-label" >Display Name</label>
<div class="col-sm-6">
<input type="text" id="edit-display-input" name="display" class="form-control" placeholder="System Default" value="<?php echo htmlentities($device_model->display); ?>">
<input type="text" id="edit-display-input" name="display" class="form-control" placeholder="System Default" value="<?php echo htmlentities($device_model->display ?? ''); ?>">
</div>
</div>
<div class="form-group" data-toggle="tooltip" data-container="body" data-placement="bottom" title="Use this IP instead of resolved one for polling" >
<label for="edit-overwrite_ip-input" class="col-sm-2 control-label text-danger" >Overwrite IP (do not use)</label>
<div class="col-sm-6">
<input type="text" id="edit-overwrite_ip-input" name="overwrite_ip" class="form-control" value="<?php echo htmlentities($device_model->overwrite_ip); ?>">
<input type="text" id="edit-overwrite_ip-input" name="overwrite_ip" class="form-control" value="<?php echo htmlentities($device_model->overwrite_ip ?? ''); ?>">
</div>
</div>
<div class="form-group">

View File

@ -15,6 +15,7 @@ print_optionbar_start();
echo "<span style='font-weight: bold;'>Graphs</span> &#187; ";
$graph_enable = [];
foreach (dbFetchRows('SELECT * FROM device_graphs WHERE device_id = ? ORDER BY graph', [$device['device_id']]) as $graph) {
$section = \LibreNMS\Config::get("graph_types.device.{$graph['graph']}.section");
if ($section != '') {
@ -26,7 +27,7 @@ $sep = '';
foreach ($graph_enable as $section => $nothing) {
if (isset($graph_enable) && is_array($graph_enable[$section])) {
$type = strtolower($section);
if (! $vars['group']) {
if (empty($vars['group'])) {
$vars['group'] = $type;
}
@ -52,10 +53,9 @@ unset($sep);
print_optionbar_end();
$group = $vars['group'];
$graph_enable = $graph_enable[$group];
$group = $vars['group'] ?? array_key_first($graph_enable);
$graph_enable = $graph_enable[$group] ?? [];
$metric = basename($vars['metric']);
if (($group != 'customoid') && (is_file("includes/html/pages/device/graphs/$group.inc.php"))) {
include "includes/html/pages/device/graphs/$group.inc.php";
} else {

View File

@ -22,6 +22,7 @@
* @copyright 2022 Peca Nesovanovic
* @author Peca Nesovanovic <peca.nesovanovic@sattrakt.com>
*/
use App\Models\DiskIo;
use App\Models\Mempool;
use App\Models\Processor;
@ -95,11 +96,11 @@ print_optionbar_start();
echo "<span style='font-weight: bold;'>Health</span> &#187; ";
if (! $vars['metric']) {
if (empty($vars['metric'])) {
$vars['metric'] = 'overview';
}
unset($sep);
$sep = '';
foreach ($datas as $type) {
echo $sep;
if ($vars['metric'] == $type) {

View File

@ -46,7 +46,7 @@ require 'overview/storage.inc.php';
if (! isset($entity_state)) {
$entity_state = get_dev_entity_state($device['device_id']);
}
if (is_array($entity_state['group']['c6kxbar'])) {
if (! empty($entity_state['group']['c6kxbar'])) {
require 'overview/c6kxbar.inc.php';
}

View File

@ -28,8 +28,6 @@ if (count($sensors)) {
// FIXME - make this "four graphs in popup" a function/include and "small graph" a function.
// FIXME - So now we need to clean this up and move it into a function. Isn't it just "print-graphrow"?
// FIXME - DUPLICATED IN health/sensors
$graph_colour = str_replace('#', '', $row_colour);
$graph_array = [];
$graph_array['height'] = '100';
$graph_array['width'] = '210';

View File

@ -48,10 +48,10 @@ if ($mempools->isNotEmpty()) {
$percent_text = $mempool->mempool_perc;
if ($mempool->mempool_class == 'system' && $mempools->count() > 1) {
// calculate available RAM instead of Free
$buffers = $mempools->firstWhere('mempool_class', '=', 'buffers');
$cached = $mempools->firstWhere('mempool_class', '=', 'cached');
$buffers = $mempools->firstWhere('mempool_class', '=', 'buffers')->mempool_used ?? 0;
$cached = $mempools->firstWhere('mempool_class', '=', 'cached')->mempool_used ?? 0;
$available_used_all = Number::calculatePercent($mempool->mempool_used + $buffers->mempool_used + $cached->mempool_used, $mempool->mempool_total, 0);
$available_used_all = Number::calculatePercent($mempool->mempool_used + $buffers + $cached, $mempool->mempool_total, 0);
}
$total = Number::formatBi($mempool->mempool_total);

View File

@ -11,7 +11,7 @@ if (\LibreNMS\Config::get('enable_syslog')) {
echo ' </div>
<table class="table table-hover table-condensed table-striped">';
foreach ($syslog as $entry) {
unset($syslog_output);
$syslog_output = '';
include 'includes/html/print-syslog.inc.php';
echo $syslog_output;
}

View File

@ -26,7 +26,7 @@
use App\Models\DevicePerf;
$perf_info = DevicePerf::where('device_id', $device['device_id'])->latest('timestamp')->first();
if ($perf_info['debug']['traceroute']) {
if (! empty($perf_info['debug']['traceroute'])) {
echo "
<div class='row'>
<div class='col-md-12'>

View File

@ -6,7 +6,7 @@ $i = 0;
foreach (dbFetchRows('SELECT * FROM `packages` WHERE `device_id` = ? ORDER BY `name`', [$device['device_id']]) as $entry) {
echo '<tr class="list">';
echo '<td width=200><a href="' . \LibreNMS\Util\Url::generate($vars, ['name' => $entry['name']]) . '">' . $entry['name'] . '</a></td>';
if ($build != '') {
if (! empty($entry['build'])) {
$dbuild = '-' . $entry['build'];
} else {
$dbuild = '';

View File

@ -6,32 +6,31 @@ use LibreNMS\Util\Url;
$vars['view'] = basename($vars['view'] ?? 'graphs');
$port = dbFetchRow('SELECT * FROM `ports` WHERE `port_id` = ?', [$vars['port']]);
$port = \App\Models\Port::find($vars['port']);
$port_details = 1;
$hostname = $device['hostname'];
$hostid = $device['port_id'];
$ifname = $port['ifDescr'];
$ifIndex = $port['ifIndex'];
$speed = \LibreNMS\Util\Number::formatSi($port['ifSpeed'], 2, 3, 'bps');
$ifname = $port->ifDescr;
$ifIndex = $port->ifIndex;
$speed = \LibreNMS\Util\Number::formatSi($port->ifSpeed, 2, 3, 'bps');
$ifalias = $port['name'];
$ifalias = $port->getLabel();
if ($port['ifPhysAddress']) {
$mac = "$port[ifPhysAddress]";
if ($port->ifPhysAddress) {
$mac = $port->ifPhysAddress;
}
$color = 'black';
if ($port['ifAdminStatus'] == 'down') {
if ($port->ifAdminStatus == 'down') {
$status = "<span class='grey'>Disabled</span>";
}
if ($port['ifAdminStatus'] == 'up' && $port['ifOperStatus'] != 'up') {
if ($port->ifAdminStatus == 'up' && $port->ifOperStatus != 'up') {
$status = "<span class='red'>Enabled / Disconnected</span>";
}
if ($port['ifAdminStatus'] == 'up' && $port['ifOperStatus'] == 'up') {
if ($port->ifAdminStatus == 'up' && $port->ifOperStatus == 'up') {
$status = "<span class='green'>Enabled / Connected</span>";
}
@ -67,7 +66,7 @@ $link_array = [
'page' => 'device',
'device' => $device['device_id'],
'tab' => 'port',
'port' => $port['port_id'],
'port' => $port->port_id,
];
$menu_options['graphs'] = 'Graphs';
@ -78,19 +77,19 @@ $menu_options['fdb'] = 'FDB Table';
$menu_options['events'] = 'Eventlog';
$menu_options['notes'] = 'Notes';
if (dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ? AND `entPhysicalIndex` = ? AND entPhysicalIndex_measured = 'ports'", [$device['device_id'], $port['ifIndex']])) {
if (dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ? AND `entPhysicalIndex` = ? AND entPhysicalIndex_measured = 'ports'", [$device['device_id'], $port->ifIndex])) {
$menu_options['sensors'] = 'Health';
}
if (dbFetchCell("SELECT COUNT(*) FROM `ports_adsl` WHERE `port_id` = '" . $port['port_id'] . "'")) {
if (dbFetchCell("SELECT COUNT(*) FROM `ports_adsl` WHERE `port_id` = '" . $port->port_id . "'")) {
$menu_options['adsl'] = 'ADSL';
}
if (dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `pagpGroupIfIndex` = '" . $port['ifIndex'] . "' and `device_id` = '" . $device['device_id'] . "'")) {
if (dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `pagpGroupIfIndex` = '" . $port->ifIndex . "' and `device_id` = '" . $device['device_id'] . "'")) {
$menu_options['pagp'] = 'PAgP';
}
if (dbFetchCell("SELECT COUNT(*) FROM `ports_vlans` WHERE `port_id` = '" . $port['port_id'] . "' and `device_id` = '" . $device['device_id'] . "'")) {
if (dbFetchCell("SELECT COUNT(*) FROM `ports_vlans` WHERE `port_id` = '" . $port->port_id . "' and `device_id` = '" . $device['device_id'] . "'")) {
$menu_options['vlans'] = 'VLANs';
}
@ -104,7 +103,7 @@ if (count($components) > 0) {
$menu_options['cbqos'] = 'CBQoS';
}
$portModel = \App\Models\Port::find($port['port_id']);
$portModel = \App\Models\Port::find($port->port_id);
if (LibreNMS\Plugins::countHooks('port_container') || \PluginManager::hasHooks(PortTabHook::class, ['port' => $portModel])) {
// Checking if any plugin implements the port_container. If yes, allow to display the menu_option
@ -128,7 +127,7 @@ foreach ($menu_options as $option => $text) {
unset($sep);
if (dbFetchCell("SELECT count(*) FROM mac_accounting WHERE port_id = '" . $port['port_id'] . "'") > '0') {
if (dbFetchCell("SELECT count(*) FROM mac_accounting WHERE port_id = '" . $port->port_id . "'") > '0') {
echo generate_link($descr, $link_array, ['view' => 'macaccounting', 'graph' => $type]);
echo ' | Mac Accounting : ';
@ -196,7 +195,7 @@ if (dbFetchCell("SELECT count(*) FROM mac_accounting WHERE port_id = '" . $port[
echo ')';
}//end if
if (dbFetchCell("SELECT COUNT(*) FROM juniAtmVp WHERE port_id = '" . $port['port_id'] . "'") > '0') {
if (dbFetchCell("SELECT COUNT(*) FROM juniAtmVp WHERE port_id = '" . $port->port_id . "'") > '0') {
// FIXME ATM VPs
// FIXME URLs BROKEN
echo ' | ATM VPs : ';
@ -204,7 +203,7 @@ if (dbFetchCell("SELECT COUNT(*) FROM juniAtmVp WHERE port_id = '" . $port['port
echo "<span class='pagemenu-selected'>";
}
echo "<a href='" . Url::generate(['page' => 'device', 'device' => $device['device_id'], 'tab' => 'port', 'port' => $port['port_id']]) . "/junose-atm-vp/bits/'>Bits</a>";
echo "<a href='" . Url::generate(['page' => 'device', 'device' => $device['device_id'], 'tab' => 'port', 'port' => $port->port_id]) . "/junose-atm-vp/bits/'>Bits</a>";
if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') {
echo '</span>';
}
@ -214,7 +213,7 @@ if (dbFetchCell("SELECT COUNT(*) FROM juniAtmVp WHERE port_id = '" . $port['port
echo "<span class='pagemenu-selected'>";
}
echo "<a href='" . Url::generate(['page' => 'device', 'device' => $device['device_id'], 'tab' => 'port', 'port' => $port['port_id']]) . "/junose-atm-vp/packets/'>Packets</a>";
echo "<a href='" . Url::generate(['page' => 'device', 'device' => $device['device_id'], 'tab' => 'port', 'port' => $port->port_id]) . "/junose-atm-vp/packets/'>Packets</a>";
if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') {
echo '</span>';
}
@ -224,7 +223,7 @@ if (dbFetchCell("SELECT COUNT(*) FROM juniAtmVp WHERE port_id = '" . $port['port
echo "<span class='pagemenu-selected'>";
}
echo "<a href='" . Url::generate(['page' => 'device', 'device' => $device['device_id'], 'tab' => 'port', 'port' => $port['port_id']]) . "/junose-atm-vp/cells/'>Cells</a>";
echo "<a href='" . Url::generate(['page' => 'device', 'device' => $device['device_id'], 'tab' => 'port', 'port' => $port->port_id]) . "/junose-atm-vp/cells/'>Cells</a>";
if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') {
echo '</span>';
}
@ -234,20 +233,20 @@ if (dbFetchCell("SELECT COUNT(*) FROM juniAtmVp WHERE port_id = '" . $port['port
echo "<span class='pagemenu-selected'>";
}
echo "<a href='" . Url::generate(['page' => 'device', 'device' => $device['device_id'], 'tab' => 'port', 'port' => $port['port_id']]) . "/junose-atm-vp/errors/'>Errors</a>";
echo "<a href='" . Url::generate(['page' => 'device', 'device' => $device['device_id'], 'tab' => 'port', 'port' => $port->port_id]) . "/junose-atm-vp/errors/'>Errors</a>";
if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') {
echo '</span>';
}
}//end if
if (Auth::user()->hasGlobalAdmin() && \LibreNMS\Config::get('enable_billing') == 1) {
$bills = dbFetchRows('SELECT `bill_id` FROM `bill_ports` WHERE `port_id`=?', [$port['port_id']]);
$bills = dbFetchRows('SELECT `bill_id` FROM `bill_ports` WHERE `port_id`=?', [$port->port_id]);
if (count($bills) === 1) {
echo "<span style='float: right;'><a href='" . Url::generate(['page' => 'bill', 'bill_id' => $bills[0]['bill_id']]) . "'><i class='fa fa-money fa-lg icon-theme' aria-hidden='true'></i> View Bill</a></span>";
} elseif (count($bills) > 1) {
echo "<span style='float: right;'><a href='" . Url::generate(['page' => 'bills']) . "'><i class='fa fa-money fa-lg icon-theme' aria-hidden='true'></i> View Bills</a></span>";
} else {
echo "<span style='float: right;'><a href='" . Url::generate(['page' => 'bills', 'view' => 'add', 'port' => $port['port_id']]) . "'><i class='fa fa-money fa-lg icon-theme' aria-hidden='true'></i> Create Bill</a></span>";
echo "<span style='float: right;'><a href='" . Url::generate(['page' => 'bills', 'view' => 'add', 'port' => $port->port_id]) . "'><i class='fa fa-money fa-lg icon-theme' aria-hidden='true'></i> Create Bill</a></span>";
}
}

View File

@ -1,7 +1,6 @@
<?php
if (file_exists(get_port_rrdfile_path($device['hostname'], $port['port_id'], 'adsl'))) {
$iid = $id;
echo '<div class=graphhead>ADSL Current Line Speed</div>';
$graph_type = 'port_adsl_speed';

View File

@ -1,7 +1,6 @@
<?php
if (Rrd::checkRrdExists(get_port_rrdfile_path($device['hostname'], $port['port_id']))) {
$iid = $id;
echo '<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Interface Traffic</h3>

View File

@ -202,7 +202,7 @@ if ($vars['subview'] == 'top10') {
$graph_array['height'] = '100';
$graph_array['width'] = '216';
$graph_array['to'] = Config::get('time.now');
echo '<tr bgcolor="' . $bg_colour . '"' . ($bg_image ? ' background="' . $bg_image . '"' : '') . '"><td colspan="7">';
echo '<tr bgcolor="' . $bg_colour . '"><td colspan="7">';
include 'includes/html/print-graphrow.inc.php';

View File

@ -12,7 +12,7 @@
$pagetitle[] = 'Notes';
$port_id_notes = 'port_id_notes:' . $port['port_id'];
$device_id = $device['device_id'];
$data = get_dev_attrib($device, $port_id_notes);
$data = get_dev_attrib($device, $port_id_notes) ?? '';
?>
<form class="form-horizontal" action="" method="post">

View File

@ -15,8 +15,9 @@ print_optionbar_start();
echo 'Polling Interval: ';
$sep = '';
foreach ([0.25, 1, 2, 5, 15, 60] as $interval) {
echo $thinger;
echo $sep;
if ($vars['interval'] == $interval) {
echo "<span class='pagemenu-selected'>";
}
@ -26,7 +27,7 @@ foreach ([0.25, 1, 2, 5, 15, 60] as $interval) {
echo '</span>';
}
$thinger = ' | ';
$sep = ' | ';
}
print_optionbar_end();

View File

@ -4,6 +4,10 @@ use App\Models\Port;
use LibreNMS\Config;
use LibreNMS\Util\Url;
if (empty($vars['view'])) {
$vars['view'] = trim(Config::get('ports_page_default'), '/');
}
if ($vars['view'] == 'graphs' || $vars['view'] == 'minigraphs') {
if (isset($vars['graph'])) {
$graph_type = 'port_' . $vars['graph'];
@ -12,10 +16,6 @@ if ($vars['view'] == 'graphs' || $vars['view'] == 'minigraphs') {
}
}
if (! $vars['view']) {
$vars['view'] = trim(Config::get('ports_page_default'), '/');
}
$link_array = [
'page' => 'device',
'device' => $device['device_id'],
@ -67,8 +67,10 @@ if (Config::get('enable_ports_etherlike')) {
$graph_types['etherlike'] = 'Etherlike';
}
$type_sep = '';
$vars['graph'] = $vars['graph'] ?? '';
foreach ($graph_types as $type => $descr) {
echo "$type_sep";
echo $type_sep;
if ($vars['graph'] == $type && $vars['view'] == 'graphs') {
echo "<span class='pagemenu-selected'>";
}
@ -154,7 +156,7 @@ if ($vars['view'] == 'minigraphs') {
$ports[$key]['ifOctets_rate'] = $port['ifInOctets_rate'] + $port['ifOutOctets_rate'];
}
switch ($vars['sort']) {
switch ($vars['sort'] ?? '') {
case 'traffic':
$ports = array_sort_by_column($ports, 'ifOctets_rate', SORT_DESC);
break;
@ -165,7 +167,6 @@ if ($vars['view'] == 'minigraphs') {
foreach ($ports as $port) {
include 'includes/html/print-interface.inc.php';
$i++;
}
echo '</table></div>';

View File

@ -31,9 +31,9 @@ $pagetitle[] = 'Routing';
echo "<span style='font-weight: bold;'>Routing</span> &#187; ";
unset($sep);
$sep = '';
foreach ($routing_tabs as $type => $type_count) {
if (! $vars['proto']) {
if (empty($vars['proto'])) {
$vars['proto'] = $type;
}

View File

@ -2,6 +2,7 @@
use LibreNMS\Util\IP;
$extra_sql = '';
$link_array = [
'page' => 'device',
'device' => $device['device_id'],
@ -116,14 +117,13 @@ $i = '1';
foreach (dbFetchRows("SELECT * FROM `bgpPeers` WHERE `device_id` = ? $extra_sql ORDER BY `bgpPeerRemoteAs`, `bgpPeerIdentifier`", [$device['device_id']]) as $peer) {
$has_macaccounting = dbFetchCell('SELECT COUNT(*) FROM `ipv4_mac` AS I, mac_accounting AS M WHERE I.ipv4_address = ? AND M.mac = I.mac_address', [$peer['bgpPeerIdentifier']]);
unset($bg_image);
if (! is_integer($i / 2)) {
$bg_colour = \LibreNMS\Config::get('list_colour.even');
} else {
$bg_colour = \LibreNMS\Config::get('list_colour.odd');
}
unset($alert, $bg_image);
unset($alert);
unset($peerhost, $peername);
if (! is_integer($i / 2)) {
@ -171,7 +171,7 @@ foreach (dbFetchRows("SELECT * FROM `bgpPeers` WHERE `device_id` = ? $extra_sql
} elseif ($ipv6_host) {
$peerhost = $ipv6_host;
} else {
unset($peerhost);
$peerhost = null;
}
if (is_array($peerhost)) {
@ -191,20 +191,18 @@ foreach (dbFetchRows("SELECT * FROM `bgpPeers` WHERE `device_id` = ? $extra_sql
}
unset($peer_af);
unset($sep);
$sep = '';
foreach (dbFetchRows('SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?', [$device['device_id'], $peer['bgpPeerIdentifier']]) as $afisafi) {
$afi = $afisafi['afi'];
$safi = $afisafi['safi'];
$this_afisafi = $afi . $safi;
$peer['afi'] .= $sep . $afi . '.' . $safi;
$peer['afi'] = $sep . $afi . '.' . $safi;
$sep = '<br />';
$peer['afisafi'][$this_afisafi] = 1;
// Build a list of valid AFI/SAFI for this peer
}
unset($sep);
// make ipv6 look pretty
$peer['bgpPeerIdentifier'] = (string) IP::parse($peer['bgpPeerIdentifier'], true);
@ -215,7 +213,9 @@ foreach (dbFetchRows("SELECT * FROM `bgpPeers` WHERE `device_id` = ? $extra_sql
$graph_array['to'] = \LibreNMS\Config::get('time.now');
$graph_array['from'] = \LibreNMS\Config::get('time.day');
$graph_array['height'] = '110';
$graph_array['width'] = $width;
if (isset($width)) {
$graph_array['width'] = $width;
}
// Peer Address
$graph_array_zoom = $graph_array;
@ -235,11 +235,11 @@ foreach (dbFetchRows("SELECT * FROM `bgpPeers` WHERE `device_id` = ? $extra_sql
$last_error = describe_bgp_error_code($peer['bgpPeerLastErrorCode'], $peer['bgpPeerLastErrorSubCode']) . '<br/>' . $peer['bgpPeerLastErrorText'];
}
echo '<tr bgcolor="' . $bg_colour . '"' . ($peer['alert'] ? ' bordercolor="#cc0000"' : '') . ($peer['disabled'] ? ' bordercolor="#cccccc"' : '') . '>
echo '<tr bgcolor="' . $bg_colour . '"' . (empty($peer['alert']) ? '' : ' bordercolor="#cc0000"') . (empty($peer['disabled']) ? '' : ' bordercolor="#cccccc"') . '>
';
echo '
<td>' . $peeraddresslink . '<br />' . $peername . "</td>
<td>' . $peeraddresslink . '<br />' . ($peername ?? '') . "</td>
<td>$peer_type</td>
<td style='font-size: 10px; font-weight: bold; line-height: 10px;'>" . (isset($peer['afi']) ? $peer['afi'] : '') . '</td>
<td><strong>AS' . $peer['bgpPeerRemoteAs'] . '</strong><br />' . $peer['astext'] . '</td>
@ -287,11 +287,11 @@ foreach (dbFetchRows("SELECT * FROM `bgpPeers` WHERE `device_id` = ? $extra_sql
$peer['graph'] = 1;
}
if ($peer['graph']) {
if (! empty($peer['graph'])) {
$graph_array['height'] = '100';
$graph_array['width'] = '216';
$graph_array['to'] = \LibreNMS\Config::get('time.now');
echo '<tr bgcolor="' . $bg_colour . '"' . ($bg_image ? ' background="' . $bg_image . '"' : '') . '"><td colspan="7">';
echo '<tr bgcolor="' . $bg_colour . '"><td colspan="7">';
include 'includes/html/print-graphrow.inc.php';

View File

@ -74,8 +74,8 @@ foreach (get_graph_subtypes($type) as $avail_type) {
$headeroptions .= '<option value="' .
\LibreNMS\Util\Url::generate($vars, [
'format' => 'graph_' . $avail_type,
'from' => $vars['from'] ?: \LibreNMS\Config::get('time.day'),
'to' => $vars['to'] ?: \LibreNMS\Config::get('time.now'),
'from' => $vars['from'] ?? \LibreNMS\Config::get('time.day'),
'to' => $vars['to'] ?? \LibreNMS\Config::get('time.now'),
]) . '" ' . $is_selected . '>' . $display_type . '</option>';
}
$headeroptions .= '</select>';
@ -345,34 +345,34 @@ if ($format == 'graph') {
post: function () {
return {
format: ' <?php echo $vars['format']; ?>',
searchPhrase: '<?php echo htmlspecialchars($vars['searchquery']); ?>',
os: '<?php echo $vars['os']; ?>',
version: '<?php echo $vars['version']; ?>',
hardware: '<?php echo $vars['hardware']; ?>',
features: '<?php echo $vars['features']; ?>',
location: '<?php echo $vars['location']; ?>',
type: '<?php echo $vars['type']; ?>',
state: '<?php echo $vars['state']; ?>',
disabled: '<?php echo $vars['disabled']; ?>',
ignore: '<?php echo $vars['ignore']; ?>',
disable_notify: '<?php echo $vars['disable_notify']; ?>',
group: '<?php echo $vars['group']; ?>',
poller_group: '<?php echo $vars['poller_group']; ?>',
device_id: '<?php echo $vars['device_id']; ?>',
searchPhrase: '<?php echo htmlspecialchars($vars['searchquery'] ?? ''); ?>',
os: '<?php echo $vars['os'] ?? ''; ?>',
version: '<?php echo $vars['version'] ?? ''; ?>',
hardware: '<?php echo $vars['hardware'] ?? ''; ?>',
features: '<?php echo $vars['features'] ?? ''; ?>',
location: '<?php echo $vars['location'] ?? ''; ?>',
type: '<?php echo $vars['type'] ?? ''; ?>',
state: '<?php echo $vars['state'] ?? ''; ?>',
disabled: '<?php echo $vars['disabled'] ?? ''; ?>',
ignore: '<?php echo $vars['ignore'] ?? ''; ?>',
disable_notify: '<?php echo $vars['disable_notify'] ?? ''; ?>',
group: '<?php echo $vars['group'] ?? ''; ?>',
poller_group: '<?php echo $vars['poller_group'] ?? ''; ?>',
device_id: '<?php echo $vars['device_id'] ?? ''; ?>',
};
},
url: "<?php echo url('/ajax/table/device') ?>"
});
<?php
if (! isset($vars['searchbar']) && $vars['searchbar'] != 'hide') {
if (empty($vars['searchbar']) || $vars['searchbar'] != 'hide') {
?>
$(".devices-headers-table-menu").append(
"<div class='pull-left'>" +
"<form method='post' action='' class='form-inline devices-search-header' role='form'>" +
"<?php echo addslashes(csrf_field()) ?>"+
"<div class='form-group'>" +
"<input type='text' name='searchquery' id='searchquery' value=''<?php echo $vars['searchquery']; ?>'' class='form-control' placeholder='Search'>" +
"<input type='text' name='searchquery' id='searchquery' value=''<?php echo $vars['searchquery'] ?? ''; ?>'' class='form-control' placeholder='Search'>" +
"</div>" +
"<div class='form-group'><?php echo $state_selection ?></div>" +
"<div class='form-group'><select name='os' id='os' class='form-control'></select></div>" +
@ -383,7 +383,7 @@ if ($format == 'graph') {
"<div class='form-group'><select name='type' id='device-type' class='form-control'></select></div>" +
"<input type='submit' class='btn btn-info' value='Search'>" +
"<a href='<?php echo \LibreNMS\Util\Url::generate(array_diff_key($vars, ['_token' => 1])) ?>' title='Update the browser URL to reflect the search criteria.' class='btn btn-default'>Update URL</a>" +
"<a href='<?php echo \LibreNMS\Util\Url::generate(['page' => 'devices', 'section' => $vars['section'], 'bare' => $vars['bare']]) ?>' title='Reset criteria to default.' class='btn btn-default'>Reset</a>" +
"<a href='<?php echo \LibreNMS\Util\Url::generate(['page' => 'devices', 'section' => $vars['section'] ?? '', 'bare' => $vars['bare'] ?? '']) ?>' title='Reset criteria to default.' class='btn btn-default'>Reset</a>" +
"</form>" +
"</div>"
);

View File

@ -14,21 +14,22 @@ if (session('widescreen')) {
$thumb_width = 113;
}
$vars['from'] = parse_at_time($vars['from']) ?: Config::get('time.day');
$vars['to'] = parse_at_time($vars['to']) ?: Config::get('time.now');
$vars['from'] = parse_at_time($vars['from'] ?? '') ?: Config::get('time.day');
$vars['to'] = parse_at_time($vars['to'] ?? '') ?: Config::get('time.now');
preg_match('/^(?P<type>[A-Za-z0-9]+)_(?P<subtype>.+)/', $vars['type'], $graphtype);
$type = basename($graphtype['type']);
$subtype = basename($graphtype['subtype']);
$id = $vars['id'];
$id = $vars['id'] ?? null;
if (is_numeric($vars['device'])) {
$device = device_by_id_cache($vars['device']);
} elseif (! empty($vars['device'])) {
$device = device_by_name($vars['device']);
if (isset($vars['device'])) {
$device = is_numeric($vars['device'])
? device_by_id_cache($vars['device'])
: device_by_name($vars['device']);
}
$auth = false;
if (is_file('includes/html/graphs/' . $type . '/auth.inc.php')) {
require 'includes/html/graphs/' . $type . '/auth.inc.php';
}
@ -128,7 +129,7 @@ if (! $auth) {
echo '<div style="padding-top: 5px";></div>';
echo '<center>';
if ($vars['legend'] == 'no') {
if (isset($vars['legend']) && $vars['legend'] == 'no') {
echo generate_link('Show Legend', $vars, ['page' => 'graphs', 'legend' => null]);
} else {
echo generate_link('Hide Legend', $vars, ['page' => 'graphs', 'legend' => 'no']);
@ -138,7 +139,7 @@ if (! $auth) {
// if ($type == "port" && $subtype == "bits")
// {
echo ' | ';
if ($vars['previous'] == 'yes') {
if (isset($vars['previous']) && $vars['previous'] == 'yes') {
echo generate_link('Hide Previous', $vars, ['page' => 'graphs', 'previous' => null]);
} else {
echo generate_link('Show Previous', $vars, ['page' => 'graphs', 'previous' => 'yes']);
@ -146,7 +147,7 @@ if (! $auth) {
// }
echo ' | ';
if ($vars['showcommand'] == 'yes') {
if (isset($vars['showcommand']) && $vars['showcommand'] == 'yes') {
echo generate_link('Hide RRD Command', $vars, ['page' => 'graphs', 'showcommand' => null]);
} else {
echo generate_link('Show RRD Command', $vars, ['page' => 'graphs', 'showcommand' => 'yes']);
@ -186,7 +187,7 @@ if (! $auth) {
print_optionbar_end();
}
if ($vars['showcommand']) {
if (! empty($vars['showcommand'])) {
$_GET = $graph_array;
$command_only = 1;

View File

@ -100,11 +100,7 @@ if ((isset($vars['searchbar']) && $vars['searchbar'] != 'hide') || ! isset($vars
$results = dbFetchRows('SELECT `D`.`device_id`,`D`.`hostname`, `D`.`sysname` FROM `devices` AS `D`, `devices_perms` AS `P` WHERE `P`.`user_id` = ? AND `P`.`device_id` = `D`.`device_id` ORDER BY `hostname`', [Auth::id()]);
}
foreach ($results as $data) {
if ($data['device_id'] == $vars['device_id']) {
$deviceselected = 'selected';
} else {
$deviceselected = '';
}
$deviceselected = isset($vars['device_id']) && $data['device_id'] == $vars['device_id'] ? 'selected' : '';
$ui_device = strlen(format_hostname($data)) > 15 ? substr(format_hostname($data), 0, 15) . '...' : format_hostname($data);
$output .= "<option value='" . $data['device_id'] . "' " . $deviceselected . '>' . $ui_device . '</option>';
}
@ -126,17 +122,13 @@ if ((isset($vars['searchbar']) && $vars['searchbar'] != 'hide') || ! isset($vars
$output .= '</select>&nbsp;';
if (strlen($vars['hostname'])) {
$hasvalue = "value='" . $vars['hostname'] . "'";
} else {
$hasvalue = '';
}
$hasvalue = ! empty($vars['hostname']) ? "value='" . $vars['hostname'] . "'" : '';
$output .= "<input type='text' name='hostname' id='hostname' title='Hostname' class='form-control input-sm' " . $hasvalue . " placeholder='Hostname'>";
$output .= '</div>&nbsp;';
switch ($vars['state']) {
switch ($vars['state'] ?? '') {
case 'up':
$isup = 'selected';
$isdown = '';
@ -152,6 +144,10 @@ if ((isset($vars['searchbar']) && $vars['searchbar'] != 'hide') || ! isset($vars
$isdown = '';
$admindown = 'selected';
break;
default:
$isup = '';
$isdown = '';
$admindown = '';
}
$output .= "<div class='form-group'>";
@ -173,11 +169,7 @@ if ((isset($vars['searchbar']) && $vars['searchbar'] != 'hide') || ! isset($vars
foreach ($ifSpeed as $data) {
if ($data['ifSpeed']) {
if ($data['ifSpeed'] == $vars['ifSpeed']) {
$speedselected = 'selected';
} else {
$speedselected = '';
}
$speedselected = isset($vars['ifSpeed']) && $data['ifSpeed'] == $vars['ifSpeed'] ? 'selected' : '';
$output .= "<option value='" . $data['ifSpeed'] . "'" . $speedselected . '>' . \LibreNMS\Util\Number::formatSi($data['ifSpeed'], 2, 3, 'bps') . '</option>';
}
}
@ -196,11 +188,7 @@ if ((isset($vars['searchbar']) && $vars['searchbar'] != 'hide') || ! isset($vars
foreach ($ifType as $data) {
if ($data['ifType']) {
if ($data['ifType'] == $vars['ifType']) {
$dataselected = 'selected';
} else {
$dataselected = '';
}
$dataselected = isset($vars['ifType']) && $data['ifType'] == $vars['ifType'] ? 'selected' : '';
$output .= "<option value='" . clean_bootgrid($data['ifType']) . "' " . $dataselected . '>' . clean_bootgrid($data['ifType']) . '</option>';
}
}
@ -223,7 +211,7 @@ if ((isset($vars['searchbar']) && $vars['searchbar'] != 'hide') || ! isset($vars
foreach ($port_descr_type as $data) {
if ($data['port_descr_type']) {
if ($data['port_descr_type'] == $vars['port_descr_type']) {
if (isset($vars['port_descr_type']) && $data['port_descr_type'] == $vars['port_descr_type']) {
$portdescrib = 'selected';
} else {
$portdescrib = '';
@ -236,9 +224,7 @@ if ((isset($vars['searchbar']) && $vars['searchbar'] != 'hide') || ! isset($vars
$output .= '</div>';
$output .= "<div class='form-group'>";
if (strlen($vars['ifAlias'])) {
$ifaliasvalue = "value='" . $vars['ifAlias'] . "'";
}
$ifaliasvalue = isset($vars['ifAlias']) ? "value='" . $vars['ifAlias'] . "'" : '';
$output .= '</div>';
@ -253,7 +239,7 @@ if ((isset($vars['searchbar']) && $vars['searchbar'] != 'hide') || ! isset($vars
$location = $location_row['location'];
$location_id = $location_row['id'];
if ($location) {
if ($location_id == $vars['location']) {
if (isset($vars['location']) && $location_id == $vars['location']) {
$locationselected = 'selected';
} else {
$locationselected = '';
@ -265,23 +251,9 @@ if ((isset($vars['searchbar']) && $vars['searchbar'] != 'hide') || ! isset($vars
$output .= '</select>&nbsp;';
if ($vars['ignore']) {
$ignorecheck = 'checked';
} else {
$ignorecheck = '';
}
if ($vars['disabled']) {
$disabledcheck = 'checked';
} else {
$disabledcheck = '';
}
if ($vars['deleted']) {
$deletedcheck = 'checked';
} else {
$deletedcheck = '';
}
$ignorecheck = isset($vars['ignore']) ? 'checked' : '';
$disabledcheck = isset($vars['disabled']) ? 'checked' : '';
$deletedcheck = isset($vars['deleted']) ? 'checked' : '';
$output .= "<label for='ignore'>Ignored</label>&nbsp;";
$output .= "<input type='checkbox' id='ignore' name='ignore' value='1' " . $ignorecheck . '>&nbsp;';
@ -291,7 +263,7 @@ if ((isset($vars['searchbar']) && $vars['searchbar'] != 'hide') || ! isset($vars
$output .= "<input type='checkbox' id='deleted' name='deleted' value='1' " . $deletedcheck . '>&nbsp;';
$output .= "<button type='submit' class='btn btn-default btn-sm'>Search</button>&nbsp;";
$output .= "<a class='btn btn-default btn-sm' href='" . \LibreNMS\Util\Url::generate(['page' => 'ports', 'section' => $vars['section'], 'bare' => $vars['bare']]) . "' title='Reset critera to default.'>Reset</a>";
$output .= "<a class='btn btn-default btn-sm' href='" . \LibreNMS\Util\Url::generate(['page' => 'ports', 'section' => $vars['section'] ?? '', 'bare' => $vars['bare'] ?? '']) . "' title='Reset critera to default.'>Reset</a>";
$output .= '</div>';
@ -416,7 +388,7 @@ if ($ignore_filter == 0 && $disabled_filter == 0) {
$where .= ' AND `I`.`ignore` = 0 AND `I`.`disabled` = 0 AND `I`.`deleted` = 0';
}
$query = 'SELECT * FROM `ports` AS I, `devices` AS D LEFT JOIN `locations` AS L ON D.location_id = L.id WHERE I.device_id = D.device_id' . $where . ' ' . $query_sort;
$query = 'SELECT * FROM `ports` AS I, `devices` AS D LEFT JOIN `locations` AS L ON D.location_id = L.id WHERE I.device_id = D.device_id' . $where;
$row = 1;
[$format, $subformat] = explode('_', basename($vars['format']));
@ -424,7 +396,7 @@ $row = 1;
// only grab list of ports for graph pages, table uses ajax
$ports = $format == 'graph' ? dbFetchRows($query, $param) : [];
switch ($vars['sort']) {
switch ($vars['sort'] ?? '') {
case 'traffic':
$ports = array_sort_by_column($ports, 'ifOctets_rate', SORT_DESC);
break;

View File

@ -13,14 +13,14 @@ foreach ($ports as $port) {
$port['in_rate'] = \LibreNMS\Util\Number::formatSi(($port['ifInOctets_rate'] * 8), 2, 3, 'bps');
$port['out_rate'] = \LibreNMS\Util\Number::formatSi(($port['ifOutOctets_rate'] * 8), 2, 3, 'bps');
if ($port['in_errors'] > 0 || $port['out_errors'] > 0) {
if ($port['ifInErrors_delta'] > 0 || $port['ifOutErrors_delta'] > 0) {
$error_img = generate_port_link($port, "<i class='fa fa-flag fa-lg' style='color:red' aria-hidden='true'></i>", 'errors');
} else {
$error_img = '';
}
if (port_permitted($port['port_id'], $port['device_id'])) {
$port = cleanPort($port, $device);
$port = cleanPort($port, $device ?? null);
$graph_type = 'port_' . $subformat;

View File

@ -14,10 +14,10 @@
*/
$details_visible = var_export($vars['format'] == 'list_detail', 1);
$errors_visible = var_export($vars['format'] == 'list_detail' || $vars['errors'], 1);
$errors_visible = var_export($vars['format'] == 'list_detail' || isset($vars['errors']), 1);
$no_refresh = true;
if ($vars['errors']) {
if (isset($vars['errors'])) {
$error_sort = ' data-order="desc"';
$sort = '';
} else {
@ -109,20 +109,20 @@ var grid = $("#ports").bootgrid({
post: function ()
{
return {
device_id: '<?php echo $vars['device_id']; ?>',
hostname: '<?php echo htmlspecialchars($vars['hostname']); ?>',
state: '<?php echo $vars['state']; ?>',
ifSpeed: '<?php echo $vars['ifSpeed']; ?>',
ifType: '<?php echo $vars['ifType']; ?>',
port_descr_type: '<?php echo $vars['port_descr_type']; ?>',
ifAlias: '<?php echo $vars['ifAlias']; ?>',
location: '<?php echo $vars['location']; ?>',
disabled: '<?php echo $vars['disabled']; ?>',
ignore: '<?php echo $vars['ignore']; ?>',
deleted: '<?php echo $vars['deleted']; ?>',
errors: '<?php echo $vars['errors']; ?>',
group: '<?php echo $vars['group']; ?>',
devicegroup: '<?php echo $vars['devicegroup']; ?>',
device_id: '<?php echo $vars['device_id'] ?? ''; ?>',
hostname: '<?php echo htmlspecialchars($vars['hostname'] ?? ''); ?>',
state: '<?php echo $vars['state'] ?? ''; ?>',
ifSpeed: '<?php echo $vars['ifSpeed'] ?? ''; ?>',
ifType: '<?php echo $vars['ifType'] ?? ''; ?>',
port_descr_type: '<?php echo $vars['port_descr_type'] ?? ''; ?>',
ifAlias: '<?php echo $vars['ifAlias'] ?? ''; ?>',
location: '<?php echo $vars['location'] ?? ''; ?>',
disabled: '<?php echo $vars['disabled'] ?? ''; ?>',
ignore: '<?php echo $vars['ignore'] ?? ''; ?>',
deleted: '<?php echo $vars['deleted'] ?? ''; ?>',
errors: '<?php echo $vars['errors'] ?? ''; ?>',
group: '<?php echo $vars['group'] ?? ''; ?>',
devicegroup: '<?php echo $vars['devicegroup'] ?? ''; ?>',
};
},
url: '<?php echo route('table.ports') ?>'

View File

@ -34,7 +34,7 @@ foreach ($routing_count as $type => $value) {
}
echo $sep;
unset($sep);
$sep = '';
if ($vars['protocol'] == $type) {
echo '<span class="pagemenu-selected">';

View File

@ -225,7 +225,7 @@ if (! Auth::user()->hasGlobalRead()) {
$peer_query = "SELECT * FROM `bgpPeers` AS `B`, `devices` AS `D` WHERE `B`.`device_id` = `D`.`device_id` $where $extra_sql ORDER BY `D`.`hostname`, `B`.`bgpPeerRemoteAs`, `B`.`bgpPeerIdentifier`";
foreach (dbFetchRows($peer_query) as $peer) {
unset($alert, $bg_image);
unset($alert);
if ($peer['bgpPeerState'] == 'established') {
$col = 'green';
@ -362,7 +362,7 @@ if (! Auth::user()->hasGlobalRead()) {
$graph_array['height'] = '100';
$graph_array['width'] = '218';
$graph_array['to'] = \LibreNMS\Config::get('time.now');
echo '<tr></tr><tr class="bgp"' . ($bg_image ? ' background="' . $bg_image . '"' : '') . '"><td colspan="9">';
echo '<tr></tr><tr class="bgp"><td colspan="9">';
include 'includes/html/print-graphrow.inc.php';

View File

@ -20,7 +20,7 @@ $no_refresh = true;
$param = [];
$device_id = (int) $vars['device'];
if ($vars['action'] == 'expunge' && \Auth::user()->hasGlobalAdmin()) {
if (isset($vars['action']) && $vars['action'] == 'expunge' && \Auth::user()->hasGlobalAdmin()) {
dbQuery('TRUNCATE TABLE `syslog`');
print_message('syslog truncated');
}
@ -63,7 +63,7 @@ $pagetitle[] = 'Syslog';
'<select name="program" id="program" class="form-control">' +
'<option value="">All Programs&nbsp;&nbsp;</option>' +
<?php
if ($vars['program']) {
if (! empty($vars['program'])) {
$js_program = addcslashes(htmlentities($vars['program']), "'");
echo "'<option value=\"$js_program\">$js_program</option>' +";
}
@ -74,7 +74,7 @@ $pagetitle[] = 'Syslog';
'<select name="priority" id="priority" class="form-control">' +
'<option value="">All Priorities</option>' +
<?php
if ($vars['priority']) {
if (! empty($vars['priority'])) {
$js_priority = addcslashes(htmlentities($vars['priority']), "'");
echo "'<option value=\"$js_priority\">$js_priority</option>' +";
}
@ -82,10 +82,10 @@ $pagetitle[] = 'Syslog';
'</select>' +
'</div>' +
'&nbsp;&nbsp;<div class="form-group">' +
'<input name="from" type="text" class="form-control" id="dtpickerfrom" maxlength="16" value="<?php echo $vars['from']; ?>" placeholder="From" data-date-format="YYYY-MM-DD HH:mm">' +
'<input name="from" type="text" class="form-control" id="dtpickerfrom" maxlength="16" value="<?php echo $vars['from'] ?? ''; ?>" placeholder="From" data-date-format="YYYY-MM-DD HH:mm">' +
'</div>' +
'<div class="form-group">' +
'&nbsp;&nbsp;<input name="to" type="text" class="form-control" id="dtpickerto" maxlength="16" value="<?php echo $vars['to']; ?>" placeholder="To" data-date-format="YYYY-MM-DD HH:mm">' +
'&nbsp;&nbsp;<input name="to" type="text" class="form-control" id="dtpickerto" maxlength="16" value="<?php echo $vars['to'] ?? ''; ?>" placeholder="To" data-date-format="YYYY-MM-DD HH:mm">' +
'</div>' +
'&nbsp;&nbsp;<button type="submit" class="btn btn-default">Filter</button>' +
'</form>' +
@ -171,7 +171,7 @@ $pagetitle[] = 'Syslog';
}
}
}
})<?php echo $vars['program'] ? ".val('" . addcslashes($vars['program'], "'") . "').trigger('change');" : ''; ?>;
})<?php echo isset($vars['program']) ? ".val('" . addcslashes($vars['program'], "'") . "').trigger('change');" : ''; ?>;
$("#priority").select2({
theme: "bootstrap",
@ -191,6 +191,6 @@ $pagetitle[] = 'Syslog';
}
}
}
})<?php echo $vars['priority'] ? ".val('" . addcslashes($vars['priority'], "'") . "').trigger('change');" : ''; ?>;
})<?php echo isset($vars['priority']) ? ".val('" . addcslashes($vars['priority'], "'") . "').trigger('change');" : ''; ?>;
</script>

View File

@ -7,6 +7,7 @@ if (empty($graph_array['device'])) {
$graph_array['device'] = $device['device_id'];
}
// FIXME not css alternating yet
$g_i = $g_i ?? 0;
if (! is_integer($g_i / 2)) {
$row_colour = \LibreNMS\Config::get('list_colour.even');
} else {

View File

@ -15,6 +15,8 @@
* @author LibreNMS Contributors
*/
use App\Models\Port;
unset($icon);
$severity_colour = eventlog_severity($entry['severity']);
$icon = '<span class="alert-status ' . $severity_colour . '"></span>';
@ -23,11 +25,12 @@ echo '<tr>';
echo '<td>' . $icon . '</td>';
echo '<td>' . $entry['humandate'] . '</td>';
echo '<td style="white-space: nowrap;max-width: 100px;overflow: hidden;text-overflow: ellipsis;">';
if ($entry['type'] == 'interface') {
$entry['link'] = '<b>' . generate_port_link(cleanPort(getifbyid($entry['reference']))) . '</b>';
echo '<b>' . \LibreNMS\Util\Url::portLink(Port::find($entry['reference'])) . '</b>';
}
echo '<td style="white-space: nowrap;max-width: 100px;overflow: hidden;text-overflow: ellipsis;">' . $entry['link'] . '</td>';
echo '<td>' . htmlspecialchars($entry['message']) . '</td>';
echo '</td><td>' . htmlspecialchars($entry['message']) . '</td>';
echo '</tr>';

View File

@ -18,14 +18,16 @@ $if_id = $port['port_id'];
$port = cleanPort($port);
if ($int_colour) {
if (isset($int_colour)) {
$row_colour = $int_colour;
} else {
$i = $i ?? 0;
if (! is_integer($i / 2)) {
$row_colour = Config::get('list_colour.even');
} else {
$row_colour = Config::get('list_colour.odd');
}
$i++;
}
$port_adsl = dbFetchRow('SELECT * FROM `ports_adsl` WHERE `port_id` = ?', [$port['port_id']]);
@ -58,9 +60,9 @@ if ($port['ifAlias']) {
echo '<br />';
}
unset($break);
$break = '';
if ($port_details) {
if (! empty($port_details)) {
foreach (dbFetchRows('SELECT * FROM `ipv4_addresses` WHERE `port_id` = ?', [$port['port_id']]) as $ip) {
echo "$break <a class=interface-desc href=\"javascript:popUp('ajax/netcmd?cmd=whois&amp;query=$ip[ipv4_address]')\">" . $ip['ipv4_address'] . '/' . $ip['ipv4_prefixlen'] . '</a>';
$break = '<br />';
@ -80,7 +82,7 @@ echo '</td><td width=100>';
echo implode('<br>', $port_group_name_list);
echo "</td><td width=100 onclick=\"location.href='" . generate_port_url($port) . "'\" >";
if ($port_details) {
if (! empty($port_details)) {
$port['graph_type'] = 'port_bits';
echo generate_port_link($port, "<img src='graph.php?type=port_bits&amp;id=" . $port['port_id'] . '&amp;from=' . Config::get('time.day') . '&amp;to=' . Config::get('time.now') . '&amp;width=100&amp;height=20&amp;legend=no&amp;bg=' . str_replace('#', '', $row_colour) . "00'>");
$port['graph_type'] = 'port_upkts';
@ -139,7 +141,7 @@ if ($vlan_count > 1) {
echo "<p style='color: green;'>" . $vrf['vrf_name'] . '</p>';
}//end if
if ($port_adsl['adslLineCoding']) {
if (! empty($port_adsl['adslLineCoding'])) {
echo "</td><td width=150 onclick=\"location.href='" . generate_port_url($port) . "'\" >";
echo $port_adsl['adslLineCoding'] . '/' . rewrite_adslLineType($port_adsl['adslLineType']);
echo '<br />';
@ -164,7 +166,7 @@ if ($port_adsl['adslLineCoding']) {
}
echo '<br />';
if ($ifHardType && $ifHardType != '') {
if (! empty($ifHardType)) {
echo '<span class=box-desc>' . $ifHardType . '</span>';
} else {
echo '-';
@ -191,7 +193,7 @@ echo '<td width=375 valign=top class="interface-desc">';
$neighborsCount = 0;
$nbLinks = 0;
$int_links = [];
if (strpos($port['label'], 'oopback') === false && ! $graph_type) {
if (strpos($port['label'], 'oopback') === false && ! empty($graph_type)) {
foreach (dbFetchRows('SELECT * FROM `links` AS L, `ports` AS I, `devices` AS D WHERE L.local_port_id = ? AND L.remote_port_id = I.port_id AND I.device_id = D.device_id', [$if_id]) as $link) {
$int_links[$link['port_id']] = $link['port_id'];
$int_links_phys[$link['port_id']] = 1;
@ -200,7 +202,7 @@ if (strpos($port['label'], 'oopback') === false && ! $graph_type) {
unset($br);
if ($port_details && Config::get('enable_port_relationship') === true) {
if (! empty($port_details) && Config::get('enable_port_relationship') === true) {
// Show which other devices are on the same subnet as this interface
foreach (dbFetchRows("SELECT `ipv4_network_id` FROM `ipv4_addresses` WHERE `port_id` = ? AND `ipv4_address` NOT LIKE '127.%'", [$port['port_id']]) as $net) {
$ipv4_network_id = $net['ipv4_network_id'];
@ -251,7 +253,7 @@ if (strpos($port['label'], 'oopback') === false && ! $graph_type) {
<span class="neighbors-interface-list-firsts" style="display: inline;">';
}
if ($port_details && Config::get('enable_port_relationship') === true && port_permitted($int_link, $device['device_id'])) {
if (! empty($port_details) && Config::get('enable_port_relationship') === true && port_permitted($int_link, $device['device_id'])) {
foreach ($int_links as $int_link) {
$neighborsCount++;
if ($neighborsCount == 4) {
@ -286,7 +288,8 @@ if (strpos($port['label'], 'oopback') === false && ! $graph_type) {
// unset($int_links, $int_links_v6, $int_links_v4, $int_links_phys, $br);
}//end if
if ($port_details && Config::get('enable_port_relationship') === true && port_permitted($port['port_id'], $device['device_id'])) {
$br = '';
if (! empty($port_details) && Config::get('enable_port_relationship') === true && port_permitted($port['port_id'], $device['device_id'])) {
foreach (dbFetchRows('SELECT * FROM `pseudowires` WHERE `port_id` = ?', [$port['port_id']]) as $pseudowire) {
// `port_id`,`peer_device_id`,`peer_ldp_id`,`cpwVcID`,`cpwOid`
$pw_peer_dev = dbFetchRow('SELECT * FROM `devices` WHERE `device_id` = ?', [$pseudowire['peer_device_id']]);
@ -337,18 +340,20 @@ if ($nbLinks > 3) {
echo '</td></tr>';
// If we're showing graphs, generate the graph and print the img tags
if ($graph_type == 'etherlike') {
$graph_file = get_port_rrdfile_path($device['hostname'], $if_id, 'dot3');
} else {
$graph_file = get_port_rrdfile_path($device['hostname'], $if_id);
}
if ($graph_type && is_file($graph_file)) {
$type = $graph_type;
echo "<tr style='background-color: $row_colour; padding: 0px;'><td colspan=7>";
include 'includes/html/print-interface-graphs.inc.php';
echo '</td></tr>';
if (isset($graph_type)) {
if ($graph_type == 'etherlike') {
$graph_file = get_port_rrdfile_path($device['hostname'], $if_id, 'dot3');
} else {
$graph_file = get_port_rrdfile_path($device['hostname'], $if_id);
}
if (is_file($graph_file)) {
$type = $graph_type;
echo "<tr style='background-color: $row_colour; padding: 0px;'><td colspan=7>";
include 'includes/html/print-interface-graphs.inc.php';
echo '</td></tr>';
}
}

View File

@ -96,7 +96,7 @@ foreach ($vars as $var => $value) {
}//end if
}//end foreach
$query = 'SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id ' . $where . ' ' . $query_sort;
$query = 'SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id ' . $where;
$row = 1;

View File

@ -40,7 +40,7 @@ if (isset($vars['min_severity'])) {
$where .= get_sql_filter_min_severity($vars['min_severity'], 'R');
}
if (is_numeric($vars['device_group'])) {
if (isset($vars['device_group']) && is_numeric($vars['device_group'])) {
$where .= ' AND D.device_id IN (SELECT `device_id` FROM `device_group_device` WHERE `device_group_id` = ?)';
$param[] = $vars['device_group'];
}

View File

@ -2,7 +2,8 @@
$param = [];
$sql .= ' FROM `ipv4_mac` AS M, `ports` AS P, `devices` AS D ';
$sql = ' FROM `ipv4_mac` AS M, `ports` AS P, `devices` AS D ';
$where = '';
if (! Auth::user()->hasGlobalRead()) {
$device_ids = Permissions::devicesForUser()->toArray() ?: [0];
@ -17,7 +18,7 @@ if (is_numeric($vars['device_id'])) {
$param[] = $vars['device_id'];
}
if (is_numeric($vars['port_id'])) {
if (isset($vars['port_id']) && is_numeric($vars['port_id'])) {
$sql .= ' AND P.port_id = ?';
$param[] = $vars['port_id'];
}
@ -65,7 +66,7 @@ $sql = "SELECT *,`P`.`ifDescr` AS `interface` $sql";
foreach (dbFetchRows($sql, $param) as $entry) {
$entry = cleanPort($entry);
if (! $ignore) {
if (! empty($ignore)) {
if ($entry['ifInErrors'] > 0 || $entry['ifOutErrors'] > 0) {
$error_img = generate_port_link($entry, "<i class='fa fa-flag fa-lg' style='color:red' aria-hidden='true'></i>", 'port_errors');
} else {

View File

@ -28,8 +28,8 @@ foreach ($segments as $pos => $segment) {
if ($pos === 0) {
$vars['page'] = $segment;
} else {
[$name, $value] = explode('=', $segment);
if ($value == '' || ! isset($value)) {
[$name, $value] = array_pad(explode('=', $segment), 2, null);
if (! $value) {
if ($vars['page'] == 'device' && $pos < 3) {
// translate laravel device routes properly
$vars[$pos === 1 ? 'device' : 'tab'] = $name;

View File

@ -39,7 +39,7 @@ function get_service_status($device = null)
return $service_count;
}
function add_service($device, $type, $desc, $ip = '', $param = '', $ignore = 0, $disabled = 0, $template_id = '', $name)
function add_service($device, $type, $desc, $ip = '', $param = '', $ignore = 0, $disabled = 0, $template_id = '', $name = '')
{
if (! is_array($device)) {
$device = device_by_id_cache($device);

View File

@ -49,7 +49,7 @@ function get_mib_dir($device)
{
$dirs = [];
if (file_exists(Config::get('mib_dir') . '/' . $device['os'])) {
if (isset($device['os']) && file_exists(Config::get('mib_dir') . '/' . $device['os'])) {
$dirs[] = Config::get('mib_dir') . '/' . $device['os'];
}
@ -67,7 +67,7 @@ function get_mib_dir($device)
}
}
if ($os_mibdir = Config::get("os.{$device['os']}.mib_dir")) {
if (isset($device['os']) && ($os_mibdir = Config::get("os.{$device['os']}.mib_dir"))) {
$dirs[] = Config::get('mib_dir') . '/' . $os_mibdir;
}