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
64 changed files with 343 additions and 324 deletions

View File

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

View File

@@ -168,7 +168,7 @@ class ConnectivityHelper
public function ipFamily(): string public function ipFamily(): string
{ {
if ($this->family === null) { 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; return $this->family;

View File

@@ -95,7 +95,7 @@ class Url
} }
if ($device->location_id) { if ($device->location_id) {
$contents .= ' - ' . htmlentities($device->location); $contents .= ' - ' . htmlentities($device->location ?? '');
} }
$contents .= '</div>'; $contents .= '</div>';
@@ -332,7 +332,7 @@ class Url
{ {
$urlargs = []; $urlargs = [];
foreach ($args as $key => $arg) { 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;" />'; return '<img src="' . url('graph.php') . '?' . implode('&amp;', $urlargs) . '" style="border:0;" />';
@@ -372,7 +372,7 @@ class Url
$urlargs = []; $urlargs = [];
foreach ($args as $key => $arg) { 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;"'; $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(); ob_start();
$device = $device->toArray(); $device = $device->toArray();
$device['os_group'] = Config::get("os.{$device['os']}.group");
Debug::set(false); Debug::set(false);
chdir(base_path()); chdir(base_path());
$init_modules = ['web', 'auth']; $init_modules = ['web', 'auth'];

View File

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

View File

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

View File

@@ -21,12 +21,13 @@ if (! Auth::check()) {
exit('Unauthorized'); exit('Unauthorized');
} }
Debug::set($_REQUEST['debug']); Debug::set(! empty($_REQUEST['debug']));
$current = $_REQUEST['current']; $current = $_REQUEST['current'];
settype($current, 'integer'); settype($current, 'integer');
$rowCount = $_REQUEST['rowCount']; $rowCount = $_REQUEST['rowCount'];
settype($rowCount, 'integer'); settype($rowCount, 'integer');
$sort = '';
if (isset($_REQUEST['sort']) && is_array($_REQUEST['sort'])) { if (isset($_REQUEST['sort']) && is_array($_REQUEST['sort'])) {
foreach ($_REQUEST['sort'] as $k => $v) { foreach ($_REQUEST['sort'] as $k => $v) {
$k = preg_replace('/[^A-Za-z0-9_]/', '', $k); // only allow plain columns $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 $ifname = $port['label']; //Interface name that will be showed on top right of graph
$hostname = shorthost($device['hostname']); $hostname = shorthost($device['hostname']);
if ($_GET['title']) { if (isset($_GET['title'])) {
$ifname = \LibreNMS\Util\Clean::html($_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/') 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') function renamehost($id, $new, $source = 'console')

View File

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

View File

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

View File

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

View File

@@ -37,11 +37,11 @@ var syslog_grid = $("#syslog").bootgrid({
post: function () post: function ()
{ {
return { return {
device: "' . addcslashes($vars['device'], '"') . '", device: "' . addcslashes($vars['device'] ?? '', '"') . '",
program: "' . addcslashes($vars['program'], '"') . '", program: "' . addcslashes($vars['program'] ?? '', '"') . '",
priority: "' . addcslashes($vars['priority'], '"') . '", priority: "' . addcslashes($vars['priority'] ?? '', '"') . '",
to: "' . addcslashes($vars['to'], '"') . '", to: "' . addcslashes($vars['to'] ?? '', '"') . '",
from: "' . addcslashes($vars['from'], '"') . '", from: "' . addcslashes($vars['from'] ?? '', '"') . '",
}; };
}, },
url: "' . url('/ajax/table/syslog') . '" 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); $to = (is_numeric($args['to']) ? $args['to'] : 0);
$width = (is_numeric($args['width']) ? $args['width'] : 0); $width = (is_numeric($args['width']) ? $args['width'] : 0);
$height = (is_numeric($args['height']) ? $args['height'] : 0); $height = (is_numeric($args['height']) ? $args['height'] : 0);
$legend = str_replace("'", '', $args['legend']); $legend = str_replace("'", '', $args['legend'] ?? '');
$state = <<<STATE $state = <<<STATE
<script type="text/javascript" language="JavaScript"> <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'])); $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 = '<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 />'; $content .= addslashes(\LibreNMS\Util\Clean::html($port['ifAlias'], [])) . '<br />';
@@ -724,22 +728,24 @@ function get_url()
function alert_details($details) function alert_details($details)
{ {
if (! is_array($details)) { if (is_string($details)) {
$details = json_decode(gzuncompress($details), true); $details = json_decode(gzuncompress($details), true);
} elseif (! is_array($details)) {
$details = [];
} }
$max_row_length = 0; $max_row_length = 0;
$all_fault_detail = ''; $all_fault_detail = '';
foreach ($details['rule'] as $o => $tmp_alerts) { foreach ($details['rule'] ?? [] as $o => $tmp_alerts) {
$fault_detail = ''; $fault_detail = '';
$fallback = true; $fallback = true;
$fault_detail .= '#' . ($o + 1) . ':&nbsp;'; $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;'; $fault_detail .= '<a href="' . \LibreNMS\Util\Url::generate(['page' => 'bill', 'bill_id' => $tmp_alerts['bill_id']], []) . '">' . $tmp_alerts['bill_name'] . '</a>;&nbsp;';
$fallback = false; $fallback = false;
} }
if ($tmp_alerts['port_id']) { if (isset($tmp_alerts['port_id'])) {
if ($tmp_alerts['isisISAdjState']) { if ($tmp_alerts['isisISAdjState']) {
$fault_detail .= 'Adjacent ' . $tmp_alerts['isisISAdjIPAddrAddress']; $fault_detail .= 'Adjacent ' . $tmp_alerts['isisISAdjIPAddrAddress'];
$port = \App\Models\Port::find($tmp_alerts['port_id']); $port = \App\Models\Port::find($tmp_alerts['port_id']);
@@ -751,12 +757,12 @@ function alert_details($details)
$fallback = false; $fallback = false;
} }
if ($tmp_alerts['accesspoint_id']) { if (isset($tmp_alerts['accesspoint_id'])) {
$fault_detail .= generate_ap_link($tmp_alerts, $tmp_alerts['name']) . ';&nbsp;'; $fault_detail .= generate_ap_link($tmp_alerts, $tmp_alerts['name']) . ';&nbsp;';
$fallback = false; $fallback = false;
} }
if ($tmp_alerts['sensor_id']) { if (isset($tmp_alerts['sensor_id'])) {
if ($tmp_alerts['sensor_class'] == 'state') { if ($tmp_alerts['sensor_class'] == 'state') {
// Give more details for a state (textual form) // Give more details for a state (textual form)
$details = 'State: ' . $tmp_alerts['state_descr'] . ' (numerical ' . $tmp_alerts['sensor_current'] . ')<br> '; $details = 'State: ' . $tmp_alerts['state_descr'] . ' (numerical ' . $tmp_alerts['sensor_current'] . ')<br> ';
@@ -784,7 +790,7 @@ function alert_details($details)
$fallback = false; $fallback = false;
} }
if ($tmp_alerts['bgpPeer_id']) { if (isset($tmp_alerts['bgpPeer_id'])) {
// If we have a bgpPeer_id, we format the data accordingly // If we have a bgpPeer_id, we format the data accordingly
$fault_detail .= "BGP peer <a href='" . $fault_detail .= "BGP peer <a href='" .
\LibreNMS\Util\Url::generate([ \LibreNMS\Util\Url::generate([
@@ -799,7 +805,7 @@ function alert_details($details)
$fallback = false; $fallback = false;
} }
if ($tmp_alerts['type'] && $tmp_alerts['label']) { if ($tmp_alerts['type'] && isset($tmp_alerts['label'])) {
if ($tmp_alerts['error'] == '') { if ($tmp_alerts['error'] == '') {
$fault_detail .= ' ' . $tmp_alerts['type'] . ' - ' . $tmp_alerts['label'] . ';&nbsp;'; $fault_detail .= ' ' . $tmp_alerts['type'] . ' - ' . $tmp_alerts['label'] . ';&nbsp;';
} else { } else {

View File

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

View File

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

View File

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

View File

@@ -19,6 +19,10 @@ use LibreNMS\Util\Number;
require 'includes/html/graphs/common.inc.php'; require 'includes/html/graphs/common.inc.php';
$stacked = generate_stacked_graphs(); $stacked = generate_stacked_graphs();
$inverse = $inverse ?? false;
$multiplier = $multiplier ?? false;
$format = $format ?? '';
$previous = $_GET['previous'] ?? 'no';
if ($rrd_filename) { if ($rrd_filename) {
$rrd_filename_out = $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'; $rrd_options .= ' DEF:' . $in . 'octets_max=' . $rrd_filename_in . ':' . $ds_in . ':MAX';
} }
if ($_GET['previous'] == 'yes') { if ($previous == 'yes') {
if ($multiplier) { if ($multiplier) {
$rrd_options .= ' DEF:p' . $out . 'octetsX=' . $rrd_filename_out . ':' . $ds_out . ':AVERAGE:start=' . $prev_from . ':end=' . $from; $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; $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')) { if (Config::get('rrdgraph_real_percentile')) {
$rrd_options .= ' CDEF:highbits=inoctets,outoctets,MAX,8,*'; $rrd_options .= ' CDEF:highbits=inoctets,outoctets,MAX,8,*';
$rrd_options .= ' VDEF:percentilehigh=highbits,' . Config::get('percentile_value') . ',PERCENT'; $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 .= ' CDEF:highbitsX=inoctetsX,outoctetsX,MAX,8,*';
$rrd_options .= ' VDEF:percentilehighX=highbitsX,' . Config::get('percentile_value') . ',PERCENT'; $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') { if ($format == 'octets' || $format == 'bytes') {
$rrd_options .= ' VDEF:percentile_in=inoctets,' . Config::get('percentile_value') . ',PERCENT'; $rrd_options .= ' VDEF:percentile_in=inoctets,' . Config::get('percentile_value') . ',PERCENT';
$rrd_options .= ' VDEF:percentile_out=outoctets,' . 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_inX=inoctetsX,' . Config::get('percentile_value') . ',PERCENT';
$rrd_options .= ' VDEF:percentile_outX=outoctetsX,' . 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 { } else {
$rrd_options .= ' VDEF:percentile_in=inbits,' . Config::get('percentile_value') . ',PERCENT'; $rrd_options .= ' VDEF:percentile_in=inbits,' . Config::get('percentile_value') . ',PERCENT';
$rrd_options .= ' VDEF:percentile_out=outbits,' . 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_inX=inbitsX,' . Config::get('percentile_value') . ',PERCENT';
$rrd_options .= ' VDEF:percentile_outX=outbitsX,' . 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"; $rrd_options .= " LINE2:olsl#4400dd:'Out Linear Prediction\\n':dashes=8";
} }
if ($_GET['previous'] == 'yes') { if ($previous == 'yes') {
$rrd_options .= " COMMENT:' \\n'"; $rrd_options .= " COMMENT:' \\n'";
$rrd_options .= ' LINE1.25:in' . $format . "X#333300:'Prev In '\t"; $rrd_options .= ' LINE1.25:in' . $format . "X#333300:'Prev In '\t";
$rrd_options .= ' GPRINT:in' . $format . 'X:AVERAGE:%6.' . $float_precision . 'lf%s'; $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(); $stacked = generate_stacked_graphs();
$length = '10'; $length = 10;
$percentile = $percentile ?? false;
$print_total = $print_total ?? false;
if (! isset($percentile)) { if (! isset($percentile)) {
$length += '2'; $length += 2;
} }
if (! isset($out_text)) { if (! isset($out_text)) {
@@ -54,12 +56,12 @@ if ($percentile) {
$rrd_options .= ' VDEF:dpercentile_out=dout,' . $percentile . ',PERCENT'; $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:in_max#' . $colour_area_in_max . $stacked['transparency'] . ':';
$rrd_options .= ' AREA:dout_max#' . $colour_area_out_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:' . $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:' . $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; $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'; $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 .= ' LINE1.25:in' . $format . "X#666666:'Prev In \\\\n'";
$rrd_options .= ' AREA:in' . $format . 'X#99999966' . $stacked['transparency'] . ':'; $rrd_options .= ' AREA:in' . $format . 'X#99999966' . $stacked['transparency'] . ':';
$rrd_options .= ' LINE1.25:dout' . $format . "X#666666:'Prev Out'"; $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'; 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 $rrddescr_len = 14; // length of the padded rrd_descr in legend
if ($width > '1500') { if ($width > '1500') {
@@ -63,7 +72,7 @@ if ($width > '500') {
$rrd_options .= sprintf(" COMMENT:'%10s'", 'Max'); $rrd_options .= sprintf(" COMMENT:'%10s'", 'Max');
} }
if ($_GET['previous']) { if ($previous) {
$rrd_options .= sprintf(" COMMENT:'\t'", ''); $rrd_options .= sprintf(" COMMENT:'\t'", '');
$rrd_options .= sprintf(" COMMENT:'%10s'", 'P Avg'); $rrd_options .= sprintf(" COMMENT:'%10s'", 'P Avg');
$rrd_options .= sprintf(" COMMENT:'%10s'", 'P Max'); $rrd_options .= sprintf(" COMMENT:'%10s'", 'P Max');
@@ -74,6 +83,7 @@ if ($_GET['previous']) {
$rrd_options .= " COMMENT:'\\n'"; $rrd_options .= " COMMENT:'\\n'";
$iter = 0;
foreach ($rrd_list ?? [] as $rrd) { foreach ($rrd_list ?? [] as $rrd) {
if (! Config::get("graph_colours.$colours_in.$iter") || ! Config::get("graph_colours.$colours_out.$iter")) { if (! Config::get("graph_colours.$colours_in.$iter") || ! Config::get("graph_colours.$colours_out.$iter")) {
$iter = 0; $iter = 0;
@@ -98,9 +108,9 @@ foreach ($rrd_list ?? [] as $rrd) {
$rrd_options .= ' CDEF:outbits' . $i . '_neg=outbits' . $i . ',' . $stacked['stacked'] . ',*'; $rrd_options .= ' CDEF:outbits' . $i . '_neg=outbits' . $i . ',' . $stacked['stacked'] . ',*';
$rrd_options .= ' CDEF:bits' . $i . '=inbits' . $i . ',outbits' . $i . ',+'; $rrd_options .= ' CDEF:bits' . $i . '=inbits' . $i . ',outbits' . $i . ',+';
if ($_GET['previous']) { if ($previous) {
$rrd_options .= ' DEF:inB' . $i . 'X=' . $rrd['filename'] . ':' . $ds_in . ':AVERAGE:start=' . $prev_from . ':end=' . $from; $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'] . ':' . $ds_out . ':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:octets' . $i . 'X=inB' . $i . 'X,outB' . $i . 'X,+';
$rrd_options .= ' CDEF:inbits' . $i . 'X=inB' . $i . 'X' . ",$multiplier,* "; $rrd_options .= ' CDEF:inbits' . $i . 'X=inB' . $i . 'X' . ",$multiplier,* ";
$rrd_options .= ' CDEF:outbits' . $i . 'X=outB' . $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:totinB' . $i . '=inB' . $i . ',TOTAL';
$rrd_options .= ' VDEF:totoutB' . $i . '=outB' . $i . ',TOTAL'; $rrd_options .= ' VDEF:totoutB' . $i . '=outB' . $i . ',TOTAL';
$rrd_options .= ' VDEF:tot' . $i . '=octets' . $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'; $in_thingX .= $seperatorX . 'inB' . $i . 'X,UN,0,' . 'inB' . $i . 'X,IF';
$out_thingX .= $seperatorX . 'outB' . $i . 'X,UN,0,' . 'outB' . $i . 'X,IF'; $out_thingX .= $seperatorX . 'outB' . $i . 'X,UN,0,' . 'outB' . $i . 'X,IF';
$plusesX .= $plusX; $plusesX .= $plusX;
@@ -150,7 +160,7 @@ foreach ($rrd_list ?? [] as $rrd) {
$rrd_options .= ' GPRINT:totinB' . $i . ':%6.' . $float_precision . "lf%s$total_units"; $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 .= " COMMENT:' \t'";
$rrd_options .= ' GPRINT:inbits' . $i . 'X:AVERAGE:%6.' . $float_precision . "lf%s$units"; $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"; $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"; $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 .= " COMMENT:' \t'";
$rrd_options .= ' GPRINT:outbits' . $i . 'X:AVERAGE:%6.' . $float_precision . "lf%s$units"; $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"; $rrd_options .= ' GPRINT:outbits' . $i . 'X:MAX:%6.' . $float_precision . "lf%s$units";
@@ -184,7 +194,7 @@ foreach ($rrd_list ?? [] as $rrd) {
$iter++; $iter++;
} }
if ($_GET['previous'] == 'yes') { if ($previous == 'yes') {
$rrd_options .= ' CDEF:inBX=' . $in_thingX . $plusesX; $rrd_options .= ' CDEF:inBX=' . $in_thingX . $plusesX;
$rrd_options .= ' CDEF:outBX=' . $out_thingX . $plusesX; $rrd_options .= ' CDEF:outBX=' . $out_thingX . $plusesX;
$rrd_options .= ' CDEF:octetsX=inBX,outBX,+'; $rrd_options .= ' CDEF:octetsX=inBX,outBX,+';
@@ -206,7 +216,7 @@ if ($_GET['previous'] == 'yes') {
$rrd_options .= ' VDEF:totX=octetsX,TOTAL'; $rrd_options .= ' VDEF:totX=octetsX,TOTAL';
} }
if ($_GET['previous'] == 'yes') { if ($previous == 'yes') {
$rrd_options .= ' AREA:in' . $format . 'X#99999999' . $stacked['transparency'] . ':'; $rrd_options .= ' AREA:in' . $format . 'X#99999999' . $stacked['transparency'] . ':';
$rrd_optionsb .= ' AREA:dout' . $format . 'X#99999999' . $transparency . ':'; $rrd_optionsb .= ' AREA:dout' . $format . 'X#99999999' . $transparency . ':';
$rrd_options .= ' LINE1.25:in' . $format . 'X#666666:'; $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:AVERAGE:%6.' . $float_precision . "lf%s$units";
$rrd_options .= ' GPRINT:inbits:MAX:%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"; $rrd_options .= ' GPRINT:totin:%6.' . $float_precision . "lf%s$total_units";
if ($_GET['previous'] == 'yes') { if ($previous == 'yes') {
$rrd_options .= " COMMENT:' \t'"; $rrd_options .= " COMMENT:' \t'";
$rrd_options .= ' GPRINT:inbitsX:AVERAGE:%6.' . $float_precision . "lf%s$units"; $rrd_options .= ' GPRINT:inbitsX:AVERAGE:%6.' . $float_precision . "lf%s$units";
$rrd_options .= ' GPRINT:inbitsX:MAX:%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:AVERAGE:%6.' . $float_precision . "lf%s$units";
$rrd_options .= ' GPRINT:outbits:MAX:%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"; $rrd_options .= ' GPRINT:totout:%6.' . $float_precision . "lf%s$total_units";
if ($_GET['previous'] == 'yes') { if ($previous == 'yes') {
$rrd_options .= " COMMENT:' \t'"; $rrd_options .= " COMMENT:' \t'";
$rrd_options .= ' GPRINT:outbitsX:AVERAGE:%6.' . $float_precision . "lf%s$units"; $rrd_options .= ' GPRINT:outbitsX:AVERAGE:%6.' . $float_precision . "lf%s$units";
$rrd_options .= ' GPRINT:outbitsX:MAX:%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:AVERAGE:%6.' . $float_precision . "lf%s$units";
$rrd_options .= ' GPRINT:bits:MAX:%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"; $rrd_options .= ' GPRINT:tot:%6.' . $float_precision . "lf%s$total_units";
if ($_GET['previous'] == 'yes') { if ($previous == 'yes') {
$rrd_options .= " COMMENT:' \t'"; $rrd_options .= " COMMENT:' \t'";
$rrd_options .= ' GPRINT:bitsX:AVERAGE:%6.' . $float_precision . "lf%s$units"; $rrd_options .= ' GPRINT:bitsX:AVERAGE:%6.' . $float_precision . "lf%s$units";
$rrd_options .= ' GPRINT:bitsX:MAX:%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'; 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)) { if (! isset($descr_len)) {
$descr_len = 12; $descr_len = 12;
} }
if ($nototal) { if ($nototal) {
$descr_len += '2'; $descr_len += 2;
$unitlen += '2'; $unitlen += 2;
} }
$rrd_options .= " COMMENT:'" . \LibreNMS\Data\Store\Rrd::fixedSafeDescr($unit_text, $descr_len) . " Now Min Max Avg\l'"; $rrd_options .= " COMMENT:'" . \LibreNMS\Data\Store\Rrd::fixedSafeDescr($unit_text, $descr_len) . " Now Min Max Avg\l'";
$unitlen = '10'; $unitlen = '10';
if ($nototal) { if ($nototal) {
$descr_len += '2'; $descr_len += 2;
$unitlen += '2'; $unitlen += 2;
} }
$unit_text = str_pad(truncate($unit_text, $unitlen), $unitlen); $unit_text = str_pad(truncate($unit_text, $unitlen), $unitlen);
$colour_iter = 0; $colour_iter = 0;
foreach ($rrd_list as $i => $rrd) { foreach ($rrd_list as $i => $rrd) {
if ($rrd['colour']) { if (isset($rrd['colour'])) {
$colour = $rrd['colour']; $colour = $rrd['colour'];
} else { } else {
if (! \LibreNMS\Config::get("graph_colours.$colours.$colour_iter")) { 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 '; $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 . 'min=' . $rrd['ds'] . $i . ' ';
$rrd_options .= ' CDEF:' . $rrd['ds'] . $i . 'max=' . $rrd['ds'] . $i . ' '; $rrd_options .= ' CDEF:' . $rrd['ds'] . $i . 'max=' . $rrd['ds'] . $i . ' ';
} else { } else {
@@ -46,7 +57,7 @@ foreach ($rrd_list as $i => $rrd) {
$rrd_options .= ' DEF:' . $rrd['ds'] . $i . 'max=' . $rrd['filename'] . ':' . $rrd['ds'] . ':MAX '; $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 .= ' DEF:' . $i . 'X=' . $rrd['filename'] . ':' . $rrd['ds'] . ':AVERAGE:start=' . $prev_from . ':end=' . $from;
$rrd_options .= ' SHIFT:' . $i . "X:$period"; $rrd_options .= ' SHIFT:' . $i . "X:$period";
$thingX .= $seperatorX . $i . 'X,UN,0,' . $i . 'X,IF'; $thingX .= $seperatorX . $i . 'X,UN,0,' . $i . 'X,IF';
@@ -100,7 +111,7 @@ foreach ($rrd_list as $i => $rrd) {
$rrd_options .= " COMMENT:'\\n'"; $rrd_options .= " COMMENT:'\\n'";
}//end foreach }//end foreach
if ($_GET['previous'] == 'yes') { if ($previous == 'yes') {
if (is_numeric($multiplier)) { if (is_numeric($multiplier)) {
$rrd_options .= ' CDEF:X=' . $thingX . $plusesX . ',' . $multiplier . ',*'; $rrd_options .= ' CDEF:X=' . $thingX . $plusesX . ',' . $multiplier . ',*';
} elseif (is_numeric($divider)) { } elseif (is_numeric($divider)) {

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
<?php <?php
$rrd_list[1]['filename'] = $rrd_filename; $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_in'] = 'INERRORS';
$rrd_list[1]['ds_out'] = 'OUTERRORS'; $rrd_list[1]['ds_out'] = 'OUTERRORS';
$rrd_list[1]['descr'] = 'Errors'; $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[1]['colour_area_out'] = 'FF6633';
$rrd_list[4]['filename'] = $rrd_filename; $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_in'] = 'INDISCARDS';
$rrd_list[4]['ds_out'] = 'OUTDISCARDS'; $rrd_list[4]['ds_out'] = 'OUTDISCARDS';
$rrd_list[4]['descr'] = 'Discards'; $rrd_list[4]['descr'] = 'Discards';

View File

@@ -3,7 +3,7 @@
$rrd_file = get_port_rrdfile_path($device['hostname'], $port['port_id']); $rrd_file = get_port_rrdfile_path($device['hostname'], $port['port_id']);
$rrd_list[2]['filename'] = $rrd_file; $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_in'] = 'INBROADCASTPKTS';
$rrd_list[2]['ds_out'] = 'OUTBROADCASTPKTS'; $rrd_list[2]['ds_out'] = 'OUTBROADCASTPKTS';
$rrd_list[2]['descr'] = 'Broadcast'; $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[2]['colour_area_out'] = '49BEB7';
$rrd_list[4]['filename'] = $rrd_file; $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_in'] = 'INMULTICASTPKTS';
$rrd_list[4]['ds_out'] = 'OUTMULTICASTPKTS'; $rrd_list[4]['ds_out'] = 'OUTMULTICASTPKTS';
$rrd_list[4]['descr'] = 'Multicast'; $rrd_list[4]['descr'] = 'Multicast';

View File

@@ -5,6 +5,8 @@ $scale_max = '100';
require 'includes/html/graphs/common.inc.php'; require 'includes/html/graphs/common.inc.php';
$previous = $_GET['previous'] ?? 'no';
$rrd_options .= ' -b 1024'; $rrd_options .= ' -b 1024';
$iter = '1'; $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:free:LAST:%6.2lf%sB';
$rrd_options .= ' GPRINT:perc:LAST:%5.2lf%%\\n'; $rrd_options .= ' GPRINT:perc:LAST:%5.2lf%%\\n';
if ($_GET['previous']) { if ($previous) {
$descr = \LibreNMS\Data\Store\Rrd::fixedSafeDescr('Prev ' . $storage['storage_descr'], 16); $descr = \LibreNMS\Data\Store\Rrd::fixedSafeDescr('Prev ' . $storage['storage_descr'], 16);
$colour = '99999999'; $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 ?'); print_error('Unsupported SNMP Version. There was a dropdown menu, how did you reach this error ?');
}//end if }//end if
$poller_group = strip_tags($_POST['poller_group']); $poller_group = strip_tags($_POST['poller_group'] ?? '');
$force_add = ($_POST['force_add'] == 'on'); $force_add = (isset($_POST['force_add']) && $_POST['force_add'] == 'on');
$port_assoc_mode = strip_tags($_POST['port_assoc_mode']); $port_assoc_mode = strip_tags($_POST['port_assoc_mode']);
try { try {
@@ -165,12 +165,7 @@ $pagetitle[] = 'Add host';
<select name="transport" id="transport" class="form-control input-sm"> <select name="transport" id="transport" class="form-control input-sm">
<?php <?php
foreach (Config::get('snmp.transports') as $transport) { foreach (Config::get('snmp.transports') as $transport) {
echo "<option value='" . $transport . "'"; echo "<option value='" . $transport . "'>" . $transport . '</option>';
if ($transport == $device['transport']) {
echo " selected='selected'";
}
echo '>' . $transport . '</option>';
} }
?> ?>
</select> </select>

View File

@@ -58,7 +58,7 @@ if (! Auth::user()->hasGlobalAdmin()) {
print_optionbar_start(); print_optionbar_start();
unset($sep); $sep = '';
foreach ($panes as $type => $text) { foreach ($panes as $type => $text) {
if (! isset($vars['section'])) { if (! isset($vars['section'])) {
$vars['section'] = $type; $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']); $device_model = Device::find($device['device_id']);
if ($_POST['editing']) { if (! empty($_POST['editing'])) {
if (Auth::user()->hasGlobalAdmin()) { if (Auth::user()->hasGlobalAdmin()) {
$reload = false; $reload = false;
if (isset($_POST['parent_id'])) { if (isset($_POST['parent_id'])) {
@@ -92,7 +92,7 @@ if ($_POST['editing']) {
} }
$override_sysContact_bool = get_dev_attrib($device, 'override_sysContact_bool'); $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'); $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 }}')" > <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> <label for="edit-display-input" class="col-sm-2 control-label" >Display Name</label>
<div class="col-sm-6"> <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> </div>
<div class="form-group" data-toggle="tooltip" data-container="body" data-placement="bottom" title="Use this IP instead of resolved one for polling" > <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> <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"> <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> </div>
<div class="form-group"> <div class="form-group">

View File

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

View File

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

View File

@@ -46,7 +46,7 @@ require 'overview/storage.inc.php';
if (! isset($entity_state)) { if (! isset($entity_state)) {
$entity_state = get_dev_entity_state($device['device_id']); $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'; 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 - 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 - 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 // FIXME - DUPLICATED IN health/sensors
$graph_colour = str_replace('#', '', $row_colour);
$graph_array = []; $graph_array = [];
$graph_array['height'] = '100'; $graph_array['height'] = '100';
$graph_array['width'] = '210'; $graph_array['width'] = '210';

View File

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

View File

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

View File

@@ -26,7 +26,7 @@
use App\Models\DevicePerf; use App\Models\DevicePerf;
$perf_info = DevicePerf::where('device_id', $device['device_id'])->latest('timestamp')->first(); $perf_info = DevicePerf::where('device_id', $device['device_id'])->latest('timestamp')->first();
if ($perf_info['debug']['traceroute']) { if (! empty($perf_info['debug']['traceroute'])) {
echo " echo "
<div class='row'> <div class='row'>
<div class='col-md-12'> <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) { foreach (dbFetchRows('SELECT * FROM `packages` WHERE `device_id` = ? ORDER BY `name`', [$device['device_id']]) as $entry) {
echo '<tr class="list">'; echo '<tr class="list">';
echo '<td width=200><a href="' . \LibreNMS\Util\Url::generate($vars, ['name' => $entry['name']]) . '">' . $entry['name'] . '</a></td>'; 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']; $dbuild = '-' . $entry['build'];
} else { } else {
$dbuild = ''; $dbuild = '';

View File

@@ -6,32 +6,31 @@ use LibreNMS\Util\Url;
$vars['view'] = basename($vars['view'] ?? 'graphs'); $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; $port_details = 1;
$hostname = $device['hostname']; $hostname = $device['hostname'];
$hostid = $device['port_id']; $ifname = $port->ifDescr;
$ifname = $port['ifDescr']; $ifIndex = $port->ifIndex;
$ifIndex = $port['ifIndex']; $speed = \LibreNMS\Util\Number::formatSi($port->ifSpeed, 2, 3, 'bps');
$speed = \LibreNMS\Util\Number::formatSi($port['ifSpeed'], 2, 3, 'bps');
$ifalias = $port['name']; $ifalias = $port->getLabel();
if ($port['ifPhysAddress']) { if ($port->ifPhysAddress) {
$mac = "$port[ifPhysAddress]"; $mac = $port->ifPhysAddress;
} }
$color = 'black'; $color = 'black';
if ($port['ifAdminStatus'] == 'down') { if ($port->ifAdminStatus == 'down') {
$status = "<span class='grey'>Disabled</span>"; $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>"; $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>"; $status = "<span class='green'>Enabled / Connected</span>";
} }
@@ -67,7 +66,7 @@ $link_array = [
'page' => 'device', 'page' => 'device',
'device' => $device['device_id'], 'device' => $device['device_id'],
'tab' => 'port', 'tab' => 'port',
'port' => $port['port_id'], 'port' => $port->port_id,
]; ];
$menu_options['graphs'] = 'Graphs'; $menu_options['graphs'] = 'Graphs';
@@ -78,19 +77,19 @@ $menu_options['fdb'] = 'FDB Table';
$menu_options['events'] = 'Eventlog'; $menu_options['events'] = 'Eventlog';
$menu_options['notes'] = 'Notes'; $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'; $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'; $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'; $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'; $menu_options['vlans'] = 'VLANs';
} }
@@ -104,7 +103,7 @@ if (count($components) > 0) {
$menu_options['cbqos'] = 'CBQoS'; $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])) { 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 // 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); 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 generate_link($descr, $link_array, ['view' => 'macaccounting', 'graph' => $type]);
echo ' | Mac Accounting : '; echo ' | Mac Accounting : ';
@@ -196,7 +195,7 @@ if (dbFetchCell("SELECT count(*) FROM mac_accounting WHERE port_id = '" . $port[
echo ')'; echo ')';
}//end if }//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 ATM VPs
// FIXME URLs BROKEN // FIXME URLs BROKEN
echo ' | ATM VPs : '; echo ' | ATM VPs : ';
@@ -204,7 +203,7 @@ if (dbFetchCell("SELECT COUNT(*) FROM juniAtmVp WHERE port_id = '" . $port['port
echo "<span class='pagemenu-selected'>"; 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') { if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') {
echo '</span>'; echo '</span>';
} }
@@ -214,7 +213,7 @@ if (dbFetchCell("SELECT COUNT(*) FROM juniAtmVp WHERE port_id = '" . $port['port
echo "<span class='pagemenu-selected'>"; 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') { if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') {
echo '</span>'; echo '</span>';
} }
@@ -224,7 +223,7 @@ if (dbFetchCell("SELECT COUNT(*) FROM juniAtmVp WHERE port_id = '" . $port['port
echo "<span class='pagemenu-selected'>"; 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') { if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') {
echo '</span>'; echo '</span>';
} }
@@ -234,20 +233,20 @@ if (dbFetchCell("SELECT COUNT(*) FROM juniAtmVp WHERE port_id = '" . $port['port
echo "<span class='pagemenu-selected'>"; 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') { if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') {
echo '</span>'; echo '</span>';
} }
}//end if }//end if
if (Auth::user()->hasGlobalAdmin() && \LibreNMS\Config::get('enable_billing') == 1) { 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) { 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>"; 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) { } 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>"; 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 { } 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 <?php
if (file_exists(get_port_rrdfile_path($device['hostname'], $port['port_id'], 'adsl'))) { if (file_exists(get_port_rrdfile_path($device['hostname'], $port['port_id'], 'adsl'))) {
$iid = $id;
echo '<div class=graphhead>ADSL Current Line Speed</div>'; echo '<div class=graphhead>ADSL Current Line Speed</div>';
$graph_type = 'port_adsl_speed'; $graph_type = 'port_adsl_speed';

View File

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

View File

@@ -202,7 +202,7 @@ if ($vars['subview'] == 'top10') {
$graph_array['height'] = '100'; $graph_array['height'] = '100';
$graph_array['width'] = '216'; $graph_array['width'] = '216';
$graph_array['to'] = Config::get('time.now'); $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'; include 'includes/html/print-graphrow.inc.php';

View File

@@ -12,7 +12,7 @@
$pagetitle[] = 'Notes'; $pagetitle[] = 'Notes';
$port_id_notes = 'port_id_notes:' . $port['port_id']; $port_id_notes = 'port_id_notes:' . $port['port_id'];
$device_id = $device['device_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"> <form class="form-horizontal" action="" method="post">

View File

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

View File

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

View File

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

View File

@@ -2,6 +2,7 @@
use LibreNMS\Util\IP; use LibreNMS\Util\IP;
$extra_sql = '';
$link_array = [ $link_array = [
'page' => 'device', 'page' => 'device',
'device' => $device['device_id'], '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) { 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']]); $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)) { if (! is_integer($i / 2)) {
$bg_colour = \LibreNMS\Config::get('list_colour.even'); $bg_colour = \LibreNMS\Config::get('list_colour.even');
} else { } else {
$bg_colour = \LibreNMS\Config::get('list_colour.odd'); $bg_colour = \LibreNMS\Config::get('list_colour.odd');
} }
unset($alert, $bg_image); unset($alert);
unset($peerhost, $peername); unset($peerhost, $peername);
if (! is_integer($i / 2)) { if (! is_integer($i / 2)) {
@@ -171,7 +171,7 @@ foreach (dbFetchRows("SELECT * FROM `bgpPeers` WHERE `device_id` = ? $extra_sql
} elseif ($ipv6_host) { } elseif ($ipv6_host) {
$peerhost = $ipv6_host; $peerhost = $ipv6_host;
} else { } else {
unset($peerhost); $peerhost = null;
} }
if (is_array($peerhost)) { if (is_array($peerhost)) {
@@ -191,20 +191,18 @@ foreach (dbFetchRows("SELECT * FROM `bgpPeers` WHERE `device_id` = ? $extra_sql
} }
unset($peer_af); unset($peer_af);
unset($sep); $sep = '';
foreach (dbFetchRows('SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?', [$device['device_id'], $peer['bgpPeerIdentifier']]) as $afisafi) { foreach (dbFetchRows('SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?', [$device['device_id'], $peer['bgpPeerIdentifier']]) as $afisafi) {
$afi = $afisafi['afi']; $afi = $afisafi['afi'];
$safi = $afisafi['safi']; $safi = $afisafi['safi'];
$this_afisafi = $afi . $safi; $this_afisafi = $afi . $safi;
$peer['afi'] .= $sep . $afi . '.' . $safi; $peer['afi'] = $sep . $afi . '.' . $safi;
$sep = '<br />'; $sep = '<br />';
$peer['afisafi'][$this_afisafi] = 1; $peer['afisafi'][$this_afisafi] = 1;
// Build a list of valid AFI/SAFI for this peer // Build a list of valid AFI/SAFI for this peer
} }
unset($sep);
// make ipv6 look pretty // make ipv6 look pretty
$peer['bgpPeerIdentifier'] = (string) IP::parse($peer['bgpPeerIdentifier'], true); $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['to'] = \LibreNMS\Config::get('time.now');
$graph_array['from'] = \LibreNMS\Config::get('time.day'); $graph_array['from'] = \LibreNMS\Config::get('time.day');
$graph_array['height'] = '110'; $graph_array['height'] = '110';
$graph_array['width'] = $width; if (isset($width)) {
$graph_array['width'] = $width;
}
// Peer Address // Peer Address
$graph_array_zoom = $graph_array; $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']; $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 ' echo '
<td>' . $peeraddresslink . '<br />' . $peername . "</td> <td>' . $peeraddresslink . '<br />' . ($peername ?? '') . "</td>
<td>$peer_type</td> <td>$peer_type</td>
<td style='font-size: 10px; font-weight: bold; line-height: 10px;'>" . (isset($peer['afi']) ? $peer['afi'] : '') . '</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> <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; $peer['graph'] = 1;
} }
if ($peer['graph']) { if (! empty($peer['graph'])) {
$graph_array['height'] = '100'; $graph_array['height'] = '100';
$graph_array['width'] = '216'; $graph_array['width'] = '216';
$graph_array['to'] = \LibreNMS\Config::get('time.now'); $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'; include 'includes/html/print-graphrow.inc.php';

View File

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

View File

@@ -14,21 +14,22 @@ if (session('widescreen')) {
$thumb_width = 113; $thumb_width = 113;
} }
$vars['from'] = parse_at_time($vars['from']) ?: Config::get('time.day'); $vars['from'] = parse_at_time($vars['from'] ?? '') ?: Config::get('time.day');
$vars['to'] = parse_at_time($vars['to']) ?: Config::get('time.now'); $vars['to'] = parse_at_time($vars['to'] ?? '') ?: Config::get('time.now');
preg_match('/^(?P<type>[A-Za-z0-9]+)_(?P<subtype>.+)/', $vars['type'], $graphtype); preg_match('/^(?P<type>[A-Za-z0-9]+)_(?P<subtype>.+)/', $vars['type'], $graphtype);
$type = basename($graphtype['type']); $type = basename($graphtype['type']);
$subtype = basename($graphtype['subtype']); $subtype = basename($graphtype['subtype']);
$id = $vars['id']; $id = $vars['id'] ?? null;
if (is_numeric($vars['device'])) { if (isset($vars['device'])) {
$device = device_by_id_cache($vars['device']); $device = is_numeric($vars['device'])
} elseif (! empty($vars['device'])) { ? device_by_id_cache($vars['device'])
$device = device_by_name($vars['device']); : device_by_name($vars['device']);
} }
$auth = false;
if (is_file('includes/html/graphs/' . $type . '/auth.inc.php')) { if (is_file('includes/html/graphs/' . $type . '/auth.inc.php')) {
require '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 '<div style="padding-top: 5px";></div>';
echo '<center>'; echo '<center>';
if ($vars['legend'] == 'no') { if (isset($vars['legend']) && $vars['legend'] == 'no') {
echo generate_link('Show Legend', $vars, ['page' => 'graphs', 'legend' => null]); echo generate_link('Show Legend', $vars, ['page' => 'graphs', 'legend' => null]);
} else { } else {
echo generate_link('Hide Legend', $vars, ['page' => 'graphs', 'legend' => 'no']); echo generate_link('Hide Legend', $vars, ['page' => 'graphs', 'legend' => 'no']);
@@ -138,7 +139,7 @@ if (! $auth) {
// if ($type == "port" && $subtype == "bits") // if ($type == "port" && $subtype == "bits")
// { // {
echo ' | '; echo ' | ';
if ($vars['previous'] == 'yes') { if (isset($vars['previous']) && $vars['previous'] == 'yes') {
echo generate_link('Hide Previous', $vars, ['page' => 'graphs', 'previous' => null]); echo generate_link('Hide Previous', $vars, ['page' => 'graphs', 'previous' => null]);
} else { } else {
echo generate_link('Show Previous', $vars, ['page' => 'graphs', 'previous' => 'yes']); echo generate_link('Show Previous', $vars, ['page' => 'graphs', 'previous' => 'yes']);
@@ -146,7 +147,7 @@ if (! $auth) {
// } // }
echo ' | '; echo ' | ';
if ($vars['showcommand'] == 'yes') { if (isset($vars['showcommand']) && $vars['showcommand'] == 'yes') {
echo generate_link('Hide RRD Command', $vars, ['page' => 'graphs', 'showcommand' => null]); echo generate_link('Hide RRD Command', $vars, ['page' => 'graphs', 'showcommand' => null]);
} else { } else {
echo generate_link('Show RRD Command', $vars, ['page' => 'graphs', 'showcommand' => 'yes']); echo generate_link('Show RRD Command', $vars, ['page' => 'graphs', 'showcommand' => 'yes']);
@@ -186,7 +187,7 @@ if (! $auth) {
print_optionbar_end(); print_optionbar_end();
} }
if ($vars['showcommand']) { if (! empty($vars['showcommand'])) {
$_GET = $graph_array; $_GET = $graph_array;
$command_only = 1; $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()]); $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) { foreach ($results as $data) {
if ($data['device_id'] == $vars['device_id']) { $deviceselected = isset($vars['device_id']) && $data['device_id'] == $vars['device_id'] ? 'selected' : '';
$deviceselected = 'selected';
} else {
$deviceselected = '';
}
$ui_device = strlen(format_hostname($data)) > 15 ? substr(format_hostname($data), 0, 15) . '...' : format_hostname($data); $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>'; $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;'; $output .= '</select>&nbsp;';
if (strlen($vars['hostname'])) { $hasvalue = ! empty($vars['hostname']) ? "value='" . $vars['hostname'] . "'" : '';
$hasvalue = "value='" . $vars['hostname'] . "'";
} else {
$hasvalue = '';
}
$output .= "<input type='text' name='hostname' id='hostname' title='Hostname' class='form-control input-sm' " . $hasvalue . " placeholder='Hostname'>"; $output .= "<input type='text' name='hostname' id='hostname' title='Hostname' class='form-control input-sm' " . $hasvalue . " placeholder='Hostname'>";
$output .= '</div>&nbsp;'; $output .= '</div>&nbsp;';
switch ($vars['state']) { switch ($vars['state'] ?? '') {
case 'up': case 'up':
$isup = 'selected'; $isup = 'selected';
$isdown = ''; $isdown = '';
@@ -152,6 +144,10 @@ if ((isset($vars['searchbar']) && $vars['searchbar'] != 'hide') || ! isset($vars
$isdown = ''; $isdown = '';
$admindown = 'selected'; $admindown = 'selected';
break; break;
default:
$isup = '';
$isdown = '';
$admindown = '';
} }
$output .= "<div class='form-group'>"; $output .= "<div class='form-group'>";
@@ -173,11 +169,7 @@ if ((isset($vars['searchbar']) && $vars['searchbar'] != 'hide') || ! isset($vars
foreach ($ifSpeed as $data) { foreach ($ifSpeed as $data) {
if ($data['ifSpeed']) { if ($data['ifSpeed']) {
if ($data['ifSpeed'] == $vars['ifSpeed']) { $speedselected = isset($vars['ifSpeed']) && $data['ifSpeed'] == $vars['ifSpeed'] ? 'selected' : '';
$speedselected = 'selected';
} else {
$speedselected = '';
}
$output .= "<option value='" . $data['ifSpeed'] . "'" . $speedselected . '>' . \LibreNMS\Util\Number::formatSi($data['ifSpeed'], 2, 3, 'bps') . '</option>'; $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) { foreach ($ifType as $data) {
if ($data['ifType']) { if ($data['ifType']) {
if ($data['ifType'] == $vars['ifType']) { $dataselected = isset($vars['ifType']) && $data['ifType'] == $vars['ifType'] ? 'selected' : '';
$dataselected = 'selected';
} else {
$dataselected = '';
}
$output .= "<option value='" . clean_bootgrid($data['ifType']) . "' " . $dataselected . '>' . clean_bootgrid($data['ifType']) . '</option>'; $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) { foreach ($port_descr_type as $data) {
if ($data['port_descr_type']) { 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'; $portdescrib = 'selected';
} else { } else {
$portdescrib = ''; $portdescrib = '';
@@ -236,9 +224,7 @@ if ((isset($vars['searchbar']) && $vars['searchbar'] != 'hide') || ! isset($vars
$output .= '</div>'; $output .= '</div>';
$output .= "<div class='form-group'>"; $output .= "<div class='form-group'>";
if (strlen($vars['ifAlias'])) { $ifaliasvalue = isset($vars['ifAlias']) ? "value='" . $vars['ifAlias'] . "'" : '';
$ifaliasvalue = "value='" . $vars['ifAlias'] . "'";
}
$output .= '</div>'; $output .= '</div>';
@@ -253,7 +239,7 @@ if ((isset($vars['searchbar']) && $vars['searchbar'] != 'hide') || ! isset($vars
$location = $location_row['location']; $location = $location_row['location'];
$location_id = $location_row['id']; $location_id = $location_row['id'];
if ($location) { if ($location) {
if ($location_id == $vars['location']) { if (isset($vars['location']) && $location_id == $vars['location']) {
$locationselected = 'selected'; $locationselected = 'selected';
} else { } else {
$locationselected = ''; $locationselected = '';
@@ -265,23 +251,9 @@ if ((isset($vars['searchbar']) && $vars['searchbar'] != 'hide') || ! isset($vars
$output .= '</select>&nbsp;'; $output .= '</select>&nbsp;';
if ($vars['ignore']) { $ignorecheck = isset($vars['ignore']) ? 'checked' : '';
$ignorecheck = 'checked'; $disabledcheck = isset($vars['disabled']) ? 'checked' : '';
} else { $deletedcheck = isset($vars['deleted']) ? 'checked' : '';
$ignorecheck = '';
}
if ($vars['disabled']) {
$disabledcheck = 'checked';
} else {
$disabledcheck = '';
}
if ($vars['deleted']) {
$deletedcheck = 'checked';
} else {
$deletedcheck = '';
}
$output .= "<label for='ignore'>Ignored</label>&nbsp;"; $output .= "<label for='ignore'>Ignored</label>&nbsp;";
$output .= "<input type='checkbox' id='ignore' name='ignore' value='1' " . $ignorecheck . '>&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 .= "<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 .= "<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>'; $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'; $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; $row = 1;
[$format, $subformat] = explode('_', basename($vars['format'])); [$format, $subformat] = explode('_', basename($vars['format']));
@@ -424,7 +396,7 @@ $row = 1;
// only grab list of ports for graph pages, table uses ajax // only grab list of ports for graph pages, table uses ajax
$ports = $format == 'graph' ? dbFetchRows($query, $param) : []; $ports = $format == 'graph' ? dbFetchRows($query, $param) : [];
switch ($vars['sort']) { switch ($vars['sort'] ?? '') {
case 'traffic': case 'traffic':
$ports = array_sort_by_column($ports, 'ifOctets_rate', SORT_DESC); $ports = array_sort_by_column($ports, 'ifOctets_rate', SORT_DESC);
break; 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['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'); $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'); $error_img = generate_port_link($port, "<i class='fa fa-flag fa-lg' style='color:red' aria-hidden='true'></i>", 'errors');
} else { } else {
$error_img = ''; $error_img = '';
} }
if (port_permitted($port['port_id'], $port['device_id'])) { if (port_permitted($port['port_id'], $port['device_id'])) {
$port = cleanPort($port, $device); $port = cleanPort($port, $device ?? null);
$graph_type = 'port_' . $subformat; $graph_type = 'port_' . $subformat;

View File

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

View File

@@ -34,7 +34,7 @@ foreach ($routing_count as $type => $value) {
} }
echo $sep; echo $sep;
unset($sep); $sep = '';
if ($vars['protocol'] == $type) { if ($vars['protocol'] == $type) {
echo '<span class="pagemenu-selected">'; 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`"; $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) { foreach (dbFetchRows($peer_query) as $peer) {
unset($alert, $bg_image); unset($alert);
if ($peer['bgpPeerState'] == 'established') { if ($peer['bgpPeerState'] == 'established') {
$col = 'green'; $col = 'green';
@@ -362,7 +362,7 @@ if (! Auth::user()->hasGlobalRead()) {
$graph_array['height'] = '100'; $graph_array['height'] = '100';
$graph_array['width'] = '218'; $graph_array['width'] = '218';
$graph_array['to'] = \LibreNMS\Config::get('time.now'); $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'; include 'includes/html/print-graphrow.inc.php';

View File

@@ -20,7 +20,7 @@ $no_refresh = true;
$param = []; $param = [];
$device_id = (int) $vars['device']; $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`'); dbQuery('TRUNCATE TABLE `syslog`');
print_message('syslog truncated'); print_message('syslog truncated');
} }
@@ -63,7 +63,7 @@ $pagetitle[] = 'Syslog';
'<select name="program" id="program" class="form-control">' + '<select name="program" id="program" class="form-control">' +
'<option value="">All Programs&nbsp;&nbsp;</option>' + '<option value="">All Programs&nbsp;&nbsp;</option>' +
<?php <?php
if ($vars['program']) { if (! empty($vars['program'])) {
$js_program = addcslashes(htmlentities($vars['program']), "'"); $js_program = addcslashes(htmlentities($vars['program']), "'");
echo "'<option value=\"$js_program\">$js_program</option>' +"; echo "'<option value=\"$js_program\">$js_program</option>' +";
} }
@@ -74,7 +74,7 @@ $pagetitle[] = 'Syslog';
'<select name="priority" id="priority" class="form-control">' + '<select name="priority" id="priority" class="form-control">' +
'<option value="">All Priorities</option>' + '<option value="">All Priorities</option>' +
<?php <?php
if ($vars['priority']) { if (! empty($vars['priority'])) {
$js_priority = addcslashes(htmlentities($vars['priority']), "'"); $js_priority = addcslashes(htmlentities($vars['priority']), "'");
echo "'<option value=\"$js_priority\">$js_priority</option>' +"; echo "'<option value=\"$js_priority\">$js_priority</option>' +";
} }
@@ -82,10 +82,10 @@ $pagetitle[] = 'Syslog';
'</select>' + '</select>' +
'</div>' + '</div>' +
'&nbsp;&nbsp;<div class="form-group">' + '&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>' +
'<div class="form-group">' + '<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>' + '</div>' +
'&nbsp;&nbsp;<button type="submit" class="btn btn-default">Filter</button>' + '&nbsp;&nbsp;<button type="submit" class="btn btn-default">Filter</button>' +
'</form>' + '</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({ $("#priority").select2({
theme: "bootstrap", 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> </script>

View File

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

View File

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

View File

@@ -18,14 +18,16 @@ $if_id = $port['port_id'];
$port = cleanPort($port); $port = cleanPort($port);
if ($int_colour) { if (isset($int_colour)) {
$row_colour = $int_colour; $row_colour = $int_colour;
} else { } else {
$i = $i ?? 0;
if (! is_integer($i / 2)) { if (! is_integer($i / 2)) {
$row_colour = Config::get('list_colour.even'); $row_colour = Config::get('list_colour.even');
} else { } else {
$row_colour = Config::get('list_colour.odd'); $row_colour = Config::get('list_colour.odd');
} }
$i++;
} }
$port_adsl = dbFetchRow('SELECT * FROM `ports_adsl` WHERE `port_id` = ?', [$port['port_id']]); $port_adsl = dbFetchRow('SELECT * FROM `ports_adsl` WHERE `port_id` = ?', [$port['port_id']]);
@@ -58,9 +60,9 @@ if ($port['ifAlias']) {
echo '<br />'; 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) { 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>'; 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 />'; $break = '<br />';
@@ -80,7 +82,7 @@ echo '</td><td width=100>';
echo implode('<br>', $port_group_name_list); echo implode('<br>', $port_group_name_list);
echo "</td><td width=100 onclick=\"location.href='" . generate_port_url($port) . "'\" >"; echo "</td><td width=100 onclick=\"location.href='" . generate_port_url($port) . "'\" >";
if ($port_details) { if (! empty($port_details)) {
$port['graph_type'] = 'port_bits'; $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'>"); 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'; $port['graph_type'] = 'port_upkts';
@@ -139,7 +141,7 @@ if ($vlan_count > 1) {
echo "<p style='color: green;'>" . $vrf['vrf_name'] . '</p>'; echo "<p style='color: green;'>" . $vrf['vrf_name'] . '</p>';
}//end if }//end if
if ($port_adsl['adslLineCoding']) { if (! empty($port_adsl['adslLineCoding'])) {
echo "</td><td width=150 onclick=\"location.href='" . generate_port_url($port) . "'\" >"; echo "</td><td width=150 onclick=\"location.href='" . generate_port_url($port) . "'\" >";
echo $port_adsl['adslLineCoding'] . '/' . rewrite_adslLineType($port_adsl['adslLineType']); echo $port_adsl['adslLineCoding'] . '/' . rewrite_adslLineType($port_adsl['adslLineType']);
echo '<br />'; echo '<br />';
@@ -164,7 +166,7 @@ if ($port_adsl['adslLineCoding']) {
} }
echo '<br />'; echo '<br />';
if ($ifHardType && $ifHardType != '') { if (! empty($ifHardType)) {
echo '<span class=box-desc>' . $ifHardType . '</span>'; echo '<span class=box-desc>' . $ifHardType . '</span>';
} else { } else {
echo '-'; echo '-';
@@ -191,7 +193,7 @@ echo '<td width=375 valign=top class="interface-desc">';
$neighborsCount = 0; $neighborsCount = 0;
$nbLinks = 0; $nbLinks = 0;
$int_links = []; $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) { 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[$link['port_id']] = $link['port_id'];
$int_links_phys[$link['port_id']] = 1; $int_links_phys[$link['port_id']] = 1;
@@ -200,7 +202,7 @@ if (strpos($port['label'], 'oopback') === false && ! $graph_type) {
unset($br); 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 // 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) { 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']; $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;">'; <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) { foreach ($int_links as $int_link) {
$neighborsCount++; $neighborsCount++;
if ($neighborsCount == 4) { 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); // unset($int_links, $int_links_v6, $int_links_v4, $int_links_phys, $br);
}//end if }//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) { foreach (dbFetchRows('SELECT * FROM `pseudowires` WHERE `port_id` = ?', [$port['port_id']]) as $pseudowire) {
// `port_id`,`peer_device_id`,`peer_ldp_id`,`cpwVcID`,`cpwOid` // `port_id`,`peer_device_id`,`peer_ldp_id`,`cpwVcID`,`cpwOid`
$pw_peer_dev = dbFetchRow('SELECT * FROM `devices` WHERE `device_id` = ?', [$pseudowire['peer_device_id']]); $pw_peer_dev = dbFetchRow('SELECT * FROM `devices` WHERE `device_id` = ?', [$pseudowire['peer_device_id']]);
@@ -337,18 +340,20 @@ if ($nbLinks > 3) {
echo '</td></tr>'; echo '</td></tr>';
// If we're showing graphs, generate the graph and print the img tags // If we're showing graphs, generate the graph and print the img tags
if ($graph_type == 'etherlike') { if (isset($graph_type)) {
$graph_file = get_port_rrdfile_path($device['hostname'], $if_id, 'dot3'); if ($graph_type == 'etherlike') {
} else { $graph_file = get_port_rrdfile_path($device['hostname'], $if_id, 'dot3');
$graph_file = get_port_rrdfile_path($device['hostname'], $if_id); } else {
} $graph_file = get_port_rrdfile_path($device['hostname'], $if_id);
}
if ($graph_type && is_file($graph_file)) {
$type = $graph_type; if (is_file($graph_file)) {
$type = $graph_type;
echo "<tr style='background-color: $row_colour; padding: 0px;'><td colspan=7>";
echo "<tr style='background-color: $row_colour; padding: 0px;'><td colspan=7>";
include 'includes/html/print-interface-graphs.inc.php';
include 'includes/html/print-interface-graphs.inc.php';
echo '</td></tr>';
echo '</td></tr>';
}
} }

View File

@@ -96,7 +96,7 @@ foreach ($vars as $var => $value) {
}//end if }//end if
}//end foreach }//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; $row = 1;

View File

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

View File

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

View File

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

View File

@@ -39,7 +39,7 @@ function get_service_status($device = null)
return $service_count; 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)) { if (! is_array($device)) {
$device = device_by_id_cache($device); $device = device_by_id_cache($device);

View File

@@ -49,7 +49,7 @@ function get_mib_dir($device)
{ {
$dirs = []; $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']; $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; $dirs[] = Config::get('mib_dir') . '/' . $os_mibdir;
} }