function switchportInfoJS($object_id) { $available_ops = array('link' => array('op' => 'get_link_status', 'gw' => 'getportstatus'), 'conf' => array('op' => 'get_port_conf', 'gw' => 'get8021q'), 'mac' => array('op' => 'get_mac_list', 'gw' => 'getmaclist'), 'portmac' => array('op' => 'get_port_mac_list', 'gw' => 'getportmaclist')); $breed = detectDeviceBreed($object_id); $allowed_ops = array(); foreach ($available_ops as $prefix => $data) { if (permitted('object', 'liveports', $data['op']) and validBreedFunction($breed, $data['gw'])) { $allowed_ops[] = $prefix; } } // make JS array with allowed items $list = ''; foreach ($allowed_ops as $item) { $list .= "'" . addslashes($item) . "', "; } $list = trim($list, ", "); addJS('js/jquery.thumbhover.js'); addCSS('css/jquery.contextmenu.css'); addJS('js/jquery.contextmenu.js'); addJS("enabled_elements = [ {$list} ];", TRUE); addJS('js/portinfo.js'); }
function gwRetrieveDeviceConfig($object_id, $command) { require_once 'deviceconfig.php'; global $breedfunc; $breed = detectDeviceBreed($object_id); assertBreedFunction($breed, $command); $objectInfo = spotEntity('object', $object_id); $endpoints = findAllEndpoints($object_id, $objectInfo['name']); if (count($endpoints) == 0) { throw new RTGatewayError('no management address set'); } if (count($endpoints) > 1) { throw new RTGatewayError('cannot pick management address'); } $endpoint = str_replace(' ', '\\ ', str_replace(' ', '+', $endpoints[0])); $tmpfilename = tempnam('', 'RackTables-deviceconfig-'); 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. return $breedfunc["{$breed}-{$command}-main"](dos2unix($configtext)); }
function switchportInfoJS($object_id) { $available_ops = array('link' => array('op' => 'get_link_status', 'gw' => 'getportstatus'), 'conf' => array('op' => 'get_port_conf', 'gw' => 'get8021q'), 'mac' => array('op' => 'get_mac_list', 'gw' => 'getmaclist'), 'portmac' => array('op' => 'get_port_mac_list', 'gw' => 'getportmaclist')); $breed = detectDeviceBreed($object_id); $allowed_ops = array(); foreach ($available_ops as $prefix => $data) { if (permitted('object', 'liveports', $data['op']) and validBreedFunction($breed, $data['gw'])) { $allowed_ops[] = $prefix; } } addJS('js/jquery.thumbhover.js'); addCSS('css/jquery.contextmenu.css'); addJS('js/jquery.contextmenu.js'); addJS("enabled_elements = " . json_encode($allowed_ops), TRUE); addJS('js/portinfo.js'); }
function trigger_anyDP($command, $constraint) { if (validBreedFunction(detectDeviceBreed(getBypassValue()), $command) and considerConfiguredConstraint(spotEntity('object', getBypassValue()), $constraint)) { return 'std'; } return ''; }
function setDevice8021QConfig($object_id, $pseudocode, $vlan_names) { // FIXME: this is a perfect place to log intended changes // $object_id argument isn't used by default translating functions, but // may come in handy for overloaded versions of these. $commands = translateDeviceCommands($object_id, $pseudocode, $vlan_names); $breed = detectDeviceBreed($object_id); $output = queryTerminal($object_id, $commands, FALSE); // throw an exception if Juniper did not allow to enter config mode or to commit changes if ($breed == 'jun10') { if (preg_match('/>\\s*configure exclusive\\s*$[^#>]*?^error:/sm', $output)) { throw new RTGatewayError("Configuration is locked by other user"); } elseif (preg_match('/#\\s*commit\\s*$([^#]*?^error: .*?)$/sm', $output, $m)) { throw new RTGatewayError("Commit failed: {$m[1]}"); } } }
function shortenIfName($if_name, $breed = NULL, $object_id = NULL) { // this is a port name we invented in snmp.php, do not translate it if (preg_match('/^AC-in(-[12])?$/', $if_name)) { return $if_name; } global $current_query_breed; if (!isset($breed)) { if (isset($object_id)) { $breed = detectDeviceBreed($object_id); } elseif (isset($current_query_breed)) { $breed = $current_query_breed; } } switch ($breed) { case 'ios12': return ios12ShortenIfName_real($if_name); case 'vrp53': case 'vrp55': return vrp5xShortenIfName($if_name); case 'vrp85': return vrp85ShortenIfName($if_name); case 'iosxr4': return iosxr4ShortenIfName($if_name); } // default case is outside of switch() return ios12ShortenIfName($if_name); }