function getExpirationsText()
{
    $row_format = "%3s|%-30s|%-15s|%-15s|%s\r\n";
    $ret = '';
    $breakdown = array();
    $breakdown[21] = array(array('from' => -365, 'to' => 0, 'title' => 'has expired within last year'), array('from' => 0, 'to' => 30, 'title' => 'expires within 30 days'));
    $breakdown[22] = $breakdown[21];
    $breakdown[24] = $breakdown[21];
    $attrmap = getAttrMap();
    foreach ($breakdown as $attr_id => $sections) {
        $ret .= $attrmap[$attr_id]['name'] . "\r\n";
        $ret .= "===========================================\r\n";
        foreach ($sections as $section) {
            $count = 1;
            $result = scanAttrRelativeDays($attr_id, $section['from'], $section['to']);
            if (!count($result)) {
                continue;
            }
            $ret .= $section['title'] . "\r\n";
            $ret .= "-----------------------------------------------------------------------------------\r\n";
            $ret .= sprintf($row_format, '#', 'Name', 'Asset Tag', 'OEM S/N 1', 'Date Warranty Expires');
            $ret .= "-----------------------------------------------------------------------------------\r\n";
            foreach ($result as $row) {
                $object = spotEntity('object', $row['object_id']);
                $attributes = getAttrValues($object['id']);
                $ret .= sprintf($row_format, $count, $object['dname'], $object['asset_no'], array_key_exists(1, $attributes) ? $attributes[1]['a_value'] : '', datetimestrFromTimestamp($row['uint_value']));
                $count++;
            }
            $ret .= "-----------------------------------------------------------------------------------\r\n";
        }
        $ret .= "\r\n";
    }
    return $ret;
}
function requireMandatoryAttrGeneric($listsrc, $attr_id, $newval)
{
    $object_id = getBypassValue();
    $attrs = getAttrValues($object_id);
    if (array_key_exists($attr_id, $attrs) && considerGivenConstraint(spotEntity('object', $object_id), $listsrc) && !mb_strlen($newval)) {
        showError('Mandatory attribute "' . $attrs[$attr_id]['name'] . '" not set');
        stopOpPropagation();
    }
    return '';
}
예제 #3
0
function checkTypeAndAttribute($object_id, $type_id, $attr_id, $values, $hit = 'std')
{
    $object = spotEntity('object', $object_id);
    if ($object['objtype_id'] != $type_id) {
        return '';
    }
    foreach (getAttrValues($object_id) as $record) {
        if ($record['id'] == $attr_id and in_array($record['key'], $values)) {
            return $hit;
        }
    }
    return '';
}
예제 #4
0
function detectDeviceBreed($object_id)
{
    global $breed_by_swcode, $breed_by_hwcode, $breed_by_mgmtcode;
    foreach (getAttrValues($object_id) as $record) {
        if ($record['id'] == 4 and array_key_exists($record['key'], $breed_by_swcode)) {
            return $breed_by_swcode[$record['key']];
        } elseif ($record['id'] == 2 and array_key_exists($record['key'], $breed_by_hwcode)) {
            return $breed_by_hwcode[$record['key']];
        } elseif ($record['id'] == 30 and array_key_exists($record['key'], $breed_by_mgmtcode)) {
            return $breed_by_mgmtcode[$record['key']];
        }
    }
    return '';
}
예제 #5
0
파일: api.php 프로젝트: xtha/salt
 //    UI handler: renderDepot()
 case 'get_depot':
     require_once 'inc/init.php';
     $cellfilter = getCellFilter();
     $objects = filterCellList(listCells('object'), $cellfilter['expression']);
     // get details if requested
     if (isset($_REQUEST['include_attrs'])) {
         foreach ($objects as $object_id => $object) {
             amplifyCell($object);
             // return the attributes in an array keyed on 'name', unless otherwise requested
             $key_attrs_on = 'name';
             if (isset($_REQUEST['key_attrs_on'])) {
                 $key_attrs_on = $_REQUEST['key_attrs_on'];
             }
             $attrs = array();
             foreach (getAttrValues($object_id) as $record) {
                 // check that the key exists for this record
                 if (!isset($record[$key_attrs_on])) {
                     throw new InvalidRequestArgException('key_attrs_on', $_REQUEST['key_attrs_on'], 'requested keying value not set for all attributes');
                 }
                 if (strlen($record['value'])) {
                     $attrs[$record[$key_attrs_on]] = $record;
                 }
             }
             $objects[$object_id] = $object;
             $objects[$object_id]['attrs'] = $attrs;
         }
     }
     sendAPIResponse($objects);
     break;
     // get all available object attributes
예제 #6
0
function detectDeviceBreed($object_id)
{
    $breed_by_swcode = array(251 => 'ios12', 252 => 'ios12', 254 => 'ios12', 963 => 'nxos4', 964 => 'nxos4', 1365 => 'nxos4', 1410 => 'nxos4', 1411 => 'nxos4', 1643 => 'nxos4', 1352 => 'xos12', 1360 => 'vrp53', 1361 => 'vrp55', 1369 => 'vrp55', 1363 => 'fdry5', 1367 => 'jun10', 1597 => 'jun10', 1598 => 'jun10', 1599 => 'jun10', 1594 => 'ftos8', 1673 => 'air12', 1674 => 'air12', 1675 => 'eos4', 1759 => 'iosxr4', 1786 => 'ros11', 242 => 'linux', 243 => 'linux', 1331 => 'linux', 1332 => 'linux', 1333 => 'linux', 1334 => 'linux', 1395 => 'linux', 1396 => 'linux');
    for ($i = 225; $i <= 235; $i++) {
        $breed_by_swcode[$i] = 'linux';
    }
    for ($i = 418; $i <= 436; $i++) {
        $breed_by_swcode[$i] = 'linux';
    }
    for ($i = 1417; $i <= 1422; $i++) {
        $breed_by_swcode[$i] = 'linux';
    }
    $breed_by_hwcode = array();
    for ($i = 589; $i <= 637; $i++) {
        $breed_by_hwcode[$i] = 'dlink';
    }
    $breed_by_mgmtcode = array(1788 => 'ucs');
    foreach (getAttrValues($object_id) as $record) {
        if ($record['id'] == 4 and array_key_exists($record['key'], $breed_by_swcode)) {
            return $breed_by_swcode[$record['key']];
        } elseif ($record['id'] == 2 and array_key_exists($record['key'], $breed_by_hwcode)) {
            return $breed_by_hwcode[$record['key']];
        } elseif ($record['id'] == 30 and array_key_exists($record['key'], $breed_by_mgmtcode)) {
            return $breed_by_mgmtcode[$record['key']];
        }
    }
    return '';
}
예제 #7
0
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>';
}
예제 #8
0
function linkmgmt_renderObjectLinks($object_id)
{
    $object = spotEntity('object', $object_id);
    $object['attr'] = getAttrValues($object_id);
    /* get ports */
    /* calls getObjectPortsAndLinks */
    amplifyCell($object);
    //$ports = getObjectPortsAndLinks($object_id);
    $ports = $object['ports'];
    /* reindex array so key starts at 0 */
    $ports = array_values($ports);
    /* URL param handling */
    if (isset($_GET['allports'])) {
        $allports = $_GET['allports'];
    } else {
        $allports = FALSE;
    }
    if (isset($_GET['allback'])) {
        $allback = $_GET['allback'];
    } else {
        $allback = FALSE;
    }
    echo '<table><tr>';
    if ($allports) {
        echo '<td width=200><a href="' . makeHref(portlist::urlparams('allports', '0', '0')) . '">Hide Ports without link</a></td>';
    } else {
        echo '<td width=200><a href="' . makeHref(portlist::urlparams('allports', '1', '0')) . '">Show All Ports</a></td>';
    }
    echo '<td width=200><span onclick=window.open("' . makeHrefProcess(portlist::urlparamsarray(array('op' => 'PortLinkDialog', 'linktype' => 'back', 'byname' => '1'))) . '","name","height=700,width=800,scrollbars=yes");><a>Link Object Ports by Name</a></span></td>';
    if ($allback) {
        echo '<td width=200><a href="' . makeHref(portlist::urlparams('allback', '0', '0')) . '">Collapse Backend Links on same Object</a></td>';
    } else {
        echo '<td width=200><a href="' . makeHref(portlist::urlparams('allback', '1', '0')) . '">Expand Backend Links on same Object</a></td>';
    }
    /* Graphviz map */
    echo '<td width=100><span onclick=window.open("' . makeHrefProcess(portlist::urlparamsarray(array('op' => 'map', 'usemap' => 1))) . '","name","height=800,width=800,scrollbars=yes");><a>Object Map</a></span></td>';
    /* Help */
    echo '<td width=200><span onclick=window.open("' . makeHrefProcess(portlist::urlparamsarray(array('op' => 'Help'))) . '","name","height=400,width=500");><a>Help</a></span></td>';
    if (isset($_REQUEST['hl_port_id'])) {
        $hl_port_id = $_REQUEST['hl_port_id'];
    } else {
        $hl_port_id = NULL;
    }
    echo '</tr></table>';
    echo '<br><br><table id=renderobjectlinks0>';
    /*  switch display order depending on backend links */
    $first = portlist::hasbackend($object_id);
    $rowcount = 0;
    foreach ($ports as $key => $port) {
        $plist = new portlist($port, $object_id, $allports, $allback);
        //echo "<td><img src=\"index.php?module=redirect&page=object&tab=linkmgmt&op=map&object_id=$object_id&port_id=${port['id']}&allports=$allports\" ></td>";
        if ($plist->printportlistrow($first, $hl_port_id, $rowcount % 2 ? portlist::ALTERNATE_ROW_BGCOLOR : "#ffffff")) {
            $rowcount++;
        }
    }
    echo "</table>";
}
예제 #9
0
function renderEditLocationForm($location_id)
{
    global $pageno;
    $location = spotEntity('location', $location_id);
    amplifyCell($location);
    startPortlet('Attributes');
    printOpFormIntro('updateLocation');
    echo '<table border=0 align=center>';
    echo "<tr><td>&nbsp;</td><th class=tdright>Parent location:</th><td class=tdleft>";
    $locations = array();
    $locations[0] = '-- NOT SET --';
    foreach (listCells('location') as $id => $locationInfo) {
        $locations[$id] = $locationInfo['name'];
    }
    natcasesort($locations);
    printSelect($locations, array('name' => 'parent_id'), $location['parent_id']);
    echo "</td></tr>\n";
    echo "<tr><td>&nbsp;</td><th class=tdright>Name (required):</th><td class=tdleft><input type=text name=name value='{$location['name']}'></td></tr>\n";
    // optional attributes
    $values = getAttrValues($location_id);
    $num_attrs = count($values);
    echo "<input type=hidden name=num_attrs value={$num_attrs}>\n";
    $i = 0;
    foreach ($values as $record) {
        echo "<input type=hidden name={$i}_attr_id value={$record['id']}>";
        echo '<tr><td>';
        if (strlen($record['value'])) {
            echo "<a href='" . makeHrefProcess(array('op' => 'clearSticker', 'location_id' => $location_id, 'attr_id' => $record['id'])) . "'>";
            printImageHREF('clear', 'Clear value');
            echo '</a>';
        } else {
            echo '&nbsp;';
        }
        echo '</td>';
        echo "<th class=sticker>{$record['name']}:</th><td class=tdleft>";
        switch ($record['type']) {
            case 'uint':
            case 'float':
            case 'string':
                echo "<input type=text name={$i}_value value='{$record['value']}'>";
                break;
            case 'dict':
                $chapter = readChapter($record['chapter_id'], 'o');
                $chapter[0] = '-- NOT SET --';
                $chapter = cookOptgroups($chapter, 1562, $record['key']);
                printNiftySelect($chapter, array('name' => "{$i}_value"), $record['key']);
                break;
        }
        echo "</td></tr>\n";
        $i++;
    }
    echo "<tr><td>&nbsp;</td><th class=tdright>Has problems:</th><td class=tdleft><input type=checkbox name=has_problems";
    if ($location['has_problems'] == 'yes') {
        echo ' checked';
    }
    echo "></td></tr>\n";
    if (count($location['locations']) == 0 and count($location['rows']) == 0) {
        echo "<tr><td>&nbsp;</td><th class=tdright>Actions:</th><td class=tdleft>";
        echo "<a href='" . makeHrefProcess(array('op' => 'deleteLocation', 'location_id' => $location_id)) . "' onclick=\"javascript:return confirm('Are you sure you want to delete the location?')\">" . getImageHREF('destroy', 'Delete location') . "</a>";
        echo "&nbsp;</td></tr>\n";
    }
    echo "<tr><td colspan=3><b>Comment:</b><br><textarea name=comment rows=10 cols=80>{$location['comment']}</textarea></td></tr>";
    echo "<tr><td class=submit colspan=3>";
    printImageHREF('SAVE', 'Save changes', TRUE);
    echo "</td></tr>\n";
    echo '</form></table><br>';
    finishPortlet();
    startPortlet('History');
    renderObjectHistory($location_id);
    finishPortlet();
}
function renderPortletWattConsumption($info)
{
    $rackTotalWattage = 0;
    $rackData = spotEntity('rack', $info['id']);
    amplifyCell($rackData);
    $objectChildren = getEntityRelatives('children', 'object', $objectData['id']);
    foreach ($rackData['mountedObjects'] as $object) {
        $objectData = spotEntity('object', $object);
        amplifyCell($objectData);
        foreach (getAttrValues($objectData['id']) as $record) {
            if ($record['name'] == 'Wattage consumption') {
                $rackTotalWattage += $record['value'];
            }
        }
    }
    startPortlet('Wattage Consumption');
    echo "<table border=0 cellspacing=5 align='center'><tr>";
    echo "<td>The total for attribute Wattage consuption is:  <b>{$rackTotalWattage}</b></td>\n";
    echo "</tr></table>\n";
    finishPortlet();
}
예제 #11
0
function snmpgeneric_opcreate()
{
    $object_id = $_REQUEST['object_id'];
    $attr = getAttrValues($object_id);
    //	sg_var_dump_html($_REQUEST);
    //	sg_var_dump_html($attr);
    /* commitUpdateAttrValue ($object_id, $attr_id, $new_value); */
    if (isset($_POST['updateattr'])) {
        foreach ($_POST['updateattr'] as $attr_id => $value) {
            //	if(empty($attr[$attr_id]['value']))
            if (!empty($value)) {
                commitUpdateAttrValue($object_id, $attr_id, $value);
                showSuccess("Attribute " . $attr[$attr_id]['name'] . " set to {$value}");
            }
        }
        unset($attr_id);
        unset($value);
    }
    /* updateattr */
    /* create ports */
    if (isset($_POST['portcreate'])) {
        foreach ($_POST['portcreate'] as $if => $value) {
            $ifName = isset($_POST['ifName'][$if]) ? trim($_POST['ifName'][$if]) : '';
            $ifPhysAddress = isset($_POST['ifPhysAddress'][$if]) ? trim($_POST['ifPhysAddress'][$if]) : '';
            $ifAlias = isset($_POST['ifAlias'][$if]) ? trim($_POST['ifAlias'][$if]) : '';
            $ifDescr = isset($_POST['ifDescr'][$if]) ? trim($_POST['ifDescr'][$if]) : '';
            //$visible_label = (empty($ifAlias) ? '' : $ifAlias.'; ').$ifDescr;
            $visible_label = $ifAlias;
            if (empty($ifName)) {
                showError('Port without ifName ' . $_POST['porttypeid'][$if] . ', ' . $visible_label . ', ' . $ifPhysAddress);
            } else {
                commitAddPort($object_id, $ifName, $_POST['porttypeid'][$if], $visible_label, $ifPhysAddress);
                showSuccess('Port created ' . $ifName . ', ' . $_POST['porttypeid'][$if] . ', ' . $visible_label . ', ' . $ifPhysAddress);
            }
        }
        unset($if);
        unset($value);
    }
    /* portcreate */
    /* net create */
    if (isset($_POST['netcreate'])) {
        foreach ($_POST['netcreate'] as $id => $addrtype) {
            $range = $_POST['netprefix'][$id];
            $name = $_POST['netname'][$id];
            $is_reserved = isset($_POST['netreserve'][$id]);
            if ($addrtype == 'ipv4' || $addrtype == 'ipv4z') {
                createIPv4Prefix($range, $name, $is_reserved);
            } else {
                createIPv6Prefix($range, $name, $is_reserved);
            }
            showSuccess("{$range} {$name} created");
        }
        unset($id);
        unset($addrtype);
    }
    /* netcreate */
    /* allocate ipv6 adresses */
    if (isset($_POST['ipv6addrcreate'])) {
        foreach ($_POST['ipv6addrcreate'] as $ipaddr => $if) {
            bindIPv6ToObject(ip6_parse($ipaddr), $object_id, $_POST['ifName'][$if], 1);
            /* connected */
            showSuccess("{$ipaddr} allocated");
        }
        unset($ipaddr);
        unset($if);
    }
    /* allocate ip adresses */
    if (isset($_POST['ipaddrcreate'])) {
        foreach ($_POST['ipaddrcreate'] as $ipaddr => $if) {
            bindIPToObject(ip_parse($ipaddr), $object_id, $_POST['ifName'][$if], 1);
            /* connected */
            showSuccess("{$ipaddr} allocated");
        }
        unset($ipaddr);
        unset($if);
    }
    /* ipaddrecreate */
    /* update label */
    if (isset($_POST['updatelabel'])) {
        foreach ($_POST['updatelabel'] as $if => $port_id) {
            $ifAlias = isset($_POST['ifAlias'][$if]) ? trim($_POST['ifAlias'][$if]) : '';
            sg_commitUpdatePortLabel($object_id, $port_id, $ifAlias);
            $ifName = isset($_POST['ifName'][$if]) ? trim($_POST['ifName'][$if]) : '';
            showSuccess("label updated on {$ifName} to {$ifAlias}");
        }
        unset($if);
        unset($port_id);
    }
    /* updatemac */
    /* update mac addresses only */
    if (isset($_POST['updatemac'])) {
        foreach ($_POST['updatemac'] as $if => $port_id) {
            $ifPhysAddress = isset($_POST['ifPhysAddress'][$if]) ? trim($_POST['ifPhysAddress'][$if]) : '';
            sg_commitUpdatePortl2address($object_id, $port_id, $ifPhysAddress);
            $ifName = isset($_POST['ifName'][$if]) ? trim($_POST['ifName'][$if]) : '';
            showSuccess("l2address updated on {$ifName} to {$ifPhysAddress}");
        }
        unset($if);
        unset($port_id);
    }
    /* updatemac */
    /* update port type */
    if (isset($_POST['updateporttype'])) {
        foreach ($_POST['updateporttype'] as $if => $port_id) {
            $porttypeid = isset($_POST['porttypeid'][$if]) ? trim($_POST['porttypeid'][$if]) : '';
            sg_commitUpdatePortType($object_id, $port_id, $porttypeid);
            $ifName = isset($_POST['ifName'][$if]) ? trim($_POST['ifName'][$if]) : '';
            showSuccess("port type updated on {$ifName}");
        }
        unset($if);
        unset($port_id);
    }
    /* updateporttype */
}
예제 #12
0
파일: interface.php 프로젝트: xtha/salt
function renderExpirations()
{
    global $nextorder;
    $breakdown = array();
    $breakdown[21] = array(array('from' => -365, 'to' => 0, 'class' => 'has_problems_', 'title' => 'has expired within last year'), array('from' => 0, 'to' => 30, 'class' => 'row_', 'title' => 'expires within 30 days'), array('from' => 30, 'to' => 60, 'class' => 'row_', 'title' => 'expires within 60 days'), array('from' => 60, 'to' => 90, 'class' => 'row_', 'title' => 'expires within 90 days'));
    $breakdown[22] = $breakdown[21];
    $breakdown[24] = $breakdown[21];
    $attrmap = getAttrMap();
    foreach ($breakdown as $attr_id => $sections) {
        startPortlet($attrmap[$attr_id]['name']);
        foreach ($sections as $section) {
            $count = 1;
            $order = 'odd';
            $result = scanAttrRelativeDays($attr_id, $section['from'], $section['to']);
            echo '<table align=center width=60% border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
            echo "<caption>{$section['title']}</caption>\n";
            if (!count($result)) {
                echo "<tr><td colspan=4>(none)</td></tr></table><br>\n";
                continue;
            }
            echo '<tr valign=top><th align=center>Count</th><th align=center>Name</th>';
            echo "<th align=center>Asset Tag</th><th align=center>OEM S/N 1</th><th align=center>Date Warranty <br> Expires</th></tr>\n";
            foreach ($result as $row) {
                $date_value = datetimestrFromTimestamp($row['uint_value']);
                $object = spotEntity('object', $row['object_id']);
                $attributes = getAttrValues($object['id']);
                $oem_sn_1 = array_key_exists(1, $attributes) ? $attributes[1]['a_value'] : '&nbsp;';
                echo '<tr class=' . $section['class'] . $order . ' valign=top>';
                echo "<td>{$count}</td>";
                echo '<td>' . mkA($object['dname'], 'object', $object['id']) . '</td>';
                echo "<td>{$object['asset_no']}</td>";
                echo "<td>{$oem_sn_1}</td>";
                echo "<td>{$date_value}</td>";
                echo "</tr>\n";
                $order = $nextorder[$order];
                $count++;
            }
            echo "</table><br>\n";
        }
        finishPortlet();
    }
}
예제 #13
0
function setSwitchVLANs($object_id = 0, $setcmd)
{
    global $remote_username;
    $objectInfo = spotEntity('object', $object_id);
    $endpoints = findAllEndpoints($object_id, $objectInfo['name']);
    if (count($endpoints) == 0) {
        throw new RTGatewayError('no management address set');
    }
    if (count($endpoints) > 1) {
        throw new RTGatewayError('cannot pick management address');
    }
    $hwtype = $swtype = 'unknown';
    foreach (getAttrValues($object_id) as $record) {
        if ($record['name'] == 'SW type' && strlen($record['o_value'])) {
            $swtype = strtr(execGMarker($record['o_value']), ' ', '+');
        }
        if ($record['name'] == 'HW type' && strlen($record['o_value'])) {
            $hwtype = strtr(execGMarker($record['o_value']), ' ', '+');
        }
    }
    $endpoint = str_replace(' ', '+', $endpoints[0]);
    $data = queryGateway('switchvlans', array("connect {$endpoint} {$hwtype} {$swtype} {$remote_username}", $setcmd));
    // Finally we can parse the response into message array.
    foreach (explode(';', substr($data[1], strlen('OK!'))) as $text) {
        $message = 'gw: ' . substr($text, 2);
        if (strpos($text, 'I!') === 0) {
            showSuccess($message);
        } elseif (strpos($text, 'W!') === 0) {
            showWarning($message);
        } elseif (strpos($text, 'E!') === 0) {
            showError($message);
        } else {
            // All improperly formatted messages must be treated as error conditions.
            showError('unexpected line from gw: ' . $text);
        }
    }
}
예제 #14
0
function doSNMPmining($object_id, $snmpsetup)
{
    $objectInfo = spotEntity('object', $object_id);
    $objectInfo['attrs'] = getAttrValues($object_id);
    $endpoints = findAllEndpoints($object_id, $objectInfo['name']);
    if (count($endpoints) == 0) {
        return showFuncMessage(__FUNCTION__, 'ERR1');
    }
    // endpoint not found
    if (count($endpoints) > 1) {
        return showFuncMessage(__FUNCTION__, 'ERR2');
    }
    // can't pick an address
    switch ($objectInfo['objtype_id']) {
        case 7:
        case 8:
            $device = new RTSNMPDevice($endpoints[0], $snmpsetup);
            return doSwitchSNMPmining($objectInfo, $device);
        case 2:
            $device = new APCPowerSwitch($endpoints[0], $snmpsetup);
            return doPDUSNMPmining($objectInfo, $device);
    }
}
예제 #15
0
function handleNetworkStickerClear()
{
    global $sic, $pageno;
    assertUIntArg('attr_id');
    if (permitted(NULL, NULL, NULL, array(array('tag' => '$attr_' . $sic['attr_id'])))) {
        commitUpdateAttrForNetwork(spotEntity($pageno === 'ipv4net' ? 'ipv4net' : 'ipv6net', getBypassValue()), $sic['attr_id']);
        showSuccess("Attribute value cleared successfully");
    } else {
        $oldvalues = getAttrValues(getBypassValue());
        showError('Permission denied, "' . $oldvalues[$sic['attr_id']]['name'] . '" left unchanged');
    }
}
예제 #16
0
function getObjectTypeChangeOptions($object_id)
{
    $map = getAttrMap();
    $used = array();
    $ret = array();
    foreach (getAttrValues($object_id) as $attr) {
        if (!array_key_exists($attr['id'], $map)) {
            return array();
        }
        // inconsistent current data
        if ($attr['value'] != '') {
            $used[] = $attr;
        }
    }
    foreach (readChapter(CHAP_OBJTYPE, 'o') as $test_id => $text) {
        foreach ($used as $attr) {
            $app = $map[$attr['id']]['application'];
            if (NULL === ($appidx = scanArrayForItem($app, 'objtype_id', $test_id)) or $attr['type'] == 'dict' and $attr['chapter_id'] != $app[$appidx]['chapter_no']) {
                continue 2;
            }
            // next type ID
        }
        $ret[$test_id] = $text;
    }
    return $ret;
}
예제 #17
0
function linkmgmt_renderObjectLinks($object_id)
{
    $object = spotEntity('object', $object_id);
    $object['attr'] = getAttrValues($object_id);
    /* get ports */
    /* calls getObjectPortsAndLinks */
    amplifyCell($object);
    //$ports = getObjectPortsAndLinks($object_id);
    $ports = $object['ports'];
    /* reindex array so key starts at 0 */
    $ports = array_values($ports);
    /* URL param handling */
    if (isset($_GET['allports'])) {
        $allports = $_GET['allports'];
    } else {
        $allports = FALSE;
    }
    if (isset($_GET['allback'])) {
        $allback = $_GET['allback'];
    } else {
        $allback = FALSE;
    }
    echo '<table><tr>';
    if ($allports) {
        echo '<td width=200><a href="' . makeHref(portlist::urlparams('allports', '0', '0')) . '">Hide Ports without link</a></td>';
    } else {
        echo '<td width=200><a href="' . makeHref(portlist::urlparams('allports', '1', '0')) . '">Show All Ports</a></td>';
    }
    echo '<td width=200><span onclick=window.open("' . makeHrefProcess(portlist::urlparamsarray(array('op' => 'PortLinkDialog', 'linktype' => 'back', 'byname' => '1'))) . '","name","height=700,width=800,scrollbars=yes");><a>Link Object Ports by Name</a></span></td>';
    if ($allback) {
        echo '<td width=200><a href="' . makeHref(portlist::urlparams('allback', '0', '0')) . '">Collapse Backend Links on same Object</a></td>';
    } else {
        echo '<td width=200><a href="' . makeHref(portlist::urlparams('allback', '1', '0')) . '">Expand Backend Links on same Object</a></td>';
    }
    /* Graphviz map */
    echo '<td width=100><span onclick=window.open("' . makeHrefProcess(portlist::urlparamsarray(array('op' => 'map', 'usemap' => 1))) . '","name","height=800,width=800,scrollbars=yes");><a>Object Map</a></span></td>';
    /* cytoscape map */
    echo '<td width=100><span onclick=window.open("' . makeHrefProcess(portlist::urlparamsarray(array('op' => 'cytoscapemap'))) . '","name","height=800,width=800,scrollbars=yes");><a>Cytoscape Object Map</a></span></td>';
    /* Help */
    echo '<td width=200><span onclick=window.open("' . makeHrefProcess(portlist::urlparamsarray(array('op' => 'Help'))) . '","name","height=400,width=500");><a>Help</a></span></td>';
    if (isset($_REQUEST['hl_port_id'])) {
        $hl_port_id = $_REQUEST['hl_port_id'];
    } else {
        $hl_port_id = NULL;
    }
    echo '</tr></table>';
    echo '<br><br><table id=renderobjectlinks0>';
    /*  switch display order depending on backend links */
    $first = portlist::hasbackend($object_id);
    $rowcount = 0;
    foreach ($ports as $key => $port) {
        $lc = new lm_linkchain($port['id']);
        if ($allports || $lc->linkcount > 0) {
            if ($port['id'] == $hl_port_id) {
                $rowbgcolor = lm_linkchain::HL_PORT_BGCOLOR;
            } else {
                $rowbgcolor = $rowcount % 2 ? lm_linkchain::ALTERNATE_ROW_BGCOLOR : "#ffffff";
            }
            echo $lc->getchainlabeltrstart($rowbgcolor) . $lc->getchainrow($allback, $rowbgcolor) . "</tr>";
            $rowcount++;
        }
    }
    echo "</table>";
}
function copyLotOfObjects()
{
    global $dbxlink;
    $dbrollback = 0;
    if (!$dbxlink->beginTransaction()) {
        throw new RTDatabaseError("can not start transaction");
    }
    // do we need this ?
    $log = emptyLog();
    $taglist = isset($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
    assertUIntArg('global_type_id', TRUE);
    assertStringArg('namelist', TRUE);
    $global_type_id = $_REQUEST['global_type_id'];
    $source_object_id = $_REQUEST['object_id'];
    $source_object = spotEntity('object', $source_object_id);
    amplifyCell($source_object);
    // only call amplifyCell_object_Backend_Port if we have function linkmgmt_linkPorts from linkmgmt.php
    if (function_exists('amplifyCell_object_Backend_Port') && function_exists('linkmgmt_linkPorts')) {
        amplifyCell_object_Backend_Port($source_object);
    }
    if ($global_type_id == 0 or !strlen($_REQUEST['namelist'])) {
        // Log something reasonable with showError Here
        // We do not have names to copy our object to !
        // Pls check what makes $global_type_id == 0  an error
        $log = mergeLogs($log, oneLiner(186));
        return;
    }
    // The name extractor below was stolen from ophandlers.php:addMultiPorts()
    $names1 = explode("\n", $_REQUEST['namelist']);
    $names2 = array();
    foreach ($names1 as $line) {
        $parts = explode('\\r', $line);
        reset($parts);
        if (!strlen($parts[0])) {
            continue;
        } else {
            $names2[] = rtrim($parts[0]);
        }
    }
    foreach ($names2 as $name_or_csv) {
        $label = '';
        $asset_no = '';
        $object_name = '';
        $regexp = '/^\\"([^\\"]*)\\","([^\\"]*)\\","([^\\"]*)\\"/';
        $object_name_or_csv = htmlspecialchars_decode($name_or_csv, ENT_QUOTES);
        // error_log( "$regexp $object_name" );
        if (preg_match($regexp, $object_name_or_csv, $matches)) {
            $object_name = $matches[1];
            $label = $matches[2];
            $asset_no = $matches[3];
        } else {
            $object_name = $name_or_csv;
        }
        try {
            $object_id = commitAddObject($object_name, $label, $global_type_id, $asset_no, $taglist);
            if (!$object_id) {
                throw new RTDatabaseError("could not create {$object_name}");
            }
            $info = spotEntity('object', $object_id);
            amplifyCell($info);
            foreach ($source_object['ports'] as $source_port) {
                $update_port = 0;
                foreach ($info['ports'] as $new_port) {
                    if ($new_port['name'] == $source_port['name']) {
                        commitUpdatePort($object_id, $new_port['id'], $new_port['name'], $new_port['oif_id'], $source_port['label'], "");
                        $update_port = 1;
                    }
                }
                if ($update_port) {
                    true;
                } else {
                    commitAddPort($object_id, $source_port['name'], sprintf("%s-%s", $source_port['iif_id'], $source_port['oif_id']), $source_port['label'], "");
                }
            }
            // Copy Backendlinks only start if we ghave function linkmgmt_linkPorts from linkmgmt.php
            if (function_exists('amplifyCell_object_Backend_Port') && function_exists('linkmgmt_linkPorts')) {
                $info = spotEntity('object', $object_id);
                amplifyCell($info);
                amplifyCell_object_Backend_Port($info);
                /*	 showError( '<div align="left"><pre>\n===== Source Object ======\n\n' .
                				 		 varDumpToString ( $source_object ) .
                						'\n\n===== New Object ======\n\n' .
                						 varDumpToString ( $info )  .  '</pre></div>' );
                			*/
                $name_by_id = array();
                foreach ($info['BackendPorts'] as $new_be_port) {
                    $name_by_id[$new_be_port['name']] = $new_be_port['id'];
                }
                $linked_ports = array();
                foreach ($source_object['BackendPorts'] as $source_be_port) {
                    if ($source_be_port['object_id'] == $source_be_port['remote_object_id']) {
                        // We have a Port that has the own object as remote object we want to copy this type of Linko
                        // We have backend Links
                        $new_be_port_a = $name_by_id[$source_be_port['name']];
                        $new_be_port_b = $name_by_id[$source_be_port['remote_name']];
                        if ($new_be_port_a && $new_be_port_b && !array_key_exists($new_be_port_a, $linked_ports) && !array_key_exists($new_be_port_b, $linked_ports)) {
                            // error_log ( sprintf ('new_be_port_a %s // new_be_port_b %s // cableid %s', $new_be_port_a  , $new_be_port_b, $source_be_port['cableid'] ));
                            $ret_val = linkmgmt_linkPorts($new_be_port_a, $new_be_port_b, 'back', $source_be_port['cableid']);
                            // error_log ( sprintf (' linkmgmt_linkPorts ret val: "%s" ', $ret_val)) ;
                            if ($ret_val) {
                                throw new RTDatabaseError("could not copy Backend Links for {$object_name} because: {$ret_val}");
                            } else {
                                $linked_ports[$new_be_port_a] = True;
                                $linked_ports[$new_be_port_b] = True;
                            }
                        }
                    }
                }
            }
            // Copy attributes
            foreach (getAttrValues($source_object_id) as $record) {
                $value = $record['value'];
                switch ($record['type']) {
                    case 'uint':
                    case 'float':
                    case 'string':
                        $value = $record['value'];
                        break;
                    case 'dict':
                        $value = $record['key'];
                        break;
                    default:
                }
                if (permitted(NULL, NULL, NULL, array(array('tag' => '$attr_' . $record['id'])))) {
                    if (empty($value)) {
                        commitUpdateAttrValue($object_id, $record['id']);
                    } else {
                        commitUpdateAttrValue($object_id, $record['id'], $value);
                    }
                } else {
                    showError('Permission denied, "' . $record['name'] . '" can not be set');
                }
            }
            //$log = mergeLogs ($log, oneLiner (5, array ('<a href="' .
            //	makeHref (array ('page' => 'object', 'tab' => 'default', 'object_id' => $object_id)) .
            //	'">' . $info['dname'] . '</a>'))
            //);
            showSuccess(sprintf("Copied Object %s ; new Object: %s", $source_object['name'], formatPortLink($object_id, $info['dname'], 1, '', '')));
        } catch (RTDatabaseError $e) {
            error_log("rolling back DB");
            $dbrollback = 1;
            $dbxlink->rollBack();
            $log = mergeLogs($log, oneLiner(147, array($object_name)));
            throw new RTDatabaseError($e->getMessage() . sprintf(' (%s)', $name_or_csv));
        }
    }
    if (!$dbrollback) {
        $dbxlink->commit();
    }
    // return buildWideRedirectURL ($log);
}
예제 #19
0
function doSNMPmining($object_id, $snmpsetup)
{
    global $objectInfo;
    $objectInfo = spotEntity('object', $object_id);
    $objectInfo['attrs'] = getAttrValues($object_id);
    $endpoints = findAllEndpoints($object_id, $objectInfo['name']);
    if (count($endpoints) == 0) {
        showFuncMessage(__FUNCTION__, 'ERR1');
        // endpoint not found
        return;
    }
    if (count($endpoints) > 1) {
        showFuncMessage(__FUNCTION__, 'ERR2');
        // can't pick an address
        return;
    }
    switch ($objectInfo['objtype_id']) {
        case 7:
            // Router
        // Router
        case 8:
            // Network switch
        // Network switch
        case 965:
            // Wireless
        // Wireless
        case 1503:
            // Network chassis
            $device = new RTSNMPDevice($endpoints[0], $snmpsetup);
            return doGenericSNMPmining($device);
        case 2:
            $device = new APCPowerSwitch($endpoints[0], $snmpsetup);
            return doPDUSNMPmining($device);
    }
}
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>';
    }
}
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>';
}
예제 #22
0
function renderSearchResults($terms, $summary)
{
    // calculate the number of found objects
    $nhits = 0;
    foreach ($summary as $realm => $list) {
        $nhits += count($list);
    }
    if ($nhits == 0) {
        echo "<center><h2>Nothing found for '{$terms}'</h2></center>";
        return;
    } elseif ($nhits == 1) {
        foreach ($summary as $realm => $record) {
            if (is_array($record)) {
                $record = array_shift($record);
            }
            break;
        }
        $url = buildSearchRedirectURL($realm, $record);
        if (isset($url)) {
            redirectUser($url);
        }
    }
    global $nextorder;
    $order = 'odd';
    echo "<center><h2>{$nhits} result(s) found for '{$terms}'</h2></center>";
    foreach ($summary as $where => $what) {
        switch ($where) {
            case 'object':
                startPortlet("<a href='index.php?page=depot'>Objects</a>");
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                echo '<tr><th>what</th><th>why</th></tr>';
                foreach ($what as $obj) {
                    echo "<tr class=row_{$order} valign=top><td>";
                    $object = spotEntity('object', $obj['id']);
                    renderCell($object);
                    echo "</td><td class=tdleft>";
                    if (isset($obj['by_attr'])) {
                        // only explain non-obvious reasons for listing
                        echo '<ul>';
                        foreach ($obj['by_attr'] as $attr_name) {
                            if ($attr_name != 'name') {
                                echo "<li>{$attr_name} matched</li>";
                            }
                        }
                        echo '</ul>';
                    }
                    if (isset($obj['by_sticker'])) {
                        echo '<table>';
                        $aval = getAttrValues($obj['id']);
                        foreach ($obj['by_sticker'] as $attr_id) {
                            $record = $aval[$attr_id];
                            echo "<tr><th width='50%' class=sticker>{$record['name']}:</th>";
                            echo "<td class=sticker>" . formatAttributeValue($record) . "</td></tr>";
                        }
                        echo '</table>';
                    }
                    if (isset($obj['by_port'])) {
                        echo '<table>';
                        amplifyCell($object);
                        foreach ($obj['by_port'] as $port_id => $text) {
                            foreach ($object['ports'] as $port) {
                                if ($port['id'] == $port_id) {
                                    $port_href = '<a href="' . makeHref(array('page' => 'object', 'object_id' => $object['id'], 'hl_port_id' => $port_id)) . '">port ' . $port['name'] . '</a>';
                                    echo "<tr><td>{$port_href}:</td>";
                                    echo "<td class=tdleft>{$text}</td></tr>";
                                    break;
                                    // next reason
                                }
                            }
                        }
                        echo '</table>';
                    }
                    if (isset($obj['by_iface'])) {
                        echo '<ul>';
                        foreach ($obj['by_iface'] as $ifname) {
                            echo "<li>interface {$ifname}</li>";
                        }
                        echo '</ul>';
                    }
                    if (isset($obj['by_nat'])) {
                        echo '<ul>';
                        foreach ($obj['by_nat'] as $comment) {
                            echo "<li>NAT rule: {$comment}</li>";
                        }
                        echo '</ul>';
                    }
                    if (isset($obj['by_cableid'])) {
                        echo '<ul>';
                        foreach ($obj['by_cableid'] as $cableid) {
                            echo "<li>link cable ID: {$cableid}</li>";
                        }
                        echo '</ul>';
                    }
                    echo "</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'ipv4net':
            case 'ipv6net':
                if ($where == 'ipv4net') {
                    startPortlet("<a href='index.php?page=ipv4space'>IPv4 networks</a>");
                } elseif ($where == 'ipv6net') {
                    startPortlet("<a href='index.php?page=ipv6space'>IPv6 networks</a>");
                }
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                foreach ($what as $cell) {
                    echo "<tr class=row_{$order} valign=top><td>";
                    renderCell($cell);
                    echo "</td></tr>\n";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'ipv4addressbydescr':
            case 'ipv6addressbydescr':
                if ($where == 'ipv4addressbydescr') {
                    startPortlet('IPv4 addresses');
                } elseif ($where == 'ipv6addressbydescr') {
                    startPortlet('IPv6 addresses');
                }
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                // FIXME: address, parent network, routers (if extended view is enabled)
                echo '<tr><th>Address</th><th>Description</th><th>Comment</th></tr>';
                foreach ($what as $addr) {
                    echo "<tr class=row_{$order}><td class=tdleft>";
                    $fmt = ip_format($addr['ip']);
                    $parentnet = getIPAddressNetworkId($addr['ip']);
                    if ($parentnet !== NULL) {
                        echo "<a href='" . makeHref(array('page' => strlen($addr['ip']) == 16 ? 'ipv6net' : 'ipv4net', 'id' => $parentnet, 'tab' => 'default', 'hl_ip' => $fmt)) . "'>{$fmt}</a></td>";
                    } else {
                        echo "<a href='index.php?page=ipaddress&tab=default&ip={$fmt}'>{$fmt}</a></td>";
                    }
                    echo "<td class=tdleft>{$addr['name']}</td><td>{$addr['comment']}</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'ipv4rspool':
                startPortlet("<a href='index.php?page=ipv4slb&tab=rspools'>RS pools</a>");
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                foreach ($what as $cell) {
                    echo "<tr class=row_{$order}><td class=tdleft>";
                    renderCell($cell);
                    echo "</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'ipvs':
                startPortlet("<a href='index.php?page=ipv4slb&tab=vs'>VS groups</a>");
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                foreach ($what as $cell) {
                    echo "<tr class=row_{$order}><td class=tdleft>";
                    renderCell($cell);
                    echo "</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'ipv4vs':
                startPortlet("<a href='index.php?page=ipv4slb&tab=default'>Virtual services</a>");
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                foreach ($what as $cell) {
                    echo "<tr class=row_{$order}><td class=tdleft>";
                    renderCell($cell);
                    echo "</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'user':
                startPortlet("<a href='index.php?page=userlist'>Users</a>");
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                foreach ($what as $item) {
                    echo "<tr class=row_{$order}><td class=tdleft>";
                    renderCell($item);
                    echo "</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'file':
                startPortlet("<a href='index.php?page=files'>Files</a>");
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                foreach ($what as $cell) {
                    echo "<tr class=row_{$order}><td class=tdleft>";
                    renderCell($cell);
                    echo "</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'rack':
                startPortlet("<a href='index.php?page=rackspace'>Racks</a>");
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                foreach ($what as $cell) {
                    echo "<tr class=row_{$order}><td class=tdleft>";
                    renderCell($cell);
                    echo "</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'row':
                startPortlet("<a href='index.php?page=rackspace'>Rack rows</a>");
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                foreach ($what as $cell) {
                    echo "<tr class=row_{$order}><td class=tdleft>";
                    echo mkCellA($cell);
                    echo "</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'location':
                startPortlet("<a href='index.php?page=rackspace'>Locations</a>");
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                foreach ($what as $cell) {
                    echo "<tr class=row_{$order}><td class=tdleft>";
                    renderCell($cell);
                    echo "</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'vlan':
                startPortlet("<a href='index.php?page=8021q'>VLANs</a>");
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                foreach ($what as $vlan) {
                    echo "<tr class=row_{$order}><td class=tdleft>";
                    echo formatVLANAsHyperlink(getVlanRow($vlan['id'])) . "</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            default:
                // you can use that in your plugins to add some non-standard search results
                startPortlet($where);
                echo $what;
                finishPortlet();
        }
    }
}
예제 #23
0
function generateEntityAutoTags($cell)
{
    $ret = array();
    if (!array_key_exists('realm', $cell)) {
        throw new InvalidArgException('cell', '(array)', 'malformed structure');
    }
    switch ($cell['realm']) {
        case 'location':
            $ret[] = array('tag' => '$locationid_' . $cell['id']);
            $ret[] = array('tag' => '$any_location');
            break;
        case 'row':
            $ret[] = array('tag' => '$rowid_' . $cell['id']);
            $ret[] = array('tag' => '$any_row');
            break;
        case 'rack':
            $ret[] = array('tag' => '$rackid_' . $cell['id']);
            $ret[] = array('tag' => '$any_rack');
            break;
        case 'object':
            $ret[] = array('tag' => '$id_' . $cell['id']);
            $ret[] = array('tag' => '$typeid_' . $cell['objtype_id']);
            $ret[] = array('tag' => '$any_object');
            if ($cell['name'] == '') {
                $ret[] = array('tag' => '$nameless');
            }
            if (validTagName('$cn_' . $cell['name'], TRUE)) {
                $ret[] = array('tag' => '$cn_' . $cell['name']);
            }
            if (!strlen($cell['rack_id'])) {
                $ret[] = array('tag' => '$unmounted');
            }
            if (!$cell['nports']) {
                $ret[] = array('tag' => '$portless');
            }
            if ($cell['asset_no'] == '') {
                $ret[] = array('tag' => '$no_asset_tag');
            }
            if (isset($cell['8021q_domain_id'])) {
                $ret[] = array('tag' => '$runs_8021Q');
                $ret[] = array('tag' => '$8021Q_domain_' . $cell['8021q_domain_id']);
                if (isset($cell['8021q_template_id'])) {
                    $ret[] = array('tag' => '$8021Q_tpl_' . $cell['8021q_template_id']);
                }
            }
            # dictionary attribute autotags '$attr_X_Y'
            $attrs = getAttrValues($cell['id']);
            foreach ($attrs as $attr_id => $attr_record) {
                if (isset($attr_record['key'])) {
                    $ret[] = array('tag' => "\$attr_{$attr_id}_{$attr_record['key']}");
                }
            }
            break;
        case 'ipv4net':
            // v4-only rules
            $ret[] = array('tag' => '$ip4net-' . str_replace('.', '-', $cell['ip']) . '-' . $cell['mask']);
        case 'ipv6net':
            // common (v4 & v6) rules
            $ver = $cell['realm'] == 'ipv4net' ? 4 : 6;
            $ret[] = array('tag' => "\$ip{$ver}netid_" . $cell['id']);
            $ret[] = array('tag' => "\$any_ip{$ver}net");
            $ret[] = array('tag' => '$any_net');
            $ret[] = array('tag' => '$masklen_eq_' . $cell['mask']);
            if ($cell['vlanc']) {
                $ret[] = array('tag' => '$runs_8021Q');
            }
            foreach ($cell['8021q'] as $vlan_info) {
                $ret[] = array('tag' => '$vlan_' . $vlan_info['vlan_id']);
            }
            foreach (array_keys($cell['spare_ranges']) as $mask) {
                $ret[] = array('tag' => '$spare_' . $mask);
            }
            if ($cell['kidc'] > 0) {
                $ret[] = array('tag' => '$aggregate');
            }
            break;
        case 'ipv4vs':
            $ret[] = array('tag' => '$ipvsid_' . $cell['id']);
            if (strlen($cell['vip_bin']) == 16) {
                $ret[] = array('tag' => '$any_ipv6vs');
            } else {
                $ret[] = array('tag' => '$any_ipv4vs');
            }
            $ret[] = array('tag' => '$any_vs');
            if ($cell['refcnt'] == 0) {
                $ret[] = array('tag' => '$unused');
            }
            $ret[] = array('tag' => '$type_' . strtolower($cell['proto']));
            // $type_tcp, $type_udp or $type_mark
            break;
        case 'ipv4rspool':
            $ret[] = array('tag' => '$ipv4rspid_' . $cell['id']);
            $ret[] = array('tag' => '$any_ipv4rsp');
            $ret[] = array('tag' => '$any_rsp');
            if ($cell['refcnt'] == 0) {
                $ret[] = array('tag' => '$unused');
            }
            break;
        case 'user':
            # {$username_XXX} autotag is generated always, but {$userid_XXX}
            # appears only for accounts, which exist in local database.
            $ret[] = array('tag' => '$username_' . $cell['user_name']);
            if (isset($cell['user_id'])) {
                $ret[] = array('tag' => '$userid_' . $cell['user_id']);
            }
            break;
        case 'file':
            $ret[] = array('tag' => '$fileid_' . $cell['id']);
            $ret[] = array('tag' => '$any_file');
            break;
        case 'vst':
            $ret[] = array('tag' => '$vstid_' . $cell['id']);
            $ret[] = array('tag' => '$any_vst');
            break;
        default:
            throw new InvalidArgException('cell', '(array)', 'this input does not belong here');
            break;
    }
    # {$tagless} doesn't apply to users
    switch ($cell['realm']) {
        case 'rack':
        case 'object':
        case 'ipv4net':
        case 'ipv6net':
        case 'ipv4vs':
        case 'ipv4rspool':
        case 'file':
        case 'vst':
            if (!count($cell['etags'])) {
                $ret[] = array('tag' => '$untagged');
            }
            break;
        default:
            break;
    }
    return $ret;
}
예제 #24
0
function localtrigger_DellWarranty()
{
    assertUIntArg('object_id', __FUNCTION__);
    $object = spotEntity('object', $_REQUEST['object_id']);
    $record = getAttrValues($object['id'], TRUE);
    if ($object['objtype_id'] == 4 && strstr($record[2][value], "Dell")) {
        return 1;
    } else {
        return '';
    }
}
예제 #25
0
파일: ophandlers.php 프로젝트: xtha/salt
function cleanupUCS()
{
    global $ucsproductmap;
    $oinfo = spotEntity('object', getBypassValue());
    $contents = getObjectContentsList($oinfo['id']);
    $clear = TRUE;
    foreach ($contents as $item_id) {
        $o = spotEntity('object', $item_id);
        $attrs = getAttrValues($item_id);
        # use HW type to decide if the object was produced by autoPopulateUCS()
        if (!array_key_exists(2, $attrs) or !in_array($attrs[2]['key'], $ucsproductmap)) {
            showWarning('Contained object ' . mkA($o['dname'], 'object', $item_id) . ' is not an automatic UCS object');
            $clear = FALSE;
        }
    }
    if (!$clear) {
        showNotice('nothing was deleted');
        return;
    }
    $done = 0;
    foreach ($contents as $item_id) {
        commitDeleteObject($item_id);
        $done++;
    }
    showSuccess("Removed {$done} items from UCS Domain '{$oinfo['name']}'");
}
예제 #26
0
파일: server-report.php 프로젝트: xtha/salt
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>';
}