function addIPv6Prefix() { assertStringArg('range'); assertStringArg('name', TRUE); $taglist = genericAssertion('taglist', 'array0'); global $sic; $vlan_ck = empty($sic['vlan_ck']) ? NULL : genericAssertion('vlan_ck', 'uint-vlan1'); $net_id = createIPv6Prefix($_REQUEST['range'], $sic['name'], isCheckSet('is_connected'), $taglist); $net_cell = spotEntity('ipv6net', $net_id); if (isset($vlan_ck)) { if (considerConfiguredConstraint($net_cell, 'VLANIPV4NET_LISTSRC')) { commitSupplementVLANIPv6($vlan_ck, $net_id); } else { showError("VLAN binding to network " . mkCellA($net_cell) . " is restricted in config"); } } showSuccess('IP network ' . mkA($_REQUEST['range'], 'ipv6net', $net_id) . ' has been created'); }
// don't indicate failure unless the pidfile is 15 minutes or more old if ($current_time < $pidfile_mtime + 15 * 60) { exit(0); } print_message_line("Failed to lock {$filename}, already locked by PID " . trim(fgets($fp, 10))); exit(1); } ftruncate($fp, 0); fwrite($fp, getmypid() . "\n"); // don't close $fp yet: we need to keep an flock } // fetch all the needed data from DB (preparing for DB connection loss) $switch_queue = array(); foreach ($switch_list as $object_id) { $cell = spotEntity('object', $object_id); $new_disabled = !considerConfiguredConstraint($cell, 'SYNC_802Q_LISTSRC'); $queue = detectVLANSwitchQueue(getVLANSwitchInfo($object_id)); if ($queue == 'disabled' xor $new_disabled) { usePreparedExecuteBlade('UPDATE VLANSwitch SET out_of_sync="yes", last_error_ts=NOW(), last_errno=? WHERE object_id=?', array($new_disabled ? E_8021Q_SYNC_DISABLED : E_8021Q_NOERROR, $object_id)); } elseif (in_array($queue, $todo[$options['mode']])) { $switch_queue[] = $cell; } } // YOU SHOULD NOT USE DB FUNCTIONS BELOW IN THE PARENT PROCESS // THE PARENT'S DB CONNECTION IS LOST DUE TO RECONNECTING IN THE CHILD $fork_slots = getConfigVar('SYNCDOMAIN_MAX_PROCESSES'); $do_fork = $fork_slots > 1 and extension_loaded('pcntl'); if ($fork_slots > 1 and !$do_fork) { throw new RackTablesError('PHP extension \'pcntl\' not found, can not use childs', RackTablesError::MISCONFIGURED); } $switches_working = 0;
function snmpgeneric_tabtrigger() { // display tab only on IPv4 Objects return considerConfiguredConstraint(spotEntity('object', getBypassValue()), 'IPV4OBJ_LISTSRC') ? 'std' : ''; }
function renderObject8021QSyncSchedule($object, $vswitch, $maxdecisions) { echo '<table border=0 cellspacing=0 cellpadding=3 align=center>'; // FIXME: sort rows newest event last $rows = array(); if (!considerConfiguredConstraint($object, 'SYNC_802Q_LISTSRC')) { $rows['auto sync'] = '<span class="trerror">disabled by operator</span>'; } $rows['last local change'] = datetimestrFromTimestamp($vswitch['last_change']) . ' (' . formatAge($vswitch['last_change']) . ')'; $rows['device out of sync'] = $vswitch['out_of_sync']; if ($vswitch['out_of_sync'] == 'no') { $push_duration = $vswitch['last_push_finished'] - $vswitch['last_push_started']; $rows['last sync session with device'] = datetimestrFromTimestamp($vswitch['last_push_started']) . ' (' . formatAge($vswitch['last_push_started']) . ', ' . ($push_duration < 0 ? 'interrupted' : "lasted {$push_duration}s") . ')'; } if ($vswitch['last_errno']) { $rows['failed'] = datetimestrFromTimestamp($vswitch['last_error_ts']) . ' (' . strerror8021Q($vswitch['last_errno']) . ')'; } if (NULL !== ($new_rows = callHook('alter8021qSyncSummaryItems', $rows))) { $rows = $new_rows; } foreach ($rows as $th => $td) { echo "<tr><th width='50%' class=tdright>{$th}:</th><td class=tdleft colspan=2>{$td}</td></tr>"; } echo '<tr><th class=tdright>run now:</th><td class=tdcenter>'; printOpFormIntro('exec8021QPull'); echo getImageHREF('prev', 'pull remote changes in', TRUE, 101) . '</form></td><td class=tdcenter>'; if ($maxdecisions) { echo getImageHREF('COMMIT gray', 'cannot push due to version conflict(s)'); } else { printOpFormIntro('exec8021QPush'); echo getImageHREF('COMMIT', 'push local changes out', TRUE, 102) . '</form>'; } echo '</td></tr>'; echo '</table>'; }
function initRackTablesObject($rackDatas) { // zabbix host data $params = array('output' => 'extend'); $result = doPost('host.get', $params); $hosts = isset($result['result']) ? $result['result'] : array(); $objectDatas = array(); foreach ($hosts as $host) { $object_type_id = 4; $object_name = isset($host['host']) ? $host['host'] : ""; $object_label = ""; $object_asset_no = ""; $taglist = array(); $has_problems = $host['status'] == 0 ? 'no' : 'yes'; $object_id = commitAddObject($object_name, $object_label, $object_type_id, $object_asset_no, $taglist); usePreparedUpdateBlade('Object', array('has_problems' => $has_problems), array('id' => $object_id)); $objectDatas[$host['hostid']] = $object_id; // set hostgroup $params = array('output' => array('name'), 'hostids' => array($host['hostid'])); $result = doPost('hostgroup.get', $params); $hostgroups = isset($result['result']) ? $result['result'] : array(); $rack_ids = array(); $_REQUEST = array(); foreach ($hostgroups as $hostgroup) { if (isset($rackDatas[$hostgroup['name']])) { $rack = $rackDatas[$hostgroup['name']]; amplifyCell($rack); array_push($rack_ids, $rack['id']); $height = $rack['height']; for ($i = 0; $i < 3; $i++) { for ($j = $height; $j > 0; $j--) { if ($rack[$j][$i]['state'] == 'F') { # state == "T" : mounted $_REQUEST['atom_' . $rack['id'] . "_{$j}" . "_{$i}"] = 'on'; break 2; } } } } } $_REQUEST['object_id'] = $object_id; $_REQUEST['rackmulti'] = $rack_ids; $object = spotEntity('object', $object_id); $changecnt = 0; // Get a list of rack ids which are parents of the object $parentRacks = reduceSubarraysToColumn(getParents($object, 'rack'), 'id'); $workingRacksData = array(); foreach ($_REQUEST['rackmulti'] as $cand_id) { if (!isset($workingRacksData[$cand_id])) { $rackData = spotEntity('rack', $cand_id); amplifyCell($rackData); $workingRacksData[$cand_id] = $rackData; } else { $rackData = $workingRacksData[$cand_id]; } $is_ro = !rackModificationPermitted($rackData, 'updateObjectAllocation', FALSE); // It's zero-U mounted to this rack on the form, but not in the DB. Mount it. if (isset($_REQUEST["zerou_{$cand_id}"]) && !in_array($cand_id, $parentRacks)) { if ($is_ro) { continue; } $changecnt++; commitLinkEntities('rack', $cand_id, 'object', $object_id); } // It's not zero-U mounted to this rack on the form, but it is in the DB. Unmount it. if (!isset($_REQUEST["zerou_{$cand_id}"]) && in_array($cand_id, $parentRacks)) { if ($is_ro) { continue; } $changecnt++; commitUnlinkEntities('rack', $cand_id, 'object', $object_id); } } foreach ($workingRacksData as &$rd) { applyObjectMountMask($rd, $object_id); } $oldMolecule = getMoleculeForObject($object_id); foreach ($workingRacksData as $rack_id => $rackData) { $is_ro = !rackModificationPermitted($rackData, 'updateObjectAllocation', FALSE); if ($is_ro || !processGridForm($rackData, 'F', 'T', $object_id)) { continue; } $changecnt++; // Reload our working copy after form processing. $rackData = spotEntity('rack', $cand_id); amplifyCell($rackData); applyObjectMountMask($rackData, $object_id); $workingRacksData[$rack_id] = $rackData; } if ($changecnt) { // Log a record. $newMolecule = getMoleculeForObject($object_id); global $remote_username, $sic; usePreparedInsertBlade('MountOperation', array('object_id' => $object_id, 'old_molecule_id' => count($oldMolecule) ? createMolecule($oldMolecule) : NULL, 'new_molecule_id' => count($newMolecule) ? createMolecule($newMolecule) : NULL, 'user_name' => $remote_username, 'comment' => empty($sic['comment']) ? NULL : $sic['comment'])); } // set IP $params = array('output' => 'extend', 'hostids' => $host['hostid']); $result = doPost('hostinterface.get', $params); $hostinterfaces = isset($result['result']) ? $result['result'] : array(); foreach ($hostinterfaces as $interface) { if (isset($interface['ip']) && $interface['ip'] != '127.0.0.1') { $allocs = getObjectIPAllocations($object_id); $current_ips = array(); foreach ($allocs as $alloc) { $ip = $alloc["addrinfo"]["ip"]; $current_ips[$ip] = $ip; } $ip = $interface['ip']; if (!in_array($ip, array_values($current_ips))) { // new IP $ip_bin = ip_parse($ip); if (null == getIPAddressNetworkId($ip_bin)) { // if ip is not exists, adding it into RackTables IPv4Prefix. $range = substr($ip, 0, strripos($ip, '.')) . '.0/24'; $vlan_ck = NULL; $net_id = createIPv4Prefix($range, 'admim', isCheckSet('is_connected'), $taglist); $net_cell = spotEntity('ipv4net', $net_id); if (isset($vlan_ck)) { if (considerConfiguredConstraint($net_cell, 'VLANIPV4NET_LISTSRC')) { commitSupplementVLANIPv4($vlan_ck, $net_id); } } } bindIPToObject($ip_bin, $object_id, "", ""); } } } } return $objectDatas; }
function triggerCactiGraphs() { if ('' == getConfigVar('CACTI_URL')) { return ''; } if (count(getCactiGraphsForObject(getBypassValue())) or considerConfiguredConstraint(spotEntity('object', getBypassValue()), 'CACTI_LISTSRC')) { return 'std'; } else { return ''; } }
function formatAttributeValue($record) { if ('date' == $record['type']) { return date(getConfigVar('DATETIME_FORMAT'), $record['value']); } else { if (!isset($record['key'])) { if ($record['id'] == 3) { $protos_to_try = array('ssh' => 'SSH_OBJS_LISTSRC', 'telnet' => 'TELNET_OBJS_LISTSRC'); foreach ($protos_to_try as $proto => $cfgvar) { if (considerConfiguredConstraint(NULL, $cfgvar)) { return "<a title='Open {$proto} session' class='mgmt-link' href='" . $proto . '://' . $record['a_value'] . "'>{$record['a_value']}</a>"; } } } return isset($record['href']) ? "<a href=\"" . $record['href'] . "\">{$record['a_value']}</a>" : $record['a_value']; } else { $href = makeHref(array('page' => 'depot', 'tab' => 'default', 'andor' => 'and', 'cfe' => '{$attr_' . $record['id'] . '_' . $record['key'] . '}')); $result = "<a href='{$href}'>" . $record['a_value'] . "</a>"; if (isset($record['href'])) { $result .= " <a class='img-link' href='{$record['href']}'>" . getImageHREF('html', 'vendor's info page') . "</a>"; } return $result; } } }
// don't indicate failure unless the pidfile is 15 minutes or more old if ($current_time < $pidfile_mtime + 15 * 60) { exit(0); } print_message_line("Failed to lock {$filename}, already locked by PID " . mb_substr(file_get_contents($filename), 0, 6)); exit(1); } ftruncate($fp, 0); fwrite($fp, getmypid() . "\n"); fclose($fp); // fetch all the needed data from DB (preparing for DB connection loss) $switch_queue = array(); foreach ($switch_list as $object_id) { if (in_array(detectVLANSwitchQueue(getVLANSwitchInfo($object_id)), $todo[$options['mode']])) { $cell = spotEntity('object', $object_id); if (considerConfiguredConstraint($cell, 'SYNC_802Q_LISTSRC')) { $switch_queue[] = $cell; } } } // YOU SHOULD NOT USE DB FUNCTIONS BELOW IN THE PARENT PROCESS // THE PARENT'S DB CONNECTION IS LOST DUE TO RECONNECTING IN THE CHILD $fork_slots = getConfigVar('SYNCDOMAIN_MAX_PROCESSES'); $do_fork = $fork_slots > 1 and extension_loaded('pcntl'); if ($fork_slots > 1 and !$do_fork) { throw new RackTablesError('PHP extension \'pcntl\' not found, can not use childs', RackTablesError::MISCONFIGURED); } $switches_working = 0; $switchesdone = 0; foreach ($switch_queue as $object) { if ($do_fork) {
function triggerMuninGraphs() { if (!count(getMuninServers())) { return ''; } if (count(getMuninGraphsForObject(getBypassValue())) or considerConfiguredConstraint(spotEntity('object', getBypassValue()), 'MUNIN_LISTSRC')) { return 'std'; } else { return ''; } }
function getobject($object_id, &$rack = null) { if (!$object_id) { return null; } if (!isset($this->cache['o' . $object_id])) { $object = spotEntity('object', $object_id); $object['IPV4OBJ'] = considerConfiguredConstraint($object, 'IPV4OBJ_LISTSRC'); /* get more object info */ if ($object['IPV4OBJ']) { // ip addresses //amplifyCell($object); /* get ports, ipv4, ipv6, nat4 and files */ $object['ipv4'] = getObjectIPv4Allocations($object_id); $object['portip'] = array(); foreach ($object['ipv4'] as $ipv4) { $object['portip'][$ipv4['osif']] = $ipv4['addrinfo']['ip']; } } if ($object['container_id']) { $container = $this->getobject($object['container_id']); } $this->cache['o' . $object_id] = $object; } else { $object = $this->cache['o' . $object_id]; } $rack = $this->getrack($object['rack_id']); return $object; }
function get8021QDeployQueues() { global $dqtitle; $ret = array(); foreach (array_keys($dqtitle) as $qcode) { if ($qcode != 'disabled') { $ret[$qcode] = array('enabled' => array(), 'disabled' => array()); } } foreach (getVLANSwitches() as $object_id) { $vswitch = getVLANSwitchInfo($object_id); if ('' != ($qcode = detectVLANSwitchQueue($vswitch))) { $cell = spotEntity('object', $vswitch['object_id']); $enabled_key = considerConfiguredConstraint($cell, 'SYNC_802Q_LISTSRC') ? 'enabled' : 'disabled'; $ret[$qcode][$enabled_key][] = $vswitch; } } return $ret; }
function sl_getsnmp(&$object, $debug = false) { $object_id = $object['id']; $object_name = $object['name']; if (isset($object['SNMP'])) { if ($debug) { echo "INFO: No SNMP Object \"{$object_name}\" ID: {$object_id}<br>"; } return null; } if (!considerConfiguredConstraint($object, 'IPV4OBJ_LISTSRC')) { if ($debug) { echo "INFO: No IPv4 Object \"{$object_name}\" ID: {$object_id}<br>"; } return False; } /* get object saved SNMP settings */ $snmpconfig = explode(':', strtok($object['comment'], "\n\r")); if ($snmpconfig[0] != "SNMP") { if ($debug) { echo "INFO: No saved SNMP Settings for \"{$object_name}\" ID: {$object_id}<br>"; } return False; } /* set objects SNMP ip address */ $ipv4 = $snmpconfig[1]; if (0) { var_dump_html($snmpconfig); } if (!$ipv4) { echo "ERROR: no ip for \"{$object_name}!!\"<br>"; return False; } $object['SNMP']['IP'] = $ipv4; if (count($snmpconfig) < 4) { echo "SNMP Error: Missing Setting for {$object_name} ({$ipv4})"; return False; } /* SNMP prerequisites successfull */ $s = new sl_ifxsnmp($snmpconfig[2], $ipv4, $snmpconfig[3], $snmpconfig); if (!$s->error) { /* get snmp data */ $iftable = $s->getiftable(); if ($debug && $s->error) { echo $s->getError(); } if ($iftable) { return $iftable; } else { echo "SNMP Error: " . $s->getError() . " for {$object_name} ({$ipv4})<br>"; return False; } } else { echo "SNMP Config Error: " . $s->error . " for \"{$object_name}\"<br>"; return False; } return null; }