/** * Import data * * @param $p_DEVICEID XML code to import * @param $p_CONTENT XML code to import * @param $p_xml value XML code to import * * @return "" (import ok) / error string (import ko) * **/ function import($p_DEVICEID, $a_CONTENT, $arrayinventory) { $pfTaskjobstate = new PluginFusioninventoryTaskjobstate(); $pfAgent = new PluginFusioninventoryAgent(); PluginFusioninventoryCommunication::addLog('Function PluginFusioninventoryCommunicationNetworkDiscovery->import().'); $errors = ''; $a_agent = $pfAgent->InfosByKey($p_DEVICEID); if (isset($a_CONTENT['PROCESSNUMBER'])) { $_SESSION['glpi_plugin_fusioninventory_processnumber'] = $a_CONTENT['PROCESSNUMBER']; if ($pfTaskjobstate->getFromDB($a_CONTENT['PROCESSNUMBER'])) { if ($pfTaskjobstate->fields['state'] != "3") { $pfTaskjobstate->changeStatus($a_CONTENT['PROCESSNUMBER'], 2); if (!isset($a_CONTENT['AGENT']['START']) and !isset($a_CONTENT['AGENT']['END'])) { $nb_devices = 0; if (isset($a_CONTENT['DEVICE'])) { if (is_int(key($a_CONTENT['DEVICE']))) { $nb_devices = count($a_CONTENT['DEVICE']); } else { $nb_devices = 1; } } $_SESSION['plugin_fusinvsnmp_taskjoblog']['taskjobs_id'] = $a_CONTENT['PROCESSNUMBER']; $_SESSION['plugin_fusinvsnmp_taskjoblog']['items_id'] = $a_agent['id']; $_SESSION['plugin_fusinvsnmp_taskjoblog']['itemtype'] = 'PluginFusioninventoryAgent'; $_SESSION['plugin_fusinvsnmp_taskjoblog']['state'] = '6'; $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = $nb_devices . ' ==devicesfound=='; $this->addtaskjoblog(); } } } } if ($pfTaskjobstate->getFromDB($a_CONTENT['PROCESSNUMBER'])) { if ($pfTaskjobstate->fields['state'] != "3") { $pfImportExport = new PluginFusioninventorySnmpmodelImportExport(); $errors .= $pfImportExport->import_netdiscovery($a_CONTENT, $p_DEVICEID); if (isset($a_CONTENT['AGENT']['END'])) { if (isset($a_CONTENT['DICO']) and $a_CONTENT['DICO'] == "REQUEST") { $pfAgent->getFromDB($pfTaskjobstate->fields["plugin_fusioninventory_agents_id"]); $input = array(); $input['id'] = $pfAgent->fields['id']; $input["senddico"] = "1"; $pfAgent->update($input); $pfTaskjobstate->changeStatusFinish($a_CONTENT['PROCESSNUMBER'], $a_agent['id'], 'PluginFusioninventoryAgent', '1', '==diconotuptodate=='); } else { $messages = array('Total Found' => 0, 'Created' => 0, 'Updated' => 0); $messages['Updated'] = countElementsInTable('glpi_plugin_fusioninventory_taskjoblogs', "`plugin_fusioninventory_taskjobstates_id`='" . $a_CONTENT['PROCESSNUMBER'] . "' " . " AND `comment` LIKE '%==updatetheitem==%'"); $messages['Created'] = countElementsInTable('glpi_plugin_fusioninventory_taskjoblogs', "`plugin_fusioninventory_taskjobstates_id`='" . $a_CONTENT['PROCESSNUMBER'] . "' " . " AND `comment` LIKE '%==addtheitem==%'"); $messages['Total Found'] = $messages['Updated'] + $messages['Created']; $message = 'Total Found:' . $messages['Total Found'] . ' Created:' . $messages['Created'] . ' Updated:' . $messages['Updated']; $pfTaskjobstate->changeStatusFinish($a_CONTENT['PROCESSNUMBER'], $a_agent['id'], 'PluginFusioninventoryAgent', '0', $message); } } } } return $errors; }
function run($jobstate) { $pfAgent = new PluginFusioninventoryAgent(); $pfTaskjobstate = new PluginFusioninventoryTaskjobstate(); $pfTaskjob = new PluginFusioninventoryTaskjob(); $pfTaskjoblog = new PluginFusioninventoryTaskjoblog(); $pfIPRange = new PluginFusioninventoryIPRange(); $pfConfigSecurity = new PluginFusioninventoryConfigSecurity(); $pfToolbox = new PluginFusioninventoryToolbox(); $pfAgent->getFromDB($jobstate->fields['plugin_fusioninventory_agents_id']); $sxml_option = $this->message->addChild('OPTION'); $sxml_option->addChild('NAME', 'NETDISCOVERY'); $a_versions = importArrayFromDB($pfAgent->fields["version"]); // * Disabled by David Durieux, I think it's not required now * // // if (((isset($a_versions["NETWORKDISCOVERY"])) AND ($a_versions["NETWORKDISCOVERY"] >= 1.3)) // OR !isset($a_versions["NETWORKDISCOVERY"])) { // if (!file_exists(GLPI_PLUGIN_DOC_DIR."/fusioninventory/discovery.xml")) { // PluginFusioninventorySnmpmodelImportExport::exportDictionnaryFile(FALSE); // } // $sxml_option->addChild('DICOHASH', // md5_file(GLPI_PLUGIN_DOC_DIR."/fusioninventory/discovery.xml")); // } // if (($pfAgent->fields["senddico"] == "1")) { // // if (((isset($a_versions["NETWORKDISCOVERY"])) // AND ($a_versions["NETWORKDISCOVERY"] >= 1.3))) { // // $sxml_option->addChild('DICO', // file_get_contents( // GLPI_PLUGIN_DOC_DIR."/fusioninventory/discovery.xml")); // } // $input = array(); // $input['id'] = $pfAgent->fields['id']; // $input["senddico"] = "0"; // $pfAgent->update($input); // } $sxml_param = $sxml_option->addChild('PARAM'); $sxml_param->addAttribute('THREADS_DISCOVERY', $pfAgent->fields["threads_networkdiscovery"]); $sxml_param->addAttribute('TIMEOUT', $pfAgent->fields["timeout_networkdiscovery"]); $sxml_param->addAttribute('PID', $jobstate->fields['id']); $changestate = 0; //foreach ($a_Taskjobstates as $taskjobstate) { $taskjobstatedatas = $jobstate->fields; $sxml_rangeip = $sxml_option->addChild('RANGEIP'); $pfTaskjob->getFromDB($taskjobstatedatas['plugin_fusioninventory_taskjobs_id']); $pfTaskjobstate->getFromDB($taskjobstatedatas['id']); $pfIPRange->getFromDB($taskjobstatedatas['items_id']); $sxml_rangeip->addAttribute('ID', $pfIPRange->fields['id']); if (!is_null($pfTaskjobstate->fields['specificity'])) { $a_split = explode("-", $pfTaskjobstate->fields['specificity']); $first_ip = $pfIPRange->getIp2long($pfIPRange->fields["ip_start"]); $last_ip = long2ip($first_ip + $a_split[1]); $first_ip = long2ip($first_ip + $a_split[0]); if ($first_ip != '0.0.0.0' && $last_ip != '0.0.0.0') { $sxml_rangeip->addAttribute('IPSTART', $first_ip); $sxml_rangeip->addAttribute('IPEND', $last_ip); } } else { $sxml_rangeip->addAttribute('IPSTART', $pfIPRange->fields["ip_start"]); $sxml_rangeip->addAttribute('IPEND', $pfIPRange->fields["ip_end"]); } $sxml_rangeip->addAttribute('ENTITY', $pfIPRange->fields["entities_id"]); if ($changestate == '0') { $pfTaskjobstate->changeStatus($pfTaskjobstate->fields['id'], 1); $pfTaskjoblog->addTaskjoblog($pfTaskjobstate->fields['id'], '0', 'PluginFusioninventoryAgent', '1', $pfAgent->fields["threads_networkdiscovery"] . ' threads', $pfAgent->fields["timeout_networkdiscovery"] . ' timeout'); $changestate = $pfTaskjobstate->fields['id']; } else { $pfTaskjobstate->changeStatusFinish($pfTaskjobstate->fields['id'], $taskjobstatedatas['items_id'], $taskjobstatedatas['itemtype'], 0, "Merged with " . $changestate); } //} $pfIPRange_ConfigSecurity = new PluginFusioninventoryIPRange_ConfigSecurity(); $a_auths = $pfIPRange_ConfigSecurity->find("`plugin_fusioninventory_ipranges_id`='" . $pfIPRange->fields['id'] . "'", "rank"); foreach ($a_auths as $dataAuth) { $pfToolbox->addAuth($sxml_option, $dataAuth['plugin_fusioninventory_configsecurities_id']); } return $this->message; }
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; }
// ?action=setAnswer&InformationSource=0x00000000&BIOSVersion=VirtualBox&SystemManufacturer=innotek%20GmbH&uuid=fepjhoug56743h&SystemProductName=VirtualBox&BIOSReleaseDate=12%2F01%2F2006 $pfTaskjobstate = new PluginFusioninventoryTaskjobstate(); $pfAgent = new PluginFusioninventoryAgent(); $jobstate = current($pfTaskjobstate->find("`uniqid`='" . $_GET['uuid'] . "'\n AND `state`!='" . PluginFusioninventoryTaskjobstate::FINISHED . "'", '', 1)); if (isset($jobstate['plugin_fusioninventory_agents_id'])) { $pfAgent->getFromDB($jobstate['plugin_fusioninventory_agents_id']); $computers_id = $pfAgent->fields['computers_id']; $a_values = $_GET; unset($a_values['action']); unset($a_values['uuid']); switch ($jobstate['itemtype']) { case 'PluginFusioninventoryCollect_Registry': // update registry content $pfCRC = new PluginFusioninventoryCollect_Registry_Content(); $pfCRC->updateComputer($computers_id, $a_values, $jobstate['items_id']); $pfTaskjobstate->changeStatus($jobstate['id'], PluginFusioninventoryTaskjobstate::AGENT_HAS_SENT_DATA); if (isset($a_values['_cpt']) && $a_values['_cpt'] == 0) { // it not find the path $pfTaskjobstate->changeStatusFinish($jobstate['id'], $jobstate['items_id'], $jobstate['itemtype'], 1, 'Path not found'); } if (isset($a_values['_cpt']) && $a_values['_cpt'] == 1) { // it last value $pfTaskjobstate->changeStatusFinish($jobstate['id'], $jobstate['items_id'], $jobstate['itemtype']); } break; case 'PluginFusioninventoryCollect_Wmi': // update registry content $pfCWC = new PluginFusioninventoryCollect_Wmi_Content(); $pfCWC->updateComputer($computers_id, $a_values, $jobstate['items_id']); $pfTaskjobstate->changeStatus($jobstate['id'], PluginFusioninventoryTaskjobstate::AGENT_HAS_SENT_DATA); if ($a_values['_cpt'] == 1) {
/** * When agent contact server, this function send datas to agent */ function run($jobstate) { $pfTaskjobstate = new PluginFusioninventoryTaskjobstate(); $pfTaskjoblog = new PluginFusioninventoryTaskjoblog(); $NetworkPort = new NetworkPort(); $sxml_option = $this->message->addChild('OPTION'); $sxml_option->addChild('NAME', 'WAKEONLAN'); $changestate = 0; // foreach ($taskjobstates as $jobstate) { $data = $jobstate->fields; $a_networkPort = $NetworkPort->find("`itemtype`='Computer' AND `items_id`='" . $data['items_id'] . "' "); $computerip = 0; foreach ($a_networkPort as $datanetwork) { //if ($datanetwork['ip'] != "127.0.0.1") { if ($datanetwork['mac'] != '') { $computerip++; $sxml_param = $sxml_option->addChild('PARAM'); $sxml_param->addAttribute('MAC', $datanetwork['mac']); //$sxml_param->addAttribute('IP', $datanetwork['ip']); if ($changestate == '0') { $pfTaskjobstate->changeStatus($data['id'], 1); $pfTaskjoblog->addTaskjoblog($data['id'], '0', 'Computer', '1', ''); $changestate = $pfTaskjobstate->fields['id']; } else { $pfTaskjobstate->changeStatusFinish($data['id'], $data['items_id'], $data['itemtype'], 0, "Merged with " . $changestate); } // Update taskjobstate (state = 3 : finish); Because we haven't return of agent on this action $pfTaskjobstate->changeStatusFinish($data['id'], $data['items_id'], $data['itemtype'], 0, 'WakeOnLan have not return state', 1); } //} } if ($computerip == '0') { $pfTaskjobstate->changeStatusFinish($data['id'], $data['items_id'], $data['itemtype'], 1, "No IP found on the computer"); } //} return $this->message; }