public function testLog() { global $DB; $DB->connect(); $pfFormatconvert = new PluginFusioninventoryFormatconvert(); $computer = new Computer(); $pfiComputerLib = new PluginFusioninventoryInventoryComputerLib(); $date = date('Y-m-d H:i:s'); $_SESSION["plugin_fusioninventory_entity"] = 0; $_SESSION['glpiactiveentities_string'] = 0; $_SESSION['glpishowallentities'] = 1; $_SESSION["glpiname"] = 'Plugin_FusionInventory'; $this->a_inventory = array('fusioninventorycomputer' => array('winowner' => 'test', 'wincompany' => 'siprossii', 'operatingsystem_installationdate' => '2012-10-16 08:12:56', 'last_fusioninventory_update' => $date), 'soundcard' => array(), 'graphiccard' => array(), 'controller' => array(), 'processor' => array(), 'computerdisk' => array(), 'memory' => array(), 'monitor' => array(), 'printer' => array(), 'peripheral' => array(), 'networkport' => array(), 'SOFTWARES' => array(), 'harddrive' => array(), 'virtualmachine' => array(), 'antivirus' => array(), 'storage' => array(), 'licenseinfo' => array(), 'networkcard' => array(), 'drive' => array(), 'batteries' => array(), 'itemtype' => 'Computer'); $this->a_inventory['Computer'] = array('name' => 'pc', 'users_id' => 0, 'operatingsystems_id' => 'freebsd', 'operatingsystemversions_id' => '9.1-RELEASE', 'uuid' => '68405E00-E5BE-11DF-801C-B05981201220', 'domains_id' => 'mydomain.local', 'os_licenseid' => '', 'os_license_number' => '', 'operatingsystemservicepacks_id' => 'GENERIC ()root@farrell.cse.buffalo.edu', 'manufacturers_id' => '', 'computermodels_id' => '', 'serial' => 'XB63J7D', 'computertypes_id' => 'Notebook', 'is_dynamic' => 1, 'contact' => 'ddurieux'); $this->a_inventory['processor'] = array(array('nbcores' => 2, 'manufacturers_id' => 'Intel Corporation', 'designation' => 'Core i3', 'frequence' => 2400, 'nbthreads' => 2, 'serial' => '', 'frequency' => 2400, 'frequency_default' => 2400), array('nbcores' => 2, 'manufacturers_id' => 'Intel Corporation', 'designation' => 'Core i3', 'frequence' => 2400, 'nbthreads' => 2, 'serial' => '', 'frequency' => 2400, 'frequency_default' => 2400), array('nbcores' => 2, 'manufacturers_id' => 'Intel Corporation', 'designation' => 'Core i3', 'frequence' => 2400, 'nbthreads' => 2, 'serial' => '', 'frequency' => 2400, 'frequency_default' => 2400), array('nbcores' => 2, 'manufacturers_id' => 'Intel Corporation', 'designation' => 'Core i3', 'frequence' => 2400, 'nbthreads' => 2, 'serial' => '', 'frequency' => 2400, 'frequency_default' => 2400)); $this->a_inventory['memory'] = array(array('size' => 2048, 'serial' => '98F6FF18', 'frequence' => '1067 MHz', 'devicememorytypes_id' => 'DDR3', 'designation' => 'DDR3 - SODIMM (None)', 'busID' => 1), array('size' => 2048, 'serial' => '95F1833E', 'frequence' => '1067 MHz', 'devicememorytypes_id' => 'DDR3', 'designation' => 'DDR3 - SODIMM (None)', 'busID' => 2)); $this->a_inventory['monitor'] = array(array('name' => '', 'serial' => '', 'manufacturers_id' => '')); $this->a_inventory['networkport'] = array('em0-00:23:18:cf:0d:93' => array('name' => 'em0', 'netmask' => '255.255.255.0', 'subnet' => '192.168.30.0', 'mac' => '00:23:18:cf:0d:93', 'instantiation_type' => 'NetworkPortEthernet', 'virtualdev' => 0, 'ssid' => '', 'gateway' => '', 'dhcpserver' => '', 'logical_number' => 0, 'ipaddress' => array('192.168.30.198')), 'lo0-' => array('name' => 'lo0', 'virtualdev' => 1, 'mac' => '', 'instantiation_type' => 'NetworkPortLocal', 'subnet' => '', 'ssid' => '', 'gateway' => '', 'netmask' => '', 'dhcpserver' => '', 'logical_number' => 1, 'ipaddress' => array('::1', 'fe80::1', '127.0.0.1'))); $this->a_inventory['software'] = array('gentiumbasic$$$$110$$$$1$$$$0' => array('name' => 'GentiumBasic', 'version' => 110, 'manufacturers_id' => 1, 'entities_id' => 0, 'is_template_computer' => 0, 'is_deleted_computer' => 0, 'is_dynamic' => 1), 'imagemagick$$$$6.8.0.7_1$$$$2$$$$0' => array('name' => 'ImageMagick', 'version' => '6.8.0.7_1', 'manufacturers_id' => 2, 'entities_id' => 0, 'is_template_computer' => 0, 'is_deleted_computer' => 0, 'is_dynamic' => 1), 'orbit2$$$$2.14.19$$$$3$$$$0' => array('name' => 'ORBit2', 'version' => '2.14.19', 'manufacturers_id' => 3, 'entities_id' => 0, 'is_template_computer' => 0, 'is_deleted_computer' => 0, 'is_dynamic' => 1)); $this->a_inventory = $pfFormatconvert->replaceids($this->a_inventory); $serialized = gzcompress(serialize($this->a_inventory)); $this->a_inventory['fusioninventorycomputer']['serialized_inventory'] = Toolbox::addslashes_deep($serialized); $computer->add(array('serial' => 'XB63J7D', 'entities_id' => 0)); // truncate glpi_logs $DB->query('TRUNCATE TABLE `glpi_logs`;'); $this->assertEquals(0, countElementsInTable('glpi_logs'), "Log must be empty (truncate)"); $_SESSION['glpiactive_entity'] = 0; $pfiComputerLib->updateComputer($this->a_inventory, 1, TRUE); $a_logs = getAllDatasFromTable('glpi_logs'); foreach ($a_logs as $id => $data) { unset($data['date_mod']); $a_logs[$id] = $data; } $a_reference = array(1 => array('id' => 1, 'itemtype' => 'Software', 'items_id' => 1, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''), 2 => array('id' => 2, 'itemtype' => 'Software', 'items_id' => 2, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''), 3 => array('id' => 3, 'itemtype' => 'Software', 'items_id' => 3, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''), 4 => array('id' => 4, 'itemtype' => 'SoftwareVersion', 'items_id' => 1, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''), 5 => array('id' => 5, 'itemtype' => 'SoftwareVersion', 'items_id' => 2, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''), 6 => array('id' => 6, 'itemtype' => 'SoftwareVersion', 'items_id' => 3, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => '')); $this->assertEquals($a_reference, $a_logs, "Log must be 6 " . print_r($a_logs, true)); $DB->query('TRUNCATE `glpi_logs`'); // Update a second time and must not have any new lines in glpi_logs $pfiComputerLib->updateComputer($this->a_inventory, 1, FALSE); $a_logs = getAllDatasFromTable('glpi_logs'); $a_reference = array(); $this->assertEquals($a_reference, $a_logs, "Log may be empty at second update " . print_r($a_logs, true)); // * Modify: contact // * remove a processor // * Remove a software $this->a_inventory['Computer']['contact'] = 'root'; unset($this->a_inventory['processor'][3]); unset($this->a_inventory['software']['orbit2$$$$2.14.19$$$$3$$$$0']); $DB->query('TRUNCATE `glpi_logs`'); $pfiComputerLib->updateComputer($this->a_inventory, 1, FALSE); $a_logs = getAllDatasFromTable('glpi_logs'); foreach ($a_logs as $id => $data) { unset($data['date_mod']); $a_logs[$id] = $data; } $a_reference = array(1 => array('id' => '1', 'itemtype' => 'Computer', 'items_id' => '1', 'itemtype_link' => '', 'linked_action' => '0', 'user_name' => '', 'id_search_option' => '7', 'old_value' => 'ddurieux', 'new_value' => 'root'), 2 => array('id' => '2', 'itemtype' => 'Computer', 'items_id' => '1', 'itemtype_link' => 'DeviceProcessor', 'linked_action' => '3', 'user_name' => '', 'id_search_option' => '0', 'old_value' => 'Core i3 (1)', 'new_value' => ''), 3 => array('id' => '3', 'itemtype' => 'Computer', 'items_id' => '1', 'itemtype_link' => 'SoftwareVersion', 'linked_action' => '5', 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => '0', 'old_value' => 'ORBit2 - 2.14.19 (3)', 'new_value' => ''), 4 => array('id' => '4', 'itemtype' => 'SoftwareVersion', 'items_id' => '3', 'itemtype_link' => 'Computer', 'linked_action' => '5', 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => '0', 'old_value' => 'pc (1)', 'new_value' => '')); $this->assertEquals($a_reference, $a_logs, "May have 5 logs (update contact, remove processor\n and remove a software)"); }
/** * @test */ public function PeripheralUniqueSerialimport() { global $DB; $DB->connect(); self::restore_database(); $_SESSION['glpiactive_entity'] = 0; $_SESSION["plugin_fusioninventory_entity"] = 0; $_SESSION["glpiname"] = 'Plugin_FusionInventory'; $pfConfig = new PluginFusioninventoryConfig(); $pfiComputerLib = new PluginFusioninventoryInventoryComputerLib(); $computer = new Computer(); $GLPIlog = new GLPIlogs(); $pxml = @simplexml_load_string($this->a_computer1_XML, 'SimpleXMLElement', LIBXML_NOCDATA); $arrayinventory = PluginFusioninventoryFormatconvert::XMLtoArray($pxml); $agent = new PluginFusioninventoryAgent(); $agents_id = $agent->importToken($arrayinventory); $_SESSION['plugin_fusioninventory_agents_id'] = $agents_id; $pfInventoryComputerInventory = new PluginFusioninventoryInventoryComputerInventory(); $pfInventoryComputerInventory->import('deviceid', $arrayinventory['CONTENT'], $arrayinventory); $computer->getFromDB(1); $this->assertEquals('ggheb7ne7', $computer->fields['serial'], 'Computer not updated correctly'); $a_ref = array(1 => array('name' => 'Périphérique USB composite', 'id' => '1', 'serial' => '10075973', 'peripheraltypes_id' => '0', 'peripheralmodels_id' => '0', 'manufacturers_id' => '2', 'is_global' => '0', 'is_deleted' => '0', 'is_template' => '0', 'is_dynamic' => '0'), 2 => array('name' => 'H5321 gw Mobile Broadband Device', 'id' => '2', 'serial' => '187A047919938CM0', 'peripheraltypes_id' => '0', 'peripheralmodels_id' => '0', 'manufacturers_id' => '7', 'is_global' => '0', 'is_deleted' => '0', 'is_template' => '0', 'is_dynamic' => '0'), 3 => array('name' => 'Périphérique d’entrée USB', 'id' => '3', 'serial' => 'STM32_EMOTION2', 'peripheraltypes_id' => '0', 'peripheralmodels_id' => '0', 'manufacturers_id' => '8', 'is_global' => '0', 'is_deleted' => '0', 'is_template' => '0', 'is_dynamic' => '0')); $a_db_peripherals = getAllDatasFromTable('glpi_peripherals'); foreach ($a_db_peripherals as $id => $data) { $data_temp = array('name' => $data['name'], 'id' => $data['id'], 'serial' => $data['serial'], 'peripheraltypes_id' => $data['peripheraltypes_id'], 'peripheralmodels_id' => $data['peripheralmodels_id'], 'manufacturers_id' => $data['manufacturers_id'], 'is_global' => $data['is_global'], 'is_deleted' => $data['is_deleted'], 'is_template' => $data['is_template'], 'is_dynamic' => $data['is_dynamic']); $a_db_peripherals[$id] = $data_temp; } $this->assertEquals($a_ref, $a_db_peripherals, 'List of peripherals'); // Update computer and may not have new values in glpi_logs $query = "SELECT * FROM `glpi_logs`\n ORDER BY `id` DESC LIMIT 1"; $result = $DB->query($query); $data = $DB->fetch_assoc($result); $last_id = $data['id']; $pfInventoryComputerInventory->import('deviceid', $arrayinventory['CONTENT'], $arrayinventory); $data = getAllDatasFromTable('glpi_logs', "`id`>'" . $last_id . "'"); $this->assertEquals(array(), $data, 'On update peripherals, may not have new lines in glpi_logs'); }
/** * @test */ public function SoftwareUniqueForTwoComputers() { global $DB; $DB->connect(); $date = date('Y-m-d H:i:s'); $_SESSION["plugin_fusioninventory_entity"] = 0; $_SESSION['glpiactiveentities_string'] = 0; $_SESSION['glpishowallentities'] = 1; $_SESSION["glpiname"] = 'Plugin_FusionInventory'; $a_inventory = array('fusioninventorycomputer' => array('winowner' => 'test', 'wincompany' => 'siprossii', 'operatingsystem_installationdate' => '2012-10-16 08:12:56', 'last_fusioninventory_update' => $date), 'soundcard' => array(), 'graphiccard' => array(), 'controller' => array(), 'processor' => array(), 'computerdisk' => array(), 'memory' => array(), 'monitor' => array(), 'printer' => array(), 'peripheral' => array(), 'networkport' => array(), 'SOFTWARES' => array(), 'harddrive' => array(), 'virtualmachine' => array(), 'antivirus' => array(), 'storage' => array(), 'licenseinfo' => array(), 'networkcard' => array(), 'drive' => array(), 'batteries' => array(), 'itemtype' => 'Computer'); $a_inventory['Computer'] = array('name' => 'pcJ1', 'comment' => 'amd64/-1-11-30 22:04:44', 'users_id' => 0, 'operatingsystems_id' => 'freebsd', 'operatingsystemversions_id' => '9.1-RELEASE', 'uuid' => '68405E00-E5BE-11DF-801C-B05981201220', 'domains_id' => 'mydomain.local', 'os_licenseid' => '', 'os_license_number' => '', 'operatingsystemservicepacks_id' => 'GENERIC ()root@farrell.cse.buffalo.edu', 'manufacturers_id' => '', 'computermodels_id' => '', 'serial' => 'XB63J7J1', 'computertypes_id' => 'Notebook', 'is_dynamic' => 1, 'contact' => 'ddurieux'); $a_inventory['software'] = array('acrobat_reader_9.2$$$$1.0.0.0$$$$192$$$$0' => array('name' => 'acrobat_Reader_9.2', 'version' => '1.0.0.0', 'manufacturers_id' => 192, 'entities_id' => 0, 'is_template_computer' => 0, 'is_deleted_computer' => 0)); $pfiComputerLib = new PluginFusioninventoryInventoryComputerLib(); $computer = new Computer(); $pfFormatconvert = new PluginFusioninventoryFormatconvert(); $software = new Software(); $a_inventory = $pfFormatconvert->replaceids($a_inventory); $serialized = gzcompress(serialize($a_inventory)); $a_inventory['fusioninventorycomputer']['serialized_inventory'] = Toolbox::addslashes_deep($serialized); $this->items_id = $computer->add(array('serial' => 'XB63J7J1', 'entities_id' => 0)); $_SESSION['glpiactive_entity'] = 0; $pfiComputerLib->updateComputer($a_inventory, $this->items_id, FALSE); $a_software = $software->find("`name`='acrobat_Reader_9.2'"); $this->assertEquals(1, count($a_software), "First computer added"); $a_inventory['Computer']['name'] = "pcJ2"; $a_inventory['Computer']['serial'] = "XB63J7J2"; $pfiComputerLib->updateComputer($a_inventory, $this->items_id, FALSE); $a_software = $software->find("`name`='acrobat_Reader_9.2'"); $this->assertEquals(1, count($a_software), "Second computer added"); }
static function computerInventoryTransformation($array) { global $DB, $PF_ESXINVENTORY, $CFG_GLPI; // Initialize $a_inventory = array('Computer' => array(), 'fusioninventorycomputer' => array(), 'processor' => array(), 'memory' => array(), 'harddrive' => array(), 'drive' => array(), 'graphiccard' => array(), 'networkcard' => array(), 'soundcard' => array(), 'controller' => array(), 'SOFTWARES' => array(), 'virtualmachine' => array(), 'computerdisk' => array(), 'networkport' => array(), 'antivirus' => array(), 'licenseinfo' => array(), 'batteries' => array(), 'monitor' => array(), 'printer' => array(), 'peripheral' => array(), 'storage' => array()); $thisc = new self(); $pfConfig = new PluginFusioninventoryConfig(); $ignorecontrollers = array(); if (isset($array['ACCOUNTINFO'])) { $a_inventory['ACCOUNTINFO'] = $array['ACCOUNTINFO']; } // * HARDWARE $array_tmp = $thisc->addValues($array['HARDWARE'], array('NAME' => 'name', 'OSNAME' => 'operatingsystems_id', 'OSVERSION' => 'operatingsystemversions_id', 'WINPRODID' => 'os_licenseid', 'WINPRODKEY' => 'os_license_number', 'WORKGROUP' => 'domains_id', 'UUID' => 'uuid', 'LASTLOGGEDUSER' => 'users_id', 'operatingsystemservicepacks_id' => 'operatingsystemservicepacks_id', 'manufacturers_id' => 'manufacturers_id', 'computermodels_id' => 'computermodels_id', 'serial' => 'serial', 'computertypes_id' => 'computertypes_id')); if ($array_tmp['operatingsystemservicepacks_id'] == '' && isset($array['HARDWARE']['OSCOMMENTS']) && $array['HARDWARE']['OSCOMMENTS'] != '') { $array_tmp['operatingsystemservicepacks_id'] = $array['HARDWARE']['OSCOMMENTS']; } if (isset($array_tmp['users_id'])) { if ($array_tmp['users_id'] == '') { unset($array_tmp['users_id']); } else { $array_tmp['contact'] = $array_tmp['users_id']; $tmp_users_id = $array_tmp['users_id']; $split_user = explode("@", $tmp_users_id); $query = "SELECT `id`\n FROM `glpi_users`\n WHERE `name` = '" . $split_user[0] . "'\n LIMIT 1"; $result = $DB->query($query); if ($DB->numrows($result) == 1) { $array_tmp['users_id'] = $DB->result($result, 0, 0); } else { $array_tmp['users_id'] = 0; } } } $array_tmp['is_dynamic'] = 1; $a_inventory['Computer'] = $array_tmp; $array_tmp = $thisc->addValues($array['HARDWARE'], array('OSINSTALLDATE' => 'operatingsystem_installationdate', 'WINOWNER' => 'winowner', 'WINCOMPANY' => 'wincompany')); $array_tmp['last_fusioninventory_update'] = date('Y-m-d H:i:s'); // * Determine "Public contact address" if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { // Try "X-Forwarded-For" HTTP header // Parse "X-Forwarded-For" header (can contain multiple IP addresses, client should be first) $forwarded_for_ip_tmp = explode(', ', $_SERVER['HTTP_X_FORWARDED_FOR']); $forwarded_for_ip_tmp = new IPAddress($forwarded_for_ip_tmp[0]); if ($forwarded_for_ip_tmp->is_valid()) { $array_tmp['remote_addr'] = $forwarded_for_ip_tmp->getTextual(); } } elseif (isset($_SERVER['HTTP_X_REAL_IP'])) { // Then try "X-Real-IP" HTTP header $real_ip_tmp = new IPAddress($_SERVER['HTTP_X_REAL_IP']); if ($real_ip_tmp->is_valid()) { $array_tmp['remote_addr'] = $real_ip_tmp->getTextual(); } } elseif (isset($_SERVER['REMOTE_ADDR'])) { // Fall back on the currently connected IP $array_tmp['remote_addr'] = $_SERVER['REMOTE_ADDR']; } $a_inventory['fusioninventorycomputer'] = $array_tmp; if (isset($array['OPERATINGSYSTEM']['INSTALL_DATE']) && !empty($array['OPERATINGSYSTEM']['INSTALL_DATE'])) { $a_inventory['fusioninventorycomputer']['operatingsystem_installationdate'] = $array['OPERATINGSYSTEM']['INSTALL_DATE']; } if (isset($array['HARDWARE']['DESCRIPTION'])) { $a_inventory['fusioninventorycomputer']['oscomment'] = $array['HARDWARE']['DESCRIPTION']; } if (empty($a_inventory['fusioninventorycomputer']['operatingsystem_installationdate'])) { $a_inventory['fusioninventorycomputer']['operatingsystem_installationdate'] = "NULL"; } // * BIOS if (isset($array['BIOS'])) { if (isset($array['BIOS']['ASSETTAG'])) { $a_inventory['fusioninventorycomputer']['bios_assettag'] = $array['BIOS']['ASSETTAG']; } if (isset($array['BIOS']['SMANUFACTURER']) and !empty($array['BIOS']['SMANUFACTURER'])) { $a_inventory['Computer']['manufacturers_id'] = $array['BIOS']['SMANUFACTURER']; } else { if (isset($array['BIOS']['MMANUFACTURER']) and !empty($array['BIOS']['MMANUFACTURER'])) { $a_inventory['Computer']['manufacturers_id'] = $array['BIOS']['MMANUFACTURER']; } else { if (isset($array['BIOS']['BMANUFACTURER']) and !empty($array['BIOS']['BMANUFACTURER'])) { $a_inventory['Computer']['manufacturers_id'] = $array['BIOS']['BMANUFACTURER']; } else { if (isset($array['BIOS']['MMANUFACTURER']) and !empty($array['BIOS']['MMANUFACTURER'])) { $a_inventory['Computer']['manufacturers_id'] = $array['BIOS']['MMANUFACTURER']; } else { if (isset($array['BIOS']['BMANUFACTURER']) and !empty($array['BIOS']['BMANUFACTURER'])) { $a_inventory['Computer']['manufacturers_id'] = $array['BIOS']['BMANUFACTURER']; } } } } } if (isset($array['BIOS']['MMANUFACTURER']) and !empty($array['BIOS']['MMANUFACTURER'])) { $a_inventory['Computer']['mmanufacturer'] = $array['BIOS']['MMANUFACTURER']; } if (isset($array['BIOS']['BMANUFACTURER']) and !empty($array['BIOS']['BMANUFACTURER'])) { $a_inventory['Computer']['bmanufacturer'] = $array['BIOS']['BMANUFACTURER']; } if (isset($array['BIOS']['SMODEL']) and $array['BIOS']['SMODEL'] != '') { $a_inventory['Computer']['computermodels_id'] = $array['BIOS']['SMODEL']; } else { if (isset($array['BIOS']['MMODEL']) and $array['BIOS']['MMODEL'] != '') { $a_inventory['Computer']['computermodels_id'] = $array['BIOS']['MMODEL']; } } if (isset($array['BIOS']['MMODEL']) and $array['BIOS']['MMODEL'] != '') { $a_inventory['Computer']['mmodel'] = $array['BIOS']['MMODEL']; } if (isset($array['BIOS']['SSN'])) { $a_inventory['Computer']['serial'] = trim($array['BIOS']['SSN']); // HP patch for serial begin with 'S' if (isset($a_inventory['Computer']['manufacturers_id']) and strstr($a_inventory['Computer']['manufacturers_id'], "ewlett") && preg_match("/^[sS]/", $a_inventory['Computer']['serial'])) { $a_inventory['Computer']['serial'] = trim(preg_replace("/^[sS]/", "", $a_inventory['Computer']['serial'])); } } if (isset($array['BIOS']['MSN'])) { $a_inventory['Computer']['mserial'] = trim($array['BIOS']['MSN']); } } // * Type of computer //First the HARDWARE/VMSYSTEM is not Physical : then it's a virtual machine if (isset($array['HARDWARE']['VMSYSTEM']) && $array['HARDWARE']['VMSYSTEM'] != '' && $array['HARDWARE']['VMSYSTEM'] != 'Physical') { $a_inventory['Computer']['computertypes_id'] = $array['HARDWARE']['VMSYSTEM']; // HACK FOR BSDJail, remove serial and UUID (because it's of host, not contener) if ($array['HARDWARE']['VMSYSTEM'] == 'BSDJail') { if (isset($a_inventory['Computer']['serial'])) { $a_inventory['Computer']['serial'] = ''; } $a_inventory['Computer']['uuid'] .= "-" . $a_inventory['Computer']['name']; } } else { //It's not a virtual machine, then check : //1 - HARDWARE/CHASSIS_TYPE //2 - BIOS/TYPE //3 - BIOS/MMODEL //4 - HARDWARE/VMSYSTEM (should not go there) if (isset($array['HARDWARE']['CHASSIS_TYPE']) && !empty($array['HARDWARE']['CHASSIS_TYPE'])) { $a_inventory['Computer']['computertypes_id'] = $array['HARDWARE']['CHASSIS_TYPE']; } else { if (isset($array['BIOS']['TYPE']) && !empty($array['BIOS']['TYPE'])) { $a_inventory['Computer']['computertypes_id'] = $array['BIOS']['TYPE']; } else { if (isset($array['BIOS']['MMODEL']) && !empty($array['BIOS']['MMODEL'])) { $a_inventory['Computer']['computertypes_id'] = $array['BIOS']['MMODEL']; } else { if (isset($array['HARDWARE']['VMSYSTEM']) && !empty($array['HARDWARE']['VMSYSTEM'])) { $a_inventory['Computer']['computertypes_id'] = $array['HARDWARE']['VMSYSTEM']; } } } } } // if (isset($array['BIOS']['SKUNUMBER'])) { // $a_inventory['BIOS']['PARTNUMBER'] = $array['BIOS']['SKUNUMBER']; // } if (isset($array['BIOS']['BDATE'])) { $a_split = explode("/", $array['BIOS']['BDATE']); // 2011-06-29 13:19:48 if (isset($a_split[0]) and isset($a_split[1]) and isset($a_split[2])) { $a_inventory['fusioninventorycomputer']['bios_date'] = $a_split[2] . "-" . $a_split[0] . "-" . $a_split[1]; } } if (isset($array['BIOS']['BVERSION'])) { $a_inventory['fusioninventorycomputer']['bios_version'] = $array['BIOS']['BVERSION']; } if (isset($array['BIOS']['BMANUFACTURER'])) { $a_inventory['fusioninventorycomputer']['bios_manufacturers_id'] = $array['BIOS']['BMANUFACTURER']; } $CFG_GLPI['plugin_fusioninventory_computermanufacturer'][$a_inventory['Computer']['manufacturers_id']] = $a_inventory['Computer']['manufacturers_id']; // * OPERATINGSYSTEM if (isset($array['OPERATINGSYSTEM'])) { $array_tmp = $thisc->addValues($array['OPERATINGSYSTEM'], array('FULL_NAME' => 'operatingsystems_id', 'VERSION' => 'operatingsystemversions_id', 'SERVICE_PACK' => 'operatingsystemservicepacks_id', 'ARCH' => 'plugin_fusioninventory_computerarchs_id')); if (!isset($array['OPERATINGSYSTEM']['VERSION']) && isset($array['OPERATINGSYSTEM']['KERNEL_VERSION'])) { $array_tmp['operatingsystemversions_id'] = $array['OPERATINGSYSTEM']['KERNEL_VERSION']; } foreach ($array_tmp as $key => $value) { if (isset($a_inventory['Computer'][$key]) && $a_inventory['Computer'][$key] != '') { $a_inventory['Computer'][$key] = $value; } } if (isset($array_tmp['plugin_fusioninventory_computerarchs_id']) && $array_tmp['plugin_fusioninventory_computerarchs_id'] != '') { $rulecollection = new PluginFusioninventoryRuleDictionnaryComputerArchCollection(); $res_rule = $rulecollection->processAllRules(array("name" => $array_tmp['plugin_fusioninventory_computerarchs_id'])); if (isset($res_rule['name'])) { $a_inventory['fusioninventorycomputer']['plugin_fusioninventory_computerarchs_id'] = $res_rule['name']; } else { $a_inventory['fusioninventorycomputer']['plugin_fusioninventory_computerarchs_id'] = $array_tmp['plugin_fusioninventory_computerarchs_id']; } } } // otherserial (on tag) if defined in config if ($pfConfig->getValue('otherserial') == 1) { if (isset($array['ACCOUNTINFO'])) { //In very rare case, ACCOUNTINFO section is present twice in the XML file... if (isset($array['ACCOUNTINFO'][0])) { $tmpacc = $array['ACCOUNTINFO'][0]; $array['ACCOUNTINFO'] = $tmpacc; } if (isset($array['ACCOUNTINFO']['KEYNAME']) && $array['ACCOUNTINFO']['KEYNAME'] == 'TAG') { if (isset($array['ACCOUNTINFO']['KEYVALUE']) && $array['ACCOUNTINFO']['KEYVALUE'] != '') { $a_inventory['Computer']['otherserial'] = $array['ACCOUNTINFO']['KEYVALUE']; } } } } // Hack for problems of ESX inventory with same deviceid than real computer inventory if (isset($a_inventory['Computer']['operatingsystems_id']) && strstr($a_inventory['Computer']['operatingsystems_id'], 'VMware ESX')) { $PF_ESXINVENTORY = TRUE; } // * BATTERIES // $a_inventory['batteries'] = array(); // if (isset($array['BATTERIES'])) { // foreach ($array['BATTERIES'] as $a_batteries) { // $a_inventory['soundcard'][] = $thisc->addValues($a_batteries, // array( // 'NAME' => 'name', // 'MANUFACTURER' => 'manufacturers_id', // 'SERIAL' => 'serial', // 'DATE' => 'date', // 'CAPACITY' => 'capacity', // 'CHEMISTRY' => 'plugin_fusioninventory_inventorycomputerchemistries_id', // 'VOLTAGE' => 'voltage')); // } // } // * SOUNDS $a_inventory['soundcard'] = array(); if ($pfConfig->getValue('component_soundcard') == 1) { if (isset($array['SOUNDS'])) { foreach ($array['SOUNDS'] as $a_sounds) { $a_inventory['soundcard'][] = $thisc->addValues($a_sounds, array('NAME' => 'designation', 'MANUFACTURER' => 'manufacturers_id', 'DESCRIPTION' => 'comment')); $ignorecontrollers[$a_sounds['NAME']] = 1; } } } // * VIDEOS $a_inventory['graphiccard'] = array(); if ($pfConfig->getValue('component_graphiccard') == 1) { if (isset($array['VIDEOS'])) { foreach ($array['VIDEOS'] as $a_videos) { if (is_array($a_videos) && isset($a_videos['NAME'])) { $array_tmp = $thisc->addValues($a_videos, array('NAME' => 'designation', 'MEMORY' => 'memory')); $array_tmp['designation'] = trim($array_tmp['designation']); $a_inventory['graphiccard'][] = $array_tmp; if (isset($a_videos['NAME'])) { $ignorecontrollers[$a_videos['NAME']] = 1; } if (isset($a_videos['CHIPSET'])) { $ignorecontrollers[$a_videos['CHIPSET']] = 1; } } } } } // * NETWORK CARD $a_inventory['networkcard'] = array(); if ($pfConfig->getValue('component_networkcard') == 1) { if (isset($array['NETWORKS'])) { foreach ($array['NETWORKS'] as $a_netcards) { if (is_array($a_netcards) && isset($a_netcards['DESCRIPTION'])) { // Search in controller if find NAME = CONTROLLER TYPE $a_found = array(); if (isset($array['CONTROLLERS'])) { foreach ($array['CONTROLLERS'] as $a_controllers) { if (count($a_found) == 0) { if (isset($a_controllers['TYPE']) && ($a_netcards['DESCRIPTION'] == $a_controllers['TYPE'] || strtolower($a_netcards['DESCRIPTION'] . " controller") == strtolower($a_controllers['TYPE'])) && !isset($ignorecontrollers[$a_controllers['NAME']])) { $a_found = $a_controllers; if (isset($a_netcards['MACADDR'])) { $a_found['MACADDR'] = $a_netcards['MACADDR']; } } } } } if (count($a_found) > 0) { $array_tmp = $thisc->addValues($a_found, array('NAME' => 'designation', 'MANUFACTURER' => 'manufacturers_id', 'MACADDR' => 'mac')); if (isset($a_found['PCIID'])) { $a_PCIData = PluginFusioninventoryInventoryExternalDB::getDataFromPCIID($a_found['PCIID']); if (isset($a_PCIData['manufacturer'])) { $array_tmp['manufacturers_id'] = $a_PCIData['manufacturer']; } if (isset($a_PCIData['name'])) { $array_tmp['designation'] = $a_PCIData['name']; } $array_tmp['designation'] = Toolbox::addslashes_deep($array_tmp['designation']); } $array_tmp['mac'] = strtolower($array_tmp['mac']); $a_inventory['networkcard'][] = $array_tmp; if (isset($a_found['NAME'])) { $ignorecontrollers[$a_found['NAME']] = 1; } } } } } } // * NETWORKS $a_inventory['networkport'] = array(); if ($pfConfig->getValue('component_networkcard') == 1) { if (isset($array['NETWORKS'])) { $a_networknames = array(); foreach ($array['NETWORKS'] as $a_networks) { $virtual_import = 1; if ($pfConfig->getValue("component_networkcardvirtual") == 0) { if (isset($a_networks['VIRTUALDEV']) && $a_networks['VIRTUALDEV'] == 1) { $virtual_import = 0; } } if ($virtual_import == 1) { $array_tmp = $thisc->addValues($a_networks, array('DESCRIPTION' => 'name', 'MACADDR' => 'mac', 'TYPE' => 'instantiation_type', 'IPADDRESS' => 'ip', 'VIRTUALDEV' => 'virtualdev', 'IPSUBNET' => 'subnet', 'SSID' => 'ssid', 'IPGATEWAY' => 'gateway', 'IPMASK' => 'netmask', 'IPDHCP' => 'dhcpserver', 'SPEED' => 'speed')); if (isset($array_tmp['name']) && $array_tmp['name'] != '' || isset($array_tmp['mac']) && $array_tmp['mac'] != '') { if (!isset($array_tmp['virtualdev']) || $array_tmp['virtualdev'] != 1) { $array_tmp['virtualdev'] = 0; } $array_tmp['logical_number'] = 1; if ($array_tmp['virtualdev'] == 1) { $array_tmp['logical_number'] = 0; } $array_tmp['mac'] = strtolower($array_tmp['mac']); if (isset($a_networknames[$array_tmp['name'] . '-' . $array_tmp['mac']])) { if (isset($array_tmp['ip']) && $array_tmp['ip'] != '') { if (!in_array($array_tmp['ip'], $a_networknames[$array_tmp['name'] . '-' . $array_tmp['mac']]['ipaddress'])) { $a_networknames[$array_tmp['name'] . '-' . $array_tmp['mac']]['ipaddress'][] = $array_tmp['ip']; } } if (isset($a_networks['IPADDRESS6']) && $a_networks['IPADDRESS6'] != '') { if (!in_array($a_networks['IPADDRESS6'], $a_networknames[$array_tmp['name'] . '-' . $array_tmp['mac']]['ipaddress'])) { $a_networknames[$array_tmp['name'] . '-' . $array_tmp['mac']]['ipaddress'][] = $a_networks['IPADDRESS6']; } } } else { if (isset($array_tmp['ip']) && $array_tmp['ip'] != '') { $array_tmp['ipaddress'] = array($array_tmp['ip']); unset($array_tmp['ip']); } else { $array_tmp['ipaddress'] = array(); } if (isset($a_networks['IPADDRESS6']) && $a_networks['IPADDRESS6'] != '') { $array_tmp['ipaddress'][] = $a_networks['IPADDRESS6']; } if (isset($array_tmp["instantiation_type"]) and $array_tmp["instantiation_type"] == 'Ethernet') { $array_tmp["instantiation_type"] = 'NetworkPortEthernet'; } else { if (isset($array_tmp["instantiation_type"]) and ($array_tmp["instantiation_type"] == 'wifi' or $array_tmp["instantiation_type"] == 'IEEE')) { $array_tmp["instantiation_type"] = 'NetworkPortWifi'; } else { if ($array_tmp['mac'] != '') { $array_tmp["instantiation_type"] = 'NetworkPortEthernet'; } else { $array_tmp["instantiation_type"] = 'NetworkPortLocal'; } } } if (isset($array_tmp['ip'])) { unset($array_tmp['ip']); } if (isset($array_tmp['speed']) && is_numeric($array_tmp['speed'])) { // Old agent version have speed in b/s instead Mb/s if ($array_tmp['speed'] > 100000) { $array_tmp['speed'] = $array_tmp['speed'] / 1000000; } } else { $array_tmp['speed'] = 0; } $a_networknames[$array_tmp['name'] . '-' . $array_tmp['mac']] = $array_tmp; } } } } $a_inventory['networkport'] = $a_networknames; } } // * CONTROLLERS $a_inventory['controller'] = array(); if ($pfConfig->getValue('component_control') == 1) { if (isset($array['CONTROLLERS'])) { foreach ($array['CONTROLLERS'] as $a_controllers) { if (isset($a_controllers["NAME"]) and !isset($ignorecontrollers[$a_controllers["NAME"]])) { $array_tmp = $thisc->addValues($a_controllers, array('NAME' => 'designation', 'MANUFACTURER' => 'manufacturers_id', 'type' => 'interfacetypes_id')); if (isset($a_controllers['PCIID'])) { $a_PCIData = PluginFusioninventoryInventoryExternalDB::getDataFromPCIID($a_controllers['PCIID']); if (isset($a_PCIData['manufacturer'])) { $array_tmp['manufacturers_id'] = $a_PCIData['manufacturer']; } if (isset($a_PCIData['name'])) { $array_tmp['designation'] = $a_PCIData['name']; } $array_tmp['designation'] = Toolbox::addslashes_deep($array_tmp['designation']); } $a_inventory['controller'][] = $array_tmp; } } } } // * CPUS $a_inventory['processor'] = array(); if ($pfConfig->getValue('component_processor') == 1) { if (isset($array['CPUS'])) { foreach ($array['CPUS'] as $a_cpus) { if (is_array($a_cpus) && (isset($a_cpus['NAME']) || isset($a_cpus['TYPE']))) { $array_tmp = $thisc->addValues($a_cpus, array('SPEED' => 'frequency', 'MANUFACTURER' => 'manufacturers_id', 'SERIAL' => 'serial', 'NAME' => 'designation', 'CORE' => 'nbcores', 'THREAD' => 'nbthreads')); if ($array_tmp['designation'] == '' && isset($a_cpus['TYPE'])) { $array_tmp['designation'] = $a_cpus['TYPE']; } $array_tmp['frequence'] = $array_tmp['frequency']; $array_tmp['frequency_default'] = $array_tmp['frequency']; $a_inventory['processor'][] = $array_tmp; } } } } // * DRIVES $a_inventory['computerdisk'] = array(); if (isset($array['DRIVES'])) { foreach ($array['DRIVES'] as $a_drives) { if ($pfConfig->getValue("component_drive") == '0' or $pfConfig->getValue("component_networkdrive") == '0' and (isset($a_drives['TYPE']) and $a_drives['TYPE'] == 'Network Drive' or isset($a_drives['FILESYSTEM']) and $a_drives['FILESYSTEM'] == 'nfs') or isset($a_drives['TYPE']) and ($a_drives['TYPE'] == "Removable Disk" or $a_drives['TYPE'] == "Compact Disc")) { } else { if ($pfConfig->getValue('import_volume') == 1) { $array_tmp = $thisc->addValues($a_drives, array('VOLUMN' => 'device', 'FILESYSTEM' => 'filesystems_id', 'TOTAL' => 'totalsize', 'FREE' => 'freesize')); if (isset($a_drives['LABEL']) and !empty($a_drives['LABEL'])) { $array_tmp['name'] = $a_drives['LABEL']; } else { if ((!isset($a_drives['VOLUMN']) or empty($a_drives['VOLUMN'])) and isset($a_drives['LETTER'])) { $array_tmp['name'] = $a_drives['LETTER']; } else { if (isset($a_drives['TYPE'])) { $array_tmp['name'] = $a_drives['TYPE']; } else { if (isset($a_drives['VOLUMN'])) { $array_tmp['name'] = $a_drives['VOLUMN']; } } } } if (isset($a_drives['MOUNTPOINT'])) { $array_tmp['mountpoint'] = $a_drives['MOUNTPOINT']; } else { if (isset($a_drives['LETTER'])) { $array_tmp['mountpoint'] = $a_drives['LETTER']; } else { if (isset($a_drives['TYPE'])) { $array_tmp['mountpoint'] = $a_drives['TYPE']; } } } $a_inventory['computerdisk'][] = $array_tmp; } } } } // * MEMORIES $a_inventory['memory'] = array(); if ($pfConfig->getValue('component_memory') == 1) { if (isset($array['MEMORIES'])) { foreach ($array['MEMORIES'] as $a_memories) { if (!isset($a_memories["CAPACITY"]) or isset($a_memories["CAPACITY"]) and !preg_match("/^[0-9]+\$/i", $a_memories["CAPACITY"])) { // Nothing } else { $array_tmp = $thisc->addValues($a_memories, array('CAPACITY' => 'size', 'SPEED' => 'frequence', 'TYPE' => 'devicememorytypes_id', 'SERIALNUMBER' => 'serial', 'NUMSLOTS' => 'busID')); if ($array_tmp['size'] > 0) { $array_tmp['designation'] = ""; if (isset($a_memories["TYPE"]) && $a_memories["TYPE"] != "Empty Slot" && $a_memories["TYPE"] != "Unknown") { $array_tmp["designation"] = $a_memories["TYPE"]; } if (isset($a_memories["DESCRIPTION"])) { if (!empty($array_tmp["designation"])) { $array_tmp["designation"] .= " - "; } $array_tmp["designation"] .= $a_memories["DESCRIPTION"]; } $a_inventory['memory'][] = $array_tmp; } } } } } // * MONITORS $a_inventory['monitor'] = array(); if (isset($array['MONITORS'])) { $a_serialMonitor = array(); foreach ($array['MONITORS'] as $a_monitors) { $array_tmp = $thisc->addValues($a_monitors, array('CAPTION' => 'name', 'MANUFACTURER' => 'manufacturers_id', 'SERIAL' => 'serial', 'DESCRIPTION' => 'comment')); if (!isset($array_tmp['name'])) { $array_tmp['name'] = ''; } if ($array_tmp['name'] == '' && isset($array_tmp['comment'])) { $array_tmp['name'] = $array_tmp['comment']; } if (isset($array_tmp['comment'])) { unset($array_tmp['comment']); } if (!isset($array_tmp['serial'])) { $array_tmp['serial'] = ''; } if (!isset($array_tmp['manufacturers_id'])) { $array_tmp['manufacturers_id'] = ''; } if (!isset($a_serialMonitor[$array_tmp['serial']])) { $a_inventory['monitor'][] = $array_tmp; $a_serialMonitor[$array_tmp['serial']] = 1; } } } // * PRINTERS $a_inventory['printer'] = array(); if (isset($array['PRINTERS'])) { $rulecollection = new RuleDictionnaryPrinterCollection(); foreach ($array['PRINTERS'] as $a_printers) { $array_tmp = $thisc->addValues($a_printers, array('NAME' => 'name', 'PORT' => 'port', 'SERIAL' => 'serial')); if (strstr($array_tmp['port'], "USB")) { $array_tmp['have_usb'] = 1; } else { $array_tmp['have_usb'] = 0; } unset($array_tmp['port']); $res_rule = $rulecollection->processAllRules(array("name" => $array_tmp['name'])); if (isset($res_rule['_ignore_ocs_import']) && $res_rule['_ignore_ocs_import'] == "1") { // Ignrore import printer } else { if (isset($res_rule['_ignore_import']) && $res_rule['_ignore_import'] == "1") { // Ignrore import printer } else { if (isset($res_rule['name'])) { $array_tmp['name'] = $res_rule['name']; } if (isset($res_rule['manufacturer'])) { $array_tmp['manufacturers_id'] = $res_rule['manufacturer']; } $a_inventory['printer'][] = $array_tmp; } } } } // * PERIPHERAL $a_inventory['peripheral'] = array(); $a_peripheral_name = array(); $per = 0; if (isset($array['USBDEVICES'])) { foreach ($array['USBDEVICES'] as $a_peripherals) { $array_tmp = $thisc->addValues($a_peripherals, array('NAME' => 'name', 'MANUFACTURER' => 'manufacturers_id', 'SERIAL' => 'serial', 'PRODUCTNAME' => 'productname')); if (isset($a_peripherals['VENDORID']) and $a_peripherals['VENDORID'] != '' and isset($a_peripherals['PRODUCTID'])) { $dataArray = PluginFusioninventoryInventoryExternalDB::getDataFromUSBID($a_peripherals['VENDORID'], $a_peripherals['PRODUCTID']); $dataArray[0] = preg_replace('/&(?!\\w+;)/', '&', $dataArray[0]); if (!empty($dataArray[0]) and empty($array_tmp['manufacturers_id'])) { $array_tmp['manufacturers_id'] = $dataArray[0]; } $dataArray[1] = preg_replace('/&(?!\\w+;)/', '&', $dataArray[1]); if (!empty($dataArray[1]) and empty($a_peripherals['productname'])) { $a_peripherals['productname'] = $dataArray[1]; } } if ($array_tmp['productname'] != '') { $array_tmp['name'] = $array_tmp['productname']; } unset($array_tmp['productname']); $a_inventory['peripheral'][] = $array_tmp; $a_peripheral_name[$array_tmp['name']] = $per; $per++; } } if (isset($array['INPUTS'])) { $a_pointingtypes = array(3 => 'Mouse', 4 => 'Trackball', 5 => 'Track Point', 6 => 'Glide Point', 7 => 'Touch Pad', 8 => 'Touch Screen', 9 => 'Mouse - Optical Sensor'); foreach ($array['INPUTS'] as $a_peripherals) { $array_tmp = $thisc->addValues($a_peripherals, array('NAME' => 'name', 'MANUFACTURER' => 'manufacturers_id')); $array_tmp['serial'] = ''; $array_tmp['peripheraltypes_id'] = ''; if (isset($a_peripherals['POINTINGTYPE']) && isset($a_pointingtypes[$a_peripherals['POINTINGTYPE']])) { $array_tmp['peripheraltypes_id'] = $a_pointingtypes[$a_peripherals['POINTINGTYPE']]; } if (isset($a_peripherals['LAYOUT'])) { $array_tmp['peripheraltypes_id'] = 'keyboard'; } if (isset($a_peripheral_name[$array_tmp['name']])) { $a_inventory['peripheral'][$a_peripheral_name[$array_tmp['name']]]['peripheraltypes_id'] = $array_tmp['peripheraltypes_id']; } else { $a_inventory['peripheral'][] = $array_tmp; } } } // * SLOTS // * SOFTWARES $a_inventory['SOFTWARES'] = array(); if ($pfConfig->getValue('import_software') == 1) { if (isset($array['SOFTWARES'])) { $a_inventory['SOFTWARES'] = $array['SOFTWARES']; } } // * STORAGES/COMPUTERDISK $a_inventory['harddrive'] = array(); if (isset($array['STORAGES'])) { foreach ($array['STORAGES'] as $a_storage) { $type_tmp = PluginFusioninventoryFormatconvert::getTypeDrive($a_storage); if ($type_tmp == "Drive") { // it's cd-rom / dvd // if ($pfConfig->getValue(, // "component_drive") =! 0) { if ($pfConfig->getValue('component_drive') == 1) { $array_tmp = $thisc->addValues($a_storage, array('SERIALNUMBER' => 'serial', 'NAME' => 'designation', 'TYPE' => 'interfacetypes_id', 'MANUFACTURER' => 'manufacturers_id')); if ($array_tmp['designation'] == '') { if (isset($a_storage['DESCRIPTION'])) { $array_tmp['designation'] = $a_storage['DESCRIPTION']; } } $a_inventory['drive'][] = $array_tmp; } } else { // it's harddisk // if ($pfConfig->getValue(, // "component_harddrive") != 0) { if (is_array($a_storage)) { if ($pfConfig->getValue('component_harddrive') == 1) { $array_tmp = $thisc->addValues($a_storage, array('DISKSIZE' => 'capacity', 'INTERFACE' => 'interfacetypes_id', 'MANUFACTURER' => 'manufacturers_id', 'MODEL' => 'designation', 'SERIALNUMBER' => 'serial')); if ($array_tmp['designation'] == '') { if (isset($a_storage['NAME'])) { $array_tmp['designation'] = $a_storage['NAME']; } else { if (isset($a_storage['DESIGNATION'])) { $array_tmp['designation'] = $a_storage['DESIGNATION']; } } } $a_inventory['harddrive'][] = $array_tmp; } } } } } // * USERS $cnt = 0; if (isset($array['USERS'])) { if (count($array['USERS']) > 0) { $user_temp = ''; if (isset($a_inventory['Computer']['contact'])) { $user_temp = $a_inventory['Computer']['contact']; } $a_inventory['Computer']['contact'] = ''; } foreach ($array['USERS'] as $a_users) { $array_tmp = $thisc->addValues($a_users, array('LOGIN' => 'login', 'DOMAIN' => 'domain')); $user = ''; if (isset($array_tmp['login'])) { $user = $array_tmp['login']; if (isset($array_tmp['domain']) && !empty($array_tmp['domain'])) { $user .= "@" . $array_tmp['domain']; } } if ($cnt == 0) { if (isset($array_tmp['login'])) { $query = "SELECT `id`\n FROM `glpi_users`\n WHERE `name` = '" . $array_tmp['login'] . "'\n LIMIT 1"; $result = $DB->query($query); if ($DB->numrows($result) == 1) { $a_inventory['Computer']['users_id'] = $DB->result($result, 0, 0); } } } if ($user != '') { if (isset($a_inventory['Computer']['contact'])) { if ($a_inventory['Computer']['contact'] == '') { $a_inventory['Computer']['contact'] = $user; } else { $a_inventory['Computer']['contact'] .= "/" . $user; } } else { $a_inventory['Computer']['contact'] = $user; } } $cnt++; } if (empty($a_inventory['Computer']['contact'])) { $a_inventory['Computer']['contact'] = $user_temp; } } // * VIRTUALMACHINES $a_inventory['virtualmachine'] = array(); if ($pfConfig->getValue('import_vm') == 1) { if (isset($array['VIRTUALMACHINES'])) { foreach ($array['VIRTUALMACHINES'] as $a_virtualmachines) { $array_tmp = $thisc->addValues($a_virtualmachines, array('NAME' => 'name', 'VCPU' => 'vcpu', 'MEMORY' => 'ram', 'VMTYPE' => 'virtualmachinetypes_id', 'SUBSYSTEM' => 'virtualmachinesystems_id', 'STATUS' => 'virtualmachinestates_id', 'UUID' => 'uuid')); $array_tmp['is_dynamic'] = 1; // Hack for BSD jails if ($array_tmp['virtualmachinetypes_id'] == 'jail') { $array_tmp['uuid'] = $a_inventory['Computer']['uuid'] . "-" . $array_tmp['name']; } $a_inventory['virtualmachine'][] = $array_tmp; } } } if ($pfConfig->getValue('create_vm') == 1) { if (isset($array['VIRTUALMACHINES'])) { foreach ($array['VIRTUALMACHINES'] as $a_virtualmachines) { if (strstr($a_virtualmachines['MEMORY'], 'MB')) { $a_virtualmachines['MEMORY'] = str_replace('MB', '', $a_virtualmachines['MEMORY']); } else { if (strstr($a_virtualmachines['MEMORY'], 'KB')) { $a_virtualmachines['MEMORY'] = str_replace('KB', '', $a_virtualmachines['MEMORY']); $a_virtualmachines['MEMORY'] = $a_virtualmachines['MEMORY'] / 1000; } else { if (strstr($a_virtualmachines['MEMORY'], 'GB')) { $a_virtualmachines['MEMORY'] = str_replace('GB', '', $a_virtualmachines['MEMORY']); $a_virtualmachines['MEMORY'] = $a_virtualmachines['MEMORY'] * 1000; } else { if (strstr($a_virtualmachines['MEMORY'], 'B')) { $a_virtualmachines['MEMORY'] = str_replace('B', '', $a_virtualmachines['MEMORY']); $a_virtualmachines['MEMORY'] = $a_virtualmachines['MEMORY'] / 1000000; } } } } $array_tmp = $thisc->addValues($a_virtualmachines, array('NAME' => 'name', 'VCPU' => 'vcpu', 'MEMORY' => 'ram', 'VMTYPE' => 'computertypes_id', 'UUID' => 'uuid', 'OPERATINGSYSTEM' => 'operatingsystems_id', 'CUSTOMFIELDS' => 'comment')); $array_tmp['is_dynamic'] = 1; if (isset($array_tmp['comment']) && is_array($array_tmp['comment'])) { $a_com_temp = $array_tmp['comment']; $array_tmp['comment'] = ''; foreach ($a_com_temp as $data) { $array_tmp['comment'] .= $data['NAME'] . ' : ' . $data['VALUE'] . '\\n'; } } $array_tmp['networkport'] = array(); if (isset($a_virtualmachines['NETWORKS']) && is_array($a_virtualmachines['NETWORKS'])) { foreach ($a_virtualmachines['NETWORKS'] as $data) { $array_tmp_np = $thisc->addValues($data, array('DESCRIPTION' => 'name', 'MACADDR' => 'mac', 'IPADDRESS' => 'ip')); $array_tmp_np['instantiation_type'] = 'NetworkPortEthernet'; $array_tmp_np['mac'] = strtolower($array_tmp_np['mac']); if (isset($array_tmp['networkport'][$array_tmp_np['name'] . '-' . $array_tmp_np['mac']])) { if (isset($array_tmp_np['ip'])) { $array_tmp['networkport'][$array_tmp_np['name'] . '-' . $array_tmp_np['mac']]['ipaddress'][] = $array_tmp_np['ip']; } } else { if (isset($array_tmp_np['ip']) && $array_tmp_np['ip'] != '') { $array_tmp_np['ipaddress'] = array($array_tmp_np['ip']); unset($array_tmp_np['ip']); } else { $array_tmp_np['ipaddress'] = array(); } $array_tmp['networkport'][$array_tmp_np['name'] . '-' . $array_tmp_np['mac']] = $array_tmp_np; } } } $a_inventory['virtualmachine_creation'][] = $array_tmp; } } } // * ANTIVIRUS $a_inventory['antivirus'] = array(); if (isset($array['ANTIVIRUS'])) { foreach ($array['ANTIVIRUS'] as $a_antiviruses) { $array_tmp = $thisc->addValues($a_antiviruses, array('NAME' => 'name', 'COMPANY' => 'manufacturers_id', 'VERSION' => 'version', 'ENABLED' => 'is_active', 'UPTODATE' => 'uptodate')); $a_inventory['antivirus'][] = $array_tmp; } } // * STORAGE/VOLUMES $a_inventory['storage'] = array(); /* begin code, may works at 90% if (isset($array['PHYSICAL_VOLUMES'])) { foreach ($array['PHYSICAL_VOLUMES'] as $a_physicalvolumes) { $array_tmp = $thisc->addValues($a_physicalvolumes, array( 'DEVICE' => 'name', 'PV_UUID' => 'uuid', 'VG_UUID' => 'uuid_link', 'SIZE' => 'totalsize', 'FREE' => 'freesize')); $array_tmp['plugin_fusioninventory_inventorycomputerstoragetypes_id'] = 'partition'; $a_inventory['storage'][] = $array_tmp; } } if (isset($array['STORAGES'])) { foreach ($array['STORAGES'] as $a_storage) { $type_tmp = PluginFusioninventoryFormatconvert::getTypeDrive($a_storage); if ($type_tmp != "Drive") { if (isset($a_storage['NAME']) AND $a_storage['NAME'] != '') { $detectsize = 0; $array_tmp = array(); foreach ($a_inventory['storage'] as $a_physicalvol) { if (preg_match("/^\/dev\/".$a_storage['NAME']."/", $a_physicalvol['name'])) { $array_tmp['name'] = $a_storage['NAME']; if (isset($a_storage['SERIALNUMBER'])) { $array_tmp['uuid'] = $a_storage['SERIALNUMBER']; } else { $array_tmp['uuid'] = $a_storage['NAME']; } $array_tmp['plugin_fusioninventory_inventorycomputerstoragetypes_id'] = 'hard disk'; if (!isset($array_tmp['uuid_link'])) { $array_tmp['uuid_link'] = array(); } $array_tmp['uuid_link'][] = $a_physicalvol['uuid']; $detectsize += $a_physicalvol['totalsize']; } } if (isset($a_storage['DISKSIZE']) && $a_storage['DISKSIZE'] != '') { $array_tmp['totalsize'] = $a_storage['DISKSIZE']; $array_tmp['size_dynamic'] = 0; } else { $array_tmp['totalsize'] = $detectsize; $array_tmp['size_dynamic'] = 1; } $a_inventory['storage'][] = $array_tmp; } } } } if (isset($array['VOLUME_GROUPS'])) { foreach ($array['VOLUME_GROUPS'] as $a_volumegroups) { $array_tmp = $thisc->addValues($a_volumegroups, array( 'VG_NAME' => 'name', 'VG_UUID' => 'uuid', 'SIZE' => 'totalsize', 'FREE' => 'freesize')); $array_tmp['plugin_fusioninventory_inventorycomputerstoragetypes_id'] = 'volume groups'; $a_inventory['storage'][] = $array_tmp; } } if (isset($array['LOGICAL_VOLUMES'])) { foreach ($array['LOGICAL_VOLUMES'] as $a_logicalvolumes) { $array_tmp = $thisc->addValues($a_logicalvolumes, array( 'LV_NAME' => 'name', 'LV_UUID' => 'uuid', 'VG_UUID' => 'uuid_link', 'SIZE' => 'totalsize')); $array_tmp['plugin_fusioninventory_inventorycomputerstoragetypes_id'] = 'logical volumes'; $a_inventory['storage'][] = $array_tmp; } } if (isset($array['DRIVES'])) { foreach ($array['DRIVES'] as $a_drives) { if ((((isset($a_drives['TYPE']) AND $a_drives['TYPE'] == 'Network Drive') OR isset($a_drives['FILESYSTEM']) AND $a_drives['FILESYSTEM'] == 'nfs')) OR ((isset($a_drives['TYPE'])) AND (($a_drives['TYPE'] == "Removable Disk") OR ($a_drives['TYPE'] == "Compact Disc")))) { } else if (isset($a_drives['VOLUMN']) && strstr($a_drives['VOLUMN'], "/dev/mapper")){ // LVM $a_split = explode("-", $a_drives['VOLUMN']); $volumn = end($a_split); $detectsize = 0; $array_tmp = array(); foreach ($a_inventory['storage'] as $num=>$a_physicalvol) { if ($a_physicalvol['plugin_fusioninventory_inventorycomputerstoragetypes_id'] == 'logical volumes') { if ($volumn == $a_physicalvol['name']) { $array_tmp['name'] = $a_drives['TYPE']; if (isset($a_drives['SERIAL'])) { $array_tmp['uuid'] = $a_drives['SERIAL']; } else { $array_tmp['uuid'] = $a_drives['TYPE']; } $array_tmp['plugin_fusioninventory_inventorycomputerstoragetypes_id'] = 'mount'; if (!isset($array_tmp['uuid_link'])) { $array_tmp['uuid_link'] = array(); } $array_tmp['uuid_link'][] = $a_physicalvol['uuid']; $detectsize += $a_physicalvol['totalsize']; } } } if (isset($array_tmp['name'])) { $array_tmp['totalsize'] = $a_drives['TOTAL']; $a_inventory['storage'][] = $array_tmp; } } else if (isset($a_drives['VOLUMN']) && strstr($a_drives['VOLUMN'], "/dev/")){ $detectsize = 0; $array_tmp = array(); foreach ($a_inventory['storage'] as $num=>$a_physicalvol) { $volumn = $a_drives['VOLUMN']; $volumn = substr_replace($volumn , "", -1); $volumn = str_replace("/dev/", "", $volumn); if ($volumn == $a_physicalvol['name']) { $array_tmp['name'] = $a_drives['VOLUMN']; if (isset($a_drives['SERIAL'])) { $array_tmp['uuid'] = $a_drives['SERIAL']; } else { $array_tmp['uuid'] = $a_drives['TYPE']; } $array_tmp['plugin_fusioninventory_inventorycomputerstoragetypes_id'] = 'partition'; if (!isset($array_tmp['uuid_link'])) { $array_tmp['uuid_link'] = array(); } $array_tmp['uuid_link'][] = $a_physicalvol['uuid']; $detectsize += $a_physicalvol['totalsize']; if ($a_physicalvol['size_dynamic'] == 1) { $a_inventory['storage'][$num]['totalsize'] += $a_drives['TOTAL']; } } } if (isset($array_tmp['name'])) { $array_tmp['totalsize'] = $a_drives['TOTAL']; $a_inventory['storage'][] = $array_tmp; $array_tmp['plugin_fusioninventory_inventorycomputerstoragetypes_id'] = 'mount'; $array_tmp['name'] = $a_drives['TYPE']; $array_tmp['uuid_link'] = array(); $array_tmp['uuid_link'][] = $array_tmp['uuid']; $array_tmp['uuid'] = $array_tmp['uuid']."-mount"; $a_inventory['storage'][] = $array_tmp; } } } } */ // * LICENSEINFOS $a_inventory['licenseinfo'] = array(); if (isset($array['LICENSEINFOS'])) { foreach ($array['LICENSEINFOS'] as $a_licenseinfo) { $array_tmp = $thisc->addValues($a_licenseinfo, array('NAME' => 'name', 'FULLNAME' => 'fullname', 'KEY' => 'serial')); $a_inventory['licenseinfo'][] = $array_tmp; } } return $a_inventory; }
/** * Update VirtualMachine in computer * * @test */ public function ComputerVirtualmachineUpdateMemory() { global $DB; $DB->connect(); $a_inventory = $this->computer_inventory; $a_inventory['virtualmachine'][0]['ram'] = '2048'; $pfiComputerLib = new PluginFusioninventoryInventoryComputerLib(); $pfFormatconvert = new PluginFusioninventoryFormatconvert(); $a_inventory = $pfFormatconvert->replaceids($a_inventory); $serialized = gzcompress(serialize($a_inventory)); $a_inventory['fusioninventorycomputer']['serialized_inventory'] = Toolbox::addslashes_deep($serialized); $pfiComputerLib->updateComputer($a_inventory, 1, FALSE); $nbvm = countElementsInTable("glpi_computervirtualmachines"); $this->assertEquals(1, $nbvm, 'May have only 1 VM'); $a_data = getAllDatasFromTable("glpi_computervirtualmachines"); $a_reference = array('1' => array('id' => '1', 'entities_id' => '0', 'computers_id' => '1', 'name' => 'Windows 7', 'virtualmachinestates_id' => '1', 'virtualmachinesystems_id' => '1', 'virtualmachinetypes_id' => '1', 'uuid' => '2961ecf6-7e94-488d-ae0d-e427123078b3', 'vcpu' => '1', 'ram' => '2048', 'is_deleted' => '0', 'is_dynamic' => '1', 'comment' => null)); $this->assertEquals($a_reference, $a_data); }
/** * Manage a hub (many mac on a port mean you have a hub) * * @param $pfNetworkport object Informations of the network port (switch port) * * @return bool * **/ function hubNetwork($pfNetworkport, $a_mac) { $nn = new NetworkPort_NetworkPort(); $Netport = new NetworkPort(); // Get port connected on switch port $hub_id = 0; $ID = $nn->getOppositeContact($pfNetworkport->fields['networkports_id']); if ($ID) { $Netport->getFromDB($ID); if ($Netport->fields["itemtype"] == $this->getType()) { $this->getFromDB($Netport->fields["items_id"]); if ($this->fields["hub"] == "1") { // It's a hub connected, so will update connections //$this->releaseHub($this->fields['id'], $p_oPort); $hub_id = $this->fields['id']; } else { // It's a direct connection, so disconnect and create a hub $this->disconnectDB($ID); $hub_id = $this->createHub($pfNetworkport, $a_mac); } } else { // It's a direct connection, so disconnect and create a hub $this->disconnectDB($ID); $hub_id = $this->createHub($pfNetworkport, $a_mac); } } else { // No connections found and create a hub $hub_id = $this->createHub($pfNetworkport, $a_mac); } // State : Now we have hub and it's id // Add source port id in comment of hub $h_input = array(); $h_input['id'] = $hub_id; $h_input['comment'] = "Port : " . $pfNetworkport->fields['networkports_id']; $this->update($h_input); // Get all ports connected to this hub $a_portglpi = array(); $a_ports = $Netport->find("`items_id`='" . $hub_id . "'\n AND `itemtype`='" . $this->getType() . "'"); foreach ($a_ports as $data) { $id = $nn->getOppositeContact($data['id']); if ($id) { $a_portglpi[$id] = $data['id']; } } foreach ($a_mac as $ifmac) { $a_ports = $Netport->find("`mac`='" . $ifmac . "'", "", 1); if (count($a_ports) == "1") { if (!$this->searchIfmacOnHub($a_ports, $a_portglpi)) { // Connect port (port found in GLPI) $this->connectPortToHub($a_ports, $hub_id); } } else { if (count($a_ports) == "0") { // Port don't exist // Create unmanaged device $input = array(); $a_manufacturer = array(0 => PluginFusioninventoryInventoryExternalDB::getManufacturerWithMAC($ifmac)); $a_manufacturer = PluginFusioninventoryFormatconvert::cleanArray($a_manufacturer); $input['name'] = $a_manufacturer[0]; if (isset($_SESSION["plugin_fusioninventory_entity"])) { $input['entities_id'] = $_SESSION["plugin_fusioninventory_entity"]; } $unmanageds_id = $this->add($input); $input = array(); $input["items_id"] = $unmanageds_id; $input["itemtype"] = $this->getType(); $input["mac"] = $ifmac; $input['instantiation_type'] = "NetworkPortEthernet"; $id_port = $Netport->add($input); $Netport->getFromDB($id_port); $this->connectPortToHub(array($id_port => $Netport->fields), $hub_id); } } } }
/** * @test */ function DiscoveryDeviceConvert() { global $DB; $DB->connect(); $sxml = '<?xml version="1.0" encoding="UTF-8" ?> <REQUEST> <CONTENT> <DEVICE> <AUTHSNMP>1</AUTHSNMP> <DESCRIPTION>Eaton 5PX 1500</DESCRIPTION> <IP>192.168.20.196</IP> <MAC>00:20:85:f5:2d:19</MAC> <MANUFACTURER>Eaton</MANUFACTURER> <SNMPHOSTNAME>ups25</SNMPHOSTNAME> <TYPE>NETWORKING</TYPE> </DEVICE> <MODULEVERSION>2.2.0</MODULEVERSION> <PROCESSNUMBER>11</PROCESSNUMBER> </CONTENT> <DEVICEID>port004.bureau.siprossii.com-2012-12-20-16-27-27</DEVICEID> <QUERY>NETDISCOVERY</QUERY> </REQUEST>'; $xml = @simplexml_load_string($sxml, 'SimpleXMLElement', LIBXML_NOCDATA); PluginFusioninventoryFormatconvert::XMLtoArray($xml); $GLPIlog = new GLPIlogs(); $GLPIlog->testSQLlogs(); $GLPIlog->testPHPlogs(); }
/** * 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); } } }
/** * @test */ public function PrinterCartridge() { global $DB; $DB->connect(); $_SESSION["plugin_fusioninventory_entity"] = 0; $_SESSION["glpiname"] = 'Plugin_FusionInventory'; $a_printer = array(); $a_printer['INFO'] = array('ID' => '54', 'NAME' => 'ARC12-B09-N', 'TYPE' => 'PRINTER'); $a_printer['CARTRIDGES'] = array('CARTRIDGEBLACK' => 90, 'CARTRIDGECYAN' => '', 'CARTRIDGEMAGENTA' => 'OK', 'CARTRIDGEYELLOW' => '30pages'); $pfFormatconvert = new PluginFusioninventoryFormatconvert(); $pfMapping = new PluginFusioninventoryMapping(); $a_return = $pfFormatconvert->printerInventoryTransformation($a_printer); $a_reference = array(); $a_id = $pfMapping->get("Printer", strtolower('CARTRIDGEBLACK')); $a_reference[$a_id['id']] = 90; $a_id = $pfMapping->get("Printer", strtolower('CARTRIDGEMAGENTA')); $a_reference[$a_id['id']] = 100000; $a_id = $pfMapping->get("Printer", strtolower('CARTRIDGEYELLOW')); $a_reference[$a_id['id']] = -30; $this->assertEquals($a_reference, $a_return['cartridge']); }
/** * Import one device * * @param type $itemtype * @param type $items_id * * @return errors string to be alimented if import ko / '' if ok */ function importDevice($itemtype, $items_id, $a_inventory) { global $PLUGIN_FUSIONINVENTORY_XML; PluginFusioninventoryCommunication::addLog('Function PluginFusioninventoryCommunicationNetworkInventory->importDevice().'); $pfFormatconvert = new PluginFusioninventoryFormatconvert(); $a_inventory = $pfFormatconvert->replaceids($a_inventory); // Write XML file if (count($a_inventory) > 0) { $xml = $PLUGIN_FUSIONINVENTORY_XML->CONTENT->DEVICE[$_SESSION['plugin_fusioninventory_xmlnum']]->asXML(); PluginFusioninventoryToolbox::writeXML($items_id, $xml, $itemtype); // $folder = substr($items_id, 0, -1); // if (empty($folder)) { // $folder = '0'; // } // if (!file_exists(GLPI_PLUGIN_DOC_DIR."/fusioninventory/".$itemtype."/".$folder)) { // mkdir(GLPI_PLUGIN_DOC_DIR."/fusioninventory/".$itemtype."/".$folder, 0777, TRUE); // } // $fileopen = fopen(GLPI_PLUGIN_DOC_DIR."/fusioninventory/".$itemtype."/".$folder."/". // $items_id, 'w'); // fwrite($fileopen, print_r($a_inventory, TRUE)); // fclose($fileopen); } $errors = ''; $this->deviceId = $items_id; $serialized = gzcompress(serialize($a_inventory)); if (isset($a_inventory['name']) && $a_inventory['name'] == '') { unset($a_inventory['name']); } if (isset($a_inventory['serial']) && $a_inventory['serial'] == '') { unset($a_inventory['serial']); } switch ($itemtype) { case 'Printer': $pfiPrinterLib = new PluginFusioninventoryInventoryPrinterLib(); $a_inventory['PluginFusioninventoryPrinter']['serialized_inventory'] = Toolbox::addslashes_deep($serialized); $pfiPrinterLib->updatePrinter($a_inventory, $items_id); break; case 'NetworkEquipment': $pfiNetworkEquipmentLib = new PluginFusioninventoryInventoryNetworkEquipmentLib(); $a_inventory['PluginFusioninventoryNetworkEquipment']['serialized_inventory'] = Toolbox::addslashes_deep($serialized); $pfiNetworkEquipmentLib->updateNetworkEquipment($a_inventory, $items_id); break; default: $errors .= __('Unattended element in', 'fusioninventory') . ' TYPE : ' . $a_inventory['itemtype'] . "\n"; } }
/** * @test */ public function AddSoftwareVersion() { global $DB; $DB->connect(); $_SESSION["plugin_fusioninventory_entity"] = 0; $_SESSION["glpiname"] = 'Plugin_FusionInventory'; $a_software = array(); $a_software['SOFTWARES'][] = array('PUBLISHER' => 'indepnet', 'NAME' => 'glpi0.85', 'VERSION' => '0.85'); $pfFormatconvert = new PluginFusioninventoryFormatconvert(); $a_return = $pfFormatconvert->computerSoftwareTransformation($a_software, 0); $a_reference = array(); $a_reference['software']["glpi\$\$\$\$0.85\$\$\$\$2\$\$\$\$0"] = array('name' => 'glpi', 'manufacturers_id' => 2, 'version' => '0.85', 'is_template_computer' => 0, 'is_deleted_computer' => 0, 'entities_id' => 0, 'is_recursive' => 0); $this->assertEquals($a_reference, $a_return); }
/** * @test */ public function NetworkEquipmentConnectionMac() { global $DB; $DB->connect(); $_SESSION["plugin_fusioninventory_entity"] = 0; $_SESSION["glpiname"] = 'Plugin_FusionInventory'; $a_inventory = array(); $a_inventory['INFO'] = array('COMMENTS' => 'Cisco IOS Software, C3750 Software (C3750-IPSERVICESK9-M), Version 12.2(55)SE, RELEASE SOFTWARE (fc2) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2010 by Cisco Systems, Inc. Compiled Sat 07-Aug-10 22:45 by prod_rel_team', 'ID' => '55', 'MAC' => '00:1b:2b:20:40:80', 'NAME' => 'sw1.siprossii.com', 'SERIAL' => 'CAT1109RGVK', 'TYPE' => 'NETWORKING'); $a_inventory['PORTS']['PORT'][1] = array('CONNECTIONS' => array('CONNECTION' => array('MAC' => array('00:0f:fe:0d:30:70'))), 'IFNAME' => 'Fa0/1', 'IFNUMBER' => 1, 'IFTYPE' => 6, 'MAC' => 'b4:39:d6:3a:7f:3a'); $a_inventory['PORTS']['PORT'][2] = array('CONNECTIONS' => array('CONNECTION' => array('MAC' => array('00:0f:fe:0d:30:76', '00:0f:fe:0d:30:77', '00:0f:fe:0d:30:78'))), 'IFNAME' => 'Fa0/2', 'IFNUMBER' => 2, 'IFTYPE' => 6, 'MAC' => 'b4:39:d6:3a:7f:3e'); $pfFormatconvert = new PluginFusioninventoryFormatconvert(); $a_return = $pfFormatconvert->networkequipmentInventoryTransformation($a_inventory); $a_reference = array('00:0f:fe:0d:30:70'); $this->assertEquals($a_reference, $a_return['connection-mac'][1]); $a_reference = array(); $a_reference = array('00:0f:fe:0d:30:76', '00:0f:fe:0d:30:77', '00:0f:fe:0d:30:78'); $this->assertEquals($a_reference, $a_return['connection-mac'][2]); $GLPIlog = new GLPIlogs(); $GLPIlog->testSQLlogs(); $GLPIlog->testPHPlogs(); }
/** * @test * * Old agent have networkport speed in b/s and new in Mb/s */ public function ComputerNetworkportOldFormat() { global $DB; $DB->connect(); $_SESSION["plugin_fusioninventory_entity"] = 0; $_SESSION["glpiname"] = 'Plugin_FusionInventory'; $a_computer = array(); $a_computer['HARDWARE'] = array('NAME' => 'vbox-winxp', 'ARCHNAME' => 'MSWin32-x86-multi-thread', 'CHASSIS_TYPE' => '', 'DESCRIPTION' => '', 'OSCOMMENTS' => 'Service Pack 3 BAD', 'OSNAME' => 'Microsoft Windows XP Professionnel BAD', 'OSVERSION' => '5.1.2600 BAD', 'VMSYSTEM' => 'VirtualBox', 'WINCOMPANY' => 'siprossii', 'WINLANG' => '1036', 'WINOWNER' => 'test', 'WINPRODID' => '76413-OEM-0054453-04701', 'WINPRODKEY' => 'BW728-6G2PM-2MCWP-VCQ79-DCWX3', 'WORKGROUP' => 'WORKGROUP'); $a_computer['NETWORKS'] = array(0 => array('DESCRIPTION' => 'Intel(R) 82577LM Gigabit Network Connection', 'IPADDRESS' => '192.168.20.50', 'IPDHCP' => '192.168.20.1', 'IPGATEWAY' => '192.168.20.1', 'IPMASK' => '255.255.255.0', 'IPSUBNET' => '192.168.20.0', 'MACADDR' => '5C:26:0A:38:C4:8B', 'PNPDEVICEID' => 'PCI\\VEN_8086&DEV_10EA&SUBSYS_040B1028&REV_05\\3&11583659&0&C8', 'SPEED' => '100000000', 'STATUS' => 'Up', 'TYPE' => 'ethernet', 'VIRTUALDEV' => '0')); $pfFormatconvert = new PluginFusioninventoryFormatconvert(); $a_return = $pfFormatconvert->computerInventoryTransformation($a_computer); $a_reference = array('Intel(R) 82577LM Gigabit Network Connection-5c:26:0a:38:c4:8b' => array('name' => 'Intel(R) 82577LM Gigabit Network Connection', 'mac' => '5c:26:0a:38:c4:8b', 'instantiation_type' => 'NetworkPortEthernet', 'ipaddress' => array('192.168.20.50'), 'virtualdev' => 0, 'subnet' => '192.168.20.0', 'ssid' => '', 'gateway' => '192.168.20.1', 'netmask' => '255.255.255.0', 'dhcpserver' => '192.168.20.1', 'speed' => 100, 'logical_number' => 1)); $this->assertEquals($a_reference, $a_return['networkport']); }
/** * 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); } } }