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


PHP NetworkPort::add方法代码示例

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


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

示例1: testAddCompleteNetworkPort

 /**
  * @covers NetworkPort::prepareInputForAdd
  * @covers NetworkPort::post_addItem
  */
 public function testAddCompleteNetworkPort()
 {
     $this->Login();
     $computer1 = getItemByTypeName('Computer', '_test_pc01');
     // Do some installations
     $ins = new NetworkPort();
     // Be sure added
     $nb_log = countElementsInTable('glpi_logs');
     $this->assertGreaterThan(0, $ins->add(['items_id' => $computer1->getID(), 'itemtype' => 'Computer', 'entities_id' => $computer1->fields['entities_id'], 'is_recursive' => 0, 'logical_number' => 3, 'mac' => '00:24:81:eb:c6:d2', 'instantiation_type' => 'NetworkPortEthernet', 'name' => 'em3', 'comment' => 'Comment me!', 'netpoints_id' => 0, 'items_devicenetworkcards_id' => 0, 'type' => 'T', 'speed' => 1000, 'speed_other_value' => '', 'NetworkName_name' => 'test1.me', 'NetworkName_fqdns_id' => 0, 'NetworkName__ipaddresses' => ['-1' => '192.168.20.1']]));
     $this->assertGreaterThan($nb_log, countElementsInTable('glpi_logs'));
     // be sure added and have no logs
     $nb_log = countElementsInTable('glpi_logs');
     $this->assertGreaterThan(0, $ins->add(['items_id' => $computer1->getID(), 'itemtype' => 'Computer', 'entities_id' => $computer1->fields['entities_id'], 'is_recursive' => 0, 'logical_number' => 4, 'mac' => '00:24:81:eb:c6:d4', 'instantiation_type' => 'NetworkPortEthernet', 'name' => 'em4', 'comment' => 'Comment me!', 'netpoints_id' => 0, 'items_devicenetworkcards_id' => 0, 'type' => 'T', 'speed' => 1000, 'speed_other_value' => '', 'NetworkName_name' => 'test2.me', 'NetworkName_fqdns_id' => 0, 'NetworkName__ipaddresses' => ['-1' => '192.168.20.2']], [], false));
     $this->assertEquals($nb_log, countElementsInTable('glpi_logs'));
 }
开发者ID:btry,项目名称:glpi,代码行数:19,代码来源:NetworkportTest.php

示例2: 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

示例3: testAddCompleteNetworkPort

 /**
  * @covers NetworkPort::prepareInputForAdd
  * @covers NetworkPort::post_addItem
  */
 public function testAddCompleteNetworkPort()
 {
     $this->Login();
     $computer1 = getItemByTypeName('Computer', '_test_pc01');
     // Do some installations
     $networkport = new NetworkPort();
     // Be sure added
     $nb_log = countElementsInTable('glpi_logs');
     $new_id = $networkport->add(['items_id' => $computer1->getID(), 'itemtype' => 'Computer', 'entities_id' => $computer1->fields['entities_id'], 'is_recursive' => 0, 'logical_number' => 3, 'mac' => '00:24:81:eb:c6:d2', 'instantiation_type' => 'NetworkPortEthernet', 'name' => 'em3', 'comment' => 'Comment me!', 'netpoints_id' => 0, 'items_devicenetworkcards_id' => 0, 'type' => 'T', 'speed' => 1000, 'speed_other_value' => '', 'NetworkName_name' => 'test1', 'NetworkName_comment' => 'test1 comment', 'NetworkName_fqdns_id' => 0, 'NetworkName__ipaddresses' => ['-1' => '192.168.20.1'], '_create_children' => true]);
     $this->assertGreaterThan(0, $new_id);
     $this->assertGreaterThan($nb_log, countElementsInTable('glpi_logs'));
     // check data in db
     // 1 -> NetworkPortEthernet
     $all_netportethernets = getAllDatasFromTable('glpi_networkportethernets', '', false, 'id');
     $networkportethernet = end($all_netportethernets);
     unset($networkportethernet['id']);
     unset($networkportethernet['date_mod']);
     unset($networkportethernet['date_creation']);
     $expected = ['networkports_id' => $new_id, 'items_devicenetworkcards_id' => '0', 'netpoints_id' => '0', 'type' => 'T', 'speed' => '1000'];
     $this->assertEquals($expected, $networkportethernet);
     // 2 -> NetworkName
     $all_networknames = getAllDatasFromTable('glpi_networknames', '', false, 'id');
     $networkname = end($all_networknames);
     $networknames_id = $networkname['id'];
     unset($networkname['id']);
     unset($networkname['date_mod']);
     unset($networkname['date_creation']);
     $expected = ['entities_id' => $computer1->fields['entities_id'], 'items_id' => $new_id, 'itemtype' => 'NetworkPort', 'name' => 'test1', 'comment' => 'test1 comment', 'fqdns_id' => 0, 'is_deleted' => 0, 'is_dynamic' => 0];
     $this->assertEquals($expected, $networkname);
     // 3 -> IPAddress
     $all_ipadresses = getAllDatasFromTable('glpi_ipaddresses', '', false, 'id');
     $ipadress = end($all_ipadresses);
     unset($ipadress['id']);
     unset($ipadress['date_mod']);
     unset($ipadress['date_creation']);
     $expected = ['entities_id' => $computer1->fields['entities_id'], 'items_id' => $networknames_id, 'itemtype' => 'NetworkName', 'version' => '4', 'name' => '192.168.20.1', 'binary_0' => '0', 'binary_1' => '0', 'binary_2' => '65535', 'binary_3' => '3232240641', 'is_deleted' => '0', 'is_dynamic' => '0', 'mainitems_id' => $computer1->getID(), 'mainitemtype' => 'Computer'];
     $this->assertEquals($expected, $ipadress);
     // be sure added and have no logs
     $nb_log = countElementsInTable('glpi_logs');
     $new_id = $networkport->add(['items_id' => $computer1->getID(), 'itemtype' => 'Computer', 'entities_id' => $computer1->fields['entities_id'], 'is_recursive' => 0, 'logical_number' => 4, 'mac' => '00:24:81:eb:c6:d4', 'instantiation_type' => 'NetworkPortEthernet', 'name' => 'em4', 'comment' => 'Comment me!', 'netpoints_id' => 0, 'items_devicenetworkcards_id' => 0, 'type' => 'T', 'speed' => 1000, 'speed_other_value' => '', 'NetworkName_name' => 'test2', 'NetworkName_fqdns_id' => 0, 'NetworkName__ipaddresses' => ['-1' => '192.168.20.2']], [], false);
     $this->assertGreaterThan(0, $new_id);
     $this->assertEquals($nb_log, countElementsInTable('glpi_logs'));
 }
开发者ID:glpi-project,项目名称:glpi,代码行数:47,代码来源:NetworkportTest.php

示例4: PrinterToInventoryWithoutIP

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

示例5: Cisco2Switch

 /**
  * @test
  */
 public function Cisco2Switch()
 {
     global $DB;
     $DB->connect();
     self::restore_database();
     $a_lldp = array('ifdescr' => 'ge-0/0/1.0', 'logical_number' => '504', 'sysdescr' => 'Juniper Networks, Inc. ex2200-24t-4g , version 10.1R1.8 Build date: 2010-02-12 16:59:31 UTC ', 'model' => '', 'ip' => '', 'mac' => '2c:6b:f5:98:f9:70', 'name' => 'juniperswitch3');
     $pfINetworkEquipmentLib = new PluginFusioninventoryInventoryNetworkEquipmentLib();
     $networkEquipment = new NetworkEquipment();
     $networkport = new NetworkPort();
     $pfNetworkPort = new PluginFusioninventoryNetworkPort();
     // Cisco switch
     $networkequipments_id = $networkEquipment->add(array('name' => 'cisco2', 'entities_id' => 0));
     $networkports_id = $networkport->add(array('itemtype' => 'NetworkEquipment', 'items_id' => $networkequipments_id, 'entities_id' => 0));
     // Another switch
     $networkequipments_other_id = $networkEquipment->add(array('name' => 'juniperswitch3', 'entities_id' => 0));
     // Port ge-0/0/1.0
     $networkports_other_id = $networkport->add(array('itemtype' => 'NetworkEquipment', 'items_id' => $networkequipments_other_id, 'entities_id' => 0, 'mac' => '2c:6b:f5:98:f9:70', 'logical_number' => 504));
     $pfNetworkPort->add(array('networkports_id' => $networkports_other_id, 'ifdescr' => 'ge-0/0/1.0'));
     $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(2, count($a_networkports), 'May have 2 network ports (' . print_r($a_networkports, TRUE) . ')');
     $a_ref = array('id' => 1, 'networkports_id_1' => $networkports_id, 'networkports_id_2' => $networkports_other_id);
     $this->assertEquals($a_ref, current($a_portslinks), 'Link port');
 }
开发者ID:C-Duv,项目名称:fusioninventory-for-glpi,代码行数:29,代码来源:NetworkEquipmentLLDPTest.php

示例6: unset

$npv = new NetworkPort_Vlan();
if (!isset($_GET["id"])) {
    $_GET["id"] = "";
}
if (isset($_POST["add"])) {
    // Is a preselected mac adress selected ?
    if (isset($_POST['pre_mac'])) {
        if (!empty($_POST['pre_mac'])) {
            $_POST['mac'] = $_POST['pre_mac'];
        }
        unset($_POST['pre_mac']);
    }
    if (!isset($_POST["several"])) {
        $np->check(-1, 'w', $_POST);
        $np->splitInputForElements($_POST);
        $newID = $np->add($_POST);
        $np->updateDependencies(1);
        Event::log($newID, "networkport", 5, "inventory", sprintf(__('%s adds an item'), $_SESSION["glpiname"]));
        Html::back();
    } else {
        Session::checkRight("networking", "w");
        $input = $_POST;
        unset($input['several']);
        unset($input['from_logical_number']);
        unset($input['to_logical_number']);
        for ($i = $_POST["from_logical_number"]; $i <= $_POST["to_logical_number"]; $i++) {
            $add = "";
            if ($i < 10) {
                $add = "0";
            }
            $input["logical_number"] = $i;
开发者ID:geldarr,项目名称:hack-space,代码行数:31,代码来源:networkport.form.php

示例7: getPortIDfromSysmacandPortnumber

 function getPortIDfromSysmacandPortnumber($sysmac, $ifnumber, $params = array())
 {
     global $DB;
     $PortID = '';
     $queryPort = "SELECT *\n         FROM `glpi_networkports`\n         WHERE `mac`='" . $sysmac . "'\n            AND `itemtype`='NetworkEquipment'\n            AND `logical_number`='" . $ifnumber . "'\n         LIMIT 1";
     $resultPort = $DB->query($queryPort);
     if ($DB->numrows($resultPort) == "1") {
         $dataPort = $DB->fetch_assoc($resultPort);
         $PortID = $dataPort['id'];
     }
     if ($PortID == '') {
         // case where mac is of switch and not of the port (like Procurve)
         $queryPort = "SELECT *\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_networkequipments`\n               ON `glpi_networkports`.`items_id`=\n                  `glpi_networkequipments`.`id`\n            WHERE `glpi_networkports`.`mac`='" . $sysmac . "'\n               AND `glpi_networkports`.`itemtype`='NetworkEquipment'\n               AND `logical_number`='" . $ifnumber . "'\n            LIMIT 1";
         $resultPort = $DB->query($queryPort);
         $dataPort = $DB->fetch_assoc($resultPort);
         if ($DB->numrows($resultPort) == "1") {
             $PortID = $dataPort['networkports_id'];
         }
     }
     // In case of mac is mac of switch, not a port
     if ($PortID == '') {
         $queryPort = "SELECT *\n            FROM `glpi_networkports`\n            WHERE `logical_number`='" . $ifnumber . "'\n               AND `itemtype`='NetworkEquipment'\n               AND `items_id` IN\n               (SELECT `items_id`\n                FROM `glpi_networkports`\n                WHERE `instantiation_type`='NetworkPortAggregate'\n                  AND `mac`='" . $sysmac . "')\n            LIMIT 1";
         $resultPort = $DB->query($queryPort);
         $dataPort = $DB->fetch_assoc($resultPort);
         if (isset($dataPort['id'])) {
             $PortID = $dataPort['id'];
         }
     }
     if ($PortID == "") {
         $NetworkPort = new NetworkPort();
         $PluginFusioninventoryUnmanaged = new PluginFusioninventoryUnmanaged();
         $query = "SELECT *\n             FROM `glpi_networkports`\n             WHERE `itemtype`='PluginFusioninventoryUnmanaged'\n               AND `mac`='" . $sysmac . "'\n             LIMIT 1";
         $result = $DB->query($query);
         if ($DB->numrows($result) == "1") {
             $data = $DB->fetch_assoc($result);
             return $data['id'];
         }
         // Add unmanaged device because not find device
         $input = array();
         $input['mac'] = $sysmac;
         if (isset($params['sysname'])) {
             $input['name'] = $params['sysname'];
         }
         if (isset($_SESSION["plugin_fusioninventory_entity"])) {
             $input['entities_id'] = $_SESSION["plugin_fusioninventory_entity"];
         }
         if (isset($params['sysdescr'])) {
             $input['sysdescr'] = $params['sysdescr'];
         }
         $unkonwn_id = $PluginFusioninventoryUnmanaged->add($input);
         // Add port
         $input = array();
         $input['items_id'] = $unkonwn_id;
         $input['itemtype'] = 'PluginFusioninventoryUnmanaged';
         $input['mac'] = $sysmac;
         if (isset($params['ifdescr'])) {
             $input['name'] = $params['ifdescr'];
         }
         $input['instantiation_type'] = 'NetworkPortEthernet';
         $PortID = $NetworkPort->add($input);
         return $PortID;
     }
     return $PortID;
 }
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:64,代码来源:networkport.class.php

示例8: 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

示例9: addNetworkEthernetPort

/**  Generate bigdump : Create networkport ethernet
 *
 * @since version 0.84
 *
 * @param $itemtype        item type
 * @param $items_id        item ID
 * @param $entities_id     item entity ID
 * @param $locations_id    ID of the location trying to link with network equipment (default 0)
**/
function addNetworkEthernetPort($itemtype, $items_id, $entities_id, $locations_id=0) {
   global $NET_LOC, $NET_PORT, $MAX, $VLAN_LOC;

   // Add networking ports
   $newIP   = getNextIP();
   $newMAC  = getNextMAC();

   if (($itemtype == 'NetworkEquipment') && $locations_id) {
      // Find father locations_id;
      $loc = new Location();
      if ($loc->getFromDB($locations_id)) {
         $locations_id = $loc->getField('locations_id');
      } else {
         $locations_id = 0;
      }
   }

   //insert netpoint
   $netpoint   = new NetPoint();
   $netpointID = $netpoint->add(toolbox::addslashes_deep(
                                array('entities_id'  => $entities_id,
                                      'locations_id' => $locations_id,
                                      'name'         => getNextNETPOINT(),
                                      'comment'      => "comment 'netpoint $locations_id")));

   if ($locations_id && !isset($VLAN_LOC[$locations_id])) {
      $vlanID                  = mt_rand(1,$MAX["vlan"]);
      $VLAN_LOC[$locations_id] = $vlanID;
   }
   if (!isset($NET_PORT[$itemtype][$items_id])) {
      $NET_PORT[$itemtype][$items_id]=0;
   }
   $np          = new NetworkPort();
   $nv          = new NetworkPort_Vlan();
   $newportname = "port of $itemtype-$items_id";
   $refportID   = 0;

   if ($locations_id && isset($NET_LOC[$locations_id]) && $NET_LOC[$locations_id]) {
      $refportname  = "link 'port to  $itemtype-$items_id";
      $newportname .= " link to 'NetworkEquipment' -".$NET_LOC[$locations_id];
      $newMAC2      = getNextMAC();
      $newIP2      = getNextIP();

      // Create new port on ref item
      $param = toolbox::addslashes_deep(
               array('itemtype'                 => 'NetworkEquipment',
                     'items_id'                 => $NET_LOC[$locations_id],
                     'entities_id'              => $entities_id,
                     'logical_number'  => $NET_PORT['NetworkEquipment'][$NET_LOC[$locations_id]]++,
                     'name'                     => "name '$refportname",
                     'instantiation_type'       => 'NetworkPortEthernet',
                     'mac'                      => $newMAC2,
                     'comment'                  => "comment '$refportname",
                     'netpoints_id'             => $netpointID,
                     'NetworkName_name'         => "NetworkEquipment$itemtype-$items_id-$entities_id",
                     'NetworkName__ipaddresses' => array(-100 => $newIP2['ip']),
                     ));

                     $np->splitInputForElements($param);
      $refportID = $np->add($param);
      $np->updateDependencies(1);
      if (isset($VLAN_LOC[$locations_id]) && $refportID) {
         $nv->add(array('networkports_id' => $refportID,
                        'vlans_id'        => $VLAN_LOC[$locations_id]));
      }
   }

//    $query = "INSERT INTO `glpi_networkports`
//                VALUES (NULL, '$netwID', 'NetworkEquipment', '$ID_entity', '0',
//                      '".$NET_PORT['NetworkEquipment'][$netwID]++."',
//                      'link port to netw ".$NET_LOC[$data['locations_id']]."',
//                      '".$newIP['ip']."', '$newMAC', '$iface', '$netpointID',
//                      '".$newIP['netwmask']."', '".$newIP['gateway']."',
//                      '".$newIP['subnet']."','comment')";
//    $DB->query($query) or die("PB REQUETE ".$query);

   $param = toolbox::addslashes_deep(
            array('itemtype'                 => $itemtype,
                  'items_id'                 => $items_id,
                  'entities_id'              => $entities_id,
                  'logical_number'           => $NET_PORT[$itemtype][$items_id]++,
                  'name'                     => "name '$newportname",
                  'instantiation_type'       => 'NetworkPortEthernet',
                  'mac'                      => $newMAC,
                  'comment'                  => "comment '$newportname",
                  'netpoints_id'             => $netpointID,
                  'NetworkName_name'         => "$itemtype-$items_id-$entities_id",
                  'NetworkName__ipaddresses' => array(-100 => $newIP['ip']),
                  ));

                  $np->splitInputForElements($param);
//.........这里部分代码省略.........
开发者ID:KaneoGmbH,项目名称:glpi,代码行数:101,代码来源:generate_bigdump.function.php

示例10: unset

$nn = new NetworkPort_NetworkPort();
$npv = new NetworkPort_Vlan();
if (!isset($_GET["id"])) {
    $_GET["id"] = "";
}
if (isset($_POST["add"])) {
    // Is a preselected mac adress selected ?
    if (isset($_POST['pre_mac'])) {
        if (!empty($_POST['pre_mac'])) {
            $_POST['mac'] = $_POST['pre_mac'];
        }
        unset($_POST['pre_mac']);
    }
    if (!isset($_POST["several"])) {
        $np->check(-1, 'w', $_POST);
        $np->add($_POST);
        Event::log(0, "networkport", 5, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][70]);
        glpi_header($_SERVER['HTTP_REFERER']);
    } else {
        checkRight("networking", "w");
        $input = $_POST;
        unset($input['several']);
        unset($input['from_logical_number']);
        unset($input['to_logical_number']);
        for ($i = $_POST["from_logical_number"]; $i <= $_POST["to_logical_number"]; $i++) {
            $add = "";
            if ($i < 10) {
                $add = "0";
            }
            $input["logical_number"] = $i;
            $input["name"] = $_POST["name"] . $add . $i;
开发者ID:ryukansent,项目名称:Thesis-SideB,代码行数:31,代码来源:networkport.form.php

示例11: processAfterInsertOrUpdate

 /**
  * @param $values
  * @param $add                (true by default)
  * @param $rights    array
  */
 function processAfterInsertOrUpdate($values, $add = true, $rights = array())
 {
     if (isset($values['NetworkEquipment']['nb_ports'])) {
         for ($i = 1; $i <= $values['NetworkEquipment']['nb_ports']; $i++) {
             $input = array();
             $netport = new NetworkPort();
             $add = "";
             if ($i < 10) {
                 $add = "0";
             }
             $input["logical_number"] = $i;
             $input["name"] = $add . $i;
             $input["items_id"] = $values['NetworkEquipment']['id'];
             $input["itemtype"] = 'NetworkEquipment';
             $input["entities_id"] = $values['NetworkEquipment']['entities_id'];
             $netport->add($input);
         }
     }
 }
开发者ID:JULIO8,项目名称:respaldo_glpi,代码行数:24,代码来源:networkequipmentinjection.class.php

示例12: importPortAggregate

 function importPortAggregate($a_ports, $networkports_id, $networkequipments_id)
 {
     $networkPort = new NetworkPort();
     $networkPortAggregate = new NetworkPortAggregate();
     $a_aggregates = $networkPortAggregate->find("`networkports_id`='" . $networkports_id . "'", "", 1);
     $input = array();
     if (count($a_aggregates) == 1) {
         $input = current($a_aggregates);
     } else {
         $input['networkports_id'] = $networkports_id;
         $input['networkports_id_list'] = exportArrayToDB(array());
         $input['id'] = $networkPortAggregate->add($input);
     }
     $a_ports_db_tmp = array();
     foreach ($a_ports as $logical_number) {
         $a_networkports_DB = current($networkPort->find("`itemtype`='NetworkEquipment'\n                       AND `items_id`='" . $networkequipments_id . "'\n                       AND `instantiation_type`='NetworkPortEthernet'\n                       AND `logical_number` = '" . $logical_number . "'", '', 1));
         if (!isset($a_networkports_DB['id'])) {
             // Add port
             $a_port['instantiation_type'] = 'NetworkPortEthernet';
             $a_port['items_id'] = $networkequipments_id;
             $a_port['itemtype'] = 'NetworkEquipment';
             $a_port['logical_number'] = $logical_number;
             $networkports_id = $networkPort->add($a_port);
         } else {
             $networkports_id = $a_networkports_DB['id'];
         }
         $a_ports_db_tmp[] = $networkports_id;
     }
     $input['networkports_id_list'] = $a_ports_db_tmp;
     $networkPortAggregate->update($input);
 }
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:31,代码来源:inventorynetworkequipmentlib.class.php

示例13: importIpDiscover

 /**
  * import ipdiscover object
  * @param type $ipDiscoveryObject array
  * @param type $plugin_ocsinventoryng_ocsservers_id integer
  * @param $subnet
  * @return array
  */
 static function importIpDiscover($ipDiscoveryObject, $plugin_ocsinventoryng_ocsservers_id, $subnet)
 {
     global $DB;
     $id = null;
     $identify = false;
     $cfg_ocs = PluginOcsinventoryngOcsServer::getConfig($plugin_ocsinventoryng_ocsservers_id);
     if (isset($ipDiscoveryObject["ocsItemType"]) && $ipDiscoveryObject["ocsItemType"] == Dropdown::EMPTY_VALUE) {
         return array('status' => PluginOcsinventoryngOcsServer::IPDISCOVER_FAILED_IMPORT);
     }
     if ($ipDiscoveryObject["itemDescription"] == '') {
         return array('status' => PluginOcsinventoryngOcsServer::IPDISCOVER_FAILED_IMPORT);
     }
     if ($ipDiscoveryObject["itemName"] == "") {
         $ipDiscoveryObject["itemName"] = $ipDiscoveryObject["itemDescription"];
     }
     switch ($ipDiscoveryObject["glpiItemType"]) {
         //empty dropdown value
         case '0':
             return array('status' => PluginOcsinventoryngOcsServer::IPDISCOVER_FAILED_IMPORT);
     }
     if (isset($ipDiscoveryObject["ocsItemType"])) {
         $identify = true;
     }
     $mac = $ipDiscoveryObject["macAdress"];
     $netPort = new NetworkPort();
     $netPort->getFromDBByQuery("WHERE `mac` = '{$mac}' ");
     if (count($netPort->fields) < 1) {
         $input = array('is_dynamic' => 1, 'locations_id' => 0, 'domains_id' => 0, 'entities_id' => $ipDiscoveryObject["entity"], 'name' => $ipDiscoveryObject["itemName"], 'comment' => $ipDiscoveryObject["itemDescription"]);
         $device = new $ipDiscoveryObject["glpiItemType"]();
         $id = $device->add($input, array(), $cfg_ocs['history_devices']);
         //ipdiscover link
         $date = date("Y-m-d H:i:s");
         $glpiType = $ipDiscoveryObject["glpiItemType"];
         $ip = $ipDiscoveryObject["itemIp"];
         $glpiQuery = "INSERT INTO `glpi_plugin_ocsinventoryng_ipdiscoverocslinks`\n                       (`items_id`,`itemtype`,`macaddress`,`last_update`,`subnet`,`plugin_ocsinventoryng_ocsservers_id`)\n                       VALUES('{$id}','{$glpiType}','{$mac}','{$date}','{$subnet}','{$plugin_ocsinventoryng_ocsservers_id}')";
         $DB->query($glpiQuery);
         //add port
         $port_input = array('name' => $ipDiscoveryObject["itemName"] . "-" . $ip, 'mac' => $mac, 'items_id' => $id, 'itemtype' => $glpiType, 'instantiation_type' => "NetworkPortEthernet", "entities_id" => $ipDiscoveryObject["entity"], "NetworkName__ipaddresses" => array("-100" => $ip), '_create_children' => 1, 'is_deleted' => 0);
         $netPort->add($port_input, array(), $cfg_ocs['history_network']);
         /* $netPortInput = array(
                       "itemtype"           => $glpiType,
                       "items_id"           => $id,
                       'entities_id'        => $ipDiscoveryObject["entity"],
                       "name"               => $ipDiscoveryObject["itemName"] . "-" . $ip,
                       "instantiation_type" => "NetworkPortEthernet",
                       "mac"                => $mac
                   );
         
                   $netPort->splitInputForElements($netPortInput);
                   $NewNetPortId = $netPort->add($netPortInput);
                   $netPort->updateDependencies(1);
                   //make link to IPAdress manualy
         
                   //add ipAdress
                   $networkName= new NetworkName();
                   $networkNameId=$networkName->add(array("items_id"=>$NewNetPortId,"itemtype"=>"NetworkPort"));
                   $ipAdresses = new IPAddress();
         
                   $input = array('name'        => $ip,
                               'itemtype'    => 'NetworkName',
                               'items_id'    => $networkNameId,
                               'is_deleted'  => 0,
                                'mainitems_id'=>$id,
                                'mainitemtype'=>$glpiType);
                   $ipAdresses->add($input);*/
     }
     if ($id && $identify) {
         //identify object
         //WAS IS DAS ? CHMA
         $userId = Session::getLoginUserID();
         $query = "SELECT `glpi_users`.`name` \n                         FROM `glpi_users`\n                         WHERE glpi_users.id like '{$userId}'";
         $queryResult = $DB->query($query);
         $userAssoc = $DB->fetch_assoc($queryResult);
         if ($userAssoc) {
             $ocsClient = new PluginOcsinventoryngOcsServer();
             $DBOCS = $ocsClient->getDBocs($plugin_ocsinventoryng_ocsservers_id)->getDB();
             $ocsType = $ipDiscoveryObject["ocsItemType"];
             $description = $ipDiscoveryObject["itemDescription"];
             $user = $userAssoc["name"];
             $ocsQuery = "INSERT INTO `network_devices` (`description`,`type`,`macaddr`,`user`)\n                            VALUES('{$description}','{$ocsType}','{$mac}','{$user}')";
             $DBOCS->query($ocsQuery);
         }
     }
     if ($id) {
         return array('status' => PluginOcsinventoryngOcsServer::IPDISCOVER_IMPORTED);
     } else {
         Session::addMessageAfterRedirect($mac . " : " . __('Unable to add. an object with same MAC address already exists.', 'ocsinventoryng'), false, ERROR);
         return array('status' => PluginOcsinventoryngOcsServer::IPDISCOVER_FAILED_IMPORT);
     }
 }
开发者ID:pluginsGLPI,项目名称:ocsinventoryng,代码行数:97,代码来源:ipdiscoverocslink.class.php

示例14: 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

示例15: addOrUpdateOther

 /**
  * @param $plugin_ocsinventoryng_ocsservers_id
  * @param $itemtype
  * @param int $ID
  * @param $ocsSnmp
  * @param $loc_id
  * @param $dom_id
  * @param $action
  * @param bool $linked
  * @return int
  */
 static function addOrUpdateOther($plugin_ocsinventoryng_ocsservers_id, $itemtype, $ID = 0, $ocsSnmp, $loc_id, $dom_id, $action, $linked = false)
 {
     $snmpDevice = new $itemtype();
     $cfg_ocs = PluginOcsinventoryngOcsServer::getConfig($plugin_ocsinventoryng_ocsservers_id);
     $input = array("is_dynamic" => 1, "entities_id" => isset($_SESSION['glpiactive_entity']) ? $_SESSION['glpiactive_entity'] : 0);
     if ($cfg_ocs['importsnmp_name'] && $action == "add" || $cfg_ocs['linksnmp_name'] && $linked || $action == "update" && $cfg_ocs['importsnmp_name'] && !$linked || $action == "update" && $cfg_ocs['linksnmp_name'] && $linked) {
         $input["name"] = $ocsSnmp['META']['NAME'];
     }
     if ($cfg_ocs['importsnmp_contact'] && $action == "add" || $cfg_ocs['linksnmp_contact'] && $linked || $action == "update" && $cfg_ocs['importsnmp_name'] && !$linked || $action == "update" && $cfg_ocs['linksnmp_name'] && $linked) {
         $input["contact"] = $ocsSnmp['META']['CONTACT'];
     }
     if ($cfg_ocs['importsnmp_comment'] && $action == "add" || $cfg_ocs['linksnmp_comment'] && $linked || $action == "update" && $cfg_ocs['importsnmp_name'] && !$linked || $action == "update" && $cfg_ocs['linksnmp_name'] && $linked) {
         $input["comment"] = $ocsSnmp['META']['DESCRIPTION'];
     }
     if ($loc_id > 0) {
         $input["locations_id"] = $loc_id;
     }
     if ($dom_id > 0 && $itemtype != "Phone") {
         $input["domains_id"] = $dom_id;
     }
     $id_item = 0;
     if ($action == "add") {
         $id_item = $snmpDevice->add($input, array('unicity_error_message' => true), $cfg_ocs['history_hardware']);
     } else {
         $input["id"] = $ID;
         $id_item = $ID;
         if ($snmpDevice->getFromDB($id_item)) {
             $input["entities_id"] = $snmpDevice->fields['entities_id'];
         }
         $snmpDevice->update($input, $cfg_ocs['history_hardware'], array('unicity_error_message' => false, '_no_history' => !$cfg_ocs['history_hardware']));
     }
     if ($id_item > 0 && ($cfg_ocs['importsnmp_createport'] && $action == "add" || $cfg_ocs['linksnmp_createport'] && $linked || $action == "update" && $cfg_ocs['importsnmp_createport'] && !$linked || $action == "update" && $cfg_ocs['linksnmp_createport'] && $linked)) {
         //Add network port
         $ip = $ocsSnmp['META']['IPADDR'];
         $mac = $ocsSnmp['META']['MACADDR'];
         $np = new NetworkPort();
         $np->getFromDBByQuery("WHERE `mac` LIKE '{$mac}' AND `items_id` = '{$id_item}' AND `itemtype` LIKE '{$itemtype}' ");
         if (count($np->fields) < 1) {
             $item = new $itemtype();
             $entity = isset($_SESSION['glpiactive_entity']) ? $_SESSION['glpiactive_entity'] : 0;
             if ($item->getFromDB($id_item)) {
                 $entity = $item->fields['entities_id'];
             }
             $port_input = array('name' => $ocsSnmp['META']['NAME'], 'mac' => $mac, 'items_id' => $id_item, 'itemtype' => $itemtype, 'instantiation_type' => "NetworkPortEthernet", "entities_id" => $entity, "NetworkName__ipaddresses" => array("-100" => $ip), '_create_children' => 1, 'is_deleted' => 0);
             $np->add($port_input, array(), $cfg_ocs['history_network']);
         }
     }
     return $id_item;
 }
开发者ID:pluginsGLPI,项目名称:ocsinventoryng,代码行数:60,代码来源:snmpocslink.class.php


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