PluginFusioninventoryAuth::checkRight("agents", "w"); if (isset($_POST['on_device'])) { if ($_POST['on_device'] != "0" and $_POST['on_device'] != "") { $_POST['device_type'] = '1'; } } $agents->update($_POST); glpi_header($_SERVER['HTTP_REFERER']); } else { if (isset($_POST["delete"])) { PluginFusioninventoryAuth::checkRight("agents", "w"); $agents->delete($_POST); glpi_header("agents.php"); } else { if (isset($_POST["startagent"])) { $pta = new PluginFusioninventoryAgents(); $pta->RemoteStartAgent($_POST['agentID'], $_POST['ip']); glpi_header($_SERVER['HTTP_REFERER']); } } } } $ID = ""; if (isset($_GET["ID"])) { $ID = $_GET["ID"]; } else { $agents->showForm($_SERVER["PHP_SELF"], $ID); } $agents->showTabs($ID, '', $_SESSION['glpi_tab']); echo "<div id='tabcontent'></div>"; echo "<script type='text/javascript'>loadDefaultTab();</script>";
function computerState($target, $ID) { global $DB, $LANG; $np = new Netport(); $pta = new PluginFusioninventoryAgents(); echo "<br/>"; echo "<div align='center'>"; echo "<form method='post' name='' id='' action=\"" . $target . "\">"; echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th colspan='2'>"; echo $LANG['plugin_fusioninventory']["agents"][15]; echo "</th>"; echo "</tr>"; $a_datas = $this->find("`device_id`='" . $ID . "'", "", "1"); if (empty($a_datas)) { // Ajouter une entrée $this->fields['device_id'] = $ID; $this->fields['date_mod'] = date("Y-m-d H:i:s"); $data['ID'] = $this->addToDB(); $data['date_mod'] = $this->fields['date_mod']; $data['state'] = 0; } else { // Afficher l'état foreach ($a_datas as $device_id => $values) { $data = $a_datas[$device_id]; } } echo "<tr class='tab_bg_1'>"; echo "<td align='center'>"; echo convDateTime($data['date_mod']); echo " : </td>"; echo "<td align='center'>"; switch ($data['state']) { case 0: echo $LANG['plugin_fusioninventory']["agents"][16]; break; case 1: echo $LANG['plugin_fusioninventory']["agents"][22]; break; case 2: echo $LANG['plugin_fusioninventory']["agents"][17]; break; case 3: echo $LANG['plugin_fusioninventory']["agents"][18]; break; case 4: echo $LANG['plugin_fusioninventory']["agents"][19]; break; case 5: echo $LANG['plugin_fusioninventory']["agents"][20]; break; case 6: echo $LANG['plugin_fusioninventory']["agents"][21]; break; default: break; } echo "</td>"; echo "</tr>"; $ip = ""; if ($data['state'] == 0 or $data['state'] == 6) { $a_data = $np->find("`on_device`='" . $ID . "' AND `device_type`='1'"); foreach ($a_data as $port_id => $port) { echo "<tr class='tab_bg_1'>"; echo "<td align='center'>"; if (!($fp = fsockopen($port['ifaddr'], 62354, $errno, $errstr, 1))) { echo $port['ifaddr'] . " : </td><td align='center'><b>" . $LANG['plugin_fusioninventory']["task"][9] . "</b>"; } else { echo $port['ifaddr'] . " : </td><td align='center'><b>" . $LANG['plugin_fusioninventory']["task"][8] . "</b>"; $ip = $port['ifaddr']; fclose($fp); } echo "</td>"; echo "</tr>"; } } echo "<tr class='tab_bg_2'>"; echo "<td align='center' colspan='2'>"; $a_datasagent = $pta->find("`on_device`='" . $ID . "' AND `device_type`='1' ", "", "1"); if (!empty($a_datasagent)) { foreach ($a_datasagent as $agent_id => $dataagent) { echo "<input type='hidden' name='agentID' value='" . $agent_id . "'/>"; } } echo "<input type='hidden' name='ID' value='" . $ID . "'/>"; echo "<input type='hidden' name='ip' value='" . $ip . "'/>"; echo "<input type='submit' name='startagent' value=\"" . $LANG['plugin_fusioninventory']["task"][12] . "\" class='submit' >"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</form>"; echo "</div>"; $glpiroot = GLPI_ROOT . "/plugins/fusioninventory/front/"; if (strstr($_SERVER["PHP_SELF"], "fusioninventory")) { $glpiroot = '../plugins/fusioninventory/front/'; } if ($data['state'] > 0 and $data['state'] < 6) { echo "<script type='text/javascript'>\nExt.getCmp('fusioninventory_1').getUpdater().startAutoRefresh(3,'" . GLPI_ROOT . "/plugins/fusioninventory/front/agents.state.php?ID=" . $ID . "');\n \n </script>"; } else { echo "<script type='text/javascript'>\nExt.getCmp('fusioninventory_1').getUpdater().stopAutoRefresh();\n\n </script>"; } }
function addProcess($pxml) { $pta = new PluginFusioninventoryAgents(); $agent = $pta->InfosByKey($pxml->DEVICEID); $input['FK_agent'] = $agent["ID"]; $input['process_number'] = time() . "/" . sprintf('%03d', $input['FK_agent']); $input['status'] = 2; $input['start_time'] = date("Y-m-d H:i:s"); $this->add($input); return $input['process_number']; }
include GLPI_ROOT . "/inc/includes.php"; header("Content-Type: text/html; charset=UTF-8"); header_nocache(); if (!isset($_POST["ID"])) { exit; } if (!isset($_POST["sort"])) { $_POST["sort"] = ""; } if (!isset($_POST["order"])) { $_POST["order"] = ""; } if (!isset($_POST["withtemplate"])) { $_POST["withtemplate"] = ""; } $pfia = new PluginFusioninventoryAgents(); $pfit = new PluginFusioninventoryTask(); $pfia->showForm($_POST['target'], $_POST["ID"]); switch ($_POST['glpi_tab']) { case -1: $pfia->showFormAdvancedOptions($_POST['target'], $_POST["ID"]); $pfit->RemoteStateAgent($_POST['target'], $_POST["ID"], PLUGIN_FUSIONINVENTORY_SNMP_AGENTS, array('INVENTORY' => 1, 'NETDISCOVERY' => 1, 'SNMPQUERY' => 1, 'WAKEONLAN' => 1)); break; case 1: $pfia->showFormAdvancedOptions($_POST['target'], $_POST["ID"]); break; case 2: $pfit->RemoteStateAgent($_POST['target'], $_POST["ID"], PLUGIN_FUSIONINVENTORY_SNMP_AGENTS, array('INVENTORY' => 1, 'NETDISCOVERY' => 1, 'SNMPQUERY' => 1, 'WAKEONLAN' => 1)); break; default: $pfia->showFormAdvancedOptions($_POST['target'], $_POST["ID"]);
function dropdownNetworkPrinterSNMP($agent_id) { // Dropdown with printer and network devices who have model and auth global $DB, $LANG; $ptcm = new PluginFusioninventoryConfigModules(); $pfia = new PluginFusioninventoryAgents(); $dropdownOptions = ""; $pfia->getFromDB($agent_id); if ($ptcm->getValue("snmp") == '1' and $pfia->fields['module_snmpquery'] == '1') { // Networking $dropdownOptions = "<optgroup label=\"" . $LANG['help'][26] . "\">"; $query = "SELECT `glpi_networking`.`ID` AS `gID`,\n `glpi_networking`.`name` AS `name`, `serial`, `otherserial`,\n `FK_snmp_connection`, `FK_model_infos`\n FROM `glpi_networking`\n LEFT JOIN `glpi_plugin_fusioninventory_networking`\n ON `FK_networking`=`glpi_networking`.`ID`\n INNER join `glpi_plugin_fusioninventory_model_infos`\n ON `FK_model_infos`=`glpi_plugin_fusioninventory_model_infos`.`ID`\n WHERE `glpi_networking`.`deleted`='0'\n AND `FK_model_infos`!='0'\n AND `FK_snmp_connection`!='0'\n GROUP BY FK_networking"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $dropdownOptions .= "<option value='" . NETWORKING_TYPE . "-" . $data['gID'] . "'>" . $data['name'] . " - " . $data['serial'] . " - " . $data['otherserial'] . "</option>"; } $dropdownOptions .= "</optgroup>"; // Printers $dropdownOptions .= "<optgroup label=\"" . $LANG['help'][27] . "\">"; $query = "SELECT `glpi_printers`.`ID` AS `gID`,\n `glpi_printers`.`name` AS `name`, `serial`, `otherserial`,\n `FK_snmp_connection`, `FK_model_infos`\n FROM `glpi_printers`\n LEFT JOIN `glpi_plugin_fusioninventory_printers`\n ON `FK_printers`=`glpi_printers`.`ID`\n LEFT JOIN `glpi_networking_ports`\n ON `on_device`=`glpi_printers`.`ID`\n AND `device_type`='" . PRINTER_TYPE . "'\n INNER join `glpi_plugin_fusioninventory_model_infos`\n ON `FK_model_infos`=`glpi_plugin_fusioninventory_model_infos`.`ID`\n WHERE `glpi_printers`.`deleted`='0'\n AND `FK_model_infos`!='0'\n AND `FK_snmp_connection`!='0'\n GROUP BY FK_printers"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $dropdownOptions .= "<option value='" . NETWORKING_TYPE . "-" . $data['gID'] . "'>" . $data['name'] . " - " . $data['serial'] . " - " . $data['otherserial'] . "</option>"; } $dropdownOptions .= "</optgroup>"; } return $dropdownOptions; }
function import_netdiscovery($p_xml, $agentKey) { global $DB, $LANG; $test = ''; $p_criteria = array(); $walks = new PluginFusioninventoryWalk(); $ptap = new PluginFusioninventoryAgentsProcesses(); $pta = new PluginFusioninventoryAgents(); $config_discovery = new PluginFusioninventoryConfig(); $np = new Netport(); $ptud = new PluginFusioninventoryUnknownDevice(); if (isset($p_xml->AGENT->START)) { $ptap->updateProcess($p_xml->PROCESSNUMBER, array('start_time_discovery' => date("Y-m-d H:i:s"))); } else { if (isset($p_xml->AGENT->END)) { $ptap->updateProcess($p_xml->PROCESSNUMBER, array('end_time_discovery' => date("Y-m-d H:i:s"))); } else { if (isset($p_xml->AGENT->EXIT)) { $ptap->endProcess($p_xml->PROCESSNUMBER, date("Y-m-d H:i:s")); } else { if (isset($p_xml->AGENT->NBIP)) { $ptap->updateProcess($p_xml->PROCESSNUMBER, array('discovery_nb_ip' => $p_xml->AGENT->NBIP)); } } } } if (isset($p_xml->AGENT->AGENTVERSION)) { $agent = $pta->InfosByKey($agentKey); $agent['fusioninventory_agent_version'] = $p_xml->AGENT->AGENTVERSION; $agent['last_agent_update'] = date("Y-m-d H:i:s"); $pta->update($agent); } $walkdata = ''; $count_discovery_devices = 0; foreach ($p_xml->DEVICE as $discovery) { $count_discovery_devices++; } $ptap->updateProcess($_SESSION['glpi_plugin_fusioninventory_processnumber'], array('discovery_nb_found' => $count_discovery_devices)); foreach ($p_xml->DEVICE as $discovery) { if ($discovery->MODELSNMP != "") { $query = "SELECT *\n FROM `glpi_plugin_fusioninventory_model_infos`\n WHERE `discovery_key`='" . $discovery->MODELSNMP . "'\n LIMIT 0,1;"; $result = $DB->query($query); $data = $DB->fetch_assoc($result); $FK_model = $data['ID']; } else { $FK_model = 0; } $discovery->MAC = strtolower($discovery->MAC); if (empty($FK_model)) { $FK_model = 0; } unset($p_criteria); $p_criteria['ip'] = $discovery->IP; if (!empty($discovery->NETBIOSNAME)) { $p_criteria['name'] = $discovery->NETBIOSNAME; } else { if (!empty($discovery->SNMPHOSTNAME)) { $p_criteria['name'] = $discovery->SNMPHOSTNAME; } } $p_criteria['serial'] = $discovery->SERIAL; $p_criteria['macaddr'] = $discovery->MAC; $discovery_criteria = PluginFusioninventoryDiscovery::criteria($p_criteria); if (!$discovery_criteria) { $ptap->updateProcess($_SESSION['glpi_plugin_fusioninventory_processnumber'], array('discovery_nb_import' => '1')); // Add in unknown device $ptud->getEmpty(); if (!empty($discovery->NETBIOSNAME)) { $ptud->fields['name'] = $discovery->NETBIOSNAME; } else { if (!empty($discovery->SNMPHOSTNAME)) { $ptud->fields['name'] = $discovery->SNMPHOSTNAME; } } $ptud->fields['dnsname'] = $discovery->DNSHOSTNAME; $ptud->fields['FK_entities'] = $discovery->ENTITY; $ptud->fields['serial'] = $discovery->SERIAL; $ptud->fields['contact'] = $discovery->USERSESSION; if (!empty($discovery->WORKGROUP)) { $ptud->fields['domain'] = Dropdown::importExternal("Domain", $discovery->WORKGROUP, $discovery->ENTITY); } $ptud->fields['comments'] = $discovery->DESCRIPTION; $ptud->fields['type'] = $discovery->TYPE; $ptud->fields['FK_model_infos'] = $FK_model; $ptud->fields['FK_snmp_connection'] = $discovery->AUTHSNMP; if ($discovery->AUTHSNMP != "") { $ptud->fields['snmp'] = 1; } $ptud->fields['location'] = 0; $ptud->fields['deleted'] = 0; if ($ptud->fields['domain'] == '') { $ptud->fields['domain'] = 0; } if ($ptud->fields['type'] == '') { $ptud->fields['type'] = 0; } if ($ptud->fields['snmp'] == '') { $ptud->fields['snmp'] = 0; } if ($ptud->fields['FK_model_infos'] == '') { $ptud->fields['FK_model_infos'] = 0; } if ($ptud->fields['FK_snmp_connection'] == '') { $ptud->fields['FK_snmp_connection'] = 0; } if ($ptud->fields['accepted'] == '') { $ptud->fields['accepted'] = 0; } $explodeprocess = explode("/", $_SESSION['glpi_plugin_fusioninventory_processnumber']); $ptud->fields['FK_agent'] = intval($explodeprocess[1]); $ptud->fields['hub'] = 0; $data = $ptud->fields; unset($data['ID']); $newID = $ptud->add($data); unset($data); // Add networking_port $port_add["on_device"] = $newID; $port_add["device_type"] = PLUGIN_FUSIONINVENTORY_MAC_UNKNOWN; $port_add["ifaddr"] = $discovery->IP; $port_add['ifmac'] = $discovery->MAC; $port_add['name'] = $discovery->NETPORTVENDOR; $port_ID = $np->add($port_add); unset($port_add); } else { # Update device //echo "discovery_criteria :".$discovery_criteria; $a_device = explode("||", $discovery_criteria); // $a_device[0] == id, $a_device[1] = type $ci = new commonitem(); $ci->getFromDB($a_device[1], $a_device[0]); $a_lockable = PluginFusioninventoryLock::getLockFields($a_device[1], $a_device[0]); $data = array(); $data['ID'] = $ci->getField('ID'); if ($a_device[1] == PLUGIN_FUSIONINVENTORY_MAC_UNKNOWN) { $data['FK_snmp_connection'] = 0; if ($ci->getField('name') && !in_array('name', $a_lockable)) { if (!empty($discovery->NETBIOSNAME)) { $data['name'] = $discovery->NETBIOSNAME; } else { if (!empty($discovery->SNMPHOSTNAME)) { $data['name'] = $discovery->SNMPHOSTNAME; } } } if ($ci->getField('dnsname') && !in_array('dnsname', $a_lockable)) { $data['dnsname'] = $discovery->DNSHOSTNAME; } if ($ci->getField('FK_entities') && !in_array('FK_entities', $a_lockable)) { $data['FK_entities'] = $discovery->ENTITY; } if ($ci->getField('serial') && !in_array('serial', $a_lockable)) { $data['serial'] = $discovery->SERIAL; } if ($ci->getField('contact') && !in_array('contact', $a_lockable)) { $data['contact'] = $discovery->USERSESSION; } if ($ci->getField('domain') && !in_array('domain', $a_lockable)) { $data['domain'] = 0; if (!empty($discovery->WORKGROUP)) { $data['domain'] = Dropdown::importExternal("Domain", $discovery->WORKGROUP, $discovery->ENTITY); } } if ($ci->getField('FK_snmp_connection') && !in_array('FK_snmp_connection', $a_lockable)) { $data['FK_snmp_connection'] = $discovery->AUTHSNMP; } if ($ci->getField('snmp') && !in_array('snmp', $a_lockable)) { $data['snmp'] = 0; if ($discovery->AUTHSNMP != "") { $data['snmp'] = 1; } } $data['type'] = $discovery->TYPE; $explodeprocess = explode("/", $_SESSION['glpi_plugin_fusioninventory_processnumber']); $data['FK_agent'] = intval($explodeprocess[1]); } if ($ci->getField('FK_model_infos') && !in_array('FK_model_infos', $a_lockable)) { $data['FK_model_infos'] = $FK_model; } if ($ci->getField('comments') && !in_array('comments', $a_lockable)) { $data['comments'] = $discovery->DESCRIPTION; } if ($a_device[1] == NETWORKING_TYPE) { if (!in_array('ifaddr', $a_lockable)) { $data["ifaddr"] = $discovery->IP; } if (!in_array('ifmac', $a_lockable)) { $data['ifmac'] = $discovery->MAC; } } else { // TODO: manage ports $np = new Netport(); $query = "SELECT ID FROM glpi_networking_ports\n WHERE (on_device = '" . $a_device[0] . "' AND device_type = '" . $a_device[1] . "')\n AND `ifaddr` NOT IN ('', '127.0.0.1')\n ORDER BY name, logical_number"; if ($result = $DB->query($query)) { if ($DB->numrows($result) == 1) { $data2 = $DB->fetch_assoc($result); $np->getFromDB($data2["ID"]); $port = array(); $port['ID'] = $data2["ID"]; $port["ifaddr"] = $discovery->IP; $port['ifmac'] = $discovery->MAC; $port['name'] = $discovery->NETPORTVENDOR; $np->update($port); } else { if ($DB->numrows($result) > 1) { $ptae = new PluginFusioninventoryAgentsErrors(); $error_input['ID'] = $a_device[0]; $error_input['TYPE'] = $a_device[1]; $error_input['MESSAGE'] = 'Unable to determine network port of device to update with values : ' . $discovery->IP . '(ip), ' . $discovery->MAC . '(mac), ' . $discovery->NETPORTVENDOR . '(name)'; $error_input['agent_type'] = 'NETDISCOVERY'; $ptae->addError($error_input); } } } } $ci->obj->update($data); $ptap->updateProcess($_SESSION['glpi_plugin_fusioninventory_processnumber'], array('discovery_nb_exists' => '1')); } } }
file_put_contents(GLPI_PLUGIN_DOC_DIR . "/fusioninventory/dial.log" . rand(), gzuncompress($GLOBALS["HTTP_RAW_POST_DATA"])); $state = $ptc->importToken(gzuncompress($GLOBALS["HTTP_RAW_POST_DATA"])); if ($state == '2') { // agent created $ocsinventory = '1'; } $top0 = gettimeofday(); if (!$ptc->import(gzuncompress($GLOBALS["HTTP_RAW_POST_DATA"]))) { //if ($ac->connectionOK($errors)) { if (1) { $res .= "1'" . $errors . "'"; $p_xml = gzuncompress($GLOBALS["HTTP_RAW_POST_DATA"]); $pxml = @simplexml_load_string($p_xml); if (isset($pxml->DEVICEID)) { $ptc->setXML("<?xml version='1.0' encoding='ISO-8859-1'?>\n<REPLY>\n</REPLY>"); $pta = new PluginFusioninventoryAgents(); $ptt = new PluginFusioninventoryTask(); $ptcm = new PluginFusioninventoryConfigModules(); $a_agent = $pta->InfosByKey($pxml->DEVICEID); $a_tasks = $ptt->find("`agent_id`='" . $a_agent['ID'] . "'", "date"); $single = 0; $_SESSION['glpi_plugin_fusioninventory_addagentprocess'] = '0'; foreach ($a_tasks as $task_id => $datas) { if ($a_tasks[$task_id]['action'] == 'INVENTORY' and $ptcm->isActivated('inventoryocs') and $a_agent['module_inventory'] == '1') { $ptc->addInventory(); $input['ID'] = $task_id; $ptt->delete($input); $ocsinventory = '0'; $single = 1; } if ($a_tasks[$task_id]['action'] == 'NETDISCOVERY' and $ptcm->isActivated('netdiscovery') and $a_agent['module_netdiscovery'] == '1') {
the Free Software Foundation; either version 2 of the License, or (at your option) any later version. GLPI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ------------------------------------------------------------------------ */ // Original Author of file: David DURIEUX // Purpose of file: // ---------------------------------------------------------------------- if (!defined('GLPI_ROOT')) { define('GLPI_ROOT', '../../..'); } $NEEDED_ITEMS = array("fusioninventory"); include GLPI_ROOT . "/inc/includes.php"; PluginFusioninventoryAuth::checkRight("snmp_agent", "r"); $agents = new PluginFusioninventoryAgents(); header("Expires: 0"); header("Cache-control: private"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Description: File Transfer"); header('Content-type: application/xml; charset="utf-8"', true); header("Content-disposition: attachment; filename=fusioninventory_agent.conf"); echo $agents->export_config($_GET["agent"]); //commonFooter();
function addWakeonlan($pxml) { $pta = new PluginFusioninventoryAgents(); $ptt = new PluginFusioninventoryTask(); $np = new Netport(); $agent = $pta->InfosByKey($pxml->DEVICEID); $sxml_option = $this->sxml->addChild('OPTION'); $sxml_option->addChild('NAME', 'WAKEONLAN'); $tasks = $ptt->ListTask($agent["ID"], "WAKEONLAN"); foreach ($tasks as $task_id => $taskInfos) { if ($taskInfos['device_type'] == COMPUTER_TYPE) { $a_portsList = $np->find('on_device=' . $taskInfos['on_device'] . ' AND device_type="' . COMPUTER_TYPE . '"'); foreach ($a_portsList as $ID => $data) { if ($data['ifaddr'] != "127.0.0.1") { $sxml_param = $sxml_option->addChild('PARAM'); $sxml_param->addAttribute('MAC', $data['ifmac']); $sxml_param->addAttribute('IP', $data['ifaddr']); } } } } }