Code

replaced plugbottom by pluin-actions
[gosa.git] / gosa-plugins / opsi / admin / opsi / class_opsigeneric.inc
index 911507fac553dfb1fc728076c7eb2858a3ca1681..026d56d4c5ff1eb0eb39ec59191c796e24a80980 100644 (file)
@@ -45,6 +45,7 @@ class opsiGeneric extends plugin
 
   public $attributes = array("mac","note","description");
 
+  public $netConfigDNS = NULL;
 
   /*! \brief  Initialize this class 
       @param  Object    The GOsa base config.
@@ -75,7 +76,7 @@ class opsiGeneric extends plugin
         $this->hostId = preg_replace('/\$$/',"",$this->hostId);
       }
     }
-  
+
     /* Try to plugin */
     $this->init();
   }
@@ -96,10 +97,10 @@ class opsiGeneric extends plugin
       $this->is_account = TRUE;
     }
 
+
     /* Try to load client infos from the gosa support daemon
      */
     if(!empty($this->hostId)){
-
       $list = $this->opsi->list_clients($this->hostId);
       $err |= $this->opsi->is_error();
 
@@ -124,61 +125,37 @@ class opsiGeneric extends plugin
       }
     }
 
-    /* Read informations about available netboot products. 
-        If not already done, before.
-     */
-    if(!$err && !count($this->a_availableNetbootProducts)){
-      $this->a_availableNetbootProducts = $this->opsi->get_netboot_products();
-      ksort($this->a_availableNetbootProducts);
-      $err |= $this->opsi->is_error();
-    }
+    // Get package info
+    $list = array(); 
+    $list = $this->opsi->get_full_product_host_information($this->hostId);
+    $err |= $this->opsi->is_error();
 
     /* Read informations about available netboot products. 
-        If not already done, before.
+       If not already done, before.
      */
-    if(!$err && !count($this->a_availableLocalProducts)) {
-      $this->a_availableLocalProducts   = $this->opsi->get_local_products();
-      ksort($this->a_availableLocalProducts);
-      $err |= $this->opsi->is_error();
-    }
+    if(!$err){
+      foreach($list as $key => $entry){
 
-    /* Get products selected by this host.
-     */
-    if(!$err && !empty($this->hostId)) {
-      $tmp = array_keys($this->opsi->get_netboot_products($this->hostId));
-      $err |= $this->opsi->is_error();
-      if(count($tmp) && !$err && !isset($this->a_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'])){
-        $this->s_selectedNetbootProduct = $tmp[0];
-      
-        /* Read configuration for "Netboot Products" */
-        if(isset($this->a_availableNetbootProducts[$this->s_selectedNetbootProduct])){
-          $CFG = $this->opsi->get_product_properties($this->s_selectedNetbootProduct,$this->hostId);
-          $this->a_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'] = $CFG;
-        }
-      }
-      $err |= $this->opsi->is_error();
-    }
+        $tmp = array('DESC'=>$entry['data']['DESCRIPTION'],'NAME'=>$key);
+        if($entry['configurable']){
+          $tmp['CFG'] = $entry['data']['PROPERTIES'];
+        } 
 
-    /* Get all selected local products 
-     */
-    if(!$err && !empty($this->hostId) && !count($this->a_selectedLocalProducts)) {
-      $tmp = $this->opsi->get_local_products($this->hostId); 
-      $err |= $this->opsi->is_error();
-      $this->a_selectedLocalProducts = $tmp;
-    }
-
-    /* Load product configuration for all already selected products.
-     */
-    if(!$err && !empty($this->hostId)) {
-      foreach($this->a_selectedLocalProducts as $name => $data){
-        if(!$err && !isset($this->a_selectedLocalProducts[$name]['CFG'])){
-          $CFG = $this->opsi->get_product_properties($name,$this->hostId);
-          $err |= $this->opsi->is_error();
-          $this->a_selectedLocalProducts[$name]['CFG'] = $CFG;
+        if($entry['data']['TYPE'] == "localboot"){
+          if(!$entry['installed']){
+            $this->a_availableLocalProducts[$key] = $tmp;
+          }else{
+            $this->a_selectedLocalProducts[$key] = $tmp;
+          }
+        }else{
+          $this->a_availableNetbootProducts[$key] = $tmp;
+          if($entry['installed']){
+            $this->s_selectedNetbootProduct= $key;
+          }
         }
       }
     }
-  
+
     /* Check if everything went fine else reset everything and display a retry button 
      */
     if($err){
@@ -196,6 +173,34 @@ class opsiGeneric extends plugin
       if(empty($this->s_selectedNetbootProduct)){
         $this->s_selectedNetbootProduct = key($this->a_availableNetbootProducts);
       }
+
+      // Now fake a valid ldap entry ... this is necessary to avoid 
+      //  modifications in the dns/dhcp classes
+
+      // First fake cn 
+      $this->attrs['hostId'][0] = $this->hostId;
+      $this->attrs['cn'][0] = $this->hostId;
+
+      // Second detect DNS settings. 
+      $ldap = $this->config->get_ldap_link();
+      $ldap->cd($this->config->current['BASE']);
+      $strippedHostId = preg_replace("/\..*$/","",$this->hostId);
+      $ldap->search("(&(objectClass=dNSZone)(|(relativeDomainName=".$this->hostId.")(relativeDomainName=".$strippedHostId."))(aRecord=*))",array("aRecord"));
+      if($ldap->count()){
+        $attrs = $ldap->fetch();
+        $this->attrs['ipHostNumber']['count'] = 0;
+        $this->attrs['ipHostNumber'][0] = $attrs['aRecord'][0];
+      }
+
+      $this->attrs['macAddress']['count'] = 1;
+      $this->attrs['macAddress'][0] = &$this->mac;
+
+      // Initialize DHCP and DNS 
+      $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses, FALSE, "hostId");
+      $this->netConfigDNS->set_acl_category("opsi");
+      $this->netConfigDNS->set_acl_base($this->config->current['BASE']);
+      $this->netConfigDNS->IPisMust = FALSE;
+      $this->netConfigDNS->MACisMust = FALSE;
     }
   }
 
@@ -205,7 +210,15 @@ class opsiGeneric extends plugin
    */
   public function check()
   {
+  
+    // In case of initialization problem, we do not save anything.
+    // We can skip checks here, the date isn't usable.
+    if($this->init_failed){ 
+      return;
+    };
+
     $messages = plugin::check();
+    $messages= array_merge($messages, $this->netConfigDNS->check());
 
     if(empty($this->hostId)){
       $messages[] = msgPool::required(_("Name"));
@@ -352,6 +365,13 @@ class opsiGeneric extends plugin
       $cfg_able &= $this->acl_is_readable("netbootProduct");
     }
 
+    // Get net config template
+    $str = $this->netConfigDNS->execute();
+    if(is_object($this->netConfigDNS->dialog)){
+      return($str);
+    }
+    $smarty->assign("netconfig", $str);
+
     $smarty->assign("netboot_configurable",$cfg_able);
     $smarty->assign("hostId", $this->hostId);
     $smarty->assign("divSLP", $divSLP->DrawList());
@@ -366,6 +386,9 @@ class opsiGeneric extends plugin
    */
   public function save()
   {
+    if($this->init_failed){ 
+      return;
+    }
     
     /* Check if we have to create a new opsi client
         or just have to save client modifications.
@@ -501,6 +524,9 @@ class opsiGeneric extends plugin
         return;
       }
     }
+
+    $this->netConfigDNS->cn = $this->hostId;
+    $this->netConfigDNS->save();
   }
 
   
@@ -510,12 +536,12 @@ class opsiGeneric extends plugin
      */
     $res = array();
     foreach($c2 as $name => $value){
-      if(!isset($c1[$name]) || $c1[$name]['DEFAULT'] != $c2[$name]['DEFAULT']){
+      if(!isset($c1[$name]) || $c1[$name]['CURRENT'] != $c2[$name]['CURRENT']){
         $res[$name] = $c2[$name];
       }
     }
     foreach($c1 as $name => $value){
-      if(!isset($c2[$name]) || $c2[$name]['DEFAULT'] != $c1[$name]['DEFAULT']){
+      if(!isset($c2[$name]) || $c2[$name]['CURRENT'] != $c1[$name]['CURRENT']){
         $res[$name] = $c1[$name];
       }
     }
@@ -527,6 +553,11 @@ class opsiGeneric extends plugin
    */  
   public function remove_from_parent()
   {
+    if($this->init_failed){ 
+      return;
+    }
+    $this->netConfigDNS->remove_from_parent();
+
     $this->opsi->del_client($this->hostId);
     if($this->opsi->is_error()){
       msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
@@ -577,7 +608,9 @@ class opsiGeneric extends plugin
     if(isset($_POST['opsiGeneric_posted'])){
 
       plugin::save_object();
-
+      $this->netConfigDNS->save_object();
+      $this->mac = $this->netConfigDNS->macAddress;
+  
       /* Get hostId 
        */
       if(isset($_POST['hostId']) && $this->standalone && $this->acl_is_writeable("hostId")){