Code

Updated opsi
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 25 Aug 2008 09:49:28 +0000 (09:49 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 25 Aug 2008 09:49:28 +0000 (09:49 +0000)
- Added MAc, note and description option.. and checks

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12267 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/opsi/admin/opsi/class_opsi.inc
gosa-plugins/opsi/admin/opsi/class_opsigeneric.inc
gosa-plugins/opsi/admin/opsi/generic.tpl

index 9e5ea54a1fb25ce8d00dc770ae0c7d3b6655e6c6..f878fcbaae741b0d62361524d96eae75b4e44644 100644 (file)
@@ -305,7 +305,7 @@ class opsi extends gosaSupportDaemon
     @param
     @return            
    */
-  public function list_clients()
+  public function list_clients( $hostId = "")
   {
     $data   = array();
     $res    = $this->send_data("gosa_opsi_list_clients",$this->target,$data,TRUE);
@@ -354,16 +354,37 @@ class opsi extends gosaSupportDaemon
     @param
     @return            
    */
-  public function add_client($hostId,$ip,$macaddress,$notes,$description)
+  public function add_client($hostId,$macaddress,$notes,$description)
   {
-    $data = array("hostId" => $hostId,"ip" => $ip,"macaddress" => $macaddress);
+    $data = array("hostId" => $hostId,"macaddress" => $macaddress);
 
     if(empty($hostId)){
       trigger_error("No valid host id given, check parameter 1.");
       return;
     }
-    if(empty($ip)){
-      trigger_error("No valid ip address given, check parameter 2.");
+  
+    /* Add optional attributes */ 
+    foreach(array("notes","description") as $attr) {
+      if(!empty($$attr)){
+        $data[$attr] = $$attr;
+      }
+    }
+
+    /* Query SI server */
+    $res    = $this->send_data("gosa_opsi_add_client",$this->target,$data,TRUE);
+  }
+
+
+  /*! \brief           Modify an opsi client.
+    @param
+    @return            
+   */
+  public function modify_client($hostId,$mac,$notes,$description)
+  {
+    $data = array("hostId" => $hostId,"mac" => $mac);
+
+    if(empty($hostId)){
+      trigger_error("No valid host id given, check parameter 1.");
       return;
     }
   
@@ -375,7 +396,7 @@ class opsi extends gosaSupportDaemon
     }
 
     /* Query SI server */
-    $res    = $this->send_data("gosa_opsi_add_client",$this->target,$data,TRUE);
+    $res    = $this->send_data("gosa_opsi_modify_client",$this->target,$data,TRUE);
   }
 
 
index fe3349c641b6777485eb56f118454c9dffa1db33..ea511b15a7a3514a16901ca191b609f2c97bf098 100644 (file)
@@ -21,6 +21,12 @@ class opsigeneric extends plugin
 
   private $parent_mode = TRUE;
 
+  public $mac          = "";
+  public $note         = "";
+  public $description  = "";
+
+  public $attributes = array("mac","note","description");
+
   public function __construct($config,$hostId)
   {
     $this->opsi = new opsi($config); 
@@ -41,6 +47,19 @@ class opsigeneric extends plugin
     $err = FALSE;
     $this->init_failed = FALSE;
 
+    if($this->hostId != "new"){
+      $list = $this->opsi->list_clients($this->hostId);
+      foreach($list as $entry){
+        if($entry['NAME'][0]['VALUE'] == $this->hostId){  
+          foreach(array("description" => "DESCRIPTION","mac" => "MAC", "note" => "NOTES") as $des => $src){
+            $this->$des = $entry[$src][0]['VALUE'];
+          } 
+
+          break;
+        }
+      }
+    }
+
     /* Get product settings */     
     if(!$err){
       $this->a_availableNetbootProducts = $this->opsi->get_netboot_products();
@@ -98,13 +117,15 @@ class opsigeneric extends plugin
     if(!preg_match("/\./",$this->hostId)){
       $messages[] = msgPool::invalid(_("Name"),$this->hostId,"",_("The client name must contain a domain part (e.g. '.company.de')."));
     }
+    if(!tests::is_mac($this->mac)){
+      $messages[] = msgPool::invalid(_("MAC address"),$this->mac,"","00:0C:7F:31:33:F1");
+    }
     return($messages);
   }
 
   public function execute()
   {
     if($this->init_failed){
-      
       $smarty = get_smarty();
       $smarty->assign("init_failed",TRUE);
       $smarty->assign("message",$this->opsi->get_error());
@@ -117,6 +138,11 @@ class opsigeneric extends plugin
     }
 
     $smarty = get_smarty();
+
+    foreach($this->attributes as $attr){
+      $smarty->assign($attr,$this->$attr);
+    }
+
     $smarty->assign("parent_mode", $this->parent_mode);
     $smarty->assign("init_failed",FALSE);
     $divSLP = new divSelectBox();
@@ -174,12 +200,17 @@ class opsigeneric extends plugin
         -Do we have to create this client first?
      */
     if(!$this->initially_was_account && $this->is_account){
-      $res = $this->opsi->add_client($this->hostId,"0.0.0.0","00:00:00:00:00:00","Hallo","TZ");
+      $res = $this->opsi->add_client($this->hostId,$this->mac,$this->note,$this->description);
       if($this->opsi->is_error()){
         msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);    
         return;
       }
     }
+    $this->opsi->modify_client($this->hostId,$this->mac,$this->note,$this->description);
+    if($this->opsi->is_error()){
+      msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
+      return;
+    }
 
     $add = array_diff_assoc($this->a_selectedLocalProducts,$this->a_initial_selectedLocalProducts);
     $del = array_diff_assoc($this->a_initial_selectedLocalProducts,$this->a_selectedLocalProducts);
@@ -257,6 +288,8 @@ class opsigeneric extends plugin
 
     if(isset($_POST['opsigeneric_posted'])){
 
+      plugin::save_object();
+
       if(isset($_POST['hostId']) && $this->parent_mode){
         $this->hostId = get_post('hostId');
       }
index 1c2c5fddf2b83e4bf234e4e7210797898911dd36..918c5f752dbb23b16c7e8a57703eb96171a82598 100644 (file)
@@ -11,7 +11,7 @@
 
 <table style="width: 100%;">
  <tr>
-  <td colspan="2">
+  <td>
    <table>
     {if $parent_mode}
      <tr>
       <td><input type='text' name='hostId' value='{$hostId}'></td>
      </tr>
     {/if}
+    <tr>
+     <td>{t}Description{/t}</td>
+     <td><input type='text' name='description' value='{$description}'></td>
+    </tr>
+    <tr>
+     <td>{t}Notes{/t}</td>
+     <td><input type='text' name='note' value='{$note}'></td>
+    </tr>
+   </table>
+  </td>
+  <td style='vertical-align: top;'>
+   <table>
+    <tr>
+     <td>{t}MAC address{/t}</td>
+     <td><input type='text' name='mac' value='{$mac}'></td>
+    </tr>
     <tr>
      <td>{t}Boot product{/t}</td>
      <td>
      </td>
     </tr>
    </table>
-  <td>
+  </td>
+ </tr>
+ <tr>
+  <td colspan="2">
+   <p class='seperator'>&nbsp;</p>
+  </td>
  </tr>
  <tr>
   <td style="width:50%;"><h2>Installed products</h2>