(
'xos12' => 'xos12ReadLLDPStatus',
'vrp53' => 'vrp53ReadLLDPStatus',
+ 'vrp55' => 'vrp55ReadLLDPStatus',
);
$gwrxlator['get8021q'] = array
(
}
$command .= " ${name}";
}
- $outputlines = queryGateway
- (
- 'sendfile',
- array ($command)
- );
- foreach ($tmpnames as $name)
- unlink ($name);
+ try
+ {
+ queryGateway ('sendfile', array ($command));
+ foreach ($tmpnames as $name)
+ unlink ($name);
+ }
+ catch (RTGatewayError $e)
+ {
+ foreach ($tmpnames as $name)
+ unlink ($name);
+ throw $e;
+ }
}
// Query something through a gateway and get some text in return. Return that text.
global $remote_username;
$tmpfilename = tempnam ('', 'RackTables-sendfile-');
$endpoint = str_replace (' ', '\ ', $endpoint); // the gateway dispatcher uses read (1) to assign arguments
- $outputlines = queryGateway
- (
- 'sendfile',
- array ("submit ${remote_username} ${endpoint} ${handlername} ${tmpfilename}")
- );
- $output = file_get_contents ($tmpfilename);
- unlink ($tmpfilename);
+ try
+ {
+ queryGateway ('sendfile', array ("submit ${remote_username} ${endpoint} ${handlername} ${tmpfilename}"));
+ $output = file_get_contents ($tmpfilename);
+ unlink ($tmpfilename);
+ }
+ catch (RTGatewayError $e)
+ {
+ unlink ($tmpfilename);
+ throw $e;
+ }
if ($output === FALSE)
throw new RTGatewayError ('failed to read temporary file');
- // Being here means having 'OK!' in the response.
- return oneLiner (66, array ($handlername)); // ignore provided "Ok" text
}
function gwSendFileToObject ($object_id = 0, $handlername, $filetext = '')
if (count ($endpoints) > 1)
return oneLiner (162); // can't pick an address
$endpoint = str_replace (' ', '+', $endpoints[0]);
- return gwRecvFile ($endpoint, $handlername, $output);
+ gwRecvFile ($endpoint, $handlername, $output);
}
function detectDeviceBreed ($object_id)
throw new RTGatewayError ('cannot pick management address');
$endpoint = str_replace (' ', '\ ', str_replace (' ', '+', $endpoints[0]));
$tmpfilename = tempnam ('', 'RackTables-deviceconfig-');
- $outputlines = queryGateway
- (
- 'deviceconfig',
- array ("${command} ${endpoint} ${breed} ${tmpfilename}")
- );
- $configtext = file_get_contents ($tmpfilename);
- unlink ($tmpfilename);
+ try
+ {
+ queryGateway ('deviceconfig', array ("${command} ${endpoint} ${breed} ${tmpfilename}"));
+ $configtext = file_get_contents ($tmpfilename);
+ unlink ($tmpfilename);
+ }
+ catch (RTGatewayError $e)
+ {
+ unlink ($tmpfilename);
+ throw $e;
+ }
if ($configtext === FALSE)
throw new RTGatewayError ('failed to read temporary file');
// Being here means it was alright.
unlink ($tmpfilename);
throw new RTGatewayError ('failed to write to temporary file');
}
- $outputlines = queryGateway
- (
- 'deviceconfig',
- array ("deploy ${endpoint} ${breed} ${tmpfilename}")
- );
- unlink ($tmpfilename);
+ try
+ {
+ queryGateway ('deviceconfig', array ("deploy ${endpoint} ${breed} ${tmpfilename}"));
+ unlink ($tmpfilename);
+ }
+ catch (RTGatewayError $e)
+ {
+ unlink ($tmpfilename);
+ throw $e;
+ }
}
// Read provided output of "show cdp neighbors detail" command and
return $ret;
}
+function vrp55ReadLLDPStatus ($input)
+{
+ $ret = array();
+ foreach (explode ("\n", $input) as $line)
+ {
+ $matches = array();
+ switch (TRUE)
+ {
+ case preg_match ('/^(.+) has 1 neighbors:$/', $line, $matches):
+ $ret['current']['local_port'] = ios12ShortenIfName ($matches[1]);
+ break;
+ case preg_match ('/^Port ID type :([^ ]+)/', $line, $matches):
+ $ret['current']['PortIdSubtype'] = $matches[1];
+ break;
+ case preg_match ('/^Port ID :(.+)$/', $line, $matches):
+ $ret['current']['PortId'] = $matches[1];
+ break;
+ case preg_match ('/^System name :(.+)$/', $line, $matches):
+ if
+ (
+ array_key_exists ('current', $ret) and
+ array_key_exists ('PortIdSubtype', $ret['current']) and
+ ($ret['current']['PortIdSubtype'] == 'interfaceAlias' or $ret['current']['PortIdSubtype'] == 'interfaceName') and
+ array_key_exists ('PortId', $ret['current']) and
+ array_key_exists ('local_port', $ret['current'])
+ )
+ $ret[$ret['current']['local_port']] = array
+ (
+ 'device' => $matches[1],
+ 'port' => ios12ShortenIfName ($ret['current']['PortId']),
+ );
+ unset ($ret['current']);
+ break;
+ default:
+ }
+ }
+ unset ($ret['current']);
+ return $ret;
+}
+
function vrp53ReadHNDPStatus ($input)
{
$ret = array();
if ($line[0] != ' ') // end of interface section
{
// save work, if it makes sense
- switch (TRUE)
+ switch ($work['current']['mode'])
{
- case $work['current']['ignore']:
- $work['portdata'][$work['current']['port_name']] = array
- (
- 'mode' => 'none',
- 'allowed' => array(),
- 'native' => 0,
- );
- break;
- case 'access' == $work['current']['mode']:
+ case 'access':
if (!array_key_exists ('access vlan', $work['current']))
$work['current']['access vlan'] = 1;
$work['portdata'][$work['current']['port_name']] = array
'native' => $work['current']['access vlan'],
);
break;
- case 'trunk' == $work['current']['mode']:
+ case 'trunk':
if (!array_key_exists ('trunk native vlan', $work['current']))
$work['current']['trunk native vlan'] = 1;
if (!array_key_exists ('trunk allowed vlan', $work['current']))
'native' => $effective_native,
);
break;
+ case 'SKIP':
+ break;
+ case 'IP':
default:
// dot1q-tunnel, dynamic, private-vlan or even none --
// show in returned config and let user decide, if they
break;
case preg_match ('@^ channel-group @', $line):
// port-channel subinterface config follows that of the master interface
+ $work['current']['mode'] = 'SKIP';
+ break;
case preg_match ('@^ ip address @', $line):
// L3 interface does no switchport functions
- $work['current']['ignore'] = TRUE;
+ $work['current']['mode'] = 'IP';
break;
default: // suppress warning on irrelevant config clause
}
if (!array_key_exists ($req_port_name, $desired_config))
{
echo '<td>';
- startPortlet ('port duplicator');
- echo '<table border=0 align=center>';
- printOpFormIntro ('save8021QConfig', array ('mutex_rev' => $vswitch['mutex_rev'], 'form_mode' => 'duplicate'));
$port_options = array();
foreach ($desired_config as $pn => $portinfo)
if (editable8021QPort ($portinfo))
$port_options[$pn] = same8021QConfigs ($desired_config[$pn], $cached_config[$pn]) ?
$pn : "${pn} (*)";
- echo '<tr><td>' . getSelect ($port_options, array ('name' => 'from_port')) . '</td></tr>';
- echo '<tr><td>↓ ↓ ↓</td></tr>';
- echo '<tr><td>' . getSelect ($port_options, array ('name' => 'to_ports[]', 'size' => getConfigVar ('MAXSELSIZE'), 'multiple' => 1)) . '</td></tr>';
- echo '<tr><td>' . getImageHREF ('COPY', 'duplicate', TRUE) . '</td></tr>';
- echo '</form></table>';
- finishPortlet();
+ if (count ($port_options) < 2)
+ echo ' ';
+ else
+ {
+ startPortlet ('port duplicator');
+ echo '<table border=0 align=center>';
+ printOpFormIntro ('save8021QConfig', array ('mutex_rev' => $vswitch['mutex_rev'], 'form_mode' => 'duplicate'));
+ echo '<tr><td>' . getSelect ($port_options, array ('name' => 'from_port')) . '</td></tr>';
+ echo '<tr><td>↓ ↓ ↓</td></tr>';
+ echo '<tr><td>' . getSelect ($port_options, array ('name' => 'to_ports[]', 'size' => getConfigVar ('MAXSELSIZE'), 'multiple' => 1)) . '</td></tr>';
+ echo '<tr><td>' . getImageHREF ('COPY', 'duplicate', TRUE) . '</td></tr>';
+ echo '</form></table>';
+ finishPortlet();
+ }
echo '</td>';
}
else
)
return formatVLANName ($vdom['vlanlist'][$port['native']], 'label');
+ static $vlanpermissions = array();
+ if (!array_key_exists ($port['native'], $vlanpermissions))
+ {
+ $vlanpermissions[$port['native']] = array();
+ foreach (array_keys ($vdom['vlanlist']) as $to)
+ if
+ (
+ permitted (NULL, NULL, 'save8021QConfig', array (array ('tag' => '$fromvlan_' . $port['native']))) and
+ permitted (NULL, NULL, 'save8021QConfig', array (array ('tag' => '$tovlan_' . $to)))
+ )
+ $vlanpermissions[$port['native']][] = $to;
+ }
$ret = "<input type=hidden name=pn_${nports} value=${port_name}>";
$ret .= "<input type=hidden name=pm_${nports} value=access>";
$options = array();
(
($vlan_id != $port['native'] or $port['mode'] == 'trunk') and
$vlan_info['vlan_type'] != 'alien' and
+ in_array ($vlan_id, $vlanpermissions[$port['native']]) and
matchVLANFilter ($vlan_id, $port['wrt_vlans'])
)
$options[$vlan_id] = formatVLANName ($vlan_info, 'option');
if
(
!array_key_exists ($local_port, $myports) or
- NULL === $remote_id = searchByMgmtHostname ($remote['device']) or
+ (
+ NULL === $remote_id = searchByMgmtHostname ($remote['device']) and
+ NULL === $remote_id = lookupEntityByString ('object', $remote['device'])
+ ) or
!count ($remote_port_ids = getPortIDs ($remote_id, $remote['port']))
)
{