From eb17e7b386fca35e4eaf28ab9bda0e5e8cb26468 Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 7 Mar 2006 08:36:20 +0000 Subject: [PATCH] Updated dns, added mx record editor git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2815 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/admin/systems/class_servDNS.inc | 19 +- .../admin/systems/class_servDNSeditZone.inc | 175 +++++++++++++++++- plugins/admin/systems/servdnseditzone.tpl | 33 ++-- 3 files changed, 191 insertions(+), 36 deletions(-) diff --git a/plugins/admin/systems/class_servDNS.inc b/plugins/admin/systems/class_servDNS.inc index c31971f3f..644c1abe2 100644 --- a/plugins/admin/systems/class_servDNS.inc +++ b/plugins/admin/systems/class_servDNS.inc @@ -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; diff --git a/plugins/admin/systems/class_servDNSeditZone.inc b/plugins/admin/systems/class_servDNSeditZone.inc index d814d416e..82e40e3db 100644 --- a/plugins/admin/systems/class_servDNSeditZone.inc +++ b/plugins/admin/systems/class_servDNSeditZone.inc @@ -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 = " "; + $onedown = " "; + $onedel = " + "; + + 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 = ""; 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 = " -
- + + + +
{t}Zone name{/t} + {t}Zone name{/t}{$must}
{t}Network address{/t}{$must} + +
+ - -
{t}Network address{/t} + + {t}Zone entries{/t} + +
@@ -85,20 +93,13 @@
-

{t}Parameter{/t}

- - - - - +

{t}MxRecords{/t}

+
{t}DNS TTL{/t} - - -
-
{t}DNS Class{/t} - - + {$Mxrecords} + +
-- 2.30.2