Code

Updated dns, added mx record editor
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 7 Mar 2006 08:36:20 +0000 (08:36 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 7 Mar 2006 08:36:20 +0000 (08:36 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2815 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_servDNS.inc
plugins/admin/systems/class_servDNSeditZone.inc
plugins/admin/systems/servdnseditzone.tpl

index c31971f3fcf97125e264f3e9a8243b4b233653eb..644c1abe25098ffe913b46460ddae67ee8cca239 100644 (file)
@@ -93,11 +93,6 @@ class servdns extends plugin
           }
         }
 
-        /* Set TTL value */
-        if(isset($attrs['dNSTTL'][0])){
-          $types[$attrs['zoneName'][0]]['dNSTTL'] = $attrs['dNSTTL'][0];
-        }
-
         /* Set dns Class*/
         if(isset($attrs['dNSClass'][0])){
           $types[$attrs['zoneName'][0]]['dNSClass'] = $attrs['dNSClass'][0];
@@ -114,8 +109,6 @@ class servdns extends plugin
           /* If there is a record attribute  */
           if(isset($attrs[$name])){
 
-            $types[$attrs['zoneName'][0]]['Records']=array();
-
             /* get all entries */
             for($i = 0 ; $i < $attrs[$value]['count']; $i ++){
               $types[$attrs['zoneName'][0]]['Records'][] =array("type"      =>$name,
@@ -269,7 +262,7 @@ class servdns extends plugin
       $ZoneList->AddEntry(array(
             array("string" => $zone),
             array("string" => _("Reverse zone")." : ".$values['ReverseZone']),
-            array("string" => _("TTL")." : ".$values['dNSTTL']),
+            array("string" => _("TTL")." : ".$values['sOAttl']),
             array("string" => _("Class")." : ".$values['dNSClass']),
             array("string" =>str_replace("%s",base64_encode($zone),$editImg))
             ));
@@ -365,7 +358,7 @@ class servdns extends plugin
         }
       }
     }
-    
+
     /* Check which dns are not used anymore ...*/
     foreach($this->usedDNS as $key => $values){
       $actions['delete'][$key] = $values;
@@ -403,8 +396,7 @@ class servdns extends plugin
   {
     $tmp = array();
     $tmp['objectClass']           = array("top","dNSZone");
-    $tmp['dNSTTL']                = $zone['dNSTTL']; 
-    $tmp['dNSClass']              = $zone['dNSClass']; 
+    $tmp['dNSClass']              = "IN";//$zone['dNSClass']; 
     $tmp['relativeDomainName']    = "@";//$zone['relativeDomainName']; 
 
     $str = "";
@@ -415,7 +407,7 @@ class servdns extends plugin
 
 
     /* Generate Record entries  */
-    $arr = array("SigRecord","KeyRecord","aAAARecord","nSRecord","iaFSDBRecord","mInfoRecord","hInfoRecord","mXRecord","mDRecord","tXTRecord",
+    $arr = array("aRecord","SigRecord","KeyRecord","aAAARecord","nSRecord","iaFSDBRecord","mInfoRecord","hInfoRecord","mXRecord","mDRecord","tXTRecord",
         "LocRecord","nXTRecord","sRVRecord","nAPTRRecord","kXRecord","certRecord","a6Record","dSRecord","sSHFPRecord","rRSIGRecord","nSECRecord");
     $aRecords = array();
     foreach($arr as $ar){
@@ -427,7 +419,6 @@ class servdns extends plugin
         }
       }
     }
-   
     /* Check if there are records removed,
         if there are some removed records, the append an array        
         to ensure that these record types are deleted 
@@ -441,7 +432,7 @@ class servdns extends plugin
         }
       }
     }
-    
+   
     /* generate forward entry */
     $dn = "zoneName=".$zone['zoneName'].",".$this->dn; 
     $tmp2[$dn] = $tmp;
index d814d416e36da1e446d715b0f66a2de307c67950..82e40e3db773c04270e3d6590aaa5506be5204ef 100644 (file)
@@ -9,7 +9,7 @@ class servdnseditZone extends plugin
 
   /* attribute list for save action */
   var $ignore_account= TRUE;
-  var $attributes     = array("zoneName","ReverseZone","dNSTTL","dNSClass",
+  var $attributes     = array("zoneName","ReverseZone","dNSClass",
       "sOAprimary","sOAmail","sOAserial","sOArefresh","sOAretry","sOAexpire","sOAttl"); 
   var $objectclasses  = array("whatever");
 
@@ -18,7 +18,6 @@ class servdnseditZone extends plugin
   var $ReverseZone              = "";
   var $ReverseDN                = "";
   var $zoneName                 = "";
-  var $dNSTTL                   = "7200";
   var $dNSClass                 = "IN";
   var $status                   = "new";
 
@@ -31,6 +30,7 @@ class servdnseditZone extends plugin
   var $sOAttl                   = "6400";
 
   var $Records                  = array();
+  var $mXRecords                = array();
 
   var $InitiallyZoneName        = "";
   var $InitiallyReverseZone     = "";
@@ -58,8 +58,25 @@ class servdnseditZone extends plugin
       }
       if(isset($attrs['Records'])){
         $this->Records = $attrs['Records']; 
+
+        $tmp2 = array();
+        $usedPrio = array();
+        foreach($this->Records as $key => $rec){
+          if($rec['type'] == "mXRecord"){
+            $tmp = split(" ",$rec['value']);
+            $rec['value'] = $tmp[0];
+            $tmp2[$tmp[1]] = $rec;
+            unset($this->Records[$key]);
+          }
+        }
+        if(count($tmp2) != 0){
+          reset($tmp2);
+          ksort($tmp2);
+        }
+        $this->mXRecords = $tmp2;
       }else{
-        $this->Records = array();
+        $this->mXRecords  = array();
+        $this->Records    = array();
       }
       $str = date("Ymd");
       if(preg_match("/^".$str."/",$this->sOAserial)){
@@ -70,15 +87,124 @@ class servdnseditZone extends plugin
     }
   }
 
+  /* TRansports the geiven Arraykey one position up*/
+  function ArrayUp($atr,$attrs)
+  {
+    $ret = $attrs;
+    $pos = $atr ;
+    $cn = count($attrs);
+    if(!(($pos == -1)||($pos == 1)||($pos >$cn))){
+      $before = array_slice($attrs,0,($pos-2));
+      $mitte  = array_reverse(array_slice($attrs,($pos-2),2));
+      $unten  = array_slice($attrs,$pos);
+      $ret = array();
+      $ret = $this->combineArrays($before,$mitte,$unten);
+    }
+    return($ret);
+  }
+
+
+  /* TRansports the geiven Arraykey one position up*/
+  function ArrayDown($atr,$attrs)
+  {
+    $ret = $attrs;
+    $pos = $atr ;
+    $cn = count($attrs);
+    if(!(($pos == -1)||($pos == $cn))){
+      $before = array_slice($attrs,0,($pos-1));
+      $mitte  = array_reverse(array_slice($attrs,($pos-1),2));
+      $unten  = array_slice($attrs,($pos+1));
+      $ret = array();
+      $ret = $this->combineArrays($before,$mitte,$unten);
+    }
+    return($ret);
+  }
+
+  /* Combine new array */
+  function combineArrays($ar0,$ar1,$ar2)
+  {
+    $ret = array();
+    if(is_array($ar0))
+    foreach($ar0 as $ar => $a){
+        $ret[]=$a;
+    }
+    if(is_array($ar1))
+    foreach($ar1 as $ar => $a){
+        $ret[]=$a;
+    }
+    if(is_array($ar2))
+    foreach($ar2 as $ar => $a){
+        $ret[]=$a;
+    }
+    return($ret);
+  }
+  
+  function getpos($atr,$attrs)
+  {
+    $i = 0;
+    foreach($attrs as $attr => $name)    {
+      $i++;
+      if($attr == $atr){
+        return($i);
+      }
+    }
+    return(-1);
+  }
+
+
   function execute()
   {
     /* Call parent execute */
     plugin::execute();
 
+
     /* Fill templating stuff */
     $smarty= get_smarty();
     $display= "";
 
+
+    $once =true;
+    foreach($_POST as $name => $value){
+      if((preg_match("/^MXup_/",$name)) && ($once)){
+        $once = false;
+
+        $id = preg_replace("/^MXup_/","",$name);
+        $id = preg_replace("/_.*$/","",$id);
+        $id = base64_decode($id);
+    
+        $this->mXRecords = $this->ArrayUp(($id+1),$this->mXRecords);
+      }
+      if((preg_match("/^MXdown_/",$name)) && ($once)){
+        $once = false;
+        
+        $id = preg_replace("/^MXdown_/","",$name);
+        $id = preg_replace("/_.*$/","",$id);
+        $id = base64_decode($id);
+  
+        $this->mXRecords = $this->ArrayDown(($id+1),$this->mXRecords);
+      }
+      if((preg_match("/^MXdel_/",$name)) && ($once)){
+        $once = false;
+        
+        $id = preg_replace("/^MXdel_/","",$name);
+        $id = preg_replace("/_.*$/","",$id);
+        $id = base64_decode($id);
+        
+        unset($this->mXRecords[$id]);
+
+        $tmp  =array();
+        foreach($this->mXRecords as $entry){
+          $tmp[] = $entry;
+        }
+        $this->mXRecords = $tmp; 
+      }
+    }
+
+    if((isset($_POST['AddMXRecord'])) && (!empty($_POST['StrMXRecord']))){
+      $this->mXRecords[] = array("type"=>"mXRecord","inittype"=>"","value"=>trim($_POST['StrMXRecord']),"status"=>"new");      
+    }
+
     /* Handle Post events */
     $once = true;
     foreach($_POST as $name => $value){
@@ -105,8 +231,30 @@ class servdnseditZone extends plugin
       $smarty->assign($name,$this->$name);
     }
 
+
+    $div = new DivSelectBox("MxRecords");
+    $div->setHeight(120);
+    $recs = $this->mXRecords;
+
+    $oneup    = "<input name='MXup_%s'    type='image' src='images/sort_up.png'    title='"._("Up")."'      class='center'>&nbsp;"; 
+    $onedown  = "<input name='MXdown_%s'  type='image' src='images/sort_down.png'  title='"._("Down")."'    class='center'>&nbsp;"; 
+    $onedel   = "<img src='images/empty.png' width='20' class='center'>
+                 <input name='MXdel_%s'   type='image' src='images/edittrash.png'  title='"._("Delete")."'  class='center'>"; 
+
+    foreach($recs as $key => $rec){
+      $div ->AddEntry(array(
+            array("string"=>$rec['value']),
+/*            array("string"=>$key,
+                  "attach"=>"style='width:20px;'"),*/
+            array("string"=>str_replace("%s",base64_encode($key),$oneup.$onedown.$onedel),
+                  "attach"=>"style='width:70px;border-right:0px;'")
+            ));
+    }
+
     /* Assign records list */
-    $smarty->assign("records",$this->generateRecordsList());
+
+    $smarty->assign("Mxrecords",  $div->DrawList());
+    $smarty->assign("records"  ,  $this->generateRecordsList());
 
     /* Display tempalte */
     $display.= $smarty->fetch(get_template_path('servdnseditzone.tpl', TRUE));
@@ -211,8 +359,10 @@ class servdnseditZone extends plugin
     $ldap->search("(&(objectClass=dNSZone)(relativeDomainName=@)(zoneName=*))",array("zoneName","tXTRecord"));
     while($attr = $ldap->fetch()){
       if(preg_match("/in-addr\.arpa/",$attr['zoneName'][0])){
-        $zn = preg_replace("/zoneName\=/","",$attr['tXTRecord'][0]);
-        $ret[$zn] = $this->FlipIp(preg_replace("/\.in-addr\.arpa/","",$attr['zoneName'][0]));
+        if(isset($attr['tXTRecord'][0])){
+          $zn = preg_replace("/zoneName\=/","",$attr['tXTRecord'][0]);
+          $ret[$zn] = $this->FlipIp(preg_replace("/\.in-addr\.arpa/","",$attr['zoneName'][0]));
+        }
       }else{
         $ret[$attr['zoneName'][0]]="";
       }
@@ -243,7 +393,14 @@ class servdnseditZone extends plugin
     foreach($this->attributes as $name){
       $ret[$name] = $this->$name;
     }
+
+    foreach($this->mXRecords as $key => $rec){
+      $rec['value'].= " ".$key;
+      $this->Records [] = $rec;
+    }
+
     $ret['Records'] = $this->Records; 
+
     return($ret);
   }
 
@@ -259,6 +416,9 @@ class servdnseditZone extends plugin
 
     $str = "<table summary=''>";
     foreach($this->Records as $key => $entry){
+
+      if($entry['type'] == "mXRecord") continue;
+      
       if($entry['status'] == "deleted") continue;
 
       $changeStateForRecords.= "changeState('RecordTypeSelectedFor_".$key."');\n";
@@ -289,6 +449,9 @@ class servdnseditZone extends plugin
   {
     $str = "<select name='".$name."' id='".$name."'>";
     foreach($this->RecordTypes as $type => $value){
+
+      if(preg_match("/^mXRecord$/i",$value)) continue;
+
       $use = "";
       if($type == $selected){
         $use = " selected ";
index 4899985ed93a572ed779b3a5597f9785902813f4..657e25a72ce4602a7d984d101dd25b4380228e51 100644 (file)
@@ -4,19 +4,27 @@
                <td style="width:50%;vertical-align:top;border-right:1px        solid   #b0b0b0;">
                        <table summary="">
                                <tr>
-                                       <td>{t}Zone name{/t}
+                                       <td>{t}Zone name{/t}{$must}
                                        </td>
                                        <td><input type="text" name="zoneName" value="{$zoneName}">
                                        </td>
                                </tr>
+                               <tr>
+                                       <td>{t}Network address{/t}{$must}
+                                       </td>
+                                       <td><input type="text" name="ReverseZone" value="{$ReverseZone}">
+                                       </td>
+                               </tr>
                        </table>
                </td>
-               <td style="vertical-align:top;">
+               <td>
                        <table summary="">
                                <tr>
-                                       <td>{t}Network address{/t}
+                                       <td>
+                                               {t}Zone entries{/t}
                                        </td>
-                                       <td><input type="text" name="ReverseZone" value="{$ReverseZone}">
+                                       <td>
+                                               <input type="submit" name="EditZoneEntries" value="{t}Edit{/t}">
                                        </td>
                                </tr>
                        </table>
 <table summary="" width="100%">
        <tr>
                <td style="vertical-align:top;width:50%;border-right:1px        solid   #b0b0b0;">
-                       <h2>{t}Parameter{/t}</h2>
-                       <table summary="">
-                               <tr>
-                                       <td>{t}DNS TTL{/t}
-                                       </td>
-                                       <td>
-                                               <input type="text" name="dNSTTL" value="{$dNSTTL}">
-                                       </td>
-                               </tr>
+                       <h2>{t}MxRecords{/t}</h2>
+                       <table width="100%">    
                                <tr>
-                                       <td>{t}DNS Class{/t}
-                                       </td>
                                        <td>
-                                               <input type="text" name="dNSClass" value="{$dNSClass}">
+                                               {$Mxrecords}
+                                               <input type="text"              name="StrMXRecord" value="">
+                                               <input type="submit"    name="AddMXRecord" value="{t}Add{/t}">
                                        </td>
                                </tr>
                        </table>