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

@@ -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'],