function renderInterfacesStats($object_id) { global $nextorder; global $port_use_age; addCSS("/* Live Interfaces */\n\t\t.text_green { color: #00cc00; }\n\t\t.text_yellow { color: #ff9900; }\n\t\t.text_red { color: #ff0000; }", TRUE); startPortlet('Interfaces statistics'); //get data: show version try { $uptime = queryDevice($object_id, 'getuptime'); } catch (RackTablesError $e) { } echo "<table width='100%'><tr>"; if (permitted(NULL, NULL, 'get_link_status')) { //get data: show interfaces try { $interfaces = queryDevice($object_id, 'getinterfaces'); } catch (RackTablesError $e) { } if (!empty($interfaces)) { $last_reboot = time_convert($uptime); echo "<td"; echo $last_reboot < $port_use_age ? " class='text_red'>" : $last_reboot > 262080 ? " class='text_green'>" : ">"; echo $uptime . "</tr>"; echo "<table width='80%' class='widetable' cellspacing=0 cellpadding='5px' align='center'><tr><th>Port<th>Link status<th>Last input<th>Last clear<th>Input packets<th>Output packets<th>Description</tr>"; $order = 'even'; foreach ($interfaces as $pn => $int) { echo "<tr class='row_{$order}'>"; $order = $nextorder[$order]; echo '<td>' . $pn . '<td'; echo $int['status'] == "connected" ? " class='text_green'>" : ">"; echo $int['status'] . '<td'; echo time_convert($int['last']) > $port_use_age ? " class='text_yellow'>" : ">"; echo $int['last'] . '<td'; echo time_convert($int['clear']) > 0 ? time_convert($int['clear']) < $port_use_age ? " class='text_red'>" : ">" : ">"; echo $int['clear']; echo '<td>' . $int['in_pkts']; echo '<td>' . $int['out_pkts']; echo '<td>' . $int['desc']; echo '</tr>'; } echo "</table></td>"; } } echo "</td></tr></table>"; finishPortlet(); }
function ripeTab($id) { $ripe_db = "http://rest.db.ripe.net/search.xml?source=ripe&query-string="; assertUIntArg('id'); $net = spotEntity('ipv4net', $id); loadIPAddrList($net); $startip = ip4_bin2int($net['ip_bin']); $endip = ip4_bin2int(ip_last($net)); // Get Data from RIPE $ripe_inetnum_str = ip4_format(ip4_int2bin($startip)) . ' - ' . ip4_format(ip4_int2bin($endip)); $ripe_query = $ripe_db . ip4_format(ip4_int2bin($startip)); $ripe_result_str = file_get_contents($ripe_query, false, NULL); $ripe_result = simplexml_load_string($ripe_result_str); // Check inetnum object $ripe_inetnum_check = "/whois-resources/objects/object[@type='inetnum']/attributes/attribute[@name='inetnum'][@value='{$ripe_inetnum_str}']"; $ripe_inetnum = $ripe_result->xpath($ripe_inetnum_check); if (empty($ripe_inetnum)) { echo "<div class=trerror><center><h1>{$net['ip']}/{$net['mask']}</h1><h2>{$net['name']}</h2></center></div>\n"; } else { $ripe_netname_check = "/whois-resources/objects/object[@type='inetnum']/attributes/attribute[@name='netname']"; $ripe_netname = $ripe_result->xpath($ripe_netname_check); $netname = trim($ripe_netname[0]['value']); if (strcmp($netname, $net['name']) != 0) { echo "<div class=trwarning><center><h1>{$net['ip']}/{$net['mask']}</h1><h2>{$net['name']}</h2></center></div><div><center>"; } else { echo "<div class=trok><center><h1>{$net['ip']}/{$net['mask']}</h1><h2>{$net['name']}</h2></center></div><div><center>"; } printOpFormIntro('importRipeData', array('ripe_query' => $ripe_query, 'net_id' => $id, 'net_name' => $netname)); echo "<input type=submit value='Import RIPE records in to comments'></center></div>"; echo "</form>"; } // echo '<em>'.$ripe_query.'</em>'; echo "<table border=0 width='100%'><tr><td class=pcleft>"; $filedir = realpath(dirname(__FILE__)); $ripe_xsl = simplexml_load_file($filedir . '/ripe_html.xsl'); startPortlet("RIPE Information Datatbase<br>{$ripe_inetnum_str}"); $proc = new XSLTProcessor(); $proc->importStyleSheet($ripe_xsl); echo '<div class=commentblock>' . trim($proc->transformToXML($ripe_result)) . '</div>'; finishPortlet(); echo "</td></tr></table>\n"; }
function renderMuninConfig() { $servers = getMuninServers(); startPortlet('Munin servers (' . count($servers) . ')'); echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>'; echo '<tr><th>base URL</th><th>graph(s)</th></tr>'; foreach ($servers as $server) { echo '<tr align=left valign=top><td>' . stringForTD($server['base_url']) . '</td>'; echo "<td class=tdright>{$server['num_graphs']}</td></tr>"; } echo '</table>'; finishPortlet(); }
function renderVLANMembership($object_id) { try { $data = getSwitchVLANs($object_id); } catch (RTGatewayError $re) { showWarning('Device configuration unavailable:<br>' . $re->getMessage()); return; } list($vlanlist, $portlist, $maclist) = $data; $vlanpermissions = array(); foreach ($portlist as $port) { if (array_key_exists($port['vlanid'], $vlanpermissions)) { continue; } $vlanpermissions[$port['vlanid']] = array(); foreach (array_keys($vlanlist) as $to) { if (permitted(NULL, NULL, 'setPortVLAN', array(array('tag' => '$fromvlan_' . $port['vlanid']), array('tag' => '$vlan_' . $port['vlanid']))) and permitted(NULL, NULL, 'setPortVLAN', array(array('tag' => '$tovlan_' . $to), array('tag' => '$vlan_' . $to)))) { $vlanpermissions[$port['vlanid']][] = $to; } } } if (isset($_REQUEST['hl_port_id'])) { assertUIntArg('hl_port_id'); $hl_port_id = intval($_REQUEST['hl_port_id']); $object = spotEntity('object', $object_id); amplifyCell($object); foreach ($object['ports'] as $port) { if (mb_strlen($port['name']) && $port['id'] == $hl_port_id) { $hl_port_name = $port['name']; break; } } } echo '<table border=0 width="100%"><tr><td colspan=3>'; startPortlet('Current status'); echo "<table class=widetable cellspacing=3 cellpadding=5 align=center width='100%'><tr>"; printOpFormIntro('setPortVLAN'); $portcount = count($portlist); echo "<input type=hidden name=portcount value=" . $portcount . ">\n"; $portno = 0; $ports_per_row = 12; foreach ($portlist as $port) { // Don't let wide forms break our fancy pages. if ($portno % $ports_per_row == 0) { if ($portno > 0) { echo "</tr>\n"; } echo "<tr><th>" . ($portno + 1) . "-" . ($portno + $ports_per_row > $portcount ? $portcount : $portno + $ports_per_row) . "</th>"; } $td_class = 'port_'; if ($port['status'] == 'notconnect') { $td_class .= 'notconnect'; } elseif ($port['status'] == 'disabled') { $td_class .= 'disabled'; } elseif ($port['status'] != 'connected') { $td_class .= 'unknown'; } elseif (!isset($maclist[$port['portname']])) { $td_class .= 'connected_none'; } else { $maccount = 0; foreach ($maclist[$port['portname']] as $vlanid => $addrs) { $maccount += count($addrs); } if ($maccount == 1) { $td_class .= 'connected_single'; } else { $td_class .= 'connected_multi'; } } if (isset($hl_port_name) and strcasecmp($hl_port_name, $port['portname']) == 0) { $td_class .= (strlen($td_class) ? ' ' : '') . 'border_highlight'; } echo "<td class='{$td_class}'>" . $port['portname'] . '<br>'; echo "<input type=hidden name=portname_{$portno} value=" . $port['portname'] . '>'; if ($port['vlanid'] == 'trunk') { echo "<input type=hidden name=vlanid_{$portno} value='trunk'>"; echo "<select disabled multiple='multiple' size=1><option>TRUNK</option></select>"; } elseif ($port['vlanid'] == 'routed') { echo "<input type=hidden name=vlanid_{$portno} value='routed'>"; echo "<select disabled multiple='multiple' size=1><option>ROUTED</option></select>"; } elseif (!array_key_exists($port['vlanid'], $vlanpermissions) or !count($vlanpermissions[$port['vlanid']])) { echo "<input type=hidden name=vlanid_{$portno} value={$port['vlanid']}>"; echo "<select disabled name=vlanid_{$portno}>"; echo "<option value={$port['vlanid']} selected>{$port['vlanid']}</option>"; echo "</select>"; } else { echo "<select name=vlanid_{$portno}>"; // A port may belong to a VLAN, which is absent from the VLAN table, this is normal. // We must be able to render its SELECT properly at least. $in_table = FALSE; foreach ($vlanpermissions[$port['vlanid']] as $v) { echo "<option value={$v}"; if ($v == $port['vlanid']) { echo ' selected'; $in_table = TRUE; } echo ">{$v}</option>\n"; } if (!$in_table) { echo "<option value={$port['vlanid']} selected>{$port['vlanid']}</option>\n"; } echo "</select>"; } $portno++; echo "</td>"; } echo "</tr><tr><td colspan=" . ($ports_per_row + 1) . "><input type=submit value='Save changes'></form></td></tr></table>"; finishPortlet(); echo '</td></tr><tr><td class=pcleft>'; startPortlet('VLAN table'); echo '<table class=cooltable cellspacing=0 cellpadding=5 align=center width="100%">'; echo "<tr><th>ID</th><th>Description</th></tr>"; $order = 'even'; global $nextorder; foreach ($vlanlist as $id => $descr) { echo "<tr class=row_{$order}><td class=tdright>{$id}</td><td class=tdleft>{$descr}</td></tr>"; $order = $nextorder[$order]; } echo '</table>'; finishPortlet(); echo '</td><td class=pcright>'; startPortlet('Color legend'); echo '<table>'; echo "<tr><th>port state</th><th>color code</th></tr>"; echo "<tr><td>not connected</td><td class=port_notconnect>SAMPLE</td></tr>"; echo "<tr><td>disabled</td><td class=port_disabled>SAMPLE</td></tr>"; echo "<tr><td>unknown</td><td class=port_unknown>SAMPLE</td></tr>"; echo "<tr><td>connected with none MAC addresses active</td><td class=port_connected_none>SAMPLE</td></tr>"; echo "<tr><td>connected with 1 MAC addresses active</td><td class=port_connected_single>SAMPLE</td></tr>"; echo "<tr><td>connected with 1+ MAC addresses active</td><td class=port_connected_multi>SAMPLE</td></tr>"; echo '</table>'; finishPortlet(); echo '</td><td class=pcright>'; if (count($maclist)) { startPortlet('MAC address table'); echo '<table border=0 class=cooltable align=center cellspacing=0 cellpadding=5>'; echo "<tr><th>Port</th><th>VLAN ID</th><th>MAC address</th></tr>\n"; $order = 'even'; foreach ($maclist as $portname => $portdata) { foreach ($portdata as $vlanid => $addrgroup) { foreach ($addrgroup as $addr) { echo "<tr class=row_{$order}><td class=tdleft>{$portname}</td><td class=tdleft>{$vlanid}</td>"; echo "<td class=tdleft>{$addr}</td></tr>\n"; $order = $nextorder[$order]; } } } echo '</table>'; finishPortlet(); } // End of main table. echo '</td></tr></table>'; }
function renderNewVSGForm() { startPortlet('Add new VS group'); printOpFormIntro('add'); echo '<table border=0 cellpadding=5 cellspacing=0 align=center>'; echo '<tr valign=bottom><th>Name:</th><td class="tdleft">'; echo '<input type=text name=name></td></tr>'; echo '<tr><th>Tags:</th><td class="tdleft">'; printTagsPicker(); echo '</td></tr>'; echo '</table>'; printImageHREF('CREATE', 'create virtual service', TRUE); echo '</form>'; finishPortlet(); }
/** * * Fing tab handler * */ function FingTab($id) { $can_import = permitted(NULL, NULL, 'importFingData'); // // allocation settings // // address allocation code, IPv4 networks view $aac_left = array('regular' => '', 'virtual' => '<span class="aac-left" title="Loopback">L:</span>', 'shared' => '<span class="aac-left" title="Shared">S:</span>', 'router' => '<span class="aac-left" title="Router">R:</span>', 'point2point' => '<span class="aac-left" title="Point-to-point">P:</span>'); // // header // global $pageno, $tabno; $maxperpage = getConfigVar('IPV4_ADDRS_PER_PAGE'); $range = spotEntity('ipv4net', $id); loadIPAddrList($range); echo "<center><h1>{$range['ip']}/{$range['mask']}</h1><h2>{$range['name']}</h2></center>\n"; // // execute fing // try { $known_ips = get_fing_scan($range['ip'], $range['mask']); $fing_cfg = get_fing_settings($range['ip'], $range['mask']); $fing_gw = $fing_cfg["gateway"]; } catch (FingException $e) { render_fing_error("Could not get network scan via fing:", $e->getMessage()); return FALSE; } echo "<table class=objview border=0 width='100%'><tr><td class=pcleft>"; startPortlet('overlook fing (via: ' . $fing_gw . ')'); // // pagination // if (isset($_REQUEST['pg'])) { $page = $_REQUEST['pg']; } else { $page = 0; } $startip = ip4_bin2int($range['ip_bin']); $endip = ip4_bin2int(ip_last($range)); $numpages = 0; if ($endip - $startip > $maxperpage) { $numpages = ($endip - $startip) / $maxperpage; $startip = $startip + $page * $maxperpage; $endip = $startip + $maxperpage - 1; } echo "<center>"; if ($numpages) { echo '<h3>' . ip4_format(ip4_int2bin($startip)) . ' ~ ' . ip4_format(ip4_int2bin($endip)) . '</h3>'; } for ($i = 0; $i < $numpages; $i++) { if ($i == $page) { echo "<b>{$i}</b> "; } else { echo "<a href='" . makeHref(array('page' => $pageno, 'tab' => $tabno, 'id' => $id, 'pg' => $i)) . "'>{$i}</a> "; } } echo "</center>"; if ($can_import) { printOpFormIntro('importFingData', array('addrcount' => $endip - $startip + 1)); $box_counter = 1; } echo "<table class='widetable' border=0 cellspacing=0 cellpadding=5 align='center'>\n"; echo "<tr><th class='tdleft'>address</th><th class='tdleft'>state</th><th class='tdleft'>current name</th><th class='tdleft'>DNS name</th><th class='tdleft'>MAC</th><th class='tdleft'>Allocation</th>"; if ($can_import) { echo '<th>import</th>'; } echo "</tr>\n"; // // Loop through all IPs // $cnt_match = $cnt_missing = $cnt_mismatch = $cnt_total = 0; for ($ip = $startip; $ip <= $endip; $ip++) { $cnt_total++; $print_cbox = FALSE; $ip_bin = ip4_int2bin($ip); $addr = isset($range['addrlist'][$ip_bin]) ? $range['addrlist'][$ip_bin] : array('name' => '', 'reserved' => 'no'); $straddr = ip4_format($ip_bin); list($fing_hostname, $fing_state, $fing_mac_vendor) = get_fing_info($straddr, $known_ips); $ip_is_up = strtoupper($fing_state) == "UP" ? TRUE : FALSE; if ($can_import) { echo "<input type=hidden name=addr_{$cnt_total} value={$straddr}>\n"; echo "<input type=hidden name=descr_{$cnt_total} value={$fing_hostname}>\n"; echo "<input type=hidden name=rsvd_{$cnt_total} value={$addr['reserved']}>\n"; } $skip_dns_check = FALSE; echo "<tr"; // Ignore network and broadcast addresses if ($ip == $startip && $addr['name'] == 'network' || $ip == $endip && $addr['name'] == 'broadcast') { echo " class='trbusy'"; $skip_dns_check = TRUE; } elseif (!$ip_is_up) { echo " class='trnull'"; } // set line color depending if we have the name already in the DB if (!$skip_dns_check) { if ($addr['name'] == $fing_hostname) { if (strlen($fing_hostname)) { echo ' class=trok'; $cnt_match++; } } elseif (!strlen($addr['name']) or !strlen($fing_hostname)) { echo ' class=trwarning'; $print_cbox = TRUE; $cnt_missing++; } else { echo ' class=trerror'; $print_cbox = TRUE; $cnt_mismatch++; } } //IP echo "><td class='tdleft"; if (isset($range['addrlist'][$ip_bin]['class']) and strlen($range['addrlist'][$ip_bin]['class'])) { echo ' ' . $range['addrlist'][$ip_bin]['class']; } echo "'><a href='" . makeHref(array('page' => 'ipaddress', 'ip' => $straddr)) . "'>{$straddr}</a></td>"; //other columns if ($skip_dns_check) { echo "<td class='tdleft'> </td>"; } else { if (!$ip_is_up) { echo "<td class='tdleft'>" . $fing_state . "</td>"; } else { echo "<td class='tdleft'><div class='strong'>" . $fing_state . "</div></td>"; } } echo "<td class=tdleft>{$addr['name']}</td>"; echo "<td class='tdleft'>" . $fing_hostname . "</td>"; echo "<td class='tdleft'>" . $fing_mac_vendor . "</td>"; //allocation echo "<td>"; $delim = ''; if ($addr['reserved'] == 'yes') { echo "<strong>RESERVED</strong> "; $delim = '; '; } foreach ($addr['allocs'] as $ref) { echo $delim . $aac_left[$ref['type']]; echo makeIPAllocLink($ip_bin, $ref, TRUE); $delim = '; '; } if ($delim != '') { $delim = '<br>'; } foreach ($addr['vslist'] as $vs_id) { $vs = spotEntity('ipv4vs', $vs_id); echo $delim . mkA("{$vs['name']}:{$vs['vport']}/{$vs['proto']}", 'ipv4vs', $vs['id']) . '→'; $delim = '<br>'; } foreach ($addr['vsglist'] as $vs_id) { $vs = spotEntity('ipvs', $vs_id); echo $delim . mkA($vs['name'], 'ipvs', $vs['id']) . '→'; $delim = '<br>'; } foreach ($addr['rsplist'] as $rsp_id) { $rsp = spotEntity('ipv4rspool', $rsp_id); echo "{$delim}→" . mkA($rsp['name'], 'ipv4rspool', $rsp['id']); $delim = '<br>'; } echo "</td>"; // import column if ($can_import) { echo '<td>'; if ($print_cbox) { echo "<input type=checkbox name=import_{$cnt_total} id=atom_1_" . $box_counter++ . "_1>"; } else { echo ' '; } echo '</td>'; } echo "</tr>"; } if ($can_import && $box_counter > 1) { echo '<tr><td colspan=4 align=center><input type=submit value="Import selected records"></td><td colspan=2 align=right>'; addJS('js/racktables.js'); echo --$box_counter ? "<a href='javascript:;' onclick=\"toggleColumnOfAtoms(1, 1, {$box_counter})\">(toggle selection)</a>" : ' '; echo '</td></tr>'; } echo "</table>"; if ($can_import) { echo '</form>'; } finishPortlet(); echo "</td><td class=pcright>"; // // PING Statistics // startPortlet('ping stats'); $cnt_ping_up = get_fing_up_count($known_ips); echo "<table border=0 width='100%' cellspacing=0 cellpadding=2>"; echo "<tr class=trok><th class=tdright>Replied to Ping</th><td class=tdleft>{$cnt_ping_up}</td></tr>\n"; echo "<tr class=trwarning><th class=tdright>No Response</th><td class=tdleft>" . ($cnt_total - $cnt_ping_up) . "</td></tr>\n"; echo "</table>\n"; finishPortlet(); // // DNS Statistics // startPortlet('dns stats'); echo "<table border=0 width='100%' cellspacing=0 cellpadding=2>"; echo "<tr class=trok><th class=tdright>Exact matches:</th><td class=tdleft>{$cnt_match}</td></tr>\n"; echo "<tr class=trwarning><th class=tdright>Missing from DB/DNS:</th><td class=tdleft>{$cnt_missing}</td></tr>\n"; if ($cnt_mismatch) { echo "<tr class=trerror><th class=tdright>Mismatches:</th><td class=tdleft>{$cnt_mismatch}</td></tr>\n"; } echo "</table>\n"; finishPortlet(); }
function renderPatchCableConfiguration() { global $nextorder; echo '<table class=objview border=0 width="100%"><tr><td class=pcleft>'; startPortlet('Connectors'); renderSimpleTableWithOriginViewer(getPatchCableConnectorList(), array('header' => 'Connector', 'key' => 'id', 'value' => 'connector', 'width' => 32)); finishPortlet(); startPortlet('Connector compatibility'); renderTwoColumnCompatTableViewer(getPatchCableConnectorCompat(), array('header' => 'Cable type', 'key' => 'pctype_id', 'value' => 'pctype', 'width' => 64), array('header' => 'Connector', 'key' => 'connector_id', 'value' => 'connector', 'width' => 32)); finishPortlet(); echo '</td><td class=pcright>'; startPortlet('Cable types'); renderSimpleTableWithOriginViewer(getPatchCableTypeList(), array('header' => 'Cable type', 'key' => 'id', 'value' => 'pctype', 'width' => 64)); finishPortlet(); startPortlet('Cable types and port outer interfaces'); renderTwoColumnCompatTableViewer(getPatchCableOIFCompat(), array('header' => 'Cable type', 'key' => 'pctype_id', 'value' => 'pctype', 'width' => 64), array('header' => 'Outer interface', 'key' => 'oif_id', 'value' => 'oif_name', 'width' => 48)); finishPortlet(); echo '</td></tr></table>'; }
function renderEditUCSForm() { startPortlet('UCS Actions'); printOpFormIntro('autoPopulateUCS'); echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>'; echo "<tr><th class=tdright><label for=ucs_login>Login:</label></th>"; echo "<td class=tdleft colspan=2><input type=text name=ucs_login id=ucs_login></td></tr>\n"; echo "<tr><th class=tdright><label for=ucs_password>Password:</label></th>"; echo "<td class=tdleft colspan=2><input type=password name=ucs_password id=ucs_password></td></tr>\n"; echo "<tr><th colspan=3><input type=checkbox name=use_terminal_settings id=use_terminal_settings>"; echo "<label for=use_terminal_settings>Use Credentials from terminal_settings()</label></th></tr>\n"; echo "<tr><th class=tdright>Actions:</th><td class=tdleft>"; printImageHREF('DQUEUE sync_ready', 'Auto-populate UCS', TRUE); echo '</td><td class=tdright>'; echo "<a href='" . makeHrefProcess(array('op' => 'cleanupUCS', 'object_id' => getBypassValue())) . "' onclick=\"javascript:return confirm('Are you sure you want to cleanup UCS Domain?')\">" . getImageHREF('CLEAR', 'Clean-up UCS domain') . "</a>"; echo "</td></tr></table></form>\n"; finishPortlet(); }
function renderEditUCSForm() { startPortlet('UCS Actions'); printOpFormIntro('autoPopulateUCS'); echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>'; echo "<tr><th class=tdright><label for=ucs_login>Login:</label></th>"; echo "<td class=tdleft colspan=2><input type=text name=ucs_login id=ucs_login></td></tr>\n"; echo "<tr><th class=tdright><label for=ucs_password>Password:</label></th>"; echo "<td class=tdleft colspan=2><input type=password name=ucs_password id=ucs_password></td></tr>\n"; echo "<tr><th colspan=3><input type=checkbox name=use_terminal_settings id=use_terminal_settings>"; echo "<label for=use_terminal_settings>Use Credentials from terminal_settings()</label></th></tr>\n"; echo "<tr><th class=tdright>Actions:</th><td class=tdleft>"; printImageHREF('DQUEUE sync_ready', 'Auto-populate UCS', TRUE); echo '</td><td class=tdright>'; echo getOpLink(array('op' => 'cleanupUCS'), '', 'CLEAR', 'Clean-up UCS domain', 'need-confirmation'); echo "</td></tr></table></form>\n"; finishPortlet(); }
function renderNodePingChecks($object_id) { $accounts = getNodePingAccounts(); $account_options = array(); foreach ($accounts as $account) { $account_options[$account['id']] = $account['name']; } startPortlet('Add new check'); echo "<table cellspacing=0 cellpadding=5 align='center'>\n"; echo "<tr><th> </th><th>Account</th><th>Check ID</th><th></th><th> </th></tr>\n"; printOpFormIntro('add'); echo '<tr><td>'; printImageHREF('add', 'add check', TRUE); echo '</td><td>' . getSelect($account_options, array('name' => 'account_id')); echo '</td><td><input type=text size=25 name=np_check_id tabindex=101></td><td>'; printImageHREF('add', 'add check', TRUE); echo "</td></tr></form></table>\n"; finishPortlet(); $checks = getUnlinkedNodePingChecks($object_id); if (count($checks) > 0) { $check_options = array(); foreach ($checks as $check) { $check_options[$check['id']] = sprintf("%s - %s", $check['label'], $check['type']); } startPortlet('Link existing check (' . count($checks) . ')'); echo "<table cellspacing=0 cellpadding=5 align='center'>\n"; printOpFormIntro('link'); echo '<tr><td>' . getSelect($check_options, array('name' => 'check_id')); echo '</td><td class=tdleft>'; printImageHREF('ATTACH', 'Link check', TRUE); echo "</td></tr></form></table>\n"; finishPortlet(); } addJs(<<<END function toggleVisibility(tbodyId) { \t\$("#" + tbodyId).toggle(); } END , TRUE); $checks = getNodePingChecks($object_id); startPortlet('NodePing checks (' . count($checks) . ')'); if (count($checks)) { echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n"; echo "<tr><th> </th><th>Type</th><th>Label</th><th>Interval</th><th>Reason</th><th>Result</th><th>Unlink</th><th> </th></tr>\n"; $token = ''; foreach ($checks as $check) { printOpFormIntro('upd', array('check_id' => $check['check_id'])); echo '<tr><td><a href="' . makeHrefProcess(array('op' => 'del', 'check_id' => $check['check_id'])) . '">'; echo getImageHREF('delete', 'Unlink and delete this check') . '</a></td>'; echo "<td><a href=\"#\" onclick=\"toggleVisibility('{$check['check_id']}');\">{$check['type']}</a></td>"; echo "<td>{$check['label']}</td>"; echo "<td>{$check['check_interval']}</td>"; // re-use a nodeping object if it already exists and is using the same token as this check if ($check['token'] != $token) { $nodeping = new NodePingClient(array('token' => $check['token'])); } $token = $check['token']; $np_result_raw = $nodeping->result->get(array('id' => $check['np_check_id'], 'limit' => 5, 'clean' => true)); if (isset($np_result_raw['error'])) { echo "<td colspan=5>Error: {$check_status_raw['error']}</td>"; } else { $np_result = $np_result_raw[0]; if ($np_result['su']) { $reason = ''; $result_str = 'PASS'; $result_class = 'msg_success'; } else { $reason = $np_result['sc']; $result_str = 'FAIL'; $result_class = 'msg_error'; } echo "<td>{$reason}</td>"; echo "<td><span class='{$result_class}'>{$result_str}</span></td>"; } echo '<td class=center><a href="' . makeHrefProcess(array('op' => 'unlink', 'link_id' => $check['link_id'])) . '">'; echo getImageHREF('cut', 'Unlink this check') . '</a></td>'; echo '<td class=tdleft>'; printImageHREF('save', 'Save changes', TRUE); echo "</td></tr>\n"; echo "<tbody id='{$check['check_id']}' style='display:none;'><tr><td colspan=8>"; echo '<table cellspacing=0 cellpadding=5 align=left>'; // override the td styling so it doesn't have a border echo '<tr><th>Account</th><td align=left style="border-top: 0px;">' . getSelect($account_options, array('name' => 'account_id'), $check['account_id']) . '</td></tr>'; echo '<tr><th>Check ID</th><td align=left style="border-top: 0px;"><input type=text size=25 name=np_check_id value="' . $check['np_check_id'] . '"></td></tr>'; echo "<tr><th>Target</th><td align=left style=\"border-top:0px; word-wrap:break-word; max-width:250px;\">{$check['target']}</td></tr>"; echo '</table></form>'; echo '<table cellspacing=0 cellpadding=5 align=right>'; echo '<tr><th colspan=5>Last 5 Results</th></tr>'; echo '<tr><th>Time</th><th>Loc</th><th>Run Time</th><th>Response</th><th>Result</th></tr>'; foreach ($np_result_raw as $np_row) { // time is reported in miliseconds, so trim off the last 3 digits printf('<tr><td>%s</td>', date('H:i:s A', substr($np_row['s'], 0, -3))); printf('<td>%s</td>', strtoupper($np_row['l'][$np_row['s']])); if ($np_row['su']) { $result_str = 'PASS'; $result_class = 'msg_success'; } else { $result_str = 'FAIL'; $result_class = 'msg_error'; } echo "<td>{$np_row['rt']}</td>"; echo "<td>{$np_row['sc']}</td>"; echo "<td><span class='{$result_class}'>{$result_str}</span></td></tr>"; } echo '</table>'; echo "</td></tr></tbody>\n"; } echo "</table>\n"; } finishPortlet(); }
function localfunc_PortGenerator() { global $errorText, $lookFor, $portList, $genText, $valueConfiguration, $searchIt; assertUIntArg('object_id', __FUNCTION__); $object = spotEntity('object', $_REQUEST['object_id']); startPortlet("Port generator"); print "<center><br>"; if (!localverify_PortGenerator($object)) { // // Autoport configuration did not work. Show this and show the error // print "{$lookFor} : Error\n"; if (isset($errorText)) { print $errorText; } } else { // // Show the list of ports that will be generated and provide a link to actually do so // print "<a href='" . makeHrefProcess(array('op' => 'addports', 'page' => 'object', 'object_id' => $object['id'], 'tab' => 'ports')) . "'>Generate the ports for <b>{$object['name']}</b> as listed below NOW</a><br>\n"; print $genText . "<p>"; print "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>"; print "<tr><th>Port name </th><th>Port label </th><th>Port type</th></tr>\n"; foreach ($portList as $aPort) { print "<tr><td>{$aPort['name']}</td><td>{$aPort['label']}</td><td>{$aPort['port_name']}</td></tr>\n"; } print "</table>"; } print "<br></center>"; finishPortlet(); // // Check whether the user is allowed to do an update of the port configurator // // if you do not want this, make sure you add a // deny {$op_updateportgenerator} // for the apprioriate groups (or any allow first and deny for the rest // if (permitted('object', 'portgenerator', null, array(array('tag' => '$op_updateportgenerator')))) { startPortlet("Update autoport configuration"); // // Description of the config rules // print "<center>"; print $genText . "<p>\n"; print "<b>USAGE</b><br><br>"; print "<list1>;<list2>;.... where <listx> is<br>"; print "<start port #>|<port count, use %n for number of ports>|"; print "<port name, use %u for number>|[<port innerinterface id>-]<port type id>[|<port label, use %u for number>]<br><br>"; print "<b>EXAMPLE (for Force10 S4810)</b><br><br>0|48|%u|9-1084|TenGigabitEthernet0/%u;48|4|%u|10-1588|FortyGigE0/48;52|4|%u|10-1588|FortyGigE0/52;56|4|%u|10-1588|FortyGigE0/56;60|4|%u|10-1588|FortyGigE0/60;1|1|RS-232|29|Serial port;1|1|Ethernet|24|ManagementEthernet0/%u;1|2|AC%u|16<br><br>"; print "<b>EXPLANATION (for AC-in ports)</b><br><br> <b>1</b> = starting number,\n <b>2</b> = number of generated ports, \n <b>AC%u</b> = will begin with <b>starting number</b> and create up to the <b>number of generated ports</b>, \n <b>16</b> = the value displayed on the chart below <b>in bold</b> (Notice: Default innerinterface ID is 1 /hardwired/, so the realy value is <b>1-16</b>)<br><br>"; //explains example print "<b>PLEASE NOTE</b><br><br> If you do not add the port that is selected <b>(dictionary value)</b> to the default list in the <b>Ports</b> Tab, \n you will get a <b>foriegn key violation</b> error. \n You must go to the <b>Configuration</b> area on the main page, go to <b>Enable port types</b>\n and hit the <b>Edit</b> tab to place the selected port in either <b>GBIC</b>, <b>hardwired</b>, or any other configuration \n on the page so that the error is not recieved.<br><br><br>"; //Very important to have a sucessful implementation of port generator // // The form that can update the configuration // On top of the table of ports avialabe instead of beneath it // printOpFormIntro('updateportgenerator', array('yId' => $searchIt)); print "<b>Autoport Configuration:</b><br><br><input type='text' style='width:100%; font-size: 16px' name='yConfig' value='"; if ($valueConfiguration) { print $valueConfiguration[0]; } print "'><br><br>\n"; print "<input type='submit' name='autoportconfig' value='"; if ($valueConfiguration) { print "Update"; } else { print "Create"; } print "'>\n"; print "</form>\n"; print "</center><br>"; print "<table border='2' rules=all>\n<tr class=row_odd>"; $isfirst = true; $i = 0; // // List all available port types with their dictionary key // $q = "SELECT IF(iif_id,CONCAT(i.id,'-',o.id),o.id) as ID , IF(iif_id,CONCAT(i.iif_name,' => ',o.oif_name),o.oif_name) as name FROM PortOuterInterface o left join PortInterfaceCompat c on o.id = c.oif_id left join PortInnerInterface i on c.iif_id = i.id order by i.id,o.id"; $result = usePreparedSelectBlade($q); //Changed for new configeration in versions after 0.17.x if ($result == NULL) { print_r($dbxlink->errorInfo()); die; } while ($row4 = $result->fetch(PDO::FETCH_NUM)) { if (!$isfirst && $i % 10 == 0) { print "</td></tr>\n<tr class=" . ($i % 4 == 0 ? "row_odd" : "row_even") . ">"; } else { $isfirst = false; } print "<td><b>{$row4[0]}</b><br>"; //seperated values to make them easier to read print "{$row4[1]}\n</td>"; $i++; } print "</td>\n"; print "</tr></table>\n"; finishPortlet(); } }
<pre id="debugmsg" style="display: none;"> <?php //print_r($_SESSION); ?> --- <?php //print_r($taglist); ?> </pre> </div> <?php finishPortlet(); ?> </div> <br clear='both'> <?php startPortlet(); echo "XenVMImport by Tyler Montgomery <br>"; $time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0]; $finish = $time; $total_time = round($finish - $start, 4); echo 'Page generated in ' . $total_time . ' seconds.'; finishPortlet(); ?> </div>
function renderPortletWattConsumption($info) { $rackTotalWattage = 0; $rackData = spotEntity('rack', $info['id']); amplifyCell($rackData); $objectChildren = getEntityRelatives('children', 'object', $objectData['id']); foreach ($rackData['mountedObjects'] as $object) { $objectData = spotEntity('object', $object); amplifyCell($objectData); foreach (getAttrValues($objectData['id']) as $record) { if ($record['name'] == 'Wattage consumption') { $rackTotalWattage += $record['value']; } } } startPortlet('Wattage Consumption'); echo "<table border=0 cellspacing=5 align='center'><tr>"; echo "<td>The total for attribute Wattage consuption is: <b>{$rackTotalWattage}</b></td>\n"; echo "</tr></table>\n"; finishPortlet(); }
function renderSearchNewIP4Range() { global $pTable; // prepare $cellfilter $cellfilter = getCellFilter(); if ($cellfilter['is_empty'] || !isset($_REQUEST['cfp'])) { if (defined('SPARE_SEARCH_PREDICATE') && isset($pTable[SPARE_SEARCH_PREDICATE])) { $_REQUEST['cfp'] = array(SPARE_SEARCH_PREDICATE); $cellfilter = getCellFilter(); } } $mask = NULL; if (!empty($_REQUEST['pref_len'])) { $mask = intval($_REQUEST['pref_len']); } $nets = array(); foreach (filterCellList(listCells('ipv4net'), $cellfilter['expression']) as $net) { if (!isset($mask)) { $nets[] = $net; } elseif ($net['mask'] <= $mask) { $is_aggregate = FALSE; foreach ($net['atags'] as $atag) { if ($atag['tag'] == '$aggregate') { $is_aggregate = TRUE; } elseif (preg_match('/^\\$spare_(\\d+)$/', $atag['tag'], $m) && $mask >= $m[1]) { $nets[] = $net; continue 2; } } if (!$is_aggregate) { $nets[] = $net; } } } $filter = getOutputOf('renderCellFilterPortlet', $cellfilter, 'ipv4net', $nets); echo '<table width="100%"><tr valign=top>'; echo '<td>'; startPortlet("Results (" . count($nets) . ")"); echo '<ul class="spare-nets">'; foreach ($nets as $net) { echo '<li>'; renderNetCellForAlloc($net, $mask); echo '</li>'; } echo '</ul>'; finishPortlet(); echo '</td>'; echo '<td width="33%">'; echo preg_replace_callback('/(<form[^<>]*>)/', 'generatePrefixLengthInput', $filter); echo '</td>'; echo '</tr></table>'; addCSS(<<<END ul.spare-nets { \tlist-style: none; \tpadding: 0px; } ul.spare-nets li { \tmargin: 5px 0px; } END , TRUE); }
function renderPopupPortSelector() { assertUIntArg('port'); $port_id = $_REQUEST['port']; $port_info = getPortInfo($port_id); $in_rack = isCheckSet('in_rack'); // fill port filter structure $filter = array('racks' => array(), 'objects' => '', 'ports' => ''); if (isset($_REQUEST['filter-obj'])) { $filter['objects'] = trim($_REQUEST['filter-obj']); } if (isset($_REQUEST['filter-port'])) { $filter['ports'] = trim($_REQUEST['filter-port']); } if ($in_rack) { $object = spotEntity('object', $port_info['object_id']); if ($object['rack_id']) { $filter['racks'] = getProximateRacks($object['rack_id'], getConfigVar('PROXIMITY_RANGE')); } } $spare_ports = array(); if (!empty($filter['racks']) || !empty($filter['objects']) || !empty($filter['ports'])) { $spare_ports = findSparePorts($port_info, $filter); } // display search form echo 'Link ' . formatPort($port_info) . ' to...'; echo '<form method=GET>'; startPortlet('Port list filter'); echo '<input type=hidden name="module" value="popup">'; echo '<input type=hidden name="helper" value="portlist">'; echo '<input type=hidden name="port" value="' . $port_id . '">'; echo '<table align="center" valign="bottom"><tr>'; echo '<td class="tdleft"><label>Object name:<br><input type=text size=8 name="filter-obj" value="' . htmlspecialchars($filter['objects'], ENT_QUOTES) . '"></label></td>'; echo '<td class="tdleft"><label>Port name:<br><input type=text size=6 name="filter-port" value="' . htmlspecialchars($filter['ports'], ENT_QUOTES) . '"></label></td>'; echo '<td class="tdleft" valign="bottom"><label><input type=checkbox name="in_rack"' . ($in_rack ? ' checked' : '') . '>Nearest racks</label></td>'; echo '<td valign="bottom"><input type=submit value="show ports"></td>'; echo '</tr></table>'; finishPortlet(); // display results startPortlet('Compatible spare ports'); if (empty($spare_ports)) { echo '(nothing found)'; } else { echo getSelect($spare_ports, array('name' => 'remote_port', 'size' => getConfigVar('MAXSELSIZE')), NULL, FALSE); echo "<p>Cable ID: <input type=text id=cable name=cable>"; echo "<p><input type='submit' value='Link' name='do_link'>"; } finishPortlet(); echo '</form>'; }
function ImportTab() { global $nextorder; global $Version; global $taglist; ?> <style type='text/css'> tr.has_problems { background-color: #ffa0a0; } </style> <!--Legend--> <table align=right> <tr class=trerror><td colspan=2>Unknown object</td></tr> <tr><td class=row_even>Existing </td><td class=row_odd> object</td></tr> </table> <center><h1>Import yaml objects </h1><h2>from /yamls/</h2></center> <?php startPortlet(); echo "<table with=90% align=center border=0 cellpadding=5 cellspacing=0 align=center class=cooltable><tr valign=top>"; echo "<form method=post name=ImportObject action='?module=redirect&page=depot&tab=yaml_import&op=RunImport'>"; echo "<tr valign=top><th>Assign tags</th><th align=center>Name</th><th align=center>Import ?</th></tr>"; // taglist on display - left handed echo "<tr valign=top><td rowspan=\"0\">"; renderNewEntityTags('object'); echo "</td></tr>"; $order = 'odd'; # Find and read loop through all .yaml files in the yaml directory. // if ($handle = opendir('./yamls/')) if ($files = scandir('./yamls/')) { // while (false !== ($file = readdir($handle))) foreach ($files as $file) { # Since puppet names the files $FQDN.yaml, we don't have to inspect the file during the first run. if (preg_match('/\\.yaml/', $file)) { $name = preg_replace('/\\.yaml/', '', $file); # Do a search on the row 'name' passing the one name, and retrieving the ID. $object = getSearchResultByField('RackObject', array('id'), 'name', $name, '', 2); if ($object) { $url = makeHref(array('page' => 'object', 'tab' => 'default', 'object_id' => $object[0]['id'])); echo "<tr class=row_{$order}><td align=left><a href=\"{$url}\">" . $name . "</a></td>\n"; } else { echo "<tr class=trerror><td align=left>" . $name . "</td>\n"; } echo "<td align=center> <input type=checkbox name=objectname[] value={$name}></td></tr>\n"; $order = $nextorder[$order]; } } } // tags ? // echo "<tr><td rowspan=\"0\">"; // renderNewEntityTags('object'); // echo "</td></tr>"; echo "<tr><td align=left><font size=1em color=gray>version {$Version}</font></td><td align=right><input type=submit name=got_very_fast_data value='Import selected items'></td><td></td></tr></table></td></tr>"; echo "</form>"; echo "</table>"; finishPortlet(); }
function renderCopyEntityTagsPortlet($title, $tags, $preselect, $realm) { startPortlet($title); echo '<a class="toggleTreeMode" style="display:none" href="#"></a>'; echo '<table border=0 cellspacing=0 cellpadding=1 align=center class="tagtree">'; printTagCheckboxTable('taglist', $preselect, array(), $tags, $realm); echo '<tr><td class=tdleft>'; //echo "</form></td><td class=tdright>"; echo '</td></tr></table>'; finishPortlet(); }
function renderIframeTabForEntity($title, $link) { // Main layout starts. echo "<style type=\"text/css\">\n"; echo "\n\n\t#iframe_wrap {\n\n\t\tposition:absolute;\n\n\t\ttop: 190px;\n\n\t\tleft: 0;\n\n\t\tright: 0;\n\n\t\tbottom: 5px;\n\n\t\talign: center;\n\t\tmargin:0;\n\n\t\tpadding:0;\n\n\t\t}\n\n\t</style>\n"; startPortlet("<a href=\"{$link}\" target=_new>{$title}</a>"); finishPortlet(); echo "<div id=\"iframe_wrap\" align=\"center\">"; echo "<iframe border=0 src=\"{$link}\" width=%99 height=%99 halign=center style='width: expression(document.documentElement.clientWidth); height: expression(document.documentElement.clientHeight-210)'>"; echo "</div>"; }
function PingTab($id) { $pingtimeout = "50"; if (isset($_REQUEST['pg'])) { $page = $_REQUEST['pg']; } else { $page = 0; } global $pageno, $tabno; $maxperpage = getConfigVar('IPV4_ADDRS_PER_PAGE'); $range = spotEntity('ipv4net', $id); loadIPAddrList($range); echo "<center><h1>{$range['ip']}/{$range['mask']}</h1><h2>{$range['name']}</h2></center>\n"; echo "<table class=objview border=0 width='100%'><tr><td class=pcleft>"; startPortlet('icmp ping comparrison:'); $startip = ip4_bin2int($range['ip_bin']); $endip = ip4_bin2int(ip_last($range)); $realstartip = $startip; $realendip = $endip; $numpages = 0; if ($endip - $startip > $maxperpage) { $numpages = ($endip - $startip) / $maxperpage; $startip = $startip + $page * $maxperpage; $endip = $startip + $maxperpage - 1; } echo "<center>"; if ($numpages) { echo '<h3>' . ip4_format(ip4_int2bin($startip)) . ' ~ ' . ip4_format(ip4_int2bin($endip)) . '</h3>'; } for ($i = 0; $i < $numpages; $i++) { if ($i == $page) { echo "<b>{$i}</b> "; } else { echo "<a href='" . makeHref(array('page' => $pageno, 'tab' => $tabno, 'id' => $id, 'pg' => $i)) . "'>{$i}</a> "; } } echo "</center>"; echo "<table class='widetable' border=0 cellspacing=0 cellpadding=5 align='center'>\n"; echo "<tr><th>address</th><th>name</th><th>response</th></tr>\n"; $idx = 1; $box_counter = 1; $cnt_ok = $cnt_noreply = $cnt_mismatch = 0; for ($ip = $startip; $ip <= $endip; $ip++) { $ip_bin = ip4_int2bin($ip); $addr = isset($range['addrlist'][$ip_bin]) ? $range['addrlist'][$ip_bin] : array('name' => '', 'reserved' => 'no'); $straddr = ip4_format($ip_bin); system("/usr/sbin/fping -q -c 1 -t {$pingtimeout} {$straddr}", $pingreply); // FIXME: This is a huge and ugly IF/ELSE block. Prettify anyone? if (!$pingreply) { if (!empty($addr['name']) and $addr['reserved'] == 'no' or !empty($addr['allocs'])) { echo '<tr class=trok'; $cnt_ok++; } else { echo $addr['reserved'] == 'yes' ? '<tr class=trwarning' : '<tr class=trerror'; $cnt_mismatch++; } } else { if (!empty($addr['name']) and $addr['reserved'] == 'no' or !empty($addr['allocs'])) { echo '<tr class=trwarning'; $cnt_noreply++; } else { echo '<tr'; } } echo "><td class='tdleft"; if (isset($range['addrlist'][$ip_bin]['class']) and strlen($range['addrlist'][$ip_bin]['class'])) { echo ' ' . $range['addrlist'][$ip_bin]['class']; } echo "'><a href='" . makeHref(array('page' => 'ipaddress', 'ip' => $straddr)) . "'>{$straddr}</a></td>"; echo "<td class=tdleft>{$addr['name']}</td><td class=tderror>"; if (!$pingreply) { echo "Yes"; } else { echo "No"; } echo "</td></tr>\n"; $idx++; } echo "</td></tr>"; echo "</table>"; echo "</form>"; finishPortlet(); echo "</td><td class=pcright>"; startPortlet('stats'); echo "<table border=0 width='100%' cellspacing=0 cellpadding=2>"; echo "<tr class=trok><th class=tdright>OKs:</th><td class=tdleft>{$cnt_ok}</td></tr>\n"; echo "<tr class=trwarning><th class=tdright>Did not reply:</th><td class=tdleft>{$cnt_noreply}</td></tr>\n"; if ($cnt_mismatch) { echo "<tr class=trerror><th class=tdright>Unallocated answer:</th><td class=tdleft>{$cnt_mismatch}</td></tr>\n"; } echo "</table>\n"; finishPortlet(); echo "</td></tr></table>\n"; }
function localfunc_PortLinker() { global $localSplit, $remoteSplit; startPortlet("Port linker"); print "<center>"; $errorText = determine_PortLinker(); $object = spotEntity('object', $_REQUEST['object_id']); if (strlen($errorText) > 0) { print "Trying to link this object to : {$object['label']}<br><br>\n"; print $errorText; } else { echo "<a href='" . makeHrefProcess(array('op' => 'linknow', 'page' => 'object', 'tab' => 'default', 'object_id' => $_REQUEST['object_id'])) . "'>Connect the following ports now:</a><p>\n"; print "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>"; print "<tr><th>Object name</th><th>Port name</th><th> </th><th>Remote object name</th><th>Remote port name</th></tr>\n"; foreach ($localSplit as $aKey => $aValue) { $numAdd = $remoteSplit[$aKey][$object['name']]['start'] - $aValue['start']; foreach ($aValue['ports'] as $aPortNum => $aPort) { print "<tr><td>{$object['name']}</td><td>{$aPort['name']}</td><td> </td><td>{$aKey}</td><td>"; print $aValue['remote_ports'][$aPortNum + $numAdd]['name'] . "</td></tr>\n"; } } print "</table>"; } print "</center>"; finishPortlet(); }
function linkmgmt_renderPopupPortSelectorbyName() { $linktype = $_REQUEST['linktype']; $object_id = $_REQUEST['object_id']; $object = spotEntity('object', $object_id); $objectlist = linkmgmt_findSparePorts(NULL, NULL, $linktype, false, true, TRUE, false, $object_id); $objectname = $object['dname']; /* remove self from list */ unset($objectlist[$object_id]); if (isset($_REQUEST['remote_object'])) { $remote_object = $_REQUEST['remote_object']; } else { /* choose first object from list */ $keys = array_keys($objectlist); if (isset($keys[0])) { $remote_object = $keys[0]; } else { $remote_object = NULL; } } if ($remote_object) { $filter['object_id'] = $remote_object; $link_list = linkmgmt_findSparePorts(NULL, $filter, $linktype, false, false, TRUE, false, $object_id); } else { $link_list = linkmgmt_findSparePorts(NULL, NULL, $linktype, false, false, TRUE, false, $object_id); } // display search form echo 'Link ' . $linktype . ' of ' . formatPortLink($object_id, $objectname, NULL, NULL) . ' Ports by Name to...'; echo '<form method=POST>'; echo '<table align="center"><tr><td>'; startPortlet('Object list'); $maxsize = getConfigVar('MAXSELSIZE'); $objectcount = count($objectlist); echo 'Object name (count ports)<br>'; echo getSelect($objectlist, array('name' => 'remote_object', 'size' => $objectcount <= $maxsize ? $objectcount : $maxsize), $remote_object, FALSE); echo '</td><td><input type=submit value="show ' . $linktype . ' ports>"></td>'; finishPortlet(); echo '<td>'; // display results startPortlet('Possible Backend Link List'); echo "Select links to create:<br>"; if (empty($link_list)) { echo '(nothing found)'; } else { $linkcount = count($link_list); $options = array('name' => 'link_list[]', 'size' => $linkcount <= $maxsize ? $linkcount : $maxsize, 'multiple' => 'multiple'); echo getSelect($link_list, $options, NULL, FALSE); echo "<p>{$linktype} Cable ID: <input type=text id=cable name=cable>"; echo "<p><input type='submit' value='Link {$linktype}' name='do_link'>"; } finishPortlet(); echo '</td></tr></table>'; echo '</form>'; }
function renderPopupPortSelector() { if (isset($_REQUEST['do_link'])) { return handlePopupPortLink(); } assertPermission('depot', 'default'); assertUIntArg('port'); $port_id = $_REQUEST['port']; $port_info = getPortInfo($port_id); $in_rack = isCheckSet('in_rack'); // fill port filter structure $filter = array('racks' => array(), 'objects' => '', 'ports' => '', 'asset_no' => ''); if (isset($_REQUEST['filter-obj'])) { $filter['objects'] = trim($_REQUEST['filter-obj']); } if (isset($_REQUEST['filter-port'])) { $filter['ports'] = trim($_REQUEST['filter-port']); } if (isset($_REQUEST['filter-asset_no'])) { $filter['asset_no'] = trim($_REQUEST['filter-asset_no']); } if ($in_rack) { $object = spotEntity('object', $port_info['object_id']); if ($object['rack_id']) { // the object itself is mounted in a rack $filter['racks'] = getProximateRacks($object['rack_id'], getConfigVar('PROXIMITY_RANGE')); } elseif ($object['container_id']) { $container = spotEntity('object', $object['container_id']); if ($container['rack_id']) { $filter['racks'] = getProximateRacks($container['rack_id'], getConfigVar('PROXIMITY_RANGE')); } } } $spare_ports = array(); if (!empty($filter['racks']) || !empty($filter['objects']) || !empty($filter['ports']) || !empty($filter['asset_no'])) { $spare_ports = findSparePorts($port_info, $filter); } // display search form echo 'Link ' . formatPort($port_info) . ' to...'; echo '<form method=GET>'; startPortlet('Port list filter'); echo '<input type=hidden name="module" value="popup">'; echo '<input type=hidden name="helper" value="portlist">'; echo '<input type=hidden name="port" value="' . $port_id . '">'; echo '<table align="center" valign="bottom"><tr>'; echo '<td class="tdleft"><label>Object name:<br><input type=text size=8 name="filter-obj" value="' . htmlspecialchars($filter['objects'], ENT_QUOTES) . '"></label></td>'; echo '<td class="tdleft"><label>Asset tag:<br><input type=text size=8 name="filter-asset_no" value="' . htmlspecialchars($filter['asset_no'], ENT_QUOTES) . '"></label></td>'; echo '<td class="tdleft"><label>Port name:<br><input type=text size=6 name="filter-port" value="' . htmlspecialchars($filter['ports'], ENT_QUOTES) . '"></label></td>'; echo '<td class="tdleft" valign="bottom"><label><input type=checkbox name="in_rack"' . ($in_rack ? ' checked' : '') . '>Nearest racks</label></td>'; echo '<td valign="bottom"><input type=submit value="show ports"></td>'; echo '</tr></table>'; finishPortlet(); // display results startPortlet('Compatible spare ports'); if (empty($spare_ports)) { echo '(nothing found)'; } else { echo getSelect($spare_ports, array('name' => 'remote_port', 'size' => getConfigVar('MAXSELSIZE')), NULL, FALSE); echo "<p>Cable ID: <input type=text id=cable name=cable>"; // suggest patch cables where it makes sense $heaps = getPatchCableHeapOptionsForOIF($port_info['oif_id']); if (count($heaps)) { // Use + instead of array_merge() to avoid renumbering the keys. echo '<p>Patch cable: ' . getSelect(array(0 => 'none') + $heaps, array('name' => 'heap_id')); } echo "<p><input type='submit' value='Link' name='do_link'>"; } finishPortlet(); echo '</form>'; }
function renderNewVSForm() { startPortlet('Add new virtual service'); printOpFormIntro('add'); echo "<table border=0 cellpadding=10 cellspacing=0 align=center>\n"; echo "<tr valign=bottom><td> </td><th>VIP</th><th>port</th><th>proto</th><th>name</th><th> </th><th>Assign tags</th></tr>"; echo '<tr valign=top><td> </td>'; echo "<td><input type=text name=vip tabindex=101></td>"; $default_port = getConfigVar('DEFAULT_SLB_VS_PORT'); if ($default_port == 0) { $default_port = ''; } echo "<td><input type=text name=vport size=5 value='{$default_port}' tabindex=102></td><td>"; global $vs_proto; printSelect($vs_proto, array('name' => 'proto'), array_shift(array_keys($vs_proto))); echo '</td><td><input type=text name=name tabindex=104></td><td>'; printImageHREF('CREATE', 'create virtual service', TRUE, 105); echo "</td><td rowspan=3>"; renderNewEntityTags('ipv4vs'); echo "</td></tr><tr><th>VS configuration</th><td colspan=5 class=tdleft><textarea name=vsconfig rows=10 cols=80></textarea></td>"; echo "<tr><th>RS configuration</th><td colspan=5 class=tdleft><textarea name=rsconfig rows=10 cols=80></textarea></td></tr>"; echo '</table></form>'; finishPortlet(); }
function showImportTab() { global $tagtree; echo "<h2 style='padding-left: 10px;'>Xen VM Import</h2>"; startPortlet("Errors"); echo "<div style='color: red;font-weight: bold;'>"; echo "Can only have one tag selected!"; echo "</div><br>"; finishPortlet(); echo "<style>label {display: block; font-weight: bold;} th {background-color: #eee; }</style>\n\t\t<div style='float: left; width: 30%'>"; startPortlet("Options"); ?> <form method='post' name='discover' action='?module=redirect&page=depot&tab=xen_import&op=discoverVMs'> <table align='center'> <tr> <td> <label for='vmMasters'>Xen Pool Masters (IP, one per line)</label> <textarea rows='20' cols='20' name='vmMasters'></textarea><br><br> <input type='submit' value='Discover VMs'> </td> <td> <label for='xenUser'>Username:</label><input type='text' length='20' name='xenUser'> <label for='xenPass'>Password:</label><input type='password' length='20' name='xenPass'><br><br> <strong>Pool Tag</strong> <div class=tagselector><table border=0 align=center cellspacing=0 class="tagtree"> <?php printTagCheckboxTable('pooltags', array(), array(), $tagtree, 'object'); ?> </table></div> <br><br> <strong>VM Tag</strong> <div class=tagselector><table border=0 align=center cellspacing=0 class="tagtree"> <?php printTagCheckboxTable('vmtags', array(), array(), $tagtree, 'object'); ?> </table></div> </td> </tr> </table> <?php finishPortlet(); echo "</form></div>\n\t\t<div style='float: left; width: 70%'>"; startPortlet("VMs Discovered"); echo "<strong>No virtual machines discovered.</strong><br><br>"; ?> <table border="1" bordercolor="CCCCCC" cellspacing="0" style="width: 100%;"> <tr> <th></th> <th>VM Name</th> <th>IP Address</th> <th>Guest OS</th> <th>VM UUID</th> <tr> <tr> <th colspan="5">Pool TX-C5220-Pool1</th> </tr> <tr> <td><input type="checkbox" name="check1"></td> <td>TX-Box01</td> <td>192.168.129.150</td> <td>Centos 5.2 (Nawahee)</td> <td>somereallynonsenselongnumberhereforaUID</td> </tr> </table> <br> <strong>Import VM Pools into:</strong> Pools<br> <strong>Import VMs into:</strong> Virtuals <br><br> <input type="submit" name="import" value="Import Selected VMs and pools"> <input type="submit" name="clear" value="Clear discovered VMs"> <?php finishPortlet(); startPortlet("Debug"); echo "<div style='text-align: left;'>"; echo "<pre>"; print_r($_SESSION); echo "</pre>"; finishPortlet(); echo "</div>"; echo "</div><br clear='both'>"; startPortlet(); echo "XenVMImport by Tyler Montgomery"; finishPortlet(); }
function renderDataIntegrityReport() { global $nextorder; $violations = FALSE; // check 1: EntityLink rows referencing not-existent relatives // check 1.1: children $realms = array('location' => 'Location', 'object' => 'RackObject', 'rack' => 'Rack', 'row' => 'Row'); $orphans = array(); foreach ($realms as $realm => $table) { $result = usePreparedSelectBlade('SELECT EL.* FROM EntityLink EL ' . "LEFT JOIN {$table} ON EL.child_entity_id = {$table}.id " . "WHERE EL.child_entity_type = ? AND {$table}.id IS NULL", array($realm)); $rows = $result->fetchAll(PDO::FETCH_ASSOC); unset($result); $orphans = array_merge($orphans, $rows); } if (count($orphans)) { $violations = TRUE; startPortlet('EntityLink: Missing Children (' . count($orphans) . ')'); echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n"; echo "<tr><th>Parent</th><th>Child Type</th><th>Child ID</th></tr>\n"; $order = 'odd'; foreach ($orphans as $orphan) { $realm_name = formatRealmName($orphan['parent_entity_type']); try { $parent = spotEntity($orphan['parent_entity_type'], $orphan['parent_entity_id']); $parent_name = $parent['name']; } catch (EntityNotFoundException $e) { $parent_name = 'missing from DB'; } echo "<tr class=row_{$order}>"; echo "<td>{$realm_name}: {$parent_name}</td>"; echo "<td>{$orphan['child_entity_type']}</td>"; echo "<td>{$orphan['child_entity_id']}</td>"; echo "</tr>\n"; $order = $nextorder[$order]; } echo "</table>\n"; finishPortLet(); } // check 1.2: parents $orphans = array(); foreach ($realms as $realm => $table) { $result = usePreparedSelectBlade('SELECT EL.* FROM EntityLink EL ' . "LEFT JOIN {$table} ON EL.parent_entity_id = {$table}.id " . "WHERE EL.parent_entity_type = ? AND {$table}.id IS NULL", array($realm)); $rows = $result->fetchAll(PDO::FETCH_ASSOC); unset($result); $orphans = array_merge($orphans, $rows); } if (count($orphans)) { $violations = TRUE; startPortlet('EntityLink: Missing Parents (' . count($orphans) . ')'); echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n"; echo "<tr><th>Child</th><th>Parent Type</th><th>Parent ID</th></tr>\n"; $order = 'odd'; foreach ($orphans as $orphan) { $realm_name = formatRealmName($orphan['child_entity_type']); try { $child = spotEntity($orphan['child_entity_type'], $orphan['child_entity_id']); $child_name = $child['name']; } catch (EntityNotFoundException $e) { $child_name = 'missing from DB'; } echo "<tr class=row_{$order}>"; echo "<td>{$realm_name}: {$child_name}</td>"; echo "<td>{$orphan['parent_entity_type']}</td>"; echo "<td>{$orphan['parent_entity_id']}</td>"; echo "</tr>\n"; $order = $nextorder[$order]; } echo "</table>\n"; finishPortLet(); } // check 3: multiple tables referencing non-existent dictionary entries // check 3.1: AttributeMap $orphans = array(); $result = usePreparedSelectBlade('SELECT AM.*, A.name AS attr_name, C.name AS chapter_name ' . 'FROM AttributeMap AM ' . 'LEFT JOIN Attribute A ON AM.attr_id = A.id ' . 'LEFT JOIN Chapter C ON AM.chapter_id = C.id ' . 'LEFT JOIN Dictionary D ON AM.objtype_id = D.dict_key ' . 'WHERE D.dict_key IS NULL'); $orphans = $result->fetchAll(PDO::FETCH_ASSOC); unset($result); if (count($orphans)) { $violations = TRUE; startPortlet('AttributeMap: Invalid Mappings (' . count($orphans) . ')'); echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n"; echo "<tr><th>Attribute</th><th>Chapter</th><th>Object TypeID</th></tr>\n"; $order = 'odd'; foreach ($orphans as $orphan) { echo "<tr class=row_{$order}>"; echo "<td>{$orphan['attr_name']}</td>"; echo "<td>{$orphan['chapter_name']}</td>"; echo "<td>{$orphan['objtype_id']}</td>"; echo "</tr>\n"; $order = $nextorder[$order]; } echo "</table>\n"; finishPortLet(); } // check 3.2: Object $orphans = array(); $result = usePreparedSelectBlade('SELECT O.* FROM Object O ' . 'LEFT JOIN Dictionary D ON O.objtype_id = D.dict_key ' . 'WHERE D.dict_key IS NULL'); $orphans = $result->fetchAll(PDO::FETCH_ASSOC); unset($result); if (count($orphans)) { $violations = TRUE; startPortlet('Object: Invalid Types (' . count($orphans) . ')'); echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n"; echo "<tr><th>ID</th><th>Name</th><th>Type ID</th></tr>\n"; $order = 'odd'; foreach ($orphans as $orphan) { echo "<tr class=row_{$order}>"; echo "<td>{$orphan['id']}</td>"; echo "<td>{$orphan['name']}</td>"; echo "<td>{$orphan['objtype_id']}</td>"; echo "</tr>\n"; $order = $nextorder[$order]; } echo "</table>\n"; finishPortLet(); } // check 3.3: ObjectHistory $orphans = array(); $result = usePreparedSelectBlade('SELECT OH.* FROM ObjectHistory OH ' . 'LEFT JOIN Dictionary D ON OH.objtype_id = D.dict_key ' . 'WHERE D.dict_key IS NULL'); $orphans = $result->fetchAll(PDO::FETCH_ASSOC); unset($result); if (count($orphans)) { $violations = TRUE; startPortlet('ObjectHistory: Invalid Types (' . count($orphans) . ')'); echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n"; echo "<tr><th>ID</th><th>Name</th><th>Type ID</th></tr>\n"; $order = 'odd'; foreach ($orphans as $orphan) { echo "<tr class=row_{$order}>"; echo "<td>{$orphan['id']}</td>"; echo "<td>{$orphan['name']}</td>"; echo "<td>{$orphan['objtype_id']}</td>"; echo "</tr>\n"; $order = $nextorder[$order]; } echo "</table>\n"; finishPortLet(); } // check 3.4: ObjectParentCompat $orphans = array(); $result = usePreparedSelectBlade('SELECT OPC.*, PD.dict_value AS parent_name, CD.dict_value AS child_name ' . 'FROM ObjectParentCompat OPC ' . 'LEFT JOIN Dictionary PD ON OPC.parent_objtype_id = PD.dict_key ' . 'LEFT JOIN Dictionary CD ON OPC.child_objtype_id = CD.dict_key ' . 'WHERE PD.dict_key IS NULL OR CD.dict_key IS NULL'); $orphans = $result->fetchAll(PDO::FETCH_ASSOC); unset($result); if (count($orphans)) { $violations = TRUE; startPortlet('Object Container Compatibility rules: Invalid Parent or Child Type (' . count($orphans) . ')'); echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n"; echo "<tr><th>Parent</th><th>Parent Type ID</th><th>Child</th><th>Child Type ID</th></tr>\n"; $order = 'odd'; foreach ($orphans as $orphan) { echo "<tr class=row_{$order}>"; echo "<td>{$orphan['parent_name']}</td>"; echo "<td>{$orphan['parent_objtype_id']}</td>"; echo "<td>{$orphan['child_name']}</td>"; echo "<td>{$orphan['child_objtype_id']}</td>"; echo "</tr>\n"; $order = $nextorder[$order]; } echo "</table>\n"; finishPortLet(); } // check 4: relationships that violate ObjectParentCompat Rules $invalids = array(); $result = usePreparedSelectBlade('SELECT CO.id AS child_id, CO.objtype_id AS child_type_id, CD.dict_value AS child_type, CO.name AS child_name, ' . 'PO.id AS parent_id, PO.objtype_id AS parent_type_id, PD.dict_value AS parent_type, PO.name AS parent_name ' . 'FROM Object CO ' . 'LEFT JOIN EntityLink EL ON CO.id = EL.child_entity_id ' . 'LEFT JOIN Object PO ON EL.parent_entity_id = PO.id ' . 'LEFT JOIN ObjectParentCompat OPC ON PO.objtype_id = OPC.parent_objtype_id ' . 'LEFT JOIN Dictionary PD ON PO.objtype_id = PD.dict_key ' . 'LEFT JOIN Dictionary CD ON CO.objtype_id = CD.dict_key ' . "WHERE EL.parent_entity_type = 'object' AND EL.child_entity_type = 'object' " . 'AND OPC.parent_objtype_id IS NULL'); $invalids = $result->fetchAll(PDO::FETCH_ASSOC); unset($result); if (count($invalids)) { $violations = TRUE; startPortlet('Objects: Violate Object Container Compatibility rules (' . count($invalids) . ')'); echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n"; echo "<tr><th>Contained Obj Name</th><th>Contained Obj Type</th><th>Container Obj Name</th><th>Container Obj Type</th></tr>\n"; $order = 'odd'; foreach ($invalids as $invalid) { echo "<tr class=row_{$order}>"; echo "<td>{$invalid['child_name']}</td>"; echo "<td>{$invalid['child_type']}</td>"; echo "<td>{$invalid['parent_name']}</td>"; echo "<td>{$invalid['parent_type']}</td>"; echo "</tr>\n"; $order = $nextorder[$order]; } echo "</table>\n"; finishPortLet(); } // check 5: Links that violate PortCompat Rules $invalids = array(); $result = usePreparedSelectBlade('SELECT OA.id AS obja_id, OA.name AS obja_name, L.porta AS porta_id, PA.name AS porta_name, POIA.oif_name AS porta_type, ' . 'OB.id AS objb_id, OB.name AS objb_name, L.portb AS portb_id, PB.name AS portb_name, POIB.oif_name AS portb_type ' . 'FROM Link L ' . 'LEFT JOIN Port PA ON L.porta = PA.id ' . 'LEFT JOIN Object OA ON PA.object_id = OA.id ' . 'LEFT JOIN PortOuterInterface POIA ON PA.type = POIA.id ' . 'LEFT JOIN Port PB ON L.portb = PB.id ' . 'LEFT JOIN Object OB ON PB.object_id = OB.id ' . 'LEFT JOIN PortOuterInterface POIB ON PB.type = POIB.id ' . 'LEFT JOIN PortCompat PC on PA.type = PC.type1 AND PB.type = PC.type2 ' . 'WHERE PC.type1 IS NULL OR PC.type2 IS NULL'); $invalids = $result->fetchAll(PDO::FETCH_ASSOC); unset($result); if (count($invalids)) { $violations = TRUE; startPortlet('Port Links: Violate Port Compatibility Rules (' . count($invalids) . ')'); echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n"; echo "<tr><th>Object A</th><th>Port A Name</th><th>Port A Type</th><th>Object B</th><th>Port B Name</th><th>Port B Type</th></tr>\n"; $order = 'odd'; foreach ($invalids as $invalid) { echo "<tr class=row_{$order}>"; echo "<td>{$invalid['obja_name']}</td>"; echo "<td>{$invalid['porta_name']}</td>"; echo "<td>{$invalid['porta_type']}</td>"; echo "<td>{$invalid['objb_name']}</td>"; echo "<td>{$invalid['portb_name']}</td>"; echo "<td>{$invalid['portb_type']}</td>"; echo "</tr>\n"; $order = $nextorder[$order]; } echo "</table>\n"; finishPortLet(); } // check 6: TagStorage rows referencing non-existent parents $realms = array('file' => array('table' => 'File', 'column' => 'id'), 'ipv4net' => array('table' => 'IPv4Network', 'column' => 'id'), 'ipv4rspool' => array('table' => 'IPv4RSPool', 'column' => 'id'), 'ipv4vs' => array('table' => 'IPv4VS', 'column' => 'id'), 'ipv6net' => array('table' => 'IPv6Network', 'column' => 'id'), 'ipvs' => array('table' => 'VS', 'column' => 'id'), 'location' => array('table' => 'Location', 'column' => 'id'), 'object' => array('table' => 'RackObject', 'column' => 'id'), 'rack' => array('table' => 'Rack', 'column' => 'id'), 'user' => array('table' => 'UserAccount', 'column' => 'user_id'), 'vst' => array('table' => 'VLANSwitchTemplate', 'column' => 'id')); $orphans = array(); foreach ($realms as $realm => $details) { $result = usePreparedSelectBlade('SELECT TS.*, TT.tag FROM TagStorage TS ' . 'LEFT JOIN TagTree TT ON TS.tag_id = TT.id ' . "LEFT JOIN {$details['table']} ON TS.entity_id = {$details['table']}.{$details['column']} " . "WHERE TS.entity_realm = ? AND {$details['table']}.{$details['column']} IS NULL", array($realm)); $rows = $result->fetchAll(PDO::FETCH_ASSOC); unset($result); $orphans = array_merge($orphans, $rows); } if (count($orphans)) { $violations = TRUE; startPortlet('TagStorage: Missing Parents (' . count($orphans) . ')'); echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n"; echo "<tr><th>Tag</th><th>Parent Type</th><th>Parent ID</th></tr>\n"; $order = 'odd'; foreach ($orphans as $orphan) { $realm_name = formatRealmName($orphan['entity_realm']); echo "<tr class=row_{$order}>"; echo "<td>{$orphan['tag']}</td>"; echo "<td>{$realm_name}</td>"; echo "<td>{$orphan['entity_id']}</td>"; echo "</tr>\n"; $order = $nextorder[$order]; } echo "</table>\n"; finishPortLet(); } // check 7: FileLink rows referencing non-existent parents // re-use the realms list from the TagStorage check, with a few mods unset($realms['file'], $realms['vst']); $realms['row'] = array('table' => 'Row', 'column' => 'id'); $orphans = array(); foreach ($realms as $realm => $details) { $result = usePreparedSelectBlade('SELECT FL.*, F.name FROM FileLink FL ' . 'LEFT JOIN File F ON FL.file_id = F.id ' . "LEFT JOIN {$details['table']} ON FL.entity_id = {$details['table']}.{$details['column']} " . "WHERE FL.entity_type = ? AND {$details['table']}.{$details['column']} IS NULL", array($realm)); $rows = $result->fetchAll(PDO::FETCH_ASSOC); unset($result); $orphans = array_merge($orphans, $rows); } if (count($orphans)) { $violations = TRUE; startPortlet('FileLink: Missing Parents (' . count($orphans) . ')'); echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n"; echo "<tr><th>File</th><th>Parent Type</th><th>Parent ID</th></tr>\n"; $order = 'odd'; foreach ($orphans as $orphan) { $realm_name = formatRealmName($orphan['entity_type']); echo "<tr class=row_{$order}>"; echo "<td>{$orphan['name']}</td>"; echo "<td>{$realm_name}</td>"; echo "<td>{$orphan['entity_id']}</td>"; echo "</tr>\n"; $order = $nextorder[$order]; } echo "</table>\n"; finishPortLet(); } // check 8: missing triggers $triggers = array('Link-before-insert' => 'Link', 'Link-before-update' => 'Link'); $result = usePreparedSelectBlade('SELECT TRIGGER_NAME, EVENT_OBJECT_TABLE ' . 'FROM information_schema.TRIGGERS WHERE TRIGGER_SCHEMA = SCHEMA()'); $rows = $result->fetchAll(PDO::FETCH_ASSOC); unset($result); $existing_triggers = $missing_triggers = array(); foreach ($rows as $row) { $existing_triggers[$row['TRIGGER_NAME']] = $row['EVENT_OBJECT_TABLE']; } foreach ($triggers as $trigger => $table) { if (!array_key_exists($trigger, $existing_triggers)) { $missing_triggers[$trigger] = $table; } } if (count($missing_triggers)) { $violations = TRUE; startPortlet('Missing Triggers (' . count($missing_triggers) . ')'); echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n"; echo "<tr><th>Table</th><th>Trigger</th></tr>\n"; $order = 'odd'; foreach ($missing_triggers as $trigger => $table) { echo "<tr class=row_{$order}>"; echo "<td>{$table}</td>"; echo "<td>{$trigger}</td>"; echo "</tr>\n"; $order = $nextorder[$order]; } echo "</table>\n"; finishPortLet(); } // check 9: missing foreign keys $fkeys = array('Atom-FK-molecule_id' => 'Atom', 'Atom-FK-rack_id' => 'Atom', 'AttributeMap-FK-chapter_id' => 'AttributeMap', 'AttributeMap-FK-attr_id' => 'AttributeMap', 'AttributeValue-FK-map' => 'AttributeValue', 'AttributeValue-FK-object' => 'AttributeValue', 'CachedPAV-FK-object-port' => 'CachedPAV', 'CachedPAV-FK-vlan_id' => 'CachedPAV', 'CachedPNV-FK-compound' => 'CachedPNV', 'CachedPVM-FK-object_id' => 'CachedPVM', 'CactiGraph-FK-server_id' => 'CactiGraph', 'CactiGraph-FK-server_id' => 'CactiGraph', 'Dictionary-FK-chapter_id' => 'Dictionary', 'FileLink-File_fkey' => 'FileLink', 'IPv4Allocation-FK-object_id' => 'IPv4Allocation', 'IPv4LB-FK-vs_id' => 'IPv4LB', 'IPv4LB-FK-object_id' => 'IPv4LB', 'IPv4LB-FK-rspool_id' => 'IPv4LB', 'IPv4NAT-FK-object_id' => 'IPv4NAT', 'IPv4RS-FK' => 'IPv4RS', 'IPv6Allocation-FK-object_id' => 'IPv6Allocation', 'Link-FK-a' => 'Link', 'Link-FK-b' => 'Link', 'MountOperation-FK-object_id' => 'MountOperation', 'MountOperation-FK-old_molecule_id' => 'MountOperation', 'MountOperation-FK-new_molecule_id' => 'MountOperation', 'MuninGraph-FK-server_id' => 'MuninGraph', 'MuninGraph-FK-server_id' => 'MuninGraph', 'ObjectHistory-FK-object_id' => 'ObjectHistory', 'ObjectLog-FK-object_id' => 'ObjectLog', 'PatchCableConnectorCompat-FK-connector_id' => 'PatchCableConnectorCompat', 'PatchCableConnectorCompat-FK-pctype_id' => 'PatchCableConnectorCompat', 'PatchCableHeap-FK-compat1' => 'PatchCableHeap', 'PatchCableHeap-FK-compat2' => 'PatchCableHeap', 'PatchCableHeapLog-FK-heap_id' => 'PatchCableHeapLog', 'PatchCableOIFCompat-FK-oif_id' => 'PatchCableOIFCompat', 'PatchCableOIFCompat-FK-pctype_id' => 'PatchCableOIFCompat', 'Port-FK-iif-oif' => 'Port', 'Port-FK-object_id' => 'Port', 'PortAllowedVLAN-FK-object-port' => 'PortAllowedVLAN', 'PortAllowedVLAN-FK-vlan_id' => 'PortAllowedVLAN', 'PortCompat-FK-oif_id1' => 'PortCompat', 'PortCompat-FK-oif_id2' => 'PortCompat', 'PortInterfaceCompat-FK-iif_id' => 'PortInterfaceCompat', 'PortInterfaceCompat-FK-oif_id' => 'PortInterfaceCompat', 'PortLog_ibfk_1' => 'PortLog', 'PortNativeVLAN-FK-compound' => 'PortNativeVLAN', 'PortVLANMode-FK-object-port' => 'PortVLANMode', 'RackSpace-FK-rack_id' => 'RackSpace', 'RackSpace-FK-object_id' => 'RackSpace', 'TagStorage-FK-TagTree' => 'TagStorage', 'TagTree-K-parent_id' => 'TagTree', 'UserConfig-FK-varname' => 'UserConfig', 'VLANDescription-FK-domain_id' => 'VLANDescription', 'VLANDescription-FK-vlan_id' => 'VLANDescription', 'VLANIPv4-FK-compound' => 'VLANIPv4', 'VLANIPv4-FK-ipv4net_id' => 'VLANIPv4', 'VLANIPv6-FK-compound' => 'VLANIPv6', 'VLANIPv6-FK-ipv6net_id' => 'VLANIPv6', 'VLANSTRule-FK-vst_id' => 'VLANSTRule', 'VLANSwitch-FK-domain_id' => 'VLANSwitch', 'VLANSwitch-FK-object_id' => 'VLANSwitch', 'VLANSwitch-FK-template_id' => 'VLANSwitch', 'VSEnabledIPs-FK-object_id' => 'VSEnabledIPs', 'VSEnabledIPs-FK-rspool_id' => 'VSEnabledIPs', 'VSEnabledIPs-FK-vs_id-vip' => 'VSEnabledIPs', 'VSEnabledPorts-FK-object_id' => 'VSEnabledPorts', 'VSEnabledPorts-FK-rspool_id' => 'VSEnabledPorts', 'VSEnabledPorts-FK-vs_id-proto-vport' => 'VSEnabledPorts', 'VSIPs-vs_id' => 'VSIPs', 'VS-vs_id' => 'VSPorts'); $result = usePreparedSelectBlade('SELECT CONSTRAINT_NAME, TABLE_NAME ' . 'FROM information_schema.TABLE_CONSTRAINTS ' . "WHERE CONSTRAINT_SCHEMA = SCHEMA() AND CONSTRAINT_TYPE = 'FOREIGN KEY'"); $rows = $result->fetchAll(PDO::FETCH_ASSOC); unset($result); $existing_fkeys = $missing_fkeys = array(); foreach ($rows as $row) { $existing_fkeys[$row['CONSTRAINT_NAME']] = $row['TABLE_NAME']; } foreach ($fkeys as $fkey => $table) { if (!array_key_exists($fkey, $existing_fkeys)) { $missing_fkeys[$fkey] = $table; } } if (count($missing_fkeys)) { $violations = TRUE; startPortlet('Missing Foreign Keys (' . count($missing_fkeys) . ')'); echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n"; echo "<tr><th>Table</th><th>Key</th></tr>\n"; $order = 'odd'; foreach ($missing_fkeys as $fkey => $table) { echo "<tr class=row_{$order}>"; echo "<td>{$table}</td>"; echo "<td>{$fkey}</td>"; echo "</tr>\n"; $order = $nextorder[$order]; } echo "</table>\n"; finishPortLet(); } // check 10: circular references // - all affected members of the tree are displayed // - it would be beneficial to only display the offending records // check 10.1: locations $invalids = array(); $locations = listCells('location'); foreach ($locations as $location) { try { $children = getLocationChildrenList($location['id']); } catch (RackTablesError $e) { $invalids[] = $location; } } if (count($invalids)) { $violations = TRUE; startPortlet('Locations: Tree Contains Circular References (' . count($invalids) . ')'); echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n"; echo "<tr><th>Child ID</th><th>Child Location</th><th>Parent ID</th><th>Parent Location</th></tr>\n"; $order = 'odd'; foreach ($invalids as $invalid) { echo "<tr class=row_{$order}>"; echo "<td>{$invalid['id']}</td>"; echo "<td>{$invalid['name']}</td>"; echo "<td>{$invalid['parent_id']}</td>"; echo "<td>{$invalid['parent_name']}</td>"; echo "</tr>\n"; $order = $nextorder[$order]; } echo "</table>\n"; finishPortLet(); } // check 10.2: objects $invalids = array(); $objects = listCells('object'); foreach ($objects as $object) { try { $children = getObjectContentsList($object['id']); } catch (RackTablesError $e) { $invalids[] = $object; } } if (count($invalids)) { $violations = TRUE; startPortlet('Objects: Tree Contains Circular References (' . count($invalids) . ')'); echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n"; echo "<tr><th>Contained ID</th><th>Contained Object</th><th>Container ID</th><th>Container Object</th></tr>\n"; $order = 'odd'; foreach ($invalids as $invalid) { echo "<tr class=row_{$order}>"; echo "<td>{$invalid['id']}</td>"; echo "<td>{$invalid['name']}</td>"; echo "<td>{$invalid['container_id']}</td>"; echo "<td>{$invalid['container_name']}</td>"; echo "</tr>\n"; $order = $nextorder[$order]; } echo "</table>\n"; finishPortLet(); } // check 10.3: tags $invalids = array(); $tags = getTagList(); foreach ($tags as $tag) { try { $children = getTagChildrenList($tag['id']); } catch (RackTablesError $e) { $invalids[] = $tag; } } if (count($invalids)) { $violations = TRUE; startPortlet('Tags: Tree Contains Circular References (' . count($invalids) . ')'); echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n"; echo "<tr><th>Child ID</th><th>Child Tag</th><th>Parent ID</th><th>Parent Tag</th></tr>\n"; $order = 'odd'; foreach ($invalids as $invalid) { echo "<tr class=row_{$order}>"; echo "<td>{$invalid['id']}</td>"; echo "<td>{$invalid['tag']}</td>"; echo "<td>{$invalid['parent_id']}</td>"; printf('<td>%s</td>', $tags[$invalid['parent_id']]['tag']); echo "</tr>\n"; $order = $nextorder[$order]; } echo "</table>\n"; finishPortLet(); } if (!$violations) { echo '<h2>No integrity violations found</h2>'; } }
function renderNewVSForm() { startPortlet('Add new virtual service'); printOpFormIntro('add'); $default_port = getConfigVar('DEFAULT_SLB_VS_PORT'); global $vs_proto; if ($default_port == 0) { $default_port = ''; } echo "<table border=0 cellpadding=5 cellspacing=0 align=center>\n"; echo "<tr><th class=tdright>VIP:</th><td class=tdleft><input type=text name=vip></td>"; echo "<tr><th class=tdright>Port:</th><td class=tdleft>"; echo "<input type=text name=vport size=5 value='{$default_port}'></td></tr>"; echo "<tr><th class=tdright>Proto:</th><td class=tdleft>"; printSelect($vs_proto, array('name' => 'proto'), array_shift(array_keys($vs_proto))); echo "</td></tr>"; echo "<tr><th class=tdright>Name:</th><td class=tdleft><input type=text name=name></td><td>"; echo "<tr><th class=tdright>Tags:</th><td class=tdleft>"; printTagsPicker(); echo "</td></tr>"; echo "<tr><th class=tdrigh>VS configuration:</th><td class=tdleft><textarea name=vsconfig rows=10 cols=80></textarea></td></tr>"; echo "<tr><th class=tdrigh>RS configuration:</th><td class=tdleft><textarea name=rsconfig rows=10 cols=80></textarea></td></tr>"; echo "<tr><td colspan=2>"; printImageHREF('CREATE', 'create virtual service', TRUE); echo "</td></tr>"; echo '</table></form>'; finishPortlet(); }
function renderNetworkEditAttrs() { global $pageno, $netobject_type_id; $network = spotEntity($pageno === 'ipv4net' ? 'ipv4net' : 'ipv6net', getBypassValue()); $values = getAttrValuesForNetwork($network); echo '<p>'; startPortlet("Attributes"); printOpFormIntro('updateAttrs'); // optional attributes echo '<table border=0 cellspacing=0 cellpadding=3 align=center>'; $suggest_records = array(); if (count($values) > 0) { $i = 0; foreach ($values as $record) { if (!permitted(NULL, NULL, NULL, array(array('tag' => '$attr_' . $record['id']), array('tag' => '$any_op')))) { continue; } echo "<input type=hidden name={$i}_attr_id value={$record['id']}>"; echo '<tr><td>'; if (strlen($record['value'])) { echo "<a href='" . makeHrefProcess(array('op' => 'clearSticker', 'id' => $network['id'], 'attr_id' => $record['id'])) . "'>"; printImageHREF('clear', 'Clear value'); echo '</a>'; } else { echo ' '; } echo '</td>'; echo "<th class=sticker>{$record['name']}:</th><td class=tdleft>"; switch ($record['type']) { case 'uint': case 'float': case 'string': echo "<input type=text name={$i}_value value='{$record['value']}'>"; break; case 'dict': $suggest_records = array(); $chapter = readChapter($record['chapter_id'], 'o'); foreach ($chapter as $id => $value) { $suggest_records[$id] = array("id" => $id, "tag" => $value); } printSuggestedInput($i . "_value", $suggest_records, array("id" => $record['key']), "macros"); enableTagsPicker(); break; case 'date': $date_value = $record['value'] ? date(getConfigVar('DATETIME_FORMAT'), $record['value']) : ''; echo "<input type=text name={$i}_value value='{$date_value}'>"; break; } $i++; echo '<input type=hidden name=num_attrs value=' . $i . ">\n"; } } echo '</table>'; printImageHREF('SAVE', 'Save changes', TRUE); echo '</form>'; finishPortlet(); }
function renderEntitySummary($cell, $title, $values = array()) { global $page_by_realm; // allow plugins to override summary table $values = callHook('modifyEntitySummary', $cell, $values); startPortlet($title); echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n"; foreach ($values as $name => $value) { if (is_array($value) and count($value) == 1) { $value = array_shift($value); echo $value; continue; } if (is_array($value)) { $name = array_shift($value); $value = array_shift($value); } elseif (!is_array($value)) { $name .= ':'; } $class = 'tdright'; $m = array(); if (preg_match('/^\\{(.*?)\\}(.*)/', $name, $m)) { $class .= ' ' . $m[1]; $name = $m[2]; } if ($name == 'tags:') { $baseurl = ''; if (isset($page_by_realm[$cell['realm']])) { $baseurl = makeHref(array('page' => $page_by_realm[$cell['realm']], 'tab' => 'default')) . "&"; } printTagTRs($cell, $baseurl); } else { echo "<tr><th width='50%' class='{$class}'>{$name}</th><td class=tdleft>{$value}</td></tr>"; } } echo "</table>\n"; finishPortlet(); }
function ViewHTML() { startPortlet(); echo "<table with=90% align=center border=0 cellpadding=5 cellspacing=0 align=center class=cooltable><tr valign=top>"; echo "<form method=post enctype=\"multipart/form-data\" action='index.php?module=redirect&page=depot&tab=facter&op=Update'>"; echo "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"30000\" />"; echo "Upload a facter file: <input name=\"userfile\" type=\"file\" /><br />"; echo "<input type=\"submit\" value=\"Upload File\" />"; echo "</td></tr></table></td></tr>"; echo "</form>"; echo "</table>"; finishPortlet(); }