function run($jobstate) { $pfAgent = new PluginFusioninventoryAgent(); $pfTaskjobstate = new PluginFusioninventoryTaskjobstate(); $pfTaskjoblog = new PluginFusioninventoryTaskjoblog(); $pfConfigSecurity = new PluginFusioninventoryConfigSecurity(); $pfToolbox = new PluginFusioninventoryToolbox(); $current = $jobstate; $pfAgent->getFromDB($current->fields['plugin_fusioninventory_agents_id']); $ip = current(PluginFusioninventoryToolbox::getIPforDevice($jobstate->fields['itemtype'], $jobstate->fields['items_id'])); if ($ip == '') { $pfTaskjobstate->changeStatusFinish($jobstate->fields['id'], $jobstate->fields['items_id'], $jobstate->fields['itemtype'], 1, "Device have no ip"); } else { $sxml_option = $this->message->addChild('OPTION'); $sxml_option->addChild('NAME', 'SNMPQUERY'); $sxml_param = $sxml_option->addChild('PARAM'); $sxml_param->addAttribute('THREADS_QUERY', $pfAgent->fields["threads_networkinventory"]); $sxml_param->addAttribute('TIMEOUT', $pfAgent->fields["timeout_networkinventory"]); $sxml_param->addAttribute('PID', $current->fields['id']); $changestate = 0; $taskjobstatedatas = $jobstate->fields; $sxml_device = $sxml_option->addChild('DEVICE'); $a_extended = array('plugin_fusioninventory_configsecurities_id' => 0); if ($jobstate->fields['itemtype'] == 'Printer') { $sxml_device->addAttribute('TYPE', 'PRINTER'); $pfPrinter = new PluginFusioninventoryPrinter(); $a_extended = current($pfPrinter->find("`printers_id`='" . $jobstate->fields['items_id'] . "'", '', 1)); } else { if ($jobstate->fields['itemtype'] == 'NetworkEquipment') { $sxml_device->addAttribute('TYPE', 'NETWORKING'); $pfNetworkEquipment = new PluginFusioninventoryNetworkEquipment(); $a_extended = current($pfNetworkEquipment->find("`networkequipments_id`='" . $jobstate->fields['items_id'] . "'", '', 1)); } } $sxml_device->addAttribute('ID', $jobstate->fields['items_id']); $sxml_device->addAttribute('IP', $ip); $sxml_device->addAttribute('AUTHSNMP_ID', $a_extended['plugin_fusioninventory_configsecurities_id']); if ($changestate == '0') { $pfTaskjobstate->changeStatus($taskjobstatedatas['id'], 1); $pfTaskjoblog->addTaskjoblog($taskjobstatedatas['id'], '0', 'PluginFusioninventoryAgent', '1', $pfAgent->fields["threads_networkinventory"] . ' threads', $pfAgent->fields["timeout_networkinventory"] . ' timeout'); $changestate = $pfTaskjobstate->fields['id']; } else { $pfTaskjobstate->changeStatusFinish($taskjobstatedatas['id'], $taskjobstatedatas['items_id'], $taskjobstatedatas['itemtype'], 0, "Merged with " . $changestate); } $snmpauthlist = $pfConfigSecurity->find(); if (count($snmpauthlist)) { foreach ($snmpauthlist as $snmpauth) { $pfToolbox->addAuth($sxml_option, $snmpauth['id']); } } } return $this->message; }
function showForm(Printer $item, $options = array()) { global $DB; Session::checkRight('plugin_fusioninventory_printer', READ); $id = $item->getID(); if (!($data = $this->find("`printers_id`='" . $id . "'", '', 1))) { // Add in database if not exist $input = array(); $input['printers_id'] = $id; $_SESSION['glpi_plugins_fusinvsnmp_table'] = 'glpi_printers'; $ID_tn = $this->add($input); $this->getFromDB($ID_tn); } else { foreach ($data as $datas) { $this->fields = $datas; } } // Form printer informations echo "<div align='center'>"; echo "<form method='post' name='snmp_form' id='snmp_form'\n action=\"" . $options['target'] . "\">"; echo "<table class='tab_cadre' cellpadding='5' width='950'>"; echo "<tr class='tab_bg_1'>"; echo "<th colspan='4'>"; echo __('SNMP information', 'fusioninventory'); echo "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td align='center'>"; echo __('Sysdescr', 'fusioninventory'); echo "</td>"; echo "<td>"; echo "<textarea name='sysdescr' cols='45' rows='5'>"; echo $this->fields['sysdescr']; echo "</textarea>"; echo "</td>"; echo "<td align='center'>"; echo __('Last inventory', 'fusioninventory') . " :"; echo "</td>"; echo "<td>"; echo Html::convDateTime($this->fields['last_fusioninventory_update']); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td align='center'></td>"; echo "<td align='center'>"; echo "</td>"; echo "<td align='center'>" . __('SNMP authentication', 'fusioninventory') . " :</td>"; echo "<td align='center'>"; PluginFusioninventoryConfigSecurity::auth_dropdown($this->fields["plugin_fusioninventory_configsecurities_id"]); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_2 center'>"; echo "<td colspan='4'>"; echo "<div align='center'>"; echo "<input type='hidden' name='id' value='" . $id . "'>"; echo "<input type='submit' name='update' value=\"" . __('Update') . "\" class='submit' >"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; }
function showForm(CommonDBTM $item, $options = array()) { $ID = $item->getField('id'); if ($item->isNewID($ID)) { return false; } if (!$item->can($item->fields['id'], READ)) { return false; } $rand = mt_rand(); $a_data = getAllDatasFromTable('glpi_plugin_fusioninventory_ipranges_configsecurities', "`plugin_fusioninventory_ipranges_id`='" . $item->getID() . "'", false, '`rank`'); $a_used = array(); foreach ($a_data as $data) { $a_used[] = $data['plugin_fusioninventory_configsecurities_id']; } echo "<div class='firstbloc'>"; echo "<form name='iprange_configsecurity_form{$rand}' id='iprange_configsecurity_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginFusioninventoryIPRange_ConfigSecurity') . "' >"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'>"; echo "<th colspan='2'>" . __('Add a SNMP authentication') . "</th>"; echo "</tr>"; echo "<tr class='tab_bg_2'>"; echo "<td>"; Dropdown::show('PluginFusioninventoryConfigSecurity', array('used' => $a_used)); echo "</td>"; echo "<td>"; echo Html::hidden('plugin_fusioninventory_ipranges_id', array('value' => $item->getID())); echo "<input type='submit' name='add' value=\"" . _sx('button', 'Associate') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; // Display list of auth associated with IP range $rand = mt_rand(); echo "<div class='spaced'>"; Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('container' => 'mass' . __CLASS__ . $rand); Html::showMassiveActions($massiveactionparams); echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'>"; echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; echo "<th>"; echo __('SNMP Authentication', 'fusioninventory'); echo "</th>"; echo "<th>"; echo __('Version', 'fusioninventory'); echo "</th>"; echo "<th>"; echo __('Rank'); echo "</th>"; echo "</tr>"; $pfConfigSecurity = new PluginFusioninventoryConfigSecurity(); foreach ($a_data as $data) { echo "<tr class='tab_bg_2'>"; echo "<td>"; Html::showMassiveActionCheckBox(__CLASS__, $data["id"]); echo "</td>"; echo "<td>"; $pfConfigSecurity->getFromDB($data['plugin_fusioninventory_configsecurities_id']); echo $pfConfigSecurity->getLink(); echo "</td>"; echo "<td>"; echo $pfConfigSecurity->getSNMPVersion($pfConfigSecurity->fields['snmpversion']); echo "</td>"; echo "<td>"; echo $data['rank']; echo "</td>"; echo "</tr>"; } echo "</table>"; $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); echo "</div>"; }
/** * Add AUTHENTICATION string to XML node * *@param $p_sxml_node XML node to authenticate *@param $p_id Authenticate id *@return nothing **/ function addAuth($p_sxml_node, $p_id) { $pfConfigSecurity = new PluginFusioninventoryConfigSecurity(); if ($pfConfigSecurity->getFromDB($p_id)) { $sxml_authentication = $p_sxml_node->addChild('AUTHENTICATION'); $sxml_authentication->addAttribute('ID', $p_id); $sxml_authentication->addAttribute('VERSION', $pfConfigSecurity->getSNMPVersion($pfConfigSecurity->fields['snmpversion'])); if ($pfConfigSecurity->fields['snmpversion'] == '3') { $sxml_authentication->addAttribute('USERNAME', $pfConfigSecurity->fields['username']); if ($pfConfigSecurity->fields['authentication'] == '0') { // $sxml_authentication->addAttribute('AUTHPROTOCOL', ''); } else { $sxml_authentication->addAttribute('AUTHPROTOCOL', $pfConfigSecurity->getSNMPAuthProtocol($pfConfigSecurity->fields['authentication'])); } $sxml_authentication->addAttribute('AUTHPASSPHRASE', $pfConfigSecurity->fields['auth_passphrase']); if ($pfConfigSecurity->fields['encryption'] == '0') { // $sxml_authentication->addAttribute('PRIVPROTOCOL', ''); } else { $sxml_authentication->addAttribute('PRIVPROTOCOL', $pfConfigSecurity->getSNMPEncryption($pfConfigSecurity->fields['encryption'])); } $sxml_authentication->addAttribute('PRIVPASSPHRASE', $pfConfigSecurity->fields['priv_passphrase']); } else { $sxml_authentication->addAttribute('COMMUNITY', $pfConfigSecurity->fields['community']); } } }
static function convertArgument($services_id, $argument) { global $DB; $pmService = new PluginMonitoringService(); $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); $pmService->getFromDB($services_id); $pmComponentscatalog_Host->getFromDB($pmService->fields['plugin_monitoring_componentscatalogs_hosts_id']); $itemtype = $pmComponentscatalog_Host->fields['itemtype']; $item = new $itemtype(); $item->getFromDB($pmComponentscatalog_Host->fields['items_id']); $argument = str_replace("[", "", $argument); $argument = str_replace("]", "", $argument); $a_arg = explode(":", $argument); $devicetype = ''; $devicedata = array(); if ($itemtype == "NetworkPort") { $itemtype2 = $item->fields['itemtype']; $item2 = new $itemtype2(); $item2->getFromDB($item->fields['items_id']); $devicetype = $itemtype2; $devicedata = $item2->fields; } else { $devicetype = $itemtype; $devicedata = $item->fields; } if ($devicetype == "NetworkEquipment") { if (class_exists("PluginFusioninventoryNetworkEquipment")) { $pfNetworkEquipment = new PluginFusioninventoryNetworkEquipment(); $a_pfNetworkEquipment = current($pfNetworkEquipment->find("`networkequipments_id`='".$devicedata['id']."'", "", 1)); switch ($a_arg[0]) { case 'OID': // Load SNMP model and get oid.portnum $query = "SELECT `glpi_plugin_fusioninventory_mappings`.`name` AS `mapping_name`, `glpi_plugin_fusioninventory_snmpmodelmibs`.* FROM `glpi_plugin_fusioninventory_snmpmodelmibs` LEFT JOIN `glpi_plugin_fusioninventory_mappings` ON `glpi_plugin_fusioninventory_snmpmodelmibs`.`plugin_fusioninventory_mappings_id`= `glpi_plugin_fusioninventory_mappings`.`id` WHERE `plugin_fusioninventory_snmpmodels_id`='".$a_pfNetworkEquipment['plugin_fusioninventory_snmpmodels_id']."' AND `is_active`='1' AND `oid_port_counter`='0' AND `glpi_plugin_fusioninventory_mappings`.`name`='".$a_arg[1]."'"; $result=$DB->query($query); while ($data=$DB->fetch_array($result)) { return Dropdown::getDropdownName('glpi_plugin_fusioninventory_snmpmodelmiboids',$data['plugin_fusioninventory_snmpmodelmiboids_id']). ".".$item->fields['logical_number']; } return ''; break; case 'SNMP': if ($a_pfNetworkEquipment['plugin_fusioninventory_configsecurities_id'] == '0') { switch ($a_arg[1]) { case 'version': return '2c'; break; case 'authentication': return 'public'; break; } } $pfConfigSecurity = new PluginFusioninventoryConfigSecurity(); $pfConfigSecurity->getFromDB($a_pfNetworkEquipment['plugin_fusioninventory_configsecurities_id']); switch ($a_arg[1]) { case 'version': if ($pfConfigSecurity->fields['snmpversion'] == '2') { $pfConfigSecurity->fields['snmpversion'] = '2c'; } return $pfConfigSecurity->fields['snmpversion']; break; case 'authentication': return $pfConfigSecurity->fields['community']; break; } break; } } } return $argument; }
/** * @since version 0.85 * * @see CommonDBTM::showMassiveActionsSubForm() **/ static function showMassiveActionsSubForm(MassiveAction $ma) { switch ($ma->getAction()) { case "assign_auth": PluginFusioninventoryConfigSecurity::auth_dropdown(); echo Html::submit(_x('button', 'Post'), array('name' => 'massiveaction')); return true; break; } }
/** * Display form for unmanaged device * * @param $id integer id of the unmanaged device * @param $options array * * @return bool TRUE if form is ok * **/ function showForm($id, $options = array()) { $this->initForm($id, $options); $this->showFormHeader($options); echo "<tr class='tab_bg_1'>"; echo "<td align='center'>" . __('Name') . " :</td>"; echo "<td align='center'>"; Html::autocompletionTextField($this, 'name', array('size' => 35)); echo "</td>"; if (Session::isMultiEntitiesMode()) { echo "<td align='center'>" . __('Entity') . " :</td>"; echo "</td>"; echo "<td align='center'>"; Dropdown::show("Entity", array('name' => 'entities_id', 'value' => $this->fields["entities_id"])); echo "</td>"; echo "</tr>"; echo "</tr>"; } else { echo "<td align='center'></td>"; echo "</td>"; echo "<td align='center'></td>"; echo "</tr>"; echo "</tr>"; } echo "<tr class='tab_bg_1'>"; echo "<td align='center'>" . __('Type') . " :</td>"; echo "<td align='center'>"; $type_list = array(); $type_list[] = 'Computer'; $type_list[] = 'NetworkEquipment'; $type_list[] = 'Printer'; $type_list[] = 'Peripheral'; $type_list[] = 'Phone'; Dropdown::showItemTypes('item_type', $type_list, array('value' => $this->fields["item_type"])); echo "</td>"; echo "<td align='center'>" . __('Alternate username') . " :</td>"; echo "</td>"; echo "<td align='center'>"; Html::autocompletionTextField($this, 'contact', array('size' => 35)); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td align='center'>" . __('Location') . " :</td>"; echo "<td align='center'>"; Dropdown::show("Location", array('name' => "locations_id", 'value' => $this->fields["locations_id"])); echo "</td>"; echo "<td align='center'>" . __('Domain') . " :</td>"; echo "</td>"; echo "<td align='center'>"; Dropdown::show("Domain", array('name' => "domain", 'value' => $this->fields["domain"])); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td align='center'>" . __('Approved devices', 'fusioninventory') . " :</td>"; echo "<td align='center'>"; Dropdown::showYesNo("accepted", $this->fields["accepted"]); echo "</td>"; echo "<td align='center'>" . __('Serial Number') . " :</td>"; echo "</td>"; echo "<td align='center'>"; Html::autocompletionTextField($this, 'serial', array('size' => 35)); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td align='center'>" . __('Network hub', 'fusioninventory') . " :</td>"; echo "<td align='center'>"; echo Dropdown::getYesNo($this->fields["hub"]); echo "</td>"; echo "<td align='center'>" . __('Inventory number') . " :</td>"; echo "</td>"; echo "<td align='center'>"; Html::autocompletionTextField($this, 'otherserial', array('size' => 35)); echo "</td>"; echo "</tr>"; if (!empty($this->fields["ip"]) or !empty($this->fields["mac"])) { echo "<tr class='tab_bg_1'>"; echo "<td align='center'>" . __('IP') . " :</td>"; echo "<td align='center'>"; Html::autocompletionTextField($this, 'ip', array('size' => 35)); echo "</td>"; echo "<td colspan='2'></td>"; echo "</tr>"; } echo "<tr class='tab_bg_1'>"; echo "<td align='center' rowspan='2'>"; echo __('Sysdescr', 'fusioninventory') . " :"; echo "</td>"; echo "<td rowspan='2'>"; echo "<textarea name='sysdescr' cols='45' rows='5'>" . $this->fields["sysdescr"] . "</textarea>"; echo "<td align='center'></td>"; echo "<td align='center'>"; echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td align='center'>" . __('SNMP authentication', 'fusioninventory') . " :</td>"; echo "<td align='center'>"; PluginFusioninventoryConfigSecurity::auth_dropdown($this->fields['plugin_fusioninventory_configsecurities_id']); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td align='center'>" . __('Comments') . " : </td>"; echo "</td>"; echo "<td align='middle' colspan='3'>"; echo "<textarea cols='80' rows='2' name='comment' >" . $this->fields["comment"] . "</textarea>"; echo "</td>"; echo "</tr>"; $this->showFormButtons($options); return TRUE; }
function showNetworkEquipmentInformation(CommonDBTM $item, $options) { global $DB; $id = $item->getID(); if (!($data = $this->find("`networkequipments_id`='" . $id . "'", '', 1))) { // Add in database if not exist $input = array(); $input['networkequipments_id'] = $id; $_SESSION['glpi_plugins_fusinvsnmp_table'] = 'glpi_networkequipments'; $ID_tn = $this->add($input); $this->getFromDB($ID_tn); } else { foreach ($data as $datas) { $this->fields = $datas; } } // Form networking informations echo "<form name='form' method='post' action='" . $options['target'] . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<th colspan='4'>"; echo __('SNMP information', 'fusioninventory'); echo "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td align='center' rowspan='4'>"; echo __('Sysdescr', 'fusioninventory') . " :"; echo "</td>"; echo "<td rowspan='4'>"; echo "<textarea name='sysdescr' cols='45' rows='5'>"; echo $this->fields['sysdescr']; echo "</textarea>"; echo "<td align='center'></td>"; echo "<td align='center'>"; echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td align='center'>" . __('SNMP authentication', 'fusioninventory') . " :</td>"; echo "<td align='center'>"; PluginFusioninventoryConfigSecurity::auth_dropdown($this->fields['plugin_fusioninventory_configsecurities_id']); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td align='center'>"; echo __('CPU usage (in %)', 'fusioninventory') . " :"; echo "</td>"; echo "<td>"; Html::displayProgressBar(250, $this->fields['cpu'], array('simple' => TRUE)); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td align='center'>"; echo __('Memory usage (in %)', 'fusioninventory') . " :"; echo "</td>"; echo "<td>"; $query2 = "SELECT *\n FROM `glpi_networkequipments`\n WHERE `id`='" . $id . "';"; $result2 = $DB->query($query2); $data2 = $DB->fetch_assoc($result2); $ram_pourcentage = 0; if (!empty($data2["ram"]) and !empty($this->fields['memory'])) { $ram_pourcentage = ceil(100 * ($data2["ram"] - $this->fields['memory']) / $data2["ram"]); } if ($data2["ram"] - $this->fields['memory'] < 0 or empty($this->fields['memory'])) { echo "<center><strong>" . __('Datas not available', 'fusioninventory') . "</strong></center>"; } else { Html::displayProgressBar(250, $ram_pourcentage, array('title' => " (" . ($data2["ram"] - $this->fields['memory']) . " Mo / " . $data2["ram"] . " Mo)")); } echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_2 center'>"; echo "<td colspan='4'>"; echo "<input type='hidden' name='id' value='" . $id . "'>"; echo "<input type='submit' name='update' value=\"" . __('Update') . "\" class='submit' >"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); }
@package FusionInventory @author David Durieux @co-author @copyright Copyright (c) 2010-2015 FusionInventory team @license AGPL License 3.0 or (at your option) any later version http://www.gnu.org/licenses/agpl-3.0-standalone.html @link http://www.fusioninventory.org/ @link http://forge.fusioninventory.org/projects/fusioninventory-for-glpi/ @since 2010 ------------------------------------------------------------------------ */ include "../../../inc/includes.php"; Session::checkRight('plugin_fusioninventory_configsecurity', READ); $pfConfigSecurity = new PluginFusioninventoryConfigSecurity(); $config = new PluginFusioninventoryConfig(); Html::header(__('FusionInventory', 'fusioninventory'), $_SERVER["PHP_SELF"], "plugins", "pluginfusioninventorymenu", "configsecurity"); PluginFusioninventoryMenu::displayMenu("mini"); if (isset($_POST["add"])) { Session::checkRight('plugin_fusioninventory_configsecurity', CREATE); $new_ID = 0; $new_ID = $pfConfigSecurity->add($_POST); Html::back(); } else { if (isset($_POST["update"])) { Session::checkRight('plugin_fusioninventory_configsecurity', UPDATE); $pfConfigSecurity->update($_POST); Html::back(); } else { if (isset($_POST["delete"])) {