function initZabbixHost($hostgroupDatas)
{
    $allObjects = scanRealmByText('object');
    foreach ($allObjects as $object) {
        // get group data
        $groups = array();
        $parentRacks = getResidentRacksData($object['id']);
        foreach ($parentRacks as $key => $rack) {
            array_push($groups, array('groupid' => $hostgroupDatas[$rack['name']]));
        }
        // set interfaces
        $interfaces = array();
        $allocs = getObjectIPAllocations($object['id']);
        $current_ips = array();
        foreach ($allocs as $alloc) {
            $interface = array('type' => 1, "main" => 0, "useip" => 1, "ip" => $alloc["addrinfo"]["ip"], "dns" => "", "port" => "10050");
            array_push($interfaces, $interface);
        }
        if (count($interfaces) < 1) {
            $interface = array('type' => 1, "main" => 1, "useip" => 1, "ip" => "127.0.0.1", "dns" => "", "port" => "10050");
            array_push($interfaces, $interface);
        } else {
            $interfaces[0]['main'] = 1;
        }
        // insert host
        $params = array('host' => $object['name'], 'groups' => $groups, 'interfaces' => $interfaces);
        $result = doPost('host.create', $params);
        // set result
        $id = isset($result['result']) ? $result['result']['hostids'][0] : -1;
        if ($id < 0) {
            http_response_code(500);
            exit;
        }
    }
}
function initRackTablesRack($remain_hostgroups)
{
    // get the data of zabbix hostgroup
    $params = array('output' => 'extend', 'sortfield' => array('name'));
    $result = doPost('hostgroup.get', $params);
    $hostgroups = isset($result['result']) ? $result['result'] : array();
    global $row_id;
    global $rack_height;
    $rowInfo = getRowInfo($row_id);
    $sort_order = $rowInfo['count'];
    foreach ($hostgroups as $hostgroup) {
        if (in_array($hostgroup['name'], $remain_hostgroups)) {
            continue;
        }
        $taglist = genericAssertion('taglist', 'array0');
        $sort_order += 1;
        $rack_id = commitAddObject($hostgroup['name'], NULL, 1560, "", $taglist);
        // set height
        $params = array('output' => array('hostids'), 'groupids' => array($hostgroup['groupid']));
        $result = doPost('host.get', $params);
        $height = isset($result['result']) ? count($result['result']) : 0;
        if ($height < $rack_height) {
            $height = $rack_height;
        }
        commitUpdateAttrValue($rack_id, 27, $height);
        commitUpdateAttrValue($rack_id, 29, $sort_order);
        // Link it to the row
        commitLinkEntities('row', $row_id, 'rack', $rack_id);
    }
    $rackDatas = array();
    $allRacks = scanRealmByText('rack');
    foreach ($allRacks as $rack_id => $rack) {
        $rackDatas[$rack['name']] = $allRacks[$rack_id];
    }
    return $rackDatas;
}
function renderSwitchReport()
{
    $aResult = array();
    $iTotal = 0;
    $sFilter = '{$typeid_8}';
    # typeid_8 = Switches
    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']]['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']]['sOSVersion'] = '';
        if (isset($attributes['5']['a_value'])) {
            $aResult[$Result['id']]['sOSVersion'] = $attributes['5']['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);
        $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', 'Comment', 'Contact', 'Type', 'OEM', 'HW Expire Date', 'OS Version', 'Location');
        fputcsv($outstream, $aCSVRow);
        foreach ($aResult as $id => $aRow) {
            $aCSVRow = array();
            $aCSVRow[0] = $aRow['sName'];
            $aCSVRow[1] = str_replace('&quot;', "'", $aRow['sComment']);
            $aCSVRow[2] = $aRow['sContact'];
            $aCSVRow[3] = $aRow['HWtype'];
            $aCSVRow[4] = $aRow['OEMSN'];
            $aCSVRow[5] = $aRow['HWExpDate'];
            $aCSVRow[6] = $aRow['sOSVersion'];
            $aCSVRow[7] = 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
    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>Switch report ({$iTotal})</h2><ul>";
    echo '<a href="index.php?page=reports&tab=switches&csv">CSV Export</a>';
    echo '<table id="reportTable" class="tablesorter">
            <thead>
              <tr>
                <th>Name</th>
                <th>Comment</th>
                <th>Contact</th>
                <th>Type</th>
                <th>OEM S/N</th>
                <th>HW Expire Date</th>
                <th>OS Version</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>' . $aRow['sComment'] . '</td>
                <td>' . $aRow['sContact'] . '</td>
                <td>' . $aRow['HWtype'] . '</td>
                <td>' . $aRow['OEMSN'] . '</td>
                <td>' . $aRow['HWExpDate'] . '</td>
                <td>' . $aRow['sOSVersion'] . '</td>
                <td>' . $aRow['sLocation'] . '</td>
              </tr>';
    }
    echo '  </tbody>
          </table>';
    echo '<script type="text/javascript">
            $(document).ready(function()
              {
                $.tablesorter.defaults.widgets = ["zebra"];
                $("#reportTable").tablesorter(
                    { headers: {
                    }, sortList: [[0,0]] }
                );
                $("#reportTable").tableFilter();
              }
            );
          </script>';
}
function renderLBList()
{
    $cells = array();
    foreach (scanRealmByText('object', getConfigVar('IPV4LB_LISTSRC')) as $object) {
        $cells[$object['id']] = $object;
    }
    renderCellList('object', 'items', FALSE, $cells);
}
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>';
}
/**
 * getResult Function
 *
 * Call Racktables API to get Objects and filter the result if required
 *
 * @param array $post
 * @return array Result
 */
function getResult($post)
{
    $sFilter = '';
    if (isset($post['objectIDs'])) {
        foreach ($post['objectIDs'] as $sFilterValue) {
            $sFilter .= '{$typeid_' . $sFilterValue . '} or ';
        }
        $sFilter = substr($sFilter, 0, -4);
        $sFilter = '(' . $sFilter . ')';
    }
    $aResult = scanRealmByText('object', $sFilter);
    // Add tags
    $aTemp = array();
    foreach ($aResult as $Result) {
        $Result['tags'] = loadEntityTags('object', $Result['id']);
        $Result['itags'] = getImplicitTags($Result['tags']);
        array_push($aTemp, $Result);
    }
    $aResult = $aTemp;
    // Search / Filter by name
    if (isset($post['name_preg']) && $post['name_preg'] != '') {
        $aTemp = array();
        foreach ($aResult as $Result) {
            if (preg_match('/' . $post['name_preg'] . '/', $Result['name'])) {
                array_push($aTemp, $Result);
            }
        }
        $aResult = $aTemp;
    }
    // Search / Filter by tag
    if (isset($post['tag_preg']) && $post['tag_preg'] != '') {
        $aTemp = array();
        foreach ($aResult as $Result) {
            if (preg_match('/' . $post['tag_preg'] . '/', $Result['asset_no'])) {
                array_push($aTemp, $Result);
            }
        }
        $aResult = $aTemp;
    }
    // Search / Filter by comment
    if (isset($post['comment_preg']) && $post['comment_preg'] != '') {
        $aTemp = array();
        foreach ($aResult as $Result) {
            if (preg_match('/' . $post['comment_preg'] . '/', $Result['comment'])) {
                array_push($aTemp, $Result);
            }
        }
        $aResult = $aTemp;
    }
    // Tags
    if (isset($post['tag']) && count($post['tag']) > 0) {
        $aTemp = array();
        $aSearchTags = array_keys($post['tag']);
        foreach ($aResult as $Result) {
            foreach ($Result['tags'] as $aTag) {
                if (in_array($aTag['id'], $aSearchTags)) {
                    array_push($aTemp, $Result);
                }
            }
            foreach ($Result['itags'] as $aTag) {
                if (in_array($aTag['id'], $aSearchTags)) {
                    array_push($aTemp, $Result);
                }
            }
        }
        $aResult = $aTemp;
    }
    // Ports - Load port data if necessary
    if (isset($post['Ports'])) {
        $aTemp = array();
        foreach ($aResult as $Result) {
            $Result['portsLinks'] = getObjectPortsAndLinks($Result['id']);
            foreach ($Result['portsLinks'] as $i => $port) {
                $Result['portsLinks'][$i]['remote_object_name'] = 'unknown';
                if (!is_null($port['remote_object_id'])) {
                    $remote_object = spotEntity('object', intval($port['remote_object_id']));
                    $Result['portsLinks'][$i]['remote_object_name'] = $remote_object['name'];
                }
            }
            array_push($aTemp, $Result);
        }
        $aResult = $aTemp;
    }
    return $aResult;
}
function renderItem()
{
    // Main layout starts.
    echo '<table border=0 class=objectview cellspacing=0 cellpadding=0><tr>';
    // Left portlet with rack list.
    echo '<td class=pcleft height="1%" width="25%">';
    startPortlet('Objects');
    printOpFormIntro('viewitems');
    // object select area
    $disabled = '';
    if (false) {
        $disabled = 'disabled';
    }
    echo "<select name=objectid style=width:50%; {$disabled} size=" . getConfigVar('MAXSELSIZE') . " onchange=getElementsByName(\"viewitems\")[0].submit()>\n";
    $allObjects = scanRealmByText('object');
    $objectlist = array();
    $selected = isset($_REQUEST['objectid']) ? $_REQUEST['objectid'] : -1;
    if ($selected < 0) {
        echo "<option value=-1 selected>All</option>\n";
    } else {
        echo "<option value=-1>All</option>\n";
    }
    foreach ($allObjects as $object) {
        //echo '<option value=' . $object['id'];
        echo '<option value=' . $object['id'];
        if ($object['id'] == $selected) {
            echo ' selected';
        }
        echo '>' . $object['name'] . "</option>\n";
    }
    echo "</select>\n";
    //$object = spotEntity('object', $selected);
    echo '</form>';
    echo '<br><br>';
    finishPortlet();
    echo '</td>';
    echo '<td class=pcright>';
    $query = "select * from item_information";
    if ($selected >= 0) {
        $query .= " where objectid = '{$selected}'";
    }
    $query .= ' order by hostid, name';
    $result = usePreparedSelectBlade($query);
    $items = $result->fetchAll();
    unset($result);
    $count = count($items);
    startPortlet("Items({$count})");
    if ($count <= 0) {
        echo '<h4>No Item is in the Object.<h4>';
    } else {
        echo '<table style=width:80%; border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
        echo '<tr><th>Name</th>';
        echo '<th>Type</th>';
        echo '<th>Key</th>';
        echo '<th>Interface</th>';
        echo '<th>Type of information</th>';
        echo '<th>Data type</th>';
        echo '<th>Units</th>';
        echo '<th>Use custom multiplier</th>';
        echo "<th>Update interval (in sec)</th></tr>\n";
        foreach ($items as $item) {
            // Name
            echo "<tr class='row_{$order} tdleft {$problem}' valign=top><td><a href=index.php?page=item&tab=properties&item_id={$item['itemid']}><strong>{$item['name']}</strong></a></td>\n";
            // Type
            global $itemtypelist;
            echo "<td>{$itemtypelist[$item['type']]}</td>";
            // Key
            echo "<td>{$item['key_']}</td>";
            // Interface
            $interfaceStr = '-';
            if (isset($item['interfaceid'])) {
                $interface = searchInterfaceById($item['interfaceid'])[0];
                if (isset($interface['ip'])) {
                    $interfaceStr = "{$interface['ip']}:{$interface['port']}";
                }
            }
            echo "<td>{$interfaceStr}</td>";
            // Type of information
            global $itemvalue_types;
            echo "<td>{$itemvalue_types[$item['value_type']]}</td>";
            // Data type
            global $itemdata_types;
            echo "<td>{$itemdata_types[$item['data_type']]}</td>";
            // Uints
            echo "<td>{$item['units']}</td>";
            // Use custom multiplier
            if ($item['multiplier'] == 1) {
                echo "<td>{$item['formula']}</td>";
            } else {
                echo "<td>-</td>";
            }
            // Update interval (in sec)
            echo "<td>{$item['delay']}</td></tr>";
        }
        echo "</table>\n";
    }
    echo '<br><br>';
    finishPortlet();
    echo '</td>';
    // end tag
    echo "</tr></table>\n";
}
Esempio n. 8
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>';
}
require_once 'inc/pre-init.php';
try {
    // Switch block below is a module request dispatcher.
    // Dispatches based on module request.
    // The last string 'interface' is the default.
    $requestedModule = array_key_exists('module', $_REQUEST) ? $_REQUEST['module'] : 'interface';
    switch ($requestedModule) {
        case 'interface':
            require_once 'inc/interface.php';
            // init.php has to be included after interface.php, otherwise the bits
            // set by local.php get lost
            require_once 'inc/init.php';
            ######################################################################
            global $rowindex;
            $tab['top'] = null;
            $allrows = scanRealmByText('row');
            foreach ($allrows as $row) {
                if (!isset($tab['top']['default'])) {
                    $tab['top']['default'] = $row['name'];
                    $tabhandler['top']['default'] = 'renderTop';
                    $rowindex['default'] = $row['id'];
                } else {
                    $tab['top'][$row['name']] = $row['name'];
                    $tabhandler['top'][$row['name']] = 'renderTop';
                    $rowindex[$row['name']] = $row['id'];
                }
            }
            /*
            // location
            $locations = scanRealmByText('location');
            foreach($locations as $location) {