Code

Some layer menus
[gosa.git] / include / functions_dns.inc
index 162caeca7123317ad71c30cb84cffa5fdef327b0..7ce7c33efc056d19ae9ff4e64543f95d6e317744 100644 (file)
@@ -247,6 +247,7 @@ function getDNSZoneEntriesDiff($config,$newZones,$HostDn)
       $soa.=" ".$zone[$attr];
     }  
     $obj['sOARecord'] = trim($soa);
+    $obj['nSRecord'] = $zone['sOAprimary'];
 
     /* If reverse zone was renamed, move entry 
      */
@@ -273,6 +274,9 @@ function getDNSZoneEntriesDiff($config,$newZones,$HostDn)
     /* Add new Records 
      */
     foreach($zone['RECORDS'] as $rec){
+      if(!isset($obj[$rec['type']])||!is_array($obj[$rec['type']])){
+        $obj[$rec['type']] = array();
+      }
       $obj[$rec['type']][] = $rec['value'];
     }
 
@@ -303,7 +307,7 @@ function getDNSZoneEntriesDiff($config,$newZones,$HostDn)
    */
   foreach($oldZones as $zone)  {
     $oldDn = "zoneName=".$zone['InitialzoneName'].",".$HostDn;
-    $del[$oldDn] = "";
+    $del[$oldDn] = $zone;
   }
 
   /* Check for entries which must be updated 
@@ -353,7 +357,9 @@ function getDNSHostEntries($config,$name,$silent = false)
   $zonesArr = array();
   foreach($zones as $zoneMix){
        $zoneIndex = split("/",$zoneMix);
-       if(!array_key_exists($zoneIndex[0],$zonesArr)) $zonesArr[$zoneIndex[0]] = array();
+       if(!array_key_exists($zoneIndex[0],$zonesArr)) {
+      $zonesArr[$zoneIndex[0]] = array();
+    }
                array_push($zonesArr[$zoneIndex[0]],$zoneIndex[1]);
   }
   
@@ -364,8 +370,8 @@ function getDNSHostEntries($config,$name,$silent = false)
        $zoneDn = getDNSZoneDN($config,$zoneMix);
        $ldap->ls("(&(objectClass=dNSZone)(zoneName=*)(relativeDomainName=".$name.")(!(relativeDomainName=@)))", $zoneDn,$attrs = array("*"));
        while($attrs = $ldap->fetch()){
-         $foundInTmp [] = $attrs['dn'];
-         $foundIn [] = $attrs['dn'];
+         $foundInTmp [$zoneMix] = $attrs['dn'];
+         $foundIn [$zoneMix] = $attrs['dn'];
        }
        }
   }
@@ -378,7 +384,8 @@ function getDNSHostEntries($config,$name,$silent = false)
 
   /* Get host informations from zone
    */ 
-  $ldap->cd($foundIn[0]);
+  $id_tmp = key($foundIn);
+  $ldap->cd($foundIn[$id_tmp]);
   $ldap->search("(&(objectClass=dNSZone)(zoneName=*)(!(relativeDomainName=@)))",array("*"));
   while($attrs = $ldap->fetch()){
 
@@ -387,7 +394,8 @@ function getDNSHostEntries($config,$name,$silent = false)
      */
     if($attrs['relativeDomainName'][0] == $name){
       $ret['exists'] = true;
-      foreach(array("dNSClass","zoneName","dNSTTL") as $atr){
+      $ret['zoneName'] = $id_tmp;
+      foreach(array("dNSClass","dNSTTL") as $atr){
         if(isset($attrs[$atr][0])){
           $ret[$atr] = $attrs[$atr][0];
         }
@@ -430,6 +438,13 @@ function getDNSHostEntriesDiff($config,$oldName,$newEntry,$newName)
   $del    = array();
   $move   = array();
 
+  /* Don't go further if there is nothing to do
+   * Is no account / was no account
+   */
+  if(($newEntry['exists'] == false )&& ($oldEntry['exists'] == false)){
+    return(array("move"=>$move,"add"=>$add,"del"=>$del));
+  }
+
   $zones              = getAvailableZones($config);
   $specialAttributes  = array("cNAMERecord","pTRRecord");
   $newRecords         = array();  // Used to remember which records are removed 
@@ -451,13 +466,6 @@ function getDNSHostEntriesDiff($config,$oldName,$newEntry,$newName)
     $newEntry['exists'] = false;
   }
 
-  /* Don't go further if there is nothing to do
-   * Is no account / was no account
-   */
-  if(($newEntry['exists'] == false )&& ($oldEntry['exists'] == false)){
-    return(array("move"=>$move,"add"=>$add,"del"=>$del));
-  }
-  
   /* If account was edited prepare some
    *  attributes & arrays ... if required add some 
    *  dns to $move 
@@ -475,7 +483,7 @@ function getDNSHostEntriesDiff($config,$oldName,$newEntry,$newName)
     /* Check if zoneName has changed 
      */   
     if(count($newEntry['RECORDS'])){
-      if($oldEntry['zoneName'] != $zoneName){
+      if($oldEntry['zoneName'] != $newEntry['zoneName']){
         $oldzoneDn = getDNSZoneDN($config,$oldEntry['zoneName']);
         $dn = "relativeDomainName=".$oldName.",".$oldzoneDn;
         $dn2= "relativeDomainName=".$oldName.",".$zoneDn;
@@ -559,12 +567,16 @@ function getDNSHostEntriesDiff($config,$oldName,$newEntry,$newName)
      *  like pTRRecord or CNAMERecord
      */
     if($rec['type']  == "pTRRecord"){
-      $PTRdn= "relativeDomainName=".$rec['value'].",".$baseDn;
+      $PTRdn= "relativeDomainName=".FlipIP($rec['value']).",".$baseDn;
       $ptrObj = $baseObj;
       $reverseName = getNameFromMix($reverseNameMix);
       $ptrObj['zoneName']           = $reverseName;
-      $ptrObj['pTRRecord']          = $newName.".".$zoneName.".";
-      $ptrObj['relativeDomainName'] = $rec['value'];
+      if(!preg_match("/\.$/",$newName)){
+        $ptrObj['pTRRecord']          = preg_replace("/\.\.$/",".",$newName.".".$zoneName.".");
+      }else{
+        $ptrObj['pTRRecord']          = preg_replace("/\.\.$/",".",$newName.".");
+      }
+      $ptrObj['relativeDomainName'] = FlipIP($rec['value']);
     
       $add[$PTRdn] = $ptrObj;
     }else  
@@ -596,20 +608,27 @@ function getNameFromMix($zoneMix){
 
 /* returns the dn for a specified zone
  */
-function getDNSZoneDN($config,$zoneNameMix){
+function getDNSZoneDN($config,$zoneNameMix)
+{
   $ret = "";
-  if(!strstr($zoneNameMix, '/')) return($ret);
+  if(!strstr($zoneNameMix, '/')) {
+    print_red(sprintf(_("Undefined zone name '%s'. Zone name must look like this 'server/zone.com'."),$zoneNameMix));
+    return($ret);
+  }
+
   $zoneNameIndex               = split("/",$zoneNameMix); 
   $zoneName           = $zoneNameIndex[1];
   $nameServer                          = strtolower($zoneNameIndex[0]);
-  $ldap = $config->get_ldap_link();
+  $ldap               = $config->get_ldap_link();
 
   /* search for the nameserver */
   $ldap-> cd($config->current['BASE']);
   $ldap->search("(&(objectClass=goServer)(cn=".$nameServer."))",array("cn"));
   if($ldap->count()){
     $attr = $ldap->fetch();
-  } else  return($ret);
+  } else {
+    return($ret);
+  }
   
   $ldap-> cd($attr['dn']);
   $ldap->search("(&(objectClass=dNSZone)(sOARecord=*)(zoneName=".$zoneName."))",array("zoneName"));