コード例 #1
0
ファイル: networkport.class.php プロジェクト: gaforeror/glpi
 /**
  * Clone the current NetworkPort when the item is clone
  *
  * @since version 0.84
  *
  * @param $itemtype     the type of the item that was clone
  * @param $old_items_id the id of the item that was clone
  * @param $new_items_id the id of the item after beeing cloned
  **/
 static function cloneItem($itemtype, $old_items_id, $new_items_id)
 {
     global $DB;
     $np = new self();
     // ADD Ports
     $query = "SELECT `id`\n                FROM `glpi_networkports`\n                WHERE `items_id` = '" . $old_items_id . "'\n                      AND `itemtype` = '" . $itemtype . "';";
     $result = $DB->query($query);
     if ($DB->numrows($result) > 0) {
         while ($data = $DB->fetch_assoc($result)) {
             $np->getFromDB($data["id"]);
             unset($np->fields["id"]);
             $np->fields["items_id"] = $new_items_id;
             $portid = $np->addToDB();
             $instantiation = $np->getInstantiation();
             if ($instantiation !== false) {
                 $instantiation->add(array('id' => $portid));
                 unset($instantiation);
             }
             $npv = new NetworkPort_Vlan();
             foreach ($DB->request($npv->getTable(), array($npv->items_id_1 => $data["id"])) as $vlan) {
                 $input = array($npv->items_id_1 => $portid, $npv->items_id_2 => $vlan['vlans_id']);
                 if (isset($vlan['tagged'])) {
                     $input['tagged'] = $vlan['tagged'];
                 }
                 $npv->add($input);
             }
         }
     }
 }
コード例 #2
0
/**  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);
   $newportID = $np->add($param);

   $np->updateDependencies(1);
   if (isset($VLAN_LOC[$locations_id]) && $newportID) {
      $nv->add(array('networkports_id' => $newportID,
                     'vlans_id'        => $VLAN_LOC[$locations_id]));
   }
   if ($locations_id && $refportID && $newportID) {
      // link ports
      $nn = new Networkport_Networkport();
      $nn->add(array('networkports_id_1' => $refportID,
                     'networkports_id_2' => $newportID,));
   } else {
      if ($locations_id) {
      }
   }
}
コード例 #3
0
ファイル: networkport.class.php プロジェクト: stweil/glpi
 /**
  * Clone the current NetworkPort when the item is clone
  *
  * @since version 0.84
  *
  * @param $itemtype     the type of the item that was clone
  * @param $old_items_id the id of the item that was clone
  * @param $new_items_id the id of the item after beeing cloned
  **/
 static function cloneItem($itemtype, $old_items_id, $new_items_id)
 {
     global $DB;
     $np = new self();
     // ADD Ports
     foreach ($DB->request('glpi_networkports', array('FIELDS' => 'id', 'WHERE' => "`items_id` = '{$old_items_id}'\n                                                AND `itemtype` = '{$itemtype}'")) as $data) {
         $np->getFromDB($data["id"]);
         $instantiation = $np->getInstantiation();
         unset($np->fields["id"]);
         $np->fields["items_id"] = $new_items_id;
         $portid = $np->addToDB();
         if ($instantiation !== false) {
             $input = array();
             $input["networkports_id"] = $portid;
             unset($instantiation->fields["id"]);
             unset($instantiation->fields["networkports_id"]);
             foreach ($instantiation->fields as $key => $val) {
                 if (!empty($val)) {
                     $input[$key] = $val;
                 }
             }
             $instantiation->add($input);
             unset($instantiation);
         }
         $npv = new NetworkPort_Vlan();
         foreach ($DB->request($npv->getTable(), array($npv::$items_id_1 => $data["id"])) as $vlan) {
             $input = array($npv::$items_id_1 => $portid, $npv::$items_id_2 => $vlan['vlans_id']);
             if (isset($vlan['tagged'])) {
                 $input['tagged'] = $vlan['tagged'];
             }
             $npv->add($input);
         }
     }
 }
 function addVlan($a_vlan, $networkports_id)
 {
     $networkPort_Vlan = new NetworkPort_Vlan();
     $vlan = new Vlan();
     $db_vlans = $vlan->find("`tag`='" . $a_vlan['tag'] . "' AND `name`='" . $a_vlan['name'] . "'", "", 1);
     $vlans_id = 0;
     if (count($db_vlans) > 0) {
         $db_vlan = current($db_vlans);
         $vlans_id = $db_vlan['id'];
     } else {
         $input = array();
         $input['tag'] = $a_vlan['tag'];
         $input['name'] = $a_vlan['name'];
         $vlans_id = $vlan->add($input);
     }
     $input = array();
     $input['networkports_id'] = $networkports_id;
     $input['vlans_id'] = $vlans_id;
     $networkPort_Vlan->add($input);
 }