Esempio n. 1
0
function renderIPv6NetworkAddresses($netinfo)
{
    global $pageno, $tabno, $aac_left;
    echo "<table class='widetable' border=0 cellspacing=0 cellpadding=5 align='center' width='100%'>\n";
    echo "<tr><th>Address</th><th>Name</th><th>Comment</th><th>Allocation</th></tr>\n";
    $hl_ip = NULL;
    if (isset($_REQUEST['hl_ip'])) {
        $hl_ip = ip6_parse($_REQUEST['hl_ip']);
        addAutoScrollScript('ip-' . ip6_format($hl_ip));
    }
    $addresses = $netinfo['addrlist'];
    ksort($addresses);
    markupIPAddrList($addresses);
    // pager
    $maxperpage = getConfigVar('IPV4_ADDRS_PER_PAGE');
    if (count($addresses) > $maxperpage && $maxperpage > 0) {
        $page = isset($_REQUEST['pg']) ? $_REQUEST['pg'] : (isset($hl_ip) ? getPageNumOfIPv6($addresses, $hl_ip, $maxperpage) : 0);
        $numpages = ceil(count($addresses) / $maxperpage);
        echo "<center><h3>{$numpages} pages:</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' => $netinfo['id'], 'pg' => $i)) . "'>{$i}</a> ";
            }
        }
        echo "</center>";
    }
    $i = 0;
    $interruped = FALSE;
    $prev_ip = ip_prev($netinfo['ip_bin']);
    foreach ($addresses as $ip_bin => $addr) {
        if (isset($page)) {
            ++$i;
            if ($i <= $maxperpage * $page) {
                continue;
            } elseif ($i > $maxperpage * ($page + 1)) {
                $interruped = TRUE;
                break;
            }
        }
        if ($ip_bin != ip_next($prev_ip)) {
            renderSeparator(ip_next($prev_ip), ip_prev($ip_bin), $hl_ip);
        }
        $prev_ip = $ip_bin;
        // render IP change history
        $title = '';
        $history_class = '';
        if (isset($addr['last_log'])) {
            $title = ' title="' . htmlspecialchars($addr['last_log']['user'] . ', ' . formatAge($addr['last_log']['time']), ENT_QUOTES) . '"';
            $history_class = 'hover-history underline';
        }
        $tr_class = $addr['class'] . ' tdleft' . ($hl_ip === $ip_bin ? ' highlight' : '');
        echo "<tr class='{$tr_class}'>";
        echo "<td><a class='{$history_class}' {$title} name='ip-{$addr['ip']}' href='" . makeHref(array('page' => 'ipaddress', 'ip' => $addr['ip'])) . "'>{$addr['ip']}</a></td>";
        $editable = empty($addr['allocs']) || !empty($addr['name']) && permitted('ipaddress', 'properties', 'editAddress') ? 'editable' : '';
        echo "<td><span class='rsvtext {$editable} id-{$addr['ip']} op-upd-ip-name'>{$addr['name']}</span></td>";
        echo "<td><span class='rsvtext {$editable} id-{$addr['ip']} op-upd-ip-comment'>{$addr['comment']}</span></td><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></tr>\n";
    }
    if (!$interruped) {
        renderSeparator(ip_next($prev_ip), ip_last($netinfo), $hl_ip);
    }
    if (isset($page)) {
        // bottom pager
        echo "<tr><td colspan=3>";
        if ($page > 0) {
            echo "<a href='" . makeHref(array('page' => $pageno, 'tab' => $tabno, 'id' => $netinfo['id'], 'pg' => $page - 1)) . "'><< prev</a> ";
        }
        if ($page < $numpages - 1) {
            echo "<a href='" . makeHref(array('page' => $pageno, 'tab' => $tabno, 'id' => $netinfo['id'], 'pg' => $page + 1)) . "'>next >></a> ";
        }
        echo "</td></tr>";
    }
    echo "</table>";
    if (permitted(NULL, NULL, 'set_reserve_comment')) {
        addJS('js/inplace-edit.js');
    }
}
function renderVMReport()
{
    $aResult = array();
    $iTotal = 0;
    $sFilter = '{$typeid_1504}';
    # typeid_1504 = Virtual machines
    foreach (scanRealmByText('object', $sFilter) as $Result) {
        $aResult[$Result['id']] = array();
        $aResult[$Result['id']]['sName'] = $Result['name'];
        // Create active links in comment
        $aResult[$Result['id']]['sComment'] = makeLinksInText($Result['comment']);
        // Load additional attributes:
        $attributes = getAttrValues($Result['id']);
        $aResult[$Result['id']]['sContact'] = '';
        if (isset($attributes['14']['a_value'])) {
            $aResult[$Result['id']]['sContact'] = $attributes['14']['a_value'];
        }
        $aResult[$Result['id']]['OEMSN'] = '';
        if (isset($attributes['1']['a_value'])) {
            $aResult[$Result['id']]['OEMSN'] = $attributes['1']['a_value'];
        }
        $aResult[$Result['id']]['sOS'] = '';
        if (isset($attributes['4']['a_value'])) {
            $aResult[$Result['id']]['sOS'] = $attributes['4']['a_value'];
        }
        // IP Informations
        $aResult[$Result['id']]['ipV4List'] = getObjectIPv4AllocationList($Result['id']);
        $aResult[$Result['id']]['ipV6List'] = getObjectIPv6AllocationList($Result['id']);
        // Port (MAC) Informations
        $aResult[$Result['id']]['ports'] = getObjectPortsAndLinks($Result['id']);
        // Container
        $aResult[$Result['id']]['container'] = getObjectContainerList($Result['id']);
        $iTotal++;
    }
    if (isset($_GET['csv'])) {
        header('Content-type: text/csv');
        header('Content-Disposition: attachment; filename=export_' . date("Ymdhis") . '.csv');
        header('Pragma: no-cache');
        header('Expires: 0');
        $outstream = fopen("php://output", "w");
        $aCSVRow = array('Name', 'MAC', 'IP(s)', 'Comment', 'Contact', 'OS', 'Hypervisor');
        fputcsv($outstream, $aCSVRow);
        foreach ($aResult as $id => $aRow) {
            $aCSVRow = array();
            $aCSVRow[0] = $aRow['sName'];
            $aCSVRow[1] = '';
            foreach ($aRow['ports'] as $portNumber => $aPortDetails) {
                if (trim($aPortDetails['l2address']) != '') {
                    $aCSVRow[1] .= $aPortDetails['l2address'] . ' ';
                }
            }
            $aCSVRow[1] = trim($aCSVRow[1]);
            $aCSVRow[2] = '';
            foreach ($aRow['ipV4List'] as $key => $aDetails) {
                if (function_exists('ip4_format')) {
                    $key = ip4_format($key);
                }
                if (trim($key) != '') {
                    $aCSVRow[2] .= $key . ' ';
                }
            }
            foreach ($aRow['ipV6List'] as $key => $aDetails) {
                if (function_exists('ip6_format')) {
                    $key = ip6_format($key);
                }
                if (trim($key) != '') {
                    $aCSVRow[2] .= $key . ' ';
                }
            }
            $aCSVRow[2] = trim($aCSVRow[2]);
            $aCSVRow[3] = str_replace('&quot;', "'", $aRow['sComment']);
            $aCSVRow[4] = $aRow['sContact'];
            $aCSVRow[5] = $aRow['sOS'];
            $aCSVRow[6] = '';
            foreach ($aRow['container'] as $key => $aDetails) {
                $aCSVRow[6] .= trim($aDetails['container_name']) . ' ';
            }
            $aCSVRow[6] = trim($aCSVRow[6]);
            fputcsv($outstream, $aCSVRow);
        }
        fclose($outstream);
        exit(0);
        # Exit normally after send CSV to browser
    }
    // Load stylesheet and jquery scripts
    addCSS('css/extensions/style.css');
    addJS('js/extensions/jquery-latest.js');
    addJS('js/extensions/jquery.tablesorter.js');
    addJS('js/extensions/picnet.table.filter.min.js');
    // Display the stat array
    echo "<h2>Virtual machines report ({$iTotal})</h2><ul>";
    echo '<a href="index.php?page=reports&tab=vm&csv">CSV Export</a>';
    echo '<table id="reportTable" class="tablesorter">
            <thead>
              <tr>
                <th>Name</th>
                <th>MAC</th>
                <th>IP(s)</th>
                <th>Comment</th>
                <th>Contact</th>
                <th>OS</th>
                <th>Hypervisor</th>
               </tr>
             </thead>
           <tbody>';
    foreach ($aResult as $id => $aRow) {
        echo '<tr>
                <td><a href="' . makeHref(array('page' => 'object', 'object_id' => $id)) . '">' . $aRow['sName'] . '</a></td>
                <td>';
        foreach ($aRow['ports'] as $portNumber => $aPortDetails) {
            if (trim($aPortDetails['l2address']) != '') {
                echo $aPortDetails['l2address'] . '<br/>';
            }
        }
        echo '  </td>' . '  <td>';
        foreach ($aRow['ipV4List'] as $key => $aDetails) {
            if (function_exists('ip4_format')) {
                $key = ip4_format($key);
            }
            if (trim($key) != '') {
                echo $key . '<br/>';
            }
        }
        foreach ($aRow['ipV6List'] as $key => $aDetails) {
            if (function_exists('ip6_format')) {
                $key = ip6_format($key);
            } else {
                $key = new IPv6Address($key);
            }
            if (trim($key) != '') {
                echo $key . '<br/>';
            }
        }
        echo '  </td>
                <td>' . $aRow['sComment'] . '</td>
                <td>' . $aRow['sContact'] . '</td>
                <td>' . $aRow['sOS'] . '</td>
                <td>';
        foreach ($aRow['container'] as $key => $aDetails) {
            echo '<a href="' . makeHref(array('page' => 'object', 'object_id' => $key)) . '">' . $aDetails['container_name'] . '</a><br/>';
        }
        echo '</td>
              </tr>';
    }
    echo '  </tbody>
          </table>';
    echo '<script type="text/javascript">
            $(document).ready(function()
              {
                $.tablesorter.defaults.widgets = ["zebra"];
                $("#reportTable").tablesorter(
                    { headers: {
                      2: { sorter: "ipAddress" }
                    }, sortList: [[0,0]] }
                );
                $("#reportTable").tableFilter();
              }
            );
          </script>';
}
Esempio n. 3
0
function renderSearchResults($terms, $summary)
{
    // calculate the number of found objects
    $nhits = 0;
    foreach ($summary as $realm => $list) {
        $nhits += count($list);
    }
    if ($nhits == 0) {
        echo "<center><h2>Nothing found for '{$terms}'</h2></center>";
    } elseif ($nhits == 1) {
        foreach ($summary as $realm => $record) {
            if (is_array($record)) {
                $record = array_shift($record);
            }
            break;
        }
        switch ($realm) {
            case 'ipv4addressbydq':
                if ($record['net_id'] !== NULL) {
                    echo "<script language='Javascript'>document.location='index.php?page=ipv4net&tab=default&id={$record['net_id']}&hl_ip={$record['ip']}';//</script>";
                }
                break;
            case 'ipv6addressbydq':
                $fmt = ip6_format($record['ip']);
                if ($record['net_id'] !== NULL) {
                    echo "<script language='Javascript'>document.location='index.php?page=ipv6net&tab=default&id={$record['net_id']}&hl_ip={$fmt}';//</script>";
                }
                break;
            case 'ipv4addressbydescr':
                $parentnet = getIPv4AddressNetworkId($record['ip']);
                if ($parentnet !== NULL) {
                    $fmt = ip4_format($record['ip']);
                    echo "<script language='Javascript'>document.location='index.php?page=ipv4net&tab=default&id={$parentnet}&hl_ip={$fmt}';//</script>";
                }
                break;
            case 'ipv6addressbydescr':
                $parentnet = getIPv6AddressNetworkId($record['ip']);
                if ($parentnet !== NULL) {
                    $fmt = ip6_format($record['ip']);
                    echo "<script language='Javascript'>document.location='index.php?page=ipv6net&tab=default&id={$parentnet}&hl_ip={$fmt}';//</script>";
                }
                break;
            case 'ipv4network':
                echo "<script language='Javascript'>document.location='index.php?page=ipv4net";
                echo "&id={$record['id']}";
                echo "';//</script>";
                break;
            case 'ipv6network':
                echo "<script language='Javascript'>document.location='index.php?page=ipv6net";
                echo "&id={$record['id']}";
                echo "';//</script>";
                break;
            case 'object':
                if (isset($record['by_port']) and 1 == count($record['by_port'])) {
                    $found_ports_ids = array_keys($record['by_port']);
                    $hl = '&hl_port_id=' . $found_ports_ids[0];
                } else {
                    $hl = '';
                }
                echo "<script language='Javascript'>document.location='index.php?page=object&object_id={$record['id']}{$hl}';//</script>";
                break;
            case 'ipv4rspool':
                echo "<script language='Javascript'>document.location='index.php?page=ipv4rspool&pool_id={$record['id']}';//</script>";
                break;
            case 'ipv4vs':
                echo "<script language='Javascript'>document.location='index.php?page=ipv4vs&vs_id={$record['id']}';//</script>";
                break;
            case 'user':
                echo "<script language='Javascript'>document.location='index.php?page=user&user_id={$record['user_id']}';//</script>";
                break;
            case 'file':
                echo "<script language='Javascript'>document.location='index.php?page=file&file_id={$record['id']}';//</script>";
                break;
            case 'rack':
                echo "<script language='Javascript'>document.location='index.php?page=rack&rack_id={$record['id']}';//</script>";
                break;
            case 'vlan':
                echo "<script language='Javascript'>document.location='index.php?page=vlan&vlan_ck={$record}';//</script>";
                break;
            default:
                startPortlet($realm);
                echo $record;
                finishPortlet();
        }
        return;
    } else {
        global $nextorder;
        $order = 'odd';
        echo "<center><h2>{$nhits} result(s) found for '{$terms}'</h2></center>";
        foreach ($summary as $where => $what) {
            switch ($where) {
                case 'object':
                    startPortlet("<a href='index.php?page=depot'>Objects</a>");
                    echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                    echo '<tr><th>what</th><th>why</th></tr>';
                    foreach ($what as $obj) {
                        echo "<tr class=row_{$order} valign=top><td>";
                        $object = spotEntity('object', $obj['id']);
                        renderCell($object);
                        echo "</td><td class=tdleft>";
                        if (isset($obj['by_attr'])) {
                            // only explain non-obvious reasons for listing
                            echo '<ul>';
                            foreach ($obj['by_attr'] as $attr_name) {
                                if ($attr_name != 'name') {
                                    echo "<li>{$attr_name} matched</li>";
                                }
                            }
                            echo '</ul>';
                        }
                        if (isset($obj['by_sticker'])) {
                            echo '<table>';
                            $aval = getAttrValues($obj['id']);
                            foreach ($obj['by_sticker'] as $attr_id) {
                                $record = $aval[$attr_id];
                                echo "<tr><th width='50%' class=sticker>{$record['name']}:</th>";
                                echo "<td class=sticker>" . formatAttributeValue($record) . "</td></tr>";
                            }
                            echo '</table>';
                        }
                        if (isset($obj['by_port'])) {
                            echo '<table>';
                            amplifyCell($object);
                            foreach ($obj['by_port'] as $port_id => $text) {
                                foreach ($object['ports'] as $port) {
                                    if ($port['id'] == $port_id) {
                                        $port_href = '<a href="' . makeHref(array('page' => 'object', 'object_id' => $object['id'], 'hl_port_id' => $port_id)) . '">port ' . $port['name'] . '</a>';
                                        echo "<tr><td>{$port_href}:</td>";
                                        echo "<td class=tdleft>{$text}</td></tr>";
                                        break;
                                        // next reason
                                    }
                                }
                            }
                            echo '</table>';
                        }
                        if (isset($obj['by_iface'])) {
                            echo '<ul>';
                            foreach ($obj['by_iface'] as $ifname) {
                                echo "<li>interface {$ifname}</li>";
                            }
                            echo '</ul>';
                        }
                        if (isset($obj['by_nat'])) {
                            echo '<ul>';
                            foreach ($obj['by_nat'] as $comment) {
                                echo "<li>NAT rule: {$comment}</li>";
                            }
                            echo '</ul>';
                        }
                        if (isset($obj['by_cableid'])) {
                            echo '<ul>';
                            foreach ($obj['by_cableid'] as $cableid) {
                                echo "<li>link cable ID: {$cableid}</li>";
                            }
                            echo '</ul>';
                        }
                        echo "</td></tr>";
                        $order = $nextorder[$order];
                    }
                    echo '</table>';
                    finishPortlet();
                    break;
                case 'ipv4network':
                    startPortlet("<a href='index.php?page=ipv4space'>IPv4 networks</a>");
                case 'ipv6network':
                    if ($where == 'ipv6network') {
                        startPortlet("<a href='index.php?page=ipv6space'>IPv6 networks</a>");
                    }
                    echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                    foreach ($what as $cell) {
                        echo "<tr class=row_{$order} valign=top><td>";
                        renderCell($cell);
                        echo "</td></tr>\n";
                        $order = $nextorder[$order];
                    }
                    echo '</table>';
                    finishPortlet();
                    break;
                case 'ipv4addressbydescr':
                    startPortlet('IPv4 addresses');
                    echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                    // FIXME: address, parent network, routers (if extended view is enabled)
                    echo '<tr><th>Address</th><th>Description</th></tr>';
                    foreach ($what as $addr) {
                        echo "<tr class=row_{$order}><td class=tdleft>";
                        $fmt = ip4_format($addr['ip']);
                        $parentnet = getIPv4AddressNetworkId($addr['ip']);
                        if ($parentnet !== NULL) {
                            echo "<a href='index.php?page=ipv4net&tab=default&id={$parentnet}&hl_ip={$fmt}'>{$fmt}</a></td>";
                        } else {
                            echo "<a href='index.php?page=ipaddress&ip={$fmt}'>{$fmt}</a></td>";
                        }
                        echo "<td class=tdleft>{$addr['name']}</td></tr>";
                        $order = $nextorder[$order];
                    }
                    echo '</table>';
                    finishPortlet();
                    break;
                case 'ipv6addressbydescr':
                    startPortlet('IPv6 addresses');
                    echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                    // FIXME: address, parent network, routers (if extended view is enabled)
                    echo '<tr><th>Address</th><th>Description</th></tr>';
                    foreach ($what as $addr) {
                        echo "<tr class=row_{$order}><td class=tdleft>";
                        $fmt = ip6_format($addr['ip']);
                        $parentnet = getIPv6AddressNetworkId($addr['ip']);
                        if ($parentnet !== NULL) {
                            echo "<a href='index.php?page=ipv6net&tab=default&id={$parentnet}&hl_ip={$fmt}'>{$fmt}</a></td>";
                        } else {
                            echo "<a href='index.php?page=ipaddress&ip={$fmt}'>{$fmt}</a></td>";
                        }
                        echo "<td class=tdleft>{$addr['name']}</td></tr>";
                        $order = $nextorder[$order];
                    }
                    echo '</table>';
                    finishPortlet();
                    break;
                case 'ipv4rspool':
                    startPortlet("<a href='index.php?page=ipv4slb&tab=rspools'>RS pools</a>");
                    echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                    foreach ($what as $cell) {
                        echo "<tr class=row_{$order}><td class=tdleft>";
                        renderCell($cell);
                        echo "</td></tr>";
                        $order = $nextorder[$order];
                    }
                    echo '</table>';
                    finishPortlet();
                    break;
                case 'ipv4vs':
                    startPortlet("<a href='index.php?page=ipv4slb&tab=default'>Virtual services</a>");
                    echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                    foreach ($what as $cell) {
                        echo "<tr class=row_{$order}><td class=tdleft>";
                        renderCell($cell);
                        echo "</td></tr>";
                        $order = $nextorder[$order];
                    }
                    echo '</table>';
                    finishPortlet();
                    break;
                case 'user':
                    startPortlet("<a href='index.php?page=userlist'>Users</a>");
                    echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                    foreach ($what as $item) {
                        echo "<tr class=row_{$order}><td class=tdleft>";
                        renderCell($item);
                        echo "</td></tr>";
                        $order = $nextorder[$order];
                    }
                    echo '</table>';
                    finishPortlet();
                    break;
                case 'file':
                    startPortlet("<a href='index.php?page=files'>Files</a>");
                    echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                    foreach ($what as $cell) {
                        echo "<tr class=row_{$order}><td class=tdleft>";
                        renderCell($cell);
                        echo "</td></tr>";
                        $order = $nextorder[$order];
                    }
                    echo '</table>';
                    finishPortlet();
                    break;
                case 'rack':
                    startPortlet("<a href='index.php?page=rackspace'>Racks</a>");
                    echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                    foreach ($what as $cell) {
                        echo "<tr class=row_{$order}><td class=tdleft>";
                        renderCell($cell);
                        echo "</td></tr>";
                        $order = $nextorder[$order];
                    }
                    echo '</table>';
                    finishPortlet();
                    break;
                case 'vlan':
                    startPortlet("<a href='index.php?page=8021q'>VLANs</a>");
                    echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                    foreach ($what as $vlan_ck) {
                        echo "<tr class=row_{$order}><td class=tdleft>";
                        echo formatVLANName(getVLANInfo($vlan_ck), 'hyperlink') . "</td></tr>";
                        $order = $nextorder[$order];
                    }
                    echo '</table>';
                    finishPortlet();
                    break;
                default:
                    // you can use that in your plugins to add some non-standard search results
                    startPortlet($where);
                    echo $what;
                    finishPortlet();
            }
        }
    }
}
function renderCustomReport()
{
    # Get object list
    $phys_typelist = readChapter(CHAP_OBJTYPE, 'o');
    $attibutes = getAttrMap();
    $aTagList = getTagList();
    if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['csv'])) {
        header('Content-type: text/csv');
        header('Content-Disposition: attachment; filename=export_' . date("Ymdhis") . '.csv');
        header('Pragma: no-cache');
        header('Expires: 0');
        $outstream = fopen("php://output", "w");
        $aResult = getResult($_POST);
        // Get Result
        $_POST['name'] = validateColums($_POST);
        // Fix empty colums
        $csvDelimiter = isset($_POST['csvDelimiter']) ? $_POST['csvDelimiter'] : ',';
        /* Create Header */
        $aCSVRow = array();
        if (isset($_POST['sName']) && $_POST['sName']) {
            array_push($aCSVRow, "Name");
        }
        if (isset($_POST['label'])) {
            array_push($aCSVRow, "Label");
        }
        if (isset($_POST['type'])) {
            array_push($aCSVRow, "Type");
        }
        if (isset($_POST['asset_no'])) {
            array_push($aCSVRow, "Asset Tag");
        }
        if (isset($_POST['has_problems'])) {
            array_push($aCSVRow, "Has Problems");
        }
        if (isset($_POST['comment'])) {
            array_push($aCSVRow, "Comment");
        }
        if (isset($_POST['runs8021Q'])) {
            array_push($aCSVRow, "Runs 8021Q");
        }
        if (isset($_POST['location'])) {
            array_push($aCSVRow, "Location");
        }
        if (isset($_POST['MACs'])) {
            array_push($aCSVRow, "MACs");
        }
        if (isset($_POST['IPs'])) {
            array_push($aCSVRow, "IPs");
        }
        if (isset($_POST['attributeIDs'])) {
            foreach ($_POST['attributeIDs'] as $attributeID) {
                array_push($aCSVRow, $attibutes[$attributeID]['name']);
            }
        }
        if (isset($_POST['Tags'])) {
            array_push($aCSVRow, "Tags");
        }
        if (isset($_POST['Ports'])) {
            array_push($aCSVRow, "Ports");
        }
        if (isset($_POST['Containers'])) {
            array_push($aCSVRow, "Containers");
        }
        if (isset($_POST['Childs'])) {
            array_push($aCSVRow, "Child objects");
        }
        fputcsv($outstream, $aCSVRow, $csvDelimiter);
        /* Create data rows */
        foreach ($aResult as $Result) {
            $aCSVRow = array();
            if (isset($_POST['sName'])) {
                array_push($aCSVRow, $Result['name']);
            }
            if (isset($_POST['label'])) {
                array_push($aCSVRow, $Result['label']);
            }
            if (isset($_POST['type'])) {
                array_push($aCSVRow, $phys_typelist[$Result['objtype_id']]);
            }
            if (isset($_POST['asset_no'])) {
                array_push($aCSVRow, $Result['asset_no']);
            }
            if (isset($_POST['has_problems'])) {
                array_push($aCSVRow, $Result['has_problems']);
            }
            if (isset($_POST['comment'])) {
                array_push($aCSVRow, str_replace('&quot;', "'", $Result['comment']));
            }
            if (isset($_POST['runs8021Q'])) {
                array_push($aCSVRow, $Result['runs8021Q']);
            }
            if (isset($_POST['location'])) {
                array_push($aCSVRow, preg_replace('/<a[^>]*>(.*)<\\/a>/iU', '$1', getLocation($Result)));
            }
            if (isset($_POST['MACs'])) {
                $sTemp = '';
                foreach (getObjectPortsAndLinks($Result['id']) as $portNumber => $aPortDetails) {
                    if (trim($aPortDetails['l2address']) != '') {
                        $sTemp .= $aPortDetails['l2address'] . ' ';
                    }
                }
                array_push($aCSVRow, $sTemp);
            }
            if (isset($_POST['IPs'])) {
                $sTemp = '';
                foreach (getObjectIPv4AllocationList($Result['id']) as $key => $aDetails) {
                    if (function_exists('ip4_format')) {
                        $key = ip4_format($key);
                    }
                    if (trim($key) != '') {
                        $sTemp .= $key . ' ';
                    }
                }
                foreach (getObjectIPv6AllocationList($Result['id']) as $key => $aDetails) {
                    if (function_exists('ip6_format')) {
                        $key = ip6_format($key);
                    } else {
                        $key = new IPv6Address($key);
                    }
                    if (trim($key) != '') {
                        $sTemp .= $key . ' ';
                    }
                }
                array_push($aCSVRow, $sTemp);
            }
            if (isset($_POST['attributeIDs'])) {
                $attributes = getAttrValues($Result['id']);
                foreach ($_POST['attributeIDs'] as $attributeID) {
                    if (isset($attributes[$attributeID]['a_value'])) {
                        array_push($aCSVRow, $attributes[$attributeID]['a_value']);
                    } elseif ($attributes[$attributeID]['value'] != '' && $attributes[$attributeID]['type'] == 'date') {
                        array_push($aCSVRow, date("Y-m-d", $attributes[$attributeID]['value']));
                    } else {
                        array_push($aCSVRow, '');
                    }
                }
            }
            if (isset($_POST['Tags'])) {
                $sTemp = '';
                foreach ($Result['tags'] as $aTag) {
                    $sTemp .= $aTag['tag'] . ' ';
                }
                if (count($Result['itags']) > 0) {
                    $sTemp .= '(';
                    foreach ($Result['itags'] as $aTag) {
                        $sTemp .= $aTag['tag'] . ' ';
                    }
                    $sTemp .= ')';
                }
                array_push($aCSVRow, $sTemp);
            }
            if (isset($_POST['Ports'])) {
                $sTemp = '';
                foreach ($Result['portsLinks'] as $port) {
                    $sTemp .= $port['name'] . ': ' . $port['remote_object_name'];
                    if (trim($port['cableid']) != '') {
                        $sTemp .= ' Cable ID: ' . $port['cableid'];
                    }
                    $sTemp .= ' ';
                }
                $sTemp = trim($sTemp);
                array_push($aCSVRow, $sTemp);
            }
            if (isset($_POST['Containers'])) {
                $sTemp = '';
                foreach (getObjectContainerList($Result['id']) as $key => $aDetails) {
                    $sTemp .= trim($aDetails['container_name']) . ' ';
                }
                $sTemp = trim($sTemp);
                array_push($aCSVRow, $sTemp);
            }
            if (isset($_POST['Childs'])) {
                $sTemp = '';
                foreach (getObjectChildObjectList($Result['id']) as $key => $aDetails) {
                    $sTemp .= trim($aDetails['object_name']) . ' ';
                }
                $sTemp = trim($sTemp);
                array_push($aCSVRow, $sTemp);
            }
            fputcsv($outstream, $aCSVRow, $csvDelimiter);
        }
        fclose($outstream);
        exit(0);
        # Exit normally after send CSV to browser
    }
    echo '<h2>Custom report</h2><ul>';
    // Load stylesheet and jquery scripts
    addCSS('css/extensions/style.css');
    addJS('js/extensions/saveFormValues.js');
    addJS('js/extensions/jquery-latest.js');
    addJS('js/extensions/jquery.tablesorter.js');
    addJS('js/extensions/picnet.table.filter.min.js');
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        echo '<a href="#" class="show_hide">Show/hide search form</a><br/><br/>';
    }
    echo '<div class="searchForm">';
    echo '<form method="post" name="searchForm">';
    echo '<table class="searchTable">
            <tr>
              <th>Object Type</th>
              <th>Common Values</th>
              <th>Attributes</th>
              <th>Tags</th>
              <th>Misc</th>
            </tr>
            <tr>';
    echo '<td valign="top">
             <table class="searchTable">';
    $i = 0;
    foreach ($phys_typelist as $objectTypeID => $sName) {
        if ($i % 2) {
            echo '<tr class="odd">';
        } else {
            echo '<tr>';
        }
        echo '  <td>
                   <input type="checkbox" name="objectIDs[]" value="' . $objectTypeID . '"';
        if (isset($_POST['objectIDs']) && in_array($objectTypeID, $_POST['objectIDs'])) {
            echo ' checked="checked"';
        }
        echo '     > ' . $sName . '
                 </td>
               </tr>';
        $i++;
    }
    echo '  </table>
           </td>';
    echo '<td valign="top">
           <table class="searchTable">
             <tr><td><input type="checkbox" name="sName" value="1" ';
    if (isset($_POST['sName'])) {
        echo ' checked="checked"';
    }
    echo '> Name</td></tr>
             <tr class="odd"><td><input type="checkbox" name="label" value="1" ';
    if (isset($_POST['label'])) {
        echo ' checked="checked"';
    }
    echo '> Label</td></tr>
             <tr><td><input type="checkbox" name="type" value="1" ';
    if (isset($_POST['type'])) {
        echo ' checked="checked"';
    }
    echo '> Type</td></tr>
             <tr class="odd"><td><input type="checkbox" name="asset_no" value="1" ';
    if (isset($_POST['asset_no'])) {
        echo ' checked="checked"';
    }
    echo '> Asset Tag</td></tr>
             <tr><td><input type="checkbox" name="location" value="1" ';
    if (isset($_POST['location'])) {
        echo ' checked="checked"';
    }
    echo '> Location</td></tr>
             <tr class="odd"><td><input type="checkbox" name="has_problems" value="1" ';
    if (isset($_POST['has_problems'])) {
        echo ' checked="checked"';
    }
    echo '> Has Problems</td></tr>
             <tr><td><input type="checkbox" name="comment" value="1" ';
    if (isset($_POST['comment'])) {
        echo ' checked="checked"';
    }
    echo '> Comment</td></tr>
             <tr class="odd"><td><input type="checkbox" name="runs8021Q" value="1" ';
    if (isset($_POST['runs8021Q'])) {
        echo ' checked="checked"';
    }
    echo '> Runs 8021Q</td></tr>
             <tr><td><input type="checkbox" name="MACs" value="1" ';
    if (isset($_POST['MACs'])) {
        echo ' checked="checked"';
    }
    echo '> MACs</td></tr>
             <tr class="odd"><td><input type="checkbox" name="IPs" value="1" ';
    if (isset($_POST['IPs'])) {
        echo ' checked="checked"';
    }
    echo '> IPs</td></tr>
             <tr><td><input type="checkbox" name="Tags" value="1" ';
    if (isset($_POST['Tags'])) {
        echo ' checked="checked"';
    }
    echo '> Tags</td></tr>
             <tr class="odd"><td><input type="checkbox" name="Ports" value="1" ';
    if (isset($_POST['Ports'])) {
        echo ' checked="checked"';
    }
    echo '> Ports</td></tr>
             <tr><td><input type="checkbox" name="Containers" value="1" ';
    if (isset($_POST['Containers'])) {
        echo ' checked="checked"';
    }
    echo '> Containers</td></tr>
             <tr class="odd"><td><input type="checkbox" name="Childs" value="1" ';
    if (isset($_POST['Childs'])) {
        echo ' checked="checked"';
    }
    echo '> Child objects</td></tr>
           </table>
         </td>';
    echo '<td valign="top">
             <table class="searchTable">';
    $i = 0;
    foreach ($attibutes as $attributeID => $aRow) {
        if ($i % 2) {
            echo '<tr class="odd">';
        } else {
            echo '<tr>';
        }
        echo ' <td>
                <input type="checkbox" name="attributeIDs[]" value="' . $attributeID . '"';
        if (isset($_POST['attributeIDs']) && in_array($attributeID, $_POST['attributeIDs'])) {
            echo ' checked="checked"';
        }
        echo '> ' . $aRow['name'] . '
              </td>
             </tr>';
        $i++;
    }
    echo '  </table>
           </td>';
    echo '<td valign="top">
            <table class="searchTable">';
    $i = 0;
    foreach ($aTagList as $aTag) {
        echo '<tr ' . ($i % 2 ? 'class="odd"' : '') . '>
                <td>
                  <input type="checkbox" name="tag[' . $aTag['id'] . ']" value="1" ' . (isset($_POST['tag'][$aTag['id']]) ? 'checked="checked" ' : '') . '> ' . $aTag['tag'] . '
                </td>
              </tr>';
        $i++;
    }
    if (count($aTagList) < 1) {
        echo '<tr><td><i>No Tags available</i></td></tr>';
    }
    echo '  </table>
          </td>';
    echo '<td valign="top">
            <table class="searchTable">
              <tr><td><input type="checkbox" name="csv" value="1"> CSV Export</td></tr>
              <tr><td><input type="text" name="csvDelimiter" value="," size="1"> CSV Delimiter</td></tr>
              <tr class="odd"><td>Name Filter: <i>(Regular Expression)</i></td></tr>
              <tr><td><input type="text" name="name_preg" value="';
    if (isset($_POST['name_preg'])) {
        echo $_POST['name_preg'];
    }
    echo '" style="height: 11pt;"></td></tr>
              <tr class="odd"><td>Asset Tag Filter: <i>(Regular Expression)</i></td></tr>
              <tr><td><input type="text" name="tag_preg" value="';
    if (isset($_POST['tag_preg'])) {
        echo $_POST['tag_preg'];
    }
    echo '" style="height: 11pt;"></td></tr>
              <tr class="odd"><td>Comment Filter: <i>(Regular Expression)</i></td></tr>
              <tr><td><input type="text" name="comment_preg" value="';
    if (isset($_POST['comment_preg'])) {
        echo $_POST['comment_preg'];
    }
    echo '" style="height: 11pt;"></td></tr>
              <tr class="odd"><td>&nbsp;</td></tr>
              <tr>
                <td>
                  Save:
                  <input id="nameQuery" type="text" name="nameQuery" value="" style="height: 11pt; width:155px"/> <input type="button" value=" Ok " onclick="saveQuery();">
                  <br/>
                  Load:<br/>
                   <span id="loadButtons"></span>
                   <script type="text/javascript">
                     loadButtons();
                   </script>
                </td>
              </tr>
              <tr class="odd"><td>&nbsp;</td></tr>
              <tr><td align="right"><input type="submit" value=" Search "></td></tr>
            </table>
          </td>
        </tr>
      </table>';
    echo '</form>';
    echo '</div>';
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        $aResult = getResult($_POST);
        // Get Result
        $_POST['sName'] = validateColums($_POST);
        // Fix empty colums
        if (count($aResult) > 0) {
            echo '<table  id="customTable" class="tablesorter">
               <thead>
                 <tr>';
            if (isset($_POST['sName']) && $_POST['sName']) {
                echo '<th>Name</th>';
            }
            if (isset($_POST['label'])) {
                echo '<th>Label</th>';
            }
            if (isset($_POST['type'])) {
                echo '<th>Type</th>';
            }
            if (isset($_POST['asset_no'])) {
                echo '<th>Asset Tag</th>';
            }
            if (isset($_POST['has_problems'])) {
                echo '<th>Has Problems</th>';
            }
            if (isset($_POST['comment'])) {
                echo '<th>Comment</th>';
            }
            if (isset($_POST['runs8021Q'])) {
                echo '<th>Runs 8021Q</th>';
            }
            if (isset($_POST['location'])) {
                echo '<th>Location</th>';
            }
            if (isset($_POST['MACs'])) {
                echo '<th>MACs</th>';
            }
            if (isset($_POST['IPs'])) {
                echo '<th>IPs</th>';
            }
            if (isset($_POST['attributeIDs'])) {
                foreach ($_POST['attributeIDs'] as $attributeID) {
                    echo '<th>' . $attibutes[$attributeID]['name'] . '</th>';
                }
            }
            if (isset($_POST['Tags'])) {
                echo '<th>Tags</th>';
            }
            if (isset($_POST['Ports'])) {
                echo '<th>Ports</th>';
            }
            if (isset($_POST['Containers'])) {
                echo '<th>Containers</th>';
            }
            if (isset($_POST['Childs'])) {
                echo '<th>Child objects</th>';
            }
            echo '  </tr>
              </thead>
              <tbody>';
            foreach ($aResult as $Result) {
                echo '<tr>';
                if (isset($_POST['sName'])) {
                    echo '<td>
                        <span class="object_' . str_replace('$', '', $Result['atags'][1]['tag']) . '">';
                    if (isset($Result['name'])) {
                        echo '<a href="' . makeHref(array('page' => 'object', 'object_id' => $Result['id'])) . '">' . $Result['name'] . '</a>';
                    } else {
                        echo '&nbsp;';
                    }
                    echo '  </span>
                       </td>';
                }
                if (isset($_POST['label'])) {
                    echo '<td>';
                    if (isset($Result['label'])) {
                        echo $Result['label'];
                    } else {
                        echo '&nbsp;';
                    }
                    echo '</td>';
                }
                if (isset($_POST['type'])) {
                    echo '<td>';
                    if (isset($Result['objtype_id'])) {
                        echo $phys_typelist[$Result['objtype_id']];
                    } else {
                        echo '&nbsp;';
                    }
                    echo '</td>';
                }
                if (isset($_POST['asset_no'])) {
                    echo '<td>';
                    if (isset($Result['asset_no'])) {
                        echo $Result['asset_no'];
                    } else {
                        echo '&nbsp;';
                    }
                    echo '</td>';
                }
                if (isset($_POST['has_problems'])) {
                    echo '<td>';
                    if (isset($Result['has_problems'])) {
                        echo $Result['has_problems'];
                    } else {
                        echo '&nbsp;';
                    }
                    echo '</td>';
                }
                if (isset($_POST['comment'])) {
                    echo '<td>';
                    if (isset($Result['comment'])) {
                        echo makeLinksInText($Result['comment']);
                    } else {
                        echo '&nbsp;';
                    }
                    echo '</td>';
                }
                if (isset($_POST['runs8021Q'])) {
                    echo '<td>';
                    if (isset($Result['runs8021Q'])) {
                        echo $Result['runs8021Q'];
                    } else {
                        echo '&nbsp;';
                    }
                    echo '</td>';
                }
                if (isset($_POST['location'])) {
                    echo '<td>';
                    echo getLocation($Result);
                    echo '</td>';
                }
                if (isset($_POST['MACs'])) {
                    echo '<td>';
                    foreach (getObjectPortsAndLinks($Result['id']) as $portNumber => $aPortDetails) {
                        if (trim($aPortDetails['l2address']) != '') {
                            echo $aPortDetails['l2address'] . '<br/>';
                        }
                    }
                    echo '</td>';
                }
                if (isset($_POST['IPs'])) {
                    echo '<td>';
                    foreach (getObjectIPv4AllocationList($Result['id']) as $key => $aDetails) {
                        if (function_exists('ip4_format')) {
                            $key = ip4_format($key);
                        }
                        if (trim($key) != '') {
                            echo $key . '<br/>';
                        }
                    }
                    foreach (getObjectIPv6AllocationList($Result['id']) as $key => $aDetails) {
                        if (function_exists('ip6_format')) {
                            $key = ip6_format($key);
                        } else {
                            $key = new IPv6Address($key);
                        }
                        if (trim($key) != '') {
                            echo $key . '<br/>';
                        }
                    }
                    echo '</td>';
                }
                if (isset($_POST['attributeIDs'])) {
                    $attributes = getAttrValues($Result['id']);
                    foreach ($_POST['attributeIDs'] as $attributeID) {
                        echo '<td>';
                        if (isset($attributes[$attributeID]['a_value']) && $attributes[$attributeID]['a_value'] != '') {
                            echo $attributes[$attributeID]['a_value'];
                        } elseif ($attributes[$attributeID]['value'] != '' && $attributes[$attributeID]['type'] == 'date') {
                            echo date("Y-m-d", $attributes[$attributeID]['value']);
                        } else {
                            echo '&nbsp;';
                        }
                    }
                }
                if (isset($_POST['Tags'])) {
                    echo '<td>';
                    foreach ($Result['tags'] as $aTag) {
                        echo '<a href="' . makeHref(array('page' => 'depot', 'tab' => 'default', 'andor' => 'and', 'cft[]' => $aTag['id'])) . '">' . $aTag['tag'] . '</a> ';
                    }
                    if (count($Result['itags']) > 0) {
                        echo '(';
                        foreach ($Result['itags'] as $aTag) {
                            echo '<a href="' . makeHref(array('page' => 'depot', 'tab' => 'default', 'andor' => 'and', 'cft[]' => $aTag['id'])) . '">' . $aTag['tag'] . '</a> ';
                        }
                        echo ')';
                    }
                    echo '</td>';
                }
                if (isset($_POST['Ports'])) {
                    echo '<td>';
                    foreach ($Result['portsLinks'] as $port) {
                        echo $port['name'] . ': ';
                        if ($port['remote_object_name'] != 'unknown') {
                            echo formatPortLink($port['remote_object_id'], $port['remote_object_name'], $port['remote_id'], NULL);
                        } else {
                            echo $port['remote_object_name'];
                        }
                        if (trim($port['cableid']) != '') {
                            echo ' Cable ID: ' . $port['cableid'];
                        }
                        echo '<br/>';
                    }
                    echo '</td>';
                }
                if (isset($_POST['Containers'])) {
                    echo '<td>';
                    foreach (getObjectContainerList($Result['id']) as $key => $aDetails) {
                        echo '<a href="' . makeHref(array('page' => 'object', 'object_id' => $key)) . '">' . $aDetails['container_name'] . '</a><br/>';
                    }
                    echo '</td>';
                }
                if (isset($_POST['Childs'])) {
                    echo '<td>';
                    foreach (getObjectChildObjectList($Result['id']) as $key => $aDetails) {
                        echo '<a href="' . makeHref(array('page' => 'object', 'object_id' => $key)) . '">' . $aDetails['object_name'] . '</a><br/>';
                    }
                    echo '</td>';
                }
                echo '</tr>';
            }
            echo '  </tbody>
              </table>
              <script type="text/javascript">$(".searchForm").hide();</script>';
        } else {
            echo '<br/><br/><div align="center" style="font-size:10pt;"><i>No items found !!!</i></div><br/>';
        }
        echo '<script type="text/javascript">
               $(document).ready(function()
                 {
                   $.tablesorter.defaults.widgets = ["zebra"];
                   $("#customTable").tablesorter(
                     { headers: {
                     }, sortList: [[0,0]] }
                   );
                   $("#customTable").tableFilter();

                   $(".show_hide").show();

                   $(".show_hide").click(function(){
                     $(".searchForm").slideToggle(\'slow\');
                   });

                 }
                 );
            </script>';
    }
}
Esempio n. 5
0
function constructIPRange($ip_bin, $mask)
{
    $node = array();
    switch (strlen($ip_bin)) {
        case 4:
            // IPv4
            if ($mask < 0 || $mask > 32) {
                throw new InvalidArgException('mask', $mask, "Invalid v4 prefix length");
            }
            $node['mask_bin'] = ip4_mask($mask);
            $node['mask'] = $mask;
            $node['ip_bin'] = $ip_bin & $node['mask_bin'];
            $node['ip'] = ip4_format($node['ip_bin']);
            break;
        case 16:
            // IPv6
            if ($mask < 0 || $mask > 128) {
                throw new InvalidArgException('mask', $mask, "Invalid v6 prefix length");
            }
            $node['mask_bin'] = ip6_mask($mask);
            $node['mask'] = $mask;
            $node['ip_bin'] = $ip_bin & $node['mask_bin'];
            $node['ip'] = ip6_format($node['ip_bin']);
            break;
        default:
            throw new InvalidArgException('ip_bin', $ip_bin, "Invalid binary IP");
    }
    return $node;
}
Esempio n. 6
0
function renderServerReport()
{
    $aResult = array();
    $iTotal = 0;
    $sFilter = '{$typeid_4}';
    # typeid_4 = Server
    foreach (scanRealmByText('object', $sFilter) as $Result) {
        $aResult[$Result['id']] = array();
        $aResult[$Result['id']]['sName'] = $Result['name'];
        // Create active links in comment
        $aResult[$Result['id']]['sComment'] = $Result['comment'];
        // Load additional attributes:
        $attributes = getAttrValues($Result['id']);
        $aResult[$Result['id']]['sContact'] = '';
        if (isset($attributes['14']['a_value'])) {
            $aResult[$Result['id']]['sContact'] = $attributes['14']['a_value'];
        }
        $aResult[$Result['id']]['HWtype'] = '';
        if (isset($attributes['2']['a_value'])) {
            $aResult[$Result['id']]['HWtype'] = $attributes['2']['a_value'];
        }
        $aResult[$Result['id']]['OEMSN'] = '';
        if (isset($attributes['1']['a_value'])) {
            $aResult[$Result['id']]['OEMSN'] = $attributes['1']['a_value'];
        }
        $aResult[$Result['id']]['HWExpDate'] = '';
        if (isset($attributes['22']['value'])) {
            $aResult[$Result['id']]['HWExpDate'] = date("Y-m-d", $attributes['22']['value']);
        }
        $aResult[$Result['id']]['sOS'] = '';
        if (isset($attributes['4']['a_value'])) {
            $aResult[$Result['id']]['sOS'] = $attributes['4']['a_value'];
        }
        $aResult[$Result['id']]['sSlotNumber'] = 'unknown';
        if (isset($attributes['28']['a_value']) && $attributes['28']['a_value'] != '') {
            $aResult[$Result['id']]['sSlotNumber'] = $attributes['28']['a_value'];
        }
        // Location
        $aResult[$Result['id']]['sLocation'] = getLocation($Result);
        // IP Informations
        $aResult[$Result['id']]['ipV4List'] = getObjectIPv4AllocationList($Result['id']);
        $aResult[$Result['id']]['ipV6List'] = getObjectIPv6AllocationList($Result['id']);
        // Port (MAC) Informations
        $aResult[$Result['id']]['ports'] = getObjectPortsAndLinks($Result['id']);
        $iTotal++;
    }
    if (isset($_GET['csv'])) {
        header('Content-type: text/csv');
        header('Content-Disposition: attachment; filename=export_' . date("Ymdhis") . '.csv');
        header('Pragma: no-cache');
        header('Expires: 0');
        $outstream = fopen("php://output", "w");
        $aCSVRow = array('Name', 'MAC', 'IP(s)', 'Comment', 'Contact', 'Type', 'OEM', 'HW Expire Date', 'OS', 'Location');
        fputcsv($outstream, $aCSVRow);
        foreach ($aResult as $id => $aRow) {
            $aCSVRow = array();
            $aCSVRow[0] = $aRow['sName'];
            $aCSVRow[1] = '';
            foreach ($aRow['ports'] as $portNumber => $aPortDetails) {
                if (trim($aPortDetails['l2address']) != '') {
                    $aCSVRow[1] .= $aPortDetails['l2address'] . ' ';
                }
            }
            $aCSVRow[1] = trim($aCSVRow[1]);
            $aCSVRow[2] = '';
            foreach ($aRow['ipV4List'] as $key => $aDetails) {
                if (function_exists('ip4_format')) {
                    $key = ip4_format($key);
                }
                if (trim($key) != '') {
                    $aCSVRow[2] .= $key . ' ';
                }
            }
            foreach ($aRow['ipV6List'] as $key => $aDetails) {
                if (function_exists('ip6_format')) {
                    $key = ip6_format($key);
                }
                if (trim($key) != '') {
                    $aCSVRow[2] .= $key . ' ';
                }
            }
            $aCSVRow[2] = trim($aCSVRow[2]);
            $aCSVRow[3] = str_replace('&quot;', "'", $aRow['sComment']);
            $aCSVRow[4] = $aRow['sContact'];
            $aCSVRow[5] = $aRow['HWtype'];
            $aCSVRow[6] = $aRow['OEMSN'];
            $aCSVRow[7] = $aRow['HWExpDate'];
            $aCSVRow[8] = $aRow['sOS'];
            $aCSVRow[9] = preg_replace('/<a[^>]*>(.*)<\\/a>/iU', '$1', $aRow['sLocation']);
            fputcsv($outstream, $aCSVRow);
        }
        fclose($outstream);
        exit(0);
        # Exit normally after send CSV to browser
    }
    // Load stylesheet and jquery scripts
    echo '<link rel="stylesheet" href="extensions/jquery/themes/racktables/style.css" type="text/css"/>';
    echo '<script type="text/javascript" src="extensions/jquery/jquery-latest.js"></script>';
    echo '<script type="text/javascript" src="extensions/jquery/jquery.tablesorter.js"></script>';
    echo '<script type="text/javascript" src="extensions/jquery/picnet.table.filter.min.js"></script>';
    // Display the stat array
    echo '<h2>Server report (' . $iTotal . ')</h2><ul>';
    echo '<a href="index.php?page=reports&tab=server&csv">CSV Export</a>';
    echo '<table id="reportTable" class="tablesorter">
          <thead>
            <tr>
              <th>Name</th>
              <th>MAC</th>
              <th>IP(s)</th>
              <th>Comment</th>
              <th>Contact</th>
              <th>Type</th>
              <th>OEM S/N</th>
              <th>HW Expire Date</th>
              <th>OS</th>
              <th>Location</th>
            </tr>
          </thead>
        <tbody>';
    foreach ($aResult as $id => $aRow) {
        echo '<tr>
              <td><a href="' . makeHref(array('page' => 'object', 'object_id' => $id)) . '">' . $aRow['sName'] . '</a></td>
              <td>';
        foreach ($aRow['ports'] as $portNumber => $aPortDetails) {
            if (trim($aPortDetails['l2address']) != '') {
                echo $aPortDetails['l2address'] . '<br/>';
            }
        }
        echo '  </td>
              <td>';
        foreach ($aRow['ipV4List'] as $key => $aDetails) {
            if (function_exists('ip4_format')) {
                $key = ip4_format($key);
            }
            if (trim($key) != '') {
                echo $key . '<br/>';
            }
        }
        foreach ($aRow['ipV6List'] as $key => $aDetails) {
            if (function_exists('ip6_format')) {
                $key = ip6_format($key);
            }
            if (trim($key) != '') {
                echo $key . '<br/>';
            }
        }
        echo '</td>
            <td>' . makeLinksInText($aRow['sComment']) . '</td>
            <td>' . $aRow['sContact'] . '</td>
            <td>' . $aRow['HWtype'] . '</td>
            <td>' . $aRow['OEMSN'] . '</td>
            <td>' . $aRow['HWExpDate'] . '</td>
            <td>' . $aRow['sOS'] . '</td>
            <td>' . $aRow['sLocation'] . '</td>
          </tr>';
    }
    echo '  </tbody>
        </table>';
    echo '<script type="text/javascript">
          $(document).ready(function()
          {
            $.tablesorter.defaults.widgets = ["zebra"];
            $("#reportTable").tablesorter(
              { headers: {
                2: { sorter: "ipAddress" },
              }, sortList: [[0,0]] }
            )
            $("#reportTable").tableFilter();
          });
       </script>';
}