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 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'>&nbsp;</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']) . '&rarr;';
            $delim = '<br>';
        }
        foreach ($addr['vsglist'] as $vs_id) {
            $vs = spotEntity('ipvs', $vs_id);
            echo $delim . mkA($vs['name'], 'ipvs', $vs['id']) . '&rarr;';
            $delim = '<br>';
        }
        foreach ($addr['rsplist'] as $rsp_id) {
            $rsp = spotEntity('ipv4rspool', $rsp_id);
            echo "{$delim}&rarr;" . 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 '&nbsp;';
            }
            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>" : '&nbsp;';
        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();
}
Example #6
0
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>';
}
Example #7
0
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();
}
Example #9
0
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 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>&nbsp;</th><th>Account</th><th>Check ID</th><th></th><th>&nbsp;</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>&nbsp;</th><th>Type</th><th>Label</th><th>Interval</th><th>Reason</th><th>Result</th><th>Unlink</th><th>&nbsp;</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} :&nbsp; &nbsp; &nbsp;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&nbsp;&nbsp;</th><th>Port label&nbsp;&nbsp;</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 "&lt;list1&gt;;&lt;list2&gt;;.... where &lt;listx&gt; is<br>";
        print "&lt;start port #&gt;|&lt;port count, use %n for number of ports&gt;|";
        print "&lt;port name, use %u for number&gt;|[&lt;port innerinterface id&gt;-]&lt;port type id&gt;[|&lt;port label, use %u for number&gt;]<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();
    }
}
Example #12
0
			<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);
}
Example #15
0
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>";
}
Example #19
0
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>&nbsp;&nbsp;&nbsp;</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>&nbsp;</td><td>{$aKey}</td><td>";
                print $aValue['remote_ports'][$aPortNum + $numAdd]['name'] . "</td></tr>\n";
            }
        }
        print "</table>";
    }
    print "</center>";
    finishPortlet();
}
Example #21
0
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>';
}
Example #22
0
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>';
}
Example #23
0
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>&nbsp;</td><th>VIP</th><th>port</th><th>proto</th><th>name</th><th>&nbsp;</th><th>Assign tags</th></tr>";
    echo '<tr valign=top><td>&nbsp;</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();
}
Example #24
0
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 renderExpirations()
{
    global $nextorder, $expirations;
    $attrmap = getAttrMap();
    foreach ($expirations as $attr_id => $sections) {
        startPortlet($attrmap[$attr_id]['name']);
        foreach ($sections as $section) {
            $count = 1;
            $order = 'odd';
            $result = scanAttrRelativeDays($attr_id, $section['from'], $section['to']);
            echo '<table align=center width=60% border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
            echo "<caption>{$section['title']}</caption>\n";
            if (!count($result)) {
                echo "<tr><td colspan=4>(none)</td></tr></table><br>\n";
                continue;
            }
            echo '<tr valign=top><th align=center>Count</th><th align=center>Name</th>';
            echo "<th align=center>Asset Tag</th><th align=center>OEM S/N 1</th><th align=center>Date Warranty <br> Expires</th></tr>\n";
            foreach ($result as $row) {
                $date_value = datetimestrFromTimestamp($row['uint_value']);
                $object = spotEntity('object', $row['object_id']);
                $attributes = getAttrValues($object['id']);
                $oem_sn_1 = array_key_exists(1, $attributes) ? $attributes[1]['a_value'] : '&nbsp;';
                echo '<tr class=' . $section['class'] . $order . ' valign=top>';
                echo "<td>{$count}</td>";
                echo '<td>' . mkA($object['dname'], 'object', $object['id']) . '</td>';
                echo "<td>{$object['asset_no']}</td>";
                echo "<td>{$oem_sn_1}</td>";
                echo "<td>{$date_value}</td>";
                echo "</tr>\n";
                $order = $nextorder[$order];
                $count++;
            }
            echo "</table><br>\n";
        }
        finishPortlet();
    }
}
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 '&nbsp;';
            }
            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();
}
Example #28
0
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();
}
Example #29
0
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();
}