Example #1
0
function renderObject8021QSyncPorts($object, $D)
{
    $allethports = array();
    foreach (array_filter($object['ports'], 'isEthernetPort') as $port) {
        $allethports[$port['name']] = formatPortIIFOIF($port);
    }
    $enabled = array();
    # OPTIONSs for existing 802.1Q ports
    foreach (sortPortList($D) as $portname => $portconfig) {
        $enabled["disable {$portname}"] = "{$portname} (" . array_fetch($allethports, $portname, 'N/A') . ') ' . serializeVLANPack($portconfig);
    }
    # OPTIONs for potential 802.1Q ports
    $disabled = array();
    foreach (sortPortList($allethports) as $portname => $iifoif) {
        if (!array_key_exists("disable {$portname}", $enabled)) {
            $disabled["enable {$portname}"] = "{$portname} ({$iifoif})";
        }
    }
    printOpFormIntro('updPortList');
    echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>';
    echo '<tr><td>';
    printNiftySelect(array('select ports to disable 802.1Q' => $enabled, 'select ports to enable 802.1Q' => $disabled), array('name' => 'ports[]', 'multiple' => 1, 'size' => getConfigVar('MAXSELSIZE')));
    echo '</td></tr>';
    echo '<tr><td>' . getImageHREF('RECALC', 'process changes', TRUE) . '</td></tr>';
    echo '</table></form>';
}
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>';
}
Example #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');
     unset($objtypes[1561]);
     // attributes may not be assigned to rows yet
     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>';
 }