Code

Added some changes
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 6 Feb 2006 13:33:29 +0000 (13:33 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 6 Feb 2006 13:33:29 +0000 (13:33 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2628 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_servDNS.inc
plugins/admin/systems/class_servDNSeditZone.inc

index adc3aa6730286c8a310256652a2e9999e552238b..121b4318a4d3f2e93fda3f41e766e18c488cea20 100644 (file)
@@ -48,7 +48,6 @@ class servdns extends plugin
     $this->RecordTypes['nSECRecord']    = "nSECRecord";        // ok
 
     $this->cn = $this->attrs['cn'][0];
-
     $types = array();
 
     /* Get all records */
@@ -63,7 +62,11 @@ class servdns extends plugin
       $this->usedDNS[$attrs['dn']] = $attrs['dn'];
       if((isset($attrs['tXTRecord'][0]))&&(preg_match("/zoneName\=/",$attrs['tXTRecord'][0]))){
         $zoneName= preg_replace("/zoneName\=/","",$attrs['tXTRecord'][0]);  
-        $types[$zoneName]['ReverseZone']  = preg_replace("/\.in\-addr\.arpa/","",$attrs['zoneName'][0]);
+        $z = preg_replace("/\.in\-addr\.arpa/","",$attrs['zoneName'][0]);
+        
+        $z = $this->FlipIp($z);
+
+        $types[$zoneName]['ReverseZone']  = $z;
         $types[$zoneName]['ReverseDN']    = $attrs['dn']; 
       }else{
 
@@ -131,6 +134,16 @@ class servdns extends plugin
     $this->DNSinitially_was_account = $this->is_account;
   }
 
+  function FlipIp($ip)
+  {
+    $tmp = array_reverse(split("\.",$ip));
+    $new = "";
+    foreach($tmp as $section){
+      $new .= $section.".";
+    }
+    return(preg_replace("/.$/","",$new));
+  }
+
   function execute()
   {
     /* Call parent execute */
@@ -155,15 +168,18 @@ class servdns extends plugin
       return ($display);
     }
 
+    /* Edited or Added zone hould be saved saved */
     if(isset($_POST['SaveZoneChanges'])){
       $this->dialog->save_object();
 
+      /* Check if noting went wrong */
       if(count($this->dialog->check())){
         foreach($this->dialog->check() as $msgs){
           print_red($msgs); 
         }
       }else{
-
+      
+        /* add new/edited zone */
         $ret = $this->dialog->save();
         unset($this->Zones[$this->dialog->InitiallyZoneName]);
         $this->Zones[$ret['zoneName']]                  = $ret;
@@ -184,7 +200,8 @@ class servdns extends plugin
     /* Check for edit zone request */
     $once = false;
     foreach( $_POST as $name => $value){
-
+  
+      /* check all post for edit request */
       if(preg_match("/^editZone_/",$name)&&!$once){
         $once =true;
         $tmp = preg_replace("/^editZone_/","",$name);
@@ -192,6 +209,7 @@ class servdns extends plugin
         $this->dialog= new servdnseditZone($this->config,$this->dn,$this->RecordTypes,$this->Zones[$tmp]);
       }
 
+      /* check posts for delete zone */
       if(preg_match("/^delZone_/",$name)&&!$once){
         $once =true;
         $tmp = preg_replace("/^delZone_/","",$name);
@@ -200,6 +218,7 @@ class servdns extends plugin
       }
     }
 
+    /* Show dialog */
     if($this->dialog!= NULL){
       $this->dialog->save_object();
       $this->dialog->parent = $this;
@@ -229,6 +248,7 @@ class servdns extends plugin
     return($display);
   }
 
+  /* Remove dns service */
   function remove_from_parent()
   {
     $ldap = $this->config->get_ldap_link();
@@ -258,13 +278,18 @@ class servdns extends plugin
   /* Save to LDAP */
   function save()
   {
+    /* Ldap conenction / var initialization */
     $ldap = $this->config->get_ldap_link();
     $ldap->cd($this->config->current['BASE']);
-
     $actions =array("update"=>array(),"add"=>array(),"delete"=>array());
 
+    /* Generate entries for all zones, and check if they must be updated deleted added */
     foreach($this->Zones as $zone){
+      
+      /* Get ldap syntax */
       $tmp = $this->generate_LDAP_entries($zone);
+
+      /* Check if dn is new, or if entry was edited */
       foreach($tmp as $key => $values){
         if(isset($this->usedDNS[$key])){
           $actions['update'][$key]=$values;
@@ -274,15 +299,19 @@ class servdns extends plugin
         }
       }
     }
+    
+    /* Check which dns are not used anymore ...*/
     foreach($this->usedDNS as $key => $values){
       $actions['delete'][$key] = $values;
     }
 
+    /* Remove deleted zones */
     foreach($actions['delete'] as $dn => $attrs){
       $ldap->cd($dn);
       $ldap->rmdir_recursive($dn);
     }
 
+    /* Add new zones */
     foreach($actions['add'] as $dn => $attrs){
       $ldap->cd($this->config->current['BASE']);
       //      $ldap->create_missing_trees($dn);
@@ -290,6 +319,7 @@ class servdns extends plugin
       $ldap->add($attrs);
     }
 
+    /* Update existing entries */
     foreach($actions['update'] as $dn => $attrs){
       $ldap->cd($dn);
       $ldap->modify($attrs);
@@ -298,6 +328,9 @@ class servdns extends plugin
   }
 
 
+  /* This function generates ldap friendly output 
+     of all changes for a single zone (reverse and forward)
+   */
   function generate_LDAP_entries($zone)
   {
     $tmp = array();
@@ -313,7 +346,7 @@ class servdns extends plugin
     $tmp['sOARecord'] = $str;
 
 
-    /* Generate some attrs  */
+    /* Generate Record entries  */
     $arr = array("SigRecord","KeyRecord","aAAARecord","nSRecord","iaFSDBRecord","mInfoRecord","hInfoRecord","mXRecord","mDRecord","tXTRecord",
         "LocRecord","nXTRecord","sRVRecord","nAPTRRecord","kXRecord","certRecord","a6Record","dSRecord","sSHFPRecord","rRSIGRecord","nSECRecord");
     $aRecords = array();
@@ -326,6 +359,11 @@ class servdns extends plugin
         }
       }
     }
+    
+    /* Check if there are records removed,
+        if there are some removed records, the append an array        
+        to ensure that these record types are deleted 
+     */
     if((isset($zone['Records']))&&(is_array($zone['Records']))){
       foreach($zone['Records'] as $type){
         if(isset($type['inittype'])){
@@ -335,13 +373,16 @@ class servdns extends plugin
         }
       }
     }
+    /* generate forward entry */
     $dn = "zoneName=".$zone['zoneName'].",".$this->dn; 
     $tmp2[$dn] = $tmp;
     $tmp2[$dn]['zoneName'] = $zone['zoneName'];
-    $dn = "zoneName=".$zone['ReverseZone'].".in-addr.arpa,".$this->dn;
+
+    /* generate reverse entry */
+    $dn = "zoneName=".$this->FlipIp($zone['ReverseZone']).".in-addr.arpa,".$this->dn;
     $tmp2[$dn] = $tmp;
     $tmp2[$dn]['tXTRecord'] ="zoneName=".$zone['zoneName'];
-    $tmp2[$dn]['zoneName'] = $zone['ReverseZone'].".in-addr.arpa";
+    $tmp2[$dn]['zoneName'] = $this->FlipIp($zone['ReverseZone']).".in-addr.arpa";
 
     return($tmp2);
   }
index e8a47f35fb0373fa251ef7c2a3bf4c213a1979a0..49e904d71014f17f1c0fba5573b910628346db4f 100644 (file)
@@ -164,14 +164,25 @@ class servdnseditZone extends plugin
     while($attr = $ldap->fetch()){
       if(preg_match("/in-addr\.arpa/",$attr['zoneName'][0])){
         $zn = preg_replace("/zoneName\=/","",$attr['tXTRecord'][0]);
-        $ret[$zn] = preg_replace("/\.in-addr\.arpa/","",$attr['zoneName'][0]);
+        $ret[$zn] = $this->FlipIp(preg_replace("/\.in-addr\.arpa/","",$attr['zoneName'][0]));
       }else{
         $ret[$attr['zoneName'][0]]="";
       }
     }
     return($ret);
   }
-  
+
+  function FlipIp($ip)
+  {
+    $tmp = array_reverse(split("\.",$ip));
+    $new = "";
+    foreach($tmp as $section){
+      $new .= $section.".";
+    }
+    return(preg_replace("/.$/","",$new));
+  }
+
 
   /* Save to LDAP */
   function save()