/** * * Import printers from OCS * @since 1.0 * @param $cfg_ocs OCSNG mode configuration * @param $computers_id computer's id in GLPI * @param $ocsid computer's id in OCS * @param $ocsservers_id OCS server id * @param $entity the entity in which the printer will be created * @param $dohistory record in history link between printer and computer */ static function importPrinter($cfg_ocs, $computers_id, $ocsservers_id, $ocsid, $entity, $dohistory) { global $PluginOcsinventoryngDBocs, $DB; self::checkOCSconnection($ocsservers_id); if ($cfg_ocs["import_printer"]) { $already_processed = array(); $conn = new Computer_Item(); $query = "SELECT*\n FROM `printers`\n WHERE `HARDWARE_ID` = '{$ocsid}'"; $result = $PluginOcsinventoryngDBocs->query($query); $p = new Printer(); if ($PluginOcsinventoryngDBocs->numrows($result) > 0) { while ($line = $PluginOcsinventoryngDBocs->fetch_array($result)) { $line = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line)); $print = array(); // TO TEST : PARSE NAME to have real name. $print['name'] = self::encodeOcsDataInutf8($cfg_ocs["ocs_db_utf8"], $line['NAME']); if (empty($print["name"])) { $print["name"] = $line["DRIVER"]; } $management_process = $cfg_ocs["import_printer"]; //Params for the dictionnary $params['name'] = $print['name']; $params['manufacturer'] = ""; $params['DRIVER'] = $line['DRIVER']; $params['PORT'] = $line['PORT']; if (!empty($print["name"])) { $rulecollection = new RuleDictionnaryPrinterCollection(); $res_rule = Toolbox::addslashes_deep($rulecollection->processAllRules(Toolbox::stripslashes_deep($params), array(), array())); if (!isset($res_rule["_ignore_import"]) || !$res_rule["_ignore_import"]) { foreach ($res_rule as $key => $value) { if ($value != '' && $value[0] != '_') { $print[$key] = $value; } } if (isset($res_rule['is_global'])) { if (!$res_rule['is_global']) { $management_process = 2; } else { $management_process = 1; } } //Look for a monitor with the same name (and serial if possible) already connected //to this computer $query = "SELECT `p`.`id`, `gci`.`is_deleted`\n FROM `glpi_printers` as `p`, `glpi_computers_items` as `gci`\n WHERE `p`.`id` = `gci`.`items_id`\n AND `gci`.`is_dynamic`='1'\n AND `computers_id`='{$computers_id}'\n AND `itemtype`='Printer'\n AND `p`.`name`='" . $print["name"] . "'"; $results = $DB->query($query); $id = false; $lock = false; if ($DB->numrows($results) > 0) { $id = $DB->result($results, 0, 'id'); $lock = $DB->result($results, 0, 'is_deleted'); } if (!$id) { // Clean printer object $p->reset(); $print["comment"] = $line["PORT"] . "\r\n" . $line["DRIVER"]; self::analizePrinterPorts($print, $line["PORT"]); $id_printer = 0; if ($management_process == 1) { //Config says : manage printers as global //check if printers already exists in GLPI $print["is_global"] = MANAGEMENT_GLOBAL; $query = "SELECT `id`\n FROM `glpi_printers`\n WHERE `name` = '" . $print["name"] . "'\n AND `is_global` = '1'\n AND `entities_id` = '{$entity}'"; $result_search = $DB->query($query); if ($DB->numrows($result_search) > 0) { //Periph is already in GLPI //Do not import anything just get periph ID for link $id_printer = $DB->result($result_search, 0, "id"); $already_processed[] = $id_printer; } else { $input = $print; if ($cfg_ocs["states_id_default"] > 0) { $input["states_id"] = $cfg_ocs["states_id_default"]; } $input["entities_id"] = $entity; $id_printer = $p->add($input); } } else { if ($management_process == 2) { //Config says : manage printers as single units //Import all printers as non global. $input = $print; $input["is_global"] = MANAGEMENT_UNITARY; if ($cfg_ocs["states_id_default"] > 0) { $input["states_id"] = $cfg_ocs["states_id_default"]; } $input["entities_id"] = $entity; $input['is_dynamic'] = 1; $id_printer = $p->add($input); } } if ($id_printer) { $already_processed[] = $id_printer; $conn = new Computer_Item(); $connID = $conn->add(array('computers_id' => $computers_id, 'itemtype' => 'Printer', 'items_id' => $id_printer, '_no_history' => !$dohistory, 'is_dynamic' => 1)); //Update column "is_deleted" set value to 0 and set status to default $input = array(); $input["id"] = $id_printer; $input["is_deleted"] = 0; $input["entities_id"] = $entity; if ($cfg_ocs["states_id_default"] > 0) { $input["states_id"] = $cfg_ocs["states_id_default"]; } $p->update($input); } } else { $already_processed[] = $id; } } } } } //Look for all monitors, not locked, not linked to the computer anymore $query = "SELECT `id`\n FROM `glpi_computers_items`\n WHERE `itemtype`='Printer'\n AND `computers_id`='{$computers_id}'\n AND `is_dynamic`='1'\n AND `is_deleted`='0'"; if (!empty($already_processed)) { $query .= "AND `items_id` NOT IN (" . implode(',', $already_processed) . ")"; } foreach ($DB->request($query) as $data) { //Delete all connexions $conn->delete(array('id' => $data['id'], '_ocsservers_id' => $ocsservers_id), 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+;)/', '&', $dataArray[0]); if (!empty($dataArray[0]) and empty($array_tmp['manufacturers_id'])) { $array_tmp['manufacturers_id'] = $dataArray[0]; } $dataArray[1] = preg_replace('/&(?!\\w+;)/', '&', $dataArray[1]); if (!empty($dataArray[1]) and empty($a_peripherals['productname'])) { $a_peripherals['productname'] = $dataArray[1]; } } if ($array_tmp['productname'] != '') { $array_tmp['name'] = $array_tmp['productname']; } unset($array_tmp['productname']); $a_inventory['peripheral'][] = $array_tmp; $a_peripheral_name[$array_tmp['name']] = $per; $per++; } } if (isset($array['INPUTS'])) { $a_pointingtypes = array(3 => 'Mouse', 4 => 'Trackball', 5 => 'Track Point', 6 => 'Glide Point', 7 => 'Touch Pad', 8 => 'Touch Screen', 9 => 'Mouse - Optical Sensor'); foreach ($array['INPUTS'] as $a_peripherals) { $array_tmp = $thisc->addValues($a_peripherals, array('NAME' => 'name', 'MANUFACTURER' => 'manufacturers_id')); $array_tmp['serial'] = ''; $array_tmp['peripheraltypes_id'] = ''; if (isset($a_peripherals['POINTINGTYPE']) && isset($a_pointingtypes[$a_peripherals['POINTINGTYPE']])) { $array_tmp['peripheraltypes_id'] = $a_pointingtypes[$a_peripherals['POINTINGTYPE']]; } if (isset($a_peripherals['LAYOUT'])) { $array_tmp['peripheraltypes_id'] = 'keyboard'; } if (isset($a_peripheral_name[$array_tmp['name']])) { $a_inventory['peripheral'][$a_peripheral_name[$array_tmp['name']]]['peripheraltypes_id'] = $array_tmp['peripheraltypes_id']; } else { $a_inventory['peripheral'][] = $array_tmp; } } } // * SLOTS // * SOFTWARES $a_inventory['SOFTWARES'] = array(); if ($pfConfig->getValue('import_software') == 1) { if (isset($array['SOFTWARES'])) { $a_inventory['SOFTWARES'] = $array['SOFTWARES']; } } // * STORAGES/COMPUTERDISK $a_inventory['harddrive'] = array(); if (isset($array['STORAGES'])) { foreach ($array['STORAGES'] as $a_storage) { $type_tmp = PluginFusioninventoryFormatconvert::getTypeDrive($a_storage); if ($type_tmp == "Drive") { // it's cd-rom / dvd // if ($pfConfig->getValue(, // "component_drive") =! 0) { if ($pfConfig->getValue('component_drive') == 1) { $array_tmp = $thisc->addValues($a_storage, array('SERIALNUMBER' => 'serial', 'NAME' => 'designation', 'TYPE' => 'interfacetypes_id', 'MANUFACTURER' => 'manufacturers_id')); if ($array_tmp['designation'] == '') { if (isset($a_storage['DESCRIPTION'])) { $array_tmp['designation'] = $a_storage['DESCRIPTION']; } } $a_inventory['drive'][] = $array_tmp; } } else { // it's harddisk // if ($pfConfig->getValue(, // "component_harddrive") != 0) { if (is_array($a_storage)) { if ($pfConfig->getValue('component_harddrive') == 1) { $array_tmp = $thisc->addValues($a_storage, array('DISKSIZE' => 'capacity', 'INTERFACE' => 'interfacetypes_id', 'MANUFACTURER' => 'manufacturers_id', 'MODEL' => 'designation', 'SERIALNUMBER' => 'serial')); if ($array_tmp['designation'] == '') { if (isset($a_storage['NAME'])) { $array_tmp['designation'] = $a_storage['NAME']; } else { if (isset($a_storage['DESIGNATION'])) { $array_tmp['designation'] = $a_storage['DESIGNATION']; } } } $a_inventory['harddrive'][] = $array_tmp; } } } } } // * USERS $cnt = 0; if (isset($array['USERS'])) { if (count($array['USERS']) > 0) { $user_temp = ''; if (isset($a_inventory['Computer']['contact'])) { $user_temp = $a_inventory['Computer']['contact']; } $a_inventory['Computer']['contact'] = ''; } foreach ($array['USERS'] as $a_users) { $array_tmp = $thisc->addValues($a_users, array('LOGIN' => 'login', 'DOMAIN' => 'domain')); $user = ''; if (isset($array_tmp['login'])) { $user = $array_tmp['login']; if (isset($array_tmp['domain']) && !empty($array_tmp['domain'])) { $user .= "@" . $array_tmp['domain']; } } if ($cnt == 0) { if (isset($array_tmp['login'])) { $query = "SELECT `id`\n FROM `glpi_users`\n WHERE `name` = '" . $array_tmp['login'] . "'\n LIMIT 1"; $result = $DB->query($query); if ($DB->numrows($result) == 1) { $a_inventory['Computer']['users_id'] = $DB->result($result, 0, 0); } } } if ($user != '') { if (isset($a_inventory['Computer']['contact'])) { if ($a_inventory['Computer']['contact'] == '') { $a_inventory['Computer']['contact'] = $user; } else { $a_inventory['Computer']['contact'] .= "/" . $user; } } else { $a_inventory['Computer']['contact'] = $user; } } $cnt++; } if (empty($a_inventory['Computer']['contact'])) { $a_inventory['Computer']['contact'] = $user_temp; } } // * VIRTUALMACHINES $a_inventory['virtualmachine'] = array(); if ($pfConfig->getValue('import_vm') == 1) { if (isset($array['VIRTUALMACHINES'])) { foreach ($array['VIRTUALMACHINES'] as $a_virtualmachines) { $array_tmp = $thisc->addValues($a_virtualmachines, array('NAME' => 'name', 'VCPU' => 'vcpu', 'MEMORY' => 'ram', 'VMTYPE' => 'virtualmachinetypes_id', 'SUBSYSTEM' => 'virtualmachinesystems_id', 'STATUS' => 'virtualmachinestates_id', 'UUID' => 'uuid')); $array_tmp['is_dynamic'] = 1; // Hack for BSD jails if ($array_tmp['virtualmachinetypes_id'] == 'jail') { $array_tmp['uuid'] = $a_inventory['Computer']['uuid'] . "-" . $array_tmp['name']; } $a_inventory['virtualmachine'][] = $array_tmp; } } } if ($pfConfig->getValue('create_vm') == 1) { if (isset($array['VIRTUALMACHINES'])) { foreach ($array['VIRTUALMACHINES'] as $a_virtualmachines) { if (strstr($a_virtualmachines['MEMORY'], 'MB')) { $a_virtualmachines['MEMORY'] = str_replace('MB', '', $a_virtualmachines['MEMORY']); } else { if (strstr($a_virtualmachines['MEMORY'], 'KB')) { $a_virtualmachines['MEMORY'] = str_replace('KB', '', $a_virtualmachines['MEMORY']); $a_virtualmachines['MEMORY'] = $a_virtualmachines['MEMORY'] / 1000; } else { if (strstr($a_virtualmachines['MEMORY'], 'GB')) { $a_virtualmachines['MEMORY'] = str_replace('GB', '', $a_virtualmachines['MEMORY']); $a_virtualmachines['MEMORY'] = $a_virtualmachines['MEMORY'] * 1000; } else { if (strstr($a_virtualmachines['MEMORY'], 'B')) { $a_virtualmachines['MEMORY'] = str_replace('B', '', $a_virtualmachines['MEMORY']); $a_virtualmachines['MEMORY'] = $a_virtualmachines['MEMORY'] / 1000000; } } } } $array_tmp = $thisc->addValues($a_virtualmachines, array('NAME' => 'name', 'VCPU' => 'vcpu', 'MEMORY' => 'ram', 'VMTYPE' => 'computertypes_id', 'UUID' => 'uuid', 'OPERATINGSYSTEM' => 'operatingsystems_id', 'CUSTOMFIELDS' => 'comment')); $array_tmp['is_dynamic'] = 1; if (isset($array_tmp['comment']) && is_array($array_tmp['comment'])) { $a_com_temp = $array_tmp['comment']; $array_tmp['comment'] = ''; foreach ($a_com_temp as $data) { $array_tmp['comment'] .= $data['NAME'] . ' : ' . $data['VALUE'] . '\\n'; } } $array_tmp['networkport'] = array(); if (isset($a_virtualmachines['NETWORKS']) && is_array($a_virtualmachines['NETWORKS'])) { foreach ($a_virtualmachines['NETWORKS'] as $data) { $array_tmp_np = $thisc->addValues($data, array('DESCRIPTION' => 'name', 'MACADDR' => 'mac', 'IPADDRESS' => 'ip')); $array_tmp_np['instantiation_type'] = 'NetworkPortEthernet'; $array_tmp_np['mac'] = strtolower($array_tmp_np['mac']); if (isset($array_tmp['networkport'][$array_tmp_np['name'] . '-' . $array_tmp_np['mac']])) { if (isset($array_tmp_np['ip'])) { $array_tmp['networkport'][$array_tmp_np['name'] . '-' . $array_tmp_np['mac']]['ipaddress'][] = $array_tmp_np['ip']; } } else { if (isset($array_tmp_np['ip']) && $array_tmp_np['ip'] != '') { $array_tmp_np['ipaddress'] = array($array_tmp_np['ip']); unset($array_tmp_np['ip']); } else { $array_tmp_np['ipaddress'] = array(); } $array_tmp['networkport'][$array_tmp_np['name'] . '-' . $array_tmp_np['mac']] = $array_tmp_np; } } } $a_inventory['virtualmachine_creation'][] = $array_tmp; } } } // * ANTIVIRUS $a_inventory['antivirus'] = array(); if (isset($array['ANTIVIRUS'])) { foreach ($array['ANTIVIRUS'] as $a_antiviruses) { $array_tmp = $thisc->addValues($a_antiviruses, array('NAME' => 'name', 'COMPANY' => 'manufacturers_id', 'VERSION' => 'version', 'ENABLED' => 'is_active', 'UPTODATE' => 'uptodate')); $a_inventory['antivirus'][] = $array_tmp; } } // * STORAGE/VOLUMES $a_inventory['storage'] = array(); /* begin code, may works at 90% if (isset($array['PHYSICAL_VOLUMES'])) { foreach ($array['PHYSICAL_VOLUMES'] as $a_physicalvolumes) { $array_tmp = $thisc->addValues($a_physicalvolumes, array( 'DEVICE' => 'name', 'PV_UUID' => 'uuid', 'VG_UUID' => 'uuid_link', 'SIZE' => 'totalsize', 'FREE' => 'freesize')); $array_tmp['plugin_fusioninventory_inventorycomputerstoragetypes_id'] = 'partition'; $a_inventory['storage'][] = $array_tmp; } } if (isset($array['STORAGES'])) { foreach ($array['STORAGES'] as $a_storage) { $type_tmp = PluginFusioninventoryFormatconvert::getTypeDrive($a_storage); if ($type_tmp != "Drive") { if (isset($a_storage['NAME']) AND $a_storage['NAME'] != '') { $detectsize = 0; $array_tmp = array(); foreach ($a_inventory['storage'] as $a_physicalvol) { if (preg_match("/^\/dev\/".$a_storage['NAME']."/", $a_physicalvol['name'])) { $array_tmp['name'] = $a_storage['NAME']; if (isset($a_storage['SERIALNUMBER'])) { $array_tmp['uuid'] = $a_storage['SERIALNUMBER']; } else { $array_tmp['uuid'] = $a_storage['NAME']; } $array_tmp['plugin_fusioninventory_inventorycomputerstoragetypes_id'] = 'hard disk'; if (!isset($array_tmp['uuid_link'])) { $array_tmp['uuid_link'] = array(); } $array_tmp['uuid_link'][] = $a_physicalvol['uuid']; $detectsize += $a_physicalvol['totalsize']; } } if (isset($a_storage['DISKSIZE']) && $a_storage['DISKSIZE'] != '') { $array_tmp['totalsize'] = $a_storage['DISKSIZE']; $array_tmp['size_dynamic'] = 0; } else { $array_tmp['totalsize'] = $detectsize; $array_tmp['size_dynamic'] = 1; } $a_inventory['storage'][] = $array_tmp; } } } } if (isset($array['VOLUME_GROUPS'])) { foreach ($array['VOLUME_GROUPS'] as $a_volumegroups) { $array_tmp = $thisc->addValues($a_volumegroups, array( 'VG_NAME' => 'name', 'VG_UUID' => 'uuid', 'SIZE' => 'totalsize', 'FREE' => 'freesize')); $array_tmp['plugin_fusioninventory_inventorycomputerstoragetypes_id'] = 'volume groups'; $a_inventory['storage'][] = $array_tmp; } } if (isset($array['LOGICAL_VOLUMES'])) { foreach ($array['LOGICAL_VOLUMES'] as $a_logicalvolumes) { $array_tmp = $thisc->addValues($a_logicalvolumes, array( 'LV_NAME' => 'name', 'LV_UUID' => 'uuid', 'VG_UUID' => 'uuid_link', 'SIZE' => 'totalsize')); $array_tmp['plugin_fusioninventory_inventorycomputerstoragetypes_id'] = 'logical volumes'; $a_inventory['storage'][] = $array_tmp; } } if (isset($array['DRIVES'])) { foreach ($array['DRIVES'] as $a_drives) { if ((((isset($a_drives['TYPE']) AND $a_drives['TYPE'] == 'Network Drive') OR isset($a_drives['FILESYSTEM']) AND $a_drives['FILESYSTEM'] == 'nfs')) OR ((isset($a_drives['TYPE'])) AND (($a_drives['TYPE'] == "Removable Disk") OR ($a_drives['TYPE'] == "Compact Disc")))) { } else if (isset($a_drives['VOLUMN']) && strstr($a_drives['VOLUMN'], "/dev/mapper")){ // LVM $a_split = explode("-", $a_drives['VOLUMN']); $volumn = end($a_split); $detectsize = 0; $array_tmp = array(); foreach ($a_inventory['storage'] as $num=>$a_physicalvol) { if ($a_physicalvol['plugin_fusioninventory_inventorycomputerstoragetypes_id'] == 'logical volumes') { if ($volumn == $a_physicalvol['name']) { $array_tmp['name'] = $a_drives['TYPE']; if (isset($a_drives['SERIAL'])) { $array_tmp['uuid'] = $a_drives['SERIAL']; } else { $array_tmp['uuid'] = $a_drives['TYPE']; } $array_tmp['plugin_fusioninventory_inventorycomputerstoragetypes_id'] = 'mount'; if (!isset($array_tmp['uuid_link'])) { $array_tmp['uuid_link'] = array(); } $array_tmp['uuid_link'][] = $a_physicalvol['uuid']; $detectsize += $a_physicalvol['totalsize']; } } } if (isset($array_tmp['name'])) { $array_tmp['totalsize'] = $a_drives['TOTAL']; $a_inventory['storage'][] = $array_tmp; } } else if (isset($a_drives['VOLUMN']) && strstr($a_drives['VOLUMN'], "/dev/")){ $detectsize = 0; $array_tmp = array(); foreach ($a_inventory['storage'] as $num=>$a_physicalvol) { $volumn = $a_drives['VOLUMN']; $volumn = substr_replace($volumn , "", -1); $volumn = str_replace("/dev/", "", $volumn); if ($volumn == $a_physicalvol['name']) { $array_tmp['name'] = $a_drives['VOLUMN']; if (isset($a_drives['SERIAL'])) { $array_tmp['uuid'] = $a_drives['SERIAL']; } else { $array_tmp['uuid'] = $a_drives['TYPE']; } $array_tmp['plugin_fusioninventory_inventorycomputerstoragetypes_id'] = 'partition'; if (!isset($array_tmp['uuid_link'])) { $array_tmp['uuid_link'] = array(); } $array_tmp['uuid_link'][] = $a_physicalvol['uuid']; $detectsize += $a_physicalvol['totalsize']; if ($a_physicalvol['size_dynamic'] == 1) { $a_inventory['storage'][$num]['totalsize'] += $a_drives['TOTAL']; } } } if (isset($array_tmp['name'])) { $array_tmp['totalsize'] = $a_drives['TOTAL']; $a_inventory['storage'][] = $array_tmp; $array_tmp['plugin_fusioninventory_inventorycomputerstoragetypes_id'] = 'mount'; $array_tmp['name'] = $a_drives['TYPE']; $array_tmp['uuid_link'] = array(); $array_tmp['uuid_link'][] = $array_tmp['uuid']; $array_tmp['uuid'] = $array_tmp['uuid']."-mount"; $a_inventory['storage'][] = $array_tmp; } } } } */ // * LICENSEINFOS $a_inventory['licenseinfo'] = array(); if (isset($array['LICENSEINFOS'])) { foreach ($array['LICENSEINFOS'] as $a_licenseinfo) { $array_tmp = $thisc->addValues($a_licenseinfo, array('NAME' => 'name', 'FULLNAME' => 'fullname', 'KEY' => 'serial')); $a_inventory['licenseinfo'][] = $array_tmp; } } return $a_inventory; }
/** * * Import printers from OCS * @since 1.0 * @param $cfg_ocs OCSNG mode configuration * @param $computers_id computer's id in GLPI * @param $ocsservers_id OCS server id * @param $ocsComputer * @param $entity the entity in which the printer will be created * @internal param computer $ocsid 's id in OCS */ static function importPrinter($cfg_ocs, $computers_id, $ocsservers_id, $ocsComputer, $entity) { global $DB, $CFG_GLPI; $already_processed = array(); $conn = new Computer_Item(); $p = new Printer(); foreach ($ocsComputer as $printer) { $printer = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($printer)); $print = array(); // TO TEST : PARSE NAME to have real name. $print['name'] = self::encodeOcsDataInUtf8($cfg_ocs["ocs_db_utf8"], $printer['NAME']); if (empty($print["name"])) { $print["name"] = $printer["DRIVER"]; } $management_process = $cfg_ocs["import_printer"]; //Params for the dictionnary $params['name'] = $print['name']; $params['manufacturer'] = ""; $params['DRIVER'] = $printer['DRIVER']; $params['PORT'] = $printer['PORT']; if (!empty($print["name"])) { $rulecollection = new RuleDictionnaryPrinterCollection(); $res_rule = Toolbox::addslashes_deep($rulecollection->processAllRules(Toolbox::stripslashes_deep($params), array(), array())); if (!isset($res_rule["_ignore_import"]) || !$res_rule["_ignore_import"]) { foreach ($res_rule as $key => $value) { if ($value != '' && $value[0] != '_') { $print[$key] = $value; } } if (isset($res_rule['is_global'])) { if (!$res_rule['is_global']) { $management_process = 2; } else { $management_process = 1; } } //Look for a printer with the same name (and serial if possible) already connected //to this computer $query = "SELECT `p`.`id`, `gci`.`is_deleted`\n FROM `glpi_printers` as `p`, `glpi_computers_items` as `gci`\n WHERE `p`.`id` = `gci`.`items_id`\n AND `gci`.`is_dynamic`\n AND `computers_id`='{$computers_id}'\n AND `itemtype`='Printer'\n AND `p`.`name`='" . $print["name"] . "'"; $results = $DB->query($query); $id = false; $lock = false; if ($DB->numrows($results) > 0) { $id = $DB->result($results, 0, 'id'); $lock = $DB->result($results, 0, 'is_deleted'); } if (!$id) { // Clean printer object $p->reset(); $print["comment"] = $printer["PORT"] . "\r\n" . $printer["DRIVER"]; self::analizePrinterPorts($print, $printer["PORT"]); $id_printer = 0; if ($management_process == 1) { //Config says : manage printers as global //check if printers already exists in GLPI $print["is_global"] = MANAGEMENT_GLOBAL; $query = "SELECT `id`\n FROM `glpi_printers`\n WHERE `name` = '" . $print["name"] . "'\n AND `is_global` = '1' "; if ($CFG_GLPI['transfers_id_auto'] < 1) { $query .= " AND `entities_id` = '{$entity}'"; } $result_search = $DB->query($query); if ($DB->numrows($result_search) > 0) { //Periph is already in GLPI //Do not import anything just get periph ID for link $id_printer = $DB->result($result_search, 0, "id"); $already_processed[] = $id_printer; } else { $input = $print; if ($cfg_ocs["states_id_default"] > 0) { $input["states_id"] = $cfg_ocs["states_id_default"]; } $input["entities_id"] = $entity; $id_printer = $p->add($input, array(), $cfg_ocs['history_printer']); } } else { if ($management_process == 2) { //Config says : manage printers as single units //Import all printers as non global. $input = $print; $input["is_global"] = MANAGEMENT_UNITARY; if ($cfg_ocs["states_id_default"] > 0) { $input["states_id"] = $cfg_ocs["states_id_default"]; } $input["entities_id"] = $entity; $input['is_dynamic'] = 1; $id_printer = $p->add($input, array(), $cfg_ocs['history_printer']); } } if ($id_printer) { $already_processed[] = $id_printer; $conn = new Computer_Item(); $connID = $conn->add(array('computers_id' => $computers_id, 'itemtype' => 'Printer', 'items_id' => $id_printer, 'is_dynamic' => 1), array(), $cfg_ocs['history_printer']); //Update column "is_deleted" set value to 0 and set status to default $input = array(); $input["id"] = $id_printer; $input["is_deleted"] = 0; $input["entities_id"] = $entity; if ($cfg_ocs["states_id_default"] > 0) { $input["states_id"] = $cfg_ocs["states_id_default"]; } $p->update($input, $cfg_ocs['history_printer']); } } else { $already_processed[] = $id; } } } } //Look for all printers, not locked, not linked to the computer anymore $query = "SELECT `id`\n FROM `glpi_computers_items`\n WHERE `itemtype`='Printer'\n AND `computers_id`='{$computers_id}'\n AND `is_dynamic`\n AND `is_deleted`='0'"; if (!empty($already_processed)) { $query .= "AND `items_id` NOT IN (" . implode(',', $already_processed) . ")"; } foreach ($DB->request($query) as $data) { // Delete all connexions //Get OCS configuration $ocs_config = self::getConfig($ocsservers_id); //Get the management mode for this device $mode = self::getDevicesManagementMode($ocs_config, 'Printer'); $decoConf = $ocs_config["deconnection_behavior"]; //Change status if : // 1 : the management mode IS NOT global // 2 : a deconnection's status have been defined // 3 : unique with serial if ($mode >= 2 && strlen($decoConf) > 0) { //Delete periph from glpi if ($decoConf == "delete") { $query = "DELETE\n FROM `glpi_computers_items`\n WHERE `id`='" . $data['id'] . "'"; $DB->query($query); //Put periph in dustbin } else { if ($decoConf == "trash") { $query = "UPDATE\n `glpi_computers_items`\n SET `is_deleted` = 1\n WHERE `id`='" . $data['id'] . "'"; $DB->query($query); } } } // foreach ($DB->request($query) as $data){ // Delete all connexions // $conn->delete(array('id' => $data['id'], // '_ocsservers_id' => $ocsservers_id), true); } }
/** * Play printers dictionnary * * @param $values **/ function processDictionnariesIfNeeded(&$values) { $matchings = array('name' => 'name', 'manufacturer' => 'manufacturers_id', 'comment' => 'comment'); foreach ($matchings as $name => $value) { if (isset($values['Printer'][$value])) { $params[$name] = $values['Printer'][$value]; } else { $params[$name] = ''; } } $rulecollection = new RuleDictionnaryPrinterCollection(); $res_rule = $rulecollection->processAllRules($params, array(), array()); if (!isset($res_rule['_no_rule_matches'])) { //Printers dictionnary explicitly refuse import if (isset($res_rule['_ignore_import']) && $res_rule['_ignore_import']) { return false; } if (isset($res_rule['is_global'])) { $values['Printer']['is_global'] = $res_rule['is_global']; } if (isset($res_rule['name'])) { $values['Printer']['name'] = $res_rule['name']; } if (isset($res_rule['supplier'])) { if (isset($values['supplier'])) { $values['Printer']['manufacturers_id'] = Dropdown::getDropdownName('glpi_suppliers', $res_rule['supplier']); } } } return true; }
/** * Import the devices for a computer * * @param $itemtype integer : item type * @param $entity integer : entity of the computer * @param $computers_id integer : glpi computer id. * @param $ocsid integer : ocs computer id (ID). * @param $ocsservers_id integer : ocs server id * @param $cfg_ocs array : ocs config * @param $import_periph array : already imported periph * @param $dohistory boolean : log changes ? * * @return Nothing (void). **/ static function updatePeripherals($itemtype, $entity, $computers_id, $ocsid, $ocsservers_id, $cfg_ocs, $import_periph, $dohistory) { global $DB, $DBocs; self::checkOCSconnection($ocsservers_id); $do_clean = false; $connID = 0; //Tag for data since 0.70 for the import_monitor array. $count_monitor = count($import_periph); switch ($itemtype) { case 'Monitor': if ($cfg_ocs["import_monitor"]) { //Update data in import_monitor array for 0.70 if (!in_array(self::IMPORT_TAG_070, $import_periph)) { foreach ($import_periph as $key => $val) { $monitor_tag = $val; //delete old value self::deleteInOcsArray($computers_id, $key, "import_monitor"); //search serial when it exists $monitor_serial = ""; $query_monitor_id = "SELECT `items_id`\n FROM `glpi_computers_items`\n WHERE `id` = '{$key}'"; $result_monitor_id = $DB->query($query_monitor_id); if ($DB->numrows($result_monitor_id) == 1) { //get monitor Id $id_monitor = $DB->result($result_monitor_id, 0, "items_id"); $query_monitor_serial = "SELECT `serial`\n FROM `glpi_monitors`\n WHERE `id` = '{$id_monitor}'"; $result_monitor_serial = $DB->query($query_monitor_serial); //get serial if ($DB->numrows($result_monitor_serial) == 1) { $monitor_serial = $DB->result($result_monitor_serial, 0, "serial"); } } //concat name + serial $monitor_tag .= $monitor_serial; //add new value (serial + name when its possible) self::addToOcsArray($computers_id, array($key => $monitor_tag), "import_monitor"); //Update the array with the new value of the monitor $import_periph[$key] = $monitor_tag; } //add the tag for the array version's self::addToOcsArray($computers_id, array(0 => self::IMPORT_TAG_070), "import_monitor"); } $do_clean = true; $m = new Monitor(); $query = "SELECT DISTINCT `CAPTION`, `MANUFACTURER`, `DESCRIPTION`, `SERIAL`, `TYPE`\n FROM `monitors`\n WHERE `HARDWARE_ID` = '{$ocsid}'"; $result = $DBocs->query($query); $lines = array(); $checkserial = true; // First pass - check if all serial present if ($DBocs->numrows($result) > 0) { while ($line = $DBocs->fetch_array($result)) { if (empty($line["SERIAL"])) { $checkserial = false; } $lines[] = clean_cross_side_scripting_deep(addslashes_deep($line)); } } if (count($lines) > 0 && ($cfg_ocs["import_monitor"] <= 2 || $checkserial)) { foreach ($lines as $line) { $mon = array(); $mon["name"] = $line["CAPTION"]; if (empty($line["CAPTION"]) && !empty($line["MANUFACTURER"])) { $mon["name"] = $line["MANUFACTURER"]; } if (empty($line["CAPTION"]) && !empty($line["TYPE"])) { if (!empty($line["MANUFACTURER"])) { $mon["name"] .= " "; } $mon["name"] .= $line["TYPE"]; } $mon["serial"] = $line["SERIAL"]; $checkMonitor = $mon["name"]; if (!empty($mon["serial"])) { $checkMonitor .= $mon["serial"]; } if (!empty($mon["name"])) { $id = array_search(stripslashes($checkMonitor), $import_periph); } if ($id === false) { // Clean monitor object $m->reset(); $mon["manufacturers_id"] = Dropdown::importExternal('Manufacturer', $line["MANUFACTURER"]); if ($cfg_ocs["import_monitor_comment"]) { $mon["comment"] = $line["DESCRIPTION"]; } $id_monitor = 0; if ($cfg_ocs["import_monitor"] == 1) { //Config says : manage monitors as global //check if monitors already exists in GLPI $mon["is_global"] = 1; $query = "SELECT `id`\n FROM `glpi_monitors`\n WHERE `name` = '" . $mon["name"] . "'\n AND `is_global` = '1'\n AND `entities_id` = '{$entity}'"; $result_search = $DB->query($query); if ($DB->numrows($result_search) > 0) { //Periph is already in GLPI //Do not import anything just get periph ID for link $id_monitor = $DB->result($result_search, 0, "id"); } else { $input = $mon; if ($cfg_ocs["states_id_default"] > 0) { $input["states_id"] = $cfg_ocs["states_id_default"]; } $input["entities_id"] = $entity; $id_monitor = $m->add($input); } } else { if ($cfg_ocs["import_monitor"] >= 2) { //Config says : manage monitors as single units //Import all monitors as non global. $mon["is_global"] = 0; // Try to find a monitor with the same serial. if (!empty($mon["serial"])) { $query = "SELECT `id`\n FROM `glpi_monitors`\n WHERE `serial` LIKE '%" . $mon["serial"] . "%'\n AND `is_global` = '0'\n AND `entities_id` = '{$entity}'"; $result_search = $DB->query($query); if ($DB->numrows($result_search) == 1) { //Monitor founded $id_monitor = $DB->result($result_search, 0, "id"); } } //Search by serial failed, search by name if ($cfg_ocs["import_monitor"] == 2 && !$id_monitor) { //Try to find a monitor with no serial, the same name and not already connected. if (!empty($mon["name"])) { $query = "SELECT `glpi_monitors`.`id`\n FROM `glpi_monitors`\n LEFT JOIN `glpi_computers_items`\n ON (`glpi_computers_items`.`itemtype`='Monitor'\n AND `glpi_computers_items`.`items_id`\n =`glpi_monitors`.`id`)\n WHERE `serial` = ''\n AND `name` = '" . $mon["name"] . "'\n AND `is_global` = '0'\n AND `entities_id` = '{$entity}'\n AND `glpi_computers_items`.`computers_id` IS NULL"; $result_search = $DB->query($query); if ($DB->numrows($result_search) == 1) { $id_monitor = $DB->result($result_search, 0, "id"); } } } if (!$id_monitor) { $input = $mon; if ($cfg_ocs["states_id_default"] > 0) { $input["states_id"] = $cfg_ocs["states_id_default"]; } $input["entities_id"] = $entity; $id_monitor = $m->add($input); } } } // ($cfg_ocs["import_monitor"] >= 2) if ($id_monitor) { //Import unique : Disconnect monitor on other computer done in Connect function $conn = new Computer_Item(); $connID = $conn->add(array('computers_id' => $computers_id, 'itemtype' => 'Monitor', 'items_id' => $id_monitor, '_no_history' => !$dohistory)); if (!in_array(self::IMPORT_TAG_070, $import_periph)) { self::addToOcsArray($computers_id, array(0 => self::IMPORT_TAG_070), "import_monitor"); } if ($connID > 0) { // sanity check - Add can fail self::addToOcsArray($computers_id, array($connID => $checkMonitor), "import_monitor"); } $count_monitor++; //Update column "is_deleted" set value to 0 and set status to default $input = array(); $old = new Monitor(); if ($old->getFromDB($id_monitor)) { if ($old->fields["is_deleted"]) { $input["is_deleted"] = 0; } if ($cfg_ocs["states_id_default"] > 0 && $old->fields["states_id"] != $cfg_ocs["states_id_default"]) { $input["states_id"] = $cfg_ocs["states_id_default"]; } if (empty($old->fields["name"]) && !empty($mon["name"])) { $input["name"] = $mon["name"]; } if (empty($old->fields["serial"]) && !empty($mon["serial"])) { $input["serial"] = $mon["serial"]; } if (count($input)) { $input["id"] = $id_monitor; $input['entities_id'] = $entity; $m->update($input); } } } } else { // found in array unset($import_periph[$id]); } } // end foreach } if (in_array(self::IMPORT_TAG_070, $import_periph)) { //unset the version Tag unset($import_periph[0]); } } break; case 'Printer': if ($cfg_ocs["import_printer"]) { $do_clean = true; $query = "SELECT *\n FROM `printers`\n WHERE `HARDWARE_ID` = '{$ocsid}'"; $result = $DBocs->query($query); $p = new Printer(); if ($DBocs->numrows($result) > 0) { while ($line = $DBocs->fetch_array($result)) { $line = clean_cross_side_scripting_deep(addslashes_deep($line)); $print = array(); // TO TEST : PARSE NAME to have real name. if (!seems_utf8($line["NAME"])) { $print["name"] = encodeInUtf8($line["NAME"]); } else { $print["name"] = $line["NAME"]; } if (empty($print["name"])) { $print["name"] = $line["DRIVER"]; } $management_process = $cfg_ocs["import_printer"]; //Params for the dictionnary $params['name'] = $print['name']; $params['manufacturer'] = ""; $params['DRIVER'] = $line['DRIVER']; $params['PORT'] = $line['PORT']; if (!empty($print["name"])) { $rulecollection = new RuleDictionnaryPrinterCollection(); $res_rule = addslashes_deep($rulecollection->processAllRules($params, array(), array())); if (!isset($res_rule["_ignore_ocs_import"]) || !$res_rule["_ignore_ocs_import"]) { foreach ($res_rule as $key => $value) { if ($value != '' && $value[0] != '_') { $print[$key] = $value; } } // if (isset($res_rule['is_global'])) { // logDebug($res_rule); // } if (isset($res_rule['is_global'])) { if (!$res_rule['is_global']) { $management_process = 2; } else { $management_process = 1; } } if (!in_array(stripslashes($print["name"]), $import_periph)) { // Clean printer object $p->reset(); $print["comment"] = $line["PORT"] . "\r\n" . $line["DRIVER"]; self::analizePrinterPorts($print, $line["PORT"]); $id_printer = 0; if ($management_process == 1) { //Config says : manage printers as global //check if printers already exists in GLPI $print["is_global"] = MANAGEMENT_GLOBAL; $query = "SELECT `id`\n FROM `glpi_printers`\n WHERE `name` = '" . $print["name"] . "'\n AND `is_global` = '1'\n AND `entities_id` = '{$entity}'"; $result_search = $DB->query($query); if ($DB->numrows($result_search) > 0) { //Periph is already in GLPI //Do not import anything just get periph ID for link $id_printer = $DB->result($result_search, 0, "id"); } else { $input = $print; if ($cfg_ocs["states_id_default"] > 0) { $input["states_id"] = $cfg_ocs["states_id_default"]; } $input["entities_id"] = $entity; // if (isset($res_rule['is_global'])) { // logDebug("global",$input); // } $id_printer = $p->add($input); } } else { if ($management_process == 2) { //Config says : manage printers as single units //Import all printers as non global. $input = $print; $input["is_global"] = MANAGEMENT_UNITARY; if ($cfg_ocs["states_id_default"] > 0) { $input["states_id"] = $cfg_ocs["states_id_default"]; } $input["entities_id"] = $entity; // if (isset($res_rule['is_global'])) { // logDebug("unitary",$input); // } $id_printer = $p->add($input); } } if ($id_printer) { $conn = new Computer_Item(); $connID = $conn->add(array('computers_id' => $computers_id, 'itemtype' => 'Printer', 'items_id' => $id_printer, '_no_history' => !$dohistory)); if ($connID > 0) { // sanity check - Add can fail self::addToOcsArray($computers_id, array($connID => $print["name"]), "import_printer"); } //Update column "is_deleted" set value to 0 and set status to default $input = array(); $input["id"] = $id_printer; $input["is_deleted"] = 0; $input["entities_id"] = $entity; if ($cfg_ocs["states_id_default"] > 0) { $input["states_id"] = $cfg_ocs["states_id_default"]; } $p->update($input); } } else { $id = array_search(stripslashes($print["name"]), $import_periph); unset($import_periph[$id]); } } } } } } break; case 'Peripheral': if ($cfg_ocs["import_periph"]) { $do_clean = true; $p = new Peripheral(); $query = "SELECT DISTINCT `CAPTION`, `MANUFACTURER`, `INTERFACE`, `TYPE`\n FROM `inputs`\n WHERE `HARDWARE_ID` = '{$ocsid}'\n AND `CAPTION` <> ''"; $result = $DBocs->query($query); if ($DBocs->numrows($result) > 0) { while ($line = $DBocs->fetch_array($result)) { $line = clean_cross_side_scripting_deep(addslashes_deep($line)); $periph = array(); if (!seems_utf8($line["CAPTION"])) { $periph["name"] = encodeInUtf8($line["CAPTION"]); } else { $periph["name"] = $line["CAPTION"]; } if (!in_array(stripslashes($periph["name"]), $import_periph)) { // Clean peripheral object $p->reset(); if ($line["MANUFACTURER"] != "NULL") { $periph["brand"] = $line["MANUFACTURER"]; } if ($line["INTERFACE"] != "NULL") { $periph["comment"] = $line["INTERFACE"]; } $periph["peripheraltypes_id"] = Dropdown::importExternal('PeripheralType', $line["TYPE"]); $id_periph = 0; if ($cfg_ocs["import_periph"] == 1) { //Config says : manage peripherals as global //check if peripherals already exists in GLPI $periph["is_global"] = 1; $query = "SELECT `id`\n FROM `glpi_peripherals`\n WHERE `name` = '" . $periph["name"] . "'\n AND `is_global` = '1'\n AND `entities_id` = '{$entity}'"; $result_search = $DB->query($query); if ($DB->numrows($result_search) > 0) { //Periph is already in GLPI //Do not import anything just get periph ID for link $id_periph = $DB->result($result_search, 0, "id"); } else { $input = $periph; if ($cfg_ocs["states_id_default"] > 0) { $input["states_id"] = $cfg_ocs["states_id_default"]; } $input["entities_id"] = $entity; $id_periph = $p->add($input); } } else { if ($cfg_ocs["import_periph"] == 2) { //Config says : manage peripherals as single units //Import all peripherals as non global. $input = $periph; $input["is_global"] = 0; if ($cfg_ocs["states_id_default"] > 0) { $input["states_id"] = $cfg_ocs["states_id_default"]; } $input["entities_id"] = $entity; $id_periph = $p->add($input); } } if ($id_periph) { $conn = new Computer_Item(); if ($connID = $conn->add(array('computers_id' => $computers_id, 'itemtype' => 'Peripheral', 'items_id' => $id_periph, '_no_history' => !$dohistory))) { self::addToOcsArray($computers_id, array($connID => $periph["name"]), "import_peripheral"); //Update column "is_deleted" set value to 0 and set status to default $input = array(); $input["id"] = $id_periph; $input["is_deleted"] = 0; $input["entities_id"] = $entity; if ($cfg_ocs["states_id_default"] > 0) { $input["states_id"] = $cfg_ocs["states_id_default"]; } $p->update($input); } } } else { $id = array_search(stripslashes($periph["name"]), $import_periph); unset($import_periph[$id]); } } } } break; } // Disconnect Unexisting Items not found in OCS if ($do_clean && count($import_periph)) { $conn = new Computer_Item(); foreach ($import_periph as $key => $val) { switch ($itemtype) { case 'Monitor': // Only if sync done if ($cfg_ocs["import_monitor"] <= 2 || $checkserial) { $conn->delete(array('id' => $key, '_ocsservers_id' => $ocsservers_id)); self::deleteInOcsArray($computers_id, $key, "import_monitor"); } break; case 'Printer': $conn->delete(array('id' => $key, '_ocsservers_id' => $ocsservers_id)); self::deleteInOcsArray($computers_id, $key, "import_printer"); break; case 'Peripheral': $conn->delete(array('id' => $key, '_ocsservers_id' => $ocsservers_id)); self::deleteInOcsArray($computers_id, $key, "import_peripheral"); break; default: $conn->delete(array('id' => $key, '_ocsservers_id' => $ocsservers_id)); } } } }