Code

Updated dns stuff.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 17 Jan 2007 06:49:51 +0000 (06:49 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 17 Jan 2007 06:49:51 +0000 (06:49 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@5577 594d385d-05f5-0310-b6e9-bd551577e9d8

include/functions_dns.inc
plugins/admin/systems/class_servDNS.inc
plugins/admin/systems/class_servDNSeditZone.inc
plugins/admin/systems/class_servDNSeditZoneEntries.inc
plugins/admin/systems/class_termDNS.inc

index 4754d822889330a454d624c3e329f075ebbe83da..b8346e26c19b82cf77fbb28a6e6dd51911765253 100644 (file)
@@ -67,7 +67,7 @@ function FlipIp($ip)
 function getDNSZoneEntries($config,$HostDn,$silent = false)
 {
   global $RecordTypes;
+
   $ldap = $config->get_ldap_link();
   $ldap->cd($config->current['BASE']); 
 
@@ -79,6 +79,10 @@ function getDNSZoneEntries($config,$HostDn,$silent = false)
    */
   $sOAREcords  = array("0"=>"sOAprimary","1"=>"sOAmail","2"=>"sOAserial","3"=>"sOArefresh","4"=>"sOAretry","5"=>"sOAexpire","6"=>"sOAttl");
 
+  /* Get host entry */
+  $ldap->cat($HostDn);
+  $host_attr = $ldap->fetch();
+
   /* Create tempalte for all fetched zone Data 
    */
   $ZoneBase = array();
@@ -105,21 +109,20 @@ function getDNSZoneEntries($config,$HostDn,$silent = false)
    */
   foreach($tmp_res as $attrs){
 
-    $zoneName                   = $attrs['zoneName'][0];
+    $zoneName                   = strtoupper($host_attr['cn'][0])."/".$attrs['zoneName'][0];
     $Zones[$zoneName]           = $ZoneBase;
     $Zones[$zoneName]['exists'] = true;
 
     /* Set basic attributes 
      */
-    foreach(array("zoneName","dNSClass") as $attr){
-      if(isset($attrs[$attr][0])){
-        $Zones[$zoneName][$attr] = $attrs[$attr][0];
-      }
+    if(isset($attrs["dNSClass"][0])){
+      $Zones[$zoneName]["dNSClass"] = $attrs["dNSClass"][0];
     }
 
     /* Set initial zone name, to be able to detect if this entry was renamed 
      */
     $Zones[$zoneName]['InitialzoneName'] = $zoneName;
+    $Zones[$zoneName]['zoneName'] = $zoneName;
 
     /* Generate SOA entry
      */
@@ -173,8 +176,8 @@ function getDNSZoneEntries($config,$HostDn,$silent = false)
       unset($Zones[$zoneName]);
     }else{
       $tmp = $ldap->fetch();
-      $Zones[$zoneName]['ReverseZone']        = FlipIp(str_replace(".in-addr.arpa","",$tmp['zoneName'][0]));
-      $Zones[$zoneName]['InitialReverseZone'] = FlipIp(str_replace(".in-addr.arpa","",$tmp['zoneName'][0]));
+      $Zones[$zoneName]['ReverseZone']        = strtoupper($host_attr['cn'][0])."/".FlipIp(str_replace(".in-addr.arpa","",$tmp['zoneName'][0]));
+      $Zones[$zoneName]['InitialReverseZone'] = strtoupper($host_attr['cn'][0])."/".FlipIp(str_replace(".in-addr.arpa","",$tmp['zoneName'][0]));
     }
   }
   return($Zones);
@@ -221,9 +224,9 @@ function getDNSZoneEntriesDiff($config,$newZones,$HostDn)
       
       /* Move old zone to new position 
        */ 
-      $oldDn = "zoneName=".$zone['InitialzoneName'].",".$HostDn;
-      $newDn = "zoneName=".$zone['zoneName'].",".$HostDn;
-      $PrePareZoneEntries[$zone['InitialzoneName']] = $zone['zoneName'];
+      $oldDn = "zoneName=".getNameFromMix($zone['InitialzoneName']).",".$HostDn;
+      $newDn = "zoneName=".getNameFromMix($zone['zoneName']).",".$HostDn;
+      $PrePareZoneEntries[$zone['InitialzoneName']] = getNameFromMix($zone['zoneName']);
       $move [$oldDn] = $newDn;      
     }
 
@@ -236,9 +239,9 @@ function getDNSZoneEntriesDiff($config,$newZones,$HostDn)
 
     /* Create forward zone entry and put it in our add queue
      */
-    $newDn  = "zoneName=".$zone['zoneName'].",".$HostDn;
+    $newDn  = "zoneName=".getNameFromMix($zone['zoneName']).",".$HostDn;
     $obj    =  $zoneBase;
-    $obj['zoneName'] = $zone['zoneName'];
+    $obj['zoneName'] = getNameFromMix($zone['zoneName']);
  
     /* Create sOARecord & add it to the obj
      */ 
@@ -252,9 +255,9 @@ function getDNSZoneEntriesDiff($config,$newZones,$HostDn)
      */
     if(!empty($zone['InitialReverseZone'])){
       if($zone['InitialReverseZone'] != $zone['ReverseZone']){
-        $base = "zoneName=".$zone['zoneName'].",".$HostDn;
-        $oldRDn = "zoneName=". FlipIp($zone['InitialReverseZone']).".in-addr.arpa,".$base; 
-        $newRDn = "zoneName=". FlipIp($zone['ReverseZone']).".in-addr.arpa,".$base;
+        $base = "zoneName=".getNameFromMix($zone['zoneName']).",".$HostDn;
+        $oldRDn = "zoneName=". FlipIp(getNameFromMix($zone['InitialReverseZone'])).".in-addr.arpa,".$base; 
+        $newRDn = "zoneName=". FlipIp(getNameFromMix($zone['ReverseZone'])).".in-addr.arpa,".$base;
         $PrePareZoneEntries[FlipIp($zone['InitialReverseZone']).".in-addr.arpa"] = FlipIp($zone['ReverseZone']).".in-addr.arpa";
         $move [$oldRDn] = $newRDn;
       }
@@ -283,8 +286,8 @@ function getDNSZoneEntriesDiff($config,$newZones,$HostDn)
     /* Create Reverse Entry 
      * And append it to our add queue
      */
-    $zone['ReverseZone'] = FlipIp($zone['ReverseZone']).".in-addr.arpa";
-    $base = "zoneName=".$zone['zoneName'].",".$HostDn;
+    $zone['ReverseZone'] = FlipIp(getNameFromMix($zone['ReverseZone'])).".in-addr.arpa";
+    $base = "zoneName=".getNameFromMix($zone['zoneName']).",".$HostDn;
     $newRDn = "zoneName=".$zone['ReverseZone'].",".$base;
     $rObj = $obj;
     $rObj['zoneName']= $zone['ReverseZone'];
@@ -302,7 +305,7 @@ function getDNSZoneEntriesDiff($config,$newZones,$HostDn)
    *  because they are no longer available in newZones anymore.
    */
   foreach($oldZones as $zone)  {
-    $oldDn = "zoneName=".$zone['InitialzoneName'].",".$HostDn;
+    $oldDn = "zoneName=".getNameFromMix($zone['InitialzoneName']).",".$HostDn;
     $del[$oldDn] = "";
   }
 
@@ -314,7 +317,7 @@ function getDNSZoneEntriesDiff($config,$newZones,$HostDn)
     $ldap = $config->get_ldap_link();
     foreach($PrePareZoneEntries as $FromZoneName => $ToZoneName){
       $ldap->cd($HostDn);
-      $ldap->search("(&(objectClass=dNSZone)(zoneName=".$FromZoneName.")(!(relativeDomainName=@)))",array("zoneName"));
+      $ldap->search("(&(objectClass=dNSZone)(zoneName=".getNameFromMix($FromZoneName).")(!(relativeDomainName=@)))",array("zoneName"));
       while($attrs = $ldap->fetch()){
         $zoneUpdates[$attrs['dn']] = array("zoneName"=>$ToZoneName);
       }
index c63fd9b1c947872ad51b66c2d07da7cc8d663185..a500ce84b9df35f64b12e6bc54d4af218ea0dde6 100644 (file)
@@ -34,7 +34,7 @@ class servdns extends plugin
     /* Get all zone Informations
      */
     $this->Zones = getDNSZoneEntries($config,$dn);
-    
+  
     /* If there is at least one entry in this -> types, we have DNS enabled 
      */
     if(count($this->Zones) == 0){
@@ -83,7 +83,7 @@ class servdns extends plugin
 
     /* Edited or Added zone 
      */
-    if(isset($_POST['SaveZoneChanges'])){
+    if((isset($_POST['SaveZoneChanges'])) && is_object($this->dialog)){
       $this->dialog->save_object();
 
       /* Check for errors  
@@ -163,11 +163,11 @@ class servdns extends plugin
       <input type='image' src='images/edittrash.png' name='delZone_%s'>";
     foreach($this->Zones as $zone => $values ){
       $ZoneList->AddEntry(array(
-            array("string" => $zone),
-            array("string" => _("Reverse zone")." : ".$values['ReverseZone']),
+            array("string" => getNameFromMix($zone)),
+            array("string" => _("Reverse zone")." : ".getNameFromMix($values['ReverseZone'])),
             array("string" => _("TTL")." : ".$values['sOAttl']),
             array("string" => _("Class")." : ".$values['dNSClass']),
-            array("string" =>str_replace("%s",base64_encode($zone),$editImg))
+            array("string" => str_replace("%s",base64_encode($zone),$editImg))
             ));
     }    
   
@@ -186,16 +186,17 @@ class servdns extends plugin
   function RemoveZone($id)
   {
     $zones =  $this->getUsedZoneNames();
-
+    $rev  ="";
+  
     if(isset($this->Zones[$id]['InitialReverseZone'])){
-      $rev = FlipIp($this->Zones[$id]['InitialReverseZone']);
-    }else{
-      $rev = FlipIp($this->Zones[$id]['ReverseZone']);
+      $rev = FlipIp(getNameFromMix($this->Zones[$id]['InitialReverseZone']));
+    }elseif(isset($this->Zones[$id]['ReverseZone'])){
+      $rev = FlipIp(getNameFromMix($this->Zones[$id]['ReverseZone']));
     }
 
     $zonename = "";
     if(isset($this->Zones[$id]['InitialzoneName'])){
-      $zonename= $this->Zones[$id]['InitialzoneName'];
+      $zonename= getNameFromMix($this->Zones[$id]['InitialzoneName']);
     }
 
     $used = array();
@@ -283,7 +284,13 @@ class servdns extends plugin
   
     /* Get differences 
      */
-    $tmp = getDNSZoneEntriesDiff($this->config,$this->Zones,$this->orig_dn);
+
+    $old_dn =  $this->orig_dn;
+    if($old_dn == "new"){
+      $old_dn = $this->dn;
+    }
+  
+    $tmp = getDNSZoneEntriesDiff($this->config,$this->Zones,$old_dn);
 
     /* Updated zone entries if reverser or forward name has changed  
      * Must be done before moving entries, else the given dn is invalid
index f8866b2defa0f5970a56d455ec87748b6178d77f..6bfe99c8217e54c8603a3d621c07a32f2efb476d 100644 (file)
@@ -9,7 +9,7 @@ class servdnseditZone extends plugin
 
   /* attribute list for save action */
   var $ignore_account= TRUE;
-  var $attributes     = array("zoneName","ReverseZone","dNSClass",
+  var $attributes     = array("zoneName","ReverseZone","dNSClass","cn",
       "sOAprimary","sOAmail","sOAserial","sOArefresh","sOAretry","sOAexpire","sOAttl"); 
   var $objectclasses  = array("whatever");
 
@@ -39,7 +39,7 @@ class servdnseditZone extends plugin
   var $dialog                   = false;
 
   var $isNew                    = true;
-
+  var $cn;
   var $ZoneObject               = array();
 
   function servdnseditZone ($config, $dn= NULL,$attrs = array())
@@ -69,7 +69,9 @@ class servdnseditZone extends plugin
       $this->isNew                  = false;
 
       foreach($this->attributes as $value){
-        $this->$value = $attrs[$value];
+        if(isset($attrs[$value])){
+          $this->$value = $attrs[$value];
+        }
       }
       if(isset($attrs['RECORDS'])){
         $this->Records = $attrs['RECORDS']; 
@@ -281,6 +283,10 @@ class servdnseditZone extends plugin
       $smarty->assign($name,$this->$name);
     }
 
+    /* Set zoneNames without server suffix */
+    foreach(array("zoneName","ReverseZone") as $attr){
+      $smarty->assign($attr,getNameFromMix($this->$attr));
+    }
 
     $div = new DivSelectBox("MxRecords");
     $div->setHeight(120);
@@ -327,6 +333,12 @@ class servdnseditZone extends plugin
       }
     }
 
+    foreach(array("zoneName","ReverseZone") as $attr){
+      if(isset($_POST[$attr])){
+        $this->$attr = strtoupper($this->cn)."/".$_POST[$attr];
+      }
+    }
+
     foreach($this->Records as $id => $value){  
       if(isset($_POST['RecordTypeSelectedFor_'.$id])){
         $this->Records[$id]['type'] = $_POST['RecordTypeSelectedFor_'.$id];
@@ -379,7 +391,7 @@ class servdnseditZone extends plugin
       $message[] = _("Your mail address contains '@' replace this with '.' to enable GOsa to create a valid SOA record.");
     }
 
-    if($this->zoneName != strtolower($this->zoneName)){
+    if(getNameFromMix($this->zoneName) != strtolower(getNameFromMix($this->zoneName))){
       $message[] = _("Only lowercase strings are allowed as zone name.");
     }
 
index 89b4538e7a9632141cba2e766718db499231966a..385041b425f63839c60b8817243bb95a92cdcb52 100644 (file)
@@ -29,9 +29,9 @@ class servDNSeditZoneEntries extends plugin
     /* Initialise class
      */
     $this->RecordTypes  = getDnsRecordTypes();
-    $this->dn           = "zoneName=".$zoneObject['InitialzoneName'].",".$dn; 
-    $this->zoneName     = strtoupper($this->cn)."/".$zoneObject['InitialzoneName'];
-    $this->reverseName  = strtoupper($this->cn)."/".$zoneObject['InitialReverseZone'];
+    $this->dn           = "zoneName=".getNameFromMix($zoneObject['InitialzoneName']).",".$dn; 
+    $this->zoneName     = $zoneObject['InitialzoneName'];
+    $this->reverseName  = $zoneObject['InitialReverseZone'];
 
     /* Get ldap connection 
      */
index 19bf04da805af27f57f47fefc2a955c19b614dd9..d3c614a88331bd549b3dc65195652bcd9e6f2958 100644 (file)
@@ -389,7 +389,7 @@ class termDNS extends plugin
     /* If isn't DNS account but initially was DNS account 
        remove all DNS entries 
      */ 
-    if(!$this->DNSenabled){
+    if((!$this->DNSenabled) || (!$this->DNS_is_account && !$this->DNSinitially_was_account)){
       return;
     }else{