当前位置: 首页>>代码示例>>PHP>>正文


PHP IPAddress::add方法代码示例

本文整理汇总了PHP中IPAddress::add方法的典型用法代码示例。如果您正苦于以下问题:PHP IPAddress::add方法的具体用法?PHP IPAddress::add怎么用?PHP IPAddress::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IPAddress的用法示例。


在下文中一共展示了IPAddress::add方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: ImportNetworkEquipment

 /**
  * @test
  */
 public function ImportNetworkEquipment()
 {
     global $DB;
     self::restore_database();
     // Load session rights
     $_SESSION['glpidefault_entity'] = 0;
     Session::initEntityProfiles(2);
     Session::changeProfile(4);
     $pfUnmanaged = new PluginFusioninventoryUnmanaged();
     $networkEquipment = new NetworkEquipment();
     $networkPort = new NetworkPort();
     $networkName = new NetworkName();
     $iPAddress = new IPAddress();
     $input = array('name' => 'switch', 'entities_id' => 0, 'item_type' => 'NetworkEquipment', 'sysdescr' => 'Cisco machin chose', 'locations_id' => 1, 'is_dynamic' => 1, 'serial' => 'XXS6BEF3', 'comment' => 'this is a comment', 'plugin_fusioninventory_configsecurities_id' => 1);
     $unmanageds_id = $pfUnmanaged->add($input);
     // * Add networkport
     $input = array();
     $input['itemtype'] = 'PluginFusioninventoryUnmanaged';
     $input['items_id'] = $unmanageds_id;
     $input['instantiation_type'] = 'NetworkPortEthernet';
     $input['name'] = 'general';
     $input['mac'] = '00:00:00:43:ae:0f';
     $input['is_dynamic'] = 1;
     $networkports_id = $networkPort->add($input);
     $input = array();
     $input['items_id'] = $networkports_id;
     $input['itemtype'] = 'NetworkPort';
     $input['name'] = '';
     $input['is_dynamic'] = 1;
     $networknames_id = $networkName->add($input);
     $input = array();
     $input['entities_id'] = 0;
     $input['itemtype'] = 'NetworkName';
     $input['items_id'] = $networknames_id;
     $input['name'] = '192.168.20.1';
     $input['is_dynamic'] = 1;
     $iPAddress->add($input);
     $pfUnmanaged->import($unmanageds_id);
     $cnt = countElementsInTable("glpi_networkequipments");
     $this->assertEquals(1, $cnt, "May have network equipment added");
     $cnt = countElementsInTable("glpi_plugin_fusioninventory_unmanageds");
     $this->assertEquals(0, $cnt, "Unknown device may be deleted");
     $networkEquipment->getFromDB(1);
     $this->assertEquals('XXS6BEF3', $networkEquipment->fields['serial'], "Serial");
     $this->assertEquals('switch', $networkEquipment->fields['name'], "Name");
     $this->assertEquals(1, $networkEquipment->fields['is_dynamic'], "is_dynamic");
     $this->assertEquals(1, $networkEquipment->fields['locations_id'], "locations_id");
     $this->assertEquals('this is a comment', $networkEquipment->fields['comment'], "comment");
     $networkPort->getFromDB(1);
     $a_reference = array('name' => 'general', 'id' => '1', 'items_id' => '1', 'itemtype' => 'NetworkEquipment', 'entities_id' => '0', 'is_recursive' => '0', 'logical_number' => '0', 'instantiation_type' => 'NetworkPortEthernet', 'mac' => '00:00:00:43:ae:0f', 'comment' => '', 'is_deleted' => '0', 'is_dynamic' => '1');
     $this->assertEquals($a_reference, $networkPort->fields, "Networkport");
     $networkName->getFromDB(1);
     $a_reference = array('id' => '1', 'entities_id' => '0', 'items_id' => '1', 'itemtype' => 'NetworkPort', 'comment' => NULL, 'fqdns_id' => '0', 'is_deleted' => '0', 'is_dynamic' => '1', 'name' => '');
     $this->assertEquals($a_reference, $networkName->fields, "Networkname");
     $iPAddress->getFromDB(1);
     $a_reference = array('name' => '192.168.20.1', 'id' => '1', 'entities_id' => '0', 'items_id' => '1', 'itemtype' => 'NetworkName', 'version' => '4', 'binary_0' => '0', 'binary_1' => '0', 'binary_2' => '65535', 'binary_3' => '3232240641', 'is_deleted' => '0', 'is_dynamic' => '1', 'mainitems_id' => '1', 'mainitemtype' => 'NetworkEquipment');
     $this->assertEquals($a_reference, $iPAddress->fields, "IPAddress");
 }
开发者ID:korial29,项目名称:fusioninventory-for-glpi,代码行数:61,代码来源:UnmanagedImportTest.php

示例2: pluginFusioninventoryUpdate

function pluginFusioninventoryUpdate($current_version, $migrationname = 'Migration')
{
    global $DB;
    ini_set("max_execution_time", "0");
    ini_set("memory_limit", "-1");
    foreach (glob(GLPI_ROOT . '/plugins/fusioninventory/inc/*.php') as $file) {
        require_once $file;
    }
    $migration = new $migrationname($current_version);
    $prepare_task = array();
    $prepare_rangeip = array();
    $prepare_Config = array();
    $a_plugin = plugin_version_fusioninventory();
    $plugins_id = PluginFusioninventoryModule::getModuleId($a_plugin['shortname']);
    $migration->displayMessage("Migration Classname : " . $migrationname);
    $migration->displayMessage("Update of plugin FusionInventory");
    /*
     * Check if folders are correctly created
     */
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/tmp')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/tmp');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/computer')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/computer');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/printer')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/printer');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/networkequipment')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/networkequipment');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/walks')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/walks');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/tmpmodels')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/tmpmodels');
    }
    /*
     * Deploy folders
     */
    if (is_dir(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/files')) {
        rename(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/files', GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files');
    }
    if (is_dir(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/repository')) {
        rename(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/repository', GLPI_PLUGIN_DOC_DIR . '/fusioninventory/repository');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/repository')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/repository');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/manifests')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/manifests');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/import')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/import');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/export')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/export');
    }
    if (is_dir(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/upload')) {
        rename(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/upload', GLPI_PLUGIN_DOC_DIR . '/fusioninventory/upload');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/upload')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/upload');
    }
    /*
     * Rename fileparts without .gz extension (cf #1999)
     */
    if (is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files')) {
        $gzfiles = pluginFusioninventoryFindFiles(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files', '/\\.gz$/');
        foreach ($gzfiles as $file) {
            $fileWithoutExt = pathinfo($file, PATHINFO_DIRNAME) . '/' . pathinfo($file, PATHINFO_FILENAME);
            rename($file, $fileWithoutExt);
        }
    }
    unset($gzfiles);
    /*
     *  Rename tables from old version of FuionInventory (2.2.1 for example)
     */
    $migration->renameTable("glpi_plugin_fusioninventory_rangeip", "glpi_plugin_fusioninventory_ipranges");
    $migration->renameTable("glpi_plugin_fusioninventory_lock", "glpi_plugin_fusioninventory_locks");
    $migration->renameTable("glpi_plugin_fusioninventory_unknown_device", "glpi_plugin_fusioninventory_unknowndevices");
    $migration->renameTable("glpi_plugin_fusioninventory_config", "glpi_plugin_fusioninventory_configs");
    $migration->renameTable("glpi_plugin_fusioninventory_networking_ports", "glpi_plugin_fusinvsnmp_networkports");
    $migration->renameTable("glpi_plugin_fusioninventory_construct_device", "glpi_plugin_fusinvsnmp_constructdevices");
    $migration->renameTable("glpi_plugin_fusioninventory_construct_mibs", "glpi_plugin_fusioninventory_snmpmodelconstructdevice_miboids");
    $migration->renameTable("glpi_plugin_fusioninventory_networking", "glpi_plugin_fusioninventory_networkequipments");
    $migration->renameTable("glpi_plugin_fusioninventory_networking_ifaddr", "glpi_plugin_fusinvsnmp_networkequipmentips");
    $migration->renameTable("glpi_plugin_fusioninventory_printers", "glpi_plugin_fusinvsnmp_printers");
    $migration->renameTable("glpi_plugin_fusioninventory_printers_cartridges", "glpi_plugin_fusinvsnmp_printercartridges");
    $migration->renameTable("glpi_plugin_fusioninventory_printers_history", "glpi_plugin_fusinvsnmp_printerlogs");
    $migration->renameTable("glpi_plugin_fusioninventory_model_infos", "glpi_plugin_fusioninventory_snmpmodels");
//.........这里部分代码省略.........
开发者ID:C-Duv,项目名称:fusioninventory-for-glpi,代码行数:101,代码来源:update.php

示例3: NetworkPort

 function _updateNetworkInfo($arrayinventory, $item_type, $id, $instanciation_type, $check_addresses)
 {
     $NetworkPort = new NetworkPort();
     $port = current($NetworkPort->find("`itemtype`='{$item_type}' AND `items_id`='{$id}'" . " AND `instantiation_type`='{$instanciation_type}'", "", 1));
     $port_id = 0;
     if (isset($port['id'])) {
         if (isset($arrayinventory['MAC']) and !empty($arrayinventory['MAC'])) {
             $input = array();
             $input['id'] = $port['id'];
             $input['mac'] = $arrayinventory['MAC'];
             $NetworkPort->update($input);
         }
         $port_id = $port['id'];
     } else {
         $input = array();
         $input['itemtype'] = $item_type;
         $input['items_id'] = $id;
         $input['instantiation_type'] = $instanciation_type;
         $input['name'] = "management";
         if (isset($arrayinventory['MAC']) && !empty($arrayinventory['MAC'])) {
             $input['mac'] = $arrayinventory['MAC'];
         }
         $port_id = $NetworkPort->add($input);
     }
     $NetworkName = new NetworkName();
     $name = current($NetworkName->find("`itemtype`='NetworkPort' AND `items_id`='" . $port_id . "'", "", 1));
     $name_id = 0;
     if (isset($name['id'])) {
         $name_id = $name['id'];
     } else {
         $input = array();
         $input['itemtype'] = 'NetworkPort';
         $input['items_id'] = $port_id;
         $name_id = $NetworkName->add($input);
     }
     if (isset($arrayinventory['IP'])) {
         $IPAddress = new IPAddress();
         if ($check_addresses) {
             $addresses = $IPAddress->find("`itemtype`='NetworkName'\n               AND `items_id`='" . $name_id . "'", '', 1);
         } else {
             // Case of NetworkEquipment
             $a_ips = $IPAddress->find("`itemtype`='NetworkName'\n               AND `items_id`='" . $name_id . "'\n               AND `name`='" . $arrayinventory['IP'] . "'", '', 1);
             if (count($a_ips) > 0) {
                 $addresses = $a_ips;
             } else {
                 $addresses = array();
             }
         }
         if (count($addresses) == 0) {
             $input = array();
             $input['itemtype'] = 'NetworkName';
             $input['items_id'] = $name_id;
             $input['name'] = $arrayinventory['IP'];
             $IPAddress->add($input);
         } else {
             $address = current($addresses);
             if ($address['name'] != $arrayinventory['IP']) {
                 $input = array();
                 $input['id'] = $address['id'];
                 $input['name'] = $arrayinventory['IP'];
                 $IPAddress->update($input);
             }
         }
     }
 }
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:65,代码来源:communicationnetworkdiscovery.class.php

示例4: array

 /**
  * \brief Update IPAddress database
  * Update IPAddress database to remove old IPs and add new ones.
  **/
 function post_workOnItem()
 {
     if (isset($this->input['_ipaddresses']) && is_array($this->input['_ipaddresses'])) {
         $input = array('itemtype' => 'NetworkName', 'items_id' => $this->getID());
         foreach ($this->input['_ipaddresses'] as $id => $ip) {
             $ipaddress = new IPAddress();
             $input['name'] = $ip;
             if ($id < 0) {
                 if (!empty($ip)) {
                     $ipaddress->add($input);
                 }
             } else {
                 if (!empty($ip)) {
                     $input['id'] = $id;
                     $ipaddress->update($input);
                     unset($input['id']);
                 } else {
                     $ipaddress->delete(array('id' => $id));
                 }
             }
         }
     }
 }
开发者ID:kipman,项目名称:glpi,代码行数:27,代码来源:networkname.class.php

示例5: updateNetworkPort

 /**
  * @param $mac
  * @param $name
  * @param $computers_id
  * @param $instantiation_type
  * @param $inst_input
  * @param $ips
  * @param $check_name
  * @param $dohistory
  * @param $already_known_ports
  * @return ID
  */
 private static function updateNetworkPort($mac, $name, $computers_id, $instantiation_type, $inst_input, $ips, $check_name, $dohistory, $already_known_ports)
 {
     global $DB;
     $network_port = new NetworkPort();
     // Then, find or create the base NetworkPort
     $query = "SELECT `id`, `is_dynamic`\n                FROM `glpi_networkports`\n                WHERE `itemtype` = 'Computer'\n                   AND `items_id` = '{$computers_id}'\n                   AND `mac` = '{$mac}'";
     // If there is virtual ports, then, filter by port's name
     if ($check_name) {
         $query .= " AND `name` = '{$name}'";
     }
     if (count($already_known_ports) > 0) {
         $query .= " AND `id` NOT IN (" . implode(',', $already_known_ports) . ")";
     }
     // We order by is_dynamic to be sure to get the static ones first !
     $query .= " ORDER BY `is_dynamic`, `id`";
     $ports = $DB->request($query);
     if ($ports->numrows() == 0) {
         $port_input = array('name' => $name, 'mac' => $mac, 'items_id' => $computers_id, 'itemtype' => 'Computer', '_no_history' => !$dohistory, 'instantiation_type' => $instantiation_type, '_create_children' => 1, 'is_dynamic' => 1, 'is_deleted' => 0);
         $networkports_id = $network_port->add($port_input, array(), $dohistory);
         if ($networkports_id === false) {
             return -1;
         }
         $inst_input['networkports_id'] = $networkports_id;
         $instantiation = $network_port->getInstantiation();
         $instantiation->update($inst_input);
         unset($instantiation);
     } else {
         $line = $ports->next();
         $networkports_id = $line['id'];
         $network_port->getFromDB($networkports_id);
         if (!$check_name && $network_port->fields['name'] != $name) {
             $port_input = array('id' => $network_port->getID(), 'name' => $name, 'is_dynamic' => 1);
             $network_port->update($port_input);
         }
         if ($network_port->fields['instantiation_type'] != $instantiation_type && $network_port->fields['is_dynamic'] == 1) {
             $network_port->switchInstantiationType($instantiation_type);
             $inst_input['networkports_id'] = $network_port->getID();
             $instantiation = $network_port->getInstantiation();
             $instantiation->add($inst_input);
             unset($instantiation);
         }
         if ($network_port->fields['instantiation_type'] == $instantiation_type) {
             $instantiation = $network_port->getInstantiation();
             $inst_input['id'] = $instantiation->getID();
             $inst_input['networkports_id'] = $network_port->getID();
             $instantiation->update($inst_input);
             unset($instantiation);
         }
     }
     if ($network_port->isNewItem()) {
         return -1;
     }
     $network_name = new NetworkName();
     $query = "SELECT `id`, `is_dynamic`\n                FROM `glpi_networknames`\n                WHERE `itemtype` = 'NetworkPort'\n                   AND `items_id` = '{$networkports_id}'\n                ORDER BY `is_dynamic`";
     if (!$ips || count($ips) == 0) {
         foreach ($DB->request($query) as $line) {
             if ($line['is_dynamic']) {
                 $network_name->delete($line, true, $dohistory);
             }
         }
     } else {
         $names = $DB->request($query);
         if ($names->numrows() == 0) {
             $name_input = array('itemtype' => 'NetworkPort', 'items_id' => $networkports_id, 'is_dynamic' => 1, 'is_deleted' => 0, '_no_history' => !$dohistory, 'name' => 'OCS-INVENTORY-NG');
             $networknames_id = $network_name->add($name_input);
         } else {
             $line = $names->next();
             $networknames_id = $line['id'];
             foreach ($names as $line) {
                 if ($line['is_dynamic'] == 1 && $line['id'] != $networknames_id) {
                     $network_port->delete($line, true, $dohistory);
                 }
             }
         }
         $ip_address = new IPAddress();
         $already_known_addresses = array();
         $query = "SELECT `id`, `name`, `is_dynamic`, `mainitems_id`\n                   FROM `glpi_ipaddresses`\n                   WHERE `itemtype` = 'NetworkName'\n                     AND `items_id` = '{$networknames_id}'\n                   ORDER BY `is_dynamic`";
         foreach ($DB->request($query) as $line) {
             if (in_array($line['name'], $ips) && !empty($line['mainitems_id'])) {
                 $already_known_addresses[] = $line['id'];
                 $ips = array_diff($ips, array($line['name']));
             } elseif ($line['is_dynamic'] == 1) {
                 $ip_address->delete($line, true, $dohistory);
             }
         }
     }
     if ($ips) {
         foreach ($ips as $ip) {
//.........这里部分代码省略.........
开发者ID:pluginsGLPI,项目名称:ocsinventoryng,代码行数:101,代码来源:networkport.class.php

示例6: PrinterToInventoryWithIP

 /**
  * @test
  */
 public function PrinterToInventoryWithIP()
 {
     self::restore_database();
     $printer = new Printer();
     $networkport = new NetworkPort();
     $networkName = new NetworkName();
     $iPAddress = new IPAddress();
     $pfPrinter = new PluginFusioninventoryPrinter();
     $pfTask = new PluginFusioninventoryTask();
     $pfTaskjob = new PluginFusioninventoryTaskjob();
     $computer = new Computer();
     $pfAgent = new PluginFusioninventoryAgent();
     $communication = new PluginFusioninventoryCommunication();
     // Create computers + agents
     $input = array('entities_id' => 0, 'name' => 'computer1');
     $computers_id = $computer->add($input);
     $input = array('entities_id' => 0, 'name' => 'computer1', 'version' => '{"INVENTORY":"v2.3.11"}', 'device_id' => 'computer1', 'useragent' => 'FusionInventory-Agent_v2.3.11', 'computers_id' => $computers_id);
     $pfAgent->add($input);
     // Create printer
     $input = array('name' => 'printer 001', 'entities_id' => 0);
     $printers_id = $printer->add($input);
     // Add port
     $networkports_id = $networkport->add(array('itemtype' => 'Printer', 'instantiation_type' => 'NetworkPortEthernet', 'items_id' => $printers_id, 'entities_id' => 0));
     $networknames_id = $networkName->add(array('entities_id' => 0, 'itemtype' => 'NetworkPort', 'items_id' => $networkports_id));
     $iPAddress->add(array('entities_id' => 0, 'itemtype' => 'NetworkName', 'items_id' => $networknames_id, 'name' => '192.168.200.124'));
     $input = array('printers_id' => 1, 'plugin_fusioninventory_configsecurities_id' => 2);
     $pfPrinter->add($input);
     // Add task
     // create task
     $input = array('entities_id' => 0, 'name' => 'network inventory', 'is_active' => 1);
     $tasks_id = $pfTask->add($input);
     // create taskjob
     $input = array('plugin_fusioninventory_tasks_id' => $tasks_id, 'entities_id' => 0, 'name' => 'inventory', 'method' => 'networkinventory', 'targets' => '[{"Printer":"' . $printers_id . '"}]', 'actors' => '[{"PluginFusioninventoryAgent":"1"}]');
     $pfTaskjob->add($input);
     PluginFusioninventoryTask::cronTaskscheduler();
     $data = $pfTask->getJoblogs(array(1));
     // Task is prepared
     // Agent will get data
     $communication->getTaskAgent(1);
     $message = $communication->getMessage();
     $json = json_encode($message);
     $array = json_decode($json, TRUE);
     $ref = array('OPTION' => array('NAME' => 'SNMPQUERY', 'PARAM' => array('@attributes' => array('THREADS_QUERY' => 1, 'TIMEOUT' => 0, 'PID' => 1)), 'DEVICE' => array('@attributes' => array('TYPE' => 'PRINTER', 'ID' => 1, 'IP' => '192.168.200.124', 'AUTHSNMP_ID' => 2)), 'AUTHENTICATION' => array(0 => array('@attributes' => array('ID' => 1, 'VERSION' => 1, 'COMMUNITY' => 'public')), 1 => array('@attributes' => array('ID' => 2, 'VERSION' => '2c', 'COMMUNITY' => 'public')))));
     $this->assertEquals($ref, $array, 'XML of SNMP inventory task');
 }
开发者ID:C-Duv,项目名称:fusioninventory-for-glpi,代码行数:48,代码来源:NetworkInventoryTest.php

示例7: Cisco1Unmanaged

 public function Cisco1Unmanaged()
 {
     global $DB;
     $DB->connect();
     self::restore_database();
     $a_lldp = array('ifdescr' => 'GigabitEthernet0/10', 'logical_number' => '', 'sysdescr' => '', 'model' => '', 'ip' => '192.168.200.124', 'mac' => '', 'name' => '');
     $pfINetworkEquipmentLib = new PluginFusioninventoryInventoryNetworkEquipmentLib();
     $networkEquipment = new NetworkEquipment();
     $networkport = new NetworkPort();
     $networkName = new NetworkName();
     $iPAddress = new IPAddress();
     $pfNetworkPort = new PluginFusioninventoryNetworkPort();
     $pfUnmanaged = new PluginFusioninventoryUnmanaged();
     // Nortel switch
     $networkequipments_id = $networkEquipment->add(array('name' => 'cisco1', 'entities_id' => 0));
     $networkports_id = $networkport->add(array('itemtype' => 'NetworkEquipment', 'items_id' => $networkequipments_id, 'entities_id' => 0));
     // Unmanaged
     $unmanageds_id = $pfUnmanaged->add(array('name' => 'otherswitch', 'entities_id' => 0));
     $networkports_unknown_id = $networkport->add(array('itemtype' => 'PluginFusioninventoryUnmanaged', 'items_id' => $unmanageds_id, 'entities_id' => 0));
     $networknames_id = $networkName->add(array('entities_id' => 0, 'itemtype' => 'NetworkPort', 'items_id' => $networkports_unknown_id));
     $iPAddress->add(array('entities_id' => 0, 'itemtype' => 'NetworkName', 'items_id' => $networknames_id, 'name' => '192.168.200.124'));
     $pfINetworkEquipmentLib->importConnectionLLDP($a_lldp, $networkports_id);
     $a_portslinks = getAllDatasFromTable('glpi_networkports_networkports');
     $this->assertEquals(1, count($a_portslinks), 'May have 1 connection between 2 network ports');
     $a_networkports = getAllDatasFromTable('glpi_networkports');
     $this->assertEquals(3, count($a_networkports), 'May have 3 network ports (' . print_r($a_networkports, TRUE) . ')');
     $a_unkowns = getAllDatasFromTable('glpi_plugin_fusioninventory_unmanageds');
     $this->assertEquals(1, count($a_unkowns), 'May have only one unknown device (' . print_r($a_unkowns, TRUE) . ')');
     $a_networkport_ref = array('id' => '3', 'items_id' => $unmanageds_id, 'itemtype' => 'PluginFusioninventoryUnmanaged', 'entities_id' => '0', 'is_recursive' => '0', 'logical_number' => '0', 'name' => 'GigabitEthernet0/10', 'instantiation_type' => 'NetworkPortEthernet', 'mac' => NULL, 'comment' => NULL, 'is_deleted' => '0', 'is_dynamic' => '0');
     $networkport->getFromDB(3);
     $this->assertEquals($a_networkport_ref, $networkport->fields, 'New unknown port created');
     $a_ref = array('id' => 1, 'networkports_id_1' => $networkports_id, 'networkports_id_2' => 3);
     $this->assertEquals($a_ref, current($a_portslinks), 'Link port');
 }
开发者ID:C-Duv,项目名称:fusioninventory-for-glpi,代码行数:34,代码来源:NetworkEquipmentLLDPTest.php

示例8: getPortIDfromDeviceIP

 function getPortIDfromDeviceIP($IP, $ifDescr, $sysdescr, $sysname, $model)
 {
     global $DB;
     $pfUnmanaged = new PluginFusioninventoryUnmanaged();
     $NetworkPort = new NetworkPort();
     $networkName = new NetworkName();
     $iPAddress = new IPAddress();
     $PortID = "";
     // search port have ifdescr + ip (in most cases not find it)
     $queryPort = "SELECT `glpi_networkports`.`id`\n                    FROM `glpi_plugin_fusioninventory_networkports`\n                    LEFT JOIN `glpi_networkports`\n                       ON `glpi_plugin_fusioninventory_networkports`.`networkports_id`=\n                          `glpi_networkports`.`id`\n                    LEFT JOIN `glpi_networknames`\n                       ON `glpi_networknames`.`items_id`=`glpi_networkports`.`id`\n                          AND `glpi_networknames`.`itemtype`='NetworkPort'\n                    LEFT JOIN `glpi_ipaddresses`\n                       ON `glpi_ipaddresses`.`items_id`=`glpi_networknames`.`id`\n                          AND `glpi_ipaddresses`.`itemtype`='NetworkName'\n\n                    WHERE (`ifdescr`='" . $ifDescr . "'\n                             OR `glpi_networkports`.`name`='" . $ifDescr . "')\n                          AND `glpi_networkports`.`itemtype`='NetworkEquipment'\n                          AND `glpi_ipaddresses`.`name`='" . $IP . "'";
     $resultPort = $DB->query($queryPort);
     if ($DB->numrows($resultPort) == 0) {
         // Search a management port of networkequipment have this IP
         $queryManagement = "SELECT `glpi_networkports`.`itemtype`,\n                        `glpi_networkports`.`items_id` FROM `glpi_networkports`\n                       LEFT JOIN `glpi_networknames`\n                          ON `glpi_networknames`.`items_id`=`glpi_networkports`.`id`\n                             AND `glpi_networknames`.`itemtype`='NetworkPort'\n                       LEFT JOIN `glpi_ipaddresses`\n                          ON `glpi_ipaddresses`.`items_id`=`glpi_networknames`.`id`\n                             AND `glpi_ipaddresses`.`itemtype`='NetworkName'\n\n                       WHERE `glpi_ipaddresses`.`name`='" . $IP . "'\n                          AND `instantiation_type`='NetworkPortAggregate'\n                       LIMIT 1";
         $resultManagement = $DB->query($queryManagement);
         if ($DB->numrows($resultManagement) == 1) {
             $dataManagement = $DB->fetch_assoc($resultManagement);
             // Seach a port have this ifdescr for this same networkequipment
             $queryPort = "SELECT `glpi_networkports`.`id`\n                          FROM `glpi_plugin_fusioninventory_networkports`\n                          LEFT JOIN `glpi_networkports`\n                             ON `glpi_plugin_fusioninventory_networkports`.`networkports_id`=\n                                `glpi_networkports`.`id`\n                          WHERE `glpi_networkports`.`itemtype`='" . $dataManagement['itemtype'] . "'\n                              AND `glpi_networkports`.`items_id`='" . $dataManagement['items_id'] . "'\n                              AND (`ifdescr`='" . $ifDescr . "'\n                                   OR `glpi_networkports`.`name`='" . $ifDescr . "')\n                          LIMIT 1";
             $resultPort = $DB->query($queryPort);
             if ($DB->numrows($resultPort) == 1) {
                 $dataPort = $DB->fetch_assoc($resultPort);
                 $PortID = $dataPort["id"];
             }
         }
     } else {
         $dataPort = $DB->fetch_assoc($resultPort);
         $PortID = $dataPort['id'];
     }
     // Detect IP Phone
     if ($PortID == "") {
         if (strstr($model, "Phone") || $model == '') {
             $queryPort = "SELECT glpi_networkports.* FROM `glpi_phones`\n                          LEFT JOIN `glpi_networkports`\n                             ON `glpi_phones`.`id`=`glpi_networkports`.`items_id`\n                          LEFT JOIN `glpi_networknames`\n                             ON `glpi_networknames`.`items_id`=`glpi_networkports`.`id`\n                                AND `glpi_networknames`.`itemtype`='NetworkPort'\n                          LEFT JOIN `glpi_ipaddresses`\n                             ON `glpi_ipaddresses`.`items_id`=`glpi_networknames`.`id`\n                                AND `glpi_ipaddresses`.`itemtype`='NetworkName'\n\n                          WHERE `glpi_ipaddresses`.`name`='" . $IP . "'\n                                AND `glpi_networkports`.`itemtype`='Phone'\n                                AND `glpi_phones`.`name`='" . $sysname . "'\n                          LIMIT 1";
             $resultPort = $DB->query($queryPort);
             if ($DB->numrows($resultPort) == 1) {
                 $dataPort = $DB->fetch_assoc($resultPort);
                 if (isset($dataPort['id'])) {
                     $PortID = $dataPort["id"];
                 }
             }
         }
     }
     if ($PortID == "") {
         $query = "SELECT * FROM `glpi_plugin_fusioninventory_unmanageds`\n            WHERE `ip`='" . $IP . "'\n            LIMIT 1";
         $result = $DB->query($query);
         if ($DB->numrows($result) == "1") {
             $data = $DB->fetch_assoc($result);
             // Search port and add if required
             $query1 = "SELECT *\n                FROM `glpi_networkports`\n                WHERE `itemtype`='PluginFusioninventoryUnmanaged'\n                   AND `items_id`='" . $data['id'] . "'\n                   AND `name`='" . $ifDescr . "'\n                LIMIT 1";
             $result1 = $DB->query($query1);
             if ($DB->numrows($result1) == "1") {
                 $data1 = $DB->fetch_assoc($result1);
                 $PortID = $data1['id'];
             } else {
                 // Add port
                 $input = array();
                 $input['items_id'] = $data['id'];
                 $input['itemtype'] = 'PluginFusioninventoryUnmanaged';
                 $input['ip'] = $IP;
                 $input['name'] = $ifDescr;
                 $input['instantiation_type'] = 'NetworkPortEthernet';
                 $PortID = $NetworkPort->add($input);
             }
             // Update unmanaged device
             $input = array();
             $input['id'] = $data['id'];
             $input['ip'] = $IP;
             if (strstr($model, "Phone")) {
                 $input['item_type'] = 'Phone';
             }
             if ($sysname != '') {
                 $input['name'] = $sysname;
             }
             if ($sysdescr != '') {
                 $input['sysdescr'] = $sysdescr;
             }
             $pfUnmanaged->update($input);
             return $PortID;
         }
         $query0 = "SELECT `glpi_networkports`.* FROM `glpi_networkports`\n             LEFT JOIN `glpi_networknames`\n                 ON `glpi_networknames`.`items_id`=`glpi_networkports`.`id`\n                    AND `glpi_networknames`.`itemtype`='NetworkPort'\n            LEFT JOIN `glpi_ipaddresses`\n                 ON `glpi_ipaddresses`.`items_id`=`glpi_networknames`.`id`\n                    AND `glpi_ipaddresses`.`itemtype`='NetworkName'\n\n             WHERE `glpi_networkports`.`itemtype`='PluginFusioninventoryUnmanaged'\n               AND `glpi_ipaddresses`.`name`='" . $IP . "'\n             LIMIT 1";
         $result0 = $DB->query($query0);
         if ($DB->numrows($result0) == 1) {
             $data0 = $DB->fetch_assoc($result0);
             // Search port and add if required
             $query1 = "SELECT *\n                FROM `glpi_networkports`\n                WHERE `itemtype`='PluginFusioninventoryUnmanaged'\n                   AND `items_id`='" . $data0['items_id'] . "'\n                   AND `name`='" . $ifDescr . "'\n                LIMIT 1";
             $result1 = $DB->query($query1);
             if ($DB->numrows($result1) == "1") {
                 $data1 = $DB->fetch_assoc($result1);
                 $PortID = $data1['id'];
             } else {
                 // Add port
                 $input = array();
                 $input['items_id'] = $data0['items_id'];
                 $input['itemtype'] = 'PluginFusioninventoryUnmanaged';
                 $input['name'] = $ifDescr;
                 $input['instantiation_type'] = 'NetworkPortEthernet';
                 $PortID = $NetworkPort->add($input);
                 $input = array();
                 $input['itemtype'] = 'NetworkPort';
                 $input['items_id'] = $PortID;
//.........这里部分代码省略.........
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:101,代码来源:networkport.class.php

示例9: manageNetworkPort

 function manageNetworkPort($inventory_networkports, $computers_id, $no_history)
 {
     global $DB;
     $networkPort = new NetworkPort();
     $networkName = new NetworkName();
     $iPAddress = new IPAddress();
     $iPNetwork = new IPNetwork();
     $networkPortEthernet = new NetworkPortEthernet();
     $item_DeviceNetworkCard = new Item_DeviceNetworkCard();
     foreach ($inventory_networkports as $a_networkport) {
         if ($a_networkport['mac'] != '') {
             $a_networkports = $networkPort->find("`mac`='" . $a_networkport['mac'] . "'\n               AND `itemtype`='PluginFusioninventoryUnmanaged'", "", 1);
             if (count($a_networkports) > 0) {
                 $input = current($a_networkports);
                 $unmanageds_id = $input['items_id'];
                 $input['logical_number'] = $a_networkport['logical_number'];
                 $input['itemtype'] = 'Computer';
                 $input['items_id'] = $computers_id;
                 $input['is_dynamic'] = 1;
                 $input['name'] = $a_networkport['name'];
                 $networkPort->update($input, !$no_history);
                 $pfUnmanaged = new PluginFusioninventoryUnmanaged();
                 $pfUnmanaged->delete(array('id' => $unmanageds_id), 1);
             }
         }
     }
     // end get port from unknwon device
     $db_networkport = array();
     if ($no_history === FALSE) {
         $query = "SELECT `id`, `name`, `mac`, `instantiation_type`, `logical_number`\n             FROM `glpi_networkports`\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 (is_null($data['mac'])) {
                 $data['mac'] = '';
             }
             if (preg_match("/[^a-zA-Z0-9 \\-_\\(\\)]+/", $data['name'])) {
                 $data['name'] = Toolbox::addslashes_deep($data['name']);
             }
             $db_networkport[$idtmp] = array_map('strtolower', $data);
         }
     }
     $simplenetworkport = array();
     foreach ($inventory_networkports as $key => $a_networkport) {
         // Add ipnetwork if not exist
         if ($a_networkport['gateway'] != '' && $a_networkport['netmask'] != '' && $a_networkport['subnet'] != '') {
             if (countElementsInTable('glpi_ipnetworks', "`address`='" . $a_networkport['subnet'] . "'\n                                     AND `netmask`='" . $a_networkport['netmask'] . "'\n                                     AND `gateway`='" . $a_networkport['gateway'] . "'\n                                     AND `entities_id`='" . $_SESSION["plugin_fusioninventory_entity"] . "'") == 0) {
                 $input_ipanetwork = array('name' => $a_networkport['subnet'] . '/' . $a_networkport['netmask'] . ' - ' . $a_networkport['gateway'], 'network' => $a_networkport['subnet'] . ' / ' . $a_networkport['netmask'], 'gateway' => $a_networkport['gateway'], 'entities_id' => $_SESSION["plugin_fusioninventory_entity"]);
                 $iPNetwork->add($input_ipanetwork, array(), !$no_history);
             }
         }
         // End add ipnetwork
         $a_field = array('name', 'mac', 'instantiation_type');
         foreach ($a_field as $field) {
             if (isset($a_networkport[$field])) {
                 $simplenetworkport[$key][$field] = $a_networkport[$field];
             }
         }
     }
     foreach ($simplenetworkport as $key => $arrays) {
         $arrayslower = array_map('strtolower', $arrays);
         foreach ($db_networkport as $keydb => $arraydb) {
             $logical_number = $arraydb['logical_number'];
             unset($arraydb['logical_number']);
             if ($arrayslower == $arraydb) {
                 if ($inventory_networkports[$key]['logical_number'] != $logical_number) {
                     $input = array();
                     $input['id'] = $keydb;
                     $input['logical_number'] = $inventory_networkports[$key]['logical_number'];
                     $networkPort->update($input, !$no_history);
                 }
                 // Add / update instantiation_type
                 if (isset($inventory_networkports[$key]['instantiation_type'])) {
                     if ($inventory_networkports[$key]['instantiation_type'] == 'NetworkPortEthernet') {
                         $portsethernet = $networkPortEthernet->find("`networkports_id`='" . $keydb . "'", '', 1);
                         if (count($portsethernet) == 1) {
                             $portethernet = current($portsethernet);
                             $input = $portethernet;
                         } else {
                             $input = array('networkports_id' => $keydb);
                         }
                         if (isset($inventory_networkports[$key]['speed'])) {
                             $input['speed'] = $inventory_networkports[$key]['speed'];
                             $input['speed_other_value'] = $inventory_networkports[$key]['speed'];
                         }
                         if (isset($inventory_networkports[$key]['mac'])) {
                             $networkcards = $item_DeviceNetworkCard->find("`mac`='" . $inventory_networkports[$key]['mac'] . "' " . " AND `itemtype`='Computer'" . " AND `items_id`='" . $computers_id . "'", '', 1);
                             if (count($networkcards) == 1) {
                                 $networkcard = current($networkcards);
                                 $input['items_devicenetworkcards_id'] = $networkcard['id'];
                             }
                         }
                         $input['_no_history'] = $no_history;
                         if (isset($input['id'])) {
                             $networkPortEthernet->update($input);
                         } else {
                             $networkPortEthernet->add($input);
                         }
                     }
//.........这里部分代码省略.........
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:101,代码来源:inventorycomputerlib.class.php

示例10: processAfterInsertOrUpdate

 /**
  * @param $values
  * @param $add                   (true by default)
  * @param $rights    array
  */
 function processAfterInsertOrUpdate($values, $add = true, $rights = array())
 {
     global $DB;
     //Manage ip adresses
     if (isset($values['NetworkName']['ipaddresses_id'])) {
         if (!countElementsInTable("glpi_ipaddresses", "`items_id`='" . $values['NetworkName']['id'] . "'\n                                       AND `itemtype`='NetworkName'\n                                       AND `name`='" . $values['NetworkName']['ipaddresses_id'] . "'")) {
             $ip = new IPAddress();
             $tmp['items_id'] = $values['NetworkName']['id'];
             $tmp['itemtype'] = "NetworkName";
             $tmp['name'] = $values['NetworkName']['ipaddresses_id'];
             $tmp['is_dynamic'] = 0;
             $ip->add($tmp);
         }
     }
 }
开发者ID:JULIO8,项目名称:respaldo_glpi,代码行数:20,代码来源:networknameinjection.class.php

示例11: internalPorts

 /**
  * Import IPs
  *
  * @param $p_ips IPs code to import
  * @param $networkequipments_id id of network equipment
  *
  * @return errors string to be alimented if import ko / '' if ok
  **/
 function internalPorts($a_ips, $networkequipments_id, $mac, $networkname_name)
 {
     $networkPort = new NetworkPort();
     $iPAddress = new IPAddress();
     $pfUnmanaged = new PluginFusioninventoryUnmanaged();
     $networkName = new NetworkName();
     // Get agregated ports
     $a_networkPortAggregates = current($networkPort->find("`itemtype`='NetworkEquipment'\n                       AND `items_id`='" . $networkequipments_id . "'\n                       AND `instantiation_type`='NetworkPortAggregate'\n                       AND `logical_number` = '0'", '', 1));
     $a_ips_DB = array();
     $networkports_id = 0;
     if (isset($a_networkPortAggregates['id'])) {
         $a_networkPortAggregates['mac'] = $mac;
         $networkPort->update($a_networkPortAggregates);
         $networkports_id = $a_networkPortAggregates['id'];
     } else {
         $input = array();
         $input['itemtype'] = 'NetworkEquipment';
         $input['items_id'] = $networkequipments_id;
         $input['instantiation_type'] = 'NetworkPortAggregate';
         $input['name'] = 'general';
         $input['mac'] = $mac;
         $networkports_id = $networkPort->add($input);
     }
     // Get networkname
     $a_networknames_find = current($networkName->find("`items_id`='" . $networkports_id . "'\n                                                         AND `itemtype`='NetworkPort'", "", 1));
     $networknames_id = 0;
     if (isset($a_networknames_find['id'])) {
         $networknames_id = $a_networknames_find['id'];
         $a_networknames_find['name'] = $networkname_name;
         $networkName->update($a_networknames_find);
     } else {
         $input = array();
         $input['items_id'] = $networkports_id;
         $input['itemtype'] = 'NetworkPort';
         $input['name'] = $networkname_name;
         $networknames_id = $networkName->add($input);
     }
     $a_ips_fromDB = $iPAddress->find("`itemtype`='NetworkName'\n                                    AND `items_id`='" . $networknames_id . "'");
     foreach ($a_ips_fromDB as $data) {
         $a_ips_DB[$data['id']] = $data['name'];
     }
     foreach ($a_ips as $key => $ip) {
         foreach ($a_ips_DB as $keydb => $ipdb) {
             if ($ip == $ipdb) {
                 unset($a_ips[$key]);
                 unset($a_ips_DB[$keydb]);
                 break;
             }
         }
     }
     if (count($a_ips) == 0 and count($a_ips_DB) == 0) {
         // Nothing to do
     } else {
         if (count($a_ips_DB) != 0 && count($a_ips) != 0) {
             // Delete IPs in DB
             foreach ($a_ips_DB as $idtmp => $ip) {
                 $iPAddress->delete(array('id' => $idtmp));
             }
         }
         if (count($a_ips) != 0) {
             foreach ($a_ips as $ip) {
                 if ($ip != '127.0.0.1') {
                     $input = array();
                     $input['entities_id'] = 0;
                     $input['itemtype'] = 'NetworkName';
                     $input['items_id'] = $networknames_id;
                     $input['name'] = $ip;
                     $iPAddress->add($input);
                     // Search in unmanaged device if device with IP (LLDP) is yet added, in this case,
                     // we get id of this unmanaged device
                     $a_manageds = $pfUnmanaged->find("`ip`='" . $ip . "'", "", 1);
                     if (count($a_manageds) > 0) {
                         $datas = current($a_unmanageds);
                         $this->unmanagedCDP = $datas['id'];
                     }
                 }
             }
         }
     }
 }
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:88,代码来源:inventorynetworkequipmentlib.class.php


注:本文中的IPAddress::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。