function CableIDTabHandler()
{
    echo '<div class=portlet><h2>Cable ID Helper</h2></div>';
    $rack = spotEntity('rack', $_REQUEST['rack_id']);
    $result = usePreparedSelectBlade('SELECT DISTINCT object_id FROM RackSpace WHERE rack_id = ? ', array($rack['id']));
    $objects = $result->fetchAll(PDO::FETCH_ASSOC);
    $cableIDs = array();
    foreach ($objects as $object) {
        $pals = getObjectPortsAndLinks($object['object_id']);
        foreach ($pals as $portLink) {
            if ($portLink['cableid']) {
                $new = true;
                $dublicate = false;
                foreach ($cableIDs as $key => $cableID) {
                    if ($portLink['object_id'] == $cableID['object1_id'] && $portLink['name'] == $cableID['object1_port'] || $portLink['object_id'] == $cableID['object2_id'] && $portLink['name'] == $cableID['object2_port']) {
                        $new = false;
                        // Link already in List
                    }
                    // Check for duplicate cable ids
                    if ($new && $portLink['cableid'] == $cableID['cableID']) {
                        $dublicate = true;
                        $cableIDs[$key]['dublicate'] = true;
                    }
                }
                if ($new) {
                    $cableID = array();
                    $cableID['cableID'] = $portLink['cableid'];
                    $cableID['object1_id'] = $portLink['object_id'];
                    $cableID['object1_name'] = $portLink['object_name'];
                    $cableID['object1_port'] = $portLink['name'];
                    $cableID['object2_id'] = $portLink['remote_object_id'];
                    $cableID['object2_name'] = $portLink['remote_object_name'];
                    $cableID['object2_port'] = $portLink['remote_name'];
                    $cableID['dublicate'] = $dublicate;
                    array_push($cableIDs, $cableID);
                }
            }
        }
    }
    // Sort by cableIDs
    usort($cableIDs, function ($elem1, $elem2) {
        return strnatcasecmp($elem1['cableID'], $elem2['cableID']);
    });
    // Print table
    echo '<table class="cooltable" align="center" border="0" cellpadding="5" cellspacing="0">' . '<tbody>' . '  <tr>' . '  <th>CableID</th>' . '  <th>Object 1</th>' . '  <th>Object 2</th>' . '  </tr>';
    $i = 0;
    foreach ($cableIDs as $cableID) {
        if ($i % 2) {
            $class = 'row_even tdleft';
        } else {
            $class = 'row_odd tdleft';
        }
        if ($cableID['dublicate']) {
            $class .= ' trerror';
        }
        echo '<tr class="' . $class . '">' . '<td>' . $cableID['cableID'] . '</td>' . '<td><a href="' . makeHref(array('page' => 'object', 'object_id' => $cableID['object1_id'])) . '">' . $cableID['object1_name'] . ': ' . $cableID['object1_port'] . '</a></td>' . '<td><a href="' . makeHref(array('page' => 'object', 'object_id' => $cableID['object2_id'])) . '">' . $cableID['object2_name'] . ': ' . $cableID['object2_port'] . '</a></td>' . '</tr>';
        $i++;
    }
    echo '  </tbody>' . '</table>';
}
function formatVSIP($vip, $plain_text = FALSE)
{
    $fmt_ip = ip_format($vip['vip']);
    if ($plain_text) {
        return $fmt_ip;
    }
    $ret = '<a href="' . makeHref(array('page' => 'ipaddress', 'ip' => $fmt_ip)) . '">' . $fmt_ip . '</a>';
    return $ret;
}
function getPatchCableHeapCursorCode($heap, $zoom_heap_id)
{
    global $pageno, $tabno;
    if ($heap['logc'] == 0) {
        return '&nbsp;';
    }
    $linkparams = array('page' => $pageno, 'tab' => $tabno);
    if ($heap['id'] == $zoom_heap_id) {
        $imagename = 'Zooming';
        $imagetext = 'hide event log';
    } else {
        $imagename = 'Zoom';
        $imagetext = 'display event log';
        $linkparams['zoom_heap_id'] = $heap['id'];
    }
    return '<a href="' . makeHref($linkparams) . '">' . getImageHREF($imagename, $imagetext) . '</a>';
}
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 menu($less, $more)
 {
     echo '<span class="nav-menu">';
     $prev = $this->query;
     $prev['page'] = $this->page - 1;
     if ($less == true) {
         echo '<a ' . makeHref($prev) . '>Prev Page</a>';
     }
     if ($less && $more) {
         echo '&nbsp;|&nbsp;';
     }
     $next = $this->query;
     $next['page'] = $this->page + 1;
     if ($more == true) {
         echo '<a ' . makeHref($next) . '>Next Page</a>';
     }
     echo '</span>';
 }
Example #6
0
function getConfiguredQuickLinks()
{
    $ret = array();
    foreach (explode(',', getConfigVar('QUICK_LINK_PAGES')) as $page_code) {
        if (!empty($page_code)) {
            $title = getPageName($page_code);
            if (!empty($title)) {
                $ret[] = array('href' => makeHref(array('page' => $page_code)), 'title' => $title);
            }
        }
    }
    return $ret;
}
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 formatAttributeValue($record)
{
    if ('date' == $record['type']) {
        return datetimestrFromTimestamp($record['value']);
    }
    if (!isset($record['key'])) {
        if ($record['id'] == 3) {
            // FQDN attribute
            foreach (getMgmtProtosConfig() as $proto => $filter) {
                try {
                    if (considerGivenConstraint(NULL, $filter)) {
                        $blank = preg_match('/^https?$/', $proto) ? 'target=_blank' : '';
                        return "<a {$blank} title='Open {$proto} session' class='mgmt-link' href='" . $proto . '://' . $record['a_value'] . "'>{$record['a_value']}</a>";
                    }
                } catch (RackTablesError $e) {
                    // syntax error in $filter
                    continue;
                }
            }
        }
        return isset($record['href']) ? "<a href=\"" . $record['href'] . "\">{$record['a_value']}</a>" : $record['a_value'];
    }
    $href = makeHref(array('page' => 'depot', 'tab' => 'default', 'andor' => 'and', 'cfe' => '{$attr_' . $record['id'] . '_' . $record['key'] . '}'));
    $result = "<a href='{$href}'>" . $record['a_value'] . "</a>";
    if (isset($record['href'])) {
        $result .= "&nbsp;<a class='img-link' href='{$record['href']}'>" . getImageHREF('html', 'vendor&apos;s info page') . "</a>";
    }
    return $result;
}
function ImportTab()
{
    global $nextorder;
    global $Version;
    global $taglist;
    ?>

  <style type='text/css'>
  tr.has_problems 
  {
    background-color: #ffa0a0;
  }
  </style>

  <!--Legend-->
  <table align=right>
  <tr class=trerror><td colspan=2>Unknown object</td></tr>
  <tr><td class=row_even>Existing </td><td class=row_odd> object</td></tr>
  </table>

  <center><h1>Import yaml objects </h1><h2>from /yamls/</h2></center>
<?php 
    startPortlet();
    echo "<table with=90% align=center border=0 cellpadding=5 cellspacing=0 align=center class=cooltable><tr valign=top>";
    echo "<form method=post name=ImportObject action='?module=redirect&page=depot&tab=yaml_import&op=RunImport'>";
    echo "<tr valign=top><th>Assign tags</th><th align=center>Name</th><th align=center>Import ?</th></tr>";
    // taglist on display - left handed
    echo "<tr valign=top><td rowspan=\"0\">";
    renderNewEntityTags('object');
    echo "</td></tr>";
    $order = 'odd';
    # Find and read loop through all .yaml files in the yaml directory.
    //  if ($handle = opendir('./yamls/'))
    if ($files = scandir('./yamls/')) {
        //    while (false !== ($file = readdir($handle)))
        foreach ($files as $file) {
            # Since puppet names the files $FQDN.yaml, we don't have to inspect the file during the first run.
            if (preg_match('/\\.yaml/', $file)) {
                $name = preg_replace('/\\.yaml/', '', $file);
                # Do a search on the row 'name' passing the one name, and retrieving the ID.
                $object = getSearchResultByField('RackObject', array('id'), 'name', $name, '', 2);
                if ($object) {
                    $url = makeHref(array('page' => 'object', 'tab' => 'default', 'object_id' => $object[0]['id']));
                    echo "<tr class=row_{$order}><td align=left><a href=\"{$url}\">" . $name . "</a></td>\n";
                } else {
                    echo "<tr class=trerror><td align=left>" . $name . "</td>\n";
                }
                echo "<td align=center> <input type=checkbox name=objectname[] value={$name}></td></tr>\n";
                $order = $nextorder[$order];
            }
        }
    }
    // tags ?
    //  echo "<tr><td rowspan=\"0\">";
    //  renderNewEntityTags('object');
    //  echo "</td></tr>";
    echo "<tr><td align=left><font size=1em color=gray>version {$Version}</font></td><td align=right><input type=submit name=got_very_fast_data value='Import selected items'></td><td></td></tr></table></td></tr>";
    echo "</form>";
    echo "</table>";
    finishPortlet();
}
Example #10
0
function PingTab($id)
{
    $pingtimeout = "50";
    if (isset($_REQUEST['pg'])) {
        $page = $_REQUEST['pg'];
    } else {
        $page = 0;
    }
    global $pageno, $tabno;
    $maxperpage = getConfigVar('IPV4_ADDRS_PER_PAGE');
    $range = spotEntity('ipv4net', $id);
    loadIPAddrList($range);
    echo "<center><h1>{$range['ip']}/{$range['mask']}</h1><h2>{$range['name']}</h2></center>\n";
    echo "<table class=objview border=0 width='100%'><tr><td class=pcleft>";
    startPortlet('icmp ping comparrison:');
    $startip = ip4_bin2int($range['ip_bin']);
    $endip = ip4_bin2int(ip_last($range));
    $realstartip = $startip;
    $realendip = $endip;
    $numpages = 0;
    if ($endip - $startip > $maxperpage) {
        $numpages = ($endip - $startip) / $maxperpage;
        $startip = $startip + $page * $maxperpage;
        $endip = $startip + $maxperpage - 1;
    }
    echo "<center>";
    if ($numpages) {
        echo '<h3>' . ip4_format(ip4_int2bin($startip)) . ' ~ ' . ip4_format(ip4_int2bin($endip)) . '</h3>';
    }
    for ($i = 0; $i < $numpages; $i++) {
        if ($i == $page) {
            echo "<b>{$i}</b> ";
        } else {
            echo "<a href='" . makeHref(array('page' => $pageno, 'tab' => $tabno, 'id' => $id, 'pg' => $i)) . "'>{$i}</a> ";
        }
    }
    echo "</center>";
    echo "<table class='widetable' border=0 cellspacing=0 cellpadding=5 align='center'>\n";
    echo "<tr><th>address</th><th>name</th><th>response</th></tr>\n";
    $idx = 1;
    $box_counter = 1;
    $cnt_ok = $cnt_noreply = $cnt_mismatch = 0;
    for ($ip = $startip; $ip <= $endip; $ip++) {
        $ip_bin = ip4_int2bin($ip);
        $addr = isset($range['addrlist'][$ip_bin]) ? $range['addrlist'][$ip_bin] : array('name' => '', 'reserved' => 'no');
        $straddr = ip4_format($ip_bin);
        system("/usr/sbin/fping -q -c 1 -t {$pingtimeout} {$straddr}", $pingreply);
        // FIXME: This is a huge and ugly IF/ELSE block. Prettify anyone?
        if (!$pingreply) {
            if (!empty($addr['name']) and $addr['reserved'] == 'no' or !empty($addr['allocs'])) {
                echo '<tr class=trok';
                $cnt_ok++;
            } else {
                echo $addr['reserved'] == 'yes' ? '<tr class=trwarning' : '<tr class=trerror';
                $cnt_mismatch++;
            }
        } else {
            if (!empty($addr['name']) and $addr['reserved'] == 'no' or !empty($addr['allocs'])) {
                echo '<tr class=trwarning';
                $cnt_noreply++;
            } else {
                echo '<tr';
            }
        }
        echo "><td class='tdleft";
        if (isset($range['addrlist'][$ip_bin]['class']) and strlen($range['addrlist'][$ip_bin]['class'])) {
            echo ' ' . $range['addrlist'][$ip_bin]['class'];
        }
        echo "'><a href='" . makeHref(array('page' => 'ipaddress', 'ip' => $straddr)) . "'>{$straddr}</a></td>";
        echo "<td class=tdleft>{$addr['name']}</td><td class=tderror>";
        if (!$pingreply) {
            echo "Yes";
        } else {
            echo "No";
        }
        echo "</td></tr>\n";
        $idx++;
    }
    echo "</td></tr>";
    echo "</table>";
    echo "</form>";
    finishPortlet();
    echo "</td><td class=pcright>";
    startPortlet('stats');
    echo "<table border=0 width='100%' cellspacing=0 cellpadding=2>";
    echo "<tr class=trok><th class=tdright>OKs:</th><td class=tdleft>{$cnt_ok}</td></tr>\n";
    echo "<tr class=trwarning><th class=tdright>Did not reply:</th><td class=tdleft>{$cnt_noreply}</td></tr>\n";
    if ($cnt_mismatch) {
        echo "<tr class=trerror><th class=tdright>Unallocated answer:</th><td class=tdleft>{$cnt_mismatch}</td></tr>\n";
    }
    echo "</table>\n";
    finishPortlet();
    echo "</td></tr></table>\n";
}
Example #11
0
function formatVLANName($vlaninfo, $context = 'markup long')
{
    switch ($context) {
        case 'option':
            $ret = $vlaninfo['vlan_id'];
            if ($vlaninfo['vlan_descr'] != '') {
                $ret .= ' ' . niftyString($vlaninfo['vlan_descr']);
            }
            return $ret;
        case 'label':
            $ret = $vlaninfo['vlan_id'];
            if ($vlaninfo['vlan_descr'] != '') {
                $ret .= ' <i>(' . niftyString($vlaninfo['vlan_descr']) . ')</i>';
            }
            return $ret;
        case 'plain long':
            $ret = 'VLAN' . $vlaninfo['vlan_id'];
            if ($vlaninfo['vlan_descr'] != '') {
                $ret .= ' (' . niftyString($vlaninfo['vlan_descr'], 20, FALSE) . ')';
            }
            return $ret;
        case 'hyperlink':
            $ret = '<a href="';
            $ret .= makeHref(array('page' => 'vlan', 'vlan_ck' => $vlaninfo['domain_id'] . '-' . $vlaninfo['vlan_id']));
            $ret .= '">' . formatVLANName($vlaninfo, 'markup long') . '</a>';
            return $ret;
        case 'markup long':
        default:
            $ret = 'VLAN' . $vlaninfo['vlan_id'];
            $ret .= ' @' . niftyString($vlaninfo['domain_descr']);
            if ($vlaninfo['vlan_descr'] != '') {
                $ret .= ' <i>(' . niftyString($vlaninfo['vlan_descr']) . ')</i>';
            }
            return $ret;
    }
}
function getWattsPerRow()
{
    // assertions
    // find the needed attributes
    global $nextorder;
    // Was this function called with a specific row_id?
    if (isset($_REQUEST['row_id'])) {
        assertStringArg('row_id');
        $row_toshow = $_REQUEST['row_id'];
    } else {
        $row_toshow = -1;
    }
    //from renderRackspace(), interface.php:151
    $found_racks = array();
    $rows = array();
    $cellfilter = getCellFilter();
    $rackCount = 0;
    $order = 'odd';
    // get rackspace information
    foreach (getAllRows() as $row_id => $rowInfo) {
        $rackList = filterCellList(listCells('rack', $row_id), $cellfilter['expression']);
        $found_racks = array_merge($found_racks, $rackList);
        $rows[] = array('location_id' => $rowInfo['location_id'], 'location_name' => $rowInfo['location_name'], 'row_id' => $row_id, 'row_name' => $rowInfo['name'], 'racks' => $rackList);
        $rackCount += count($rackList);
    }
    // Main layout starts.
    echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
    // Left portlet with list of rows.
    echo "<tr><td class=pcleft width='50%'>";
    startPortlet('Rack Rows (' . count($rows) . ')');
    echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
    foreach ($rows as $row) {
        $row_id = $row['row_id'];
        $row_name = $row['row_name'];
        $row_location = $row['location_name'];
        $rackList = $row['racks'];
        echo "<tr class=row_{$order}><td width='20%'></td><td class=tdleft>";
        if (!count($rackList)) {
            echo "{$row_location} - {$row_name} (empty row)";
        } else {
            echo "<a href='" . makeHref(array('page' => 'reports', 'tab' => 'watts_per_row', 'row_id' => $row_id)) . "'>{$row_location} - {$row_name}</a>";
        }
        echo "<td><tr>\n";
        $order = $nextorder[$order];
    }
    echo "</td></tr>\n";
    echo "</table><br>\n";
    finishPortlet();
    echo "</td><td class=pcright>";
    // Right Portlet: Draw the racks in the selected row
    if ($row_toshow > -1) {
        $rowInfo = getRowInfo($row_toshow);
        $cellfilter = getCellFilter();
        $rackList = filterCellList(listCells('rack', $row_toshow), $cellfilter['expression']);
        $rackwidth = getRackImageWidth() * getConfigVar('ROW_SCALE');
        // Maximum number of racks per row is proportionally less, but at least 1.
        $maxPerRow = max(floor(getConfigVar('RACKS_PER_ROW') / getConfigVar('ROW_SCALE')), 1);
        $rackListIdx = 0;
        $rowTotalWattage = 0;
        $order = 'odd';
        startPortlet('Racks within ' . $rowInfo['name'] . ' (' . count($rackList) . ')');
        echo "<table border=0 cellspacing=5 align='center'><tr>";
        foreach ($rackList as $rack) {
            $rackTotalWattage = 0;
            // see renderRack(), interface.php:311
            $rackData = spotEntity('rack', $rack['id']);
            amplifyCell($rackData);
            $objectChildren = getEntityRelatives('children', 'object', $objectData['id']);
            foreach ($rackData['mountedObjects'] as $object) {
                $objectData = spotEntity('object', $object);
                amplifyCell($objectData);
                foreach (getAttrValues($objectData['id']) as $record) {
                    if ($record['name'] == 'Wattage consumption') {
                        $rackTotalWattage += $record['value'];
                    }
                }
            }
            if ($rackListIdx % $maxPerRow == 0) {
                echo $rackListIdx > 0 ? '</tr><tr>' : '<tr>';
            }
            echo "<td align=center class=row_{$order}><a href='" . makeHref(array('page' => 'rack', 'rack_id' => $rack['id'])) . "'>";
            echo "<img border=0 width={$rackwidth} height=" . getRackImageHeight($rack['height']) * getConfigVar('ROW_SCALE');
            echo " title='{$rack['height']} units'";
            echo "src='?module=image&img=minirack&rack_id={$rack['id']}'>";
            echo "<br>{$rack['name']} ({$rackTotalWattage})</a></td>";
            $order = $nextorder[$order];
            $rackListIdx++;
            $rowTotalWattage += $rackTotalWattage;
        }
        echo "</tr><tr><td align=center colspan=";
        print count($rackList);
        echo "><br><b>The row total for attribute Wattage consuption is:  {$rowTotalWattage}</b></td>\n";
        echo "</tr></table>\n";
        finishPortlet();
    }
    echo "</td></tr></table>";
}
Example #13
0
function renderServerReport()
{
    $aResult = array();
    $iTotal = 0;
    $sFilter = '{$typeid_4}';
    # typeid_4 = Server
    foreach (scanRealmByText('object', $sFilter) as $Result) {
        $aResult[$Result['id']] = array();
        $aResult[$Result['id']]['sName'] = $Result['name'];
        // Create active links in comment
        $aResult[$Result['id']]['sComment'] = $Result['comment'];
        // Load additional attributes:
        $attributes = getAttrValues($Result['id']);
        $aResult[$Result['id']]['sContact'] = '';
        if (isset($attributes['14']['a_value'])) {
            $aResult[$Result['id']]['sContact'] = $attributes['14']['a_value'];
        }
        $aResult[$Result['id']]['HWtype'] = '';
        if (isset($attributes['2']['a_value'])) {
            $aResult[$Result['id']]['HWtype'] = $attributes['2']['a_value'];
        }
        $aResult[$Result['id']]['OEMSN'] = '';
        if (isset($attributes['1']['a_value'])) {
            $aResult[$Result['id']]['OEMSN'] = $attributes['1']['a_value'];
        }
        $aResult[$Result['id']]['HWExpDate'] = '';
        if (isset($attributes['22']['value'])) {
            $aResult[$Result['id']]['HWExpDate'] = date("Y-m-d", $attributes['22']['value']);
        }
        $aResult[$Result['id']]['sOS'] = '';
        if (isset($attributes['4']['a_value'])) {
            $aResult[$Result['id']]['sOS'] = $attributes['4']['a_value'];
        }
        $aResult[$Result['id']]['sSlotNumber'] = 'unknown';
        if (isset($attributes['28']['a_value']) && $attributes['28']['a_value'] != '') {
            $aResult[$Result['id']]['sSlotNumber'] = $attributes['28']['a_value'];
        }
        // Location
        $aResult[$Result['id']]['sLocation'] = getLocation($Result);
        // IP Informations
        $aResult[$Result['id']]['ipV4List'] = getObjectIPv4AllocationList($Result['id']);
        $aResult[$Result['id']]['ipV6List'] = getObjectIPv6AllocationList($Result['id']);
        // Port (MAC) Informations
        $aResult[$Result['id']]['ports'] = getObjectPortsAndLinks($Result['id']);
        $iTotal++;
    }
    if (isset($_GET['csv'])) {
        header('Content-type: text/csv');
        header('Content-Disposition: attachment; filename=export_' . date("Ymdhis") . '.csv');
        header('Pragma: no-cache');
        header('Expires: 0');
        $outstream = fopen("php://output", "w");
        $aCSVRow = array('Name', 'MAC', 'IP(s)', 'Comment', 'Contact', 'Type', 'OEM', 'HW Expire Date', 'OS', 'Location');
        fputcsv($outstream, $aCSVRow);
        foreach ($aResult as $id => $aRow) {
            $aCSVRow = array();
            $aCSVRow[0] = $aRow['sName'];
            $aCSVRow[1] = '';
            foreach ($aRow['ports'] as $portNumber => $aPortDetails) {
                if (trim($aPortDetails['l2address']) != '') {
                    $aCSVRow[1] .= $aPortDetails['l2address'] . ' ';
                }
            }
            $aCSVRow[1] = trim($aCSVRow[1]);
            $aCSVRow[2] = '';
            foreach ($aRow['ipV4List'] as $key => $aDetails) {
                if (function_exists('ip4_format')) {
                    $key = ip4_format($key);
                }
                if (trim($key) != '') {
                    $aCSVRow[2] .= $key . ' ';
                }
            }
            foreach ($aRow['ipV6List'] as $key => $aDetails) {
                if (function_exists('ip6_format')) {
                    $key = ip6_format($key);
                }
                if (trim($key) != '') {
                    $aCSVRow[2] .= $key . ' ';
                }
            }
            $aCSVRow[2] = trim($aCSVRow[2]);
            $aCSVRow[3] = str_replace('&quot;', "'", $aRow['sComment']);
            $aCSVRow[4] = $aRow['sContact'];
            $aCSVRow[5] = $aRow['HWtype'];
            $aCSVRow[6] = $aRow['OEMSN'];
            $aCSVRow[7] = $aRow['HWExpDate'];
            $aCSVRow[8] = $aRow['sOS'];
            $aCSVRow[9] = preg_replace('/<a[^>]*>(.*)<\\/a>/iU', '$1', $aRow['sLocation']);
            fputcsv($outstream, $aCSVRow);
        }
        fclose($outstream);
        exit(0);
        # Exit normally after send CSV to browser
    }
    // Load stylesheet and jquery scripts
    echo '<link rel="stylesheet" href="extensions/jquery/themes/racktables/style.css" type="text/css"/>';
    echo '<script type="text/javascript" src="extensions/jquery/jquery-latest.js"></script>';
    echo '<script type="text/javascript" src="extensions/jquery/jquery.tablesorter.js"></script>';
    echo '<script type="text/javascript" src="extensions/jquery/picnet.table.filter.min.js"></script>';
    // Display the stat array
    echo '<h2>Server report (' . $iTotal . ')</h2><ul>';
    echo '<a href="index.php?page=reports&tab=server&csv">CSV Export</a>';
    echo '<table id="reportTable" class="tablesorter">
          <thead>
            <tr>
              <th>Name</th>
              <th>MAC</th>
              <th>IP(s)</th>
              <th>Comment</th>
              <th>Contact</th>
              <th>Type</th>
              <th>OEM S/N</th>
              <th>HW Expire Date</th>
              <th>OS</th>
              <th>Location</th>
            </tr>
          </thead>
        <tbody>';
    foreach ($aResult as $id => $aRow) {
        echo '<tr>
              <td><a href="' . makeHref(array('page' => 'object', 'object_id' => $id)) . '">' . $aRow['sName'] . '</a></td>
              <td>';
        foreach ($aRow['ports'] as $portNumber => $aPortDetails) {
            if (trim($aPortDetails['l2address']) != '') {
                echo $aPortDetails['l2address'] . '<br/>';
            }
        }
        echo '  </td>
              <td>';
        foreach ($aRow['ipV4List'] as $key => $aDetails) {
            if (function_exists('ip4_format')) {
                $key = ip4_format($key);
            }
            if (trim($key) != '') {
                echo $key . '<br/>';
            }
        }
        foreach ($aRow['ipV6List'] as $key => $aDetails) {
            if (function_exists('ip6_format')) {
                $key = ip6_format($key);
            }
            if (trim($key) != '') {
                echo $key . '<br/>';
            }
        }
        echo '</td>
            <td>' . makeLinksInText($aRow['sComment']) . '</td>
            <td>' . $aRow['sContact'] . '</td>
            <td>' . $aRow['HWtype'] . '</td>
            <td>' . $aRow['OEMSN'] . '</td>
            <td>' . $aRow['HWExpDate'] . '</td>
            <td>' . $aRow['sOS'] . '</td>
            <td>' . $aRow['sLocation'] . '</td>
          </tr>';
    }
    echo '  </tbody>
        </table>';
    echo '<script type="text/javascript">
          $(document).ready(function()
          {
            $.tablesorter.defaults.widgets = ["zebra"];
            $("#reportTable").tablesorter(
              { headers: {
                2: { sorter: "ipAddress" },
              }, sortList: [[0,0]] }
            )
            $("#reportTable").tableFilter();
          });
       </script>';
}
function renderChapter($tgt_chapter_no)
{
    global $nextorder;
    $words = readChapter($tgt_chapter_no, 'a');
    $wc = count($words);
    if (!$wc) {
        echo "<center><h2>(no records)</h2></center>";
        return;
    }
    $refcnt = getChapterRefc($tgt_chapter_no, array_keys($words));
    $attrs = getChapterAttributes($tgt_chapter_no);
    echo "<br><table class=cooltable border=0 cellpadding=5 cellspacing=0 align=center>\n";
    echo "<tr><th colspan=4>{$wc} record(s)</th></tr>\n";
    echo "<tr><th>Origin</th><th>Key</th><th>Refcnt</th><th>Word</th></tr>\n";
    $order = 'odd';
    foreach ($words as $key => $value) {
        echo "<tr class=row_{$order}><td>";
        printImageHREF($key < 50000 ? 'computer' : 'favorite');
        echo "</td><td class=tdright>{$key}</td><td>";
        if ($refcnt[$key]) {
            $cfe = '';
            foreach ($attrs as $attr_id) {
                if (!empty($cfe)) {
                    $cfe .= ' or ';
                }
                $cfe .= '{$attr_' . $attr_id . '_' . $key . '}';
            }
            if (!empty($cfe)) {
                $href = makeHref(array('page' => 'depot', 'tab' => 'default', 'andor' => 'and', 'cfe' => $cfe));
                echo '<a href="' . $href . '">' . $refcnt[$key] . '</a>';
            } else {
                echo $refcnt[$key];
            }
        }
        echo "</td><td>{$value}</td></tr>\n";
        $order = $nextorder[$order];
    }
    echo "</table>\n<br>";
}
function addAttributesToNetworkSummary($ret, $cell, $summary)
{
    if (!isset($cell['realm']) || $cell['realm'] !== 'ipv4net' && $cell['realm'] !== 'ipv6net') {
        return $ret;
    }
    foreach (getAttrValuesForNetwork($cell) as $record) {
        if (strlen($record['value']) and permitted(NULL, NULL, NULL, array(array('tag' => '$attr_' . $record['id'])))) {
            if (!isset($record['key'])) {
                $value = formatAttributeValue($record);
            } else {
                $href = makeHref(array('page' => 'flatip', 'tab' => 'default', 'attr_id' => $record['id'], 'attr_value' => $record['key'], 'clear-cf' => ''));
                $value = '<a href="' . $href . '">' . $record['a_value'] . '</a>';
            }
            $ret['{sticker}' . $record['name']] = $value;
        }
    }
    return $ret;
}
function renderNetCellForAlloc($cell, $needed_mask = NULL)
{
    if (empty($cell['spare_ranges']) and $cell['kidc'] == 0 and $cell['mask'] < 31) {
        $cell['spare_ranges'][$cell['mask'] + 1][] = $cell['ip_bin'];
        $cell['spare_ranges'][$cell['mask'] + 1][] = ip_last($cell) & ip4_mask($cell['mask'] + 1);
    }
    $ranges = array_keys($cell['spare_ranges']);
    sort($ranges, SORT_NUMERIC);
    foreach ($ranges as &$range) {
        $suffix = count($cell['spare_ranges'][$range]) <= 1 ? '' : '<small> x ' . count($cell['spare_ranges'][$range]) . '</small>';
        $range = '<a href="' . makeHref(array('page' => 'ipv4space', 'tab' => 'newrange', 'set-prefix' => ip_format($cell['spare_ranges'][$range][0]) . '/' . $range)) . '">/' . $range . '</a>' . $suffix;
    }
    $spare_cidr = NULL;
    if (isset($needed_mask)) {
        for ($i = $needed_mask; $i > 0; $i--) {
            if (!empty($cell['spare_ranges'][$i])) {
                $spare_cidr = ip_format($cell['spare_ranges'][$i][0]) . '/' . $needed_mask;
                break;
            }
        }
    }
    echo "<table class='slbcell vscell'><tr><td rowspan=3 width='5%'>";
    printImageHREF('NET');
    echo '</td>';
    echo "<td><a href='index.php?page={$cell['realm']}&id={$cell['id']}'>{$cell['ip']}/{$cell['mask']}</a>";
    echo getRenderedIPNetCapacity($cell);
    echo '</td></tr>';
    echo "<tr><td>";
    if (strlen($cell['name'])) {
        echo "<strong>" . niftyString($cell['name']) . "</strong>";
    } else {
        echo "<span class=sparenetwork>no name</span>";
    }
    // render VLAN
    echo '<div class="vlan">' . implode(', ', $ranges) . '</div>';
    renderNetVLAN($cell);
    echo "</td></tr>";
    echo '<tr><td>';
    echo count($cell['etags']) ? "<small>" . serializeTags($cell['etags']) . "</small>" : '&nbsp;';
    if (isset($spare_cidr)) {
        echo "<div class='vlan'><a href=\"" . makeHref(array('page' => 'ipv4space', 'tab' => 'newrange', 'set-prefix' => $spare_cidr)) . "\">Allocate /{$needed_mask}</a></div>";
    }
    echo "</td></tr></table>";
}
Example #17
0
function cloneRSPool()
{
    assertUIntArg('pool_id');
    $pool = spotEntity('ipv4rspool', $_REQUEST['pool_id']);
    $rs_list = getRSListInPool($pool['id']);
    $tagidlist = array();
    foreach ($pool['etags'] as $taginfo) {
        $tagidlist[] = $taginfo['id'];
    }
    $new_id = commitCreateRSPool($pool['name'] . ' (copy)', $pool['vsconfig'], $pool['rsconfig'], $tagidlist);
    foreach ($rs_list as $rs) {
        addRStoRSPool($new_id, $rs['rsip_bin'], $rs['rsport'], $rs['inservice'], $rs['rsconfig'], $rs['comment']);
    }
    showSuccess("Created a copy of pool <a href='" . makeHref(array('page' => 'ipv4rspool', 'tab' => 'default', 'pool_id' => $pool['id'])) . "'>{$pool['name']}</a>");
    return buildRedirectURL('ipv4rspool', 'default', array('pool_id' => $new_id));
}
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>';
    }
}
Example #19
0
 function _getRackInfo($object_id, $style = '')
 {
     global $lm_cache;
     $rackinfocache = $lm_cache['rackinfo'];
     /* if not in cache get it */
     if (!array_key_exists($object_id, $rackinfocache)) {
         $object = spotEntity('object', $object_id);
         $rack_id = $object['rack_id'];
         if ($rack_id) {
             $rackinfocache[$object_id] = spotEntity('rack', $object['rack_id']);
         }
     }
     $rack =& $rackinfocache[$object_id];
     if (empty($rack)) {
         return '<span style="' . $style . '">Unmounted</span>';
     } else {
         return '<a style="' . $style . '" href=' . makeHref(array('page' => 'row', 'row_id' => $rack['row_id'])) . '>' . $rack['row_name'] . '</a>/<a style="' . $style . '" href=' . makeHref(array('page' => 'rack', 'rack_id' => $rack['id'])) . '>' . $rack['name'] . '</a>';
     }
 }
Example #20
0
function renderEditVlan($vlan_ck)
{
    global $vtoptions;
    $vlan = getVLANInfo($vlan_ck);
    startPortlet('Modify');
    printOpFormIntro('upd');
    // static attributes
    echo '<table border=0 cellspacing=0 cellpadding=2 align=center>';
    echo '<tr><th class=tdright>Name:</th><td class=tdleft>' . "<input type=text size=40 name=vlan_descr value='{$vlan['vlan_descr']}'>" . '</td></tr>';
    echo '<tr><th class=tdright>Type:</th><td class=tdleft>' . getSelect($vtoptions, array('name' => 'vlan_type', 'tabindex' => 102), $vlan['vlan_prop']) . '</td></tr>';
    echo '</table>';
    echo '<p>';
    echo '<input type="hidden" name="vdom_id" value="' . htmlspecialchars($vlan['domain_id'], ENT_QUOTES) . '">';
    echo '<input type="hidden" name="vlan_id" value="' . htmlspecialchars($vlan['vlan_id'], ENT_QUOTES) . '">';
    printImageHREF('SAVE', 'Update VLAN', TRUE);
    echo '</form><p>';
    // get configured ports count
    $portc = 0;
    foreach (getVLANConfiguredPorts($vlan_ck) as $subarray) {
        $portc += count($subarray);
    }
    $clear_line = '';
    $delete_line = '';
    if ($portc) {
        $clear_line .= '<p>';
        $clear_line .= '<a href="' . makeHrefProcess(array('op' => 'clear', 'vlan_ck' => $vlan_ck)) . '">';
        $clear_line .= getImageHREF('clear', "remove this vlan from {$portc} ports") . ' remove</a>' . ' this VLAN from ' . '<a href="' . makeHref(array('page' => 'vlan', 'tab' => 'default', 'vlan_ck' => $vlan_ck)) . '">' . "{$portc} ports</a>";
    }
    $reason = '';
    if ($vlan['vlan_id'] == VLAN_DFL_ID) {
        $reason = "You can not delete default VLAN";
    } elseif ($portc) {
        $reason = "Can not delete: {$portc} ports configured";
    }
    if (!empty($reason)) {
        echo getOpLink(NULL, 'delete VLAN', 'nodestroy', $reason);
    } else {
        echo getOpLink(array('op' => 'del', 'vlan_ck' => $vlan_ck), 'delete VLAN', 'destroy');
    }
    echo $clear_line;
    finishPortlet();
}
Example #21
0
function getRenderedIPPortPair($ip, $port = NULL)
{
    return "<a href=\"" . makeHref(array('page' => 'ipaddress', 'tab' => 'default', 'ip' => $ip)) . "\">" . $ip . "</a>" . (isset($port) ? ":" . $port : "");
}
Example #22
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();
}
Example #23
0
function renderNetVLAN($cell)
{
    if (!empty($cell['8021q'])) {
        $seen = array();
        foreach ($cell['8021q'] as $vlan_info) {
            $seen[$vlan_info['vlan_id']] = $vlan_info['domain_id'] . '-' . $vlan_info['vlan_id'];
        }
        echo '<div class="vlan"><strong><small>VLAN' . (count($seen) > 1 ? 'S' : '') . '</small> ';
        $links = array();
        foreach ($seen as $vlan_id => $vlan_ck) {
            $links[] = '<a href="' . makeHref(array('page' => 'vlan', 'vlan_ck' => $vlan_ck)) . '">' . $vlan_id . '</a>';
        }
        echo implode(', ', $links);
        echo '</strong></div>';
    }
}
function renderSwitchReport()
{
    $aResult = array();
    $iTotal = 0;
    $sFilter = '{$typeid_8}';
    # typeid_8 = Switches
    foreach (scanRealmByText('object', $sFilter) as $Result) {
        $aResult[$Result['id']] = array();
        $aResult[$Result['id']]['sName'] = $Result['name'];
        // Create active links in comment
        $aResult[$Result['id']]['sComment'] = makeLinksInText($Result['comment']);
        // Load additional attributes:
        $attributes = getAttrValues($Result['id']);
        $aResult[$Result['id']]['sContact'] = '';
        if (isset($attributes['14']['a_value'])) {
            $aResult[$Result['id']]['sContact'] = $attributes['14']['a_value'];
        }
        $aResult[$Result['id']]['HWtype'] = '';
        if (isset($attributes['2']['a_value'])) {
            $aResult[$Result['id']]['HWtype'] = $attributes['2']['a_value'];
        }
        $aResult[$Result['id']]['OEMSN'] = '';
        if (isset($attributes['1']['a_value'])) {
            $aResult[$Result['id']]['OEMSN'] = $attributes['1']['a_value'];
        }
        $aResult[$Result['id']]['HWExpDate'] = '';
        if (isset($attributes['22']['value'])) {
            $aResult[$Result['id']]['HWExpDate'] = date("Y-m-d", $attributes['22']['value']);
        }
        $aResult[$Result['id']]['sOSVersion'] = '';
        if (isset($attributes['5']['a_value'])) {
            $aResult[$Result['id']]['sOSVersion'] = $attributes['5']['a_value'];
        }
        $aResult[$Result['id']]['sSlotNumber'] = 'unknown';
        if (isset($attributes['28']['a_value']) && $attributes['28']['a_value'] != '') {
            $aResult[$Result['id']]['sSlotNumber'] = $attributes['28']['a_value'];
        }
        // Location
        $aResult[$Result['id']]['sLocation'] = getLocation($Result);
        $iTotal++;
    }
    if (isset($_GET['csv'])) {
        header('Content-type: text/csv');
        header('Content-Disposition: attachment; filename=export_' . date("Ymdhis") . '.csv');
        header('Pragma: no-cache');
        header('Expires: 0');
        $outstream = fopen("php://output", "w");
        $aCSVRow = array('Name', 'Comment', 'Contact', 'Type', 'OEM', 'HW Expire Date', 'OS Version', 'Location');
        fputcsv($outstream, $aCSVRow);
        foreach ($aResult as $id => $aRow) {
            $aCSVRow = array();
            $aCSVRow[0] = $aRow['sName'];
            $aCSVRow[1] = str_replace('&quot;', "'", $aRow['sComment']);
            $aCSVRow[2] = $aRow['sContact'];
            $aCSVRow[3] = $aRow['HWtype'];
            $aCSVRow[4] = $aRow['OEMSN'];
            $aCSVRow[5] = $aRow['HWExpDate'];
            $aCSVRow[6] = $aRow['sOSVersion'];
            $aCSVRow[7] = preg_replace('/<a[^>]*>(.*)<\\/a>/iU', '$1', $aRow['sLocation']);
            fputcsv($outstream, $aCSVRow);
        }
        fclose($outstream);
        exit(0);
        # Exit normally after send CSV to browser
    }
    // Load stylesheet and jquery scripts
    addCSS('css/extensions/style.css');
    addJS('js/extensions/jquery-latest.js');
    addJS('js/extensions/jquery.tablesorter.js');
    addJS('js/extensions/picnet.table.filter.min.js');
    // Display the stat array
    echo "<h2>Switch report ({$iTotal})</h2><ul>";
    echo '<a href="index.php?page=reports&tab=switches&csv">CSV Export</a>';
    echo '<table id="reportTable" class="tablesorter">
            <thead>
              <tr>
                <th>Name</th>
                <th>Comment</th>
                <th>Contact</th>
                <th>Type</th>
                <th>OEM S/N</th>
                <th>HW Expire Date</th>
                <th>OS Version</th>
                <th>Location</th>
               </tr>
             </thead>
           <tbody>';
    foreach ($aResult as $id => $aRow) {
        echo '<tr>
                <td><a href="' . makeHref(array('page' => 'object', 'object_id' => $id)) . '">' . $aRow['sName'] . '</a></td>
                <td>' . $aRow['sComment'] . '</td>
                <td>' . $aRow['sContact'] . '</td>
                <td>' . $aRow['HWtype'] . '</td>
                <td>' . $aRow['OEMSN'] . '</td>
                <td>' . $aRow['HWExpDate'] . '</td>
                <td>' . $aRow['sOSVersion'] . '</td>
                <td>' . $aRow['sLocation'] . '</td>
              </tr>';
    }
    echo '  </tbody>
          </table>';
    echo '<script type="text/javascript">
            $(document).ready(function()
              {
                $.tablesorter.defaults.widgets = ["zebra"];
                $("#reportTable").tablesorter(
                    { headers: {
                    }, sortList: [[0,0]] }
                );
                $("#reportTable").tableFilter();
              }
            );
          </script>';
}
Example #25
0
 /** Displays a page bar consisting of clickable page numbers. */
 function displayPageBar($noPages, $page)
 {
     // bug found by benoit, first we have to reset the q_result
     $this->filter[Q_RESULT] = 1;
     $barSize = 10;
     // *2
     $start = $page - $barSize > 0 ? $page - $barSize : 1;
     $end = min($noPages, $start + $barSize * 2);
     echo '<div class="menu"><center>';
     // fast reverse (<<)
     if ($start - $barSize * 2 > 0) {
         $this->filter[Q_RESULT] = $page - $barSize * 2;
         $href = makeHref($this->filter);
         echo '<a ' . $href . ">[&#171;]</a>";
     }
     // reverse (<)
     if ($start > 1) {
         $this->filter[Q_RESULT] = $start - 1;
         $href = makeHref($this->filter);
         echo '<a ' . $href . ">[&lt;]</a>";
     }
     // page numbers
     foreach (range($start, $end) as $i) {
         // default page is #1
         // we don't duplicate URLs
         if ($i > 1) {
             $this->filter[Q_RESULT] = $i;
         }
         $href = makeHref($this->filter);
         if ($i == $page) {
             // don't make links for current page
             echo '<b>[' . $i . ']</b>';
         } else {
             echo '<a ' . $href . '>[' . $i . ']</a>';
         }
     }
     // forward (>)
     if ($end < $noPages) {
         $this->filter[Q_RESULT] = $end + 1;
         $href = makeHref($this->filter);
         echo '<a ' . $href . ">[&gt;]</a>";
     }
     // fast forward (>>)
     if ($end + $barSize * 2 <= $noPages) {
         $this->filter[Q_RESULT] = $end + $barSize * 2;
         $href = makeHref($this->filter);
         echo '<a ' . $href . ">[&#187;]</a>\n";
     }
     //print_r($this->filter);
     echo '</center></div>';
 }
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>';
}
Example #27
0
function renderVirtualService($vsid)
{
    $vsinfo = spotEntity('ipv4vs', $vsid);
    echo '<table border=0 class=objectview cellspacing=0 cellpadding=0>';
    if (strlen($vsinfo['name'])) {
        echo "<tr><td colspan=2 align=center><h1>{$vsinfo['name']}</h1></td></tr>\n";
    }
    echo '<tr>';
    echo '<td class=pcleft>';
    $summary = array();
    $summary['Name'] = $vsinfo['name'];
    $summary['Protocol'] = $vsinfo['proto'];
    $summary['Virtual IP address'] = "<a href='" . makeHref(array('page' => 'ipaddress', 'tab' => 'default', 'ip' => $vsinfo['vip'])) . "'>{$vsinfo['vip']}</a>";
    $summary['Virtual port'] = $vsinfo['vport'];
    $summary['tags'] = '';
    $summary['VS configuration'] = '<div class="dashed slbconf">' . $vsinfo['vsconfig'] . '</div>';
    $summary['RS configuration'] = '<div class="dashed slbconf">' . $vsinfo['rsconfig'] . '</div>';
    renderEntitySummary($vsinfo, 'Summary', $summary);
    echo '</td>';
    echo '<td class=pcright>';
    renderSLBTriplets($vsinfo);
    echo '</td></tr><tr><td colspan=2>';
    renderFilesPortlet('ipv4vs', $vsid);
    echo '</tr><table>';
}
Example #28
0
function makeIPAllocLink($ip_bin, $alloc, $display_ifname = FALSE)
{
    $object_name = !isset($object_name) || !strlen($object_name) ? formatEntityName(spotEntity('object', $alloc['object_id'])) : $alloc['object_name'];
    $title = $display_ifname ? '' : "{$alloc['name']} @ {$object_name}";
    return '<a href="' . makeHref(array('page' => 'object', 'tab' => 'default', 'object_id' => $alloc['object_id'], 'hl_ip' => ip_format($ip_bin))) . '"' . ' title="' . htmlspecialchars($title, ENT_QUOTES) . '"' . ">" . ($display_ifname ? $alloc['name'] . '@' : '') . $object_name . "</a>";
}
Example #29
0
function formatAttributeValue($record)
{
    if ('date' == $record['type']) {
        return date(getConfigVar('DATETIME_FORMAT'), $record['value']);
    } else {
        if (!isset($record['key'])) {
            if ($record['id'] == 3) {
                $protos_to_try = array('ssh' => 'SSH_OBJS_LISTSRC', 'telnet' => 'TELNET_OBJS_LISTSRC');
                foreach ($protos_to_try as $proto => $cfgvar) {
                    if (considerConfiguredConstraint(NULL, $cfgvar)) {
                        return "<a title='Open {$proto} session' class='mgmt-link' href='" . $proto . '://' . $record['a_value'] . "'>{$record['a_value']}</a>";
                    }
                }
            }
            return isset($record['href']) ? "<a href=\"" . $record['href'] . "\">{$record['a_value']}</a>" : $record['a_value'];
        } else {
            $href = makeHref(array('page' => 'depot', 'tab' => 'default', 'andor' => 'and', 'cfe' => '{$attr_' . $record['id'] . '_' . $record['key'] . '}'));
            $result = "<a href='{$href}'>" . $record['a_value'] . "</a>";
            if (isset($record['href'])) {
                $result .= "&nbsp;<a class='img-link' href='{$record['href']}'>" . getImageHREF('html', 'vendor&apos;s info page') . "</a>";
            }
            return $result;
        }
    }
}