public function testSendMessageGzipCompression() { $communication = new PluginFusioninventoryCommunication(); $communication->setMessage('<foo><bar/></foo>'); $this->expectOutputString(gzencode($this->output)); $communication->sendMessage('gzip'); $headers = xdebug_get_headers(); $this->assertContains('Content-Type: application/x-compress-gzip', $headers); }
/** * Method for import XML by webservice * * @param $params array ID of the agent * @param $protocol value the communication protocol used * * @return array or error value * **/ static function loadInventory($params, $protocol) { if (isset($params['help'])) { return array('base64' => 'string, mandatory', 'help' => 'bool, optional'); } if (!isset($_SESSION['glpiID'])) { return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED); } $content = base64_decode($params['base64']); $pfCommunication = new PluginFusioninventoryCommunication(); $pfCommunication->handleOCSCommunication('', $content); $msg = __('Computer injected into GLPI', 'fusioninventory'); return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_FAILED, '', $msg); }
/** * Prepare data and send them to rule engine * * @param type $p_xml simpleXML object */ function sendCriteria($arrayinventory) { PluginFusioninventoryCommunication::addLog('Function PluginFusioninventoryCommunicationNetworkDiscovery->sendCriteria().'); if (isset($arrayinventory['MAC']) && $arrayinventory['MAC'] == "00:00:00:00:00:00") { unset($arrayinventory['MAC']); } $_SESSION['SOURCE_XMLDEVICE'] = $arrayinventory; $input = array(); // Global criterias if (isset($arrayinventory['SERIAL']) && !empty($arrayinventory['SERIAL'])) { $input['serial'] = $arrayinventory['SERIAL']; } if (isset($arrayinventory['MAC']) && !empty($arrayinventory['MAC'])) { $input['mac'][] = $arrayinventory['MAC']; } if (isset($arrayinventory['IP']) && !empty($arrayinventory['IP'])) { $input['ip'][] = $arrayinventory['IP']; } if (isset($arrayinventory['MODELSNMP']) && !empty($arrayinventory['MODELSNMP'])) { $input['model'] = $arrayinventory['MODELSNMP']; } if (isset($arrayinventory['SNMPHOSTNAME']) && !empty($arrayinventory['SNMPHOSTNAME'])) { $input['name'] = $arrayinventory['SNMPHOSTNAME']; } else { if (isset($arrayinventory['NETBIOSNAME']) && !empty($arrayinventory['NETBIOSNAME'])) { $input['name'] = $arrayinventory['NETBIOSNAME']; } else { if (isset($arrayinventory['DNSHOSTNAME']) && !empty($arrayinventory['DNSHOSTNAME'])) { if (strpos($arrayinventory['DNSHOSTNAME'], '.') !== false) { $splitname = explode('.', $arrayinventory['DNSHOSTNAME']); $input['name'] = $splitname[0]; if (!isset($arrayinventory['WORKGROUP'])) { unset($splitname[0]); $arrayinventory['WORKGROUP'] = implode('.', $splitname); $_SESSION['SOURCE_XMLDEVICE'] = $arrayinventory; } } else { $input['name'] = $arrayinventory['DNSHOSTNAME']; } } } } if (!isset($arrayinventory['ENTITY'])) { $arrayinventory['ENTITY'] = 0; } $input['entities_id'] = $arrayinventory['ENTITY']; if (isset($arrayinventory['TYPE'])) { switch ($arrayinventory['TYPE']) { case '1': case 'COMPUTER': $input['itemtype'] = "Computer"; // Computer break; case '2': case 'NETWORKING': $input['itemtype'] = "NetworkEquipment"; break; case '3': case 'PRINTER': $input['itemtype'] = "Printer"; break; } } $_SESSION['plugin_fusinvsnmp_datacriteria'] = serialize($input); $_SESSION['plugin_fusioninventory_classrulepassed'] = "PluginFusioninventoryCommunicationNetworkDiscovery"; $rule = new PluginFusioninventoryInventoryRuleImportCollection(); $data = $rule->processAllRules($input, array()); PluginFusioninventoryConfig::logIfExtradebug("pluginFusioninventory-rules", $data); if (isset($data['action']) && $data['action'] == PluginFusioninventoryInventoryRuleImport::LINK_RESULT_DENIED) { $a_text = ''; foreach ($input as $key => $data) { if (is_array($data)) { $a_text[] = "[" . $key . "]:" . implode(", ", $data); } else { $a_text[] = "[" . $key . "]:" . $data; } } $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = '==importdenied== ' . implode(", ", $a_text); $this->addtaskjoblog(); $pfIgnoredimport = new PluginFusioninventoryIgnoredimportdevice(); $inputdb = array(); if (isset($input['name'])) { $inputdb['name'] = $input['name']; } $inputdb['date'] = date("Y-m-d H:i:s"); if (isset($input['itemtype'])) { $inputdb['itemtype'] = $input['itemtype']; } if (isset($input['serial'])) { $input['serial'] = $input['serial']; } if (isset($input['ip'])) { $inputdb['ip'] = exportArrayToDB($input['ip']); } if (isset($input['mac'])) { $inputdb['mac'] = exportArrayToDB($input['mac']); } if (isset($input['uuid'])) { $inputdb['uuid'] = $input['uuid']; } $inputdb['rules_id'] = $_SESSION['plugin_fusioninventory_rules_id']; $inputdb['method'] = 'netdiscovery'; $pfIgnoredimport->add($inputdb); unset($_SESSION['plugin_fusioninventory_rules_id']); } if (isset($data['_no_rule_matches']) and $data['_no_rule_matches'] == '1') { if (!isset($_SESSION['glpiactiveentities_string'])) { $_SESSION['glpiactiveentities_string'] = "'" . $input['entities_id'] . "'"; } if (isset($input['itemtype']) && isset($data['action']) && $data['action'] == PluginFusioninventoryInventoryRuleImport::LINK_RESULT_CREATE) { $this->rulepassed(0, $input['itemtype'], $input['entities_id']); } else { if (isset($input['itemtype']) and !isset($data['action'])) { $this->rulepassed(0, $input['itemtype'], $input['entities_id']); } else { $this->rulepassed(0, "PluginFusioninventoryUnmanaged", $input['entities_id']); } } } }
@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"; Html::header(__('FusionInventory', 'fusioninventory'), $_SERVER["PHP_SELF"], "plugins", "pluginfusioninventorymenu", "inventorycomputerimportxml"); Session::checkRight('plugin_fusioninventory_importxml', CREATE); PluginFusioninventoryMenu::displayMenu("mini"); $pfCommunication = new PluginFusioninventoryCommunication(); if (isset($_FILES['importfile']) && $_FILES['importfile']['tmp_name'] != '') { error_log($_FILES['importfile']['name']); ini_set("memory_limit", "-1"); ini_set("max_execution_time", "0"); if (preg_match('/\\.zip/i', $_FILES['importfile']['name'])) { $zip = zip_open($_FILES['importfile']['tmp_name']); if (!$zip) { error_log("Zip failure"); $_SESSION["MESSAGE_AFTER_REDIRECT"] = __("Can't read zip file!", 'fusioninventory'); } else { error_log("Zip ok"); while ($zip_entry = zip_read($zip)) { if (zip_entry_open($zip, $zip_entry, "r")) { $xml = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); error_log("toto");
/** * @test */ public function PrinterToInventoryWithoutIP() { self::restore_database(); $printer = new Printer(); $networkport = new NetworkPort(); $networkName = new NetworkName(); $pfPrinter = new PluginFusioninventoryPrinter(); $pfTask = new PluginFusioninventoryTask(); $pfTaskjob = new PluginFusioninventoryTaskjob(); $computer = new Computer(); $pfAgent = new PluginFusioninventoryAgent(); $communication = new PluginFusioninventoryCommunication(); // Create computers + agents $input = array('entities_id' => 0, 'name' => 'computer1'); $computers_id = $computer->add($input); $input = array('entities_id' => 0, 'name' => 'computer1', 'version' => '{"INVENTORY":"v2.3.11"}', 'device_id' => 'computer1', 'useragent' => 'FusionInventory-Agent_v2.3.11', 'computers_id' => $computers_id); $pfAgent->add($input); // Create printer $input = array('name' => 'printer 001', 'entities_id' => 0); $printers_id = $printer->add($input); // Add port $networkports_id = $networkport->add(array('itemtype' => 'Printer', 'instantiation_type' => 'NetworkPortEthernet', 'items_id' => $printers_id, 'entities_id' => 0)); $networknames_id = $networkName->add(array('entities_id' => 0, 'itemtype' => 'NetworkPort', 'items_id' => $networkports_id)); $input = array('printers_id' => 1, 'plugin_fusioninventory_configsecurities_id' => 2); $pfPrinter->add($input); // Add task // create task $input = array('entities_id' => 0, 'name' => 'network inventory', 'is_active' => 1); $tasks_id = $pfTask->add($input); // create taskjob $input = array('plugin_fusioninventory_tasks_id' => $tasks_id, 'entities_id' => 0, 'name' => 'inventory', 'method' => 'networkinventory', 'targets' => '[{"Printer":"' . $printers_id . '"}]', 'actors' => '[{"PluginFusioninventoryAgent":"1"}]'); $pfTaskjob->add($input); PluginFusioninventoryTask::cronTaskscheduler(); $data = $pfTask->getJoblogs(array(1)); // Task is prepared // Agent will get data $communication->getTaskAgent(1); $message = $communication->getMessage(); $json = json_encode($message); $array = json_decode($json, TRUE); $ref = array(); $this->assertEquals($ref, $array, 'XML of SNMP inventory task'); }
$_SESSION['glpi_use_mode'] = Session::NORMAL_MODE; if (!isset($_SESSION['glpilanguage'])) { $_SESSION['glpilanguage'] = 'fr_FR'; } $_SESSION['glpi_fusionionventory_nolock'] = TRUE; ini_set('display_errors', 'On'); error_reporting(E_ALL | E_STRICT); set_error_handler(array('Toolbox', 'userErrorHandlerDebug')); $_SESSION['glpi_use_mode'] = 0; $_SESSION['glpiparententities'] = ''; $_SESSION['glpishowallentities'] = TRUE; ob_end_clean(); header("server-type: glpi/fusioninventory " . PLUGIN_FUSIONINVENTORY_VERSION); if (!class_exists("PluginFusioninventoryConfig")) { header("Content-Type: application/xml"); echo "<?xml version='1.0' encoding='UTF-8'?>\n<REPLY>\n <ERROR>Plugin FusionInventory not installed!</ERROR>\n</REPLY>"; session_destroy(); exit; } $pfCommunication = new PluginFusioninventoryCommunication(); if (!isset($rawdata)) { $rawdata = file_get_contents("php://input"); } if (isset($_GET['action']) && isset($_GET['machineid'])) { PluginFusioninventoryCommunicationRest::handleFusionCommunication(); } else { if (!empty($rawdata)) { $pfCommunication->handleOCSCommunication($rawdata); } } session_destroy();
/** * If rule have found computer or rule give to create computer * * @param $items_id integer id of the computer found (or 0 if must be created) * @param $itemtype value Computer type here * * @return nothing * **/ function rulepassed($items_id, $itemtype) { global $DB, $PLUGIN_FUSIONINVENTORY_XML, $PF_ESXINVENTORY, $CFG_GLPI; PluginFusioninventoryToolbox::logIfExtradebug("pluginFusioninventory-rules", "Rule passed : " . $items_id . ", " . $itemtype . "\n"); $pfFormatconvert = new PluginFusioninventoryFormatconvert(); $a_computerinventory = $pfFormatconvert->replaceids($this->arrayinventory); $entities_id = $_SESSION["plugin_fusioninventory_entity"]; if ($itemtype == 'Computer') { $pfInventoryComputerLib = new PluginFusioninventoryInventoryComputerLib(); $pfAgent = new PluginFusioninventoryAgent(); $computer = new Computer(); if ($items_id == '0') { if ($entities_id == -1) { $entities_id = 0; $_SESSION["plugin_fusioninventory_entity"] = 0; } $_SESSION['glpiactiveentities'] = array($entities_id); $_SESSION['glpiactiveentities_string'] = $entities_id; $_SESSION['glpiactive_entity'] = $entities_id; } else { $computer->getFromDB($items_id); $a_computerinventory['Computer']['states_id'] = $computer->fields['states_id']; $input = array(); PluginFusioninventoryInventoryComputerInventory::addDefaultStateIfNeeded($input); if (isset($input['states_id'])) { $a_computerinventory['Computer']['states_id'] = $input['states_id']; } if ($entities_id == -1) { $entities_id = $computer->fields['entities_id']; $_SESSION["plugin_fusioninventory_entity"] = $computer->fields['entities_id']; } $_SESSION['glpiactiveentities'] = array($entities_id); $_SESSION['glpiactiveentities_string'] = $entities_id; $_SESSION['glpiactive_entity'] = $entities_id; if ($computer->fields['entities_id'] != $entities_id) { $pfEntity = new PluginFusioninventoryEntity(); $pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer(); $moveentity = FALSE; if ($pfEntity->getValue('transfers_id_auto', $computer->fields['entities_id']) > 0) { if (!$pfInventoryComputerComputer->getLock($items_id)) { $moveentity = TRUE; } } if ($moveentity) { $pfEntity = new PluginFusioninventoryEntity(); $transfer = new Transfer(); $transfer->getFromDB($pfEntity->getValue('transfers_id_auto', $entities_id)); $item_to_transfer = array("Computer" => array($items_id => $items_id)); $transfer->moveItems($item_to_transfer, $entities_id, $transfer->fields); } else { $_SESSION["plugin_fusioninventory_entity"] = $computer->fields['entities_id']; $_SESSION['glpiactiveentities'] = array($computer->fields['entities_id']); $_SESSION['glpiactiveentities_string'] = $computer->fields['entities_id']; $_SESSION['glpiactive_entity'] = $computer->fields['entities_id']; $entities_id = $computer->fields['entities_id']; } } } $a_computerinventory = $pfFormatconvert->extraCollectInfo($a_computerinventory, $items_id); $a_computerinventory = $pfFormatconvert->computerSoftwareTransformation($a_computerinventory, $entities_id); $no_history = FALSE; // * New $setdynamic = 1; if ($items_id == '0') { $input = array(); $input['entities_id'] = $entities_id; PluginFusioninventoryInventoryComputerInventory::addDefaultStateIfNeeded($input); if (isset($input['states_id'])) { $a_computerinventory['Computer']['states_id'] = $input['states_id']; } else { $a_computerinventory['Computer']['states_id'] = 0; } $items_id = $computer->add($input); $no_history = TRUE; $setdynamic = 0; } if (isset($_SESSION['plugin_fusioninventory_locations_id'])) { $a_computerinventory['Computer']['locations_id'] = $_SESSION['plugin_fusioninventory_locations_id']; unset($_SESSION['plugin_fusioninventory_locations_id']); } $serialized = gzcompress(serialize($a_computerinventory)); $a_computerinventory['fusioninventorycomputer']['serialized_inventory'] = Toolbox::addslashes_deep($serialized); if (!$PF_ESXINVENTORY) { $pfAgent->setAgentWithComputerid($items_id, $this->device_id, $entities_id); } $pfConfig = new PluginFusioninventoryConfig(); $query = "INSERT INTO `glpi_plugin_fusioninventory_dblockinventories`\n SET `value`='" . $items_id . "'"; $CFG_GLPI["use_log_in_files"] = FALSE; if (!$DB->query($query)) { $communication = new PluginFusioninventoryCommunication(); $communication->setMessage("<?xml version='1.0' encoding='UTF-8'?>\n <REPLY>\n <ERROR>ERROR: SAME COMPUTER IS CURRENTLY UPDATED</ERROR>\n </REPLY>"); $communication->sendMessage($_SESSION['plugin_fusioninventory_compressmode']); exit; } $CFG_GLPI["use_log_in_files"] = TRUE; // * For benchs //$start = microtime(TRUE); PluginFusioninventoryInventoryComputerStat::increment(); $pfInventoryComputerLib->updateComputer($a_computerinventory, $items_id, $no_history, $setdynamic); $query = "DELETE FROM `glpi_plugin_fusioninventory_dblockinventories`\n WHERE `value`='" . $items_id . "'"; $DB->query($query); $plugin = new Plugin(); if ($plugin->isActivated('monitoring')) { Plugin::doOneHook("monitoring", "ReplayRulesForItem", array('Computer', $items_id)); } // * For benchs //Toolbox::logInFile("exetime", (microtime(TRUE) - $start)." (".$items_id.")\n". // memory_get_usage()."\n". // memory_get_usage(TRUE)."\n". // memory_get_peak_usage()."\n". // memory_get_peak_usage()."\n"); if (isset($_SESSION['plugin_fusioninventory_rules_id'])) { $pfRulematchedlog = new PluginFusioninventoryRulematchedlog(); $inputrulelog = array(); $inputrulelog['date'] = date('Y-m-d H:i:s'); $inputrulelog['rules_id'] = $_SESSION['plugin_fusioninventory_rules_id']; if (isset($_SESSION['plugin_fusioninventory_agents_id'])) { $inputrulelog['plugin_fusioninventory_agents_id'] = $_SESSION['plugin_fusioninventory_agents_id']; } $inputrulelog['items_id'] = $items_id; $inputrulelog['itemtype'] = $itemtype; $inputrulelog['method'] = 'inventory'; $pfRulematchedlog->add($inputrulelog, array(), FALSE); $pfRulematchedlog->cleanOlddata($items_id, $itemtype); unset($_SESSION['plugin_fusioninventory_rules_id']); } // Write XML file if (!empty($PLUGIN_FUSIONINVENTORY_XML)) { PluginFusioninventoryToolbox::writeXML($items_id, $PLUGIN_FUSIONINVENTORY_XML->asXML(), 'computer'); } } else { if ($itemtype == 'PluginFusioninventoryUnmanaged') { $a_computerinventory = $pfFormatconvert->computerSoftwareTransformation($a_computerinventory, $entities_id); $class = new $itemtype(); if ($items_id == "0") { if ($entities_id == -1) { $entities_id = 0; $_SESSION["plugin_fusioninventory_entity"] = 0; } $input = array(); $input['date_mod'] = date("Y-m-d H:i:s"); $items_id = $class->add($input); if (isset($_SESSION['plugin_fusioninventory_rules_id'])) { $pfRulematchedlog = new PluginFusioninventoryRulematchedlog(); $inputrulelog = array(); $inputrulelog['date'] = date('Y-m-d H:i:s'); $inputrulelog['rules_id'] = $_SESSION['plugin_fusioninventory_rules_id']; if (isset($_SESSION['plugin_fusioninventory_agents_id'])) { $inputrulelog['plugin_fusioninventory_agents_id'] = $_SESSION['plugin_fusioninventory_agents_id']; } $inputrulelog['items_id'] = $items_id; $inputrulelog['itemtype'] = $itemtype; $inputrulelog['method'] = 'inventory'; $pfRulematchedlog->add($inputrulelog); $pfRulematchedlog->cleanOlddata($items_id, $itemtype); unset($_SESSION['plugin_fusioninventory_rules_id']); } } $class->getFromDB($items_id); $_SESSION["plugin_fusioninventory_entity"] = $class->fields['entities_id']; $input = array(); $input['id'] = $class->fields['id']; // Write XML file if (!empty($PLUGIN_FUSIONINVENTORY_XML)) { PluginFusioninventoryToolbox::writeXML($items_id, $PLUGIN_FUSIONINVENTORY_XML->asXML(), 'PluginFusioninventoryUnmanaged'); } if (isset($a_computerinventory['Computer']['name'])) { $input['name'] = $a_computerinventory['Computer']['name']; } $input['item_type'] = "Computer"; if (isset($a_computerinventory['Computer']['domains_id'])) { $input['domain'] = $a_computerinventory['Computer']['domains_id']; } if (isset($a_computerinventory['Computer']['serial'])) { $input['serial'] = $a_computerinventory['Computer']['serial']; } $class->update($input); } } }
/** * After rules import device * * @param integer $items_id id of the device in GLPI DB (0 = created, other = merge) * @param varchar $itemtype itemtype of the device * * @return type */ function rulepassed($items_id, $itemtype) { PluginFusioninventoryLogger::logIfExtradebug("pluginFusioninventory-rules", "Rule passed : " . $items_id . ", " . $itemtype . "\n"); PluginFusioninventoryLogger::logIfExtradebugAndDebugMode('fusioninventorycommunication', 'Function PluginFusinvsnmpCommunicationSNMPQuery->rulepassed().'); $_SESSION["plugin_fusioninventory_entity"] = 0; PluginFusioninventoryConfig::logIfExtradebug("pluginFusioninventory-rules", "Rule passed : " . $items_id . ", " . $itemtype . "\n"); PluginFusioninventoryCommunication::addLog('Function PluginFusioninventoryCommunicationNetworkInventory->rulepassed().'); $a_inventory = $_SESSION['SOURCE_XMLDEVICE']; $errors = ''; $class = new $itemtype(); if ($items_id == "0") { $input = array(); $input['date_mod'] = date("Y-m-d H:i:s"); if ($class->getFromDB($a_inventory[$a_inventory['itemtype']]['id'])) { $input['entities_id'] = $class->fields['entities_id']; } else { $input['entities_id'] = 0; } if (!isset($_SESSION['glpiactiveentities_string'])) { $_SESSION['glpiactiveentities_string'] = "'" . $input['entities_id'] . "'"; } $_SESSION["plugin_fusioninventory_entity"] = $input['entities_id']; $items_id = $class->add($input); if (isset($_SESSION['plugin_fusioninventory_rules_id'])) { $pfRulematchedlog = new PluginFusioninventoryRulematchedlog(); $inputrulelog = array(); $inputrulelog['date'] = date('Y-m-d H:i:s'); $inputrulelog['rules_id'] = $_SESSION['plugin_fusioninventory_rules_id']; if (isset($_SESSION['plugin_fusioninventory_agents_id'])) { $inputrulelog['plugin_fusioninventory_agents_id'] = $_SESSION['plugin_fusioninventory_agents_id']; } $inputrulelog['items_id'] = $items_id; $inputrulelog['itemtype'] = $itemtype; $inputrulelog['method'] = 'snmpinventory'; $pfRulematchedlog->add($inputrulelog); $pfRulematchedlog->cleanOlddata($items_id, $itemtype); unset($_SESSION['plugin_fusioninventory_rules_id']); } } if ($itemtype == "PluginFusioninventoryUnmanaged") { $class->getFromDB($items_id); $input = array(); $input['id'] = $class->fields['id']; if (!empty($a_inventory[$a_inventory['itemtype']]['name'])) { $input['name'] = $a_inventory[$a_inventory['itemtype']]['name']; } if (!empty($a_inventory[$a_inventory['itemtype']]['serial'])) { $input['serial'] = $a_inventory[$a_inventory['itemtype']]['serial']; } if (!empty($a_inventory['itemtype'])) { $input['itemtype'] = $a_inventory['itemtype']; } // TODO : add import ports PluginFusioninventoryToolbox::writeXML($items_id, serialize($_SESSION['SOURCE_XMLDEVICE']), 'PluginFusioninventoryUnmanaged'); $class->update($input); $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = '[==detail==] ==updatetheitem== Update ' . PluginFusioninventoryUnmanaged::getTypeName() . ' [[PluginFusioninventoryUnmanaged::' . $items_id . ']]'; $this->addtaskjoblog(); } else { $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = '[==detail==] Update ' . $class->getTypeName() . ' [[' . $itemtype . '::' . $items_id . ']]'; $this->addtaskjoblog(); $errors .= $this->importDevice($itemtype, $items_id, $a_inventory); } return $errors; }
function getTask($deviceid) { $pta = new PluginFusioninventoryAgents(); $ptc = new PluginFusioninventoryCommunication(); $a_agent = $pta->InfosByKey($deviceid); $a_tasks = $this->find("`agent_id`='" . $a_agent['ID'] . "'", "date"); // TODO gest last foreach ($a_tasks as $task_id => $datas) { if ($a_tasks[$task_id]['action'] == 'INVENTORY') { $ptc->addInventory(); } } // If not unique get all in addition ;) }
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: MAZZONI Vincent // Purpose of file: test of communication class // ---------------------------------------------------------------------- if (!defined('GLPI_ROOT')) { define('GLPI_ROOT', '../../..'); } $NEEDED_ITEMS = array("computer", "device", "printer", "networking", "peripheral", "monitor", "software", "infocom", "phone", "tracking", "enterprise", "reservation", "setup", "group", "registry", "rulesengine", "ocsng", "admininfo", "rule.ocs", "rule.softwarecategories", "rule.dictionnary.software", "rule.dictionnary.dropdown", "entity"); include GLPI_ROOT . "/inc/includes.php"; $_SESSION["glpi_use_mode"] = 2; $ptc = new PluginFusioninventoryCommunication(); $ptap = new PluginFusioninventoryAgentsProcesses(); $res = ''; $errors = ''; // ***** For debug only ***** // //$GLOBALS["HTTP_RAW_POST_DATA"] = gzcompress(''); // ********** End ********** // // Get conf tu know if SSL is only $fusioninventory_config = new PluginFusioninventoryConfig(); $ssl = $fusioninventory_config->getValue('ssl_only'); if (isset($_SERVER["HTTPS"]) and $_SERVER["HTTPS"] == "on" and $ssl == "1" or $ssl == "0") { // echo "On continue"; } else { $ptc->setXML("<?xml version='1.0' encoding='ISO-8859-1'?>\n<REPLY>\n</REPLY>"); $ptc->noSSL(); exit;
function import_netdiscovery($arrayinventory, $agentKey) { PluginFusioninventoryCommunication::addLog('Function PluginFusioninventorySnmpmodelImportExport->import_netdiscovery().'); $ptap = new PluginFusioninventoryStateDiscovery(); $pta = new PluginFusioninventoryAgent(); $agent = $pta->InfosByKey($agentKey); if (isset($arrayinventory['AGENT']['START'])) { $ptap->updateState($arrayinventory['PROCESSNUMBER'], array('start_time' => date("Y-m-d H:i:s")), $agent['id']); } else { if (isset($arrayinventory['AGENT']['END'])) { $ptap->updateState($arrayinventory['PROCESSNUMBER'], array('end_time' => date("Y-m-d H:i:s")), $agent['id']); } else { if (isset($arrayinventory['AGENT']['EXIT'])) { $ptap->endState($arrayinventory['PROCESSNUMBER'], date("Y-m-d H:i:s"), $agent['id']); } else { if (isset($arrayinventory['AGENT']['NBIP'])) { $ptap->updateState($arrayinventory['PROCESSNUMBER'], array('nb_ip' => $arrayinventory['AGENT']['NBIP']), $agent['id']); } } } } if (isset($arrayinventory['AGENT']['AGENTVERSION'])) { $agent['last_contact'] = date("Y-m-d H:i:s"); $pta->update($agent); } $_SESSION['glpi_plugin_fusioninventory_agentid'] = $agent['id']; $count_discovery_devices = 0; if (isset($arrayinventory['DEVICE'])) { if (is_int(key($arrayinventory['DEVICE']))) { $count_discovery_devices = count($arrayinventory['DEVICE']); } else { $count_discovery_devices = 1; } } if ($count_discovery_devices != "0") { $ptap->updateState($_SESSION['glpi_plugin_fusioninventory_processnumber'], array('nb_found' => $count_discovery_devices), $agent['id']); if (is_int(key($arrayinventory['DEVICE']))) { foreach ($arrayinventory['DEVICE'] as $discovery) { if (count($discovery) > 0) { $pfCommunicationNetworkDiscovery = new PluginFusioninventoryCommunicationNetworkDiscovery(); $pfCommunicationNetworkDiscovery->sendCriteria($discovery); } } } else { $pfCommunicationNetworkDiscovery = new PluginFusioninventoryCommunicationNetworkDiscovery(); $pfCommunicationNetworkDiscovery->sendCriteria($arrayinventory['DEVICE']); } } }
function oidList($p_sxml_node, $p_id) { global $DB; $ptc = new PluginFusioninventoryCommunication(); // oid GET $query = "SELECT * FROM `glpi_plugin_fusioninventory_mib`\n WHERE `FK_model_infos`='" . $p_id . "'\n AND `activation`='1'\n AND `oid_port_counter`='0';"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { switch ($data['oid_port_dyn']) { case 0: $ptc->addGet($p_sxml_node, $data['mapping_name'], Dropdown::getDropdownName('glpi_plugin_fusioninventory_mib_oid', $data['FK_mib_oid']), $data['mapping_name'], $data['vlan']); break; case 1: $ptc->addWalk($p_sxml_node, $data['mapping_name'], Dropdown::getDropdownName('glpi_plugin_fusioninventory_mib_oid', $data['FK_mib_oid']), $data['mapping_name'], $data['vlan']); break; } } // oid WALK }
/** * Manage communication with old protocol (XML over POST) * **/ function handleOCSCommunication($rawdata, $xml = '', $output = 'ext') { // ***** For debug only ***** // //$rawdata = gzcompress(''); // ********** End ********** // $config = new PluginFusioninventoryConfig(); $user = new User(); // ob_start(); if (!isset($_SESSION['glpiID'])) { $users_id = $config->getValue('users_id'); $_SESSION['glpiID'] = $users_id; $user->getFromDB($users_id); Session::changeActiveEntities(); $_SESSION["glpiname"] = $user->getField('name'); $_SESSION['glpiactiveprofile'] = array(); $_SESSION['glpiactiveprofile']['interface'] = 'central'; $_SESSION['glpiactiveprofile']['internet'] = 'w'; $_SESSION['glpiactiveprofile']['computer'] = 'w'; $_SESSION['glpiactiveprofile']['monitor'] = 'w'; $_SESSION['glpiactiveprofile']['printer'] = 'w'; $_SESSION['glpiactiveprofile']['peripheral'] = 'w'; $_SESSION['glpiactiveprofile']['networking'] = 'w'; $_SESSION["glpi_plugin_fusioninventory_profile"]['unmanaged'] = 'w'; } $communication = new PluginFusioninventoryCommunication(); $pfToolbox = new PluginFusioninventoryToolbox(); // identify message compression algorithm $agent = new PluginFusioninventoryAgent(); $agent->disableDebug(); $compressmode = ''; if (!empty($xml)) { $compressmode = 'none'; } else { if ($_SERVER['CONTENT_TYPE'] == "application/x-compress-zlib") { $xml = gzuncompress($rawdata); $compressmode = "zlib"; } else { if ($_SERVER['CONTENT_TYPE'] == "application/x-compress-gzip") { $xml = $pfToolbox->gzdecode($rawdata); $compressmode = "gzip"; } else { if ($_SERVER['CONTENT_TYPE'] == "application/xml") { $xml = $rawdata; $compressmode = 'none'; } else { # try each algorithm successively if ($xml = gzuncompress($rawdata)) { $compressmode = "zlib"; } else { if ($xml = $pfToolbox->gzdecode($rawdata)) { $compressmode = "gzip"; } else { if ($xml = gzinflate(substr($rawdata, 2))) { // accept deflate for OCS agent 2.0 compatibility, // but use zlib for answer if (strstr($xml, "<QUERY>PROLOG</QUERY>") and !strstr($xml, "<TOKEN>")) { $compressmode = "zlib"; } else { $compressmode = "deflate"; } } else { $xml = $rawdata; $compressmode = 'none'; } } } } } } } $agent->restoreDebug(); // check if we are in ssl only mode $ssl = $config->getValue('ssl_only'); if ($ssl == "1" and (!isset($_SERVER["HTTPS"]) or $_SERVER["HTTPS"] != "on")) { if ($output == 'glpi') { Session::addMessageAfterRedirect('SSL REQUIRED BY SERVER', false, ERROR); } else { $communication->setMessage("<?xml version='1.0' encoding='UTF-8'?>\n<REPLY>\n <ERROR>SSL REQUIRED BY SERVER</ERROR>\n</REPLY>"); $communication->sendMessage($compressmode); } return; } PluginFusioninventoryConfig::logIfExtradebug('pluginFusioninventory-dial' . uniqid(), $xml); // Check XML integrity $pxml = ''; if ($pxml = @simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)) { } else { if ($pxml = @simplexml_load_string(utf8_encode($xml), 'SimpleXMLElement', LIBXML_NOCDATA)) { $xml = utf8_encode($xml); } else { $xml = preg_replace('/<FOLDER>.*?<\\/SOURCE>/', '', $xml); $pxml = @simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); if (!$pxml) { if ($output == 'glpi') { Session::addMessageAfterRedirect('XML not well formed!', false, ERROR); } else { $communication->setMessage("<?xml version='1.0' encoding='UTF-8'?>\n<REPLY>\n <ERROR>XML not well formed!</ERROR>\n</REPLY>"); $communication->sendMessage($compressmode); } return; } } } $_SESSION['plugin_fusioninventory_compressmode'] = $compressmode; // Convert XML into PHP array $arrayinventory = PluginFusioninventoryFormatconvert::XMLtoArray($pxml); unset($pxml); $deviceid = ''; if (isset($arrayinventory['DEVICEID'])) { $deviceid = $arrayinventory['DEVICEID']; } $agent = new PluginFusioninventoryAgent(); $agents_id = $agent->importToken($arrayinventory); $_SESSION['plugin_fusioninventory_agents_id'] = $agents_id; if (!$communication->import($arrayinventory)) { if ($deviceid != '') { $communication->setMessage("<?xml version='1.0' encoding='UTF-8'?>\n<REPLY>\n</REPLY>"); $a_agent = $agent->InfosByKey($deviceid); // Get taskjob in waiting $communication->getTaskAgent($a_agent['id']); // ******** Send XML $communication->addInventory($a_agent['id']); $communication->addProlog(); $communication->sendMessage($compressmode); } } else { if ($output == 'glpi') { Session::addMessageAfterRedirect('XML has been imported succesfully!'); } else { $communication->setMessage("<?xml version='1.0' encoding='UTF-8'?>\n<REPLY>\n</REPLY>"); $communication->sendMessage($compressmode); } } }