You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2007-10-08 15:36:03

Tungsten
Member
From: Poitiers
Registered: 2006-02-15
Posts: 6
Website

Transfert des ports d'un materiel réseau vers un autre

Bonjour,

J'ai développé un patch pour la 68.3-2 concernant le transfert des ports réseaux (et des connexions qui vont avec) vers un autre équipement. l'intérêt de la fonction est la possibilité de garder une configuration réseau dans le cas d'un remplacement d'un matériel défectueux par un spare.

Commentaires,suggestions et critiques sont les bienvenus !


voici le patch. (désolé je n'ai pas fait les traductions)

--- ./glpi/ajax/dropdownMassiveActionPorts.php    2007-06-18 11:22:05.000000000 +0200
+++ /var/www/glpi/ajax/dropdownMassiveActionPorts.php    2007-10-03 16:40:56.000000000 +0200
@@ -57,6 +57,10 @@
             dropdownValue("glpi_dropdown_vlan","vlan",0);
         echo "&nbsp;<input type=\"submit\" name=\"unassign_vlan_several\" class=\"submit\" value=\"".$lang["buttons"][2]."\" >";
         break;
+        case "assign_NetworkPortbyIDtoDevice":
+            dropdownValue("glpi_networking","device",0);
+        echo "&nbsp;<input type=\"submit\" name=\"assign_NetworkPortbyIDtoDevice_several\" class=\"submit\" value=\"".$lang["buttons"][2]."\" >";
+        break;
 
     }
 }
--- ./glpi/front/networking.port.php    2007-06-18 11:22:05.000000000 +0200
+++ /var/www/glpi/front/networking.port.php    2007-10-03 16:27:19.000000000 +0200
@@ -173,6 +173,32 @@
     }
     glpi_header($_SERVER['HTTP_REFERER']);
 }
+
+
+
+else if (isset($_POST['assign_NetworkPortbyIDtoDevice'])){
+        checkRight("networking","w");
+
+        if (isset($_POST["device"])&&$_POST["device"]>0){
+                assignNetworkPortbyID($_POST["ID"],$_POST["device"]);
+                logEvent(0, "networking", 5, "inventory", $_SESSION["glpiname"]." assign ports to device.");
+        }
+        glpi_header($_SERVER['HTTP_REFERER'].$ADDREFERER);
+}
+else if(isset($_POST["assign_NetworkPortbyIDtoDevice_several"]))
+{
+        checkRight("networking","w");
+        if ($_POST["device"]>0){
+                if (isset($_POST["del_port"])&&count($_POST["del_port"]))
+                        foreach ($_POST["del_port"] as $port_id => $val){
+                                assignNetworkPortbyIDtoDevice($port_id,$_POST["device"]);
+                        }
+
+                logEvent(0, "networking", 5, "inventory", $_SESSION["glpiname"]." assign ports to device.");
+        }
+        glpi_header($_SERVER['HTTP_REFERER']);
+}
+
 else if (isset($_GET['unassign_vlan'])){
     checkRight("networking","w");
 

--- ./glpi/inc/dropdown.function.php    2007-06-18 11:22:06.000000000 +0200
+++ /var/www/glpi/inc/dropdown.function.php    2007-10-04 17:38:06.000000000 +0200
@@ -351,7 +351,7 @@
  * @param $withcomments give array with name and comments
  * @return string the value of the dropdown or &nbsp; if not exists
  */
-function getDropdownName($table,$id,$withcomments=0) {
+function getDropdownName($table,$id,$withcomments=0,$nodetail=0) {
     global $db,$cfg_glpi,$lang;
 
     if (in_array($table,$cfg_glpi["dropdowntree_tables"])){
@@ -392,7 +392,7 @@
                             
                             break;
                         case "glpi_dropdown_netpoint":
-                            $name .= " (".getDropdownName("glpi_dropdown_locations",$data["location"]).")";
+                            if (!$nodetail) $name .= " (".getDropdownName("glpi_dropdown_locations",$data["location"]).")";
                             break;
                         case "glpi_software":
                             $name .= "  (v. ".$data["version"].")";
@@ -1232,6 +1232,7 @@
     echo "<option value=\"delete\">".$lang["buttons"][6]."</option>";
     echo "<option value=\"assign_vlan\">".$lang["networking"][55]."</option>";
     echo "<option value=\"unassign_vlan\">".$lang["networking"][58]."</option>";
+    echo "<option value=\"assign_NetworkPortbyIDtoDevice\">".$lang["networking"][59]."</option>";
     echo "</select>";
 
     echo "<script type='text/javascript' >\n";

--- ./glpi/inc/networking.class.php    2007-06-18 11:22:06.000000000 +0200
+++ /var/www/glpi/inc/networking.class.php    2007-10-04 16:41:01.000000000 +0200
@@ -473,7 +473,7 @@
     }
 
     function post_updateItem($input,$updates,$history){
-        $tomatch=array("netpoint","ifaddr","ifmac");
+        //$tomatch=array("netpoint","ifaddr","ifmac");
         $updates=array_intersect($updates,$tomatch);
         if (count($updates)){
             $save_ID=$this->fields["ID"];

--- ./glpi/inc/networking.function.php    2007-06-18 11:22:06.000000000 +0200
+++ /var/www/glpi/inc/networking.function.php    2007-10-04 16:35:33.000000000 +0200
@@ -168,6 +168,15 @@
 
 }
 
+
+
+function assignNetworkPortbyIDtoDevice($portID,$networkdevice){
+        global $db;
+    $query="UPDATE glpi_networking_ports set on_device='$networkdevice' where ID='$portID'";
+        $db->query($query);
+}
+
+
 function unassignVlanbyID($ID){
     global $db;
     $query="DELETE FROM glpi_networking_vlan WHERE ID='$ID'";
@@ -310,6 +319,16 @@
         echo "<td align='center'>";
         echo "<input type='submit' name='delete' value=\"".$lang["buttons"][6]."\" class='submit'>";
         echo "</td></tr>";
+
+        echo "<tr class='tab_bg_2'>";
+        echo "<tr  class='tab_bg_2'><td>";
+        echo $lang["networking"][59].":&nbsp;";
+                dropdown("glpi_networking","networkdevice");
+                echo "<input type='hidden' name='PortID' value='$ID'>";
+        echo "<input type='submit' name='assign_NetworkPortbyIDtoDevice' value='".$lang["buttons"][3]."' class='submit'>";
+                echo "</td></tr>";
+
+
     } else 
     {
 
@@ -319,6 +338,7 @@
         echo "<input type='hidden' name='device_type' value='$devtype'>";
         echo "<input type='submit' name='add' value=\"".$lang["buttons"][8]."\" class='submit'>";
         echo "</td></tr>";
+        
     }
 
     echo "</table></form></div>";    
@@ -326,6 +346,7 @@
     if ($ID){
         echo "<div align='center'>";
         echo "<form method='post' action=\"$target\">";
+        
         echo "<input type='hidden' name='referer' value='$REFERER'>";
         echo "<input type='hidden' name='ID' value='$ID'>";
 
@@ -444,8 +465,8 @@
     $nps="";
     $ips="";
     $macs="";
-    if (isset($ps->fields["netpoint"])&&$ps->fields["netpoint"]!=0)
-        $nps=$ps->fields["netpoint"];
+    //if (isset($ps->fields["netpoint"])&&$ps->fields["netpoint"]!=0)
+    //        $nps=$ps->fields["netpoint"];
     if (isset($ps->fields["ifaddr"]))
         $ips=$ps->fields["ifaddr"];
     if (isset($ps->fields["ifmac"]))
@@ -457,8 +478,8 @@
     $npd="";
     $ipd="";
     $macd="";
-    if (isset($pd->fields["netpoint"])&&$pd->fields["netpoint"]!=0)
-        $npd=$pd->fields["netpoint"];
+    //if (isset($pd->fields["netpoint"])&&$pd->fields["netpoint"]!=0)
+    //    $npd=$pd->fields["netpoint"];
     if (isset($pd->fields["ifaddr"]))
         $ipd=$pd->fields["ifaddr"];
     if (isset($pd->fields["ifmac"]))
@@ -494,8 +515,8 @@
     else if ($macs!=$macd){
         echo "<div align='center'><b>".$lang["connect"][22]."</b></div>";
     }
-    // Update unknown netpoint
-    $updates[0]="netpoint";
+     // Update unknown netpoint
+    /* $updates[0]="netpoint";
     if (empty($nps)&&!empty($npd)){
         $ps->fields["netpoint"]=$npd;
         $ps->updateInDB($updates);
@@ -509,7 +530,7 @@
     else if ($nps!=$npd){
         echo "<div align='center'><b>".$lang["connect"][18]."</b></div>";
     }
-
+    */
     $query = "INSERT INTO glpi_networking_wire VALUES (NULL,$sport,$dport)";
     if ($result = $db->query($query)) {
         $source=new CommonItem;


--- ./glpi/locales/fr_FR.php    2007-06-18 11:22:05.000000000 +0200
+++ /var/www/glpi/locales/fr_FR.php    2007-10-03 15:48:25.000000000 +0200
@@ -876,6 +876,7 @@
 $lang["networking"][56]="VLAN";
 $lang["networking"][57]="Choisissez une adresse MAC dans la liste ou spécifiez-la ci-dessous.";
 $lang["networking"][58]="Supprimer un VLAN";
+$lang["networking"][59]="Associer a un autre materiel";
 
 
 $lang["ocsng"][0]="OCS Inventory NG";

GPL 0.68.3-2 + OCS
Ubuntu Dapper 6.06

Offline

Board footer

Powered by FluxBB