Code

Updated workstation - Startup
[gosa.git] / plugins / admin / systems / class_servDNSeditZone.inc
index 3dbfcec3a6b049d9bea13755b9fc12fd39691ff1..d5df0871d9bbbb912ec1699716255342ccb2b451 100644 (file)
@@ -39,11 +39,13 @@ class servdnseditZone extends plugin
 
   var $dialog                   = false;
 
+  var $zoneEditor               = NULL;
+
   var $isNew                    = true;
 
   var $ZoneObject               = array();
 
-  function servdnseditZone ($config, $dn= NULL,$attrs = array())
+  function servdnseditZone (&$config, $dn= NULL,$attrs = array())
   {
     plugin::plugin ($config, $dn);
 
@@ -61,6 +63,9 @@ class servdnseditZone extends plugin
     }else{
       $this->ZoneObject         = $attrs;
 
+      if(isset($attrs['zoneEditor'])){
+        $this->zoneEditor         = $attrs['zoneEditor'];
+      }
       $this->OldZoneName        = $attrs['zoneName'];
       $this->OldReverseZone     = $attrs['ReverseZone'];
 
@@ -72,6 +77,12 @@ class servdnseditZone extends plugin
       foreach($this->attributes as $value){
         $this->$value = $attrs[$value];
       }
+
+      $this->sOAmail            = preg_replace("/\./","@",$this->sOAmail,1);
+      $this->sOAmail            = preg_replace("/\.$/","",$this->sOAmail);
+      $this->sOAprimary         = preg_replace("/\.$/","",$this->sOAprimary);
+      $this->zoneName           = preg_replace("/\.$/","",$this->zoneName);
+
       if(isset($attrs['RECORDS'])){
         $this->Records = $attrs['RECORDS']; 
 
@@ -84,6 +95,9 @@ class servdnseditZone extends plugin
             $tmp2[$tmp[0]] = $rec;
             unset($this->Records[$key]);
           }
+          if($rec['type'] == "nSRecord"){
+            unset($this->Records[$key]);
+          }
         }
         if(count($tmp2) != 0){
           reset($tmp2);
@@ -105,15 +119,17 @@ class servdnseditZone extends plugin
 
     /* Detect Network class */
     if(!empty($this->ReverseZone)){
-      $addr = preg_replace("/^[^\/]+\//","",$this->ReverseZone);
-      if(preg_match("/^[0-9]*\.0\.0\.0$/",$addr)){
-        $this->NetworkClass = "A";
-      }
-      if(preg_match("/^[0-9]*\.[0-9]*\.0\.0$/",$addr)){
-        $this->NetworkClass = "B";
-      }
-      if(preg_match("/^[0-9]*\.[0-9]*\.[0-9]*\.0$/",$addr)){
-        $this->NetworkClass = "C";
+
+      $dots = count(split("\.",$this->ReverseZone));
+      if($dots == 1){
+        $this->NetworkClass = "A";  
+        $this->ReverseZone .= ".0.0.0"; 
+      }elseif($dots == 2){
+        $this->NetworkClass = "B";  
+        $this->ReverseZone .= ".0.0"; 
+      }else{
+        $this->NetworkClass = "C";  
+        $this->ReverseZone .= ".0"; 
       }
     }
   }
@@ -189,8 +205,12 @@ class servdnseditZone extends plugin
     plugin::execute();
 
 
+
     /* Fill templating stuff */
     $smarty= get_smarty();
+    $ui = get_userinfo();
+
+    $smarty->assign("ACLs",$this->parent->getacl(""));
     $display= "";
 
     /* Open Zone Entry Edit Dialog
@@ -200,7 +220,11 @@ class servdnseditZone extends plugin
     }else{
       $smarty->assign("AllowZoneEdit" , true);
       if(isset($_POST['EditZoneEntries'])){
-        $this->dialog= new servDNSeditZoneEntries($this->config,$this->dn,$this->ZoneObject);
+        if($this->zoneEditor == NULL){
+          $this->zoneEditor= new servDNSeditZoneEntries($this->config,$this->dn,$this->ZoneObject);
+          $this->zoneEditor->parent = $this;
+        }
+        $this->dialog = $this->zoneEditor;
       }
     }
 
@@ -214,8 +238,14 @@ class servdnseditZone extends plugin
           print_red($msg);
         }
       }else{
-        $this->dialog->save();
-        $this->dialog = false;
+        $this->zoneEditor = clone $this->dialog;
+        $this->dialog = FALSE;
+#       $rev = FlipIp(getNameFromMix($this->InitialReverseZone)).".in-addr.arpa";
+#       $for = 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));
+#       $this->dialog = false;
       }
     }
 
@@ -227,7 +257,7 @@ class servdnseditZone extends plugin
 
     /* Display any type of open dialogs 
      */
-    if($this->dialog){
+    if(is_object($this->dialog)){
       $this->dialog->save_object();
       return($this->dialog->execute());
     }
@@ -297,7 +327,7 @@ class servdnseditZone extends plugin
     }
 
 
-    $div = new DivSelectBox("MxRecords");
+    $div = new divSelectBox("MxRecords");
     $div->setHeight(120);
     $recs = $this->mXRecords;
 
@@ -321,7 +351,7 @@ class servdnseditZone extends plugin
     $smarty->assign("Mxrecords",  $div->DrawList());
     $smarty->assign("records"  ,  $this->generateRecordsList());
     $smarty->assign("NetworkClass",  $this->NetworkClass);
-    $smarty->assign("NetworkClasses",  array("A"=>"A","B"=>"B","C"=>"C"));
+    $smarty->assign("NetworkClasses",  array("A"=>"255.0.0.0 (Class A)","B"=>"255.255.0.0 (Class B)","C"=>"255.255.255.0 (Class C)"));
 
     /* Display tempalte */
     $display.= $smarty->fetch(get_template_path('servdnseditzone.tpl', TRUE));
@@ -383,22 +413,6 @@ class servdnseditZone extends plugin
       $message[] =sprintf(_("Please choose a valid reverse zone name."));
     }
 
-    if(!preg_match("/\.$/",$this->sOAprimary)){
-      $message[] = _("Primary dns server must end with '.' to be a valid entry.");
-    }
-
-    if(!preg_match("/\.$/",$this->sOAmail)){
-      $message[] = _("Your specified mail address must end with '.' to be a valid record.");
-    }
-
-    if(preg_match("/@/",$this->sOAmail)){
-      $message[] = _("Your mail address contains '@' replace this with '.' to enable GOsa to create a valid SOA record.");
-    }
-
-    if(preg_match("/@/",$this->sOAmail)){
-      $message[] = _("Your mail address contains '@' replace this with '.' to enable GOsa to create a valid SOA record.");
-    }
-
     if($this->zoneName != strtolower($this->zoneName)){
       $message[] = _("Only lowercase strings are allowed as zone name.");
     }
@@ -431,30 +445,30 @@ class servdnseditZone extends plugin
     }
 
     /* Check class for given Zone Address */
-    $addr = preg_replace("/^[^\/]+\//","",$this->ReverseZone);
-
+    $addr = preg_replace("/^[^\/]*+\//","",$this->ReverseZone);
+  
     /* Check for valid&complete IP address */
     if(!is_ip($addr)){
       $message[] = _("The given network address is not a valid, please specify a valid IP address.");
     }
-  
     /* Check if given address matches selected network class */
     switch($this->NetworkClass){
       case 'A': { 
                   if(!preg_match("/^[0-9]*\.0\.0\.0$/",$addr)){
-                    $message[] = sprintf(_("The specified network address is not matching with the specified zone class, try it this was x.0.0.0"));
+                    $message[] = sprintf(_("The specified network address is not matching with the specified zone class, try it this way x.0.0.0"));
                   }
                 }
                 break;
       case 'B': {
                   if(!preg_match("/^[0-9]*\.[0-9]*\.0\.0$/",$addr)){
-                    $message[] = sprintf(_("The specified network address is not matching with the specified zone class, try it this was x.x.0.0"));
+                    $message[] = sprintf(_("The specified network address is not matching with the specified zone class, try it this way x.x.0.0"));
                   }
                 }
                 break;
       case 'C': {
                   if(!preg_match("/^[0-9]*\.[0-9]*\.[0-9]*\.0$/",$addr)){
-                    $message[] = sprintf(_("The specified network address is not matching with the specified zone class, try it this was x.x.x.0"));
+                    $message[] = sprintf(_("The specified network address is not matching with the specified zone class, try it this way x.x.x.0"));
                   }
                 }
                 break;
@@ -499,11 +513,32 @@ class servdnseditZone extends plugin
       $this->Records [] = $rec;
     }
 
+  
     $ret['RECORDS'] = $this->Records; 
+    switch($this->NetworkClass){
+      case 'C' : $ret['ReverseZone']= preg_replace("/\.[0-9]*$/","",$this->ReverseZone);break;
+      case 'B' : $ret['ReverseZone']= preg_replace("/\.[0-9]*\.[0-9]*$/","",$this->ReverseZone);break;
+      case 'A' : $ret['ReverseZone']= preg_replace("/\.[0-9]*\.[0-9]*\.[0-9]*$/","",$this->ReverseZone);break;
+      default : trigger_error("Invalid network class given '".$this->NetworkClass."'");
+    }
 
     $ret['InitialReverseZone']=  $this->InitialReverseZone;
     $ret['InitialzoneName']   =  $this->InitialzoneName;
 
+    $ret['sOAmail']            = preg_replace("/\@/",".",$this->sOAmail);
+
+    foreach(array("sOAprimary","zoneName","sOAmail") as $attr){
+      if(!preg_match("/\.$/",$ret[$attr])){
+        if(!is_ip($ret[$attr])){
+          $ret[$attr] = $ret[$attr].".";
+        }
+      }
+    }
+
+    $ret['RECORDS'][] = array("type" => "nSRecord","value" => $ret['sOAprimary']) ;
+
+    $ret['zoneEditor'] = $this->zoneEditor;
     return($ret);
   }