Code

Initial zoneEditor checkin
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 31 Mar 2006 05:46:04 +0000 (05:46 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 31 Mar 2006 05:46:04 +0000 (05:46 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2936 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_servDNSeditZone.inc
plugins/admin/systems/class_servDNSeditZoneEntries.inc
plugins/admin/systems/servDNSeditZoneEntries.tpl
plugins/admin/systems/servdnseditzone.tpl

index 5ddf04346082fd579dc8f67cf4af281b127a4e79..13ed5678e06b1d4e97a59b2f514d89549f44487c 100644 (file)
@@ -40,6 +40,8 @@ class servdnseditZone extends plugin
 
   var $isNew                    = true;
 
+  var $ZoneObject               = array();
+
   function servdnseditZone ($config, $dn= NULL,$attrs = array())
   {
     plugin::plugin ($config, $dn);
@@ -56,6 +58,8 @@ class servdnseditZone extends plugin
       $this->InitialzoneName    = "";//$attrs['InitialzoneName'];
       $this->InitialReverseZone = "";//$attrs['InitialReverseZone'];
     }else{
+      $this->ZoneObject         = $attrs;
+
       $this->OldZoneName        = $attrs['zoneName'];
       $this->OldReverseZone     = $attrs['ReverseZone'];
 
@@ -174,11 +178,15 @@ class servdnseditZone extends plugin
     $smarty= get_smarty();
     $display= "";
 
-
     /* Open Zone Entry Edit Dialog
      */
-    if(isset($_POST['EditZoneEntries'])){
-      $this->dialog= new servDNSeditZoneEntries($this->config,$this->dn,$this->InitialzoneName,FlipIp($this->InitialReverseZone));
+    if(!count($this->ZoneObject)){
+      $smarty->assign("AllowZoneEdit" , false);
+    }else{
+      $smarty->assign("AllowZoneEdit" , true);
+      if(isset($_POST['EditZoneEntries'])){
+        $this->dialog= new servDNSeditZoneEntries($this->config,$this->dn,$this->ZoneObject);
+      }
     }
 
     /* Save Zone Entry Edit Dialog
index e775a21f05f3ee0c41aab93d675e676d38d479b7..fa41684f87f1d392356002951ae6b45224c7cbc5 100644 (file)
@@ -8,154 +8,54 @@ class servDNSeditZoneEntries extends plugin
   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();
+  var $objectclasses      = array("whatever");
 
-  var $Devices      = array();
-  var $InitDevices  = array();
+  var $Devices            = 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 $disableDialog = false; // Dialog will be disabled, if this zone is new 
-
-  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();
+    $this->dn           = "zoneName=".$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=@)))");
-    $this->disableDialog = false;
-    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";
-        }
-      }
-    }
-   
-    /* Check if this zone exists 
-     */ 
-    $res = $ldap->search("(&(objectClass=dNSZone)(relativeDomainName=@)(|(zoneName=".$zoneName.")(zoneName=".$reverseName.".in-addr.arpa)))",
-        array("zoneName"));
-    if($ldap->count()){
-    }else{
-      $this->disableDialog = true;
-    }
-
-    /* Add additional informations 
-       to all caught 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 entries
-     * Free 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 subtrees within a zone.
-     * For example : 
-     *  The object name is free1, 
-     *                                                             zoneName=test.de,cn=server ...
-     *                                // ObjectContainer
-     *                                relativeDomainName=Free1,zoneName=....
-     * // Dns entry
-     * relativeDomainName=Free1,  relativeDomainName=Free1,zoneName=....
-     * // cName entry .... 
-     * relativeDomainName=terminal12, relativeDomainName=Free1,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()){
-
-      $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];
-          }
-        }
-      } 
+    if(!count($this->Devices)){
+      $this->disableDialog = true;
     }
-
-    $this->Devices;
-    $this->InitDevices = $this->Devices;
   }
 
   function execute()
   {
     plugin::execute();
 
+
     /* Check posts for operations ...  
      */
     $once = true;
@@ -163,51 +63,42 @@ class servDNSeditZoneEntries extends plugin
 
       /* 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);
+      
+      $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;
+      }
 
-        $dn     = base64_decode($tmp2[0]);
-        $record = $tmp2[1];
-        $numrec = $tmp2[2];        
+      if(count($tmp2) != 2) continue;
 
-        $this->Devices[$dn]['RECORDS'][$record][] = ""; 
+      $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];
       }
 
       /* 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]);
-          }
+        if(isset($this->Devices[$Name]['RECORDS'][$RecordID])){
+          unset($this->Devices[$Name]['RECORDS'][$RecordID]);
         }
-
       }
 
-      /* Add new host entry
-       */
-      if((preg_match("/^UserRecord_/",$name)) && ($once)){
-        $once = false;
-        $tmp['RECORDS']['aRecord'][0] =  'empty';
-        $tmp['Type']                  =  'Free';
-        $tmp['OBJECT']['cn'][0]       =  'Free';
-        $this->Devices[] = $tmp;
-      }
     }
 
     /* Fill templating stuff */
@@ -219,7 +110,6 @@ 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));
@@ -227,268 +117,136 @@ class servDNSeditZoneEntries extends plugin
   }
 
 
-  /* 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 
-     */
-    $str.= "<table cellspacing='0' cellpadding='0'>";
-    foreach($obj['RECORDS'] as $id => $types){
-
-      /* Create table
-       */
-      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:50px;text-align:right;'>
-          <input type='image' name='AddRecord_".$name."'   src='images/crossref.png' alt='"._("Add")."' title='"._("Add")."'>
-          <input type='image' name='RemoveRecord_".$name."' src='images/edittrash.png'      alt='"._("Remove")."' title='"._("Remove")."'>
-          </td>
-          </tr>";
-      }
-    }
-    $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>";
-      }
-    }
-    $str.= "\n</select>";
-    return($str);
-  }
-
-  function remove_from_parent()
-  {
-  }
-
   function save_object()
   {
-    /* Save all form fields 
-     */
-
     /* 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;
-              }
-              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;
-            }
-          }
+      /* 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])){
+          $this->Devices[$Name]['RECORDS'][$RecordID]['value'] = $value;
         }
       }
+
+      /* 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)){
+          $this->Devices[$value] = $this->Devices[$Name];
+          unset($this->Devices[$Name]);
+        }
       }
     }
   }
 
+
   /*  check something 
    */
   function check()
   {
     $message= array();
-
+    
     $ldap = $this->config->get_ldap_link();
     $ldap->cd($this->config->current['BASE']);
 
     $names = array();
-    foreach($this->Devices as $devDN => $device){
-
-      /* check: if given name for host entry is valid.
-       * cn exists ? invalid characters ? ...
-       */
-      if($device['Type'] == "Free"){
-        $cn = $device['OBJECT']['cn'][0];
-
-        $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){
 
       /* Checking entry name
        */
-      if(!is_uid($device['OBJECT']['cn'][0])){
-        $message[] = sprintf(_("Entry name '%s' contains invalid characters."), $device['OBJECT']['cn'][0]);
+      if((!is_uid($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.
-       */
-      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); 
-        }
-      }
-
-
       /* Renaming check for existing devices 
        */
-      if(($device['Type'] == "Exists") && ($device['OrigCn'] != $device['OBJECT']['cn'][0])){
-        $cn = $device['OBJECT']['cn'][0];
-
-        $ldap->search("(cn=".$cn.")",array("cn"));
+      if(isset($device['OrigCn'])  && ($DevName != $device['OrigCn'] )){
+        $ldap->search("(cn=".$DevName.")",array("cn"));
         if($ldap->count()){
-          $message[] = sprintf(_("Can't rename '%s' to '%s',the destination name already exists."),$device['OrigCn'],$cn);
+          $message[] = sprintf(_("Can't rename '%s' to '%s',the destination name already exists."),$device['OrigCn'],$DevName);
         }
-
-        if(!is_uid($cn)){
-          $message[] = sprintf(_("Can't rename '%s' to '%s',the destination name contains invalid characters."),$device['OrigCn'],$cn);
-        }      
       }
 
       /* Check names 
        */
-      if(!isset($names[$device['OBJECT']['cn'][0]])){
-        $names[$device['OBJECT']['cn'][0]] = "";
+      if(!isset($names[$DevName])){
+        $names[$DevName] = "";
       }else{
-        $message[] = sprintf(_("The name '%s' is used more than once."),$device['OBJECT']['cn'][0]);
+        $message[] = sprintf(_("The name '%s' is used more than once."),$DevName);
       }
 
       /* Names should be written in lowercase
        */
-      if(strtolower($device['OBJECT']['cn'][0]) != $device['OBJECT']['cn'][0]){
-        $message[] = sprintf(_("The host name '%s' should be written in lowercase."), $device['OBJECT']['cn'][0]);
+      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."),$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); 
         }
       }
     }
@@ -497,28 +255,37 @@ class servDNSeditZoneEntries extends plugin
 
   function save()
   {
-  
     if($this->disableDialog) return;
 
-    /* Set all initial records to array()
-       This means they will be removed from the entry
-       if they won't be overwritten
+    $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);
       }
     }
 
@@ -527,215 +294,113 @@ 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);
+      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)
-  {
-
-    $entries = array();
-    $delete  = array();    
-    $rename  = array();
+  function generateRecordConfigurationRow($objKey){
 
-    $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 = "<h3>".sprintf(_("Settings for '%s'"),$objKey)." : </h3>";
 
-      /* 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){
 
-      /* If is valid entry 
+      /* Create unique post name
        */
-      if($obj != NULL){  
+      $name = base64_encode($objKey)."|".$id;
 
-        /*  Both type must be handled different 
-         *  free / Exists 
-         */
-        if($obj["Type"] == "Free"){
-          $objectName = $obj['OBJECT']['cn'][0];
-        }else{
-          $objectName = $obj['OrigCn'];
-        }
-
-
-        /* 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:80px;'>\n";
 
-          $ldap->cat($dn);
-          if($ldap->count() == 0){
-            $entries[$dn]['objectClass']        = array("top","dNSZone");
-            $entries[$dn]['zoneName']           = $this->zoneName;
-            $entries[$dn]['relativeDomainName'] = $objectName;
-          }
-        }
-      }
-
-      /* Calculate records ... 
+      /* Only first host entry name should be editable
        */
-      foreach($recs as $type =>  $rec){
+      if($hostNameOnce){
+        $hostNameOnce = false;  
+        $str .="<input type='text' name='RenameHost_".$name."' value='".$objectName."'>\n";
+      }else{
+        $str .=$objectName;
+      }  
 
-        /*  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 ;
-          }
+      /* Create rest. Selectbox, icons ...
+       */
+      $str .="
+        </td>
+        <td style='width:80px;'>
+          ".$this->createRecordTypeSelection($record['type'],$name)."
+        </td>
+        <td>
+          <input type='text'  value='".$record['value']."' name='ValueSelection_".$name."' style='width:250px;'>
+        </td>
+        <td style='width:50px;text-align:right;'>
+          <input type='image' name='AddRecord_".$name."'   src='images/crossref.png' alt='"._("Add")."' title='"._("Add")."'>
+          <input type='image' name='RemoveRecord_".$name."' src='images/edittrash.png'      alt='"._("Remove")."' title='"._("Remove")."'>
+        </td>
+      </tr>";
+    }
+    $str .="</table>";
+    return($str); 
+  }
 
-          /*  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;
-              }
-            }
-          }
 
-          /* 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()
+  {
   }
 
 }
index fed6442c7553578949fc0ac4b6cb1f3a40d6f2f0..7211fb32abc5df5e99c9c2b2ba66276df570b484 100644 (file)
@@ -9,7 +9,7 @@
        </b>
 {else}
        {t}To add a new host entry just click here{/t}
-       <input type='image' name='UserRecord_Free' src='images/select_default.png' alt='{t}New{/t}' title='{t}New{/t}'>
+       <input type='image' name='UserRecord' src='images/select_default.png' alt='{t}New{/t}' title='{t}New{/t}'>
        <br>
        {$table}        
 {/if}
index 99cada49e64be3a135656c34c573516535fd6498..44d5ef556c24f1ea9c49fda6c0e6a2f8895ab990 100644 (file)
                                <tr>
                                        <td>
                                                {t}Zone entries{/t}
+                                               <br>
+                                               {if $AllowZoneEdit == false}
+                                                       <i>{t}Can't be edited because the zone wasn't saved right now.{/t}</i>
+                                               {/if}
                                        </td>
                                        <td>
-                                               <input type="submit" name="EditZoneEntries" value="{t}Edit{/t}" disabled>
+                                               <input type="submit" name="EditZoneEntries" value="{t}Edit{/t}" {if $AllowZoneEdit == false} disabled {/if}> 
                                        </td>
                                </tr>
                        </table>