Ejemplo n.º 1
0
function snmpgeneric_snmpconfig($object_id)
{
    $object = spotEntity('object', $object_id);
    //$object['attr'] = getAttrValues($object_id);
    $endpoints = findAllEndpoints($object_id, $object['name']);
    addJS('function showsnmpv3(element) {
				var style;
				if(element.value != \'v3\') {
					style = \'none\';
					document.getElementById(\'snmp_community_label\').style.display=\'\';
				} else {
					style = \'\';
					document.getElementById(\'snmp_community_label\').style.display=\'none\';
				}

				var elements = document.getElementsByName(\'snmpv3\');
				for(var i=0;i<elements.length;i++) {
					elements[i].style.display=style;
				}
			};', TRUE);
    addJS('function shownewobject(element) {
				var style;

				if(element.checked) {
					style = \'\';
				} else {
					style = \'none\';
				}

				var elements = document.getElementsByName(\'newobject\');
				for(var i=0;i<elements.length;i++) {
					elements[i].style.display=style;
				}
			};', TRUE);
    addJS('function checkInput() {
				var host = document.getElementById(\'host\');

				if(host.value == "-1") {
					var newvalue = prompt("Enter Hostname or IP Address","");
					if(newvalue != "") {
						host.options[host.options.length] = new Option(newvalue, newvalue);
						host.value = newvalue;
					}
				}

				if(host.value != "-1" && host.value != "")
					return true;
				else
					return false;
			};', TRUE);
    echo '<body onload="document.getElementById(\'submitbutton\').focus(); showsnmpv3(document.getElementById(\'snmpversion\')); shownewobject(document.getElementById(\'asnewobject\'));">';
    foreach ($endpoints as $key => $value) {
        $endpoints[$value] = $value;
        unset($endpoints[$key]);
    }
    unset($key);
    unset($value);
    foreach (getObjectIPv4Allocations($object_id) as $ip => $value) {
        $ip = ip_format($ip);
        if (!in_array($ip, $endpoints)) {
            $endpoints[$ip] = $ip;
        }
    }
    unset($ip);
    unset($value);
    foreach (getObjectIPv6Allocations($object_id) as $value) {
        $ip = ip_format(ip_parse($value['addrinfo']['ip']));
        if (!in_array($ip, $endpoints)) {
            $endpoints[$ip] = $ip;
        }
    }
    unset($value);
    /* ask for ip/host name on submit see js checkInput() */
    $endpoints['-1'] = 'ask me';
    // saved snmp settings
    $snmpstr = strtok($object['comment'], "\n\r");
    $snmpstrarray = explode(':', $snmpstr);
    if ($snmpstrarray[0] == "SNMP") {
        /* keep it compatible with older version */
        switch ($snmpstrarray[2]) {
            case "1":
                $snmpstrarray[2] = 'v1';
                break;
            case "2":
            case "v2C":
                $snmpstrarray[2] = 'v2c';
                break;
            case "3":
                $snmpstrarray[2] = 'v3';
                break;
        }
        $snmpnames = array('SNMP', 'host', 'version', 'community');
        if ($snmpstrarray[2] == "v3") {
            $snmpnames = array_merge($snmpnames, array('sec_level', 'auth_protocol', 'auth_passphrase', 'priv_protocol', 'priv_passphrase'));
        }
        $snmpvalues = array();
        foreach ($snmpnames as $key => $value) {
            if (isset($snmpstrarray[$key])) {
                switch ($key) {
                    case 6:
                    case 8:
                        $snmpvalues[$value] = base64_decode($snmpstrarray[$key]);
                        break;
                    default:
                        $snmpvalues[$value] = $snmpstrarray[$key];
                }
            }
        }
        unset($snmpvalues['SNMP']);
        $snmpconfig = $snmpvalues;
    } else {
        $snmpconfig = array();
    }
    $snmpconfig += $_POST;
    if (!isset($snmpconfig['host'])) {
        $snmpconfig['host'] = -1;
        /* try to find first FQDN or IP */
        foreach ($endpoints as $value) {
            if (preg_match('/^[^ .]+(\\.[^ .]+)+\\.?/', $value)) {
                $snmpconfig['host'] = $value;
                break;
            }
        }
        unset($value);
    }
    //	sg_var_dump_html($endpoints);
    if (!isset($snmpconfig['version'])) {
        $snmpconfig['version'] = mySNMP::SNMP_VERSION;
    }
    if (!isset($snmpconfig['community'])) {
        $snmpconfig['community'] = getConfigVar('DEFAULT_SNMP_COMMUNITY');
    }
    if (empty($snmpconfig['community'])) {
        $snmpconfig['community'] = mySNMP::SNMP_COMMUNITY;
    }
    if (!isset($snmpconfig['sec_level'])) {
        $snmpconfig['sec_level'] = NULL;
    }
    if (!isset($snmpconfig['auth_protocol'])) {
        $snmpconfig['auth_protocol'] = NULL;
    }
    if (!isset($snmpconfig['auth_passphrase'])) {
        $snmpconfig['auth_passphrase'] = NULL;
    }
    if (!isset($snmpconfig['priv_protocol'])) {
        $snmpconfig['priv_protocol'] = NULL;
    }
    if (!isset($snmpconfig['priv_passphrase'])) {
        $snmpconfig['priv_passphrase'] = NULL;
    }
    if (!isset($snmpconfig['asnewobject'])) {
        $snmpconfig['asnewobject'] = NULL;
    }
    if (!isset($snmpconfig['object_type_id'])) {
        $snmpconfig['object_type_id'] = '8';
    }
    if (!isset($snmpconfig['object_name'])) {
        $snmpconfig['object_name'] = NULL;
    }
    if (!isset($snmpconfig['object_label'])) {
        $snmpconfig['object_label'] = NULL;
    }
    if (!isset($snmpconfig['object_asset_no'])) {
        $snmpconfig['object_asset_no'] = NULL;
    }
    if (!isset($snmpconfig['save'])) {
        $snmpconfig['save'] = true;
    }
    //	sg_var_dump_html($snmpconfig);
    //	$snmpv3displaystyle = ($snmpconfig['version'] == "3" ? "style=\"\"" : "style=\"display:none;\"");
    echo '<h1 align=center>SNMP Config</h1>';
    echo '<form method=post name="snmpconfig" onsubmit="return checkInput()" action=' . $_SERVER['REQUEST_URI'] . ' />';
    echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>
	<tr><th class=tdright>Host:</th><td>';
    //if($snmpconfig['asnewobject'] == '1' )
    if ($snmpconfig['host'] != '-1' and !isset($endpoints[$snmpconfig['host']])) {
        $endpoints[$snmpconfig['host']] = $snmpconfig['host'];
    }
    echo getSelect($endpoints, array('id' => 'host', 'name' => 'host'), $snmpconfig['host'], FALSE);
    echo '</td></tr>
	<tr>
                <th class=tdright><label for=snmpversion>Version:</label></th>
                <td class=tdleft>';
    echo getSelect(array("v1" => 'v1', "v2c" => 'v2c', "v3" => 'v3'), array('name' => 'version', 'id' => 'snmpversion', 'onchange' => 'showsnmpv3(this)'), $snmpconfig['version'], FALSE);
    echo '</td>
        </tr>
        <tr>
                <th id="snmp_community_label" class=tdright><label for=community>Community:</label></th>
                <th name="snmpv3" style="display:none;" class=tdright><label for=community>Security Name:</label></th>
                <td class=tdleft><input type=text name=community value=' . $snmpconfig['community'] . ' ></td>
        </tr>
        <tr name="snmpv3" style="display:none;">
		<th></th>
        </tr>
        <tr name="snmpv3" style="display:none;">
                <th class=tdright><label">Security Level:</label></th>
                <td class=tdleft>';
    echo getSelect(array('noAuthNoPriv' => 'no Auth and no Priv', 'authNoPriv' => 'auth without Priv', 'authPriv' => 'auth with Priv'), array('name' => 'sec_level'), $snmpconfig['sec_level'], FALSE);
    echo '</td></tr>
        <tr name="snmpv3" style="display:none;">
                <th class=tdright><label>Auth Type:</label></th>
                <td class=tdleft>
                <input name=auth_protocol type=radio value=MD5 ' . ($snmpconfig['auth_protocol'] == 'MD5' ? ' checked="checked"' : '') . '/><label>MD5</label>
                <input name=auth_protocol type=radio value=SHA ' . ($snmpconfig['auth_protocol'] == 'SHA' ? ' checked="checked"' : '') . '/><label>SHA</label>
                </td>
        </tr>
        <tr name="snmpv3" style="display:none;">
                <th class=tdright><label>Auth Key:</label></th>
                <td class=tdleft><input type=password id=auth_passphrase name=auth_passphrase value="' . $snmpconfig['auth_passphrase'] . '"></td>
        </tr>
        <tr name="snmpv3" style="display:none;">
                <th class=tdright><label>Priv Type:</label></th>
                <td class=tdleft>
                <input name=priv_protocol type=radio value=DES ' . ($snmpconfig['priv_protocol'] == 'DES' ? ' checked="checked"' : '') . '/><label>DES</label>
                <input name=priv_protocol type=radio value=AES ' . ($snmpconfig['priv_protocol'] == 'AES' ? ' checked="checked"' : '') . '/><label>AES</label>
                </td>
        </tr>
        <tr name="snmpv3" style="display:none;">
                <th class=tdright><label>Priv Key</label></th>
                <td class=tdleft><input type=password name=priv_passphrase value="' . $snmpconfig['priv_passphrase'] . '"></td>
        </tr>
	</tr>

	<tr>
		<th></th>
		<td class=tdleft>
		<input name=asnewobject id=asnewobject type=checkbox value=1 onchange="shownewobject(this)"' . ($snmpconfig['asnewobject'] == '1' ? ' checked="checked"' : '') . '>
		<label>Create as new object</label></td>
	</tr>';
    //	$newobjectdisplaystyle = ($snmpconfig['asnewobject'] == '1' ? "" : "style=\"display:none;\"");
    echo '<tr name="newobject" style="display:none;">
	<th class=tdright>Type:</th><td class=tdleft>';
    $typelist = withoutLocationTypes(readChapter(CHAP_OBJTYPE, 'o'));
    $typelist = cookOptgroups($typelist);
    printNiftySelect($typelist, array('name' => "object_type_id"), $snmpconfig['object_type_id']);
    echo '</td></tr>

	<tr name="newobject" style="display:none;">
	<th class=tdright>Common name:</th><td class=tdleft><input type=text name=object_name value=' . $snmpconfig['object_name'] . '></td></tr>
	<tr name="newobject" style="display:none;">
	<th class=tdright>Visible label:</th><td class=tdleft><input type=text name=object_label value=' . $snmpconfig['object_label'] . '></td></tr>
	<tr name="newobject" style="display:none;">
	<th class=tdright>Asset tag:</th><td class=tdleft><input type=text name=object_asset_no value=' . $snmpconfig['object_asset_no'] . '></td></tr>

	<tr>
		<th></th>
		<td class=tdleft>
		<input name=save id=save type=checkbox value=1' . ($snmpconfig['save'] == '1' ? ' checked="checked"' : '') . '>
		<label>Save SNMP settings for object</label></td>
	</tr>
	<td colspan=2>

        <input type=hidden name=snmpconfig value=1>
	<input type=submit id="submitbutton" tabindex="1" value="Show List"></td></tr>

        </table></form>';
}
Ejemplo n.º 2
0
Archivo: api.php Proyecto: xtha/salt
     //    UI equivalent: /index.php?page=chapter&module=redirect&op=del&dict_key=50228&tab=edit&chapter_no=10007
     //    UI handler: tableHandler()
 // delete an entry from a chapter
 //    UI equivalent: /index.php?page=chapter&module=redirect&op=del&dict_key=50228&tab=edit&chapter_no=10007
 //    UI handler: tableHandler()
 case 'delete_chapter_entry':
     require_once 'inc/init.php';
     assertUIntArg('chapter_no', TRUE);
     assertStringArg('dict_value', TRUE);
     // make sure the chapter exists
     $chapters = getChapterList();
     if (!isset($chapters[$_REQUEST['chapter_no']])) {
         throw new InvalidArgException('chapter_no', $_REQUEST['chapter_no'], "invalid argument: no such chapter");
     }
     // make sure the entry exists in this chapter
     $words = readChapter($_REQUEST['chapter_no'], 'o');
     if (!in_array($_REQUEST['dict_value'], $words)) {
         throw new InvalidArgException('dict_value', $_REQUEST['dict_value'], "invalid argument: no such value in chapter ID " . $_REQUEST['chapter_no']);
     }
     usePreparedDeleteBlade('Dictionary', array('chapter_id' => $_REQUEST['chapter_no'], 'dict_value' => $_REQUEST['dict_value']));
     sendAPIResponse(array(), array('message' => 'dictionary entry deleted successfully', 'chapter_no' => $_REQUEST['chapter_no'], 'dict_value' => $_REQUEST['dict_value']));
     break;
     // perform a generic search
     //    UI equivalent: /index.php?page=search
     //    UI handler: searchEntitiesByText()
 // perform a generic search
 //    UI equivalent: /index.php?page=search
 //    UI handler: searchEntitiesByText()
 case 'search':
     require_once 'inc/init.php';
     assertStringArg('term', TRUE);
Ejemplo n.º 3
0
 function printNewItemTR($attrMap)
 {
     printOpFormIntro('add');
     echo '<tr><td colspan=2 class=tdleft>';
     echo '<select name=attr_id tabindex=100>';
     $shortType['uint'] = 'U';
     $shortType['float'] = 'F';
     $shortType['string'] = 'S';
     $shortType['dict'] = 'D';
     $shortType['date'] = 'T';
     foreach ($attrMap as $attr) {
         echo "<option value={$attr['id']}>[" . $shortType[$attr['type']] . "] {$attr['name']}</option>";
     }
     echo "</select></td><td class=tdleft>";
     printImageHREF('add', '', TRUE);
     echo ' ';
     $objtypes = readChapter(CHAP_OBJTYPE, 'o');
     printNiftySelect(cookOptgroups($objtypes), array('name' => 'objtype_id', 'tabindex' => 101));
     echo ' <select name=chapter_no tabindex=102><option value=0>-- dictionary chapter for [D] attributes --</option>';
     foreach (getChapterList() as $chapter) {
         if ($chapter['sticky'] != 'yes') {
             echo "<option value='{$chapter['id']}'>{$chapter['name']}</option>";
         }
     }
     echo '</select></td></tr></form>';
 }
Ejemplo n.º 4
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";
    echo "<tr><td>&nbsp;</td><th class=tdright>Tags:</th><td class=tdleft>";
    printTagsPicker();
    echo "</td></tr>\n";
    // optional attributes
    $values = getAttrValuesSorted($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 getOpLink(array('op' => 'clearSticker', 'attr_id' => $record['id']), '', 'clear', 'Clear value', 'need-confirmation');
        } 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 getOpLink(array('op' => 'deleteLocation'), '', 'destroy', 'Delete location', 'need-confirmation');
        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();
}
Ejemplo n.º 5
0
 function printNewitemTR()
 {
     printOpFormIntro('add');
     echo '<tr><th class=tdleft>';
     printImageHREF('add', 'add pair', TRUE);
     echo '</th><th class=tdleft>';
     printSelect(getPortIIFOptions(), array('name' => 'iif_id'));
     echo '</th><th class=tdleft>';
     printSelect(readChapter(CHAP_PORTTYPE), array('name' => 'oif_id'));
     echo '</th></tr></form>';
 }
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>';
    }
}
Ejemplo n.º 7
0
function renderNetworkEditAttrs()
{
    global $pageno, $netobject_type_id;
    $network = spotEntity($pageno === 'ipv4net' ? 'ipv4net' : 'ipv6net', getBypassValue());
    $values = getAttrValuesForNetwork($network);
    echo '<p>';
    startPortlet("Attributes");
    printOpFormIntro('updateAttrs');
    // optional attributes
    echo '<table border=0 cellspacing=0 cellpadding=3 align=center>';
    $suggest_records = array();
    if (count($values) > 0) {
        $i = 0;
        foreach ($values as $record) {
            if (!permitted(NULL, NULL, NULL, array(array('tag' => '$attr_' . $record['id']), array('tag' => '$any_op')))) {
                continue;
            }
            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', 'id' => $network['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':
                    $suggest_records = array();
                    $chapter = readChapter($record['chapter_id'], 'o');
                    foreach ($chapter as $id => $value) {
                        $suggest_records[$id] = array("id" => $id, "tag" => $value);
                    }
                    printSuggestedInput($i . "_value", $suggest_records, array("id" => $record['key']), "macros");
                    enableTagsPicker();
                    break;
                case 'date':
                    $date_value = $record['value'] ? date(getConfigVar('DATETIME_FORMAT'), $record['value']) : '';
                    echo "<input type=text name={$i}_value value='{$date_value}'>";
                    break;
            }
            $i++;
            echo '<input type=hidden name=num_attrs value=' . $i . ">\n";
        }
    }
    echo '</table>';
    printImageHREF('SAVE', 'Save changes', TRUE);
    echo '</form>';
    finishPortlet();
}
function localfunc_ObjectCopier($object_id)
{
    $object = spotEntity('object', $object_id);
    amplifyCell($object);
    global $virtual_obj_types, $tagtree, $taglist, $target_given_tags;
    $typelist = readChapter(CHAP_OBJTYPE, 'o');
    $typelist[0] = 'select type...';
    $typelist = cookOptgroups($typelist);
    $max = getConfigVar('MASSCOUNT');
    $tabindex = 100;
    echo "\n";
    echo "\n<!-- printOpFormIntro ('copyLotOfObjects') -->\n";
    printOpFormIntro('copyLotOfObjects');
    echo "\n";
    startPortlet('Make many copies of this object');
    echo "\n" . sprintf('<table border=%s align=center>', TABLE_BORDER);
    echo "\n" . '<tr><th align=left>name or "name","label","asset_no" (no csv escaping)<br><br>';
    echo 'Example:<br> "server.example.com","server.example.com","12345"<br>www.example.com<br>testmachine<br>';
    echo '</th><th>Copy Tags</th></tr>';
    //echo "<tr><td><input type=submit name=got_very_fast_data value='Go!'></td><td></td></tr>\n";
    echo "\n" . "<tr><td valign=top ><textarea name=namelist cols=60 rows=35>\n</textarea></td>";
    echo "<td valign=top>";
    printf("<input type=hidden name=global_type_id value='%s'>\n", $object['objtype_id']);
    //renderCopyEntityTagsPortlet ('Tag tree', $tagtree, $target_given_tags, $etype_by_pageno[$pageno]);
    renderCopyEntityTags($object);
    echo "</td></tr>";
    echo "<tr><td colspan=2><input type=submit name=got_very_fast_data value='Go!'></td></tr></table>\n";
    echo "</form>\n";
    finishPortlet();
}
Ejemplo n.º 9
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;
}
function renderChapterEditor($tgt_chapter_no)
{
    global $nextorder;
    function printNewItemTR()
    {
        printOpFormIntro('add');
        echo '<tr><td>&nbsp;</td><td>&nbsp;</td><td>';
        printImageHREF('add', 'Add new', TRUE);
        echo "</td>";
        echo "<td class=tdleft><input type=text name=dict_value size=64></td><td>";
        printImageHREF('add', 'Add new', TRUE);
        echo '</td></tr></form>';
    }
    echo "<br><table class=cooltable border=0 cellpadding=5 cellspacing=0 align=center>\n";
    $words = readChapter($tgt_chapter_no, 'r');
    $refcnt = getChapterRefc($tgt_chapter_no, array_keys($words));
    $order = 'odd';
    echo "<tr><th>Origin</th><th>Key</th><th>&nbsp;</th><th>Word</th><th>&nbsp;</th></tr>\n";
    if (getConfigVar('ADDNEW_AT_TOP') == 'yes') {
        printNewItemTR();
    }
    foreach ($words as $key => $value) {
        echo "<tr class=row_{$order}><td>";
        $order = $nextorder[$order];
        // Show plain row for stock records, render a form for user's ones.
        if ($key < 50000) {
            printImageHREF('computer');
            echo "</td><td class=tdright>{$key}</td><td>&nbsp;</td><td>{$value}</td><td>&nbsp;</td></tr>";
            continue;
        }
        printOpFormIntro('upd', array('dict_key' => $key));
        printImageHREF('favorite');
        echo "</td><td class=tdright>{$key}</td><td>";
        // Prevent deleting words currently used somewhere.
        if ($refcnt[$key]) {
            printImageHREF('nodelete', 'referenced ' . $refcnt[$key] . ' time(s)');
        } else {
            echo getOpLink(array('op' => 'del', 'dict_key' => $key), '', 'delete', 'Delete word');
        }
        echo '</td>';
        echo "<td class=tdleft><input type=text name=dict_value size=64 value='{$value}'></td><td>";
        printImageHREF('save', 'Save changes', TRUE);
        echo "</td></tr></form>";
    }
    if (getConfigVar('ADDNEW_AT_TOP') != 'yes') {
        printNewItemTR();
    }
    echo "</table>\n";
}