示例#1
0
function allJS()
{
    $toret = "";
    $conf = new Config();
    if ($dh = opendir($conf->jsfolder)) {
        while (($file = readdir($dh)) !== false) {
            if (is_file($conf->jsfolder . '/' . $file) && $file != '.' && $file != '..') {
                $toret .= addJS($file);
            }
        }
        closedir($dh);
    }
    echo $toret;
}
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('"', "'", $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 getPopupSLBConfig($row)
{
    $do_vs = isset($row) && isset($row['vsconfig']) && strlen($row['vsconfig']);
    $do_rs = isset($row) && isset($row['rsconfig']) && strlen($row['rsconfig']);
    if (!$do_vs && !$do_rs) {
        return;
    }
    $ret = '';
    $ret .= '<div class="slbconf-btn">…</div>';
    $ret .= '<div class="slbconf popup-box">';
    if ($do_vs) {
        $ret .= '<h1>VS config:</h1>';
        $ret .= $row['vsconfig'];
    }
    if ($do_rs) {
        $ret .= '<h1>RS config:</h1>';
        $ret .= $row['rsconfig'];
    }
    $ret .= '</div>';
    static $js_added = FALSE;
    if (!$js_added) {
        addJS('js/jquery.thumbhover.js');
        addJS(<<<END
\$(document).ready (function () {
\t\$('.slbconf-btn').each (function () {
\t\t\$(this).thumbPopup(\$(this).siblings('.slbconf.popup-box'), { showFreezeHint: false });
\t});
});
END
, TRUE);
    }
    return $ret;
}
示例#4
0
/**
 *
 * 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();
}
示例#5
0
function handlePopupPortLink()
{
    assertPermission('depot', 'default');
    assertUIntArg('port');
    assertUIntArg('remote_port');
    assertStringArg('cable', TRUE);
    $port_info = getPortInfo($_REQUEST['port']);
    $remote_port_info = getPortInfo($_REQUEST['remote_port']);
    $POIFC = getPortOIFCompat();
    if (isset($_REQUEST['port_type']) and isset($_REQUEST['remote_port_type'])) {
        $type_local = $_REQUEST['port_type'];
        $type_remote = $_REQUEST['remote_port_type'];
    } else {
        $type_local = $port_info['oif_id'];
        $type_remote = $remote_port_info['oif_id'];
    }
    $matches = FALSE;
    $js_table = '';
    foreach ($POIFC as $pair) {
        if ($pair['type1'] == $type_local && $pair['type2'] == $type_remote) {
            $matches = TRUE;
            break;
        } else {
            $js_table .= "POIFC['{$pair['type1']}-{$pair['type2']}'] = 1;\n";
        }
    }
    if ($matches) {
        if ($port_info['oif_id'] != $type_local) {
            commitUpdatePortOIF($port_info['id'], $type_local);
        }
        if ($remote_port_info['oif_id'] != $type_remote) {
            commitUpdatePortOIF($remote_port_info['id'], $type_remote);
        }
        linkPorts($port_info['id'], $remote_port_info['id'], $_REQUEST['cable']);
        // patch cable?
        if (array_key_exists('heap_id', $_REQUEST)) {
            // Leave the compatibility constraints check up to the foreign keys.
            if (0 != ($heap_id = genericAssertion('heap_id', 'uint0'))) {
                $heaps = getPatchCableHeapSummary();
                if (commitModifyPatchCableAmount($heap_id, -1)) {
                    showSuccess('consumed a patch cable from ' . formatPatchCableHeapAsPlainText($heaps[$heap_id]));
                } else {
                    showError('failed to consume a patch cable');
                }
            }
        }
        showOneLiner(8, array(formatPortLink($port_info['object_id'], NULL, $port_info['id'], $port_info['name']), formatPort($remote_port_info)));
        addJS(<<<END
window.opener.location.reload(true);
window.close();
END
, TRUE);
        backupLogMessages();
    } else {
        // JS code to display port compatibility hint
        addJS(<<<END
POIFC = {};
{$js_table}
\$(document).ready(function () {
\t\$('select.porttype').change(onPortTypeChange);\t
\tonPortTypeChange();
});
function onPortTypeChange() {
\tvar key = \$('*[name=port_type]')[0].value + '-' + \$('*[name=remote_port_type]')[0].value;
\tif (POIFC[key] == 1)
\t{
\t\t\$('#hint-not-compat').hide();
\t\t\$('#hint-compat').show();
\t}
\telse
\t{
\t\t\$('#hint-compat').hide();
\t\t\$('#hint-not-compat').show();
\t}
}
END
, TRUE);
        addCSS(<<<END
.compat-hint {
\tdisplay: none;
\tfont-size: 125%;
}
.compat-hint#hint-compat {
\tcolor: green;
}
.compat-hint#hint-not-compat {
\tcolor: #804040;
}
END
, TRUE);
        // render port type editor form
        echo '<form method=GET>';
        echo '<input type=hidden name="module" value="popup">';
        echo '<input type=hidden name="helper" value="portlist">';
        echo '<input type=hidden name="port" value="' . $port_info['id'] . '">';
        echo '<input type=hidden name="remote_port" value="' . $remote_port_info['id'] . '">';
        echo '<input type=hidden name="cable" value="' . htmlspecialchars($_REQUEST['cable'], ENT_QUOTES) . '">';
        echo '<p>The ports you have selected are not compatible. Please select a compatible transceiver pair.';
        echo '<p>';
        echo formatPort($port_info) . ' ';
        if ($port_info['iif_id'] == 1) {
            echo formatPortIIFOIF($port_info);
            echo '<input type=hidden name="port_type" value="' . $port_info['oif_id'] . '">';
        } else {
            echo '<label>' . $port_info['iif_name'] . ' ';
            printSelect(getExistingPortTypeOptions($port_info), array('class' => 'porttype', 'name' => 'port_type'), $type_local);
            echo '</label>';
        }
        echo ' &mdash; ';
        if ($remote_port_info['iif_id'] == 1) {
            echo formatPortIIFOIF($remote_port_info);
            echo '<input type=hidden name="remote_port_type" value="' . $remote_port_info['oif_id'] . '">';
        } else {
            echo '<label>' . $remote_port_info['iif_name'] . ' ';
            printSelect(getExistingPortTypeOptions($remote_port_info), array('class' => 'porttype', 'name' => 'remote_port_type'), $type_remote);
            echo '</label>';
        }
        echo ' ' . formatPort($remote_port_info);
        echo '<p class="compat-hint" id="hint-not-compat">&#10005; Not compatible port types</p>';
        echo '<p class="compat-hint" id="hint-compat">&#10004; Compatible port types</p>';
        echo '<p><input type=submit name="do_link" value="Link">';
    }
}
示例#6
0
文件: interface.php 项目: xtha/salt
function switchportInfoJS($object_id)
{
    $available_ops = array('link' => array('op' => 'get_link_status', 'gw' => 'getportstatus'), 'conf' => array('op' => 'get_port_conf', 'gw' => 'get8021q'), 'mac' => array('op' => 'get_mac_list', 'gw' => 'getmaclist'), 'portmac' => array('op' => 'get_port_mac_list', 'gw' => 'getportmaclist'));
    $breed = detectDeviceBreed($object_id);
    $allowed_ops = array();
    foreach ($available_ops as $prefix => $data) {
        if (permitted('object', 'liveports', $data['op']) and validBreedFunction($breed, $data['gw'])) {
            $allowed_ops[] = $prefix;
        }
    }
    // make JS array with allowed items
    $list = '';
    foreach ($allowed_ops as $item) {
        $list .= "'" . addslashes($item) . "', ";
    }
    $list = trim($list, ", ");
    addJS('js/jquery.thumbhover.js');
    addCSS('css/jquery.contextmenu.css');
    addJS('js/jquery.contextmenu.js');
    addJS("enabled_elements = [ {$list} ];", TRUE);
    addJS('js/portinfo.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>';
}
function snmplive_tabhandler($object_id)
{
    addCSS(<<<ENDCSS
        .ifoperstatus-default { background-color:#ddd; }
        .ifoperstatus-1, .ifoperstatus-up { background-color:#00ff00; }
        .ifoperstatus-2, .ifoperstatus-down { background-color:#ff0000; }
        .ifoperstatus-3, .ifoperstatus-testing { background-color:#ffff66; }
        .ifoperstatus-4, .ifoperstatus-unknown { background-color:#ffffff; }
        .ifoperstatus-5, .ifoperstatus-dormant { background-color:#90bcf5; }
        .ifoperstatus-6, .ifoperstatus-notPresent { }
        .ifoperstatus-7, .ifoperstatus-lowerLayerDown { }

        .port-groups { border-spacing:1px;display:table; }
        .port-group { display:table-cell;border:3px solid #000;background-color:#c0c0c0; }

        .port-column { display:table-cell;position:relative; }

        .port { position:relative;width:42px;height:100px;border:2px solid #000;overflow:hidden; }
        .port-pos-1 { margin-bottom:1px; }
        .port-pos-2 { }
        .port-pos-0 { margin-top:1px; }

        .port-header { position:absolute }
        .port-header-pos-1 { top:0px; }
        .port-header-pos-0 { bottom:0px; }

        .port-status { position:absolute;min-width:42px;text-align:center;font-size:10pt; }

        .port-status-pos-1 { top:35px; }
        .port-status-pos-0 { bottom:35px; }

        .port-info { position:absolute;width:90%;background-color:#ddd;overflow:hidden; }
        .port-info-pos-1 { top: 80px; }
        .port-info-pos-0 { bottom: 80px;}

        .port-name {  font-size:10pt;margin:0px auto;width:40px;text-align:center; }
        .port-number { font-size:8pt;color:#eee; }

        .port-detail { position:fixed;z-index:1000;top:0px;right:0px;border:3px solid #000;background-color:#fff }
        .port-detail-links { background-color:#ccc }
        .hidden { visibility:hidden; }
        .info-footer { }

ENDCSS
, TRUE);
    echo "<div id=\"info\"></div>";
    if (isset($_GET['debug'])) {
        $debug = $_GET['debug'];
    } else {
        $debug = 0;
    }
    $object = spotEntity('object', $object_id);
    amplifyCell($object);
    if (isset($_GET['modules'])) {
        $modules = $_GET['modules'];
    } else {
        $modules = false;
    }
    if ($modules) {
        unset($_GET['modules']);
    } else {
        $_GET['modules'] = 1;
    }
    echo "<a href=" . makeHref($_GET) . ">" . ($modules ? "Hide" : "Show") . " Modules</a>";
    pl_layout_default($object, 0, false, $modules);
    addJS(<<<ENDJS
       function togglevisibility(elem, hide)
        {
                if(hide)
                        elem.css('visibility', 'hidden');
                else
                        elem.css('visibility', 'visible');
                //a.show();
                //a.hide();
        }

       function setdetail(elem, hide)
        {
                var a = \$( "#port" + elem.id + "-detail");

                togglevisibility(a, hide);
        }

         function setports( data, textStatus, jqHXR ) {
                if(data.debug)
                        \$( "#info" ).html(\$( "#info" ).html() + "DEBUG: " + data.name + ": " + data.debug);

                for(var index in data.ports)
                {
                        setport(data, data.ports[index]);
                }
         }

        function setportstatus( obj, port , id , detail)
        {

                tagidsuffix = "";

                if(detail)
                        tagidsuffix = tagidsuffix + "-detail";

                if(!detail)
                {
                        \$( "#port" + id + "-status" + tagidsuffix ).html("<table class=\\"ifoperstatus-" + port.snmpinfos.
operstatus + "\\"><tr><td>"
                                        +  port.snmpinfos.operstatus + "<br>" + port.snmpinfos.speed
\t\t\t\t\t+  ( port.snmpinfos.vlan ? "<br>" + port.snmpinfos.vlan : "" )
                                        + "</td></tr></table>");
                        return;
                }

                \$( "#port" + id + "-status" + tagidsuffix ).html(port.snmpinfos.alias
                                        + "<table class=\\"ifoperstatus-" + port.snmpinfos.operstatus + "\\"><tr><td>"
                                        + (port.snmpinfos.ipv4 ? port.snmpinfos.ipv4 : "")
\t\t\t\t\t+ "<br>" + port.snmpinfos.operstatus
\t\t\t\t\t+ ( port.snmpinfos.vlan ? "<br>" + port.snmpinfos.vlan_name + " (" + port.snmpinfos.vlan + ")" : "" )
                                        + "</td></tr></table>");
        }

        function setport( obj, port ) {

                if(port.debug)
                        \$( "#info" ).html(\$( "#info" ).html() + port.name + " " + port.debug);

                if(port.snmpinfos)
                {
                        setportstatus(obj, port, port.id, false);
                        setportstatus(obj, port, port.id, true);
                }

        }

        function ajaxerror(jqHXR, textStatus, qXHR, errorThrown)
        {
                \$( "#info" ).html(\$( "#info" ).html() + "<br>" + textStatus + " " + qXHR + " " + errorThrown);
        }

\t\$.ajax({
\t\tdataType: "json",
\t\turl: "index.php",
\t\tdata: {
\t\t\tpage: "object",
\t\t\ttab: "snmplive",
\t\t\tmodule: "redirect",
\t\t\top: "ajax",
\t\t\tjson: "get",
\t\t\tobject_id: "{$object_id}",
\t\t\tdebug: {$debug}
\t\t},
\t\terror: ajaxerror,
\t\tsuccess: setports
\t});

ENDJS
, TRUE);
}
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>';
    }
}
示例#10
0
?>
/assets/custom/img/me.jpg" alt="...">
                              <div class="caption">
                                <h3>Thumbnail label</h3>
                                <p>Lorem ipsum In in ullamco Duis.</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
</div>
</body>
<?php 
addJS("assets/admin/plugins/jQuery/jQuery-2.1.3.min.js");
addJS("assets/admin/plugins/slimScroll/jquery.slimscroll.min.js");
addJS("assets/admin/plugins/niceScroll/jquery.nicescroll.min.js");
addJS("assets/admin/js/bootstrap.min.js");
addJS("assets/global/plugins/onepage-scroll/jquery.onepage-scroll.js");
addJS("assets/global/plugins/slick/slick.js");
addJS("assets/global/plugins/lazy-line-painter-master/jquery.lazylinepainter-1.7.0.min.js");
addJS("assets/custom/js/custom.js");
?>

<?php 
getJS();
?>
</html>
示例#11
0
function includeJQueryUI($do_css = TRUE)
{
    addJS('js/jquery-ui-1.8.21.min.js');
    if ($do_css) {
        addCSS('css/jquery-ui-1.8.22.redmond.css');
    }
}
示例#12
0
function linkmgmt_tabhandler($object_id)
{
    global $lm_cache;
    $target = makeHrefProcess(portlist::urlparams('op', 'update'));
    addJS('js/jquery.jeditable.mini.js');
    /* TODO  if (permitted (NULL, 'ports', 'set_reserve_comment')) */
    /* TODO Link / unlink permissions  */
    $lm_cache['allowcomment'] = permitted(NULL, NULL, 'set_reserve_comment');
    /* RackCode {$op_set_reserve_comment} */
    $lm_cache['allowlink'] = permitted(NULL, NULL, 'set_link');
    /* RackCode {$op_set_link} */
    $lm_cache['allowbacklink'] = permitted(NULL, NULL, 'set_backlink');
    /* RackCode {$op_set_backlink} */
    //portlist::var_dump_html($lm_cache);
    /* init jeditable fields/tags */
    if ($lm_cache['allowcomment']) {
        addJS('$(document).ready(function() { $(".editcmt").editable("' . $target . '",{placeholder : "add comment"}); });', TRUE);
    }
    if ($lm_cache['allowlink']) {
        addJS('$(document).ready(function() { $(".editcable").editable("' . $target . '",{placeholder : "edit cableID"}); });', TRUE);
    }
    /* linkmgmt for current object */
    linkmgmt_renderObjectLinks($object_id);
    /* linkmgmt for every child */
    //$parents = getEntityRelatives ('parents', 'object', $object_id);
    $children = getEntityRelatives('children', 'object', $object_id);
    //'entity_id'
    foreach ($children as $child) {
        $childobj = spotEntity($child['entity_type'], $child['entity_id']);
        echo '<h1>Links for Child: ' . $childobj['name'] . '</h1>';
        linkmgmt_renderObjectLinks($child['entity_id']);
        unset($childobj);
    }
    return;
}
function renderCopyEntityTags($entity_id)
{
    global $tagtree, $taglist, $target_given_tags, $pageno, $etype_by_pageno;
    echo '<table border=0 width="10%"><tr>';
    if (count($taglist) > getConfigVar('TAGS_QUICKLIST_THRESHOLD')) {
        $minilist = getTagChart(getConfigVar('TAGS_QUICKLIST_SIZE'), $etype_by_pageno[$pageno], $target_given_tags);
        // It could happen, that none of existing tags have been used in the current realm.
        if (count($minilist)) {
            $js_code = "tag_cb.setTagShortList ({";
            $is_first = TRUE;
            foreach ($minilist as $tag) {
                if (!$is_first) {
                    $js_code .= ",";
                }
                $is_first = FALSE;
                $js_code .= "\n\t{$tag['id']} : 1";
            }
            $js_code .= "\n});\n\$(document).ready(tag_cb.compactTreeMode);";
            addJS('js/tag-cb.js');
            addJS($js_code, TRUE);
        }
    }
    // do not do anything about empty tree, trigger function ought to work this out
    echo '<td class=pcright>';
    renderCopyEntityTagsPortlet('', $tagtree, $target_given_tags, $etype_by_pageno[$pageno]);
    echo '</td>';
    echo '</tr></table>';
}
function renderTagTreeEditor()
{
    addJS(<<<END
function tageditor_showselectbox(e) {
\t\$(this).load('index.php', {module: 'ajax', ac: 'get-tag-select', tagid: this.id});
\t\$(this).unbind('mousedown', tageditor_showselectbox);
}
\$(document).ready(function () {
\t\$('select.taglist-popup').bind('mousedown', tageditor_showselectbox);
});
END
, TRUE);
    function printNewItemTR($options)
    {
        global $taglist;
        printOpFormIntro('createTag');
        echo '<tr>';
        echo '<td align=left style="padding-left: 16px;">' . getImageHREF('create', 'Create tag', TRUE) . '</td>';
        echo '<td><input type=text size=48 name=tag_name></td>';
        echo '<td class=tdleft>' . getSelect(array('yes' => 'yes', 'no' => 'no'), array('name' => 'is_assignable'), 'yes') . '</td>';
        echo '<td>' . getSelect($options, array('name' => 'parent_id')) . '</td>';
        echo '<td>' . getImageHREF('create', 'Create tag', TRUE, 120) . '</td>';
        echo '</tr></form>';
    }
    global $taglist;
    $options = array(0 => '-- NONE --');
    foreach ($taglist as $taginfo) {
        $options[$taginfo['id']] = htmlspecialchars($taginfo['tag']);
    }
    $otags = getOrphanedTags();
    if (count($otags)) {
        startPortlet('fallen leaves');
        echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
        echo '<tr class=trerror><th>tag name</th><th>parent tag</th><th>&nbsp;</th></tr>';
        foreach ($otags as $taginfo) {
            printOpFormIntro('updateTag', array('tag_id' => $taginfo['id'], 'tag_name' => $taginfo['tag']));
            echo "<input type=hidden name=is_assignable value={$taginfo['is_assignable']}>";
            echo '<tr>';
            echo '<td>' . $taginfo['tag'] . '</td>';
            echo '<td>' . getSelect($options, array('name' => 'parent_id'), $taglist[$taginfo['id']]['parent_id']) . '</td>';
            echo '<td>' . getImageHREF('save', 'Save changes', TRUE) . '</td>';
            echo '</tr></form>';
        }
        echo '</table>';
        finishPortlet();
    }
    startPortlet('tag tree');
    echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
    echo '<tr><th>&nbsp;</th><th>tag name</th><th>assignable</th><th>parent tag</th><th>&nbsp;</th></tr>';
    if (getConfigVar('ADDNEW_AT_TOP') == 'yes') {
        printNewItemTR($options);
    }
    foreach (getTagTree() as $taginfo) {
        renderTagRowForEditor($taginfo);
    }
    if (getConfigVar('ADDNEW_AT_TOP') != 'yes') {
        printNewItemTR($options);
    }
    echo '</table>';
    finishPortlet();
}
function snmpgeneric_list($object_id)
{
    global $sg_create_noconnector_ports, $sg_known_sysObjectIDs, $sg_portoifoptions, $sg_ifType_ignore;
    if (isset($_POST['snmpconfig'])) {
        $snmpconfig = $_POST;
    } else {
        showError("Missing SNMP Config");
        return;
    }
    //	sg_var_dump_html($snmpconfig);
    echo '<body onload="document.getElementById(\'createbutton\').focus();">';
    addJS('function setchecked(classname) { var boxes = document.getElementsByClassName(classname);
				 var value = document.getElementById(classname).checked;
				 for(i=0;i<boxes.length;i++) {
					if(boxes[i].disabled == false)
						boxes[i].checked=value;
				 }
		};', TRUE);
    $object = spotEntity('object', $object_id);
    $object['attr'] = getAttrValues($object_id);
    $snmpdev = new mySNMP($snmpconfig['version'], $snmpconfig['host'], $snmpconfig['community']);
    if ($snmpconfig['version'] == "v3") {
        $snmpdev->setSecurity($snmpconfig['sec_level'], $snmpconfig['auth_protocol'], $snmpconfig['auth_passphrase'], $snmpconfig['priv_protocol'], $snmpconfig['priv_passphrase']);
    }
    $snmpdev->init();
    if ($snmpdev->getErrno()) {
        showError($snmpdev->getError());
        return;
    }
    /* SNMP connect successfull */
    showSuccess("SNMP " . $snmpconfig['version'] . " connect to {$snmpconfig['host']} successfull");
    echo '<form name=CreatePorts method=post action=' . $_SERVER['REQUEST_URI'] . '&module=redirect&op=create>';
    echo "<strong>System Informations</strong>";
    echo "<table>";
    //	echo "<tr><th>OID</th><th>Value</th></tr>";
    $systemoids = array('sysDescr', 'sysObjectID', 'sysUpTime', 'sysContact', 'sysName', 'sysLocation');
    foreach ($systemoids as $shortoid) {
        $value = $snmpdev->{$shortoid};
        if ($shortoid == 'sysUpTime') {
            /* in hundredths of a second */
            $secs = (int) ($value / 100);
            $days = (int) ($secs / (60 * 60 * 24));
            $secs -= $days * 60 * 60 * 24;
            $hours = (int) ($secs / (60 * 60));
            $secs -= $hours * 60 * 60;
            $mins = (int) ($secs / 60);
            $secs -= $mins * 60;
            $value = "{$value} ({$days} {$hours}:{$mins}:{$secs})";
        }
        echo "<tr><td title=\"" . $snmpdev->lastgetoid . "\" align=\"right\">{$shortoid}: </td><td>{$value}</td></tr>";
    }
    unset($shortoid);
    echo "</table>";
    /* sysObjectID Attributes and Ports */
    $sysObjectID['object'] =& $object;
    /* get sysObjectID */
    $sysObjectID['raw_value'] = $snmpdev->sysObjectID;
    //$sysObjectID['raw_value'] = 'NET-SNMP-MIB::netSnmpAgentOIDs.10';
    $sysObjectID['value'] = preg_replace('/^.*enterprises\\.([\\.[:digit:]]+)$/', '\\1', $sysObjectID['raw_value']);
    /* try snmptranslate to numeric */
    if (preg_match('/[^\\.0-9]+/', $sysObjectID['value'])) {
        $numeric_value = $snmpdev->translatetonumeric($sysObjectID['value']);
        if (!empty($numeric_value)) {
            showSuccess("sysObjectID: " . $sysObjectID['value'] . " translated to {$numeric_value}");
            $sysObjectID['value'] = preg_replace('/^.1.3.6.1.4.1.([\\.[:digit:]]+)$/', '\\1', $numeric_value);
        }
    }
    /* array_merge doesn't work with numeric keys !! */
    $sysObjectID['attr'] = array();
    $sysObjectID['port'] = array();
    $sysobjid = $sysObjectID['value'];
    $count = 1;
    while ($count) {
        if (isset($sg_known_sysObjectIDs[$sysobjid])) {
            $sysObjectID = $sysObjectID + $sg_known_sysObjectIDs[$sysobjid];
            if (isset($sg_known_sysObjectIDs[$sysobjid]['attr'])) {
                $sysObjectID['attr'] = $sysObjectID['attr'] + $sg_known_sysObjectIDs[$sysobjid]['attr'];
            }
            if (isset($sg_known_sysObjectIDs[$sysobjid]['port'])) {
                $sysObjectID['port'] = $sysObjectID['port'] + $sg_known_sysObjectIDs[$sysobjid]['port'];
            }
            if (isset($sg_known_sysObjectIDs[$sysobjid]['text'])) {
                showSuccess("found sysObjectID ({$sysobjid}) " . $sg_known_sysObjectIDs[$sysobjid]['text']);
            }
        }
        $sysobjid = preg_replace('/\\.[[:digit:]]+$/', '', $sysobjid, 1, $count);
        /* add default sysobjectid */
        if ($count == 0 && $sysobjid != 'default') {
            $sysobjid = 'default';
            $count = 1;
        }
    }
    $sysObjectID['vendor_number'] = $sysobjid;
    /* device pf */
    if (isset($sysObjectID['pf'])) {
        foreach ($sysObjectID['pf'] as $function) {
            if (function_exists($function)) {
                /* call device pf */
                $function($snmpdev, $sysObjectID, NULL);
            } else {
                showWarning("Missing processor function " . $function . " for device {$sysobjid}");
            }
        }
    }
    /* sort attributes maintain numeric keys */
    ksort($sysObjectID['attr']);
    /* DEBUG */
    //sg_var_dump_html($sysObjectID['attr'], "Before processing");
    /* needs PHP >= 5 foreach call by reference */
    /* php 5.1.6 doesn't seem to work */
    //foreach($sysObjectID['attr'] as $attr_id => &$attr)
    foreach ($sysObjectID['attr'] as $attr_id => $value) {
        $attr =& $sysObjectID['attr'][$attr_id];
        if (isset($object['attr'][$attr_id])) {
            if (array_key_exists('key', $object['attr'][$attr_id])) {
                $attr['key'] = $object['attr'][$attr_id]['key'];
            }
            switch (TRUE) {
                case isset($attr['pf']):
                    if (function_exists($attr['pf'])) {
                        $attr['pf']($snmpdev, $sysObjectID, $attr_id);
                    } else {
                        showWarning("Missing processor function " . $attr['pf'] . " for attribute {$attr_id}");
                    }
                    break;
                case isset($attr['oid']):
                    $attrvalue = $snmpdev->get($attr['oid']);
                    if (isset($attr['regex'])) {
                        $regex = $attr['regex'];
                        if (isset($attr['replacement'])) {
                            $replacement = $attr['replacement'];
                            $attrvalue = preg_replace($regex, $replacement, $attrvalue);
                        } else {
                            if (!preg_match($regex, $attrvalue)) {
                                if (!isset($attr['uncheck'])) {
                                    $attr['uncheck'] = "regex doesn't match";
                                }
                            } else {
                                unset($attr['uncheck']);
                            }
                        }
                    }
                    $attr['value'] = $attrvalue;
                    break;
                case isset($attr['value']):
                    break;
                default:
                    showError("Error handling attribute id: {$attr_id}");
            }
        } else {
            showWarning("Object has no attribute id: {$attr_id}");
            unset($sysObjectID['attr'][$attr_id]);
        }
    }
    unset($attr_id);
    /* sort again in case there where attribs added ,maintain numeric keys */
    ksort($sysObjectID['attr']);
    /* print attributes */
    echo '<br>Attributes<br><table>';
    echo '<tr><th><input type="checkbox" id="attribute" checked="checked" onclick="setchecked(this.id)"></td>';
    echo '<th>Name</th><th>Current Value</th><th>new value</th></tr>';
    /* DEBUG */
    //sg_var_dump_html($sysObjectID['attr'], "After processing");
    foreach ($sysObjectID['attr'] as $attr_id => &$attr) {
        $attr['id'] = $attr_id;
        if (isset($object['attr'][$attr_id]) && isset($attr['value'])) {
            if ($attr['value'] == $object['attr'][$attr_id]['value']) {
                $attr['uncheck'] = 'Current = new value';
            }
            if (isset($attr['key']) && isset($object['attr'][$attr_id]['key'])) {
                if ($attr['key'] == $object['attr'][$attr_id]['key']) {
                    $attr['uncheck'] = 'Current = new key';
                }
            }
            $value = $attr['value'];
            $val_key = isset($object['attr'][$attr_id]['key']) ? ' (' . $object['attr'][$attr_id]['key'] . ')' : '';
            $comment = '';
            if (isset($attr['comment'])) {
                if (!empty($attr['comment'])) {
                    $comment = $attr['comment'];
                }
            }
            if (isset($attr['uncheck'])) {
                $checked = '';
                $comment .= ', ' . $attr['uncheck'];
            } else {
                $checked = ' checked="checked"';
            }
            $updateattrcheckbox = '<b style="background-color:#00ff00">' . '<input style="background-color:#00ff00" class="attribute" type="checkbox" name="updateattr[' . $attr_id . ']" value="' . $value . '"' . $checked . '></b>';
            $comment = trim($comment, ', ');
            echo "<tr><td>{$updateattrcheckbox}</td><td title=\"id: {$attr_id}\">" . $object['attr'][$attr_id]['name'] . '</td><td style="background-color:#d8d8d8">' . $object['attr'][$attr_id]['value'] . $val_key . '</td><td>' . $value . '</td>' . '<td style="color:#888888">' . $comment . '</td></tr>';
        }
    }
    unset($attr_id);
    echo '</table>';
    $object['breed'] = sg_detectDeviceBreedByObject($sysObjectID);
    if (!empty($object['breed'])) {
        echo "Found Breed: " . $object['breed'] . "<br>";
    }
    /* ports */
    /* get ports */
    amplifyCell($object);
    /* set array key to lowercase port name */
    foreach ($object['ports'] as $key => $values) {
        $object['ports'][strtolower(shortenIfName($values['name'], $object['breed']))] = $values;
        unset($object['ports'][$key]);
    }
    $newporttypeoptions = getNewPortTypeOptions();
    //	sg_var_dump_html($sysObjectID['port']);
    if (!empty($sysObjectID['port'])) {
        echo '<br>Vendor / Device specific ports<br>';
        echo '<table><tr><th><input type="checkbox" id="moreport" checked="checked" onclick="setchecked(this.id)"></th><th>ifName</th><th>porttypeid</th></tr>';
        foreach ($sysObjectID['port'] as $name => $port) {
            if (array_key_exists(strtolower($name), $object['ports'])) {
                $disableport = TRUE;
            } else {
                $disableport = FALSE;
            }
            $comment = '';
            if (isset($port['comment'])) {
                if (!empty($port['comment'])) {
                    $comment = $port['comment'];
                }
            }
            if (isset($port['uncheck'])) {
                $checked = '';
                $comment .= ', ' . $port['uncheck'];
            } else {
                $checked = ' checked="checked"';
            }
            $portcreatecheckbox = '<b style="background-color:' . ($disableport ? '#ff0000' : '#00ff00') . '"><input style="background-color:' . ($disableport ? '#ff0000' : '#00ff00') . '" class="moreport" type="checkbox" name="portcreate[' . $name . ']" value="' . $name . '"' . ($disableport ? ' disabled="disbaled"' : $checked) . '></b>';
            $formfield = '<input type="hidden" name="ifName[' . $name . ']" value="' . $name . '">';
            echo "<tr>{$formfield}<td>{$portcreatecheckbox}</td><td>{$name}</td>";
            if (isset($port['disabled'])) {
                $disabledselect = array('disabled' => "disabled");
            } else {
                $disabledselect = array();
            }
            foreach ($port as $key => $value) {
                if ($key == 'uncheck' || $key == 'comment') {
                    continue;
                }
                /* TODO iif_name */
                if ($key == 'porttypeid') {
                    $displayvalue = getNiftySelect($newporttypeoptions, array('name' => "porttypeid[{$name}]") + $disabledselect, $value);
                } else {
                    $displayvalue = $value;
                }
                $formfield = '<input type="hidden" name="' . $key . '[' . $name . ']" value="' . $value . '">';
                echo "{$formfield}<td>{$displayvalue}</td>";
            }
            $comment = trim($comment, ', ');
            echo "<td style=\"color:#888888\">{$comment}</td></tr>";
        }
        unset($name);
        unset($port);
        echo '</table>';
    }
    /* snmp ports */
    $ifsnmp = new ifSNMP($snmpdev);
    // needed for shortenIfName()
    $ifsnmp->object_breed = $object['breed'];
    /* ip spaces */
    $ipspace = NULL;
    foreach ($ifsnmp->ipaddress as $ifindex => $ipaddresses) {
        foreach ($ipaddresses as $ipaddr => $value) {
            $addrtype = $value['addrtype'];
            $netaddr = $value['net'];
            $maskbits = $value['maskbits'];
            $netid = NULL;
            $linklocal = FALSE;
            //echo "<br> - DEBUG: ipspace $ipaddr - $netaddr - $addrtype - $maskbits<br>";
            /* check for ip space */
            switch ($addrtype) {
                case 'ipv4':
                case 'ipv4z':
                    if ($maskbits == 32) {
                        $netid = 'host';
                    } else {
                        $netid = getIPv4AddressNetworkId(ip_parse($ipaddr));
                    }
                    break;
                case 'ipv6':
                    if (ip_checkparse($ipaddr) === false) {
                        /* format ipaddr for ip6_parse */
                        $ipaddr = preg_replace('/((..):(..))/', '\\2\\3', $ipaddr);
                        $ipaddr = preg_replace('/%.*$/', '', $ipaddr);
                    }
                    if (ip_checkparse($ipaddr) === false) {
                        continue 2;
                    }
                    // 2 because of switch
                    $ip6_bin = ip6_parse($ipaddr);
                    $ip6_addr = ip_format($ip6_bin);
                    $netid = getIPv6AddressNetworkId($ip6_bin);
                    $node = constructIPRange($ip6_bin, $maskbits);
                    $netaddr = $node['ip'];
                    $linklocal = substr($ip6_addr, 0, 5) == "fe80:";
                    //echo "<br> - DEBUG: ipspace $ipaddr - $addrtype - $maskbits - $netaddr - >$linklocal<<br>";
                    break;
                case 'ipv6z':
                    /* link local */
                    $netid = 'ignore';
                    break;
                default:
            }
            if (empty($netid) && $netaddr != '::1' && $netaddr != '127.0.0.1' && $netaddr != '127.0.0.0' && $netaddr != '0.0.0.0' && !$linklocal) {
                $netaddr .= "/{$maskbits}";
                $ipspace[$netaddr] = array('addrtype' => $addrtype, 'checked' => $maskbits > 0 ? true : false);
            }
        }
        unset($ipaddr);
        unset($value);
        unset($addrtype);
    }
    unset($ifindex);
    unset($ipaddresses);
    /* print ip spaces table */
    if (!empty($ipspace)) {
        echo '<br><br>Create IP Spaces';
        echo '<table><tr><th><input type="checkbox" id="ipspace" onclick="setchecked(this.id)" checked=\\"checked\\"></th>';
        echo '<th>Type</th><th>prefix</th><th>name</th><th width=150 title="reserve network and router addresses">reserve network / router addresses</th></tr>';
        $i = 1;
        foreach ($ipspace as $prefix => $ipspace) {
            $netcreatecheckbox = '<b style="background-color:#00ff00">' . '<input class="ipspace" style="background-color:#00ff00" type="checkbox" name="netcreate[' . $i . ']" value="' . $ipspace['addrtype'] . '"' . ($ipspace['checked'] ? ' checked=\\"checked\\"' : '') . '></b>';
            $netprefixfield = '<input type="text" size=50 name="netprefix[' . $i . ']" value="' . $prefix . '">';
            $netnamefield = '<input type="text" name="netname[' . $i . ']">';
            $netreservecheckbox = '<input type="checkbox" name="netreserve[' . $i . ']" checked="checked">';
            echo "<tr><td>{$netcreatecheckbox}</td><td style=\"color:#888888\">{$ipspace['addrtype']}</td><td>{$netprefixfield}</td><td>{$netnamefield}</td><td>{$netreservecheckbox}</td></tr>";
            $i++;
        }
        unset($prefix);
        unset($addrtype);
        unset($i);
        echo '</table>';
    }
    echo "<br><br>ifNumber: " . $ifsnmp->ifNumber . "<br>indexcount: " . $ifsnmp->indexcount . "<br><table><tbody valign=\"top\">";
    $portcompat = getPortInterfaceCompat();
    $ipnets = array();
    $ifsnmp->printifInfoTableHeader("<th>add ip</th><th>add port</th><th>upd label</th><th title=\"update mac\">upd mac</th><td>upd port type</th><th>porttypeid</th><th>comment</th></tr>");
    echo '<tr><td colspan="11"></td>
		<td><input type="checkbox" id="ipaddr" onclick="setchecked(this.id);" checked="checked">IPv4<br>
		<input type="checkbox" id="ipv6addr" onclick="setchecked(this.id);" checked="checked">IPv6</td>
		<td><input type="checkbox" id="ports" onclick="setchecked(this.id)"></td>
		<td><input type="checkbox" id="label" onclick="setchecked(this.id);" checked="checked"></td>
		<td><input type="checkbox" id="mac" onclick="setchecked(this.id);" checked="checked"></td>
		<td><input type="checkbox" id="porttype" onclick="setchecked(this.id);"></td></tr>';
    foreach ($ifsnmp as $if) {
        $createport = TRUE;
        $disableport = FALSE;
        $ignoreport = FALSE;
        $port_info = NULL;
        $updatelabel = false;
        $updateporttype = false;
        $updatemaccheckbox = '';
        $hrefs = array();
        $comment = "";
        if (trim($ifsnmp->ifName($if)) == '') {
            $comment .= "no ifName";
            $createport = FALSE;
        } else {
            if (array_key_exists($ifsnmp->ifName($if), $object['ports'])) {
                $port_info =& $object['ports'][$ifsnmp->ifName($if)];
                $comment .= "Name exists";
                /* ifalias change */
                if ($port_info['label'] != $ifsnmp->ifAlias($if)) {
                    $updatelabel = true;
                }
                $createport = FALSE;
                $disableport = TRUE;
            }
        }
        if ($ifsnmp->ifPhysAddress($if) != '') {
            $ifPhysAddress = $ifsnmp->ifPhysAddress($if);
            $l2port = sg_checkL2Address($ifPhysAddress);
            if (!empty($l2port)) {
                $l2object_id = key($l2port);
                $porthref = makeHref(array('page' => 'object', 'tab' => 'ports', 'object_id' => $l2object_id, 'hl_port_id' => $l2port[$l2object_id]));
                $comment .= ", L2Address exists";
                $hrefs['ifPhysAddress'] = $porthref;
                $createport = FALSE;
                //	$disableport = TRUE;
                $updatemaccheckbox = '';
            }
            $disablemac = true;
            if ($disableport) {
                if ($port_info !== NULL) {
                    if (str_replace(':', '', $port_info['l2address']) != $ifPhysAddress) {
                        $disablemac = false;
                    } else {
                        $disablemac = true;
                    }
                }
            } else {
                /* port create always updates mac */
                $updatemaccheckbox = '<b style="background-color:#00ff00">' . '<input style="background-color:' . '#00ff00" type="checkbox"' . ' checked="checked"' . ' disabled=\\"disabled\\"></b>';
            }
            if (!$disablemac) {
                $updatemaccheckbox = '<b style="background-color:' . ($disablemac ? '#ff0000' : '#00ff00') . '">' . '<input class="mac" style="background-color:' . ($disablemac ? '#ff0000' : '#00ff00') . '" type="checkbox" name="updatemac[' . $if . ']" value="' . $object['ports'][$ifsnmp->ifName($if)]['id'] . '" checked="checked"' . ($disablemac ? ' disabled=\\"disabled\\"' : '') . '></b>';
            }
        }
        $porttypeid = guessRToif_id($ifsnmp->ifType($if), $ifsnmp->ifDescr($if));
        if (in_array($ifsnmp->ifType($if), $sg_ifType_ignore)) {
            $comment .= ", ignore if type";
            $createport = FALSE;
            $ignoreport = TRUE;
        } else {
            if ($port_info) {
                $ptid = $port_info['iif_id'] . "-" . $port_info['oif_id'];
                if ($porttypeid != $ptid) {
                    $comment .= ", Update Type {$ptid} -> {$porttypeid}";
                    $updateporttype = true;
                }
            }
        }
        /* ignore ports without an Connector */
        if (!$sg_create_noconnector_ports && $ifsnmp->ifConnectorPresent($if) == 2) {
            $comment .= ", no Connector";
            $createport = FALSE;
        }
        /* Allocate IPs ipv4 and ipv6 */
        $ipaddresses = $ifsnmp->ipaddress($if);
        if (!empty($ipaddresses)) {
            $ipaddrcell = '<table>';
            foreach ($ipaddresses as $ipaddr => $value) {
                $createipaddr = FALSE;
                $disableipaddr = FALSE;
                $ipaddrhref = '';
                $linklocal = FALSE;
                $addrtype = $value['addrtype'];
                $maskbits = $value['maskbits'];
                $bcast = $value['bcast'];
                //echo "<br> - DEBUG: ip $ipaddr - $addrtype - $maskbits - $bcast<br>";
                switch ($addrtype) {
                    case 'ipv4z':
                    case 'ipv4':
                        if ($maskbits == 32) {
                            $bcast = "host";
                        }
                        $inputname = 'ip';
                        break;
                    case 'ipv6z':
                        $disableipaddr = TRUE;
                    case 'ipv6':
                        $inputname = 'ipv6';
                        if (ip_checkparse($ipaddr) === false) {
                            /* format ipaddr for ip6_parse */
                            $ipaddr = preg_replace('/((..):(..))/', '\\2\\3', $ipaddr);
                            $ipaddr = preg_replace('/%.*$/', '', $ipaddr);
                        }
                        if (ip_checkparse($ipaddr) === false) {
                            continue 2;
                        }
                        // 2 because of switch
                        /* ip_parse throws exception on parse errors */
                        $ip6_bin = ip_parse($ipaddr);
                        $ipaddr = ip_format($ip6_bin);
                        $node = constructIPRange($ip6_bin, $maskbits);
                        $linklocal = $node['ip'] == 'fe80::';
                        $createipaddr = FALSE;
                        break;
                }
                //switch
                $address = getIPAddress(ip_parse($ipaddr));
                /* only if ip not already allocated */
                if (empty($address['allocs'])) {
                    if (!$ignoreport) {
                        $createipaddr = TRUE;
                    }
                } else {
                    $disableipaddr = TRUE;
                    $ipobject_id = $address['allocs'][0]['object_id'];
                    $ipaddrhref = makeHref(array('page' => 'object', 'object_id' => $ipobject_id, 'hl_ipv4_addr' => $ipaddr));
                }
                /* reserved addresses */
                if ($address['reserved'] == 'yes') {
                    $comment .= ', ' . $address['ip'] . ' reserved ' . $address['name'];
                    $createipaddr = FALSE;
                    //	$disableipaddr = TRUE;
                }
                if ($ipaddr == '127.0.0.1' || $ipaddr == '0.0.0.0' || $ipaddr == '::1' || $ipaddr == '::' || $linklocal) {
                    $createipaddr = FALSE;
                    $disableipaddr = TRUE;
                }
                if ($ipaddr === $bcast) {
                    $comment .= ", {$ipaddr} broadcast";
                    $createipaddr = FALSE;
                    $disableipaddr = TRUE;
                }
                if (!$disableipaddr) {
                    $ipaddrcheckbox = '<b style="background-color:' . ($disableipaddr ? '#ff0000' : '#00ff00') . '"><input class="' . $inputname . 'addr" style="background-color:' . ($disableipaddr ? '#ff0000' : '#00ff00') . '" type="checkbox" name="' . $inputname . 'addrcreate[' . $ipaddr . ']" value="' . $if . '"' . ($disableipaddr ? ' disabled="disabled"' : '') . ($createipaddr ? ' checked="checked"' : '') . '></b>';
                } else {
                    $ipaddrcheckbox = '';
                }
                $ipaddrcell .= "<tr><td>{$ipaddrcheckbox}</td>";
                if (!empty($ipaddrhref)) {
                    $ipaddrcell .= "<td><a href={$ipaddrhref}>{$ipaddr}/{$maskbits}</a></td></tr>";
                } else {
                    $ipaddrcell .= "<td>{$ipaddr}/{$maskbits}</td></tr>";
                }
            }
            // foreach
            unset($ipaddr);
            unset($value);
            $ipaddrcell .= '</table>';
            // if(!empty($ipaddresses))
        } else {
            $ipaddrcreatecheckbox = '';
            $ipaddrcell = '';
        }
        /* checkboxes for add port and add ip */
        /* FireFox needs <b style=..>, IE and Opera work with <td style=..> */
        if (!$disableport) {
            $portcreatecheckbox = '<b style="background-color:' . ($disableport ? '#ff0000' : '#00ff00') . '"><input class="ports" style="background-color:' . ($disableport ? '#ff0000' : '#00ff00') . '" type="checkbox" name="portcreate[' . $if . ']" value="' . $if . '"' . ($disableport ? ' disabled="disbaled"' : '') . ($createport ? ' checked="checked"' : '') . '></b>';
        } else {
            $portcreatecheckbox = '';
        }
        /* port type id */
        /* add port type to newporttypeoptions if missing */
        if (strpos(serialize($newporttypeoptions), $porttypeid) === FALSE) {
            $portids = explode('-', $porttypeid);
            $oif_name = $sg_portoifoptions[$portids[1]];
            $newporttypeoptions['auto'] = array($porttypeid => "*{$oif_name}");
        }
        $selectoptions = array('name' => "porttypeid[{$if}]");
        if ($disableport && !$updateporttype) {
            $selectoptions['disabled'] = "disabled";
        }
        $updateporttypecheckbox = "";
        if ($updateporttype) {
            $updateporttypecheckbox = '<b style="background-color:#00ff00;">' . '<input class="porttype" style="background-color:#00ff00;" type="checkbox" name="updateporttype[' . $if . ']" value="' . $port_info['id'] . '"></b>';
        }
        $porttypeidselect = getNiftySelect($newporttypeoptions, $selectoptions, $porttypeid);
        $updatelabelcheckbox = "";
        if ($updatelabel) {
            $updatelabelcheckbox = '<b style="background-color:#00ff00;">' . '<input class="label" style="background-color:#00ff00;" type="checkbox" name="updatelabel[' . $if . ']" value="' . $port_info['id'] . ($updatelabel ? '" checked="checked"' : '') . '></b>';
        }
        $comment = trim($comment, ', ');
        $ifsnmp->printifInfoTableRow($if, "<td>{$ipaddrcell}</td><td>{$portcreatecheckbox}</td><td>{$updatelabelcheckbox}</td><td>{$updatemaccheckbox}</td><td>{$updateporttypecheckbox}</td><td>{$porttypeidselect}</td><td nowrap=\"nowrap\">{$comment}</td>", $hrefs);
    }
    unset($if);
    /* preserve snmpconfig */
    foreach ($_POST as $key => $value) {
        echo '<input type=hidden name=' . $key . ' value=' . $value . ' />';
    }
    unset($key);
    unset($value);
    echo '<tr><td colspan=15 align="right"><p><input id="createbutton" type=submit value="Create Ports and IPs" onclick="return confirm(\'Create selected items?\')"></p></td></tr></tbody></table></form>';
}
示例#16
0
function switchportInfoJS($object_id)
{
    $available_ops = array('link' => array('op' => 'get_link_status', 'gw' => 'getportstatus'), 'conf' => array('op' => 'get_port_conf', 'gw' => 'get8021q'), 'mac' => array('op' => 'get_mac_list', 'gw' => 'getmaclist'), 'portmac' => array('op' => 'get_port_mac_list', 'gw' => 'getportmaclist'));
    $breed = detectDeviceBreed($object_id);
    $allowed_ops = array();
    foreach ($available_ops as $prefix => $data) {
        if (permitted('object', 'liveports', $data['op']) and validBreedFunction($breed, $data['gw'])) {
            $allowed_ops[] = $prefix;
        }
    }
    addJS('js/jquery.thumbhover.js');
    addCSS('css/jquery.contextmenu.css');
    addJS('js/jquery.contextmenu.js');
    addJS("enabled_elements = " . json_encode($allowed_ops), TRUE);
    addJS('js/portinfo.js');
}
示例#17
0
function enableTagsPicker()
{
    global $taglist;
    static $taglist_inserted;
    includeJQueryUI();
    addCSS('css/tagit.css');
    addJS('js/tag-it.js');
    addJS('js/tag-it-local.js');
    if (!$taglist_inserted) {
        $taglist_filtered = array();
        foreach ($taglist as $key => $taginfo) {
            # remove unused fields
            $taglist_filtered[$key] = array_sub($taginfo, array("tag", "is_assignable", "trace"));
        }
        addJS('var taglist = ' . json_encode($taglist_filtered) . ';', TRUE);
        $taglist_inserted = TRUE;
    }
}
示例#18
0
文件: index.php 项目: druto/druto
<?php

use Widgets\Hello\Helper;
addCSS($widgetBaseURL . '/css/default.css');
addJS($widgetBaseURL . '/js/custom.js');
?>
<div id="Hello">
	<?php 
echo Helper::welcome();
?>
</div>