Code

Updated translation, fixed some typo/errors
[gosa.git] / plugins / admin / systems / class_termDNS.inc
index a587f6cb76803cd68027270aa9363d24e285c809..065a6e1129204b5aab84c4447748bf8400edd2cb 100644 (file)
@@ -29,6 +29,7 @@ class termDNS extends plugin
   var $dhcpHostEntry            = array();
   var $initial_dhcpParentNode   = "";
   var $initial_dhcpHostEntry    = array();
+  var $initial_dhcp_is_Account  = FALSE;
 
 
   /* DNS attributes  
@@ -73,6 +74,7 @@ class termDNS extends plugin
       $this->dhcpParentNode  = $this->get_dhcp_parent_node();
       if($this->dhcpParentNode){
         $this->dhcp_is_Account = TRUE;
+        $this->initial_dhcp_is_Account = TRUE;
         $this->dhcpHostEntry  = $this->get_dhcp_host_entry();    
       }
       $this->initial_dhcpHostEntry = $this->dhcpHostEntry;
@@ -119,10 +121,14 @@ class termDNS extends plugin
 
       /* Remove A record which equals $this->ipHostNumber
        */
+      $ptr = $this->get_pTRRecord();
       foreach($this->dnsEntry['RECORDS'] as $key => $rec){
         if(($rec['type'] == "aRecord") && ($rec['value'] == $this->ipHostNumber)){
           unset($this->dnsEntry['RECORDS'][$key]);
         }
+        if(($rec['type'] == "pTRRecord") && ($rec['value'] == $ptr)){
+          unset($this->dnsEntry['RECORDS'][$key]);
+        }
       }
 
       /* Get Record types 
@@ -201,7 +207,17 @@ class termDNS extends plugin
      **********/
  
     if(isset($_POST['dhcpEditOptions'])){
-      $this->dialog = new dhcpHost($this->dhcpHostEntry);
+
+      if(count($this->dhcpHostEntry) == 0){
+        $this->dialog = new dhcpHost($this->dhcpParentNode,TRUE);
+      }else{
+        $this->dialog = new dhcpHost($this->dhcpHostEntry,TRUE);
+      }
+      $this->dialog->cn = $this->cn; 
+      $this->dialog->dhcpHWAddress = $this->macAddress; 
+      if(!empty($this->ipHostNumber)){
+        $this->dialog->statements['fixed-address'] = $this->ipHostNumber; 
+      }
     }
 
     if(isset($_POST['cancel_dhcp'])){
@@ -209,10 +225,21 @@ class termDNS extends plugin
     }
 
     if(isset($_POST['save_dhcp'])){
-      $this->dialog = FALSE; 
+      $this->dialog->save_object();
+      
+      $msgs = $this->dialog->check(array());
+      if(count($msgs)){
+        foreach($msgs as $msg){
+          print_red($msg);
+        }
+      }else{
+        $this->dhcpHostEntry = $this->dialog->save();
+        $this->dialog = FALSE; 
+      }
     }
 
     if(isset($this->dialog) && $this->dialog != FALSE){
+      $this->dialog->save_object();
       return($this->dialog->execute());
     }
  
@@ -220,11 +247,7 @@ class termDNS extends plugin
     $smarty->assign("dhcp_is_Account",$this->dhcp_is_Account);
     $smarty->assign("dhcpParentNode", $this->dhcpParentNode);
     $smarty->assign("dhcpParentNodes",$this->dhcpParentNodes);
-
-
-
-
-
+    $smarty->assign("dhcpParentNodeCnt",count($this->dhcpParentNodes));
 
     /* There is no dns available 
      */
@@ -288,6 +311,7 @@ class termDNS extends plugin
 
       $smarty->assign("DNSAccount",$this->DNS_is_account);
       $smarty->assign("Zones",$this->Zones);
+      $smarty->assign("ZoneCnt",count($this->Zones));
       $smarty->assign("ZoneKeys",($this->Zones));
       $smarty->assign("IPisMust",(($this->IPisMust)||($this->DNS_is_account)));
 
@@ -339,16 +363,16 @@ class termDNS extends plugin
 
     /* Handle DHCP Posts*/ 
     if($this->dhcpEnabled && isset($_POST['network_tpl_posted'])){
-      if(isset($_POST['dhcp_is_Account'])){
-        $this->dhcp_is_Account = TRUE;
-      }else{
-        $this->dhcp_is_Account = FALSE;
-      }
       foreach($this->dhcpAttributes as $attr){
         if(isset($_POST[$attr])){
           $this->$attr = $_POST[$attr];
         }
       }
+      if(isset($_POST['dhcp_is_Account'])){
+        $this->dhcp_is_Account = TRUE;
+      }else{
+        $this->dhcp_is_Account = FALSE;
+      }
     }
  
  
@@ -392,6 +416,10 @@ class termDNS extends plugin
     /* Call common method to give check the hook */
     $message= plugin::check();
 
+    if($this->dhcpEnabled && $this->dhcp_is_Account && $this->dhcpParentNode != "" && count($this->dhcpHostEntry) == 0){
+      $message[] =_("You have not configured your dhcp settings yet.");
+    }
+
     /* Check if ip must be given
      */  
     if(($this->IPisMust)||($this->DNS_is_account)){
@@ -500,6 +528,70 @@ class termDNS extends plugin
     $this->cleanup();
     $ldap->modify ($this->attrs); 
 
+    /****************/ 
+    /* DHCP HANDLING */
+    /****************/ 
+  
+    /* New entry */
+    if($this->dhcpEnabled){
+
+      /* Unset dhcpStatements if this attribute is empty  */
+      if(isset($this->dhcpHostEntry['dhcpStatements']) && 
+          ($this->dhcpHostEntry['dhcpStatements'] == "" || count($this->dhcpHostEntry['dhcpStatements']) == 0) ){
+        unset($this->dhcpHostEntry['dhcpStatements']);
+      }
+  
+      /* DHCP removed */
+      if($this->initial_dhcp_is_Account && !$this->dhcp_is_Account){
+        $ldap->rmdir_recursive($this->dhcpHostEntry['dn']);
+        show_ldap_error($ldap->get_error(),_("Removing dhcp entry for this object failed."));
+      }
+
+      /* DHCP Added */
+      if(!$this->initial_dhcp_is_Account && $this->dhcp_is_Account){
+        $attrs = $this->dhcpHostEntry;
+        unset($attrs['MODIFIED']);
+        unset($attrs['dn']);
+        $ldap->cd("cn=".$this->cn.",".$this->dhcpParentNode);
+        $res = $ldap->add($attrs);
+#        print_a($attrs);
+#        print("cn=".$this->cn.",".$this->dhcpParentNode);
+        show_ldap_error($ldap->get_error(),_("Tried to add new dhcp entry failed."));
+      }
+
+      /* DHCP still activated */
+      if($this->initial_dhcp_is_Account && $this->dhcp_is_Account){
+
+        /* DHCP node changed */
+        if(($this->initial_dhcpParentNode != $this->dhcpParentNode) || 
+           ($this->cn != $this->OrigCn)){
+          $attrs = $this->dhcpHostEntry;
+          $attrs['cn'] = $this->cn;
+          unset($attrs['dn']);
+          unset($attrs['MODIFIED']);
+          $ldap->cd("cn=".$this->cn.",".$this->dhcpParentNode);
+          $res = $ldap->add($attrs);
+          show_ldap_error($ldap->get_error(),_("Tried to add new dhcp entry failed."));
+          if($res){
+            $ldap->rmdir_recursive($this->dhcpHostEntry['dn']);
+            show_ldap_error($ldap->get_error(),_("Removing old dhcp entry failed."));
+          }
+        }
+         
+        /* SAME node but modified */ 
+        if(isset($this->dhcpHostEntry['MODIFIED']) && $this->dhcpHostEntry['MODIFIED'] == 1  && 
+            $this->initial_dhcpParentNode == $this->dhcpParentNode){
+          $attrs = $this->dhcpHostEntry;
+          unset($attrs['dn']);
+          unset($attrs['MODIFIED']);
+          $ldap->cd($this->dhcpHostEntry['dn']);
+          $ldap->modify($attrs);
+          show_ldap_error($ldap->get_error(),_("Modifying dhcp entry failed."));
+        }    
+      }
+    }
+      
+
     /****************/ 
     /* DNS HANDLING */
     /****************/ 
@@ -515,6 +607,10 @@ class termDNS extends plugin
        */
       if(!empty($this->ipHostNumber)){
         $this->dnsEntry['RECORDS'][] = array("type"=>"aRecord","value"=>$this->ipHostNumber);
+        $ptr = $this->get_pTRRecord();
+        if(!empty($ptr)){
+          $this->dnsEntry['RECORDS'][] = array("type"=>"pTRRecord","value"=>$ptr);
+        }
       }
 
       /* Create diff and follow instructions 
@@ -670,27 +766,49 @@ class termDNS extends plugin
     while($attr = $ldap->fetch()){
       $dhcp_dns[$attr['dn']] = $attr['dhcpPrimaryDN'][0];
     }
-  
     foreach($dhcp_dns as $key => $pri_dns){
       $ldap->cat($pri_dns,array("cn"));
       $tmp = $ldap->fetch();
-      $dhcp_dns[$key] = $tmp['cn'][0];
+      if(isset($tmp['cn'][0])){
+        $dhcp_dns[$key] = $tmp['cn'][0];
+      }else{
+        unset($dhcp_dns[$key]);
+      }
     }
+
+    $tmp = $tmp2 = array();
     foreach($dhcp_dns as $dn => $cn){
       $ldap->cd($dn);
       $ldap->search("(|(objectClass=dhcpService)(objectClass=dhcpGroup)".
                     "(objectClass=dhcpSubnet)(objectClass=dhcpSharedNetwork))",array("cn"));
-      $tmp = array();
       while($attr = $ldap->fetch()){
         $tmp[$attr['dn']] = $attr['cn'][0];
       }
-      $tmp2 = $this->create_tree($tmp,preg_replace("/^[^,]+,/i","",$dn),"(".$cn.") ");
+      $tmp2 = array_merge($tmp2,$this->create_tree($tmp,preg_replace("/^[^,]+,/i","",$dn),"(".$cn.") "));
     }
     return($tmp2);
   }
 
   
+  /* this function returns the default ptr record entry */
+  function get_pTRRecord()
+  {
+    if(!empty($this->ipHostNumber) && isset($this->dnsEntry['zoneName']) && !empty($this->dnsEntry['zoneName'])){
+      $ldap = $this->config->get_ldap_link();
+      $ldap->cat(getDNSZoneDN($this->config,$this->dnsEntry['zoneName']));
+      $attrs = $ldap->fetch();
+      $tmp = array_flip($this->Zones);
+      $tmp = preg_replace("/^[^\/]*+\//","",$tmp[$this->dnsEntry['zoneName']]);
+      $tmp = trim(preg_replace("/\.in-addr.arpa$/","",$tmp));
+      $ptr = preg_replace("/^".normalizePreg(FlipIp($tmp))."\./","",$this->ipHostNumber);
+      return($ptr);
+    }else{
+      return(FALSE);
+    }
+  }
+
+  
   function create_tree($arr,$base,$current = "")
   {
     $ret = array();