function localfunc_HPSysMan()
{
    assertUIntArg('object_id', __FUNCTION__);
    $object = spotEntity('object', $_REQUEST['object_id']);
    $alloclist = getObjectIPv4Allocations($object['id']);
    if (count($alloclist)) {
        foreach ($alloclist as $dottedquad => $alloc) {
            if ($alloc[addrinfo][allocs][0][type] == "regular") {
                renderIframeTabForEntity("HP System Management Homepage", "https://" . $alloc[addrinfo][ip] . ":2381");
            }
        }
    }
}
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. 3
0
function amplifyCell(&$record, $dummy = NULL)
{
    switch ($record['realm']) {
        case 'object':
            $record['ports'] = getObjectPortsAndLinks($record['id']);
            $record['ipv4'] = getObjectIPv4Allocations($record['id']);
            $record['ipv6'] = getObjectIPv6Allocations($record['id']);
            $record['nat4'] = getNATv4ForObject($record['id']);
            $record['files'] = getFilesOfEntity($record['realm'], $record['id']);
            break;
        case 'file':
            $record['links'] = getFileLinks($record['id']);
            break;
        case 'location':
            $record['locations'] = getLocations($record['id']);
            $record['rows'] = getRows($record['id']);
            break;
        case 'row':
            $record['racks'] = getRacks($record['id']);
        case 'rack':
            $record['mountedObjects'] = array();
            // start with default rackspace
            for ($i = $record['height']; $i > 0; $i--) {
                for ($locidx = 0; $locidx < 3; $locidx++) {
                    $record[$i][$locidx]['state'] = 'F';
                }
            }
            // load difference
            $query = "select unit_no, atom, state, object_id " . "from RackSpace where rack_id = ? and " . "unit_no between 1 and ? order by unit_no";
            $result = usePreparedSelectBlade($query, array($record['id'], $record['height']));
            global $loclist;
            $mounted_objects = array();
            while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
                $record[$row['unit_no']][$loclist[$row['atom']]]['state'] = $row['state'];
                $record[$row['unit_no']][$loclist[$row['atom']]]['object_id'] = $row['object_id'];
                if ($row['state'] == 'T' and $row['object_id'] != NULL) {
                    $mounted_objects[$row['object_id']] = TRUE;
                }
            }
            $record['mountedObjects'] = array_keys($mounted_objects);
            unset($result);
            break;
        case 'vst':
            $record['rules'] = array();
            $record['switches'] = array();
            $result = usePreparedSelectBlade('SELECT rule_no, port_pcre, port_role, wrt_vlans, description ' . 'FROM VLANSTRule WHERE vst_id = ? ORDER BY rule_no', array($record['id']));
            while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
                $record['rules'][$row['rule_no']] = $row;
            }
            unset($result);
            $result = usePreparedSelectBlade('SELECT object_id, domain_id FROM VLANSwitch WHERE template_id = ?', array($record['id']));
            while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
                $record['switches'][$row['object_id']] = $row;
            }
            break;
        default:
    }
}
Esempio n. 4
0
function snmpgeneric_snmpconfig($object_id)
{
    echo '<body onload="document.getElementById(\'submitbutton\').focus();">';
    $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 != \'' . SNMPgeneric::VERSION_3 . '\') {
					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 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);
    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';
    $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['snmpversion'])) {
        $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;
    }
    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>';
    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(SNMPgeneric::VERSION_1 => 'v1', SNMPgeneric::VERSION_2C => 'v2c', SNMPgeneric::VERSION_3 => '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>
	<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. 5
0
 function getobject($object_id, &$rack = null)
 {
     if (!$object_id) {
         return null;
     }
     if (!isset($this->cache['o' . $object_id])) {
         $object = spotEntity('object', $object_id);
         $object['IPV4OBJ'] = considerConfiguredConstraint($object, 'IPV4OBJ_LISTSRC');
         /* get more object info */
         if ($object['IPV4OBJ']) {
             // ip addresses
             //amplifyCell($object); /* get ports, ipv4, ipv6, nat4 and files */
             $object['ipv4'] = getObjectIPv4Allocations($object_id);
             $object['portip'] = array();
             foreach ($object['ipv4'] as $ipv4) {
                 $object['portip'][$ipv4['osif']] = $ipv4['addrinfo']['ip'];
             }
         }
         if ($object['container_id']) {
             $container = $this->getobject($object['container_id']);
         }
         $this->cache['o' . $object_id] = $object;
     } else {
         $object = $this->cache['o' . $object_id];
     }
     $rack = $this->getrack($object['rack_id']);
     return $object;
 }