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>'; }
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> </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> </td><th class=tdright>Name (required):</th><td class=tdleft><input type=text name=name value='{$location['name']}'></td></tr>\n"; echo "<tr><td> </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 ' '; } 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> </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> </td><th class=tdright>Actions:</th><td class=tdleft>"; echo getOpLink(array('op' => 'deleteLocation'), '', 'destroy', 'Delete location', 'need-confirmation'); echo " </td></tr>\n"; } echo "<tr><td colspan=3><b>Comment:</b><br><textarea name=comment rows=10 cols=80>{$location['comment']}</textarea></td></tr>"; echo "<tr><td class=submit colspan=3>"; printImageHREF('SAVE', 'Save changes', TRUE); echo "</td></tr>\n"; echo '</form></table><br>'; finishPortlet(); startPortlet('History'); renderObjectHistory($location_id); finishPortlet(); }
function 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>'; }
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(); }