From f8dc0335d722acf93a5175786c9217621894e475 Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 8 Mar 2006 09:01:25 +0000 Subject: [PATCH] Some dns checkins git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2822 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../admin/systems/class_servDNSeditZone.inc | 9 +- .../systems/class_servDNSeditZoneEntries.inc | 342 +++++++++++++++++- plugins/admin/systems/class_termDNS.inc | 2 + .../admin/systems/servDNSeditZoneEntries.tpl | 9 +- plugins/admin/systems/servdnseditzone.tpl | 6 +- 5 files changed, 359 insertions(+), 9 deletions(-) diff --git a/plugins/admin/systems/class_servDNSeditZone.inc b/plugins/admin/systems/class_servDNSeditZone.inc index e3770a5e4..d563fc302 100644 --- a/plugins/admin/systems/class_servDNSeditZone.inc +++ b/plugins/admin/systems/class_servDNSeditZone.inc @@ -168,7 +168,7 @@ class servdnseditZone extends plugin /* Open Zone Entry Edit Dialog */ if(isset($_POST['EditZoneEntries'])){ - $this->dialog= new servDNSeditZoneEntries($this->config,$this->dn); + $this->dialog= new servDNSeditZoneEntries($this->config,$this->dn,$this->zoneName,$this->FlipIp($this->ReverseZone),$this->RecordTypes); } /* Save Zone Entry Edit Dialog @@ -289,6 +289,13 @@ class servdnseditZone extends plugin /* Assign records list */ + + if($this->dn != "new"){ + $smarty->assign("NotNew", true); + }else{ + $smarty->assign("NotNew", false); + } + $smarty->assign("Mxrecords", $div->DrawList()); $smarty->assign("records" , $this->generateRecordsList()); diff --git a/plugins/admin/systems/class_servDNSeditZoneEntries.inc b/plugins/admin/systems/class_servDNSeditZoneEntries.inc index d3b503139..35b2143c1 100644 --- a/plugins/admin/systems/class_servDNSeditZoneEntries.inc +++ b/plugins/admin/systems/class_servDNSeditZoneEntries.inc @@ -9,44 +9,378 @@ class servDNSeditZoneEntries extends plugin /* attribute list for save action */ var $ignore_account= TRUE; - var $attributes= array(); + var $attributes= array("zoneName"); var $objectclasses= array("whatever"); - function servDNSeditZoneEntries ($config, $dn= NULL) + var $Devices = array(); + var $InitDevices = array(); + var $zoneName = ""; + var $reverseName = ""; + var $RecordTypes= array(); + + function servDNSeditZoneEntries ($config, $dn= NULL,$zoneName,$reverseName,$RTypes) { plugin::plugin ($config, $dn); + + $this->zoneName = $zoneName; + $this->reverseName = $reverseName; + $this->RecordTypes = $RTypes; + $this->RecordTypes['cNAMERecord'] = "relativeDomainName"; + + + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + + /* Get all objects it this zone ... + */ + $res = $ldap->search("(&(objectClass=dNSZone)(|(zoneName=".$zoneName.")(zoneName=".$reverseName.".in-addr.arpa))(!(relativeDomainName=@)))"); + while($attrs = $ldap->fetch($res)){ + 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]; + } + } + } + + /* Add additional informations + to all catched objects + */ + foreach($this->Devices as $dn => $Recs){ + $this->Devices[$dn]['OBJECT'] = $ldap->fetch($ldap->cat($dn,array("objectClass","cn"))); + } + + $this->Devices; + $this->InitDevices = $this->Devices; } function execute() { plugin::execute(); + /* Check posts for operations ... + */ + $once = true; + foreach($_POST as $name => $value){ + + /* 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); + + $dn = base64_decode($tmp2[0]); + $record = $tmp2[1]; + $numrec = $tmp2[2]; + + $this->Devices[$dn]['RECORDS'][$record][] = ""; + } + + /* 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]); + } + + /* Don't know how i should implement this ... + */ + if((preg_match("/^UserRecord_/",$name)) && ($once)){ + $once = false; + $tmp = preg_replace("/^UserRecord_/","",$name); + $tmp = preg_replace("/_.*$/","",$tmp); + $tmp2 = split("\|",$tmp); + + $dn = base64_decode($tmp2[0]); + $record = $tmp2[1]; + $numrec = $tmp2[2]; + + $this->FreeDevices[$dn]['RECORDS']['User'][$numrec] = ""; + } + } + + /* Fill templating stuff */ $smarty= get_smarty(); $display= ""; + + $table = ""; + foreach($this->Devices as $key => $dev){ + $table .= $this->generateRecordConfigurationRow($key); + } + + $smarty->assign("table",$table);; $display.= $smarty->fetch(get_template_path('servDNSeditZoneEntries.tpl', TRUE)); return($display); } + /* 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 + $str = "

".sprintf(_("Settings for '%s'"),$obj_dn)." :

"; + + /* Walk through all defined records + */ + foreach($obj['RECORDS'] as $id => $types){ + + /* Create table + */ + $str.= ""; + foreach($types as $key => $type){ + + /* Create unique post name + */ + $name = base64_encode($obj_dn)."|".$id."|".$key; + + $str .= " + + + + + + "; + } + $str .="
+ ".$objectName." + + ".$this->createRecordTypeSelection($id,$name)." + + + + + + + +
"; + } + return($str); + } + + /* Create selectbox with all available option types + */ + function createRecordTypeSelection($id,$refID){ + $str = "\n"; + return($str); + } + function remove_from_parent() { } function save_object() { - plugin::save_object(); + /* Save all form fields + */ + + /* Possible attributes posted + */ + $arr = array("RecordTypeSelection_","ValueSelection_"); + + foreach($_POST as $name=>$value){ + + foreach($arr as $type) + + /* Check if attribute was posted + */ + if(preg_match("/".$type."/",$name)){ + + /* Extract informations out of postname + */ + $action = $type; + $tmp = preg_replace("/^".$action."/","",$name); + $tmp = preg_replace("/_.*$/","",$tmp); + $tmp2 = split("\|",$tmp); + + $dn = base64_decode($tmp2[0]); + $record = $tmp2[1]; + $numrec = $tmp2[2]; + + /* Check which type of post was posted + */ + + // checkbox was posted + if($action == "RecordTypeSelection_"){ + if($record != $value){ + $str = $this->Devices[$dn]['RECORDS'][$record][$numrec]; + unset($this->Devices[$dn]['RECORDS'][$record][$numrec]); + $this->Devices[$dn]['RECORDS'][$value][] = $str; + } + } + + // entry value was psoted + if($action == "ValueSelection_"){ + $this->Devices[$dn]['RECORDS'][$record][$numrec] = $value; + } + } + } } + /* check something + */ function check() { $message= array(); + // Nothing right now return ($message); } function save() { - plugin::save(); + /* Set all initial records to array() + This means they will be removed from the entry + */ + foreach($this->InitDevices as $dn => $obj){ + $attrs[$dn]= array(); + foreach($obj['RECORDS'] as $rectype => $records){ + $attrs[$dn][$rectype] = array(); + } + } + + /* 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; + } + } + } + + /* Get ldap link + */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->config->current['BASE']); + + /* Generate 'T odo' :-) + */ + $tmp = ($this->generate_LDAP_entries($attrs)); + + /* Delete all objects which should be delted + */ + foreach($tmp['del'] as $key => $ntr){ + $ldap->rmdir($key); + } + + /* Add append new / updated entries + */ + foreach($tmp['addupdate'] as $key => $attrs){ + $ldap->cat($key); + if($ldap->count() > 0){ + $ldap->cd($key); + $ldap->modify($attrs); + }else{ + $ldap->cd($this->config->current['BASE']); + $ldap->cd($key); + $ldap->add($attrs); + } + + /* Display errors ... + */ + if($ldap->error != "Success"){ + echo "
".$ldap->error."
"; + print_a($attrs); + } + } + } + + + function generate_LDAP_entries($objs) + { + $entries = array(); + $delete = array(); + + /* these entries are added to base object ... + */ + $normal = array("mDRecord","aRecord","tXTRecord","mXRecord","hInfoRecord","mInfoRecord","aFSDBRecord","SigRecord","KeyRecord","aAAARecord","nSRecord", + "LocRecord","nXTRecord","sRVRecord","nAPTRRecord","kXRecord","certRecord","a6Record","dSRecord","sSHFPRecord","rRSIGRecord","nSECRecord"); + + /* Create t odo + */ + foreach($objs as $dn => $recs){ + + /* Get basic info + */ + $obj = $this->Devices[$dn]; + $objectName = $obj['OBJECT']['cn'][0]; + + /* Calculate records ... + */ + foreach($recs as $type => $rec){ + + /* Simply add normal entries + */ + if(in_array($type,$normal)){ + $entries['relativeDomainName='.$objectName.','.$dn][$type] = $rec ; + } + + /* Special handling for cNAMERecords + */ + if($type == "cNAMERecord"){ + if(isset($this->InitDevices[$dn]['RECORDS']['cNAMERecord'])){ + foreach($this->InitDevices[$dn]['RECORDS']['cNAMERecord'] as $warmal){ + $delete['relativeDomainName='.$warmal.','.$dn] = ""; + } + } + foreach($rec as $r){ + if(!empty($r)){ + $entries['relativeDomainName='.$r.','.$dn]['cNAMERecord'] = $objectName; + $entries['relativeDomainName='.$r.','.$dn]['relativeDomainName'] = $r; + $entries['relativeDomainName='.$r.','.$dn]['objectClass'] = array("top","dNSZone"); + $entries['relativeDomainName='.$r.','.$dn]['zoneName'] = $this->zoneName; + } + } + } + + /* Special handling for ptrrecord + */ + if($type == "pTRRecord"){ + if(isset($this->InitDevices[$dn]['RECORDS']['pTRRecord'])){ + foreach($this->InitDevices[$dn]['RECORDS']['pTRRecord'] as $warmal){ + $delete['relativeDomainName='.$warmal.','.$dn] = ""; + } + } + foreach($rec as $r){ + if(!empty($r)){ + $entries['relativeDomainName='.$r.','.$dn]['pTRRecord'] = $objectName; + $entries['relativeDomainName='.$r.','.$dn]['zoneName'] = $this->reverseName.".in-addr.arpa"; + $entries['relativeDomainName='.$r.','.$dn]['relativeDomainName'] = $r; + $entries['relativeDomainName='.$r.','.$dn]['objectClass'] = array("top","dNSZone"); + } + } + } + } + } + + return(array("del"=> $delete , "addupdate"=> $entries)); } + } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: diff --git a/plugins/admin/systems/class_termDNS.inc b/plugins/admin/systems/class_termDNS.inc index 7f35024a6..b35c9c70f 100644 --- a/plugins/admin/systems/class_termDNS.inc +++ b/plugins/admin/systems/class_termDNS.inc @@ -318,6 +318,8 @@ class termDNS extends plugin if($this->DNS_is_account){ foreach($this->types as $name => $values){ + if($values['type'] == "tXTRecord") continue; + /* Check if there is an aRecord defined which uses the same IP as used in IPhostAddress */ if(($values['type'] == "aRecord")&&($values['value'] == $this->ipHostNumber)&&($values['status']!="deleted")){ $message[]=sprintf(_("The device IP '%s' is added as 'A Record', this will be done automatically, please remove the record."), diff --git a/plugins/admin/systems/servDNSeditZoneEntries.tpl b/plugins/admin/systems/servDNSeditZoneEntries.tpl index 5cc51d728..2ab4f2aa4 100644 --- a/plugins/admin/systems/servDNSeditZoneEntries.tpl +++ b/plugins/admin/systems/servDNSeditZoneEntries.tpl @@ -1,11 +1,18 @@ -sdfasdf +

{t}This dialog allows you to configure all components of this DNS zone on a single list.{/t}

+{$table} + + + + +

 

+