Code

Closes #229 ZoneEditor changes will be saved when server object is saved
[gosa.git] / plugins / admin / systems / class_servDNSeditZoneEntries.inc
index faf29d198257ca3f5c207d4da2ea9425193a4483..e1d836c0c85b4bb9c3653caa8462767a4bdcb482 100644 (file)
 
 class servDNSeditZoneEntries extends plugin
 {
-  /* CLI vars */
-  var $cli_summary= "Manage server basic objects";
-  var $cli_description= "Some longer text\nfor help";
-  var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
   /* attribute list for save action */
-  var $ignore_account= TRUE;
-  var $attributes= array("zoneName");
-  var $objectclasses= array("whatever");
+  var $ignore_account     = TRUE;
+  var $attributes         = array("cn");
+  var $objectclasses      = array("whatever");
 
-  var $Devices      = array();
-  var $InitDevices  = array();
+  var $Devices            = array();
 
-  var $FreeHosts    = array();
-  var $InitFreeHosts= array();
+  var $zoneName           = "";   // ZoneName of currently edited Zone
+  var $reverseName        = "";   // ReverseZone of the currently edited Zone
 
-  var $zoneName       = "";   // ZoneName of currently edited Zone
-  var $reverseName    = "";   // ReverseZone of the currently edited Zone
-  var $RecordTypes= array();  // Possible record type. They will be set in contrucktor
-                              //  and some types will be added later  (cName/Ptr)
+  var $RecordTypes        = array();  // Possible record type.
+
+  var $disableDialog      = false; // Dialog will be disabled, if this zone is new 
+  var $cn;
 
-  function servDNSeditZoneEntries ($config, $dn= NULL,$zoneName,$reverseName,$RTypes)
+  function servDNSeditZoneEntries ($config,$dn, $zoneObject)
   {
     plugin::plugin ($config, $dn);
 
     /* Initialise class
      */
-    $this->zoneName     = $zoneName;
-    $this->reverseName  = $reverseName;
-    $this->RecordTypes  = $RTypes;
-  
-    /* Add records types which are not allowed in zones 
-     */
-    $this->RecordTypes['cNAMERecord']  = "relativeDomainName";
-    $this->RecordTypes['pTRRecord']    = "relativeDomainName";
-    $this->RecordTypes['tXTRecord']    = "tXTRecord";
+    $this->RecordTypes  = getDnsRecordTypes();
+
+    /* Remove nSRecord from listed types */
+    if(isset($this->RecordTypes['nSRecord'])){
+      unset($this->RecordTypes['nSRecord']);
+    }
+    /* Remove nSRecord from listed types */
+    if(isset($this->RecordTypes['pTRRecord'])){
+      unset($this->RecordTypes['pTRRecord']);
+    }
+
+    $this->dn           = "zoneName=".getNameFromMix($zoneObject['InitialzoneName']).",".$dn; 
+    $this->zoneName     = $zoneObject['InitialzoneName'];
+    $this->reverseName  = $zoneObject['InitialReverseZone'];
+
     /* Get ldap connection 
      */
     $ldap = $this->config->get_ldap_link();
     $ldap->cd($this->config->current['BASE']);
 
-    /* Get all objects using this zone  
-     * Workstations / Terminals
-     */
-    $res = $ldap->search("(&(objectClass=dNSZone)(|(zoneName=".$zoneName.")(zoneName=".$reverseName.".in-addr.arpa))(!(relativeDomainName=@)))");
-    while($attrs = $ldap->fetch($res)){
-      if(preg_match("/zoneName=/",$attrs['dn'])) continue;
-      foreach($this->RecordTypes as $atr => $val){
-        if((isset($attrs[$atr])) && (is_array($attrs[$atr]))){
-          unset($attrs[$val]['count']);
-          $dn = preg_replace("/^.*,cn/","cn",$attrs['dn']);
-          $this->Devices[$dn]['RECORDS'][$atr] = $attrs[$val]; 
-          $this->Devices[$dn]['Type']   = "Exists";
-        }
-      }
-    }
-   
-    /* Add additional informations 
-       to all catched objects ( ObjectInformations)
-     */
-    foreach($this->Devices as $dn => $Recs){
-      $attrs = $ldap->fetch($ldap->cat($dn,array("objectClass","cn")));
-      $this->Devices[$dn]['OBJECT'] = $attrs;
-      $this->Devices[$dn]['OrigCn'] = $attrs['cn'][0];
-    }
-
-    /* Add Free Hand  entries
-     * Free hand entries are entries which are not directly assigned
-     *  to an existing network object like a WS or a Terminal.
-     * They will be found in a subtree within this zone.
-     * For example : 
-     *  The object name is FreeHand1, 
-     *                                                             zoneName=test.de,cn=server ...
-     *                                // ObjectContainer
-     *                                relativeDomainName=FreeHand1,zoneName=....
-     * // Dns entry
-     * relativeDomainName=FreeHand1,  relativeDomainName=FreeHand1,zoneName=....
-     * // cName entry .... 
-     * relativeDomainName=terminal12, relativeDomainName=FreeHand1,zone...
+    /* Get zone content
      */
-    $ldap->cd ("zoneName=".$this->zoneName.",".$this->dn);
-    $ldap->ls ("(&(objectClass=dNSZone)(!(relativeDomainName=@)))","zoneName=".$this->zoneName.",".$this->dn,array("*"));
-   
-    $GetSubInformations = array();
+    $ldap->ls("(&(objectClass=dNSZone)(!(relativeDomainName=@)))",$this->dn,array("relativeDomainName"));
+    
     while($attrs = $ldap->fetch()){
-
-      unset($attrs[$val]['count']);
-
-      $dn = $attrs['dn'];
-
-      /* Split dn into relativeDomainNames 
-       */
-      $tmp =  split("relativeDomainName=",trim(preg_replace("/,zoneName=.*$/","\\1",$dn)));
-      $tmp2 = array();
-      foreach($tmp as $t){
-        if(empty($t)) continue;
-        $tmp2[] = preg_replace("/,$/","",$t);
-      }
-
-      /* Set object Name
-       */
-      $cn = $tmp2[0];
-      $dn = "relativeDomainName=".$cn.",zoneName=".$this->zoneName.",".$this->dn;  
-
-      /* Create entry 
-       */
-      $this->Devices[$dn]['OBJECT']           = $attrs;
-      $this->Devices[$dn]['OBJECT']['cn'][0]  = $cn;//attrs['relativeDomainName'];
-      $this->Devices[$dn]['OBJECT']['OrigCn'] = $cn;//attrs['relativeDomainName'][0];
-      $this->Devices[$dn]['Type']             = "Free";
-
-      $GetSubInformations [] = $dn;
+      $this->Devices[$attrs['relativeDomainName'][0]] = getDNSHostEntries($config,$attrs['relativeDomainName'][0],true);
+      $this->Devices[$attrs['relativeDomainName'][0]]['OrigCn'] = $attrs['relativeDomainName'][0];
     }
-    
-    /* Get sub informations 
-       CName or pTR records are stored in a sub entry.
-    
-        // The base entry with aRecords/tXTrecords/....
-        relativeDomainName=Keks, relativeDomainName=Keks, zoneName=....
 
-        // And the sub entries like this one
-        relativeDomainName=10.2.64.in-addr.arpa, relativeDomainName=Keks, zoneName =...
-        (  They can't be stored in a single entry, so i decided to store them this way  ).
-     */ 
-    foreach($GetSubInformations as $dn){
-      $ldap->ls("(&(objectClass=dNSZone)(!(relativeDomainName=@)))",$dn,array("*"));
-      while($attrs= $ldap->fetch()){
-        foreach($this->RecordTypes as $atr => $val){
-          if((isset($attrs[$atr])) && (is_array($attrs[$atr]))){
-            unset($attrs[$val]['count']);
-            $this->Devices[$dn]['RECORDS'][$atr]    = $attrs[$val];
-          }
-        }
-      } 
+    $ldap->cat($this->dn,array("objectClass"));
+
+    $this->disableDialog = true;
+    if(count($this->Devices)|| $ldap->count()){
+      $this->disableDialog = false;
     }
-    
-    $this->Devices;
-    $this->InitDevices = $this->Devices;
   }
 
   function execute()
   {
-         plugin::execute();
-
-    /* Check posts for operations ...  
-     */
-    $once = true;
-    foreach($_POST as $name => $value){
-    
-      /* Add a new Record in given object  
-       */
-      if((preg_match("/^AddRecord_/",$name)) && ($once)){
-        $once   = false;
-        $tmp    = preg_replace("/^AddRecord_/","",$name);
-        $tmp    = preg_replace("/_.*$/","",$tmp);
-        $tmp2   = split("\|",$tmp);
-      
-        $dn     = base64_decode($tmp2[0]);
-        $record = $tmp2[1];
-        $numrec = $tmp2[2];        
-     
-        $this->Devices[$dn]['RECORDS'][$record][] = ""; 
-      }
-      
-      /* Remove record from given dn
-       */
-      if((preg_match("/^RemoveRecord_/",$name)) && ($once)){
-        $once   = false;
-        $tmp    = preg_replace("/^RemoveRecord_/","",$name);
-        $tmp    = preg_replace("/_.*$/","",$tmp);
-        $tmp2   = split("\|",$tmp);
-      
-        $dn     = base64_decode($tmp2[0]);
-        $record = $tmp2[1];
-        $numrec = $tmp2[2];        
-     
-         unset($this->Devices[$dn]['RECORDS'][$record][$numrec]); 
-  
-        if(count($this->Devices[$dn]['RECORDS'][$record]) == 0){
-          unset($this->Devices[$dn]['RECORDS'][$record]);
-          if(count($this->Devices[$dn]['RECORDS']) ==0){
-            unset($this->Devices[$dn]);
-          }
-        }
-
-      }
-    
-      /* Don't know how i should implement this ...
-       */
-      if((preg_match("/^UserRecord_/",$name)) && ($once)){
-        $once = false;
-        $tmp['RECORDS']['aRecord'][0] =  'empty';
-        $tmp['Type']                  =  'Free';
-        $tmp['OBJECT']['cn'][0]       =  'Free';
-        $this->Devices[] = $tmp;
-      }
-    }
+    plugin::execute();
 
     /* Fill templating stuff */
     $smarty= get_smarty();
@@ -211,263 +73,247 @@ class servDNSeditZoneEntries extends plugin
       $table .= $this->generateRecordConfigurationRow($key);
     }
 
+    $smarty->assign("disableDialog",$this->disableDialog);
     $smarty->assign("table",$table);;
     $display.= $smarty->fetch(get_template_path('servDNSeditZoneEntries.tpl', TRUE));
     return($display);
   }
-  
 
-  /* Create html table out of given entry 
-   */
-  function generateRecordConfigurationRow($obj_dn){
 
-    /* get some basic inforamtions 
-     */
-    $obj        = $this->Devices[$obj_dn];
-    $objectName = $obj['OBJECT']['cn'][0];
-
-    /* Set title 
-     */
-    if($obj['Type'] == "Free"){   
-      $str = "<h3>".sprintf(_("Settings for host entry #%s"),($obj_dn +1))." : </h3>";
-    }else{
-      $str = "<h3>".sprintf(_("Settings for '%s'"),$obj_dn)." : </h3>";
-    }
-    
-    $hostNameOnce = true;
-    /* Walk through all defined records 
+  function save_object()
+  {
+    /* Check posts for operations ...  
      */
-    $str.= "<table cellspacing='0' cellpadding='0'>";
-    foreach($obj['RECORDS'] as $id => $types){
+    $once = true;
+    $ptr_updates = array();
+    foreach($_POST as $name => $value){
 
-      /* Create table
+      /* Add a new Record in given object  
        */
-      foreach($types as $key => $type){
-
-        /* Create unique post name
-         */
-        $name = base64_encode($obj_dn)."|".$id."|".$key;
-
-        $str .= "<tr>
-          <td style='width:80px;'>";
-          
-        if($hostNameOnce){
-          $hostNameOnce = false;  
-          $str .="<input type='text' name='RenameHost_".$name."' value='".$objectName."'>";
-        }else{
-          $str .=$objectName;
-        }  
       
-        $str .="
-          </td>
-          <td style='width:80px;'>
-            ".$this->createRecordTypeSelection($id,$name)."
-          </td>
-          <td>
-            <input type='text'  value='".$type."' name='ValueSelection_".$name."' style='width:250px;'>
-          </td>
-          <td style='width:30px;text-align:right;'>
-            <input type='image' name='AddRecord_".$name."'   src='images/crossref.png' alt='"._("Add")."' title='"._("Add")."'>
-          </td>
-          <td style='width:60px;text-align:right;'>
-            <input type='image' name='UserRecord_".$name."'   src='images/select_default.png' alt='"._("New")."' title='"._("New")."'>
-            <input type='image' name='RemoveRecord_".$name."' src='images/edittrash.png'      alt='"._("Remove")."' title='"._("Remove")."'>
-          </td>
-         </tr>";
+      $tmp    = preg_replace("/^.*_(.*)_.*$/","\\1",$name);
+      $tmp2   = split("\|",$tmp);
+
+      /* Add new host entry
+       */
+      if((preg_match("/^UserRecord_?/",$name)) && ($once)){
+        $once = false;
+        $entry = getDNSHostEntries($this->config,"",true);     
+        $entry['exists']    = true;
+        $entry['zoneName']  = $this->zoneName; 
+        $entry['RECORDS'][] = array("type" => "aRecord" , "value"=>"");
+        $this->Devices[_("New entry")] = $entry;
       }
-    }
-      $str .="</table>";
-    return($str); 
-  }
 
-  /* Create selectbox with all available option types 
-   */
-  function createRecordTypeSelection($id,$refID,$isFreeRecord =false){
-    if(!$isFreeRecord){
-      $str = "\n<select name='RecordTypeSelection_".$refID."'>";
-    }else{
-      $str = "\n<select name='FreeRecordTypeSelection_".$refID."'>";
-    }
-    foreach($this->RecordTypes as $type => $atr) {
-      if($id == $type){
-        $str .="\n<option value='".$type."' selected >".strtoupper(preg_replace("/record/i","",$type))."</option>";
-      }else{
-        $str .="\n<option value='".$type."'>".strtoupper(preg_replace("/record/i","",$type))."</option>";
+      if(count($tmp2) != 2) continue;
+
+      $Name     = base64_decode($tmp2[0]);
+      $RecordID = $tmp2[1];
+
+      /* Add new REcord
+       */
+      if((preg_match("/^AddRecord_/",$name)) && ($once)){
+        $once = false;
+        $this->Devices[$Name]['RECORDS'][] = $this->Devices[$Name]['RECORDS'][$RecordID];
       }
-    }
-    $str.= "\n</select>";
-    return($str);
-  }
 
-  function remove_from_parent()
-  {
-  }
+      /* Remove record from given dn
+       */
+      if((preg_match("/^RemoveRecord_/",$name)) && ($once)){
+        $once   = false;
+        if(isset($this->Devices[$Name]['RECORDS'][$RecordID])){
+          unset($this->Devices[$Name]['RECORDS'][$RecordID]);
+        }
 
-  function save_object()
-  {
-    /* Save all form fields 
-     */
+        /* Check if there is at least one visible record. Else remove complete entry */
+        $visible = false;
+        foreach($this->Devices[$Name]['RECORDS'] as $rec){
+          if(in_array($rec['type'],$this->RecordTypes)){
+            $visible = true;  
+            break;
+          }
+        }
+        if(!$visible && isset($this->Devices[$Name]['RECORDS'])){
+          $this->Devices[$Name]['RECORDS'] = array();
+        }
+      }
+    }
 
     /* Possible attributes posted 
      */
-    $actions = array("RenameHost_","ValueSelection_");
-    foreach($_POST as $name=>$value){
+    foreach($_POST as $name => $value){
 
-      foreach($actions as $act){
-        /* Check if attribute was posted 
-         */
-        if(preg_match("/".$act."/",$name)){
-
-          /* Extract informations out of postname 
-           */
-          $action = $act;
-          $tmp    = preg_replace("/^".$action."/","",$name);
-          $tmp    = preg_replace("/_.*$/","",$tmp); 
-          $tmp2   = split("\|",$tmp);      
-
-          $dn     = base64_decode($tmp2[0]);
-          $record = $tmp2[1];
-          $numrec = $tmp2[2]; 
-
-          // entry value was psoted
-          if($act == "ValueSelection_"){ 
-            $this->Devices[$dn]['RECORDS'][$record][$numrec] = $value;
-          }elseif($act == "RenameHost_"){
-            $tmp = array();
-            foreach($this->Devices as $dnn => $dev){
-              if($dn == $dnn){
-                continue;
+      /* Extract informations out of post name 
+       */
+      $tmp    = preg_replace("/^.*_/","\\1",$name);
+      $tmp2   = split("\|",$tmp);      
+      if(count($tmp2) != 2) continue;
+
+      $Name     = base64_decode($tmp2[0]);
+      $RecordID = $tmp2[1];
+
+      /* Check for value change 
+       */          
+      if(preg_match("/ValueSelection_/",$name)){
+        if(isset($this->Devices[$Name]['RECORDS'][$RecordID])){
+         
+          /* Update value */ 
+          $old = $this->Devices[$Name]['RECORDS'][$RecordID]['value'];
+          $this->Devices[$Name]['RECORDS'][$RecordID]['value'] = $value;
+
+          /* Handle pTRRecord */
+          if(!isset($ptr_updates[$Name]) && $this->Devices[$Name]['RECORDS'][$RecordID]['type'] == "aRecord"){
+    
+            $found = false;
+            $ip = $value;
+            $match = preg_replace("/^[^\/]*+\//","",$this->reverseName);
+            $ip = preg_replace("/^".normalizePreg($match)."/","",$ip);
+            $ip = preg_replace("/^\./","",$ip);
+
+            foreach($this->Devices[$Name]['RECORDS'] as $key => $dev){
+              if($dev['type'] == "pTRRecord"){
+                $ptr_updates[$Name] = $Name;
+                $this->Devices[$Name]['RECORDS'][$key]['value'] = $ip;
+                $found = true;
+                break;
               }
-              if(isset($dev['OrigCn'])){
-                $n1 = strtolower($dev['OrigCn']);
-                $tmp[$n1] = $n1;
-              } 
-              $n2 = strtolower($dev['OBJECT']['cn'][0]);
-              $tmp[$n2] = $n2;
             }
-    
-            if(!isset($tmp[strtolower($value)])){
-              $this->Devices[$dn]['OBJECT']['cn'][0] = $value;
+            if(!$found){
+              $dev = array('type'=> 'pTRRecord', 'value' => $ip);
+              $this->Devices[$Name]['RECORDS'][] = $dev;
             }
           }
         }
       }
+
+      /* record type changed
+       */        
+      if(preg_match("/^RecordTypeSelection_/",$name)){
+        if(isset($this->Devices[$Name]['RECORDS'][$RecordID])){
+          $this->Devices[$Name]['RECORDS'][$RecordID]['type'] = $value;
+        }  
+      }   
     }
+    
+    /* check for renamed entries 
+     */ 
     foreach($_POST as $name => $value){
 
-      /* Check if attribute was posted
+      /* Extract informations out of post name 
        */
-      if(preg_match("/^RecordTypeSelection_/",$name)){
+      $tmp    = preg_replace("/^.*_/","\\1",$name);
+      $tmp2   = split("\|",$tmp);      
+      if(count($tmp2) != 2) continue;
 
-        /* Extract informations out of postname
-         */
-        $action = "RecordTypeSelection_";
-        $tmp    = preg_replace("/^".$action."/","",$name);
-        $tmp    = preg_replace("/_.*$/","",$tmp);
-        $tmp2   = split("\|",$tmp);
-
-        $dn     = base64_decode($tmp2[0]);
-        $record = $tmp2[1];
-        $numrec = $tmp2[2];
-
-        if($record != $value){ 
-          $str =  $this->Devices[$dn]['RECORDS'][$record][$numrec];
-          unset($this->Devices[$dn]['RECORDS'][$record][$numrec]);
-          $this->Devices[$dn]['RECORDS'][$value][] = $str;
-        } 
+      $Name     = base64_decode($tmp2[0]);
+      $RecordID = $tmp2[1];
+
+      /* Host renamed
+       */
+      if(preg_match("/RenameHost_/",$name)){
+        if((isset($this->Devices[$Name])) && ($Name != $value)){
+    
+          if(isset($this->Devices[$value])){
+            print_red(sprintf(_("Can't rename '%s' to '%s' there is already an entry with the same name in our zone editing dialog."),$Name,$value));
+          }else{
+            $this->Devices[$value] = $this->Devices[$Name];
+            unset($this->Devices[$Name]);
+          }
+        }
       }
     }
   }
 
+
   /*  check something 
    */
   function check()
   {
-    $message= array();
+    /* Call common method to give check the hook */
+    $message= plugin::check();
+    
     $ldap = $this->config->get_ldap_link();
     $ldap->cd($this->config->current['BASE']);
-    foreach($this->Devices as $devDN => $device){
 
-      /* check: if given name for Free Hand entry is valid.
-       * cn exists ? invalid characters ? ...
-       */
-      if($device['Type'] == "Free"){
-        $cn = $device['OBJECT']['cn'][0];
+    $names = array();
 
-        $ldap->search("(cn=".$cn.")",array("cn"));
-        if($ldap->count()){
-          $message[] = sprintf(_("The name '%s' can't be used as host entry, the name is already used in this ldap tree."),$cn);
-        }
+    foreach($this->Devices as $DevName => $device){
+
+      /* skip checking empty attributes */
+      if(count($this->Devices[$DevName]['RECORDS']) == 0){
+        return;
       }
 
       /* Checking entry name
        */
-      if(!is_uid($device['OBJECT']['cn'][0])){
-        $message[] = sprintf(_("Entry name '%s' contains invalid characters."), $device['OBJECT']['cn'][0]);
-
+      if(!preg_match("/^[a-z0-9_\.-]+$/i", $DevName) || (empty($DevName))){
+        $message[] = sprintf(_("Entry name '%s' contains invalid characters."), $DevName);
       }      
 
-      /* Check if we have renamed the server, hich we are currently editing.
-       * reset the value and display a message.
+      /* Renaming check for existing devices 
        */
-      if(strcmp($devDN,$this->dn) ==0 ){  
-        $new = $device['OBJECT']['cn'][0];
-        $old = $this->InitDevices[$devDN]['OBJECT']['cn'][0];
-     
-        if($new != $old){
-          $message[] = sprintf(_("Can't rename the server '%s' to '%s', the server contains this zone."),$old,$new); 
+      if(isset($device['OrigCn'])  && ($DevName != $device['OrigCn'] )){
+        $ldap->cd($this->dn);
+        $ldap->search("(relativeDomainName=".$DevName.")",array("relativeDomainName"));
+        if($ldap->count()){
+          $message[] = sprintf(_("Can not rename '%s' to '%s',the destination name already exists."),$device['OrigCn'],$DevName);
+        }
+      }elseif(!isset($device['OrigCn'])){
+        $ldap->cd($this->dn);
+        $ldap->search("(relativeDomainName=".$DevName.")",array("relativeDomainName"));
+        if($ldap->count()){
+          $message[] = sprintf(_("Can not create '%s',the destination name already exists."),$DevName);
         }
       }
 
+      /* Check names 
+       */
+      if(!isset($names[$DevName])){
+        $names[$DevName] = "";
+      }else{
+        $message[] = sprintf(_("The name '%s' is used more than once."),$DevName);
+      }
 
-      /* Renaming check for existing devices 
+      /* Names should be written in lowercase
        */
-      if(($device['Type'] == "Exists") && ($device['OrigCn'] != $device['OBJECT']['cn'][0])){
-        $cn = $device['OBJECT']['cn'][0];
 
-        $ldap->search("(cn=".$cn.")",array("cn"));
-        if($ldap->count()){
-          $message[] = sprintf(_("Can't rename '%s' to '%s',the destination name already exists."),$device['OrigCn'],$cn);
-        }
-    
-        if(!is_uid($cn)){
-          $message[] = sprintf(_("Can't rename '%s' to '%s',the destination name contains invalid characters."),$device['OrigCn'],$cn);
-        }      
+
+      if(strtolower($DevName) != $DevName){
+        $message[] = sprintf(_("The host name '%s' should be written in lowercase."), $DevName);
       }
 
       /* Check records
        */                 
       $singleEntries = array("cNAMERecord","pTRRecord");
 
+      $tmp  = array();
       $tmp2 = array();
-      foreach($device['RECORDS'] as $type => $entries){
-   
+      foreach($device['RECORDS'] as $Num => $Rec){
+
         /* Check for multiple use of unique record types
          */
-        if((in_array($type,$singleEntries)) && (count($entries) > 1)){
-          $message[] = sprintf(_("The record type '%s' is a unique type and can't be defined twice."),$type);
+        if(in_array($Rec['type'],$singleEntries)){
+          if(!isset($tmp[$Rec['type']])){
+            $tmp[$Rec['type']] = "";
+          }else{
+            $message[] = sprintf(_("The record type '%s' is a unique type and can't be defined twice."),$Rec['type']);
+          }
         }
 
         /* Check for empty / duplicate entries in record array 
-        */
-        $tmp = array();
-        foreach($entries as $entry){
-
-          /* Check for empty records 
-           */
-          if(empty($entry)){
-            $message[] = sprintf(_("There is an empty '%s' for host '%s'."),$type,$device['OBJECT']['cn'][0]);
-          }
+         */
+        if(empty($Rec['value'])){
+          $message[] = sprintf(_("There is an empty '%s' for host '%s'."),$Rec['type'],$DevName);
+        }
 
-          /* Check for duplicate record entries 
-           */
-          if(!isset($tmp[$entry])){
-            $tmp[$entry]= 'test';
-          }else{
-            $message[] = sprintf(_("There is a duplicate entry in '%s' for '%s'."),$type,$device['OBJECT']['cn'][0]); 
-          }
+        /* Check for duplicate record entries 
+         */
+        if(!isset($tmp[$Rec['type']][$Rec['value']])){
+          $tmp[$Rec['type']][$Rec['value']] = "";
+        }else{
+          $message[] = sprintf(_("There is a duplicate entry in '%s' for '%s'."),$Rec['type'],$DevName); 
         }
       }
     }
@@ -476,25 +322,38 @@ class servDNSeditZoneEntries extends plugin
 
   function save()
   {
-    /* Set all initial records to array()
-       This means they will be removed from the entry
-        if they won't be overwritten
+    if($this->disableDialog) return;
+
+    $todo = array(); 
+
+
+    /* Create todolist
      */
-    foreach($this->InitDevices as $dn => $obj){
-      $attrs[$dn]= array();
-      foreach($obj['RECORDS'] as $rectype => $records){
-        $attrs[$dn][$rectype] = array();
+    foreach($this->Devices as $name => $dev){
+      if(isset($dev['OrigCn'])){
+        if(count($dev['RECORDS'])){
+          $todo[] = getDNSHostEntriesDiff($this->config,$dev['OrigCn'],$dev,$name);
+        }else{
+          $dev['exists'] = false;
+          $todo[] = getDNSHostEntriesDiff($this->config,$dev['OrigCn'],$dev,$name);
+        }
+      }else{
+        if(count($dev['RECORDS'])){
+          $todo[] = getDNSHostEntriesDiff($this->config,"",$dev,$name);
+        }else{
+          $dev['exists'] = false;
+          $todo[] = getDNSHostEntriesDiff($this->config,"",$dev,$name);
+        }
       }
     }
 
-    /* Add new entries
-     */
-    foreach($this->Devices as $dn => $obj){
-      foreach($obj['RECORDS'] as $rectype => $records){
-        $attrs[$dn][$rectype] = array();
-        foreach($records as $rec){
-          $attrs[$dn][$rectype][] = $rec;
-        } 
+    $tmp = array();
+    $tmp['del']   = array();
+    $tmp['add']   = array();
+    $tmp['move']  = array();
+    foreach($todo as $to){
+      foreach($to as $type => $entries){
+        $tmp[$type] = array_merge($tmp[$type],$entries);
       }
     }
 
@@ -503,215 +362,126 @@ class servDNSeditZoneEntries extends plugin
     $ldap = $this->config->get_ldap_link();
     $ldap->cd ($this->config->current['BASE']);
 
-    /* Generate 'T odo' :-)
+    /* move follwoing entries
      */
-    $tmp = ($this->generate_LDAP_entries($attrs));
+    foreach($tmp['move'] as $src => $dst){
+      $this->recursive_move($src,$dst);
+    }
 
-    /* Delete all objects which should be delted 
-     */
-    foreach($tmp['del'] as $key => $ntr){
-      $ldap->rmdir_recursive($key);   
+    /* Delete dns */
+    foreach($tmp['del'] as $dn => $del){
+      $ldap->cd($dn);
+      $ldap->rmdir_recursive($dn);
     }
 
-    /* Add append new / updated entries 
+    /* Add || Update new DNS entries
      */
-    foreach($tmp['addupdate'] as $key => $attrs){
-      $ldap->cat($key);
-      if($ldap->count() > 0){
-        $ldap->cd($key);
-        $ldap->modify($attrs);
+    foreach($tmp['add'] as $dn => $attrs){
+      $ldap->cd($dn);
+      $ldap->cat($dn, array('dn'));
+      if(count($ldap->fetch())){
+        $ldap->cd($dn);
+        $ldap->modify ($attrs);
       }else{
-        $ldap->cd($this->config->current['BASE']);
-        $ldap->cd($key);
-        $ldap->add($attrs);        
-      }
-
-      /* Display errors ...
-       */
-      if($ldap->error != "Success"){
-        echo "<br>".$ldap->error."<br>";
-        print_a($attrs);
-        echo $key;
+        $ldap->cd($dn);
+        $ldap->add($attrs);
       }
     }
-   
-    /* Rename entries 
-        !! Terminals / WS / etc will be renamed too
-     */
-    foreach($tmp['rename'] as $old => $new){
-      $ldap->cat($old);
-      $this->recursive_move($old,$new);
-    }
   }
 
 
-  /* This function creates an array with following indexs
-   * 'delete'       for all dns which should be deleted recursivly
-   * 'addupdated'   Contains all entries which should be written
-   * 'rename'       Contains all dns which should be renamed 
+  /* Create html table out of given entry 
    */
-  function generate_LDAP_entries($objs)
-  {
+  function generateRecordConfigurationRow($objKey){
 
-    $entries = array();
-    $delete  = array();    
-    $rename  = array();
-
-    $ldap = $this->config->get_ldap_link();
-    $ldap->cd ($this->config->current['BASE']);
+    /* Get some basic informations 
+     */
+    $obj        = $this->Devices[$objKey];
+    $objectName = $objKey;
 
-    /* these entries are added to base object ... 
+    /* Abort if emtpy
      */
-    $normal = array("mDRecord","aRecord","tXTRecord","mXRecord","hInfoRecord","mInfoRecord","aFSDBRecord","SigRecord","KeyRecord","aAAARecord","nSRecord",
-        "LocRecord","nXTRecord","sRVRecord","nAPTRRecord","kXRecord","certRecord","a6Record","dSRecord","sSHFPRecord","rRSIGRecord","nSECRecord");
+    if(count($obj['RECORDS']) == 0) return "";
 
-    /* Create t odo
+    /* Set title 
      */
-    foreach($objs as $dn => $recs){
+    $str= "<br>";
 
-      /* Check if object must be renamed 
-       */
-      if(isset($this->Devices[$dn]['OrigCn'])){
-        if($this->Devices[$dn]['OBJECT']['cn'][0] != $this->Devices[$dn]['OrigCn']){
-          $newdn = str_replace("cn=".$this->Devices[$dn]['OrigCn'], "cn=".$this->Devices[$dn]['OBJECT']['cn'][0],$this->Devices[$dn]['OBJECT']['dn']);
-          $rename[$this->Devices[$dn]['OBJECT']['dn']]  =  $newdn;
-          $rename["relativeDomainName=".$this->Devices[$dn]['OrigCn'].",".$newdn]  = "relativeDomainName=".$this->Devices[$dn]['OBJECT']['cn'][0].",".$newdn;
-        }
-      }
+    $hostNameOnce = true;
 
-      /* Get basic info
-       */ 
-      if(isset($this->Devices[$dn])){
-        $obj = $this->Devices[$dn];
-      }else{
-        $obj = NULL;
+    /* Walk through all defined records 
+     */
+    $str.= "<table cellspacing='0' cellpadding='0'>";
+    foreach($obj['RECORDS'] as $id => $record){
+
+      /* Skip not selectable entries */
+      if(!isset($this->RecordTypes [$record['type']])) {
+        continue;
       }
 
-      /* If is valid entry 
+      /* Create unique post name
        */
-      if($obj != NULL){  
-
-        /*  Both type must be handled different 
-         *  Free / Exists 
-         */
-        if($obj["Type"] == "Free"){
-          $objectName = $obj['OBJECT']['cn'][0];
-        }else{
-          $objectName = $obj['OrigCn'];
-        }
+      $name = base64_encode($objKey)."|".$id;
 
-      
-        /* If type is Free, check 
-         */
-        if($obj['Type'] == "Free"){
-
-          /* Remove entry, if it was renamed 
-           */
-          if(isset($obj['OBJECT']['OrigCn'])){
-            if($obj['OBJECT']['cn'][0] != $obj['OBJECT']['OrigCn']){
-              $delete["relativeDomainName=".$obj['OBJECT']['OrigCn'].",zoneName=".$this->zoneName.",".$this->dn]="";
-            }
-          }
-
-          /* Add new entry 
-           */
-          $dn  = "relativeDomainName=".$objectName.",zoneName=".$this->zoneName.",".$this->dn;
-          $dn2 = $dn;
+      $str .= "<tr><td style='width:170px;'>\n";
 
-          $ldap->cat($dn);
-          if($ldap->count() == 0){
-            $entries[$dn]['objectClass']        = array("top","dNSZone");
-            $entries[$dn]['zoneName']           = $this->zoneName;
-            $entries[$dn]['relativeDomainName'] = $objectName;
-          }
-        }
+      /* Only first host entry name should be editable
+       */
+      if($hostNameOnce){
+        $hostNameOnce = false;  
+        $str .="<input type='text' name='RenameHost_".$name."' value='".$objectName."'>\n";
       }
 
-      /* Calculate records ... 
+      /* Create rest. Selectbox, icons ...
        */
-      foreach($recs as $type =>  $rec){
-
-        /*  Simply add normal entries 
-         */
-        if($obj != NULL){
-          if(in_array($type,$normal)){
-            $ldap->cat('relativeDomainName='.$objectName.','.$dn);
-
-            /* Append objectFrame if object doesn't exists in ldap
-             */
-            if($ldap->count()  == 0) {
-              $entries['relativeDomainName='.$objectName.','.$dn]['objectClass']        = array("top","dNSZone");
-              $entries['relativeDomainName='.$objectName.','.$dn]['zoneName']           = $this->zoneName;
-              $entries['relativeDomainName='.$objectName.','.$dn]['relativeDomainName'] = $objectName;
-            }
-            $entries['relativeDomainName='.$objectName.','.$dn][$type] = $rec ;
-          }
-
-          /*  Special handling for cNAMERecords 
-           */
-          if($type == "cNAMERecord"){
-
-            $useDn = $dn;
-            if($obj['Type'] == "Free"){
-              $useDn = $dn2;
-            }
-             
-            if(isset($this->InitDevices[$useDn]['RECORDS']['cNAMERecord'])){
-              foreach($this->InitDevices[$useDn]['RECORDS']['cNAMERecord'] as $warmal){
-                $delete['relativeDomainName='.$warmal.','.$useDn] = "";
-              }
-            }
-            foreach($rec as $r){
-              if(!empty($r)){
-                $entries['relativeDomainName='.$r.','.$useDn]['objectClass']        = array("top","dNSZone");
-                $entries['relativeDomainName='.$r.','.$useDn]['zoneName']           = $this->zoneName;
-                $entries['relativeDomainName='.$r.','.$useDn]['cNAMERecord']        = $objectName;
-                $entries['relativeDomainName='.$r.','.$useDn]['relativeDomainName'] = $r;
-              }
-            }
-          }
+      $str .="
+        </td>
+        <td style='width:90px;'>
+          ".$this->createRecordTypeSelection($record['type'],$name)."
+        </td>
+        <td>
+          <input type='text'  value='".$record['value']."' name='ValueSelection_".$name."' style='width:250px;'>
+        </td>
+        <td style='width:75px;text-align:right;'>
+          <input type='image' name='AddRecord_".$name."'   src='images/list_new.png' alt='"._("Add")."' title='"._("Add")."'>
+          <input type='image' name='RemoveRecord_".$name."' src='images/edittrash.png'      alt='"._("Remove")."' title='"._("Remove")."'>
+        ";
+
+#        if($record['type'] == "aRecord"){
+#          $str .="<input type='image' name='AddPtr_".$name."' src='images/network.png' 
+#                    alt='"._("Add PTR")."' title='"._("Add PTR record")."'>";
+#        }else{
+#          $str .= "<img src='images/empty.png' alt=''>";
+#        }
+
+      $str.=
+        "</td>
+      </tr>";
+    }
+    $str .="</table>";
+    return($str); 
+  }
 
-          /* Special handling for ptrrecord
-           */ 
-          if($type == "pTRRecord"){
-          
-            $useDn = $dn;
-            if($obj['Type'] == "Free"){
-              $useDn = $dn2;
-            }
 
-            if(isset($this->InitDevices[$dn]['RECORDS']['pTRRecord'])){
-              foreach($this->InitDevices[$dn]['RECORDS']['pTRRecord'] as $warmal){
-                $delete['relativeDomainName='.$warmal.','.$useDn] = "";
-              }
-            }
-            foreach($rec as $r){
-              if(!empty($r)){
-                $entries['relativeDomainName='.$r.','.$useDn]['pTRRecord']          = $objectName;
-                $entries['relativeDomainName='.$r.','.$useDn]['zoneName']           = $this->reverseName.".in-addr.arpa";
-                $entries['relativeDomainName='.$r.','.$useDn]['relativeDomainName'] = $r;
-                $entries['relativeDomainName='.$r.','.$useDn]['objectClass']        = array("top","dNSZone");
-              }
-            }
-          }
-        }
-        if($obj == NULL){
-          $obj = $this->InitDevices[$dn];
-          if($obj['Type'] == "Free"){
-            $delete['relativeDomainName='.$objectName.','.$dn] = "";
-          }else{
-            $ldap->cd($dn);
-            $ldap->ls("(&(objectClass=dNSZone)(!(relativeDomainName=@)))",$dn,array("relativeDomainName"));
-            while($attrs = $ldap->fetch()){
-              $delete[$attrs['dn']] = "";
-            }
-          }
-        }    
+  /* Create selectbox with all available option types 
+   */
+  function createRecordTypeSelection($id,$refID){
 
+    $str = "\n<select name='RecordTypeSelection_".$refID."'>";
+    foreach($this->RecordTypes as $type => $atr) {
+      if($id == $type){
+        $str .="\n<option value='".$type."' selected >".strtoupper(preg_replace("/record/i","",$type))."</option>";
+      }else{
+        $str .="\n<option value='".$type."'>".strtoupper(preg_replace("/record/i","",$type))."</option>";
       }
     }
-    $ret = array("del"=> $delete , "addupdate"=> $entries, "rename"=> $rename);
-    return($ret);
+    $str.= "\n</select>";
+    return($str);
+  }
+
+
+  function remove_from_parent()
+  {
   }
 
 }