Code

Updated workstation - Startup
[gosa.git] / plugins / admin / systems / class_servDNSeditZoneEntries.inc
index d451283438ec45b0d27e4a64c34502c1610295f9..8453ae794e3322bd5fd1e648f050131246d5f74c 100644 (file)
@@ -21,7 +21,7 @@ class servDNSeditZoneEntries extends plugin
 
   var $disableDialog      = false; // Dialog will be disabled, if this zone is new 
 
-  function servDNSeditZoneEntries ($config,$dn, $zoneObject)
+  function servDNSeditZoneEntries (&$config,$dn, &$zoneObject)
   {
     plugin::plugin ($config, $dn);
 
@@ -32,6 +32,15 @@ class servDNSeditZoneEntries extends plugin
     $this->zoneName     = $zoneObject['InitialzoneName'];
     $this->reverseName  = $zoneObject['InitialReverseZone'];
 
+    /* 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']);
+    }
+
     /* Get ldap connection 
      */
     $ldap = $this->config->get_ldap_link();
@@ -46,8 +55,11 @@ class servDNSeditZoneEntries extends plugin
       $this->Devices[$attrs['relativeDomainName'][0]]['OrigCn'] = $attrs['relativeDomainName'][0];
     }
 
-    if(!count($this->Devices)){
-      $this->disableDialog = true;
+    $ldap->cat($this->dn,array("objectClass"));
+
+    $this->disableDialog = true;
+    if(count($this->Devices)|| $ldap->count()){
+      $this->disableDialog = false;
     }
   }
 
@@ -55,10 +67,28 @@ class servDNSeditZoneEntries extends plugin
   {
     plugin::execute();
 
+    /* Fill templating stuff */
+    $smarty= get_smarty();
+    $display= "";
+
+    $table = "";
+    foreach($this->Devices as $key => $dev){
+      $table .= $this->generateRecordConfigurationRow($key);
+    }
+
+    $smarty->assign("disableDialog",$this->disableDialog);
+    $smarty->assign("table",$table);;
+    $display.= $smarty->fetch(get_template_path('servDNSeditZoneEntries.tpl', TRUE));
+    return($display);
+  }
+
 
+  function save_object()
+  {
     /* Check posts for operations ...  
      */
     $once = true;
+    $ptr_updates = array();
     foreach($_POST as $name => $value){
 
       /* Add a new Record in given object  
@@ -73,7 +103,7 @@ class servDNSeditZoneEntries extends plugin
         $once = false;
         $entry = getDNSHostEntries($this->config,"",true);     
         $entry['exists']    = true;
-        $entry['zoneName']  = $this->zoneName; 
+        $entry['zoneName']  = strtoupper($this->attrs['cn'][0])."/".$this->zoneName; 
         $entry['RECORDS'][] = array("type" => "aRecord" , "value"=>"");
         $this->Devices[_("New entry")] = $entry;
       }
@@ -97,28 +127,21 @@ class servDNSeditZoneEntries extends plugin
         if(isset($this->Devices[$Name]['RECORDS'][$RecordID])){
           unset($this->Devices[$Name]['RECORDS'][$RecordID]);
         }
-      }
 
+        /* 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();
+        }
+      }
     }
 
-    /* Fill templating stuff */
-    $smarty= get_smarty();
-    $display= "";
-
-    $table = "";
-    foreach($this->Devices as $key => $dev){
-      $table .= $this->generateRecordConfigurationRow($key);
-    }
-
-    $smarty->assign("disableDialog",$this->disableDialog);
-    $smarty->assign("table",$table);;
-    $display.= $smarty->fetch(get_template_path('servDNSeditZoneEntries.tpl', TRUE));
-    return($display);
-  }
-
-
-  function save_object()
-  {
     /* Possible attributes posted 
      */
     foreach($_POST as $name => $value){
@@ -137,7 +160,33 @@ class servDNSeditZoneEntries extends plugin
        */          
       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(!$found){
+              $dev = array('type'=> 'pTRRecord', 'value' => $ip);
+              $this->Devices[$Name]['RECORDS'][] = $dev;
+            }
+          }
         }
       }
 
@@ -194,9 +243,12 @@ class servDNSeditZoneEntries extends plugin
     $names = array();
     foreach($this->Devices as $DevName => $device){
 
+      /* Don't need to check empty values ... */
+      if(!count($device['RECORDS'])) continue;
+
       /* Checking entry name
        */
-      if((!is_uid($DevName)) | (empty($DevName))){
+      if(!preg_match("/^[a-z0-9_\.-]+$/i", $DevName) || (empty($DevName))){
         $message[] = sprintf(_("Entry name '%s' contains invalid characters."), $DevName);
       }      
 
@@ -226,9 +278,9 @@ class servDNSeditZoneEntries extends plugin
 
       /* Names should be written in lowercase
        */
-      if(strtolower($DevName) != $DevName){
-        $message[] = sprintf(_("The host name '%s' should be written in lowercase."), $DevName);
-      }
+#      if(strtolower($DevName) != $DevName){
+#        $message[] = sprintf(_("The host name '%s' should be written in lowercase."), $DevName);
+#      }
 
       /* Check records
        */                 
@@ -244,7 +296,7 @@ class servDNSeditZoneEntries extends plugin
           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);
+            $message[] = sprintf(_("The record type '%s' is a unique type and can't be defined twice."),$Rec['type']);
           }
         }
 
@@ -272,6 +324,8 @@ class servDNSeditZoneEntries extends plugin
 
     $todo = array(); 
 
+
+
     /* Create todolist
      */
     foreach($this->Devices as $name => $dev){
@@ -317,6 +371,9 @@ class servDNSeditZoneEntries extends plugin
     foreach($tmp['del'] as $dn => $del){
       $ldap->cd($dn);
       $ldap->rmdir_recursive($dn);
+      if(is_object($this->parent->parent)){
+        $this->parent->parent->handle_post_events("remove",array("dn" => $dn));
+      }
     }
 
     /* Add || Update new DNS entries
@@ -327,9 +384,15 @@ class servDNSeditZoneEntries extends plugin
       if(count($ldap->fetch())){
         $ldap->cd($dn);
         $ldap->modify ($attrs);
+        if(is_object($this->parent->parent)){
+          $this->parent->parent->handle_post_events("modify",array("dn" => $dn));
+        }
       }else{
         $ldap->cd($dn);
         $ldap->add($attrs);
+        if(is_object($this->parent->parent)){
+          $this->parent->parent->handle_post_events("create",array("dn" => $dn));
+        }
       }
     }
   }
@@ -359,6 +422,11 @@ class servDNSeditZoneEntries extends plugin
     $str.= "<table cellspacing='0' cellpadding='0'>";
     foreach($obj['RECORDS'] as $id => $record){
 
+      /* Skip not selectable entries */
+      if(!isset($this->RecordTypes [$record['type']])) {
+        continue;
+      }
+
       /* Create unique post name
        */
       $name = base64_encode($objKey)."|".$id;
@@ -382,10 +450,20 @@ class servDNSeditZoneEntries extends plugin
         <td>
           <input type='text'  value='".$record['value']."' name='ValueSelection_".$name."' style='width:250px;'>
         </td>
-        <td style='width:50px;text-align:right;'>
+        <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")."'>
-        </td>
+        ";
+
+#        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>";