Code

Updated opsi
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 22 Aug 2008 09:35:09 +0000 (09:35 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 22 Aug 2008 09:35:09 +0000 (09:35 +0000)
-Fixed client creation.

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12261 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 e764de2409dfceb279f37471eaaa8a0f3670a9a2..2e42a3abe74c0fd2087ff47ef8ba97983f7ab553 100644 (file)
@@ -56,6 +56,7 @@ class opsi extends gosaSupportDaemon
     $this->target = "00:01:6c:9d:b9:fa";
   }
 
+
   /******************
     Opsi handling 
    ******************/
@@ -262,15 +263,21 @@ class opsi extends gosaSupportDaemon
     @param
     @return            
    */
-  public function get_client_hardware()
+  public function get_client_hardware($hostId)
   {
-    /* <xml> 
-        <header>gosa_opsi_get_client_hardware</header> 
-        <source>GOSA</source> 
-        <target>GOSA</target> 
-        <hostId>limux-cl-2.intranet.gonicus.de</hostId> 
-        </xml> 
-     */
+    $data = array("hostId" => $hostId);
+
+    /* Check parameter */ 
+    if(empty($hostId)){
+      trigger_error("No valid host id given, check parameter 1.");
+      return;
+    }
+
+    /* Query SI server */
+    $res    = $this->send_data("gosa_opsi_get_client_hardware",$this->target,$data,TRUE);
+    if(isset($res['XML']['ITEM'])){
+      #print_a($res['XML']['ITEM']);
+    }
   }
 
 
@@ -354,19 +361,28 @@ class opsi extends gosaSupportDaemon
     @param
     @return            
    */
-  public function add_client()
+  public function add_client($hostId,$ip,$macaddress,$notes,$description)
   {
-    /*  <xml> 
-        <header>gosa_opsi_add_client</header> 
-        <source>GOSA</source> 
-        <target>00:01:6c:9d:b9:fa</target> 
-        <hostId>limux-cl-2.intranet.gonicus.de</hostId> 
-        <macaddress>00:11:25:4b:8c:e5</macaddress> 
-        <description>Test halt</description> 
-        <ip>1.2.3.4</ip> 
-        <notes>Im a note</notes> 
-        </xml>
-     */
+    $data = array("hostId" => $hostId,"ip" => $ip,"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.");
+      return;
+    }
+  
+    /* 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);
   }
 
 
index a36c388469a19ff046f58a5d547a8866f7356698..5acbc597cb5c46579b481087ffaacac437ea5dff 100644 (file)
@@ -19,14 +19,16 @@ class opsigeneric extends plugin
 
   private $init_failed = FALSE;
 
+  private $parent_mode = TRUE;
+
   public function __construct($config,$hostId)
   {
     $this->opsi = new opsi($config); 
     $this->is_account =TRUE;
-    $this->initially_was_account = TRUE;
   
     /* Get hostId */
     if($hostId != "new"){
+      $this->initially_was_account = TRUE;
       $this->hostId = preg_replace("/^opsi:=([^,]*),.*$/","\\1",$hostId);
     }
   
@@ -88,6 +90,15 @@ class opsigeneric extends plugin
     }
   }
 
+  public function check()
+  {
+    $messages = plugin::check();
+    if(!preg_match("/\./",$this->hostId)){
+      $messages[] = msgPool::invalid(_("Name"),$this->hostId,"",_("The client name must contain a domain part (e.g. '.company.de')."));
+    }
+    return($messages);
+  }
+
   public function execute()
   {
     if($this->init_failed){
@@ -98,13 +109,13 @@ class opsigeneric extends plugin
       return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
     }  
 
-
     if(is_object($this->dialog)){
       $this->dialog->save_object();
       return($this->dialog->execute());
     }
 
     $smarty = get_smarty();
+    $smarty->assign("parent_mode", $this->parent_mode);
     $smarty->assign("init_failed",FALSE);
     $divSLP = new divSelectBox();
     $divALP = new divSelectBox();
@@ -145,11 +156,11 @@ class opsigeneric extends plugin
       $divSLP->AddEntry(array($name_tab,$desc_tab,$opt_tab));
     }
 
+    ksort($this->a_availableNetbootProducts);
+    $smarty->assign("hostId", $this->hostId);
     $smarty->assign("divSLP", $divSLP->DrawList());
     $smarty->assign("divALP", $divALP->DrawList());
     $smarty->assign("SNP", $this->s_selectedNetbootProduct);
-  
-    ksort($this->a_availableNetbootProducts);
     $smarty->assign("ANP", $this->a_availableNetbootProducts);
     return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
   }
@@ -157,6 +168,17 @@ class opsigeneric extends plugin
 
   public function save()
   {
+    /* Check if this a new opsi client 
+        -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");
+      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);
 
@@ -190,7 +212,7 @@ class opsigeneric extends plugin
 
   public function save_object()
   {
-    if(isset($_POST['reinit'])){
+    if(isset($_POST['reinit']) && $this->init_failed){
       $this->init();
     }
 
@@ -207,7 +229,11 @@ class opsigeneric extends plugin
       $this->dialog = NULL;
     }
 
-    if(isset($_POST['opsigeneric'])){
+    if(isset($_POST['opsigeneric_posted'])){
+
+      if(isset($_POST['hostId']) && $this->parent_mode){
+        $this->hostId = get_post('hostId');
+      }
 
       if(isset($_POST['opsi_netboot_product'])){
         $SNP = trim($_POST['opsi_netboot_product']);
index 17b3b1ab9342e0ab898b8f49ddeaa50681ec0bff..1c2c5fddf2b83e4bf234e4e7210797898911dd36 100644 (file)
  <tr>
   <td colspan="2">
    <table>
+    {if $parent_mode}
+     <tr>
+      <td>{t}Name{/t}</td>
+      <td><input type='text' name='hostId' value='{$hostId}'></td>
+     </tr>
+    {/if}
     <tr>
      <td>{t}Boot product{/t}</td>
      <td>
@@ -35,5 +41,5 @@
   </td>
  </tr>
 </table> 
-<input type='hidden' name='opsigeneric' value='1'>
+<input type='hidden' name='opsigeneric_posted' value='1'>
 {/if}