Code

Updated dns class.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 16 Jan 2008 07:50:49 +0000 (07:50 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 16 Jan 2008 07:50:49 +0000 (07:50 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8377 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/include/functions_dns.inc
gosa-core/plugins/admin/systems/services/dns/class_servDNS.inc
gosa-core/plugins/admin/systems/services/dns/class_servDNSeditZone.inc
gosa-core/plugins/admin/systems/services/dns/class_servDNSeditZoneEntries.inc
gosa-core/plugins/admin/systems/services/dns/class_termDNS.inc

index f758f9a40f42b52dfa03ac2a96a3d0f9a5610ad4..c560c36ac0b63afdbf76f7d08c7982ee1d97fc26 100644 (file)
@@ -28,657 +28,659 @@ $RecordTypes['sSHFPRecord']   = "sSHFPRecord";
 $RecordTypes['rRSIGRecord']   = "rRSIGRecord";      
 $RecordTypes['nSECRecord']    = "nSECRecord";       
 
-
-/* Return all record types 
- */
-function getDnsRecordTypes($ForZones = false)
+class DNS
 {
-  global $RecordTypes;
-  if($ForZones){
-    $tmp = $RecordTypes;
-    unset($tmp['cNAMERecord']);
-    unset($tmp['pTRRecord']);
-    unset($tmp['tXTRecord']);
-    return($tmp);
-  }else{
-    return($RecordTypes);
-  }
-}
 
-
-/* This fucntion is used to flip the ip address, for example
-   12.3.45  ->  45.3.12
-   Because some entries (like zones) are store like that 45.3.12.in-addr.arpa
-   but we want to display 12.3.45.
- */
-function FlipIp($ip)
-{
-  $tmp = array_reverse(split("\.",$ip));
-  $new = "";
-  foreach($tmp as $section){
-    $new .= $section.".";
+  /* Return all record types 
+   */
+  static function getDnsRecordTypes($ForZones = false)
+  {
+    global $RecordTypes;
+    if($ForZones){
+      $tmp = $RecordTypes;
+      unset($tmp['cNAMERecord']);
+      unset($tmp['pTRRecord']);
+      unset($tmp['tXTRecord']);
+      return($tmp);
+    }else{
+      return($RecordTypes);
+    }
   }
-  return(preg_replace("/.$/","",$new));
-}
 
 
-/* This function returns the zones specified for given host
- */
-function getDNSZoneEntries($config,$HostDn,$silent = false)
-{
-  global $RecordTypes;
-  $ldap = $config->get_ldap_link();
-  $ldap->cd($config->current['BASE']); 
-
-  /* Not all records are allowed within a zone entry
-   */  
-  $SkipRecords = array("tXTRecord","cNAMERecord","pTRRecord");
-
-  /* Special sOArecords 
-   */
-  $sOAREcords  = array("0"=>"sOAprimary","1"=>"sOAmail","2"=>"sOAserial","3"=>"sOArefresh","4"=>"sOAretry","5"=>"sOAexpire","6"=>"sOAttl");
-
-  /* Create tempalte for all fetched zone Data 
+  /* This fucntion is used to flip the ip address, for example
+     12.3.45  ->  45.3.12
+     Because some entries (like zones) are store like that 45.3.12.in-addr.arpa
+     but we want to display 12.3.45.
    */
-  $ZoneBase = array();
-  $ZoneBase['exists']  = false;
-  $ZoneBase['RECORDS'] = array();
-  $ZoneBase['zoneName'] = array();
-  $ZoneBase['dNSClass'] = array();
-   
-  foreach($sOAREcords as $attr){
-    $ZoneBase[$attr] = "";
+  static function FlipIp($ip)
+  {
+    $tmp = array_reverse(split("\.",$ip));
+    $new = "";
+    foreach($tmp as $section){
+      $new .= $section.".";
+    }
+    return(preg_replace("/.$/","",$new));
   }
-  $Zones    = array();
 
-  /* Get & Parse all zone entries 
-   */
-  $ldap->ls("(&(objectClass=dNSZone)(zoneName=*)(relativeDomainName=@))",$HostDn,array("*"));
-  $tmp_res = array();
-  while($attrs = $ldap->fetch()) {
-    $tmp_res[] = $attrs;
-  }
 
-  /* Parse fetched zones 
+  /* This static function returns the zones specified for given host
    */
-  foreach($tmp_res as $attrs){
+  static function getDNSZoneEntries($config,$HostDn,$silent = false)
+  {
+    global $RecordTypes;
 
-    $zoneName                   = $attrs['zoneName'][0];
-    $Zones[$zoneName]           = $ZoneBase;
-    $Zones[$zoneName]['exists'] = true;
+    $ldap = $config->get_ldap_link();
+    $ldap->cd($config->current['BASE']); 
 
-    /* Set basic attributes 
+    /* Not all records are allowed within a zone entry
+     */  
+    $SkipRecords = array("tXTRecord","cNAMERecord","pTRRecord");
+
+    /* Special sOArecords 
      */
-    foreach(array("zoneName","dNSClass") as $attr){
-      if(isset($attrs[$attr][0])){
-        $Zones[$zoneName][$attr] = $attrs[$attr][0];
-      }
+    $sOAREcords  = array("0"=>"sOAprimary","1"=>"sOAmail","2"=>"sOAserial","3"=>"sOArefresh","4"=>"sOAretry","5"=>"sOAexpire","6"=>"sOAttl");
+
+    /* Create tempalte for all fetched zone Data 
+     */
+    $ZoneBase = array();
+    $ZoneBase['exists']  = false;
+    $ZoneBase['RECORDS'] = array();
+    $ZoneBase['zoneName'] = array();
+    $ZoneBase['dNSClass'] = array();
+
+    foreach($sOAREcords as $attr){
+      $ZoneBase[$attr] = "";
     }
 
-    /* Set initial zone name, to be able to detect if this entry was renamed 
+    $Zones    = array();
+
+    /* Get & Parse all zone entries 
      */
-    $Zones[$zoneName]['InitialzoneName'] = $zoneName;
+    $ldap->ls("(&(objectClass=dNSZone)(zoneName=*)(relativeDomainName=@))",$HostDn,array("*"));
+    $tmp_res = array();
+    while($attrs = $ldap->fetch()) {
+      $tmp_res[] = $attrs;
+    }
 
-    /* Generate SOA entry
+    /* Parse fetched zones 
      */
-    if(isset($attrs['sOARecord'][0])){
-      $tmp = split("\ ",$attrs['sOARecord'][0]) ;
-      $tmp2 = array();
-
-      /* Assign soa vars */
-      foreach($sOAREcords as $key => $name){
-        if(isset($tmp[$key])){
-          $Zones[$zoneName][$name] = $tmp[$key];
-        }else{
-          $Zones[$zoneName][$name] = "";
+    foreach($tmp_res as $attrs){
+
+      $zoneName                   = $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];
         }
       }
-    } // ENDE SOA Record 
-  
-    /* Get record attributes 
-    */
-    foreach($RecordTypes as $name => $value){
-  
-      /* Skip some attributes 
+
+      /* Set initial zone name, to be able to detect if this entry was renamed 
        */
-      if(in_array($name,$SkipRecords)) continue;
+      $Zones[$zoneName]['InitialzoneName'] = $zoneName;
 
-      /* If there is a record attribute
+      /* Generate SOA entry
        */
-      if(isset($attrs[$name])){
+      if(isset($attrs['sOARecord'][0])){
+        $tmp = split("\ ",$attrs['sOARecord'][0]) ;
+        $tmp2 = array();
+
+        /* Assign soa vars */
+        foreach($sOAREcords as $key => $name){
+          if(isset($tmp[$key])){
+            $Zones[$zoneName][$name] = $tmp[$key];
+          }else{
+            $Zones[$zoneName][$name] = "";
+          }
+        }
+      } // ENDE SOA Record 
 
-        /* get all entries
+      /* Get record attributes 
+       */
+      foreach($RecordTypes as $name => $value){
+
+        /* Skip some attributes 
+         */
+        if(in_array($name,$SkipRecords)) continue;
+
+        /* If there is a record attribute
          */
-        for($i = 0 ; $i < $attrs[$value]['count']; $i ++){
-          $Zones[$zoneName]['RECORDS'][] =  array("type"=>$name,"value"=>$attrs[$value][$i]);
+        if(isset($attrs[$name])){
+
+          /* get all entries
+           */
+          for($i = 0 ; $i < $attrs[$value]['count']; $i ++){
+            $Zones[$zoneName]['RECORDS'][] =  array("type"=>$name,"value"=>$attrs[$value][$i]);
+          }
         }
       }
-    }
 
-    /* Get reverse record ..
-     */
-    $ldap->ls("(&(objectClass=dNSZone)(relativeDomainName=@)(zoneName=*))",$attrs['dn'],array("zoneName"));
+      /* Get reverse record ..
+       */
+      $ldap->ls("(&(objectClass=dNSZone)(relativeDomainName=@)(zoneName=*))",$attrs['dn'],array("zoneName"));
 
-    if($ldap->count() == 0){
-      if(!$silent){
-        msg_dialog::display(_("Error"), sprintf(_("Cannot find reverse zone for DNS zone '%s'. Parsing zone aborted."),$zoneName), ERROR_DIALOG);
-      }
-      unset($Zones[$zoneName]);
-    }elseif($ldap->count()>1){
-      if(!$silent){
-        msg_dialog::display(_("Error"), sprintf(_("Found more than one reverse zone for '%s'. Parsing zone aborted."),$zoneName), ERROR_DIALOG);
+      if($ldap->count() == 0){
+        if(!$silent){
+          msg_dialog::display(_("Error"), sprintf(_("Cannot find reverse zone for DNS zone '%s'. Parsing zone aborted."),$zoneName), ERROR_DIALOG);
+        }
+        unset($Zones[$zoneName]);
+      }elseif($ldap->count()>1){
+        if(!$silent){
+          msg_dialog::display(_("Error"), sprintf(_("Found more than one reverse zone for '%s'. Parsing zone aborted."),$zoneName), ERROR_DIALOG);
+        }
+        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]));
       }
-      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]));
     }
+    return($Zones);
   }
-  return($Zones);
-}
 
 
-/* This function compares two dns zone objects and returns an 
- *  array with following indexes 
- *   - delete, for dns which must be deleted (only if dns zone is removed)
- *   - rename, if a dn must be renamed, for example, the zoneName has changed
- *   - add,    if there is a new dns account created    
- */
-function getDNSZoneEntriesDiff($config,$newZones,$HostDn)
-{
-  $oldZones = getDNSZoneEntries($config,$HostDn,true);
-  
-  $sOAattributes =  array("sOAprimary","sOAmail","sOAserial","sOArefresh","sOAretry","sOAexpire","sOAttl");
+  /* This static function compares two dns zone objects and returns an 
+   *  array with following indexes 
+   *   - delete, for dns which must be deleted (only if dns zone is removed)
+   *   - rename, if a dn must be renamed, for example, the zoneName has changed
+   *   - add,    if there is a new dns account created    
+   */
+  static function getDNSZoneEntriesDiff($config,$newZones,$HostDn)
+  {
+    $oldZones = getDNSZoneEntries($config,$HostDn,true);
 
-  $move   = array();
-  $add    = array();
-  $del    = array();
+    $sOAattributes =  array("sOAprimary","sOAmail","sOAserial","sOArefresh","sOAretry","sOAexpire","sOAttl");
 
-  /* Generate a template for zones with default values
-   */
-  $zoneBase                       = array();
-  $zoneBase['objectClass']        = array("top","dNSZone");
-  $zoneBase['zoneName']           = "";
-  $zoneBase['relativeDomainName'] = "@";
-  $zoneBase['dNSClass']           = "IN";
-  $zoneBase['sOARecord']          = "";
-
-  /* Contains all renamed zoneNames 
-   * For zone entry udpdates
-   */
-  $PrePareZoneEntries = array();
-  
-  /* Walk through all zones and detect renamed/added/deleted zones ... 
-   */
-  foreach($newZones as $name => $zone){
-    
-    /* This zone was renamed 
-     */
-    if((!empty($zone['InitialzoneName'])) && ($zone['InitialzoneName'] != $zone['zoneName'])){
-      
-      /* Move old zone to new position 
-       */ 
-      $oldDn = "zoneName=".$zone['InitialzoneName'].",".$HostDn;
-      $newDn = "zoneName=".$zone['zoneName'].",".$HostDn;
-      $PrePareZoneEntries[$zone['InitialzoneName']] = $zone['zoneName'];
-      $move [$oldDn] = $newDn;      
-    }
+    $move   = array();
+    $add    = array();
+    $del    = array();
 
-    /* Get old zone if available
+    /* Generate a template for zones with default values
      */
-    $oldZone=array();
-    if(!empty($oldZones[$zone['InitialzoneName']])){
-      $oldZone = $oldZones[$zone['InitialzoneName']];
-    }
-
-    /* Create forward zone entry and put it in our add queue
+    $zoneBase                       = array();
+    $zoneBase['objectClass']        = array("top","dNSZone");
+    $zoneBase['zoneName']           = "";
+    $zoneBase['relativeDomainName'] = "@";
+    $zoneBase['dNSClass']           = "IN";
+    $zoneBase['sOARecord']          = "";
+
+    /* Contains all renamed zoneNames 
+     * For zone entry udpdates
      */
-    $newDn  = "zoneName=".$zone['zoneName'].",".$HostDn;
-    $obj    =  $zoneBase;
-    $obj['zoneName'] = $zone['zoneName'];
-    /* Create sOARecord & add it to the obj
-     */ 
-    $soa = "";
-    foreach($sOAattributes as $attr){
-      $soa.=" ".$zone[$attr];
-    }  
-    $obj['sOARecord'] = trim($soa);
-    $obj['nSRecord'] = $zone['sOAprimary'];
-
-    /* If reverse zone was renamed, move entry 
+    $PrePareZoneEntries = array();
+
+    /* Walk through all zones and detect renamed/added/deleted zones ... 
      */
-    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;
-        $PrePareZoneEntries[FlipIp($zone['InitialReverseZone']).".in-addr.arpa"] = FlipIp($zone['ReverseZone']).".in-addr.arpa";
-        $move [$oldRDn] = $newRDn;
+    foreach($newZones as $name => $zone){
+
+      /* This zone was renamed 
+       */
+      if((!empty($zone['InitialzoneName'])) && ($zone['InitialzoneName'] != $zone['zoneName'])){
+
+        /* Move old zone to new position 
+         */ 
+        $oldDn = "zoneName=".$zone['InitialzoneName'].",".$HostDn;
+        $newDn = "zoneName=".$zone['zoneName'].",".$HostDn;
+        $PrePareZoneEntries[$zone['InitialzoneName']] = $zone['zoneName'];
+        $move [$oldDn] = $newDn;      
       }
-    }
 
-    /* Append record entries 
-     *  Set old value to array, to ensure that 
-     *  they will be deleted if necessary
-     */
-    if(isset($oldZone['RECORDS'])){
-      foreach($oldZone['RECORDS'] as $rec){
-        $obj[$rec['type']] = array();
+      /* Get old zone if available
+       */
+      $oldZone=array();
+      if(!empty($oldZones[$zone['InitialzoneName']])){
+        $oldZone = $oldZones[$zone['InitialzoneName']];
       }
-    }
 
-    /* Add new Records 
-     */
-    foreach($zone['RECORDS'] as $rec){
-      if(!isset($obj[$rec['type']])||!is_array($obj[$rec['type']])){
-        $obj[$rec['type']] = array();
+      /* Create forward zone entry and put it in our add queue
+       */
+      $newDn  = "zoneName=".$zone['zoneName'].",".$HostDn;
+      $obj    =  $zoneBase;
+      $obj['zoneName'] = $zone['zoneName'];
+
+      /* Create sOARecord & add it to the obj
+       */ 
+      $soa = "";
+      foreach($sOAattributes as $attr){
+        $soa.=" ".$zone[$attr];
+      }  
+      $obj['sOARecord'] = trim($soa);
+      $obj['nSRecord'] = $zone['sOAprimary'];
+
+      /* If reverse zone was renamed, move entry 
+       */
+      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;
+          $PrePareZoneEntries[FlipIp($zone['InitialReverseZone']).".in-addr.arpa"] = FlipIp($zone['ReverseZone']).".in-addr.arpa";
+          $move [$oldRDn] = $newRDn;
+        }
       }
-      $obj[$rec['type']][] = $rec['value'];
-    }
 
-    /* Append udpated Zone Forward Entry to our add queue
-     */    
-    $add[$newDn] = $obj;   
+      /* Append record entries 
+       *  Set old value to array, to ensure that 
+       *  they will be deleted if necessary
+       */
+      if(isset($oldZone['RECORDS'])){
+        foreach($oldZone['RECORDS'] as $rec){
+          $obj[$rec['type']] = array();
+        }
+      }
 
-    /* Create Reverse Entry 
-     * And append it to our add queue
-     */
-    $zone['ReverseZone'] = FlipIp($zone['ReverseZone']).".in-addr.arpa";
-    $base = "zoneName=".$zone['zoneName'].",".$HostDn;
-    $newRDn = "zoneName=".$zone['ReverseZone'].",".$base;
-    $rObj = $obj;
-    $rObj['zoneName']= $zone['ReverseZone'];
-    $add[$newRDn] = $rObj;
-    /* Remove currently managed zone from oldZones.
-     *  this gives us the ability to detect removed zones
-     */
-    if(isset($oldZones[$zone['InitialzoneName']])){
-      unset($oldZones[$zone['InitialzoneName']]); 
-    }
-  }
-  /* The rest of our oldZones must be deleted
-   *  because they are no longer available in newZones anymore.
-   */
-  foreach($oldZones as $zone)  {
-    $oldDn = "zoneName=".$zone['InitialzoneName'].",".$HostDn;
-    $del[$oldDn] = $zone;
-  }
+      /* 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'];
+      }
 
-  /* Check for entries which must be updated 
-   */
-  $zoneUpdates = array();
-  $udpate = array();
-  if(count($PrePareZoneEntries)){
-    $ldap = $config->get_ldap_link();
-    foreach($PrePareZoneEntries as $FromZoneName => $ToZoneName){
-      $ldap->cd($HostDn);
-      $ldap->search("(&(objectClass=dNSZone)(zoneName=".$FromZoneName.")(!(relativeDomainName=@)))",array("zoneName"));
-      while($attrs = $ldap->fetch()){
-        $zoneUpdates[$attrs['dn']] = array("zoneName"=>$ToZoneName);
+      /* Append udpated Zone Forward Entry to our add queue
+       */    
+      $add[$newDn] = $obj;   
+
+      /* Create Reverse Entry 
+       * And append it to our add queue
+       */
+      $zone['ReverseZone'] = FlipIp($zone['ReverseZone']).".in-addr.arpa";
+      $base = "zoneName=".$zone['zoneName'].",".$HostDn;
+      $newRDn = "zoneName=".$zone['ReverseZone'].",".$base;
+      $rObj = $obj;
+      $rObj['zoneName']= $zone['ReverseZone'];
+      $add[$newRDn] = $rObj;
+
+      /* Remove currently managed zone from oldZones.
+       *  this gives us the ability to detect removed zones
+       */
+      if(isset($oldZones[$zone['InitialzoneName']])){
+        unset($oldZones[$zone['InitialzoneName']]); 
       }
     }
-  }
-
-  $ret = array("del" => $del , "move" => $move , "add" => $add,"zoneUpdates"=>$zoneUpdates);
-  return($ret);
-}
 
+    /* The rest of our oldZones must be deleted
+     *  because they are no longer available in newZones anymore.
+     */
+    foreach($oldZones as $zone)  {
+      $oldDn = "zoneName=".$zone['InitialzoneName'].",".$HostDn;
+      $del[$oldDn] = $zone;
+    }
 
-/* This function returns the dns-host eintries for given 
- *  name.
- */
-function getDNSHostEntries($config,$name,$silent = false)
-{
-  global $RecordTypes;
-
-  $types = array();
-  $ret = array();
-  $ret['RECORDS']   = array();
-  $ret['dNSClass']  = "IN";
-  $ret['zoneName']  = "";
-  $ret['dNSTTL']    = "7440";
-  $ret['exists']    = false;
-  $ldap = $config->get_ldap_link();
-  $ldap->cd($config->current['BASE']);
-  
-  /* First check all zones for an entry with the given name.
-   * If the name occurs in more than one entry alert the user ...
-   */
-  $foundIn = array();
-  $zones = getAvailableZones($config);
-  
-  $zonesArr = array();
-  foreach($zones as $zoneMix){
-       $zoneIndex = split("/",$zoneMix);
-       if(!array_key_exists($zoneIndex[0],$zonesArr)) {
-      $zonesArr[$zoneIndex[0]] = array();
+    /* Check for entries which must be updated 
+     */
+    $zoneUpdates = array();
+    $udpate = array();
+    if(count($PrePareZoneEntries)){
+      $ldap = $config->get_ldap_link();
+      foreach($PrePareZoneEntries as $FromZoneName => $ToZoneName){
+        $ldap->cd($HostDn);
+        $ldap->search("(&(objectClass=dNSZone)(zoneName=".$FromZoneName.")(!(relativeDomainName=@)))",array("zoneName"));
+        while($attrs = $ldap->fetch()){
+          $zoneUpdates[$attrs['dn']] = array("zoneName"=>$ToZoneName);
+        }
+      }
     }
-               array_push($zonesArr[$zoneIndex[0]],$zoneIndex[1]);
-  }
-  
-  foreach($zonesArr as $nameServer => $nameServerArr){
-       $foundInTmp = array();
-       foreach($nameServerArr as $zoneArr => $zone){
-               $zoneMix = $nameServer."/".$zone;
-       $zoneDn = getDNSZoneDN($config,$zoneMix);
-       $ldap->ls("(&(objectClass=dNSZone)(zoneName=*)(relativeDomainName=".$name.")(!(relativeDomainName=@)))", $zoneDn,$attrs = array("*"));
-       while($attrs = $ldap->fetch()){
-         $foundInTmp [$zoneMix] = $attrs['dn'];
-         $foundIn [$zoneMix] = $attrs['dn'];
-       }
-       }
-  }
 
-  /* No zone found which contains an entry for us
-   */
-  if(count($foundIn) == 0){
+    $ret = array("del" => $del , "move" => $move , "add" => $add,"zoneUpdates"=>$zoneUpdates);
     return($ret);
   }
 
-  /* Get host informations from zone
-   */ 
-  $id_tmp = key($foundIn);
-  $ldap->cd($foundIn[$id_tmp]);
-  $ldap->search("(&(objectClass=dNSZone)(zoneName=*)(!(relativeDomainName=@)))",array("*"));
-  while($attrs = $ldap->fetch()){
 
-    /* If relative domainname == cn
-     * Try to read dnsclass / TTl / zone
+  /* This static function returns the dns-host eintries for given 
+   *  name.
+   */
+  static function getDNSHostEntries($config,$name,$silent = false)
+  {
+    global $RecordTypes;
+
+    $types = array();
+    $ret = array();
+    $ret['RECORDS']   = array();
+    $ret['dNSClass']  = "IN";
+    $ret['zoneName']  = "";
+    $ret['dNSTTL']    = "7440";
+    $ret['exists']    = false;
+
+    $ldap = $config->get_ldap_link();
+    $ldap->cd($config->current['BASE']);
+
+    /* First check all zones for an entry with the given name.
+     * If the name occurs in more than one entry alert the user ...
      */
-    if($attrs['relativeDomainName'][0] == $name){
-      $ret['exists'] = true;
-      $ret['zoneName'] = $id_tmp;
-      foreach(array("dNSClass","dNSTTL") as $atr){
-        if(isset($attrs[$atr][0])){
-          $ret[$atr] = $attrs[$atr][0];
+    $foundIn = array();
+    $zones = DNS::getAvailableZones($config);
+
+    $zonesArr = array();
+    foreach($zones as $zoneMix){
+      $zoneIndex = split("/",$zoneMix);
+      if(!array_key_exists($zoneIndex[0],$zonesArr)) {
+        $zonesArr[$zoneIndex[0]] = array();
+      }
+      array_push($zonesArr[$zoneIndex[0]],$zoneIndex[1]);
+    }
+
+    foreach($zonesArr as $nameServer => $nameServerArr){
+      $foundInTmp = array();
+      foreach($nameServerArr as $zoneArr => $zone){
+        $zoneMix = $nameServer."/".$zone;
+        $zoneDn = DNS::getDNSZoneDN($config,$zoneMix);
+        $ldap->ls("(&(objectClass=dNSZone)(zoneName=*)(relativeDomainName=".$name.")(!(relativeDomainName=@)))", $zoneDn,$attrs = array("*"));
+        while($attrs = $ldap->fetch()){
+          $foundInTmp [$zoneMix] = $attrs['dn'];
+          $foundIn [$zoneMix] = $attrs['dn'];
         }
       }
     }
 
-    /* Create list with all used records */
-    foreach($RecordTypes as $name => $value){
+    /* No zone found which contains an entry for us
+     */
+    if(count($foundIn) == 0){
+      return($ret);
+    }
 
-      /* If there is a record attribute  */
-      if(isset($attrs[$name])){
+    /* Get host informations from zone
+     */ 
+    $id_tmp = key($foundIn);
+    $ldap->cd($foundIn[$id_tmp]);
+    $ldap->search("(&(objectClass=dNSZone)(zoneName=*)(!(relativeDomainName=@)))",array("*"));
+    while($attrs = $ldap->fetch()){
 
-        /* get all entries */
-        for($i = 0 ; $i < $attrs[$value]['count']; $i ++){
-          $types[] = array( "type"    => $name,
-                            "value"   => $attrs[$value][$i]);
+      /* If relative domainname == cn
+       * Try to read dnsclass / TTl / zone
+       */
+      if($attrs['relativeDomainName'][0] == $name){
+        $ret['exists'] = true;
+        $ret['zoneName'] = $id_tmp;
+        foreach(array("dNSClass","dNSTTL") as $atr){
+          if(isset($attrs[$atr][0])){
+            $ret[$atr] = $attrs[$atr][0];
+          }
         }
       }
-    }
-    $ret['RECORDS'] = $types;
-  }
-  return($ret);
-}  
 
+      /* Create list with all used records */
+      foreach($RecordTypes as $name => $value){
 
+        /* If there is a record attribute  */
+        if(isset($attrs[$name])){
 
-/* This function compares two dns settings and returns an 
- *  array with following indexes 
- *   - delete, for dns which must be deleted (only if dns account is removed)
- *   - rename, if a dn must be renamed, for example, the relativeDomainName has changed
- *   - add,    if there is a new dns account created    
- */
-function getDNSHostEntriesDiff($config,$oldName,$newEntry,$newName)
-{
-  global $RecordTypes;
+          /* get all entries */
+          for($i = 0 ; $i < $attrs[$value]['count']; $i ++){
+            $types[] = array( "type"    => $name,
+                "value"   => $attrs[$value][$i]);
+          }
+        }
+      }
+      $ret['RECORDS'] = $types;
+    }
+    return($ret);
+  }  
 
-  $oldEntry = getDNSHostEntries($config,$oldName);
 
-  $add    = array();
-  $del    = array();
-  $move   = array();
 
-  /* Don't go further if there is nothing to do
-   * Is no account / was no account
+  /* This static function compares two dns settings and returns an 
+   *  array with following indexes 
+   *   - delete, for dns which must be deleted (only if dns account is removed)
+   *   - rename, if a dn must be renamed, for example, the relativeDomainName has changed
+   *   - add,    if there is a new dns account created    
    */
-  if(($newEntry['exists'] == false )&& ($oldEntry['exists'] == false)){
-    return(array("move"=>$move,"add"=>$add,"del"=>$del));
-  }
+  static function getDNSHostEntriesDiff($config,$oldName,$newEntry,$newName)
+  {
+    global $RecordTypes;
 
-  $zones              = getAvailableZones($config);
-  $specialAttributes  = array("cNAMERecord","pTRRecord");
-  $newRecords         = array();  // Used to remember which records are removed 
-  $zoneNameMix           = $newEntry['zoneName'];
-  $zoneDn             = getDNSZoneDN($config,$zoneNameMix);
-  $tmp                = array_flip($zones);
-  $zoneName                                    = getNameFromMix($zoneNameMix);
-  /* If reverseZone can't be resolved ... this 
-   *  can't be a valid entry, so remove this account
-   */ 
-  if(isset($tmp[$zoneNameMix])){
-    $reverseNameMix  = $tmp[$zoneNameMix];
-    $reverseDn    = getDNSZoneDN($config,$reverseNameMix);
-    if(empty($reverseDn)){
-      $newEntry['exists'] = false;
-    }
-  }else{
-    $newEntry['exists'] = false;
-  }
+    $oldEntry = getDNSHostEntries($config,$oldName);
 
-  /* If account was edited prepare some
-   *  attributes & arrays ... if required add some 
-   *  dns to $move 
-   */
-  if($oldEntry['exists']){
+    $add    = array();
+    $del    = array();
+    $move   = array();
 
-    /* Check if the account was removed 
+    /* Don't go further if there is nothing to do
+     * Is no account / was no account
      */
-    if($newEntry['exists'] == false){
-      $dn = "relativeDomainName=".$oldName.",".getDNSZoneDN($config,$oldEntry['zoneName']);
-      $del[$dn] ="";
+    if(($newEntry['exists'] == false )&& ($oldEntry['exists'] == false)){
       return(array("move"=>$move,"add"=>$add,"del"=>$del));
     }
 
-    /* Check if zoneName has changed 
-     */   
-    if(count($newEntry['RECORDS'])){
-      if($oldEntry['zoneName'] != $newEntry['zoneName']){
-        $oldzoneDn = getDNSZoneDN($config,$oldEntry['zoneName']);
-        $dn = "relativeDomainName=".$oldName.",".$oldzoneDn;
-        $dn2= "relativeDomainName=".$oldName.",".$zoneDn;
-        $move[$dn]=$dn2;
-      }
+    $zones              = DNS::getAvailableZones($config);
+    $specialAttributes  = array("cNAMERecord","pTRRecord");
+    $newRecords         = array();  // Used to remember which records are removed 
+    $zoneNameMix           = $newEntry['zoneName'];
+    $zoneDn             = DNS::getDNSZoneDN($config,$zoneNameMix);
+    $tmp                = array_flip($zones);
+    $zoneName                                  = DNS::getNameFromMix($zoneNameMix);
 
-      /* Check if host name has changed 
-       */ 
-      if($oldName != $newName){
-        $dn = "relativeDomainName=".$oldName.",".$zoneDn;
-        $dn2= "relativeDomainName=".$newName.",".$zoneDn;
-        $move[$dn]=$dn2;
-        $dn = "relativeDomainName=".$oldName.",".$dn2;
-        $dn2= "relativeDomainName=".$newName.",".$dn2;
-        $move[$dn]=$dn2;
+    /* If reverseZone can't be resolved ... this 
+     *  can't be a valid entry, so remove this account
+     */ 
+    if(isset($tmp[$zoneNameMix])){
+      $reverseNameMix  = $tmp[$zoneNameMix];
+      $reverseDn    = DNS::getDNSZoneDN($config,$reverseNameMix);
+      if(empty($reverseDn)){
+        $newEntry['exists'] = false;
       }
+    }else{
+      $newEntry['exists'] = false;
     }
 
-    /* Prepare record entries
-     *  Fill old records with array();
-     *  To ensure that they will be deleted if they stay unused
+    /* If account was edited prepare some
+     *  attributes & arrays ... if required add some 
+     *  dns to $move 
      */
-    foreach($oldEntry['RECORDS'] as $id => $rec){
-      $newRecords[$rec['type']] = array();
-    }
-  }
+    if($oldEntry['exists']){
 
-  /* There must be at least one record in our entry  
-   */
-  if((!count($newEntry['RECORDS'])) || (!$newEntry['exists'])){
-    $dn = "relativeDomainName=".$newName.",".getDNSZoneDN($config,$oldEntry['zoneName']);
-    $del[$dn] ="";
-    $ret = array("move"=>$move,"add"=>$add,"del"=>$del);
-    return($ret);
-  }
+      /* Check if the account was removed 
+       */
+      if($newEntry['exists'] == false){
+        $dn = "relativeDomainName=".$oldName.",".DNS::getDNSZoneDN($config,$oldEntry['zoneName']);
+        $del[$dn] ="";
+        return(array("move"=>$move,"add"=>$add,"del"=>$del));
+      }
 
-  /* Prepare temp obj
-   */
-  $baseObj =  array();
-  $baseObj['objectClass']       = array("top","dNSZone");
-  $baseObj['dNSTTL']            = $newEntry['dNSTTL'];
-  $baseObj['dNSClass']          = $newEntry['dNSClass'];
-  $baseObj['zoneName']          = $zoneName; 
-  $baseObj['relativeDomainName']= $newName; 
-    
-  /* Add Container Object to zone
-   *  (this possibly already exists, check this before writing to ldap)
-   */
-  $baseDn =  "relativeDomainName=".$newName.",".$zoneDn;
-  $add[$baseDn] = $baseObj;
+      /* Check if zoneName has changed 
+       */   
+      if(count($newEntry['RECORDS'])){
+        if($oldEntry['zoneName'] != $newEntry['zoneName']){
+          $oldzoneDn = DNS::getDNSZoneDN($config,$oldEntry['zoneName']);
+          $dn = "relativeDomainName=".$oldName.",".$oldzoneDn;
+          $dn2= "relativeDomainName=".$oldName.",".$zoneDn;
+          $move[$dn]=$dn2;
+        }
 
-  /* Add base obejct which contains all std records
-   */
-  $stdDn = "relativeDomainName=".$newName.",".$baseDn;
-  $add[$stdDn] = $baseObj;
+        /* Check if host name has changed 
+         */ 
+        if($oldName != $newName){
+          $dn = "relativeDomainName=".$oldName.",".$zoneDn;
+          $dn2= "relativeDomainName=".$newName.",".$zoneDn;
+          $move[$dn]=$dn2;
+          $dn = "relativeDomainName=".$oldName.",".$dn2;
+          $dn2= "relativeDomainName=".$newName.",".$dn2;
+          $move[$dn]=$dn2;
+        }
+      }
 
-  /* Set defaults. Normaly only contains old record names.
-   *  The old names will be set to array, to ensure that they will be deleted.
-   *  Or overwritten and filled with new values.
-   */
-  foreach($newRecords as $name => $def){
-    if(!in_array($name,$specialAttributes)){
-      $add[$stdDn][$name] = $def;
+      /* Prepare record entries
+       *  Fill old records with array();
+       *  To ensure that they will be deleted if they stay unused
+       */
+      foreach($oldEntry['RECORDS'] as $id => $rec){
+        $newRecords[$rec['type']] = array();
+      }
     }
-  }
 
-  /* Delete all OLD special attributes.
-   */
-  foreach($oldEntry['RECORDS'] as $id => $rec){
-    if(in_array($rec['type'],$specialAttributes)){
-      $deldn= "relativeDomainName=".$rec['value'].",".$baseDn;
-      $del[$deldn] = "";
+    /* There must be at least one record in our entry  
+     */
+    if((!count($newEntry['RECORDS'])) || (!$newEntry['exists'])){
+      $dn = "relativeDomainName=".$newName.",".DNS::getDNSZoneDN($config,$oldEntry['zoneName']);
+      $del[$dn] ="";
+      $ret = array("move"=>$move,"add"=>$add,"del"=>$del);
+      return($ret);
     }
-  }
 
+    /* Prepare temp obj
+     */
+    $baseObj =  array();
+    $baseObj['objectClass']       = array("top","dNSZone");
+    $baseObj['dNSTTL']            = $newEntry['dNSTTL'];
+    $baseObj['dNSClass']          = $newEntry['dNSClass'];
+    $baseObj['zoneName']          = $zoneName; 
+    $baseObj['relativeDomainName']= $newName; 
+
+    /* Add Container Object to zone
+     *  (this possibly already exists, check this before writing to ldap)
+     */
+    $baseDn =  "relativeDomainName=".$newName.",".$zoneDn;
+    $add[$baseDn] = $baseObj;
 
-  /* Create new record entries 
-   */
-  foreach($newEntry['RECORDS'] as $id => $rec){
-    /* Create object which contains special records 
-     *  like pTRRecord or CNAMERecord
+    /* Add base obejct which contains all std records
      */
-    if($rec['type']  == "pTRRecord"){
-      $PTRdn= "relativeDomainName=".FlipIP($rec['value']).",".$baseDn;
-      $ptrObj = $baseObj;
-      $reverseName = getNameFromMix($reverseNameMix);
-      $ptrObj['zoneName']           = $reverseName;
-      if(!preg_match("/\.$/",$newName)){
-        $ptrObj['pTRRecord']          = preg_replace("/\.\.$/",".",$newName.".".$zoneName.".");
-      }else{
-        $ptrObj['pTRRecord']          = preg_replace("/\.\.$/",".",$newName.".");
+    $stdDn = "relativeDomainName=".$newName.",".$baseDn;
+    $add[$stdDn] = $baseObj;
+
+    /* Set defaults. Normaly only contains old record names.
+     *  The old names will be set to array, to ensure that they will be deleted.
+     *  Or overwritten and filled with new values.
+     */
+    foreach($newRecords as $name => $def){
+      if(!in_array($name,$specialAttributes)){
+        $add[$stdDn][$name] = $def;
+      }
+    }
+
+    /* Delete all OLD special attributes.
+     */
+    foreach($oldEntry['RECORDS'] as $id => $rec){
+      if(in_array($rec['type'],$specialAttributes)){
+        $deldn= "relativeDomainName=".$rec['value'].",".$baseDn;
+        $del[$deldn] = "";
       }
-      $ptrObj['relativeDomainName'] = FlipIP($rec['value']);
-    
-      $add[$PTRdn] = $ptrObj;
-    }else  
-    if($rec['type']  == "cNAMERecord"){
-      $PTRdn= "relativeDomainName=".$rec['value'].",".$baseDn;
-      $ptrObj = $baseObj;
-      $ptrObj['zoneName']           = $zoneName;
-      $ptrObj['cNAMERecord']        = $newName;
-      $ptrObj['relativeDomainName'] = $rec['value'];
-      
-      $add[$PTRdn] = $ptrObj;
-    }else{
-      /* Append basic attributes
-       */
-      $add[$stdDn][$rec['type']][] = $rec['value'];  
     }
-  } // foreach record 
 
-  $ret = array("move"=>$move,"add"=>$add,"del"=>$del);
-  return($ret);
-} 
 
-function getNameFromMix($zoneMix){
-       $ret = "";
-  if(!strstr($zoneMix, '/')) return($ret);     
-  $zoneIndex           = split("/",$zoneMix);
-  return($zoneIndex[1]);
-}
+    /* Create new record entries 
+     */
+    foreach($newEntry['RECORDS'] as $id => $rec){
+      /* Create object which contains special records 
+       *  like pTRRecord or CNAMERecord
+       */
+      if($rec['type']  == "pTRRecord"){
+        $PTRdn= "relativeDomainName=".DNS::FlipIP($rec['value']).",".$baseDn;
+        $ptrObj = $baseObj;
+        $reverseName = DNS::getNameFromMix($reverseNameMix);
+        $ptrObj['zoneName']           = $reverseName;
+        if(!preg_match("/\.$/",$newName)){
+          $ptrObj['pTRRecord']          = preg_replace("/\.\.$/",".",$newName.".".$zoneName.".");
+        }else{
+          $ptrObj['pTRRecord']          = preg_replace("/\.\.$/",".",$newName.".");
+        }
+        $ptrObj['relativeDomainName'] = DNS::FlipIP($rec['value']);
+
+        $add[$PTRdn] = $ptrObj;
+      }else  
+        if($rec['type']  == "cNAMERecord"){
+          $PTRdn= "relativeDomainName=".$rec['value'].",".$baseDn;
+          $ptrObj = $baseObj;
+          $ptrObj['zoneName']           = $zoneName;
+          $ptrObj['cNAMERecord']        = $newName;
+          $ptrObj['relativeDomainName'] = $rec['value'];
+
+          $add[$PTRdn] = $ptrObj;
+        }else{
+          /* Append basic attributes
+           */
+          $add[$stdDn][$rec['type']][] = $rec['value'];  
+        }
+    } // foreach record 
 
-/* returns the dn for a specified zone
- */
-function getDNSZoneDN($config,$zoneNameMix)
-{
-  $ret = "";
-  if(!strstr($zoneNameMix, '/')) {
-    msg_dialog::display(_("Error"), sprintf(_("Undefined zone name '%s'!"),$zoneNameMix), ERROR_DIALOG);
+    $ret = array("move"=>$move,"add"=>$add,"del"=>$del);
     return($ret);
+  } 
+
+  static function getNameFromMix($zoneMix){
+    $ret = "";
+    if(!strstr($zoneMix, '/')) return($ret);   
+    $zoneIndex                 = split("/",$zoneMix);
+    return($zoneIndex[1]);
   }
 
-  $zoneNameIndex               = split("/",$zoneNameMix); 
-  $zoneName           = $zoneNameIndex[1];
-  $nameServer                          = strtolower($zoneNameIndex[0]);
-  $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 {
+  /* returns the dn for a specified zone
+   */
+  static function getDNSZoneDN($config,$zoneNameMix)
+  {
+    $ret = "";
+    if(!strstr($zoneNameMix, '/')) {
+      msg_dialog::display(_("Error"), sprintf(_("Undefined zone name '%s'!"),$zoneNameMix), ERROR_DIALOG);
+      return($ret);
+    }
+
+    $zoneNameIndex             = split("/",$zoneNameMix); 
+    $zoneName           = $zoneNameIndex[1];
+    $nameServer                                = strtolower($zoneNameIndex[0]);
+    $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);
+    }
+
+    $ldap-> cd($attr['dn']);
+    $ldap->search("(&(objectClass=dNSZone)(sOARecord=*)(zoneName=".$zoneName."))",array("zoneName"));
+    if($ldap->count()){
+      $attr = $ldap->fetch();
+      return($attr['dn']);
+    }
+
     return($ret);
   }
-  
-  $ldap-> cd($attr['dn']);
-  $ldap->search("(&(objectClass=dNSZone)(sOARecord=*)(zoneName=".$zoneName."))",array("zoneName"));
-  if($ldap->count()){
-    $attr = $ldap->fetch();
-    return($attr['dn']);
-  }
-  
-  return($ret);
-}
 
 
-/* returns all available zones 
- *  array[reverseName] = zoneName;
- */
-function getAvailableZones($config)
-{
-  $ret = array();
-  $ldap = $config->get_ldap_link();
-  $ldap->cd ($config->current['BASE']);
-
-  /* Search for zones ...
+  /* returns all available zones 
+   *  array[reverseName] = zoneName;
    */
-  $ldap->search("(&(objectClass=dNSZone)(sOARecord=*))",array("zoneName"));
+  static function getAvailableZones($config)
+  {
+    $ret = array();
+    $ldap = $config->get_ldap_link();
+    $ldap->cd ($config->current['BASE']);
 
-  $ForwardZones = array();
-  $ReverseZones = array();
-  $zones = array();
+    /* Search for zones ...
+     */
+    $ldap->search("(&(objectClass=dNSZone)(sOARecord=*))",array("zoneName"));
 
-  while($at = $ldap->fetch()){
-    if(preg_match("/\.in\-addr\.arpa/",$at['zoneName'][0])){
-      $ReverseZones[$at['dn']] = $at;
-    }else{
-      $ForwardZones[$at['dn']] = $at;
-    }
-  }
+    $ForwardZones = array();
+    $ReverseZones = array();
+    $zones = array();
 
-  foreach($ForwardZones as $dn => $obj){
-    
-    /* try to find reverse
-     */  
-    foreach($ReverseZones as $Rdn => $Robj ){
-      if(preg_match("/".$dn."/",$Rdn)){
-        $zones[strtoupper($ldap->getCn($dn))."/".$Robj['zoneName'][0]] =  
-                       strtoupper($ldap->getCn($dn))."/".$obj['zoneName'][0];
+    while($at = $ldap->fetch()){
+      if(preg_match("/\.in\-addr\.arpa/",$at['zoneName'][0])){
+        $ReverseZones[$at['dn']] = $at;
+      }else{
+        $ForwardZones[$at['dn']] = $at;
       }
-    }   
+    }
+
+    foreach($ForwardZones as $dn => $obj){
+
+      /* try to find reverse
+       */  
+      foreach($ReverseZones as $Rdn => $Robj ){
+        if(preg_match("/".$dn."/",$Rdn)){
+          $zones[strtoupper($ldap->getCn($dn))."/".$Robj['zoneName'][0]] =  
+            strtoupper($ldap->getCn($dn))."/".$obj['zoneName'][0];
+        }
+      }   
+    }
+    return($zones);
   }
-  return($zones);
 }
-
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>
index 13e7a93170a042cbac0f84194f37d564e615c0fd..9890931ea7ae3d477c07963729d2422783c6aee5 100644 (file)
@@ -39,11 +39,11 @@ class servdns extends goService
 
     /* Get record types for zones
      */
-    $this->RecordTypes = getDnsRecordTypes(true);
+    $this->RecordTypes = DNS::getDnsRecordTypes(true);
 
     /* Get all zone Informations
      */
-    $this->Zones = getDNSZoneEntries($config,$dn);
+    $this->Zones = DNS::getDNSZoneEntries($config,$dn);
     
     /* If there is at least one entry in this -> types, we have DNS enabled 
      */
@@ -300,9 +300,9 @@ class servdns extends goService
     $zones =  $this->getUsedZoneNames();
 
     if(isset($this->Zones[$id]['InitialReverseZone'])){
-      $rev = FlipIp($this->Zones[$id]['InitialReverseZone']);
+      $rev = DNS::FlipIp($this->Zones[$id]['InitialReverseZone']);
     }else{
-      $rev = FlipIp($this->Zones[$id]['ReverseZone']);
+      $rev = DNS::FlipIp($this->Zones[$id]['ReverseZone']);
     }
 
     $zonename = "";
@@ -435,10 +435,10 @@ class servdns extends goService
       $old_dn = $this->dn;
     }
 
-    $tmp = getDNSZoneEntriesDiff($this->config,$this->Zones,$old_dn);
+    $tmp = DNS::getDNSZoneEntriesDiff($this->config,$this->Zones,$old_dn);
 
     /* Update dns to current object dn */ 
-    $tmp = getDNSZoneEntriesDiff($this->config,$this->Zones,$old_dn);
+    $tmp = DNS::getDNSZoneEntriesDiff($this->config,$this->Zones,$old_dn);
     $tmp2 = array();
     foreach($tmp as $key1 => $data1){
       $tmp2[$key1] = array();
@@ -465,7 +465,7 @@ class servdns extends goService
     foreach($tmp['del'] as $dn => $del){
 
       $for = $del['InitialzoneName'];
-      $rev = FlipIp($del['InitialReverseZone']).".in-addr.arpa";
+      $rev = DNS::FlipIp($del['InitialReverseZone']).".in-addr.arpa";
 
       $ldap->cd($dn);
       $ldap->rmdir_recursive($dn);
index c9ecd96df076a911c26664bf1f230bf139427224..6ccbade692e77f74a600de34b8a4356280924141 100644 (file)
@@ -50,7 +50,7 @@ class servdnseditZone extends plugin
     plugin::plugin ($config, $dn);
 
     /* All types with required attrs */
-    $this->RecordTypes = getDnsRecordTypes(true); 
+    $this->RecordTypes = DNS::getDnsRecordTypes(true); 
 
     if(!count($attrs)){
       $this->OldZoneName        = "";
@@ -240,8 +240,8 @@ class servdnseditZone extends plugin
       }else{
         $this->zoneEditor = clone $this->dialog;
         $this->dialog = FALSE;
-#       $rev = FlipIp(getNameFromMix($this->InitialReverseZone)).".in-addr.arpa";
-#       $for = getNameFromMix($this->InitialzoneName);
+#       $rev = DNS::FlipIp(DNS::getNameFromMix($this->InitialReverseZone)).".in-addr.arpa";
+#       $for = DNS::getNameFromMix($this->InitialzoneName);
 #      
 #       $this->parent->handle_post_events("modify",array("dn" => $this->dn,"zoneName" => $rev));
 #       $this->parent->handle_post_events("modify",array("dn" => $this->dn,"zoneName" => $for));
@@ -489,7 +489,7 @@ class servdnseditZone extends plugin
       if(preg_match("/in-addr\.arpa/",$attr['zoneName'][0])){
         if(isset($attr['tXTRecord'][0])){
           $zn = preg_replace("/zoneName\=/","",$attr['tXTRecord'][0]);
-          $ret[$zn] =FlipIp(preg_replace("/\.in-addr\.arpa/","",$attr['zoneName'][0]));
+          $ret[$zn] =DNS::FlipIp(preg_replace("/\.in-addr\.arpa/","",$attr['zoneName'][0]));
         }
       }else{
         $ret[$attr['zoneName'][0]]="";
index 8453ae794e3322bd5fd1e648f050131246d5f74c..fffbd1052248656db6aa90d05695ed58f96e0288 100644 (file)
@@ -27,7 +27,7 @@ class servDNSeditZoneEntries extends plugin
 
     /* Initialise class
      */
-    $this->RecordTypes  = getDnsRecordTypes();
+    $this->RecordTypes  = DNS::getDnsRecordTypes();
     $this->dn           = "zoneName=".$zoneObject['InitialzoneName'].",".$dn; 
     $this->zoneName     = $zoneObject['InitialzoneName'];
     $this->reverseName  = $zoneObject['InitialReverseZone'];
@@ -51,7 +51,7 @@ class servDNSeditZoneEntries extends plugin
     $ldap->ls("(&(objectClass=dNSZone)(!(relativeDomainName=@)))",$this->dn,array("relativeDomainName"));
     
     while($attrs = $ldap->fetch()){
-      $this->Devices[$attrs['relativeDomainName'][0]] = getDNSHostEntries($config,$attrs['relativeDomainName'][0],true);
+      $this->Devices[$attrs['relativeDomainName'][0]] = DNS::getDNSHostEntries($config,$attrs['relativeDomainName'][0],true);
       $this->Devices[$attrs['relativeDomainName'][0]]['OrigCn'] = $attrs['relativeDomainName'][0];
     }
 
@@ -101,7 +101,7 @@ class servDNSeditZoneEntries extends plugin
        */
       if((preg_match("/^UserRecord_?/",$name)) && ($once)){
         $once = false;
-        $entry = getDNSHostEntries($this->config,"",true);     
+        $entry = DNS::getDNSHostEntries($this->config,"",true);     
         $entry['exists']    = true;
         $entry['zoneName']  = strtoupper($this->attrs['cn'][0])."/".$this->zoneName; 
         $entry['RECORDS'][] = array("type" => "aRecord" , "value"=>"");
@@ -331,17 +331,17 @@ class servDNSeditZoneEntries extends plugin
     foreach($this->Devices as $name => $dev){
       if(isset($dev['OrigCn'])){
         if(count($dev['RECORDS'])){
-          $todo[] = getDNSHostEntriesDiff($this->config,$dev['OrigCn'],$dev,$name);
+          $todo[] = DNS::getDNSHostEntriesDiff($this->config,$dev['OrigCn'],$dev,$name);
         }else{
           $dev['exists'] = false;
-          $todo[] = getDNSHostEntriesDiff($this->config,$dev['OrigCn'],$dev,$name);
+          $todo[] = DNS::getDNSHostEntriesDiff($this->config,$dev['OrigCn'],$dev,$name);
         }
       }else{
         if(count($dev['RECORDS'])){
-          $todo[] = getDNSHostEntriesDiff($this->config,"",$dev,$name);
+          $todo[] = DNS::getDNSHostEntriesDiff($this->config,"",$dev,$name);
         }else{
           $dev['exists'] = false;
-          $todo[] = getDNSHostEntriesDiff($this->config,"",$dev,$name);
+          $todo[] = DNS::getDNSHostEntriesDiff($this->config,"",$dev,$name);
         }
       }
     }
index 48c1918526218569235baaf5954472bb1a472a3e..526eefcccb6a6ea6747de25cc0dc99a07195775d 100644 (file)
@@ -118,11 +118,11 @@ class termDNS extends plugin
 
       /* Get Zones  
        */
-      $this->Zones        = getAvailableZones($config);
+      $this->Zones        = DNS::getAvailableZones($config);
 
       /* Get Entry 
        */
-      $this->dnsEntry     = getDNSHostEntries($config,$this->OrigCn);
+      $this->dnsEntry     = DNS::getDNSHostEntries($config,$this->OrigCn);
 
       /* Remove A record which equals $this->ipHostNumber
        */
@@ -138,7 +138,7 @@ class termDNS extends plugin
 
       /* Get Record types 
        */
-      $this->RecordTypes  = getDnsRecordTypes();
+      $this->RecordTypes  = DNS::getDnsRecordTypes();
 
       /* If there is at least one entry in this -> types, we have DNS enabled 
        */
@@ -179,7 +179,7 @@ class termDNS extends plugin
 
   function netmaskIsCoherent($idZone) 
   {
-    $netmask = FlipIp(str_replace(".in-addr.arpa","",getNameFromMix($idZone)));
+    $netmask = DNS::FlipIp(str_replace(".in-addr.arpa","",DNS::getNameFromMix($idZone)));
     if(!strstr($this->ipHostNumber, $netmask)){
       return false;
     }else{
@@ -312,7 +312,7 @@ class termDNS extends plugin
       if(isset($_POST['propose_ip'])){
         foreach($this->Zones as $key => $name){
           if($name == $this->dnsEntry['zoneName']){
-            $net = FlipIp(str_replace(".in-addr.arpa","",getNameFromMix($key)));
+            $net = DNS::FlipIp(str_replace(".in-addr.arpa","",DNS::getNameFromMix($key)));
             $this->ipHostNumber = $this->generateRandomIp($net);
           }
         }
@@ -391,7 +391,7 @@ class termDNS extends plugin
 
       $tmp = array();
       $this->dnsEntry['exists'] = false;
-      $tmp = getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn);
+      $tmp = DNS::getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn);
 
       /* Delete dns */
       foreach($tmp['del'] as $dn => $del){
@@ -739,10 +739,10 @@ class termDNS extends plugin
        */
       if((!$this->DNS_is_account)&&($this->initially_was_account)){  
         $this->dnsEntry['exists'] = false;
-        $tmp = getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn);
+        $tmp = DNS::getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn);
       }else{
         $this->dnsEntry['exists'] = $this->DNS_is_account;
-        $tmp = getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn);
+        $tmp = DNS::getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn);
       }   
 
       /* move follwoing entries 
@@ -957,12 +957,12 @@ class termDNS extends plugin
   {
     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']));
+      $ldap->cat(DNS::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);
+      $ptr = preg_replace("/^".normalizePreg(DNS::FlipIp($tmp))."\./","",$this->ipHostNumber);
       return($ptr);
     }else{
       return(FALSE);