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>';
}
Esempio n. 2
0
function renderAddMultipleObjectsForm()
{
    $typelist = withoutLocationTypes(readChapter(CHAP_OBJTYPE, 'o'));
    $typelist[0] = 'select type...';
    $typelist = cookOptgroups($typelist);
    $max = getConfigVar('MASSCOUNT');
    startPortlet('Distinct types, same tags');
    printOpFormIntro('addObjects');
    echo '<table border=0 align=center>';
    echo "<tr><th>Object type</th><th>Common name</th><th>Visible label</th>";
    echo "<th>Asset tag</th><th>Tags</th></tr>\n";
    for ($i = 0; $i < $max; $i++) {
        echo '<tr><td>';
        // Don't employ DEFAULT_OBJECT_TYPE to avoid creating ghost records for pre-selected empty rows.
        printNiftySelect($typelist, array('name' => "{$i}_object_type_id"), 0);
        echo '</td>';
        echo "<td><input type=text size=30 name={$i}_object_name></td>";
        echo "<td><input type=text size=30 name={$i}_object_label></td>";
        echo "<td><input type=text size=20 name={$i}_object_asset_no></td>";
        if ($i == 0) {
            echo "<td valign=top rowspan={$max}>";
            printTagsPicker();
            echo "</td>\n";
        }
        echo "</tr>\n";
    }
    echo "<tr><td class=submit colspan=5><input type=submit name=got_fast_data value='Go!'></td></tr>\n";
    echo "</form></table>\n";
    finishPortlet();
    startPortlet('Same type, same tags');
    printOpFormIntro('addLotOfObjects');
    echo "<table border=0 align=center><tr><th>names</th><th>type</th></tr>";
    echo "<tr><td rowspan=3><textarea name=namelist cols=40 rows=25>\n";
    echo "</textarea></td><td valign=top>";
    printNiftySelect($typelist, array('name' => 'global_type_id'), getConfigVar('DEFAULT_OBJECT_TYPE'));
    echo "</td></tr>";
    echo "<tr><th>Tags</th></tr>";
    echo "<tr><td valign=top>";
    printTagsPicker();
    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();
}