static function uninstall()
 {
     global $DB;
     CronTask::Unregister('fusioninventory');
     PluginFusioninventoryProfile::uninstallProfile();
     $pfSetup = new PluginFusioninventorySetup();
     $user = new User();
     if (class_exists('PluginFusioninventoryConfig')) {
         $fusioninventory_config = new PluginFusioninventoryConfig();
         $users_id = $fusioninventory_config->getValue('users_id');
         $user->delete(array('id' => $users_id), 1);
     }
     if (file_exists(GLPI_PLUGIN_DOC_DIR . '/fusioninventory')) {
         $pfSetup->rrmdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory');
     }
     $query = "SHOW TABLES;";
     $result = $DB->query($query);
     while ($data = $DB->fetch_array($result)) {
         if (strstr($data[0], "glpi_plugin_fusioninventory_") or strstr($data[0], "glpi_plugin_fusinvsnmp_") or strstr($data[0], "glpi_plugin_fusinvinventory_") or strstr($data[0], "glpi_dropdown_plugin_fusioninventory") or strstr($data[0], "glpi_plugin_tracker") or strstr($data[0], "glpi_dropdown_plugin_tracker")) {
             $query_delete = "DROP TABLE `" . $data[0] . "`;";
             $DB->query($query_delete) or die($DB->error());
         }
     }
     $query = "DELETE FROM `glpi_displaypreferences`\n               WHERE `itemtype` LIKE 'PluginFusioninventory%';";
     $DB->query($query) or die($DB->error());
     // Delete rules
     $Rule = new Rule();
     $Rule->deleteByCriteria(array('sub_type' => 'PluginFusioninventoryInventoryRuleImport'));
     //Remove informations related to profiles from the session (to clean menu and breadcrumb)
     PluginFusioninventoryProfile::removeRightsFromSession();
     return TRUE;
 }
 function isActive()
 {
     global $DB;
     $config = new PluginFusioninventoryConfig();
     // state number for an active device
     if (!($active_device_state = $config->getValue("active_device_state"))) {
         return false;
     }
     // compare device status and active device status
     $query = "SELECT `state`\n                FROM {$this->table}\n                WHERE `ID`='" . $this->ID . "';";
     if ($result = $DB->query($query)) {
         if ($fields = $DB->fetch_row($result)) {
             if ($fields['0'] == $active_device_state) {
                 return true;
             }
         }
     }
     return false;
 }
Пример #3
0
  ------------------------------------------------------------------------
*/
// Original Author of file: David DURIEUX
// Purpose of file:
// ----------------------------------------------------------------------
if (!defined('GLPI_ROOT')) {
    define('GLPI_ROOT', '../../..');
}
$NEEDED_ITEMS = array("fusioninventory", "search", "setup", "rulesengine");
include GLPI_ROOT . "/inc/includes.php";
commonHeader($LANG['plugin_fusioninventory']["title"][0], $_SERVER["PHP_SELF"], "plugins", "fusioninventory", "snmp_auth");
PluginFusioninventoryAuth::checkRight("snmp_authentification", "r");
$config = new PluginFusioninventoryConfig();
PluginFusioninventoryDisplay::mini_menu();
// Forms for FILE
if ($config->getValue("authsnmp") == "file") {
    $plugin_fusioninventory_snmp_auth = new PluginFusioninventorySnmpauth();
    if (!isset($_GET["ID"])) {
        echo $plugin_fusioninventory_snmp_auth->plugin_fusioninventory_snmp_connections();
    }
} else {
    if ($config->getValue("authsnmp") == "DB") {
        // Forms for DB
        $_GET['target'] = "snmp_auth.php";
        manageGetValuesInSearch(PLUGIN_FUSIONINVENTORY_SNMP_AUTH);
        searchForm(PLUGIN_FUSIONINVENTORY_SNMP_AUTH, $_GET);
        showList(PLUGIN_FUSIONINVENTORY_SNMP_AUTH, $_GET);
    } else {
        echo $LANG['plugin_fusioninventory']["functionalities"][19];
    }
}
 /**
  * Display form for config tab in fusioninventory config form
  *
  * @param $options array
  *
  * @return bool TRUE if form is ok
  *
  **/
 static function showFormDeploy($options = array())
 {
     $pfConfig = new PluginFusioninventoryConfig();
     $pfConfig->fields['id'] = 1;
     $options['colspan'] = 1;
     $pfConfig->showFormHeader($options);
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Root folder for sending files from server', 'fusioninventory') . "&nbsp;:</td>";
     echo "<td>";
     echo "<input type='text' name='server_upload_path' value='" . $pfConfig->getValue('server_upload_path') . "' size='60' />";
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td>" . __('Use this GLPI server as a mirror server', 'fusioninventory') . "&nbsp;:</td>";
     echo "<td>";
     Dropdown::showYesNo("server_as_mirror", $pfConfig->getValue('server_as_mirror'));
     echo "</td>";
     echo "</tr>";
     $options['candel'] = FALSE;
     $pfConfig->showFormButtons($options);
     return TRUE;
 }
 static function cronWakeupAgents($crontask)
 {
     global $DB;
     $wakeupArray = array();
     $tasks = array();
     //Get the maximum number of agent to wakeup,
     //as allowed in the general configuration
     $config = new PluginFusioninventoryConfig();
     $maxWakeUp = $config->getValue('wakeup_agent_max');
     $counter = 0;
     $continue = true;
     //Get all active timeslots
     $timeslot = new PluginFusioninventoryTimeslot();
     $timeslots = $timeslot->getCurrentActiveTimeslots();
     if (empty($timeslots)) {
         $query_timeslot = '';
     } else {
         $query_timeslot = "OR (`plugin_fusioninventory_timeslots_id` IN (" . implode(',', $timeslots) . "))";
     }
     //Get all active task requiring an agent wakeup
     //Check all tasks without timeslot or task with a current active timeslot
     $query = "SELECT `id`, `wakeup_agent_counter`, `wakeup_agent_time`, `last_agent_wakeup` \n                 FROM `glpi_plugin_fusioninventory_tasks` \n                 WHERE `wakeup_agent_time` > 0 \n                    AND `wakeup_agent_counter` > 0\n                    AND `is_active`='1' \n                    AND ((`plugin_fusioninventory_timeslots_id`='0') \n                    {$query_timeslot})";
     foreach ($DB->request($query) as $task) {
         if (!is_null($task['wakeup_agent_time'])) {
             //Do not wake up is last wake up in inferior to the minimum wake up interval
             $interval = time() - strtotime($task['last_agent_wakeup']);
             if ($interval < $task['wakeup_agent_time'] * MINUTE_TIMESTAMP) {
                 continue;
             }
         }
         //For each task, get a number of taskjobs at the PREPARED state
         //(the maximum is defined in wakeup_agent_counter)
         $query_states = "SELECT `taskjobstates`.`plugin_fusioninventory_agents_id`, \n                                 `tasks`.`id` as `taskID`, \n                                 `tasks`.`wakeup_agent_time`,\n                                 `tasks`.`last_agent_wakeup`\n                          FROM `glpi_plugin_fusioninventory_taskjobstates` as `taskjobstates`,\n                               `glpi_plugin_fusioninventory_taskjobs` as `taskjobs`\n                          LEFT JOIN `glpi_plugin_fusioninventory_tasks` as `tasks` \n                             ON `tasks`.`id`=`taskjobs`.`plugin_fusioninventory_tasks_id`\n                          WHERE `tasks`.`id`='" . $task['id'] . "' \n                             AND `taskjobs`.`id`=`taskjobstates`.`plugin_fusioninventory_taskjobs_id` \n                             AND `taskjobstates`.`state`='" . PluginFusioninventoryTaskjobstate::PREPARED . "' \n                          ORDER BY `taskjobstates`.`id` ASC LIMIT " . $task['wakeup_agent_counter'];
         foreach ($DB->request($query_states) as $state) {
             $agents_id = $state['plugin_fusioninventory_agents_id'];
             //Check if agent is already added to the list of agents to wake up
             if (!isset($wakeupArray[$agents_id])) {
                 //This agent must be woken up
                 $wakeupArray[$agents_id] = $agents_id;
                 $counter++;
             }
             //Store task ID
             if (!in_array($state['taskID'], $tasks)) {
                 $tasks[] = $state['taskID'];
             }
             //Do not process more than the maximum number of wakeup allowed in the configuration
             if ($counter >= $maxWakeUp) {
                 if (PluginFusioninventoryConfig::isExtradebugActive()) {
                     Toolbox::logDebug(__("Maximum number of agent wakeup reached", 'fusioninventory') . ":" . $maxWakeUp);
                 }
                 $continue = false;
                 break;
             }
         }
         //We've reached the maximum number of agents to wake up !
         if (!$continue) {
             break;
         }
     }
     //Number of agents successfully woken up
     $wokeup = 0;
     $myTask = new PluginFusioninventoryTask();
     if (!empty($tasks)) {
         //Update last wake up time each task
         $query_lastrun = "UPDATE `glpi_plugin_fusioninventory_tasks` \n                           SET `last_agent_wakeup`='" . $_SESSION['glpi_currenttime'] . "' \n                           WHERE `id` IN (" . implode(",", $tasks) . ")";
         $DB->query($query_lastrun);
         $agent = new PluginFusioninventoryAgent();
         //Try to wake up agents one by one
         foreach ($wakeupArray as $ID => $value) {
             $agent->getFromDB($ID);
             if ($agent->wakeUp()) {
                 $wokeup++;
             }
         }
     }
     $crontask->addVolume($wokeup);
     return true;
 }
 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+;)/', '&amp;', $dataArray[0]);
                 if (!empty($dataArray[0]) and empty($array_tmp['manufacturers_id'])) {
                     $array_tmp['manufacturers_id'] = $dataArray[0];
                 }
                 $dataArray[1] = preg_replace('/&(?!\\w+;)/', '&amp;', $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;
 }
Пример #7
0
/**
* Check if FusionInventory need to be updated
*
* @param
*
* @return 0 (no need update) OR 1 (need update)
**/
function plugin_fusioninventory_needUpdate()
{
    /**
     *  List of all FusionInventorys versions :
     *    1.0.0
     *    1.1.0 non exists glpi_plugin_fusioninventory_agents (MySQL)
     *    2.0.0 non exists glpi_plugin_fusioninventory_config_discovery (MySQL)
     *    2.0.1 Nothing
     *    2.0.2 config version field 2.0.2
     *    2.1.0 config version field 2.1.0
     *    2.1.1 config version field 2.1.1
     **/
    if (!TableExists("glpi_plugin_fusioninventory_config")) {
        return 0;
        // Installation
    } else {
        if (!TableExists("glpi_plugin_fusioninventory_agents")) {
            return 1;
            //Update
        } else {
            if (!TableExists("glpi_plugin_fusioninventory_config_discovery")) {
                //		return 1; // Update (Bug with new version SVN 2.1.4
            } else {
                if (!FieldExists("glpi_plugin_fusioninventory_config", "version")) {
                    return 1;
                    // Update
                } else {
                    if (FieldExists("glpi_plugin_fusioninventory_config", "version")) {
                        $config = new PluginFusioninventoryConfig();
                        if ($config->getValue('version') != "2.1.3") {
                            return 1;
                        } else {
                            return 0;
                        }
                    } else {
                        return 0;
                    }
                }
            }
        }
    }
}
 static function getServerFileTree($params)
 {
     $nodes = array();
     if (isset($params['node'])) {
         //root node
         $pfConfig = new PluginFusioninventoryConfig();
         $dir = $pfConfig->getValue('server_upload_path');
         // leaf node
         if ($params['node'] != -1) {
             $dir = $params['node'];
         }
         if ($handle = opendir($dir)) {
             $folders = $files = array();
             //list files in dir selected
             //we store folders and files separately to sort them alphabeticaly separatly
             while (FALSE !== ($entry = readdir($handle))) {
                 if ($entry != "." && $entry != "..") {
                     $filepath = $dir . "/" . $entry;
                     if (is_dir($filepath)) {
                         $folders[$filepath] = $entry;
                     } else {
                         $files[$filepath] = $entry;
                     }
                 }
             }
             //sort folders and files (and maintain index association)
             asort($folders);
             asort($files);
             //add folders in json
             foreach ($folders as $filepath => $entry) {
                 $path['text'] = $entry;
                 $path['id'] = $filepath;
                 $path['draggable'] = FALSE;
                 $path['leaf'] = FALSE;
                 $path['cls'] = 'folder';
                 $nodes[] = $path;
             }
             //add files in json
             foreach ($files as $filepath => $entry) {
                 $path['text'] = $entry;
                 $path['id'] = $filepath;
                 $path['draggable'] = FALSE;
                 $path['leaf'] = TRUE;
                 $path['cls'] = 'file';
                 $nodes[] = $path;
             }
             closedir($handle);
         }
     }
     print json_encode($nodes);
 }
 function CleanErrors()
 {
     $ptc = new PluginFusioninventoryConfig();
     $data = $this->find("`date`<DATE_SUB(NOW(), INTERVAL " . $ptc->getValue('delete_agent_process') . " HOUR)");
     foreach ($data as $process_id => $dataInfos) {
         $this->deleteFromDB($process_id, 1);
     }
 }
 /**
  * Update computer data
  *
  * @global type $DB
  *
  * @param php array $a_computerinventory all data from the agent
  * @param integer $computers_id id of the computer
  * @param boolean $no_history set true if not want history
  *
  * @return nothing
  */
 function updateComputer($a_computerinventory, $computers_id, $no_history, $setdynamic = 0)
 {
     global $DB, $CFG_GLPI;
     $computer = new Computer();
     $pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer();
     $item_DeviceProcessor = new Item_DeviceProcessor();
     $deviceProcessor = new DeviceProcessor();
     $item_DeviceMemory = new Item_DeviceMemory();
     $deviceMemory = new DeviceMemory();
     $computerVirtualmachine = new ComputerVirtualMachine();
     $computerDisk = new ComputerDisk();
     $item_DeviceControl = new Item_DeviceControl();
     $item_DeviceHardDrive = new Item_DeviceHardDrive();
     $item_DeviceDrive = new Item_DeviceDrive();
     $item_DeviceGraphicCard = new Item_DeviceGraphicCard();
     $item_DeviceNetworkCard = new Item_DeviceNetworkCard();
     $item_DeviceSoundCard = new Item_DeviceSoundCard();
     $networkPort = new NetworkPort();
     $networkName = new NetworkName();
     $iPAddress = new IPAddress();
     $ipnetwork = new IPNetwork();
     $pfInventoryComputerAntivirus = new PluginFusioninventoryInventoryComputerAntivirus();
     $pfConfig = new PluginFusioninventoryConfig();
     $pfComputerLicenseInfo = new PluginFusioninventoryComputerLicenseInfo();
     $computer_Item = new Computer_Item();
     $monitor = new Monitor();
     $printer = new Printer();
     $peripheral = new Peripheral();
     //      $pfInventoryComputerStorage   = new PluginFusioninventoryInventoryComputerStorage();
     //      $pfInventoryComputerStorage_Storage =
     //             new PluginFusioninventoryInventoryComputerStorage_Storage();
     $computer->getFromDB($computers_id);
     $a_lockable = PluginFusioninventoryLock::getLockFields('glpi_computers', $computers_id);
     // * Computer
     $db_computer = array();
     $db_computer = $computer->fields;
     $computerName = $a_computerinventory['Computer']['name'];
     $a_ret = PluginFusioninventoryToolbox::checkLock($a_computerinventory['Computer'], $db_computer, $a_lockable);
     $a_computerinventory['Computer'] = $a_ret[0];
     $input = $a_computerinventory['Computer'];
     $input['id'] = $computers_id;
     $history = TRUE;
     if ($no_history) {
         $history = FALSE;
     }
     $input['_no_history'] = $no_history;
     PluginFusioninventoryInventoryComputerInventory::addDefaultStateIfNeeded($input);
     $computer->update($input, !$no_history);
     $this->computer = $computer;
     // * Computer fusion (ext)
     $db_computer = array();
     if ($no_history === FALSE) {
         $query = "SELECT * FROM `glpi_plugin_fusioninventory_inventorycomputercomputers`\n                WHERE `computers_id` = '{$computers_id}'\n                LIMIT 1";
         $result = $DB->query($query);
         while ($data = $DB->fetch_assoc($result)) {
             foreach ($data as $key => $value) {
                 $data[$key] = Toolbox::addslashes_deep($value);
             }
             $db_computer = $data;
         }
     }
     if (count($db_computer) == '0') {
         // Add
         $a_computerinventory['fusioninventorycomputer']['computers_id'] = $computers_id;
         $pfInventoryComputerComputer->add($a_computerinventory['fusioninventorycomputer'], array(), FALSE);
     } else {
         // Update
         if (!empty($db_computer['serialized_inventory'])) {
             $setdynamic = 0;
         }
         $idtmp = $db_computer['id'];
         unset($db_computer['id']);
         unset($db_computer['computers_id']);
         $a_ret = PluginFusioninventoryToolbox::checkLock($a_computerinventory['fusioninventorycomputer'], $db_computer);
         $a_computerinventory['fusioninventorycomputer'] = $a_ret[0];
         $db_computer = $a_ret[1];
         $input = $a_computerinventory['fusioninventorycomputer'];
         $input['id'] = $idtmp;
         $input['_no_history'] = $no_history;
         $pfInventoryComputerComputer->update($input, !$no_history);
     }
     // Put all link item dynamic (in case of update computer not yet inventoried with fusion)
     if ($setdynamic == 1) {
         $this->setDynamicLinkItems($computers_id);
     }
     // * Processors
     if ($pfConfig->getValue("component_processor") != 0) {
         $db_processors = array();
         if ($no_history === FALSE) {
             $query = "SELECT `glpi_items_deviceprocessors`.`id`, `designation`,\n                     `frequency`, `frequence`, `frequency_default`,\n                     `serial`, `manufacturers_id`, `glpi_items_deviceprocessors`.`nbcores`,\n                     `glpi_items_deviceprocessors`.`nbthreads`\n                  FROM `glpi_items_deviceprocessors`\n                  LEFT JOIN `glpi_deviceprocessors`\n                     ON `deviceprocessors_id`=`glpi_deviceprocessors`.`id`\n                  WHERE `items_id` = '{$computers_id}'\n                     AND `itemtype`='Computer'\n                     AND `is_dynamic`='1'";
             $result = $DB->query($query);
             while ($data = $DB->fetch_assoc($result)) {
                 $idtmp = $data['id'];
                 unset($data['id']);
                 $db_processors[$idtmp] = Toolbox::addslashes_deep($data);
             }
         }
         if (count($db_processors) == 0) {
             foreach ($a_computerinventory['processor'] as $a_processor) {
                 $this->addProcessor($a_processor, $computers_id, $no_history);
             }
         } else {
             // Check all fields from source: 'designation', 'serial', 'manufacturers_id',
             // 'frequence'
             foreach ($a_computerinventory['processor'] as $key => $arrays) {
                 $frequence = $arrays['frequence'];
                 unset($arrays['frequence']);
                 unset($arrays['frequency']);
                 unset($arrays['frequency_default']);
                 foreach ($db_processors as $keydb => $arraydb) {
                     $frequencedb = $arraydb['frequence'];
                     unset($arraydb['frequence']);
                     unset($arraydb['frequency']);
                     unset($arraydb['frequency_default']);
                     if ($arrays == $arraydb) {
                         $a_criteria = $deviceProcessor->getImportCriteria();
                         $criteriafrequence = $a_criteria['frequence'];
                         $compare = explode(':', $criteriafrequence);
                         if ($frequence > $frequencedb - $compare[1] && $frequence < $frequencedb + $compare[1]) {
                             unset($a_computerinventory['processor'][$key]);
                             unset($db_processors[$keydb]);
                             break;
                         }
                     }
                 }
             }
             if (count($a_computerinventory['processor']) == 0 and count($db_processors) == 0) {
                 // Nothing to do
             } else {
                 if (count($db_processors) != 0) {
                     // Delete processor in DB
                     foreach ($db_processors as $idtmp => $data) {
                         $item_DeviceProcessor->delete(array('id' => $idtmp), 1);
                     }
                 }
                 if (count($a_computerinventory['processor']) != 0) {
                     foreach ($a_computerinventory['processor'] as $a_processor) {
                         $this->addProcessor($a_processor, $computers_id, $no_history);
                     }
                 }
             }
         }
     }
     // * Memories
     if ($pfConfig->getValue("component_memory") != 0) {
         $db_memories = array();
         if ($no_history === FALSE) {
             $query = "SELECT `glpi_items_devicememories`.`id`, `designation`, `size`,\n                     `frequence`, `serial`, `devicememorytypes_id`,\n                     `glpi_items_devicememories`.`busID`\n                     FROM `glpi_items_devicememories`\n                  LEFT JOIN `glpi_devicememories` ON `devicememories_id`=`glpi_devicememories`.`id`\n                  WHERE `items_id` = '{$computers_id}'\n                     AND `itemtype`='Computer'\n                     AND `is_dynamic`='1'";
             $result = $DB->query($query);
             while ($data = $DB->fetch_assoc($result)) {
                 $idtmp = $data['id'];
                 unset($data['id']);
                 $data1 = Toolbox::addslashes_deep($data);
                 $db_memories[$idtmp] = $data1;
             }
         }
         if (count($db_memories) == 0) {
             foreach ($a_computerinventory['memory'] as $a_memory) {
                 $this->addMemory($a_memory, $computers_id, $no_history);
             }
         } else {
             // Check all fields from source: 'designation', 'serial', 'size',
             // 'devicememorytypes_id', 'frequence'
             foreach ($a_computerinventory['memory'] as $key => $arrays) {
                 $frequence = $arrays['frequence'];
                 unset($arrays['frequence']);
                 foreach ($db_memories as $keydb => $arraydb) {
                     $frequencedb = $arraydb['frequence'];
                     unset($arraydb['frequence']);
                     if ($arrays == $arraydb) {
                         $a_criteria = $deviceMemory->getImportCriteria();
                         $criteriafrequence = $a_criteria['frequence'];
                         $compare = explode(':', $criteriafrequence);
                         if ($frequence > $frequencedb - $compare[1] && $frequence < $frequencedb + $compare[1]) {
                             unset($a_computerinventory['memory'][$key]);
                             unset($db_memories[$keydb]);
                             break;
                         }
                     }
                 }
             }
             if (count($a_computerinventory['memory']) == 0 and count($db_memories) == 0) {
                 // Nothing to do
             } else {
                 if (count($db_memories) != 0) {
                     // Delete memory in DB
                     foreach ($db_memories as $idtmp => $data) {
                         $item_DeviceMemory->delete(array('id' => $idtmp), 1);
                     }
                 }
                 if (count($a_computerinventory['memory']) != 0) {
                     foreach ($a_computerinventory['memory'] as $a_memory) {
                         $this->addMemory($a_memory, $computers_id, $no_history);
                     }
                 }
             }
         }
     }
     // * Hard drive
     if ($pfConfig->getValue("component_harddrive") != 0) {
         $db_harddrives = array();
         if ($no_history === FALSE) {
             $query = "SELECT `glpi_items_deviceharddrives`.`id`, `serial`,\n                     `capacity`\n                     FROM `glpi_items_deviceharddrives`\n                  WHERE `items_id` = '{$computers_id}'\n                     AND `itemtype`='Computer'\n                     AND `is_dynamic`='1'";
             $result = $DB->query($query);
             while ($data = $DB->fetch_assoc($result)) {
                 $idtmp = $data['id'];
                 unset($data['id']);
                 $data1 = Toolbox::addslashes_deep($data);
                 $data2 = array_map('strtolower', $data1);
                 $db_harddrives[$idtmp] = $data2;
             }
         }
         if (count($db_harddrives) == 0) {
             foreach ($a_computerinventory['harddrive'] as $a_harddrive) {
                 $this->addHardDisk($a_harddrive, $computers_id, $no_history);
             }
         } else {
             foreach ($a_computerinventory['harddrive'] as $key => $arrays) {
                 $arrayslower = array_map('strtolower', $arrays);
                 foreach ($db_harddrives as $keydb => $arraydb) {
                     if ($arrayslower['serial'] == $arraydb['serial']) {
                         if ($arraydb['capacity'] == 0 and $arrayslower['capacity'] > 0) {
                             $input = array('id' => $keydb, 'capacity' => $arrayslower['capacity']);
                             $item_DeviceHardDrive->update($input);
                         }
                         unset($a_computerinventory['harddrive'][$key]);
                         unset($db_harddrives[$keydb]);
                         break;
                     }
                 }
             }
             if (count($a_computerinventory['harddrive']) == 0 and count($db_harddrives) == 0) {
                 // Nothing to do
             } else {
                 if (count($db_harddrives) != 0) {
                     // Delete hard drive in DB
                     foreach ($db_harddrives as $idtmp => $data) {
                         $item_DeviceHardDrive->delete(array('id' => $idtmp), 1);
                     }
                 }
                 if (count($a_computerinventory['harddrive']) != 0) {
                     foreach ($a_computerinventory['harddrive'] as $a_harddrive) {
                         $this->addHardDisk($a_harddrive, $computers_id, $no_history);
                     }
                 }
             }
         }
     }
     // * drive
     if ($pfConfig->getValue("component_drive") != 0) {
         $db_drives = array();
         if ($no_history === FALSE) {
             $query = "SELECT `glpi_items_devicedrives`.`id`, `serial`,\n                     `glpi_devicedrives`.`designation`\n                     FROM `glpi_items_devicedrives`\n                  LEFT JOIN `glpi_devicedrives` ON `devicedrives_id`=`glpi_devicedrives`.`id`\n                  WHERE `items_id` = '{$computers_id}'\n                     AND `itemtype`='Computer'\n                     AND `is_dynamic`='1'";
             $result = $DB->query($query);
             while ($data = $DB->fetch_assoc($result)) {
                 $idtmp = $data['id'];
                 unset($data['id']);
                 $data1 = Toolbox::addslashes_deep($data);
                 $data2 = array_map('strtolower', $data1);
                 $db_drives[$idtmp] = $data2;
             }
         }
         if (count($db_drives) == 0) {
             foreach ($a_computerinventory['drive'] as $a_drive) {
                 $this->addDrive($a_drive, $computers_id, $no_history);
             }
         } else {
             foreach ($a_computerinventory['drive'] as $key => $arrays) {
                 $arrayslower = array_map('strtolower', $arrays);
                 if ($arrayslower['serial'] == '') {
                     foreach ($db_drives as $keydb => $arraydb) {
                         if ($arrayslower['designation'] == $arraydb['designation']) {
                             unset($a_computerinventory['drive'][$key]);
                             unset($db_drives[$keydb]);
                             break;
                         }
                     }
                 } else {
                     foreach ($db_drives as $keydb => $arraydb) {
                         if ($arrayslower['serial'] == $arraydb['serial']) {
                             unset($a_computerinventory['drive'][$key]);
                             unset($db_drives[$keydb]);
                             break;
                         }
                     }
                 }
             }
             if (count($a_computerinventory['drive']) == 0 and count($db_drives) == 0) {
                 // Nothing to do
             } else {
                 if (count($db_drives) != 0) {
                     // Delete drive in DB
                     foreach ($db_drives as $idtmp => $data) {
                         $item_DeviceDrive->delete(array('id' => $idtmp), 1);
                     }
                 }
                 if (count($a_computerinventory['drive']) != 0) {
                     foreach ($a_computerinventory['drive'] as $a_drive) {
                         $this->addDrive($a_drive, $computers_id, $no_history);
                     }
                 }
             }
         }
     }
     // * Graphiccard
     if ($pfConfig->getValue("component_graphiccard") != 0) {
         $db_graphiccards = array();
         if ($no_history === FALSE) {
             $query = "SELECT `glpi_items_devicegraphiccards`.`id`, `designation`, `memory`\n                     FROM `glpi_items_devicegraphiccards`\n                  LEFT JOIN `glpi_devicegraphiccards`\n                     ON `devicegraphiccards_id`=`glpi_devicegraphiccards`.`id`\n                  WHERE `items_id` = '{$computers_id}'\n                     AND `itemtype`='Computer'\n                     AND `is_dynamic`='1'";
             $result = $DB->query($query);
             while ($data = $DB->fetch_assoc($result)) {
                 $idtmp = $data['id'];
                 unset($data['id']);
                 if (preg_match("/[^a-zA-Z0-9 \\-_\\(\\)]+/", $data['designation'])) {
                     $data['designation'] = Toolbox::addslashes_deep($data['designation']);
                 }
                 $data['designation'] = trim(strtolower($data['designation']));
                 $db_graphiccards[$idtmp] = $data;
             }
         }
         if (count($db_graphiccards) == 0) {
             foreach ($a_computerinventory['graphiccard'] as $a_graphiccard) {
                 $this->addGraphicCard($a_graphiccard, $computers_id, $no_history);
             }
         } else {
             // Check all fields from source: 'designation', 'memory'
             foreach ($a_computerinventory['graphiccard'] as $key => $arrays) {
                 $arrays['designation'] = strtolower($arrays['designation']);
                 foreach ($db_graphiccards as $keydb => $arraydb) {
                     if ($arrays == $arraydb) {
                         unset($a_computerinventory['graphiccard'][$key]);
                         unset($db_graphiccards[$keydb]);
                         break;
                     }
                 }
             }
             if (count($a_computerinventory['graphiccard']) == 0 and count($db_graphiccards) == 0) {
                 // Nothing to do
             } else {
                 if (count($db_graphiccards) != 0) {
                     // Delete graphiccard in DB
                     foreach ($db_graphiccards as $idtmp => $data) {
                         $item_DeviceGraphicCard->delete(array('id' => $idtmp), 1);
                     }
                 }
                 if (count($a_computerinventory['graphiccard']) != 0) {
                     foreach ($a_computerinventory['graphiccard'] as $a_graphiccard) {
                         $this->addGraphicCard($a_graphiccard, $computers_id, $no_history);
                     }
                 }
             }
         }
     }
     // * networkcard
     if ($pfConfig->getValue("component_networkcard") != 0) {
         $db_networkcards = array();
         if ($no_history === FALSE) {
             $query = "SELECT `glpi_items_devicenetworkcards`.`id`, `designation`, `mac`,\n                     `manufacturers_id`\n                     FROM `glpi_items_devicenetworkcards`\n                  LEFT JOIN `glpi_devicenetworkcards`\n                     ON `devicenetworkcards_id`=`glpi_devicenetworkcards`.`id`\n                  WHERE `items_id` = '{$computers_id}'\n                     AND `itemtype`='Computer'\n                     AND `is_dynamic`='1'";
             $result = $DB->query($query);
             while ($data = $DB->fetch_assoc($result)) {
                 $idtmp = $data['id'];
                 unset($data['id']);
                 if (preg_match("/[^a-zA-Z0-9 \\-_\\(\\)]+/", $data['designation'])) {
                     $data['designation'] = Toolbox::addslashes_deep($data['designation']);
                 }
                 $data['designation'] = trim(strtolower($data['designation']));
                 $db_networkcards[$idtmp] = $data;
             }
         }
         if (count($db_networkcards) == 0) {
             foreach ($a_computerinventory['networkcard'] as $a_networkcard) {
                 $this->addNetworkCard($a_networkcard, $computers_id, $no_history);
             }
         } else {
             // Check all fields from source: 'designation', 'mac'
             foreach ($a_computerinventory['networkcard'] as $key => $arrays) {
                 $arrays['designation'] = strtolower($arrays['designation']);
                 foreach ($db_networkcards as $keydb => $arraydb) {
                     if ($arrays == $arraydb) {
                         unset($a_computerinventory['networkcard'][$key]);
                         unset($db_networkcards[$keydb]);
                         break;
                     }
                 }
             }
             if (count($a_computerinventory['networkcard']) == 0 and count($db_networkcards) == 0) {
                 // Nothing to do
             } else {
                 if (count($db_networkcards) != 0) {
                     // Delete networkcard in DB
                     foreach ($db_networkcards as $idtmp => $data) {
                         $item_DeviceNetworkCard->delete(array('id' => $idtmp), 1);
                     }
                 }
                 if (count($a_computerinventory['networkcard']) != 0) {
                     foreach ($a_computerinventory['networkcard'] as $a_networkcard) {
                         $this->addNetworkCard($a_networkcard, $computers_id, $no_history);
                     }
                 }
             }
         }
     }
     // * Sound
     if ($pfConfig->getValue("component_soundcard") != 0) {
         $db_soundcards = array();
         if ($no_history === FALSE) {
             $query = "SELECT `glpi_items_devicesoundcards`.`id`, `designation`, `comment`,\n                     `manufacturers_id` FROM `glpi_items_devicesoundcards`\n                  LEFT JOIN `glpi_devicesoundcards`\n                     ON `devicesoundcards_id`=`glpi_devicesoundcards`.`id`\n                  WHERE `items_id` = '{$computers_id}'\n                     AND `itemtype`='Computer'\n                     AND `is_dynamic`='1'";
             $result = $DB->query($query);
             while ($data = $DB->fetch_assoc($result)) {
                 $idtmp = $data['id'];
                 unset($data['id']);
                 $data1 = Toolbox::addslashes_deep($data);
                 $db_soundcards[$idtmp] = $data1;
             }
         }
         if (count($db_soundcards) == 0) {
             foreach ($a_computerinventory['soundcard'] as $a_soundcard) {
                 $this->addSoundCard($a_soundcard, $computers_id, $no_history);
             }
         } else {
             // Check all fields from source: 'designation', 'memory', 'manufacturers_id'
             foreach ($a_computerinventory['soundcard'] as $key => $arrays) {
                 //               $arrayslower = array_map('strtolower', $arrays);
                 $arrayslower = $arrays;
                 foreach ($db_soundcards as $keydb => $arraydb) {
                     if ($arrayslower == $arraydb) {
                         unset($a_computerinventory['soundcard'][$key]);
                         unset($db_soundcards[$keydb]);
                         break;
                     }
                 }
             }
             if (count($a_computerinventory['soundcard']) == 0 and count($db_soundcards) == 0) {
                 // Nothing to do
             } else {
                 if (count($db_soundcards) != 0) {
                     // Delete soundcard in DB
                     foreach ($db_soundcards as $idtmp => $data) {
                         $item_DeviceSoundCard->delete(array('id' => $idtmp), 1);
                     }
                 }
                 if (count($a_computerinventory['soundcard']) != 0) {
                     foreach ($a_computerinventory['soundcard'] as $a_soundcard) {
                         $this->addSoundCard($a_soundcard, $computers_id, $no_history);
                     }
                 }
             }
         }
     }
     // * Controllers
     if ($pfConfig->getValue("component_control") != 0) {
         $db_controls = array();
         if ($no_history === FALSE) {
             $query = "SELECT `glpi_items_devicecontrols`.`id`, `interfacetypes_id`,\n                     `manufacturers_id`, `designation` FROM `glpi_items_devicecontrols`\n                  LEFT JOIN `glpi_devicecontrols` ON `devicecontrols_id`=`glpi_devicecontrols`.`id`\n                  WHERE `items_id` = '{$computers_id}'\n                     AND `itemtype`='Computer'\n                     AND `is_dynamic`='1'";
             $result = $DB->query($query);
             while ($data = $DB->fetch_assoc($result)) {
                 $idtmp = $data['id'];
                 unset($data['id']);
                 $data1 = Toolbox::addslashes_deep($data);
                 $data2 = array_map('strtolower', $data1);
                 $db_controls[$idtmp] = $data2;
             }
         }
         if (count($db_controls) == 0) {
             foreach ($a_computerinventory['controller'] as $a_control) {
                 $this->addControl($a_control, $computers_id, $no_history);
             }
         } else {
             // Check all fields from source:
             foreach ($a_computerinventory['controller'] as $key => $arrays) {
                 $arrayslower = array_map('strtolower', $arrays);
                 foreach ($db_controls as $keydb => $arraydb) {
                     if ($arrayslower == $arraydb) {
                         unset($a_computerinventory['controller'][$key]);
                         unset($db_controls[$keydb]);
                         break;
                     }
                 }
             }
             if (count($a_computerinventory['controller']) == 0 and count($db_controls) == 0) {
                 // Nothing to do
             } else {
                 if (count($db_controls) != 0) {
                     // Delete controller in DB
                     foreach ($db_controls as $idtmp => $data) {
                         $item_DeviceControl->delete(array('id' => $idtmp), 1);
                     }
                 }
                 if (count($a_computerinventory['controller']) != 0) {
                     foreach ($a_computerinventory['controller'] as $a_control) {
                         $this->addControl($a_control, $computers_id, $no_history);
                     }
                 }
             }
         }
     }
     // * Software
     if ($pfConfig->getValue("import_software") != 0) {
         $entities_id = 0;
         if (count($a_computerinventory['software']) > 0) {
             $a_softfirst = current($a_computerinventory['software']);
             if (isset($a_softfirst['entities_id'])) {
                 $entities_id = $a_softfirst['entities_id'];
             }
         }
         $db_software = array();
         if ($no_history === FALSE) {
             $query = "SELECT `glpi_computers_softwareversions`.`id` as sid,\n                          `glpi_softwares`.`name`,\n                          `glpi_softwareversions`.`name` AS version,\n                          `glpi_softwares`.`manufacturers_id`,\n                          `glpi_softwareversions`.`entities_id`,\n                          `glpi_computers_softwareversions`.`is_template_computer`,\n                          `glpi_computers_softwareversions`.`is_deleted_computer`\n                   FROM `glpi_computers_softwareversions`\n                   LEFT JOIN `glpi_softwareversions`\n                        ON (`glpi_computers_softwareversions`.`softwareversions_id`\n                              = `glpi_softwareversions`.`id`)\n                   LEFT JOIN `glpi_softwares`\n                        ON (`glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`)\n                   WHERE `glpi_computers_softwareversions`.`computers_id` = '{$computers_id}'\n                     AND `glpi_computers_softwareversions`.`is_dynamic`='1'";
             $result = $DB->query($query);
             while ($data = $DB->fetch_assoc($result)) {
                 $idtmp = $data['sid'];
                 unset($data['sid']);
                 if (preg_match("/[^a-zA-Z0-9 \\-_\\(\\)]+/", $data['name'])) {
                     $data['name'] = Toolbox::addslashes_deep($data['name']);
                 }
                 if (preg_match("/[^a-zA-Z0-9 \\-_\\(\\)]+/", $data['version'])) {
                     $data['version'] = Toolbox::addslashes_deep($data['version']);
                 }
                 $comp_key = strtolower($data['name']) . "\$\$\$\$" . strtolower($data['version']) . "\$\$\$\$" . $data['manufacturers_id'] . "\$\$\$\$" . $data['entities_id'];
                 $db_software[$comp_key] = $idtmp;
             }
         }
         $lastSoftwareid = 0;
         $lastSoftwareVid = 0;
         /*
          * Schema
          *
          * LOCK software
          * 1/ Add all software
          * RELEASE software
          *
          * LOCK softwareversion
          * 2/ Add all software versions
          * RELEASE softwareversion
          *
          * 3/ add version to computer
          *
          */
         if (count($db_software) == 0) {
             // there are no software associated with computer
             $nb_unicity = count(FieldUnicity::getUnicityFieldsConfig("Software", $entities_id));
             $options = array();
             if ($nb_unicity == 0) {
                 $options['disable_unicity_check'] = TRUE;
             }
             $a_softwareInventory = array();
             $a_softwareVersionInventory = array();
             $lastSoftwareid = $this->loadSoftwares($entities_id, $a_computerinventory['software'], $lastSoftwareid);
             $queryDBLOCK = "INSERT INTO `glpi_plugin_fusioninventory_dblocksoftwares`\n                     SET `value`='1'";
             $CFG_GLPI["use_log_in_files"] = FALSE;
             while (!$DB->query($queryDBLOCK)) {
                 usleep(100000);
             }
             $CFG_GLPI["use_log_in_files"] = TRUE;
             $this->loadSoftwares($entities_id, $a_computerinventory['software'], $lastSoftwareid);
             foreach ($a_computerinventory['software'] as $a_software) {
                 if (!isset($this->softList[$a_software['name'] . "\$\$\$\$" . $a_software['manufacturers_id']])) {
                     $this->addSoftware($a_software, $options);
                 }
             }
             $queryDBLOCK = "DELETE FROM `glpi_plugin_fusioninventory_dblocksoftwares`\n                     WHERE `value`='1'";
             $DB->query($queryDBLOCK);
             $lastSoftwareVid = $this->loadSoftwareVersions($entities_id, $a_computerinventory['software'], $lastSoftwareVid);
             $queryDBLOCK = "INSERT INTO `glpi_plugin_fusioninventory_dblocksoftwareversions`\n                     SET `value`='1'";
             $CFG_GLPI["use_log_in_files"] = FALSE;
             while (!$DB->query($queryDBLOCK)) {
                 usleep(100000);
             }
             $CFG_GLPI["use_log_in_files"] = TRUE;
             $this->loadSoftwareVersions($entities_id, $a_computerinventory['software'], $lastSoftwareVid);
             foreach ($a_computerinventory['software'] as $a_software) {
                 $softwares_id = $this->softList[$a_software['name'] . "\$\$\$\$" . $a_software['manufacturers_id']];
                 if (!isset($this->softVersionList[strtolower($a_software['version']) . "\$\$\$\$" . $softwares_id])) {
                     $this->addSoftwareVersion($a_software, $softwares_id);
                 }
             }
             $queryDBLOCK = "DELETE FROM `glpi_plugin_fusioninventory_dblocksoftwareversions`\n                     WHERE `value`='1'";
             $DB->query($queryDBLOCK);
             $a_toinsert = array();
             foreach ($a_computerinventory['software'] as $a_software) {
                 $softwares_id = $this->softList[$a_software['name'] . "\$\$\$\$" . $a_software['manufacturers_id']];
                 $softwareversions_id = $this->softVersionList[strtolower($a_software['version']) . "\$\$\$\$" . $softwares_id];
                 $a_tmp = array('computers_id' => $computers_id, 'softwareversions_id' => $softwareversions_id, 'is_dynamic' => 1, 'entities_id' => $a_software['entities_id']);
                 $a_toinsert[] = "('" . implode("','", $a_tmp) . "')";
             }
             if (count($a_toinsert) > 0) {
                 $this->addSoftwareVersionsComputer($a_toinsert);
                 if (!$no_history) {
                     foreach ($a_computerinventory['software'] as $a_software) {
                         $softwares_id = $this->softList[$a_software['name'] . "\$\$\$\$" . $a_software['manufacturers_id']];
                         $softwareversions_id = $this->softVersionList[strtolower($a_software['version']) . "\$\$\$\$" . $softwares_id];
                         $changes[0] = '0';
                         $changes[1] = "";
                         $changes[2] = $a_software['name'] . " - " . sprintf(__('%1$s (%2$s)'), $a_software['version'], $softwareversions_id);
                         $this->addPrepareLog($computers_id, 'Computer', 'SoftwareVersion', $changes, Log::HISTORY_INSTALL_SOFTWARE);
                         $changes[0] = '0';
                         $changes[1] = "";
                         $changes[2] = sprintf(__('%1$s (%2$s)'), $computerName, $computers_id);
                         $this->addPrepareLog($softwareversions_id, 'SoftwareVersion', 'Computer', $changes, Log::HISTORY_INSTALL_SOFTWARE);
                     }
                 }
             }
         } else {
             foreach ($a_computerinventory['software'] as $key => $arrayslower) {
                 if (isset($db_software[$key])) {
                     unset($a_computerinventory['software'][$key]);
                     unset($db_software[$key]);
                 }
             }
             if (count($a_computerinventory['software']) == 0 && count($db_software) == 0) {
                 // Nothing to do
             } else {
                 if (count($db_software) > 0) {
                     // Delete softwares in DB
                     $a_delete = array();
                     foreach ($db_software as $idtmp) {
                         $this->computer_SoftwareVersion->getFromDB($idtmp);
                         $this->softwareVersion->getFromDB($this->computer_SoftwareVersion->fields['softwareversions_id']);
                         //                        $this->computer_SoftwareVersion->delete(array('id'=>$idtmp, '_no_history'=> TRUE), FALSE);
                         if (!$no_history) {
                             $changes[0] = '0';
                             $changes[1] = addslashes($this->computer_SoftwareVersion->getHistoryNameForItem1($this->softwareVersion, 'delete'));
                             $changes[2] = "";
                             $this->addPrepareLog($computers_id, 'Computer', 'SoftwareVersion', $changes, Log::HISTORY_UNINSTALL_SOFTWARE);
                             $changes[0] = '0';
                             $changes[1] = sprintf(__('%1$s (%2$s)'), $computerName, $computers_id);
                             $changes[2] = "";
                             $this->addPrepareLog($idtmp, 'SoftwareVersion', 'Computer', $changes, Log::HISTORY_UNINSTALL_SOFTWARE);
                         }
                     }
                     $query = "DELETE FROM `glpi_computers_softwareversions` " . "WHERE `id` IN ('" . implode("', '", $db_software) . "')";
                     $DB->query($query);
                 }
                 if (count($a_computerinventory['software']) > 0) {
                     $nb_unicity = count(FieldUnicity::getUnicityFieldsConfig("Software", $entities_id));
                     $options = array();
                     if ($nb_unicity == 0) {
                         $options['disable_unicity_check'] = TRUE;
                     }
                     $lastSoftwareid = $this->loadSoftwares($entities_id, $a_computerinventory['software'], $lastSoftwareid);
                     $queryDBLOCK = "INSERT INTO `glpi_plugin_fusioninventory_dblocksoftwares`\n                           SET `value`='1'";
                     $CFG_GLPI["use_log_in_files"] = FALSE;
                     while (!$DB->query($queryDBLOCK)) {
                         usleep(100000);
                     }
                     $CFG_GLPI["use_log_in_files"] = TRUE;
                     $this->loadSoftwares($entities_id, $a_computerinventory['software'], $lastSoftwareid);
                     foreach ($a_computerinventory['software'] as $a_software) {
                         if (!isset($this->softList[$a_software['name'] . "\$\$\$\$" . $a_software['manufacturers_id']])) {
                             $this->addSoftware($a_software, $options);
                         }
                     }
                     $queryDBLOCK = "DELETE FROM `glpi_plugin_fusioninventory_dblocksoftwares`\n                           WHERE `value`='1'";
                     $DB->query($queryDBLOCK);
                     $lastSoftwareVid = $this->loadSoftwareVersions($entities_id, $a_computerinventory['software'], $lastSoftwareVid);
                     $queryDBLOCK = "INSERT INTO `glpi_plugin_fusioninventory_dblocksoftwareversions`\n                           SET `value`='1'";
                     $CFG_GLPI["use_log_in_files"] = FALSE;
                     while (!$DB->query($queryDBLOCK)) {
                         usleep(100000);
                     }
                     $CFG_GLPI["use_log_in_files"] = TRUE;
                     $this->loadSoftwareVersions($entities_id, $a_computerinventory['software'], $lastSoftwareVid);
                     foreach ($a_computerinventory['software'] as $a_software) {
                         $softwares_id = $this->softList[$a_software['name'] . "\$\$\$\$" . $a_software['manufacturers_id']];
                         if (!isset($this->softVersionList[strtolower($a_software['version']) . "\$\$\$\$" . $softwares_id])) {
                             $this->addSoftwareVersion($a_software, $softwares_id);
                         }
                     }
                     $queryDBLOCK = "DELETE FROM `glpi_plugin_fusioninventory_dblocksoftwareversions`\n                           WHERE `value`='1'";
                     $DB->query($queryDBLOCK);
                     $a_toinsert = array();
                     foreach ($a_computerinventory['software'] as $a_software) {
                         $softwares_id = $this->softList[$a_software['name'] . "\$\$\$\$" . $a_software['manufacturers_id']];
                         $softwareversions_id = $this->softVersionList[strtolower($a_software['version']) . "\$\$\$\$" . $softwares_id];
                         $a_tmp = array('computers_id' => $computers_id, 'softwareversions_id' => $softwareversions_id, 'is_dynamic' => 1, 'entities_id' => $a_software['entities_id']);
                         $a_toinsert[] = "('" . implode("','", $a_tmp) . "')";
                     }
                     $this->addSoftwareVersionsComputer($a_toinsert);
                     if (!$no_history) {
                         foreach ($a_computerinventory['software'] as $a_software) {
                             $softwares_id = $this->softList[$a_software['name'] . "\$\$\$\$" . $a_software['manufacturers_id']];
                             $softwareversions_id = $this->softVersionList[strtolower($a_software['version']) . "\$\$\$\$" . $softwares_id];
                             $changes[0] = '0';
                             $changes[1] = "";
                             $changes[2] = $a_software['name'] . " - " . sprintf(__('%1$s (%2$s)'), $a_software['version'], $softwareversions_id);
                             $this->addPrepareLog($computers_id, 'Computer', 'SoftwareVersion', $changes, Log::HISTORY_INSTALL_SOFTWARE);
                             $changes[0] = '0';
                             $changes[1] = "";
                             $changes[2] = sprintf(__('%1$s (%2$s)'), $computerName, $computers_id);
                             $this->addPrepareLog($softwareversions_id, 'SoftwareVersion', 'Computer', $changes, Log::HISTORY_INSTALL_SOFTWARE);
                         }
                     }
                 }
             }
         }
     }
     // * Virtualmachines
     if ($pfConfig->getValue("import_vm") == 1) {
         $db_computervirtualmachine = array();
         if ($no_history === FALSE) {
             $query = "SELECT `id`, `name`, `uuid`, `virtualmachinesystems_id`\n                     FROM `glpi_computervirtualmachines`\n                  WHERE `computers_id` = '{$computers_id}'\n                     AND `is_dynamic`='1'";
             $result = $DB->query($query);
             while ($data = $DB->fetch_assoc($result)) {
                 $idtmp = $data['id'];
                 unset($data['id']);
                 $data1 = Toolbox::addslashes_deep($data);
                 $db_computervirtualmachine[$idtmp] = $data1;
             }
         }
         $simplecomputervirtualmachine = array();
         if (isset($a_computerinventory['virtualmachine'])) {
             foreach ($a_computerinventory['virtualmachine'] as $key => $a_computervirtualmachine) {
                 $a_field = array('name', 'uuid', 'virtualmachinesystems_id');
                 foreach ($a_field as $field) {
                     if (isset($a_computervirtualmachine[$field])) {
                         $simplecomputervirtualmachine[$key][$field] = $a_computervirtualmachine[$field];
                     }
                 }
             }
         }
         foreach ($simplecomputervirtualmachine as $key => $arrays) {
             foreach ($db_computervirtualmachine as $keydb => $arraydb) {
                 if ($arrays == $arraydb) {
                     $input = array();
                     $input['id'] = $keydb;
                     if (isset($a_computerinventory['virtualmachine'][$key]['vcpu'])) {
                         $input['vcpu'] = $a_computerinventory['virtualmachine'][$key]['vcpu'];
                     }
                     if (isset($a_computerinventory['virtualmachine'][$key]['ram'])) {
                         $input['ram'] = $a_computerinventory['virtualmachine'][$key]['ram'];
                     }
                     if (isset($a_computerinventory['virtualmachine'][$key]['virtualmachinetypes_id'])) {
                         $input['virtualmachinetypes_id'] = $a_computerinventory['virtualmachine'][$key]['virtualmachinetypes_id'];
                     }
                     if (isset($a_computerinventory['virtualmachine'][$key]['virtualmachinestates_id'])) {
                         $input['virtualmachinestates_id'] = $a_computerinventory['virtualmachine'][$key]['virtualmachinestates_id'];
                     }
                     $computerVirtualmachine->update($input, !$no_history);
                     unset($simplecomputervirtualmachine[$key]);
                     unset($a_computerinventory['virtualmachine'][$key]);
                     unset($db_computervirtualmachine[$keydb]);
                     break;
                 }
             }
         }
         if (count($a_computerinventory['virtualmachine']) == 0 && count($db_computervirtualmachine) == 0) {
             // Nothing to do
         } else {
             if (count($db_computervirtualmachine) != 0) {
                 // Delete virtualmachine in DB
                 foreach ($db_computervirtualmachine as $idtmp => $data) {
                     $computerVirtualmachine->delete(array('id' => $idtmp), 1);
                 }
             }
             if (count($a_computerinventory['virtualmachine']) != 0) {
                 foreach ($a_computerinventory['virtualmachine'] as $a_virtualmachine) {
                     $a_virtualmachine['computers_id'] = $computers_id;
                     $computerVirtualmachine->add($a_virtualmachine, array(), !$no_history);
                 }
             }
         }
     }
     if ($pfConfig->getValue("create_vm") == 1) {
         // Create VM based on information of section VIRTUALMACHINE
         $pfAgent = new PluginFusioninventoryAgent();
         // Use ComputerVirtualMachine::getUUIDRestrictRequest to get existant
         // vm in computer list
         $computervm = new Computer();
         if (isset($a_computerinventory['virtualmachine_creation']) && is_array($a_computerinventory['virtualmachine_creation'])) {
             foreach ($a_computerinventory['virtualmachine_creation'] as $a_vm) {
                 // Define location of physical computer (host)
                 $a_vm['locations_id'] = $computer->fields['locations_id'];
                 if (isset($a_vm['uuid']) && $a_vm['uuid'] != '') {
                     $query = "SELECT * FROM `glpi_computers`\n                        WHERE `uuid` " . ComputerVirtualMachine::getUUIDRestrictRequest($a_vm['uuid']) . "\n                        LIMIT 1";
                     // TODO: Add entity search
                     $result = $DB->query($query);
                     $computers_vm_id = 0;
                     while ($data = $DB->fetch_assoc($result)) {
                         $computers_vm_id = $data['id'];
                     }
                     if ($computers_vm_id == 0) {
                         // Add computer
                         $a_vm['entities_id'] = $computer->fields['entities_id'];
                         $computers_vm_id = $computervm->add($a_vm, array(), !$no_history);
                         // Manage networks
                         $this->manageNetworkPort($a_vm['networkport'], $computers_vm_id, FALSE);
                     } else {
                         if ($pfAgent->getAgentWithComputerid($computers_vm_id) === FALSE) {
                             // Update computer
                             $a_vm['id'] = $computers_vm_id;
                             $computervm->update($a_vm, !$no_history);
                             // Manage networks
                             $this->manageNetworkPort($a_vm['networkport'], $computers_vm_id, FALSE);
                         }
                     }
                 }
             }
         }
     }
     // * ComputerDisk
     if ($pfConfig->getValue("import_volume") != 0) {
         $db_computerdisk = array();
         if ($no_history === FALSE) {
             $query = "SELECT `id`, `name`, `device`, `mountpoint`\n                   FROM `glpi_computerdisks`\n                   WHERE `computers_id` = '" . $computers_id . "'\n                     AND `is_dynamic`='1'";
             $result = $DB->query($query);
             while ($data = $DB->fetch_assoc($result)) {
                 $idtmp = $data['id'];
                 unset($data['id']);
                 $data1 = Toolbox::addslashes_deep($data);
                 $data2 = array_map('strtolower', $data1);
                 $db_computerdisk[$idtmp] = $data2;
             }
         }
         $simplecomputerdisk = array();
         foreach ($a_computerinventory['computerdisk'] as $key => $a_computerdisk) {
             $a_field = array('name', 'device', 'mountpoint');
             foreach ($a_field as $field) {
                 if (isset($a_computerdisk[$field])) {
                     $simplecomputerdisk[$key][$field] = $a_computerdisk[$field];
                 }
             }
         }
         foreach ($simplecomputerdisk as $key => $arrays) {
             $arrayslower = array_map('strtolower', $arrays);
             foreach ($db_computerdisk as $keydb => $arraydb) {
                 if ($arrayslower == $arraydb) {
                     $input = array();
                     $input['id'] = $keydb;
                     if (isset($a_computerinventory['computerdisk'][$key]['filesystems_id'])) {
                         $input['filesystems_id'] = $a_computerinventory['computerdisk'][$key]['filesystems_id'];
                     }
                     $input['totalsize'] = $a_computerinventory['computerdisk'][$key]['totalsize'];
                     $input['freesize'] = $a_computerinventory['computerdisk'][$key]['freesize'];
                     $input['_no_history'] = TRUE;
                     $computerDisk->update($input, FALSE);
                     unset($simplecomputerdisk[$key]);
                     unset($a_computerinventory['computerdisk'][$key]);
                     unset($db_computerdisk[$keydb]);
                     break;
                 }
             }
         }
         if (count($a_computerinventory['computerdisk']) == 0 and count($db_computerdisk) == 0) {
             // Nothing to do
         } else {
             if (count($db_computerdisk) != 0) {
                 // Delete computerdisk in DB
                 foreach ($db_computerdisk as $idtmp => $data) {
                     $computerDisk->delete(array('id' => $idtmp), 1);
                 }
             }
             if (count($a_computerinventory['computerdisk']) != 0) {
                 foreach ($a_computerinventory['computerdisk'] as $a_computerdisk) {
                     $a_computerdisk['computers_id'] = $computers_id;
                     $a_computerdisk['is_dynamic'] = 1;
                     $a_computerdisk['_no_history'] = $no_history;
                     $computerDisk->add($a_computerdisk, array(), !$no_history);
                 }
             }
         }
     }
     // * Networkports
     if ($pfConfig->getValue("component_networkcard") != 0) {
         // Get port from unmanaged device if exist
         $this->manageNetworkPort($a_computerinventory['networkport'], $computers_id, $no_history);
     }
     // * Antivirus
     $db_antivirus = array();
     if ($no_history === FALSE) {
         $query = "SELECT `id`, `name`, `version`\n                  FROM `glpi_plugin_fusioninventory_inventorycomputerantiviruses`\n               WHERE `computers_id` = '{$computers_id}'";
         $result = $DB->query($query);
         while ($data = $DB->fetch_assoc($result)) {
             $idtmp = $data['id'];
             unset($data['id']);
             $data1 = Toolbox::addslashes_deep($data);
             $data2 = array_map('strtolower', $data1);
             $db_antivirus[$idtmp] = $data2;
         }
     }
     $simpleantivirus = array();
     foreach ($a_computerinventory['antivirus'] as $key => $a_antivirus) {
         $a_field = array('name', 'version');
         foreach ($a_field as $field) {
             if (isset($a_antivirus[$field])) {
                 $simpleantivirus[$key][$field] = $a_antivirus[$field];
             }
         }
     }
     foreach ($simpleantivirus as $key => $arrays) {
         $arrayslower = array_map('strtolower', $arrays);
         foreach ($db_antivirus as $keydb => $arraydb) {
             if ($arrayslower == $arraydb) {
                 $input = array();
                 $input = $a_computerinventory['antivirus'][$key];
                 $input['id'] = $keydb;
                 $pfInventoryComputerAntivirus->update($input, !$no_history);
                 unset($simpleantivirus[$key]);
                 unset($a_computerinventory['antivirus'][$key]);
                 unset($db_antivirus[$keydb]);
                 break;
             }
         }
     }
     if (count($a_computerinventory['antivirus']) == 0 and count($db_antivirus) == 0) {
         // Nothing to do
     } else {
         if (count($db_antivirus) != 0) {
             foreach ($db_antivirus as $idtmp => $data) {
                 $pfInventoryComputerAntivirus->delete(array('id' => $idtmp), 1);
             }
         }
         if (count($a_computerinventory['antivirus']) != 0) {
             foreach ($a_computerinventory['antivirus'] as $a_antivirus) {
                 $a_antivirus['computers_id'] = $computers_id;
                 $pfInventoryComputerAntivirus->add($a_antivirus, array(), !$no_history);
             }
         }
     }
     // * Licenseinfo
     $db_licenseinfo = array();
     if ($no_history === FALSE) {
         $query = "SELECT `id`, `name`, `fullname`, `serial`\n                  FROM `glpi_plugin_fusioninventory_computerlicenseinfos`\n               WHERE `computers_id` = '{$computers_id}'";
         $result = $DB->query($query);
         while ($data = $DB->fetch_assoc($result)) {
             $idtmp = $data['id'];
             unset($data['id']);
             $data1 = Toolbox::addslashes_deep($data);
             $data2 = array_map('strtolower', $data1);
             $db_licenseinfo[$idtmp] = $data2;
         }
     }
     foreach ($a_computerinventory['licenseinfo'] as $key => $arrays) {
         $arrayslower = array_map('strtolower', $arrays);
         foreach ($db_licenseinfo as $keydb => $arraydb) {
             if ($arrayslower == $arraydb) {
                 unset($a_computerinventory['licenseinfo'][$key]);
                 unset($db_licenseinfo[$keydb]);
                 break;
             }
         }
     }
     if (count($a_computerinventory['licenseinfo']) == 0 and count($db_licenseinfo) == 0) {
         // Nothing to do
     } else {
         if (count($db_licenseinfo) != 0) {
             foreach ($db_licenseinfo as $idtmp => $data) {
                 $pfComputerLicenseInfo->delete(array('id' => $idtmp), 1);
             }
         }
         if (count($a_computerinventory['licenseinfo']) != 0) {
             foreach ($a_computerinventory['licenseinfo'] as $a_licenseinfo) {
                 $a_licenseinfo['computers_id'] = $computers_id;
                 $pfComputerLicenseInfo->add($a_licenseinfo, array(), !$no_history);
             }
         }
     }
     // * Batteries
     /* Standby, see ticket http://forge.fusioninventory.org/issues/1907
              $db_batteries = array();
              if ($no_history === FALSE) {
                 $query = "SELECT `id`, `name`, `serial`
                       FROM `glpi_plugin_fusioninventory_inventorycomputerbatteries`
                    WHERE `computers_id` = '$computers_id'";
                 $result = $DB->query($query);
                 while ($data = $DB->fetch_assoc($result)) {
                    $idtmp = $data['id'];
                    unset($data['id']);
                    $data = Toolbox::addslashes_deep($data);
                    $data = array_map('strtolower', $data);
                    $db_batteries[$idtmp] = $data;
                 }
              }
              $simplebatteries = array();
              foreach ($a_computerinventory['batteries'] as $key=>$a_batteries) {
                 $a_field = array('name', 'serial');
                 foreach ($a_field as $field) {
                    if (isset($a_batteries[$field])) {
                       $simplebatteries[$key][$field] = $a_batteries[$field];
                    }
                 }
              }
              foreach ($simplebatteries as $key => $arrays) {
                 $arrayslower = array_map('strtolower', $arrays);
                 foreach ($db_batteries as $keydb => $arraydb) {
                    if ($arrayslower == $arraydb) {
                       $input = array();
                       $input = $a_computerinventory['batteries'][$key];
                       $input['id'] = $keydb;
                       $pfInventoryComputerBatteries->update($input);
                       unset($simplebatteries[$key]);
                       unset($a_computerinventory['batteries'][$key]);
                       unset($db_batteries[$keydb]);
                       break;
                    }
                 }
              }
              if (count($a_computerinventory['batteries']) == 0
                 AND count($db_batteries) == 0) {
                 // Nothing to do
              } else {
                 if (count($db_batteries) != 0) {
                    foreach ($db_batteries as $idtmp => $data) {
                       $pfInventoryComputerBatteries->delete(array('id'=>$idtmp), 1);
                    }
                 }
                 if (count($a_computerinventory['batteries']) != 0) {
                    foreach($a_computerinventory['batteries'] as $a_batteries) {
                       $a_batteries['computers_id'] = $computers_id;
                       $pfInventoryComputerBatteries->add($a_batteries, array(), FALSE);
                    }
                 }
              }
     */
     $entities_id = $_SESSION["plugin_fusioninventory_entity"];
     // * Monitors
     $rule = new PluginFusioninventoryInventoryRuleImportCollection();
     $a_monitors = array();
     foreach ($a_computerinventory['monitor'] as $key => $arrays) {
         $input = array();
         $input['itemtype'] = "Monitor";
         $input['name'] = $arrays['name'];
         $input['serial'] = $arrays['serial'];
         $data = $rule->processAllRules($input, array(), array('class' => $this, 'return' => TRUE));
         if (isset($data['found_equipment'])) {
             if ($data['found_equipment'][0] == 0) {
                 // add monitor
                 $arrays['entities_id'] = $entities_id;
                 $a_monitors[] = $monitor->add($arrays);
             } else {
                 $a_monitors[] = $data['found_equipment'][0];
             }
         }
     }
     $db_monitors = array();
     $query = "SELECT `glpi_monitors`.`id`,\n                       `glpi_computers_items`.`id` as link_id\n            FROM `glpi_computers_items`\n         LEFT JOIN `glpi_monitors` ON `items_id`=`glpi_monitors`.`id`\n         WHERE `itemtype`='Monitor'\n            AND `computers_id`='" . $computers_id . "'\n            AND `entities_id`='" . $entities_id . "'\n            AND `glpi_computers_items`.`is_dynamic`='1'\n            AND `glpi_monitors`.`is_global`='0'";
     $result = $DB->query($query);
     while ($data = $DB->fetch_assoc($result)) {
         $idtmp = $data['link_id'];
         unset($data['link_id']);
         $db_monitors[$idtmp] = $data['id'];
     }
     if (count($db_monitors) == 0) {
         foreach ($a_monitors as $monitors_id) {
             $input = array();
             $input['computers_id'] = $computers_id;
             $input['itemtype'] = 'Monitor';
             $input['items_id'] = $monitors_id;
             $input['is_dynamic'] = 1;
             $input['_no_history'] = $no_history;
             $computer_Item->add($input, array(), !$no_history);
         }
     } else {
         // Check all fields from source:
         foreach ($a_monitors as $key => $monitors_id) {
             foreach ($db_monitors as $keydb => $monits_id) {
                 if ($monitors_id == $monits_id) {
                     unset($a_monitors[$key]);
                     unset($db_monitors[$keydb]);
                     break;
                 }
             }
         }
         if (count($a_monitors) == 0 and count($db_monitors) == 0) {
             // Nothing to do
         } else {
             if (count($db_monitors) != 0) {
                 // Delete monitors links in DB
                 foreach ($db_monitors as $idtmp => $monits_id) {
                     $computer_Item->delete(array('id' => $idtmp), 1);
                 }
             }
             if (count($a_monitors) != 0) {
                 foreach ($a_monitors as $key => $monitors_id) {
                     $input = array();
                     $input['computers_id'] = $computers_id;
                     $input['itemtype'] = 'Monitor';
                     $input['items_id'] = $monitors_id;
                     $input['is_dynamic'] = 1;
                     $input['_no_history'] = $no_history;
                     $computer_Item->add($input, array(), !$no_history);
                 }
             }
         }
     }
     // * Printers
     $rule = new PluginFusioninventoryInventoryRuleImportCollection();
     $a_printers = array();
     foreach ($a_computerinventory['printer'] as $key => $arrays) {
         $input = array();
         $input['itemtype'] = "Printer";
         $input['name'] = $arrays['name'];
         $input['serial'] = $arrays['serial'];
         $data = $rule->processAllRules($input, array(), array('class' => $this, 'return' => TRUE));
         if (isset($data['found_equipment'])) {
             if ($data['found_equipment'][0] == 0) {
                 // add printer
                 $arrays['entities_id'] = $entities_id;
                 $a_printers[] = $printer->add($arrays);
             } else {
                 $a_printers[] = $data['found_equipment'][0];
             }
         }
     }
     $db_printers = array();
     $query = "SELECT `glpi_printers`.`id`, `glpi_computers_items`.`id` as link_id\n            FROM `glpi_computers_items`\n         LEFT JOIN `glpi_printers` ON `items_id`=`glpi_printers`.`id`\n         WHERE `itemtype`='Printer'\n            AND `computers_id`='" . $computers_id . "'\n            AND `entities_id`='" . $entities_id . "'\n            AND `glpi_computers_items`.`is_dynamic`='1'\n            AND `glpi_printers`.`is_global`='0'";
     $result = $DB->query($query);
     while ($data = $DB->fetch_assoc($result)) {
         $idtmp = $data['link_id'];
         unset($data['link_id']);
         $db_printers[$idtmp] = $data['id'];
     }
     if (count($db_printers) == 0) {
         foreach ($a_printers as $printers_id) {
             $input['entities_id'] = $entities_id;
             $input['computers_id'] = $computers_id;
             $input['itemtype'] = 'Printer';
             $input['items_id'] = $printers_id;
             $input['is_dynamic'] = 1;
             $input['_no_history'] = $no_history;
             $computer_Item->add($input, array(), !$no_history);
         }
     } else {
         // Check all fields from source:
         foreach ($a_printers as $key => $printers_id) {
             foreach ($db_printers as $keydb => $prints_id) {
                 if ($printers_id == $prints_id) {
                     unset($a_printers[$key]);
                     unset($db_printers[$keydb]);
                     break;
                 }
             }
         }
         if (count($a_printers) == 0 and count($db_printers) == 0) {
             // Nothing to do
         } else {
             if (count($db_printers) != 0) {
                 // Delete printers links in DB
                 foreach ($db_printers as $idtmp => $data) {
                     $computer_Item->delete(array('id' => $idtmp), 1);
                 }
             }
             if (count($a_printers) != 0) {
                 foreach ($a_printers as $printers_id) {
                     $input['entities_id'] = $entities_id;
                     $input['computers_id'] = $computers_id;
                     $input['itemtype'] = 'Printer';
                     $input['items_id'] = $printers_id;
                     $input['is_dynamic'] = 1;
                     $input['_no_history'] = $no_history;
                     $computer_Item->add($input, array(), !$no_history);
                 }
             }
         }
     }
     // * Peripheral
     $rule = new PluginFusioninventoryInventoryRuleImportCollection();
     $a_peripherals = array();
     foreach ($a_computerinventory['peripheral'] as $key => $arrays) {
         $input = array();
         $input['itemtype'] = "Peripheral";
         $input['name'] = $arrays['name'];
         $input['serial'] = $arrays['serial'];
         $data = $rule->processAllRules($input, array(), array('class' => $this, 'return' => TRUE));
         if (isset($data['found_equipment'])) {
             if ($data['found_equipment'][0] == 0) {
                 // add peripheral
                 $arrays['entities_id'] = $entities_id;
                 $a_peripherals[] = $peripheral->add($arrays);
             } else {
                 $a_peripherals[] = $data['found_equipment'][0];
             }
         }
     }
     $db_peripherals = array();
     $query = "SELECT `glpi_peripherals`.`id`, `glpi_computers_items`.`id` as link_id\n            FROM `glpi_computers_items`\n         LEFT JOIN `glpi_peripherals` ON `items_id`=`glpi_peripherals`.`id`\n         WHERE `itemtype`='Peripheral'\n            AND `computers_id`='" . $computers_id . "'\n            AND `entities_id`='" . $entities_id . "'\n            AND `glpi_computers_items`.`is_dynamic`='1'\n      AND `glpi_peripherals`.`is_global`='0'";
     $result = $DB->query($query);
     while ($data = $DB->fetch_assoc($result)) {
         $idtmp = $data['link_id'];
         unset($data['link_id']);
         $db_peripherals[$idtmp] = $data['id'];
     }
     if (count($db_peripherals) == 0) {
         foreach ($a_peripherals as $peripherals_id) {
             $input = array();
             $input['computers_id'] = $computers_id;
             $input['itemtype'] = 'Peripharal';
             $input['items_id'] = $peripherals_id;
             $input['is_dynamic'] = 1;
             $input['_no_history'] = $no_history;
             $computer_Item->add($input, array(), !$no_history);
         }
     } else {
         // Check all fields from source:
         foreach ($a_peripherals as $key => $peripherals_id) {
             foreach ($db_peripherals as $keydb => $periphs_id) {
                 if ($peripherals_id == $periphs_id) {
                     unset($a_peripherals[$key]);
                     unset($db_peripherals[$keydb]);
                     break;
                 }
             }
         }
         if (count($a_peripherals) == 0 and count($db_peripherals) == 0) {
             // Nothing to do
         } else {
             if (count($db_peripherals) != 0) {
                 // Delete peripherals links in DB
                 foreach ($db_peripherals as $idtmp => $data) {
                     $computer_Item->delete(array('id' => $idtmp), 1);
                 }
             }
             if (count($a_peripherals) != 0) {
                 foreach ($a_peripherals as $peripherals_id) {
                     $input = array();
                     $input['computers_id'] = $computers_id;
                     $input['itemtype'] = 'Peripharal';
                     $input['items_id'] = $peripherals_id;
                     $input['is_dynamic'] = 1;
                     $input['_no_history'] = $no_history;
                     $computer_Item->add($input, array(), !$no_history);
                 }
             }
         }
     }
     // * storage
     // Manage by uuid to correspond with GLPI data
     //         $db_storage = array();
     //         if ($no_history === FALSE) {
     //            $query = "SELECT `id`, `uuid` FROM ".
     //                "`glpi_plugin_fusioninventory_inventorycomputerstorages`
     //                WHERE `computers_id` = '$computers_id'";
     //            $result = $DB->query($query);
     //            while ($data = $DB->fetch_assoc($result)) {
     //               $idtmp = $data['id'];
     //               unset($data['id']);
     //               $data = Toolbox::addslashes_deep($data);
     //               $data = array_map('strtolower', $data);
     //               $db_storage[$idtmp] = $data;
     //            }
     //         }
     //         if (count($db_storage) == 0) {
     //            $a_links = array();
     //            $a_uuid  = array();
     //            foreach ($a_computerinventory['storage'] as $a_storage) {
     //               $a_storage['computers_id'] = $computers_id;
     //               $insert_id = $pfInventoryComputerStorage->add($a_storage);
     //               if (isset($a_storage['uuid'])) {
     //                  $a_uuid[$a_storage['uuid']] = $insert_id;
     //                  if (isset($a_storage['uuid_link'])) {
     //                     if (is_array($a_storage['uuid_link'])) {
     //                        $a_links[$insert_id] = $a_storage['uuid_link'];
     //                     } else {
     //                        $a_links[$insert_id][] = $a_storage['uuid_link'];
     //                     }
     //                  }
     //               }
     //            }
     //            foreach ($a_links as $id=>$data) {
     //               foreach ($data as $num=>$uuid) {
     //                  $a_links[$id][$num] = $a_uuid[$uuid];
     //               }
     //            }
     //            foreach ($a_links as $id=>$data) {
     //               foreach ($data as $id2) {
     //                  $input = array();
     //                  $input['plugin_fusioninventory_inventorycomputerstorages_id_1'] = $id;
     //                  $input['plugin_fusioninventory_inventorycomputerstorages_id_2'] = $id2;
     //                  $pfInventoryComputerStorage_Storage->add($input);
     //               }
     //            }
     //         } else {
     //            // Check only field *** from source:
     //
     //         }
     $this->addLog();
 }
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;
}
$ocsinventory = '0';
file_put_contents(GLPI_PLUGIN_DOC_DIR . "/fusioninventory/dial.log" . rand(), gzuncompress($GLOBALS["HTTP_RAW_POST_DATA"]));
$state = $ptc->importToken(gzuncompress($GLOBALS["HTTP_RAW_POST_DATA"]));
if ($state == '2') {
    // agent created
    $ocsinventory = '1';
}
$top0 = gettimeofday();
Пример #12
0
function plugin_fusioninventory_getAddSearchOptions($itemtype)
{
    $sopt = array();
    if ($itemtype == 'Computer' or $itemtype == 'PluginFusioninventoryComputer') {
        $sopt[5150]['table'] = 'glpi_plugin_fusioninventory_inventorycomputercomputers';
        $sopt[5150]['field'] = 'last_fusioninventory_update';
        $sopt[5150]['linkfield'] = 'id';
        $sopt[5150]['name'] = __('FusInv', 'fusioninventory') . " - " . __('Last inventory', 'fusioninventory');
        $sopt[5150]['datatype'] = 'datetime';
        $sopt[5150]['itemlink_type'] = 'PluginFusioninventoryInventoryComputerLib';
        $sopt[5150]['massiveaction'] = FALSE;
        $sopt[5151]['table'] = 'glpi_plugin_fusioninventory_inventorycomputerantiviruses';
        $sopt[5151]['field'] = 'name';
        $sopt[5151]['name'] = __('Antivirus name', 'fusioninventory');
        $sopt[5151]['datatype'] = 'string';
        $sopt[5151]['joinparams'] = array('jointype' => 'child');
        $sopt[5151]['massiveaction'] = FALSE;
        $sopt[5151]['forcegroupby'] = TRUE;
        $sopt[5151]['searchtype'] = array('contains');
        $sopt[5152]['table'] = 'glpi_plugin_fusioninventory_inventorycomputerantiviruses';
        $sopt[5152]['field'] = 'version';
        $sopt[5152]['name'] = __('Antivirus version', 'fusioninventory');
        $sopt[5152]['datatype'] = 'string';
        $sopt[5152]['joinparams'] = array('jointype' => 'child');
        $sopt[5152]['massiveaction'] = FALSE;
        $sopt[5152]['forcegroupby'] = TRUE;
        $sopt[5151]['searchtype'] = array('contains');
        $sopt[5153]['table'] = 'glpi_plugin_fusioninventory_inventorycomputerantiviruses';
        $sopt[5153]['field'] = 'is_active';
        $sopt[5153]['linkfield'] = '';
        $sopt[5153]['name'] = __('Antivirus enabled', 'fusioninventory');
        $sopt[5153]['datatype'] = 'bool';
        $sopt[5153]['joinparams'] = array('jointype' => 'child');
        $sopt[5153]['massiveaction'] = FALSE;
        $sopt[5153]['forcegroupby'] = TRUE;
        $sopt[5153]['searchtype'] = array('equals');
        $sopt[5154]['table'] = 'glpi_plugin_fusioninventory_inventorycomputerantiviruses';
        $sopt[5154]['field'] = 'uptodate';
        $sopt[5154]['linkfield'] = '';
        $sopt[5154]['name'] = __('Antivirus up to date', 'fusioninventory');
        $sopt[5154]['datatype'] = 'bool';
        $sopt[5154]['joinparams'] = array('jointype' => 'child');
        $sopt[5154]['massiveaction'] = FALSE;
        $sopt[5154]['forcegroupby'] = TRUE;
        $sopt[5154]['searchtype'] = array('equals');
        $sopt[5155]['table'] = 'glpi_plugin_fusioninventory_inventorycomputercomputers';
        $sopt[5155]['field'] = 'bios_date';
        $sopt[5155]['name'] = __('BIOS', 'fusioninventory') . "-" . __('Date');
        //         $sopt[5155]['forcegroupby'] = true;
        //         $sopt[5155]['usehaving'] = true;
        $sopt[5155]['datatype'] = 'date';
        $sopt[5155]['joinparams'] = array('jointype' => 'child');
        $sopt[5155]['massiveaction'] = FALSE;
        $sopt[5156]['table'] = 'glpi_plugin_fusioninventory_inventorycomputercomputers';
        $sopt[5156]['field'] = 'bios_version';
        $sopt[5156]['name'] = __('BIOS', 'fusioninventory') . "-" . __('Version');
        $sopt[5156]['joinparams'] = array('jointype' => 'child');
        $sopt[5156]['massiveaction'] = FALSE;
        $sopt[5157]['table'] = 'glpi_plugin_fusioninventory_inventorycomputercomputers';
        $sopt[5157]['field'] = 'operatingsystem_installationdate';
        $sopt[5157]['name'] = __('Operating system') . " - " . __('Installation') . " (" . strtolower(__('Date')) . ")";
        $sopt[5157]['joinparams'] = array('jointype' => 'child');
        $sopt[5157]['datatype'] = 'date';
        $sopt[5157]['massiveaction'] = FALSE;
        $sopt[5158]['table'] = 'glpi_plugin_fusioninventory_inventorycomputercomputers';
        $sopt[5158]['field'] = 'winowner';
        $sopt[5158]['joinparams'] = array('jointype' => 'child');
        $sopt[5158]['name'] = __('Owner', 'fusioninventory');
        $sopt[5158]['massiveaction'] = FALSE;
        $sopt[5159]['table'] = 'glpi_plugin_fusioninventory_inventorycomputercomputers';
        $sopt[5159]['field'] = 'wincompany';
        $sopt[5159]['name'] = __('Company', 'fusioninventory');
        $sopt[5159]['joinparams'] = array('jointype' => 'child');
        $sopt[5159]['massiveaction'] = FALSE;
        $sopt[5160]['table'] = 'glpi_plugin_fusioninventory_agents';
        $sopt[5160]['field'] = 'useragent';
        $sopt[5160]['name'] = __('Useragent', 'fusioninventory');
        $sopt[5160]['joinparams'] = array('jointype' => 'child');
        $sopt[5160]['massiveaction'] = FALSE;
        $sopt[5161]['table'] = 'glpi_plugin_fusioninventory_agents';
        $sopt[5161]['field'] = 'tag';
        $sopt[5161]['linkfield'] = '';
        $sopt[5161]['name'] = __('FusionInventory tag', 'fusioninventory');
        $sopt[5162]['table'] = 'glpi_plugin_fusioninventory_computerarchs';
        $sopt[5162]['field'] = 'name';
        $sopt[5162]['name'] = __('Architecture', 'fusioninventory');
        $sopt[5162]['datatype'] = 'dropdown';
        $sopt[5162]['massiveaction'] = FALSE;
        $sopt[5162]['joinparams'] = array('beforejoin' => array('table' => 'glpi_plugin_fusioninventory_inventorycomputercomputers', 'joinparams' => array('jointype' => 'child')));
        //         $sopt[5163]['table']     = 'glpi_plugin_fusioninventory_configurationmanagements';
        //         $sopt[5163]['field']     = 'conform';
        //         $sopt[5163]['name']      = __('Conformité (configuration management)', 'fusioninventory');
        //         $sopt[5163]['joinparams']  = array('jointype' => 'itemtype_item');
        //         $sopt[5163]['massiveaction'] = FALSE;
        //         $sopt[5163]['datatype']  = 'bool';
        $sopt[5163]['table'] = 'glpi_plugin_fusioninventory_inventorycomputercomputers';
        $sopt[5163]['field'] = 'oscomment';
        $sopt[5163]['name'] = __('Operating system') . '/' . __('Comments');
        $sopt[5163]['joinparams'] = array('jointype' => 'child');
        $sopt[5163]['massiveaction'] = FALSE;
        $sopt[5164]['table'] = "glpi_plugin_fusioninventory_agentmodules";
        $sopt[5164]['field'] = "DEPLOY";
        $sopt[5164]['linkfield'] = "DEPLOY";
        $sopt[5164]['name'] = __('Module', 'fusioninventory') . "-" . __('Deploy', 'fusioninventory');
        $sopt[5164]['datatype'] = 'bool';
        $sopt[5164]['massiveaction'] = FALSE;
        $sopt[5165]['table'] = "glpi_plugin_fusioninventory_agentmodules";
        $sopt[5165]['field'] = "WAKEONLAN";
        $sopt[5165]['linkfield'] = "WAKEONLAN";
        $sopt[5165]['name'] = __('Module', 'fusioninventory') . "-" . __('WakeOnLan', 'fusioninventory');
        $sopt[5165]['datatype'] = 'bool';
        $sopt[5165]['massiveaction'] = FALSE;
        $sopt[5166]['table'] = "glpi_plugin_fusioninventory_agentmodules";
        $sopt[5166]['field'] = "INVENTORY";
        $sopt[5166]['linkfield'] = "INVENTORY";
        $sopt[5166]['name'] = __('Module', 'fusioninventory') . "-" . __('Local inventory', 'fusioninventory');
        $sopt[5166]['datatype'] = 'bool';
        $sopt[5166]['massiveaction'] = FALSE;
        $sopt[5167]['table'] = "glpi_plugin_fusioninventory_agentmodules";
        $sopt[5167]['field'] = "InventoryComputerESX";
        $sopt[5167]['linkfield'] = "InventoryComputerESX";
        $sopt[5167]['name'] = __('Module', 'fusioninventory') . "-" . __('ESX/VMWare', 'fusioninventory');
        $sopt[5167]['datatype'] = 'bool';
        $sopt[5167]['massiveaction'] = FALSE;
        $sopt[5168]['table'] = "glpi_plugin_fusioninventory_agentmodules";
        $sopt[5168]['field'] = "NETWORKINVENTORY";
        $sopt[5168]['linkfield'] = "NETWORKINVENTORY";
        $sopt[5168]['name'] = __('Module', 'fusioninventory') . "-" . __('Network inventory', 'fusioninventory');
        $sopt[5168]['datatype'] = 'bool';
        $sopt[5168]['massiveaction'] = FALSE;
        $sopt[5169]['table'] = "glpi_plugin_fusioninventory_agentmodules";
        $sopt[5169]['field'] = "NETWORKDISCOVERY";
        $sopt[5169]['linkfield'] = "NETWORKDISCOVERY";
        $sopt[5169]['name'] = __('Module', 'fusioninventory') . "-" . __('Network discovery', 'fusioninventory');
        $sopt[5169]['datatype'] = 'bool';
        $sopt[5169]['massiveaction'] = FALSE;
        $sopt[5170]['table'] = "glpi_plugin_fusioninventory_agentmodules";
        $sopt[5170]['field'] = "Collect";
        $sopt[5170]['linkfield'] = "Collect";
        $sopt[5170]['name'] = __('Module', 'fusioninventory') . "-" . __('Collect', 'fusioninventory');
        $sopt[5170]['datatype'] = 'bool';
        $sopt[5170]['massiveaction'] = FALSE;
        $sopt[5171]['name'] = __('Static group', 'fusioninventory');
        $sopt[5171]['table'] = getTableForItemType('PluginFusioninventoryDeployGroup');
        $sopt[5171]['massiveaction'] = FALSE;
        $sopt[5171]['field'] = 'name';
        $sopt[5171]['forcegroupby'] = true;
        $sopt[5171]['usehaving'] = true;
        $sopt[5171]['datatype'] = 'dropdown';
        $sopt[5171]['joinparams'] = array('beforejoin' => array('table' => 'glpi_plugin_fusioninventory_deploygroups_staticdatas', 'joinparams' => array('jointype' => 'itemtype_item', 'specific_itemtype' => 'Computer')));
    }
    if ($itemtype == 'Computer') {
        // Switch
        $sopt[5192]['table'] = 'glpi_plugin_fusioninventory_networkequipments';
        $sopt[5192]['field'] = 'name';
        $sopt[5192]['linkfield'] = '';
        $sopt[5192]['name'] = __('FusInv', 'fusioninventory') . " - " . __('Switch');
        $sopt[5192]['itemlink_type'] = 'NetworkEquipment';
        // Port of switch
        $sopt[5193]['table'] = 'glpi_plugin_fusioninventory_networkports';
        $sopt[5193]['field'] = 'id';
        $sopt[5193]['linkfield'] = '';
        $sopt[5193]['name'] = __('FusInv', 'fusioninventory') . " - " . __('Switch ports');
        $sopt[5193]['forcegroupby'] = '1';
    }
    if ($itemtype == 'Entity') {
        // Agent base URL
        $sopt[6192]['table'] = 'glpi_plugin_fusioninventory_entities';
        $sopt[6192]['field'] = 'agent_base_url';
        $sopt[6192]['linkfield'] = '';
        $sopt[6192]['name'] = __('Agent base URL', 'fusioninventory');
        $sopt[6192]['joinparams'] = array('jointype' => 'child');
        $sopt[6192]['massiveaction'] = FALSE;
    }
    if ($itemtype == 'Printer') {
        // Switch
        $sopt[5192]['table'] = 'glpi_plugin_fusioninventory_networkequipments';
        $sopt[5192]['field'] = 'name';
        $sopt[5192]['linkfield'] = '';
        $sopt[5192]['name'] = __('FusInv', 'fusioninventory') . " - " . __('Switch');
        $sopt[5192]['itemlink_type'] = 'NetworkEquipment';
        // Port of switch
        $sopt[5193]['table'] = 'glpi_plugin_fusioninventory_networkports';
        $sopt[5193]['field'] = 'id';
        $sopt[5193]['linkfield'] = '';
        $sopt[5193]['name'] = __('FusInv', 'fusioninventory') . " - " . __('Hardware ports');
        $sopt[5193]['forcegroupby'] = '1';
        $pfConfig = new PluginFusioninventoryConfig();
        $plugins_id = PluginFusioninventoryModule::getModuleId('fusioninventory');
        if ($pfConfig->getValue("storagesnmpauth") == "file") {
            $sopt[5191]['table'] = 'glpi_plugin_fusioninventory_printers';
            $sopt[5191]['field'] = 'plugin_fusioninventory_configsecurities_id';
            $sopt[5191]['linkfield'] = 'id';
            $sopt[5191]['name'] = __('FusInv', 'fusioninventory') . " - " . __('SNMP authentication', 'fusioninventory');
            $sopt[5191]['massiveaction'] = FALSE;
        } else {
            $sopt[5191]['table'] = 'glpi_plugin_fusioninventory_configsecurities';
            $sopt[5191]['field'] = 'name';
            $sopt[5191]['linkfield'] = 'plugin_fusioninventory_configsecurities_id';
            $sopt[5191]['name'] = __('FusInv', 'fusioninventory') . " - " . __('SNMP authentication', 'fusioninventory');
            $sopt[5191]['datatype'] = 'itemlink';
            $sopt[5191]['itemlink_type'] = 'PluginFusioninventoryConfigSecurity';
            $sopt[5191]['massiveaction'] = FALSE;
        }
        $sopt[5194]['table'] = 'glpi_plugin_fusioninventory_printers';
        $sopt[5194]['field'] = 'last_fusioninventory_update';
        $sopt[5194]['linkfield'] = '';
        $sopt[5194]['name'] = __('FusInv', 'fusioninventory') . " - " . __('Last inventory', 'fusioninventory');
        $sopt[5194]['datatype'] = 'datetime';
        $sopt[5194]['massiveaction'] = FALSE;
        $sopt[5196]['table'] = 'glpi_plugin_fusioninventory_printers';
        $sopt[5196]['field'] = 'sysdescr';
        $sopt[5196]['linkfield'] = '';
        $sopt[5196]['name'] = __('Sysdescr', 'fusioninventory');
        $sopt[5196]['datatype'] = 'text';
    }
    if ($itemtype == 'NetworkEquipment') {
        $pfConfig = new PluginFusioninventoryConfig();
        $plugins_id = PluginFusioninventoryModule::getModuleId('fusioninventory');
        $sopt[5191]['table'] = 'glpi_plugin_fusioninventory_configsecurities';
        $sopt[5191]['field'] = 'name';
        $sopt[5191]['linkfield'] = 'plugin_fusioninventory_configsecurities_id';
        $sopt[5191]['name'] = __('FusInv', 'fusioninventory') . " - " . __('SNMP authentication', 'fusioninventory');
        $sopt[5191]['datatype'] = 'itemlink';
        $sopt[5191]['itemlink_type'] = 'PluginFusioninventoryConfigSecurity';
        $sopt[5191]['massiveaction'] = FALSE;
        $sopt[5194]['table'] = 'glpi_plugin_fusioninventory_networkequipments';
        $sopt[5194]['field'] = 'last_fusioninventory_update';
        $sopt[5194]['linkfield'] = '';
        $sopt[5194]['name'] = __('FusInv', 'fusioninventory') . " - " . __('Last inventory', 'fusioninventory');
        $sopt[5194]['datatype'] = 'datetime';
        $sopt[5194]['massiveaction'] = FALSE;
        $sopt[5195]['table'] = 'glpi_plugin_fusioninventory_networkequipments';
        $sopt[5195]['field'] = 'cpu';
        $sopt[5195]['linkfield'] = '';
        $sopt[5195]['name'] = __('FusInv', 'fusioninventory') . " - " . __('CPU usage (in %)', 'fusioninventory');
        $sopt[5195]['datatype'] = 'number';
        $sopt[5196]['table'] = 'glpi_plugin_fusioninventory_networkequipments';
        $sopt[5196]['field'] = 'sysdescr';
        $sopt[5196]['linkfield'] = '';
        $sopt[5196]['name'] = __('Sysdescr', 'fusioninventory');
        $sopt[5196]['datatype'] = 'text';
    }
    return $sopt;
}
 /**
  * Clean agent too old (so haven't contacted glpi
  * since xx days)
  *
  * @return bool cron is ok or not
  *
  **/
 static function cronCleanoldagents()
 {
     global $DB;
     $pfConfig = new PluginFusioninventoryConfig();
     $pfAgent = new PluginFusioninventoryAgent();
     $retentiontime = $pfConfig->getValue('agents_old_days');
     if ($retentiontime == 0) {
         return TRUE;
     }
     $sql = "SELECT * FROM `glpi_plugin_fusioninventory_agents`\n                WHERE `last_contact` < date_add(now(), interval -" . $retentiontime . " day)";
     $result = $DB->query($sql);
     if ($result) {
         while ($data = $DB->fetch_array($result)) {
             $pfAgent->delete($data);
         }
     }
     return TRUE;
 }
 /**
  * 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);
         }
     }
 }
 /**
  *  Execute a function as Fusioninventory user
  *  @param $function callable
  *  @param $args array
  *
  *  @return the normally returned value from executed callable
  */
 function executeAsFusioninventoryUser($function, array $args = array())
 {
     $config = new PluginFusioninventoryConfig();
     $user = new User();
     // Backup _SESSION environment
     $OLD_SESSION = array();
     foreach (array('glpiID', 'glpiname', 'glpiactiveentities_string', 'glpiactiveentities', 'glpiparententities') as $session_key) {
         if (isset($_SESSION[$session_key])) {
             $OLD_SESSION[$session_key] = $_SESSION[$session_key];
         }
     }
     // Configure impersonation
     $users_id = $config->getValue('users_id');
     $user->getFromDB($users_id);
     $_SESSION['glpiID'] = $users_id;
     $_SESSION['glpiname'] = $user->getField('name');
     $_SESSION['glpiactiveentities'] = getSonsOf('glpi_entities', 0);
     $_SESSION['glpiactiveentities_string'] = "'" . implode("', '", $_SESSION['glpiactiveentities']) . "'";
     $_SESSION['glpiparententities'] = array();
     // Execute function with impersonated SESSION
     $result = call_user_func_array($function, $args);
     // Restore SESSION
     foreach ($OLD_SESSION as $key => $value) {
         $_SESSION[$key] = $value;
     }
     // Return function results
     return $result;
 }
 /**
  * Cron for clean taskjob
  *
  * @return nothing
  */
 static function cronCleantaskjob()
 {
     global $DB;
     $config = new PluginFusioninventoryConfig();
     $retentiontime = $config->getValue('delete_task');
     $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
     $sql = "SELECT * FROM `glpi_plugin_fusioninventory_taskjoblogs`\n         WHERE  `date` < date_add(now(), interval -" . $retentiontime . " day)\n         GROUP BY `plugin_fusioninventory_taskjobstates_id`";
     $result = $DB->query($sql);
     if ($result) {
         while ($data = $DB->fetch_array($result)) {
             $pfTaskjobstate->getFromDB($data['plugin_fusioninventory_taskjobstates_id']);
             $pfTaskjobstate->delete($pfTaskjobstate->fields, 1);
             $sql_delete = "DELETE FROM `glpi_plugin_fusioninventory_taskjoblogs`\n               WHERE `plugin_fusioninventory_taskjobstates_id` = '" . $data['plugin_fusioninventory_taskjobstates_id'] . "'";
             $DB->query($sql_delete);
         }
     }
 }
 /**
  * Get default value for state of devices (monitor, printer...)
  *
  * @param type $input
  * @param type $check_management
  * @param type $management_value
  *
  */
 static function addDefaultStateIfNeeded(&$input, $check_management = FALSE, $management_value = 0)
 {
     $config = new PluginFusioninventoryConfig();
     $state = $config->getValue("states_id_default");
     if ($state) {
         if (!$check_management || $check_management && !$management_value) {
             $input['states_id'] = $state;
         }
     }
     return $input;
 }
Пример #18
0
 static function auth_dropdown($selected = "")
 {
     global $DB;
     $plugin_fusioninventory_snmp_auth = new PluginFusioninventorySnmpauth();
     $config = new PluginFusioninventoryConfig();
     if ($config->getValue("authsnmp") == "file") {
         echo $plugin_fusioninventory_snmp_auth->selectbox($selected);
     } else {
         if ($config->getValue("authsnmp") == "DB") {
             Dropdown::show("PluginFusioninventorySnmpauth", array('name' => "FK_snmp_connection", 'value' => $selected, 'comments' => false));
         }
     }
 }
 *    2.0.1 Nothing
 *    2.0.2 config version field 2.0.2
 *    2.1.0 config version field 2.1.0
 **/
if (Session::haveRight('config', UPDATE) && Session::haveRight('profile', UPDATE)) {
    $config = new PluginFusioninventoryConfig();
    if (!TableExists("glpi_plugin_fusioninventory_agents")) {
        PluginFusioninventorySetup::update("1.1.0");
    }
    if (!TableExists("glpi_plugin_fusioninventory_config_discovery")) {
        PluginFusioninventorySetup::update("2.0.0");
    }
    if (!FieldExists("glpi_plugin_fusioninventory_configs", "version")) {
        PluginFusioninventorySetup::update("2.0.2");
    }
    if (FieldExists("glpi_plugin_fusioninventory_configs", "version")) {
        if ($config->getValue('version') == "2.0.2" || $config->getValue('version') == "2.1.0") {
            $DB->query("UPDATE `glpi_plugin_fusioninventory_configs`\n                     SET `version` = '2.1.1'\n                     WHERE `id`=1");
        }
        PluginFusioninventorySetup::update("2.0.2");
        if ($config->getValue('version') == "0") {
            $DB->query("UPDATE `glpi_plugin_fusioninventory_configs`\n                     SET `version` = '2.1.1'\n                     WHERE `id`=1");
        }
    }
    Html::back();
} else {
    Html::header(__('Access denied'), $_SERVER['PHP_SELF'], "plugins", "fusioninventory");
    echo "<div align='center'><br><br><img src=\"" . $CFG_GLPI['root_doc'] . "/pics/warning.png\"\n              alt=\"warning\"><br><br>";
    echo "<b>" . __('Access denied') . "</b></div>";
    Html::footer();
}
 /**
  * Get SNMP version and authentification 
  *
  * @param $ID_Device ID of the device ("all" if we want to get all snmp auth)
  * @param $xml_auth_rep folder where as stocked authxml file (if the management is by FILE)
  * @param $type type of device (NETWORKING_TYPE, PRINTER_TYPE ...)
  *
  * @return $snmp_auth : array with auth informations && version
  *
  **/
 function GetInfos($ID_Device, $xml_auth_rep, $type)
 {
     global $DB, $CFG_GLPI, $LANG;
     $config = new PluginFusioninventoryConfig();
     if ($ID_Device != "all") {
         switch ($type) {
             case NETWORKING_TYPE:
                 $query = "SELECT *\n                         FROM `glpi_plugin_fusioninventory_networking`\n                         WHERE `FK_networking`='" . $ID_Device . "';";
                 break;
             case PRINTER_TYPE:
                 $query = "SELECT *\n                         FROM `glpi_plugin_fusioninventory_printers`\n                         WHERE `FK_printers`='" . $ID_Device . "';";
                 break;
         }
         $result = $DB->query($query);
         if ($DB->numrows($result) > 0) {
             $ID_auth = $DB->result($result, 0, "FK_snmp_connection");
         } else {
             return;
         }
     } else {
         // Put Default community of devices
         $snmp_auth[0]["Name"] = "Public-v2c";
         $snmp_auth[0]["snmp_version"] = "2c";
         $snmp_auth[0]["community"] = "public";
         $snmp_auth[0]["sec_name"] = "";
         $snmp_auth[0]["auth_protocol"] = "";
         $snmp_auth[0]["auth_passphrase"] = "";
         $snmp_auth[0]["priv_protocol"] = "";
         $snmp_auth[0]["priv_passphrase"] = "";
         $snmp_auth[0]["ID"] = 0;
         $snmp_auth[1]["Name"] = "Public-v1";
         $snmp_auth[1]["snmp_version"] = "1";
         $snmp_auth[1]["community"] = "public";
         $snmp_auth[1]["sec_name"] = "";
         $snmp_auth[1]["auth_protocol"] = "";
         $snmp_auth[1]["auth_passphrase"] = "";
         $snmp_auth[1]["priv_protocol"] = "";
         $snmp_auth[1]["priv_passphrase"] = "";
         $snmp_auth[1]["ID"] = 0;
     }
     if ($config->getValue("authsnmp") == "file") {
         $xml = simplexml_load_file($xml_auth_rep . "auth.xml");
         $i = -1;
         foreach ($xml->auth[0] as $num) {
             $i++;
             $j = 0;
             $recup = 0;
             foreach ($xml->auth->conf[$i] as $item) {
                 $j++;
                 switch ($j) {
                     case 1:
                         if ($ID_Device == "all") {
                             $recup = 1;
                             $snmp_auth[$i + 2]["ID"] = $item;
                         } else {
                             if ($item == $ID_auth) {
                                 $recup = 1;
                             }
                         }
                         break;
                     case 2:
                         if ($recup == "1" and $ID_Device != "all") {
                             $snmp_auth["Name"] = $item;
                         }
                         if ($ID_Device == "all") {
                             $snmp_auth[$i + 2]["Name"] = $item;
                         }
                         break;
                     case 3:
                         if ($recup == "1" and $ID_Device != "all") {
                             $snmp_auth["snmp_version"] = Dropdown::getDropdownName("glpi_plugin_fusioninventory_snmpversions", $item);
                         }
                         if ($ID_Device == "all") {
                             $snmp_auth[$i + 2]["snmp_version"] = Dropdown::getDropdownName("glpi_plugin_fusioninventory_snmpversions", $item);
                         }
                         break;
                     case 4:
                         if ($recup == "1" and $ID_Device != "all") {
                             $snmp_auth["community"] = $item;
                         }
                         if ($ID_Device == "all") {
                             $snmp_auth[$i + 2]["community"] = $item;
                         }
                         break;
                     case 5:
                         if ($recup == "1" and $ID_Device != "all") {
                             $snmp_auth["sec_name"] = $item;
                         }
                         if ($ID_Device == "all") {
                             $snmp_auth[$i + 2]["sec_name"] = $item;
                         }
                         break;
                     case 7:
                         if ($recup == "1" and $ID_Device != "all") {
                             $snmp_auth["auth_protocol"] = Dropdown::getDropdownName("glpi_plugin_fusioninventory_snmpprotocolauths", $item);
                         }
                         if ($ID_Device == "all") {
                             $snmp_auth[$i + 2]["auth_protocol"] = Dropdown::getDropdownName("glpi_plugin_fusioninventory_snmpprotocolauths", $item);
                         }
                         break;
                     case 8:
                         if ($recup == "1" and $ID_Device != "all") {
                             $snmp_auth["auth_passphrase"] = $item;
                         }
                         if ($ID_Device == "all") {
                             $snmp_auth[$i + 2]["auth_passphrase"] = $item;
                         }
                         break;
                     case 9:
                         if ($recup == "1" and $ID_Device != "all") {
                             $snmp_auth["priv_protocol"] = Dropdown::getDropdownName("glpi_plugin_fusioninventory_snmpprotocolprivs", $item);
                         }
                         if ($ID_Device == "all") {
                             $snmp_auth[$i + 2]["priv_protocol"] = Dropdown::getDropdownName("glpi_plugin_fusioninventory_snmpprotocolprivs", $item);
                         }
                         break;
                     case 10:
                         if ($recup == "1" and $ID_Device != "all") {
                             $snmp_auth["priv_passphrase"] = $item;
                         }
                         if ($ID_Device == "all") {
                             $snmp_auth[$i + 2]["priv_passphrase"] = $item;
                         }
                         break;
                 }
             }
         }
     } else {
         if ($config->getValue("authsnmp") == "DB") {
             if ($ID_Device == "all") {
                 $query = "SELECT *\n                      FROM `glpi_plugin_fusioninventory_snmpauths`";
             } else {
                 $query = "SELECT *\n                      FROM `glpi_plugin_fusioninventory_snmpauths`\n                      WHERE `ID`='" . $ID_auth . "';";
             }
             $result = $DB->query($query);
             if ($DB->numrows($result) == "0" and $ID_Device != "all") {
                 $snmp_auth["Name"] = "";
                 $snmp_auth["snmp_version"] = "";
                 $snmp_auth["community"] = "";
                 $snmp_auth["sec_name"] = "";
                 $snmp_auth["auth_protocol"] = "";
                 $snmp_auth["auth_passphrase"] = "";
                 $snmp_auth["priv_protocol"] = "";
                 $snmp_auth["priv_passphrase"] = "";
             } else {
                 if ($ID_Device != "all") {
                     $snmp_auth["Name"] = $DB->result($result, 0, "name");
                     $snmp_auth["snmp_version"] = Dropdown::getDropdownName("glpi_plugin_fusioninventory_snmpversions", $DB->result($result, 0, "FK_snmp_version"));
                     $snmp_auth["community"] = $DB->result($result, 0, "community");
                     $snmp_auth["sec_name"] = $DB->result($result, 0, "sec_name");
                     $snmp_auth["auth_protocol"] = Dropdown::getDropdownName("glpi_plugin_fusioninventory_snmpprotocolauths", $DB->result($result, 0, "auth_protocol"));
                     $snmp_auth["auth_passphrase"] = $DB->result($result, 0, "auth_passphrase");
                     $snmp_auth["priv_protocol"] = Dropdown::getDropdownName("glpi_plugin_fusioninventory_snmpprotocolprivs", $DB->result($result, 0, "priv_protocol"));
                     $snmp_auth["priv_passphrase"] = $DB->result($result, 0, "priv_passphrase");
                 } else {
                     if ($ID_Device == "all") {
                         $i = 2;
                         while ($data = $DB->fetch_array($result)) {
                             if ($snmp_auth[0]["snmp_version"] == Dropdown::getDropdownName("glpi_plugin_fusioninventory_snmpversions", $data["FK_snmp_version"]) and $snmp_auth[0]["community"] == $data["community"]) {
                                 $snmp_auth[0]["ID"] = $data["ID"];
                             } else {
                                 if ($snmp_auth[1]["snmp_version"] == Dropdown::getDropdownName("glpi_plugin_fusioninventory_snmpversions", $data["FK_snmp_version"]) and $snmp_auth[1]["community"] == $data["community"]) {
                                     $snmp_auth[1]["ID"] = $data["ID"];
                                 } else {
                                     $snmp_auth[$i]["ID"] = $data["ID"];
                                     $snmp_auth[$i]["Name"] = $data["name"];
                                     $snmp_auth[$i]["snmp_version"] = Dropdown::getDropdownName("glpi_plugin_fusioninventory_snmpversions", $data["FK_snmp_version"]);
                                     $snmp_auth[$i]["community"] = $data["community"];
                                     $snmp_auth[$i]["sec_name"] = $data["sec_name"];
                                     $snmp_auth[$i]["auth_protocol"] = Dropdown::getDropdownName("glpi_plugin_fusioninventory_snmpprotocolauths", $data["auth_protocol"]);
                                     $snmp_auth[$i]["auth_passphrase"] = $data["auth_passphrase"];
                                     $snmp_auth[$i]["priv_protocol"] = Dropdown::getDropdownName("glpi_plugin_fusioninventory_snmpprotocolprivs", $data["priv_protocol"]);
                                     $snmp_auth[$i]["priv_passphrase"] = $data["priv_passphrase"];
                                     $i++;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $snmp_auth;
 }
 function addInventory()
 {
     $ptc = new PluginFusioninventoryConfig();
     $ptap = new PluginFusioninventoryAgentsProcesses();
     //      if ($_SESSION['glpi_plugin_fusioninventory_addagentprocess'] == '0') {
     //         $this->addProcessNumber($ptap->addProcess($pxml));
     //         $_SESSION['glpi_plugin_fusioninventory_addagentprocess'] = '1';
     //      }
     $this->sxml->addAttribute('RESPONSE', "SEND");
     $this->sxml->addAttribute('PROLOG_FREQ', $ptc->getValue('inventory_frequence'));
 }