refactor: Moved ifLabel -> cleanPort and updated the usage (#6288)

* refactor: Moved ifLabel -> cleanPort and updated the usage

* added list of tags allowed

* few updates as per comments from @murrant

* Added simple unit tests

* double display for javascript popover

* Remove ifNameDescr() function
Fix realtime port page

* remove accidental temp code

* Remove double display calls in ajax tables
This commit is contained in:
Neil Lathwood 2017-04-04 08:08:23 +01:00 committed by GitHub
parent b1c2ea2194
commit 1bbbaff58b
54 changed files with 137 additions and 69 deletions

View File

@ -32,7 +32,6 @@ if ($type == 'placeholder') {
$results_limit = 10;
$typeahead_limit = $config['webui']['global_search_result_limit'];
$no_form = true;
$title = ucfirst(display($type));
$unique_id = str_replace(array("-","."), "_", uniqid($type, true));
$widget_id = mres($_POST['id']);
$widget_settings = json_decode(dbFetchCell('select settings from users_widgets where user_widget_id = ?', array($widget_id)), true);
@ -43,7 +42,7 @@ if ($type == 'placeholder') {
include 'includes/common/'.$type.'.inc.php';
$output = implode('', $common_output);
$status = 'ok';
$title = display($widget_settings['title']) ?: $title;
$title = display($widget_settings['title']) ?: ucfirst(display($type));
}
$response = array(

View File

@ -22,8 +22,8 @@ if (!$_SESSION['authenticated']) {
if (is_numeric($_GET['device_id'])) {
foreach (dbFetch('SELECT * FROM ports WHERE device_id = ?', array($_GET['device_id'])) as $interface) {
$interface = ifNameDescr($interface);
$string = addslashes(display($interface['label'].' - '.$interface['ifAlias']));
$interface = cleanPort($interface);
$string = addslashes(html_entity_decode($interface['label'].' - '.$interface['ifAlias']));
echo "obj.options[obj.options.length] = new Option('".$string."','".$interface['port_id']."');\n";
}
}

View File

@ -14,7 +14,7 @@ $init_modules = array('web', 'auth');
require realpath(__DIR__ . '/..') . '/includes/init.php';
if (is_numeric($_GET['id']) && ($config['allow_unauth_graphs'] || port_permitted($_GET['id']))) {
$port = get_port_by_id($_GET['id']);
$port = cleanPort(get_port_by_id($_GET['id']));
$device = device_by_id_cache($port['device_id']);
$title = generate_device_link($device);
$title .= ' :: Port '.generate_port_link($port);

View File

@ -17,7 +17,7 @@ $init_modules = array('web', 'auth');
require realpath(__DIR__ . '/..') . '/includes/init.php';
if (is_numeric($_GET['id']) && ($config['allow_unauth_graphs'] || port_permitted($_GET['id']))) {
$port = get_port_by_id($_GET['id']);
$port = cleanPort(get_port_by_id($_GET['id']));
$device = device_by_id_cache($port['device_id']);
$title = generate_device_link($device);
$title .= " :: Port ".generate_port_link($port);
@ -31,12 +31,11 @@ header("Content-type: image/svg+xml");
/********** HTTP GET Based Conf ***********/
$ifnum=@$port['ifIndex']; // BSD / SNMP interface name / number
$ifname=ifLabel($port);
$ifname=$ifname['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']);
if ($_GET['title']) {
$ifname = $_GET['title'];
$ifname = display($_GET['title']);
}
/********* Other conf *******/
@ -75,7 +74,8 @@ $width=300; //SVG internal width : do not modify
/********* Graph DATA **************/
print('<?xml version="1.0" encoding="iso-8859-1"?>' . "\n");?>
<svg width="100%" height="100%" viewBox="0 0 <?php echo("$width $height") ?>" preserveAspectRatio="none" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" onload="init(evt)">
<svg width="100%" height="100%" viewBox="0 0 <?php echo("$width $height") ?>" preserveAspectRatio="none" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"
onload="init(evt)">
<g id="graph">
<rect id="bg" x1="0" y1="0" width="100%" height="100%" fill="white"/>
<line id="axis_x" x1="0" y1="0" x2="0" y2="100%" <?php echo ($attribs['axis']) ?>/>

View File

@ -17,7 +17,7 @@ if (defined('SHOW_SETTINGS') || empty($widget_settings)) {
<form class="form-horizontal" onsubmit="widget_settings(this); return false;">
<div class="form-group">
<div class="col-sm-12">
html is supported here. If you want just text then wrap in &lt;pre&gt;&lt;/pre&gt;
The following html tags are supported: &lt;b&gt;, &lt;iframe&gt;, &lt;i&gt;, &lt;ul&gt;, &lt;li&gt;, &lt;h1&gt;, &lt;h2&gt;, &lt;h3&gt;, &lt;h4&gt;, &lt;br&gt;, &lt;p&gt;. If you want just text then wrap in &lt;pre&gt;&lt;/pre&gt;
</div>
</div>
<div class="form-group">
@ -33,5 +33,11 @@ if (defined('SHOW_SETTINGS') || empty($widget_settings)) {
</div>
</form>';
} else {
$common_output[] = nl2br(display($widget_settings['notes']));
$tmp_config = array(
'HTML.Allowed' => 'b,iframe,i,ul,li,h1,h2,h3,h4,br,p',
'HTML.Trusted' => true,
'HTML.SafeIframe' => true,
);
$common_output[] = display(nl2br($widget_settings['notes']), $tmp_config);
unset($tmp_config);
}

View File

@ -142,6 +142,7 @@ $(function() {
';
foreach (dbFetchRows($query, $params) as $result) {
$result = cleanPort($result);
$common_output[] = '
<tr>
<td class="text-left">'.generate_device_link($result, shorthost($result['hostname'])).'</td>

View File

@ -49,6 +49,7 @@ if (is_admin() === true || is_read() === true) {
echo "<strong>Top $top ports (last $minutes minutes)</strong>\n";
echo "<table class='simple'>\n";
foreach (dbFetchRows($query, $param) as $result) {
$result = cleanPort($result);
echo '<tr class=top10>'.'<td class=top10>'.generate_device_link($result, shorthost($result['hostname'])).'</td>'.'<td class=top10>'.generate_port_link($result).'</td>'.'<td class=top10>'.generate_port_link($result, generate_port_thumbnail($result)).'</td>'."</tr>\n";
}

View File

@ -610,7 +610,7 @@ function generate_port_link($port, $text = null, $type = null, $overlib = 1, $si
global $config;
$graph_array = array();
$port = ifNameDescr($port);
if (!$text) {
$text = fixifName($port['label']);
}
@ -629,9 +629,9 @@ function generate_port_link($port, $text = null, $type = null, $overlib = 1, $si
$port = array_merge($port, device_by_id_cache($port['device_id']));
}
$content = '<div class=list-large>'.$port['hostname'].' - '.fixifName($port['label']).'</div>';
$content = '<div class=list-large>'.$port['hostname'].' - '.fixifName(addslashes(display($port['label']))).'</div>';
if ($port['ifAlias']) {
$content .= display($port['ifAlias']).'<br />';
$content .= addslashes(display($port['ifAlias'])).'<br />';
}
$content .= "<div style=\'width: 850px\'>";
@ -1139,6 +1139,7 @@ function alert_details($details)
}
if ($tmp_alerts['port_id']) {
$tmp_alerts = cleanPort($tmp_alerts);
$fault_detail .= generate_port_link($tmp_alerts).';&nbsp;';
$fallback = false;
}

View File

@ -7,7 +7,7 @@ if ($_GET['id'] && is_numeric($_GET['id'])) {
$vp = dbFetchRow('SELECT * FROM `juniAtmVp` as J, `ports` AS I, `devices` AS D WHERE J.juniAtmVp_id = ? AND I.port_id = J.port_id AND I.device_id = D.device_id', array($atm_vp_id));
if ($auth || port_permitted($vp['port_id'])) {
$port = $vp;
$port = cleanPort($vp);
$device = device_by_id_cache($port['device_id']);
$title = generate_device_link($device);
$title .= ' :: Port '.generate_port_link($port);

View File

@ -24,7 +24,7 @@ foreach (dbFetchRows('SELECT * FROM `ports` WHERE `device_id` = ?', array($devic
$rrd_filename = get_port_rrdfile_path($device['hostname'], $port['port_id']);
if ($ignore != 1 && rrdtool_check_rrd_exists($rrd_filename)) {
$port = ifLabel($port);
$port = cleanPort($port);
// Fix Labels! ARGH. This needs to be in the bloody database!
$rrd_filenames[] = $rrd_filename;
$rrd_list[$i]['filename'] = $rrd_filename;

View File

@ -18,7 +18,7 @@ if (is_numeric($vars['id'])) {
d_echo('exists');
$rrd_filename = $filename;
$port = get_port_by_id($acc['port_id']);
$port = cleanPort(get_port_by_id($acc['port_id']));
$device = device_by_id_cache($port['device_id']);
$title = generate_device_link($device);
$title .= ' :: Port '.generate_port_link($port);

View File

@ -6,7 +6,7 @@ foreach (explode(',', $vars['id']) as $ifid) {
$port = dbFetchRow('SELECT * FROM `ports` AS I, devices as D WHERE I.port_id = ? AND I.device_id = D.device_id', array($ifid));
$rrd_file = get_port_rrdfile_path($port['hostname'], $ifid);
if (rrdtool_check_rrd_exists($rrd_file)) {
$port = ifLabel($port);
$port = cleanPort($port);
$rrd_list[$i]['filename'] = $rrd_file;
$rrd_list[$i]['descr'] = $port['hostname'].' '.$port['ifDescr'];
$rrd_list[$i]['descr_in'] = $port['hostname'];

View File

@ -1,7 +1,7 @@
<?php
if (is_numeric($vars['id']) && ($auth || port_permitted($vars['id']))) {
$port = get_port_by_id($vars['id']);
$port = cleanPort(get_port_by_id($vars['id']));
$device = device_by_id_cache($port['device_id']);
$title = generate_device_link($device);
$title .= ' :: Port '.generate_port_link($port);

View File

@ -56,7 +56,7 @@ if (is_admin() !== false) {
<?php if (is_array($port)) {
// Need to pre-populate port as we've got a port pre-selected
foreach (dbFetch('SELECT * FROM ports WHERE device_id = ?', array($port_device_id)) as $interface) {
$interface = ifNameDescr($interface);
$interface = cleanPort($interface);
$string = $interface['label'].' - '.display($interface['ifAlias']);
$selected = $interface['port_id'] === $port['port_id'] ? " selected" : "";
echo "<option value='${interface['port_id']}' $selected>$string</option>\n";

View File

@ -18,7 +18,7 @@ echo '<tr">
<td>';
if ($entry['type'] == 'interface') {
$entry['link'] = '<b>'.generate_port_link(getifbyid($entry['reference'])).'</b>';
$entry['link'] = '<b>'.generate_port_link(cleanPort(getifbyid($entry['reference']))).'</b>';
}
echo $entry['link'].' '.htmlspecialchars($entry['message']).'</td>

View File

@ -20,7 +20,7 @@ if (!isset($vars['device'])) {
}
if ($entry['type'] == 'interface') {
$this_if = ifLabel(getifbyid($entry['reference']));
$this_if = cleanPort(getifbyid($entry['reference']));
$entry['link'] = '<b>'.generate_port_link($this_if, makeshortif(strtolower($this_if['label']))).'</b>';
} else {
$entry['link'] = 'System';

View File

@ -6,7 +6,7 @@ $port['hostname'] = $device['hostname'];
$if_id = $port['port_id'];
$port = ifLabel($port);
$port = cleanPort($port);
if (!is_integer($i / 2)) {
$row_colour = $list_colour_a;

View File

@ -11,7 +11,7 @@ $port['hostname'] = $device['hostname'];
$if_id = $port['port_id'];
$port = ifLabel($port);
$port = cleanPort($port);
if ($int_colour) {
$row_colour = $int_colour;
@ -47,7 +47,7 @@ if (is_admin() || is_read()) {
echo ' <span class=list-large>
'.generate_port_link($port, $port['label'])." $error_img $mac
</span><br /><span class=interface-desc>".display($port['ifAlias']).'</span>';
</span><br /><span class=interface-desc>".$port['ifAlias'].'</span>';
if ($port['ifAlias']) {
echo '<br />';
@ -246,6 +246,7 @@ if (strpos($port['label'], 'oopback') === false && !$graph_type) {
echo '<span class="neighbors-interface-list" style="display: none;">';
}
$link_if = dbFetchRow('SELECT * from ports AS I, devices AS D WHERE I.device_id = D.device_id and I.port_id = ?', array($int_link));
$link_if = cleanPort($link_if);
echo "$br";
if ($int_links_phys[$int_link]) {
@ -277,18 +278,20 @@ if ($port_details && $config['enable_port_relationship'] === true && port_permit
$pw_peer_dev = dbFetchRow('SELECT * FROM `devices` WHERE `device_id` = ?', array($pseudowire['peer_device_id']));
$pw_peer_int = dbFetchRow('SELECT * FROM `ports` AS I, pseudowires AS P WHERE I.device_id = ? AND P.cpwVcID = ? AND P.port_id = I.port_id', array($pseudowire['peer_device_id'], $pseudowire['cpwVcID']));
$pw_peer_int = ifNameDescr($pw_peer_int);
$pw_peer_int = cleanPort($pw_peer_int);
echo "$br<i class='fa fa-cube fa-lg' style='color:green' aria-hidden='true'></i><b> ".generate_port_link($pw_peer_int, makeshortif($pw_peer_int['label'])).' on '.generate_device_link($pw_peer_dev, shorthost($pw_peer_dev['hostname'])).'</b>';
$br = '<br />';
}
foreach (dbFetchRows('SELECT * FROM `ports` WHERE `pagpGroupIfIndex` = ? and `device_id` = ?', array($port['ifIndex'], $device['device_id'])) as $member) {
$member = cleanPort($member);
echo "$br<i class='fa fa-cube fa-lg icon-theme' aria-hidden='true'></i> <strong>".generate_port_link($member).' (PAgP)</strong>';
$br = '<br />';
}
if ($port['pagpGroupIfIndex'] && $port['pagpGroupIfIndex'] != $port['ifIndex']) {
$parent = dbFetchRow('SELECT * FROM `ports` WHERE `ifIndex` = ? and `device_id` = ?', array($port['pagpGroupIfIndex'], $device['device_id']));
$parent = cleanPort($parent);
echo "$br<i class='fa fa-cube fa-lg icon-theme' aria-hidden='true'></i> <strong>".generate_port_link($parent).' (PAgP)</strong>';
$br = '<br />';
}
@ -296,6 +299,7 @@ if ($port_details && $config['enable_port_relationship'] === true && port_permit
foreach (dbFetchRows('SELECT * FROM `ports_stack` WHERE `port_id_low` = ? and `device_id` = ?', array($port['ifIndex'], $device['device_id'])) as $higher_if) {
if ($higher_if['port_id_high']) {
$this_port = get_port_by_index_cache($device['device_id'], $higher_if['port_id_high']);
$this_port = cleanPort($this_port);
echo "$br<i class='fa fa-expand fa-lg icon-theme' aria-hidden='true'></i> <strong>".generate_port_link($this_port).'</strong>';
$br = '<br />';
}
@ -304,6 +308,7 @@ if ($port_details && $config['enable_port_relationship'] === true && port_permit
foreach (dbFetchRows('SELECT * FROM `ports_stack` WHERE `port_id_high` = ? and `device_id` = ?', array($port['ifIndex'], $device['device_id'])) as $lower_if) {
if ($lower_if['port_id_low']) {
$this_port = get_port_by_index_cache($device['device_id'], $lower_if['port_id_low']);
$this_port = cleanPort($this_port);
echo "$br<i class='fa fa-compress fa-lg icon-theme' aria-hidden='true'></i> <strong>".generate_port_link($this_port).'</strong>';
$br = '<br />';
}

View File

@ -193,8 +193,8 @@ foreach ($list as $items) {
!array_key_exists($link_id2, $link_assoc_seen) &&
!array_key_exists($device_id1, $device_assoc_seen) &&
!array_key_exists($device_id2, $device_assoc_seen)) {
$local_port = ifNameDescr($local_port);
$remote_port = ifNameDescr($remote_port);
$local_port = cleanPort($local_port);
$remote_port = cleanPort($remote_port);
$links[] = array('from'=>$items['local_device_id'],'to'=>$items['remote_device_id'],'label'=>shorten_interface_type($local_port['ifName']) . ' > ' . shorten_interface_type($remote_port['ifName']),'title'=>generate_port_link($local_port, "<img src='graph.php?type=port_bits&amp;id=".$items['local_port_id']."&amp;from=".$config['time']['day']."&amp;to=".$config['time']['now']."&amp;width=100&amp;height=20&amp;legend=no&amp;bg=".str_replace("#", "", $row_colour)."'>\n", '', 0, 1),'width'=>$width,'color'=>$link_color);
}
$link_assoc_seen[$link_id1] = 1;

View File

@ -32,7 +32,7 @@ if ($traverse_ifvlan) {
ksort($vlan_ports);
foreach ($vlan_ports as $port) {
$port = ifLabel($port, $device);
$port = cleanPort($port, $device);
if ($vars['view'] == 'graphs') {
echo "<div style='display: block; padding: 2px; margin: 2px; min-width: 139px; max-width:139px; min-height:85px; max-height:85px; text-align: center; float: left; background-color: ".$list_colour_b_b.";'>
<div style='font-weight: bold;'>".makeshortif($port['ifDescr'])."</div>

View File

@ -15,17 +15,18 @@ echo '<td width=100 class=box-desc>'.$vrf['mplsVpnVrfRouteDistinguisher'].'</td>
echo '<td class="list-bold">';
foreach (dbFetchRows('SELECT * FROM ports WHERE `device_id` = ? AND `ifVrf` = ?', array($device['device_id'], $vrf['vrf_id'])) as $port) {
$port = cleanPort($port, $device);
if ($vars['view'] == 'graphs') {
$graph_type = 'port_'.$vars['graph'];
echo "<div style='display: block; padding: 2px; margin: 2px; min-width: 139px; max-width:139px; min-height:85px; max-height:85px; text-align: center; float: left; background-color: #e9e9e9;'>
<div style='font-weight: bold;'>".makeshortif($port['ifDescr'])."</div>
<a href='device/".$device['device_id'].'/port/'.$port['port_id']."/' onmouseover=\"return overlib('\
<div style=\'font-size: 16px; padding:5px; font-weight: bold; color: #e5e5e5;\'>".$device['hostname'].' - '.$port['ifDescr'].'</div>\
'.display($port['ifAlias'])." \
'.$port['ifAlias']." \
<img src=\'graph.php?type=$graph_type&amp;id=".$port['port_id'].'&amp;from='.$config['time']['twoday'].'&amp;to='.$config['time']['now']."&amp;width=450&amp;height=150\'>\
', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\" >"."<img src='graph.php?type=$graph_type&amp;id=".$port['port_id'].'&amp;from='.$config['time']['twoday'].'&amp;to='.$config['time']['now']."&amp;width=132&amp;height=40&amp;legend=no'>
</a>
<div style='font-size: 9px;'>".substr(short_port_descr(display($port['ifAlias'])), 0, 22).'</div>
<div style='font-size: 9px;'>".substr(short_port_descr($port['ifAlias']), 0, 22).'</div>
</div>';
} else {
echo $vrf['port_sep'].generate_port_link($port, makeshortif($port['ifDescr']));

View File

@ -157,7 +157,7 @@ foreach ($ports as $port) {
$type = humanmedia($port['ifType']);
$port['in_rate'] = formatRates(($port['ifInOctets_rate'] * 8));
$port['out_rate'] = formatRates(($port['ifOutOctets_rate'] * 8));
$port = ifLabel($port, $device);
$port = cleanPort($port, $device);
$csv[] = array(
$port['hostname'],
fixIfName($port['label']),

View File

@ -98,12 +98,12 @@ foreach (dbFetchRows($sql, $param) as $interface) {
}
if (port_permitted($interface['port_id'])) {
$interface = ifLabel($interface, $interface);
$interface = cleanPort($interface, $interface);
$response[] = array(
'hostname' => generate_device_link($interface),
'interface' => generate_port_link($interface).' '.$error_img,
'address' => $address,
'description' => display($interface['ifAlias']),
'description' => $interface['ifAlias'],
);
}
}//end foreach

View File

@ -64,6 +64,7 @@ if ($rowCount != -1) {
$sql = "SELECT *,`P`.`ifDescr` AS `interface` $sql";
foreach (dbFetchRows($sql, $param) as $entry) {
$entry = cleanPort($entry);
if (!$ignore) {
if ($entry['ifInErrors'] > 0 || $entry['ifOutErrors'] > 0) {
$error_img = generate_port_link($entry, "<i class='fa fa-flag fa-lg' style='color:red' aria-hidden='true'></i>", port_errors);
@ -96,7 +97,7 @@ foreach (dbFetchRows($sql, $param) as $entry) {
'mac_address' => formatMac($entry['mac_address']),
'ipv4_address' => $entry['ipv4_address'],
'hostname' => generate_device_link($entry),
'interface' => generate_port_link($entry, makeshortif(fixifname(ifLabel($entry['label'])))).' '.$error_img,
'interface' => generate_port_link($entry, makeshortif(fixifname(cleanPort($entry['label'])))).' '.$error_img,
'remote_device' => $arp_name,
'remote_interface' => $arp_if,
);

View File

@ -50,6 +50,7 @@ foreach (dbFetchRows($sql, $param) as $customer) {
$ifname = fixifname($device['ifDescr']);
$ifclass = ifclass($port['ifOperStatus'], $port['ifAdminStatus']);
$port = cleanPort($port);
if ($device['os'] == 'ios') {
if ($port['ifTrunk']) {

View File

@ -45,7 +45,7 @@ $response[] = array(
);
foreach (dbFetchRows($sql, $param) as $port) {
$port = ifLabel($port);
$port = cleanPort($port);
// Mark interfaces which are OperDown (but not AdminDown) yet not ignored or disabled, or up yet ignored or disabled
// - as to draw the attention to a possible problem.
@ -70,7 +70,7 @@ foreach (dbFetchRows($sql, $param) as $port) {
'ignore' => '<input type="checkbox" class="ignore-check" name="ignore_'.$port['port_id'].'"'.($port['ignore'] ? 'checked' : '').'>
<input type="hidden" name="oldign_'.$port['port_id'].'" value="'.($port['ignore'] ? 1 : 0).'"">',
'port_tune' => '<input type="checkbox" id="override_config" name="override_config" data-attrib="ifName_tune:'.$port['ifName'].'" data-device_id="'.$port['device_id'].'" data-size="small" '.$checked.'>',
'ifAlias' => '<div class="form-group"><input class="form-control input-sm" id="if-alias" name="if-alias" data-device_id="'.$port['device_id'].'" data-port_id="'.$port['port_id'].'" data-ifName="'.$port['ifName'].'" value="'.display($port['ifAlias']).'"><span class="form-control-feedback"><i class="fa" aria-hidden="true"></i></span></div>',
'ifAlias' => '<div class="form-group"><input class="form-control input-sm" id="if-alias" name="if-alias" data-device_id="'.$port['device_id'].'" data-port_id="'.$port['port_id'].'" data-ifName="'.$port['ifName'].'" value="'.$port['ifAlias'].'"><span class="form-control-feedback"><i class="fa" aria-hidden="true"></i></span></div>',
'ifSpeed' => '<div class="form-group has-feedback"><input type="text" pattern="[0-9]*" inputmode="numeric" class="form-control input-sm" id="if-speed" name="if-speed" data-device_id="'.$port['device_id'].'" data-port_id="'.$port['port_id'].'" data-ifName="'.$port['ifName'].'" value="'.$port['ifSpeed'].'"><span class="form-control-feedback"><i class="fa" aria-hidden="true"></i></span></div>',
);
}//end foreach

View File

@ -54,7 +54,7 @@ $sql = "SELECT `E`.*,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['co
foreach (dbFetchRows($sql, $param) as $eventlog) {
$dev = device_by_id_cache($eventlog['host']);
if ($eventlog['type'] == 'interface') {
$this_if = ifLabel(getifbyid($eventlog['reference']));
$this_if = cleanPort(getifbyid($eventlog['reference']));
$type = '<b>'.generate_port_link($this_if, makeshortif(strtolower($this_if['label']))).'</b>';
} else {
$type = $eventlog['type'];

View File

@ -139,6 +139,7 @@ $query .= $sql;
foreach (dbFetchRows($query, $param) as $port) {
$device = device_by_id_cache($port['device_id']);
$port = cleanPort($port, $device);
// FIXME what actions should we have?
$actions = '<div class="container-fluid"><div class="row">';
@ -168,7 +169,7 @@ foreach (dbFetchRows($query, $param) as $port) {
'ifInErrors' => $port['ifInErrors'],
'ifOutErrors' => $port['ifOutErrors'],
'ifType' => humanmedia($port['ifType']),
'description' => display($port['ifAlias']),
'description' => $port['ifAlias'],
'actions' => $actions,
);
}

View File

@ -30,11 +30,12 @@ if ($rowCount != -1) {
$sql = "SELECT `ps`.*, `p`.* $sql";
foreach (dbFetchRows($sql, array($device_id)) as $stp_ports_db) {
$stp_ports_db = cleanPort($stp_ports_db);
$bridge_device = dbFetchRow("SELECT `devices`.*, `stp`.`device_id`, `stp`.`bridgeAddress` FROM `devices` JOIN `stp` ON `devices`.`device_id`=`stp`.`device_id` WHERE `stp`.`bridgeAddress` = ?", array($stp_ports_db['designatedBridge']));
$root_device = dbFetchRow("SELECT `devices`.*, `stp`.`device_id`, `stp`.`bridgeAddress` FROM `devices` JOIN `stp` ON `devices`.`device_id`=`stp`.`device_id` WHERE `stp`.`bridgeAddress` = ?", array($stp_ports_db['designatedRoot']));
$response[] = array (
'port_id' => generate_port_link($stp_ports_db, $stp_ports_db['ifName'])."<br>".display($stp_ports_db['ifAlias']),
'port_id' => generate_port_link($stp_ports_db, $stp_ports_db['ifName'])."<br>".$stp_ports_db['ifAlias'],
'priority' => $stp_ports_db['priority'],
'state' => $stp_ports_db['state'],
'enable' => $stp_ports_db['enable'],

View File

@ -118,9 +118,9 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format'])) {
$src = md5($src);
}
$sif = ifNameDescr(dbFetchRow("SELECT * FROM ports WHERE `port_id` = ?", array($link['local_port_id'])), $device);
$sif = cleanPort(dbFetchRow("SELECT * FROM ports WHERE `port_id` = ?", array($link['local_port_id'])), $device);
if ($remote_port_id) {
$dif = ifNameDescr(dbFetchRow("SELECT * FROM ports WHERE `port_id` = ?", array($link['remote_port_id'])));
$dif = cleanPort(dbFetchRow("SELECT * FROM ports WHERE `port_id` = ?", array($link['remote_port_id'])));
} else {
$dif['label'] = $link['remote_port'];
$dif['port_id'] = $link['remote_hostname'] . '/' . $link['remote_port'];

View File

@ -75,7 +75,8 @@ if (bill_permitted($bill_id)) {
// Collected Earlier
foreach ($ports as $port) {
$portalias = (empty($port['ifAlias']) ? '' : ' - '.display($port['ifAlias']).'');
$port = cleanPort($port);
$portalias = (empty($port['ifAlias']) ? '' : ' - '.$port['ifAlias'].'');
echo '<div class="list-group-item">';
echo generate_port_link($port, $port['ifName'].$portalias).' on '.generate_device_link($port);

View File

@ -106,8 +106,9 @@ if ($bill_data['bill_type'] == 'cdr') {
?>
<div class="list-group">
<?php foreach ($ports as $port) {
$port = cleanPort($port);
$emptyCheck = true;
$portalias = (empty($port['ifAlias']) ? '' : ' - '.display($port['ifAlias']).'');
$portalias = (empty($port['ifAlias']) ? '' : ' - '.$port['ifAlias'].'');
?>
<div class="list-group-item">

View File

@ -4,6 +4,7 @@ $pagetitle[] = 'Deleted ports';
if ($vars['purge'] == 'all') {
foreach (dbFetchRows("SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = '1' AND D.device_id = P.device_id") as $interface) {
$interface = cleanPort($interface);
if (port_permitted($interface['port_id'], $interface['device_id'])) {
delete_port($interface['port_id']);
echo '<div class=infobox>Deleted '.generate_device_link($interface).' - '.generate_port_link($interface).'</div>';
@ -11,6 +12,7 @@ if ($vars['purge'] == 'all') {
}
} elseif ($vars['purge']) {
$interface = dbFetchRow('SELECT * from `ports` AS P, `devices` AS D WHERE `port_id` = ? AND D.device_id = P.device_id', array($vars['purge']));
$interface = cleanPort($interface);
if (port_permitted($interface['port_id'], $interface['device_id'])) {
delete_port($interface['port_id']);
}
@ -22,7 +24,7 @@ echo '<table class="table table-hover table-condensed">';
echo "<tr><td>Device</td><td>Port</td><td></td><td><a href='deleted-ports/purge=all/'><i class='fa fa-times'></i> Purge All</a></td></tr>";
foreach (dbFetchRows("SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = '1' AND D.device_id = P.device_id", array(), true) as $interface) {
$interface = ifLabel($interface, $interface);
$interface = cleanPort($interface, $interface);
if (port_permitted($interface['port_id'], $interface['device_id'])) {
echo '<tr class=list>';
echo '<td width=250>'.generate_device_link($interface).'</td>';

View File

@ -50,6 +50,7 @@ function printEntPhysical($ent, $level, $class)
if ($ent['ifIndex']) {
$interface = dbFetchRow('SELECT * FROM `ports` WHERE ifIndex = ? AND device_id = ?', array($ent['ifIndex'], $device['device_id']));
$interface = cleanPort($interface);
$ent['entPhysicalName'] = generate_port_link($interface);
}

View File

@ -31,6 +31,7 @@ foreach (dbFetchRows('SELECT * FROM `hrDevice` WHERE `device_id` = ? ORDER BY `h
} elseif ($hrdevice['hrDeviceType'] == 'hrDeviceNetwork') {
$int = str_replace('network interface ', '', $hrdevice['hrDeviceDescr']);
$interface = dbFetchRow('SELECT * FROM ports WHERE device_id = ? AND ifDescr = ?', array($device['device_id'], $int));
$interface = cleanPort($interface);
if ($interface['ifIndex']) {
echo '<td>'.generate_port_link($interface).'</td>';

View File

@ -60,7 +60,7 @@ if ($ports['total']) {
$ifsep = '';
foreach (dbFetchRows("SELECT * FROM `ports` WHERE device_id = ? AND `deleted` != '1'", array($device['device_id'])) as $data) {
$data = ifNameDescr($data);
$data = cleanPort($data);
$data = array_merge($data, $device);
echo "$ifsep".generate_port_link($data, makeshortif(strtolower($data['label'])));
$ifsep = ', ';

View File

@ -130,6 +130,7 @@ if ($vars['subview'] == 'top10') {
$addy = dbFetchRow('SELECT * FROM ipv4_mac where mac_address = ?', array($acc['mac']));
// $name = gethostbyaddr($addy['ipv4_address']); FIXME - Maybe some caching for this?
$arp_host = dbFetchRow('SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id', array($addy['ipv4_address']));
$arp_host = cleanPort($arp_host);
if ($arp_host) {
$arp_name = generate_device_link($arp_host);
$arp_name .= ' '.generate_port_link($arp_host);

View File

@ -29,6 +29,7 @@ echo "<a href='#' onmouseover=\"return overlib('<img src=\'$yearly_url\'>', LEFT
<img src='$yearly_traffic' border=0></a>";
foreach (dbFetchRows('SELECT * FROM `ports` WHERE `pagpGroupIfIndex` = ? and `device_id` = ?', array($port['ifIndex'], $device['device_id'])) as $member) {
$member = cleanPort($member);
echo "$br<i class='fa fa-anchor fa-lg icon-theme' aria-hidden='true'></i> <strong>".generate_port_link($member).' (PAgP)</strong>';
$br = '<br />';
}

View File

@ -55,6 +55,7 @@ foreach ($vlans as $vlan) {
echo '<td>';
$vsep = '';
foreach ($vlan_ports as $otherport) {
$otherport = cleanPort($otherport);
echo $vsep.generate_port_link($otherport, makeshortif($otherport['ifDescr']));
if ($otherport['untagged']) {
echo '(U)';

View File

@ -102,17 +102,18 @@ if ($vars['view'] == 'minigraphs') {
// FIXME - FIX THIS. UGLY.
foreach (dbFetchRows('select * from ports WHERE device_id = ? ORDER BY ifIndex', array($device['device_id'])) as $port) {
$port = cleanPort($port, $device);
echo "<div style='display: block; padding: 3px; margin: 3px; min-width: 183px; max-width:183px; min-height:90px; max-height:90px; text-align: center; float: left; background-color: #e9e9e9;'>
<div style='font-weight: bold;'>".makeshortif($port['ifDescr']).'</div>
<a href="'.generate_port_url($port)."\" onmouseover=\"return overlib('\
<div style=\'background-color: #ffffff;\'>\
<div style=\'font-size: 16px; padding:5px; font-weight: bold; color: #555;\'>".$device['hostname'].' - '.$port['ifDescr'].'</div>\
'.display($port['ifAlias'])." \
'.$port['ifAlias']." \
<img src=\'graph.php?type=".$graph_type.'&amp;id='.$port['port_id'].'&amp;from='.$from.'&amp;to='.$config['time']['now']."&amp;width=450&amp;height=150\'>\
</div>\
', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\" >"."<img src='graph.php?type=".$graph_type.'&amp;id='.$port['port_id'].'&amp;from='.$from.'&amp;to='.$config['time']['now']."&amp;width=180&amp;height=45&amp;legend=no'>
</a>
<div style='font-size: 9px;'>".substr(short_port_descr(display($port['ifAlias'])), 0, 32).'</div>
<div style='font-size: 9px;'>".substr(short_port_descr($port['ifAlias']), 0, 32).'</div>
</div>';
}

View File

@ -11,6 +11,7 @@ echo '<tr><th>Local Port</th>
</tr>';
foreach (dbFetchRows('SELECT * FROM links AS L, ports AS I WHERE I.device_id = ? AND I.port_id = L.local_port_id', array($device['device_id'])) as $neighbour) {
$neighbour = cleanPort($neighbour);
if ($bg_colour == $list_colour_b) {
$bg_colour = $list_colour_a;
} else {
@ -18,12 +19,12 @@ foreach (dbFetchRows('SELECT * FROM links AS L, ports AS I WHERE I.device_id = ?
}
echo '<tr bgcolor="'.$bg_colour.'">';
echo '<td><span style="font-weight: bold;">'.generate_port_link($neighbour).'</span><br />'.display($neighbour['ifAlias']).'</td>';
echo '<td><span style="font-weight: bold;">'.generate_port_link($neighbour).'</span><br />'.$neighbour['ifAlias'].'</td>';
if (is_numeric($neighbour['remote_port_id']) && $neighbour['remote_port_id']) {
$remote_port = get_port_by_id($neighbour['remote_port_id']);
$remote_port = cleanPort(get_port_by_id($neighbour['remote_port_id']));
$remote_device = device_by_id_cache($remote_port['device_id']);
echo '<td>'.generate_port_link($remote_port).'<br />'.display($remote_port['ifAlias']).'</td>';
echo '<td>'.generate_port_link($remote_port).'<br />'.$remote_port['ifAlias'].'</td>';
echo '<td>'.generate_device_link($remote_device).'<br />'.$remote_device['hardware'].'</td>';
} else {
echo '<td>'.$neighbour['remote_port'].'</td>';

View File

@ -37,6 +37,7 @@ print_optionbar_end();
echo '<table cellpadding=5 cellspacing=0 class=devicetable width=100%>';
foreach (dbFetchRows('SELECT * FROM pseudowires AS P, ports AS I WHERE P.port_id = I.port_id AND I.device_id = ? ORDER BY I.ifDescr', array($device['device_id'])) as $pw_a) {
$pw_a = cleanPort($pw_a);
$i = 0;
while ($i < count($linkdone)) {
$thislink = $pw_a['device_id'].$pw_a['port_id'];
@ -52,6 +53,7 @@ foreach (dbFetchRows('SELECT * FROM pseudowires AS P, ports AS I WHERE P.port_id
AND P.cpwVcID = ? AND P.port_id = I.port_id',
array( $pw_a['peer_device_id'], $pw_a['cpwVcID'],)
);
$pw_b = cleanPort($pw_b);
if (!port_permitted($pw_a['port_id'])) {
$skip = 'yes';
@ -73,7 +75,7 @@ foreach (dbFetchRows('SELECT * FROM pseudowires AS P, ports AS I WHERE P.port_id
echo "<tr style=\"background-color: #$bg;\"><td rowspan=2 style='font-size:18px; padding:4px;'>".$pw_a['cpwVcID'].'</td><td>'.generate_port_link($pw_a)."</td>
<td rowspan=2> <i class='fa fa-arrows-alt fa-lg icon-theme' aria-hidden='true'></i> </td>
<td>".generate_device_link($pw_b).'</td><td>'.generate_port_link($pw_b).'</td></tr>';
echo "<tr style=\"background-color: #$bg;\"><td colspan=2>".display($pw_a['ifAlias']).'</td><td>'.display($pw_b['ifAlias']).'</td></tr>';
echo "<tr style=\"background-color: #$bg;\"><td colspan=2>".$pw_a['ifAlias'].'</td><td>'.$pw_b['ifAlias'].'</td></tr>';
if ($vars['view'] == 'minigraphs') {
echo "<tr style=\"background-color: #$bg;\"><td></td><td colspan=2>";

View File

@ -160,6 +160,7 @@ foreach (dbFetchRows("SELECT * FROM `bgpPeers` WHERE `device_id` = ? $extra_sql
unset($peerhost);
}
$peerhost = cleanPort($peerhost);
if (is_array($peerhost)) {
// $peername = generate_device_link($peerhost);
$peername = generate_device_link($peerhost).' '.generate_port_link($peerhost);

View File

@ -98,6 +98,7 @@ foreach (dbFetchRows('SELECT * FROM `ospf_instances` WHERE `device_id` = ?', arr
</thead>
</div>';
foreach (dbFetchRows("SELECT * FROM `ospf_ports` AS O, `ports` AS P WHERE O.`ospfIfAdminStat` = 'enabled' AND O.`device_id` = ? AND O.`ospfIfAreaId` = ? AND P.port_id = O.port_id", array($device['device_id'], $area['ospfAreaId'])) as $ospfport) {
$ospfport = cleanPort($ospfport);
$port_status_color = 'default';
if ($ospfport['ospfIfAdminStat'] == 'enabled') {

View File

@ -59,7 +59,7 @@ if (is_admin() === true || is_read() === true) {
if ($config['warn']['ifdown']) {
foreach (dbFetchRows($sql) as $interface) {
if (!$interface['deleted']) {
$interface = ifNameDescr($interface);
$interface = cleanPort($interface);
generate_front_box(
'alert alert-danger',
generate_device_link($interface, shorthost($interface['hostname'])) . "<br />

View File

@ -44,10 +44,11 @@ if ($if_list) {
echo '</td></tr>';
foreach ($ports as $port) {
$port = cleanPort($port);
$done = 'yes';
unset($class);
$port['ifAlias'] = str_ireplace($type.': ', '', display($port['ifAlias']));
$port['ifAlias'] = str_ireplace('[PNI]', 'Private', display($port['ifAlias']));
$port['ifAlias'] = str_ireplace($type.': ', '', $port['ifAlias']);
$port['ifAlias'] = str_ireplace('[PNI]', 'Private', $port['ifAlias']);
$ifclass = ifclass($port['ifOperStatus'], $port['ifAdminStatus']);
if ($bg == '#ffffff') {
$bg = '#e5e5e5';

View File

@ -20,7 +20,7 @@ foreach ($ports as $port) {
}
if (port_permitted($port['port_id'], $port['device_id'])) {
$port = ifLabel($port, $device);
$port = cleanPort($port, $device);
$graph_type = 'port_'.$subformat;

View File

@ -37,6 +37,7 @@ print_optionbar_end();
echo '<table cellpadding=5 cellspacing=0 class=devicetable width=100%>';
foreach (dbFetchRows('SELECT * FROM pseudowires AS P, ports AS I, devices AS D WHERE P.port_id = I.port_id AND I.device_id = D.device_id ORDER BY D.hostname,I.ifDescr') as $pw_a) {
$pw_a = cleanPort($pw_a);
$i = 0;
while ($i < count($linkdone)) {
$thislink = $pw_a['device_id'].$pw_a['port_id'];
@ -56,6 +57,8 @@ foreach (dbFetchRows('SELECT * FROM pseudowires AS P, ports AS I, devices AS D W
)
);
$pw_b = cleanPort($pw_b);
if (!port_permitted($pw_a['port_id'])) {
$skip = 'yes';
}
@ -76,7 +79,7 @@ foreach (dbFetchRows('SELECT * FROM pseudowires AS P, ports AS I, devices AS D W
echo "<tr style=\"background-color: #$bg;\"><td rowspan=2 style='font-size:18px; padding:4px;'>".$pw_a['cpwVcID'].'</td><td>'.generate_device_link($pw_a).'</td><td>'.generate_port_link($pw_a)."</td>
<td rowspan=2> <i class='fa fa-arrows-alt fa-lg icon-theme' aria-hidden='true'></i> </td>
<td>".generate_device_link($pw_b).'</td><td>'.generate_port_link($pw_b).'</td></tr>';
echo "<tr style=\"background-color: #$bg;\"><td colspan=2>".display($pw_a['ifAlias']).'</td><td colspan=2>'.display($pw_b['ifAlias']).'</td></tr>';
echo "<tr style=\"background-color: #$bg;\"><td colspan=2>".$pw_a['ifAlias'].'</td><td colspan=2>'.$pw_b['ifAlias'].'</td></tr>';
if ($vars['view'] == 'minigraphs') {
echo "<tr style=\"background-color: #$bg;\"><td></td><td colspan=2>";

View File

@ -150,6 +150,7 @@ if ($_SESSION['userlevel'] >= '5') {
unset($seperator);
foreach ($ports[$device['vrf_id']][$device['device_id']] as $port) {
$port = cleanPort($port);
$port = array_merge($device, $port);
switch ($_GET['optc']) {
@ -167,7 +168,7 @@ if ($_SESSION['userlevel'] >= '5') {
text-align: center; float: left; background-color: ".$list_colour_b_b.";'>
<div style='font-weight: bold;'>".makeshortif($port['ifDescr']).'</div>';
print_port_thumbnail($port);
echo "<div style='font-size: 9px;'>".substr(short_port_descr(display($port['ifAlias'])), 0, 22).'</div>
echo "<div style='font-size: 9px;'>".substr(short_port_descr($port['ifAlias']), 0, 22).'</div>
</div>';
break;

View File

@ -1511,16 +1511,27 @@ function clean($value)
/**
* @param $value
* @param array $purifier_config (key, value pair)
* @return string
*/
function display($value)
function display($value, $purifier_config = array())
{
/** @var HTMLPurifier $purifier */
global $config, $purifier;
// If $purifier_config is non-empty then we don't want
// to convert html tags and allow these to be controlled
// by purifier instead.
if (empty($purifier_config)) {
$value = htmlentities($value);
}
if (!isset($purifier)) {
// initialize HTML Purifier here since this is the only user
$p_config = HTMLPurifier_Config::createDefault();
$p_config->set('Cache.SerializerPath', $config['temp_dir']);
foreach ($purifier_config as $k => $v) {
$p_config->set($k, $v);
}
$purifier = new HTMLPurifier($p_config);
}

View File

@ -41,7 +41,7 @@ foreach (dbFetchRows($sql, array($deviceid)) as $entry) {
$ip = $entry['ipv4_address'];
$mac = $entry['mac_address'];
$if = $entry['port_id'];
$int = ifLabel($if);
$int = cleanPort($if);
$label = $int['label'];
// Even though match_network is done inside discover_new_device, we do it here

View File

@ -65,7 +65,7 @@ function discover_new_device($hostname, $device = '', $method = '', $interface =
device_by_id_cache($remote_device_id, 1);
if ($remote_device_id && is_array($device) && !empty($method)) {
$extra_log = '';
$int = ifNameDescr($interface);
$int = cleanPort($interface);
if (is_array($int)) {
$extra_log = ' (port ' . $int['label'] . ') ';
}

View File

@ -56,17 +56,21 @@ function rewrite_entity_descr($descr)
}
function ifNameDescr($interface, $device = null)
{
return ifLabel($interface, $device);
}
function ifLabel($interface, $device = null)
/**
* Clean port values for html display
* Add label to the port array (usually one of ifAlias, ifName, ifDescr)
*
* @param array $interface
* @param null|array $device
* @return mixed
*/
function cleanPort($interface, $device = null)
{
global $config;
$interface['ifAlias'] = display($interface['ifAlias']);
$interface['ifName'] = display($interface['ifName']);
$interface['ifDescr'] = display($interface['ifDescr']);
if (!$device) {
$device = device_by_id_cache($interface['device_id']);

View File

@ -104,4 +104,19 @@ class CommonFunctionsTest extends \PHPUnit_Framework_TestCase
$this->assertFalse(is_ip('192.168.0.1', 'ipv6'));
$this->assertFalse(is_ip('not_an_ip'));
}
public function testDisplay()
{
$this->assertEquals('&lt;html&gt;string&lt;/html&gt;', display('<html>string</html>'));
$this->assertEquals('&lt;script&gt;alert("test")&lt;/script&gt;', display('<script>alert("test")</script>'));
$tmp_config = array(
'HTML.Allowed' => 'b,iframe,i,ul,li,h1,h2,h3,h4,br,p',
'HTML.Trusted' => true,
'HTML.SafeIframe' => true,
);
$this->assertEquals('<b>Bold</b>', display('<b>Bold</b>', $tmp_config));
$this->assertEquals('', display('<script>alert("test")</script>', $tmp_config));
}
}