From: hickert Date: Wed, 15 Mar 2006 08:01:06 +0000 (+0000) Subject: Added editing dialog for zones ... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=1a7070808b558fa25a8fea2043d4142079d5b7db;p=gosa.git Added editing dialog for zones ... git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2841 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/plugins/admin/systems/class_servDNS.inc b/plugins/admin/systems/class_servDNS.inc index 644c1abe2..a876012c4 100644 --- a/plugins/admin/systems/class_servDNS.inc +++ b/plugins/admin/systems/class_servDNS.inc @@ -35,10 +35,9 @@ class servdns extends plugin $this->RecordTypes['mDRecord'] = "mDRecord"; // ok $this->RecordTypes['mXRecord'] = "mXRecord"; // ok $this->RecordTypes['nSRecord'] = "nSRecord"; // ok - $this->RecordTypes['pTRRecord'] = "relativeDomainName";// ok $this->RecordTypes['hInfoRecord'] = "hInfoRecord"; // ok $this->RecordTypes['mInfoRecord'] = "mInfoRecord"; // ok - $this->RecordTypes['tXTRecord'] = "tXTRecord"; // ok +// $this->RecordTypes['tXTRecord'] = "tXTRecord"; // ok $this->RecordTypes['aFSDBRecord'] = "aFSDBRecord"; // ok $this->RecordTypes['SigRecord'] = "SigRecord"; // ok $this->RecordTypes['KeyRecord'] = "KeyRecord"; // ok @@ -60,9 +59,10 @@ class servdns extends plugin /* Get all records */ $ldap = $this->config->get_ldap_link(); $ldap->cd($this->dn); - $ldap->search("(&(objectClass=dNSZone)(relativeDomainName=@))",array("*")); + $ldap->ls("(&(objectClass=dNSZone)(relativeDomainName=@))",$dn,array("*")); while($attrs = $ldap->fetch()){ + /* If relative domainname * Try to read dnsclass / TTl / zone */ @@ -77,7 +77,8 @@ class servdns extends plugin $types[$zoneName]['ReverseDN'] = $attrs['dn']; }else{ - /* Generate SOA entry */ + /* Generate SOA entry + */ if(isset($attrs['sOARecord'][0])){ $tmp = split("\ ",$attrs['sOARecord'][0]) ; $tmp2 = array(); @@ -93,23 +94,28 @@ class servdns extends plugin } } - /* Set dns Class*/ + /* Set dns Class + */ if(isset($attrs['dNSClass'][0])){ $types[$attrs['zoneName'][0]]['dNSClass'] = $attrs['dNSClass'][0]; } - /* Set zone Name */ + /* Set zone Name + */ if(isset($attrs['zoneName'][0])){ $types[$attrs['zoneName'][0]]['zoneName'] = $attrs['zoneName'][0]; } - /* Create list with all used records */ + /* Create list with all used records + */ foreach($this->RecordTypes as $name => $value){ - /* If there is a record attribute */ + /* If there is a record attribute + */ if(isset($attrs[$name])){ - /* get all entries */ + /* get all entries + */ for($i = 0 ; $i < $attrs[$value]['count']; $i ++){ $types[$attrs['zoneName'][0]]['Records'][] =array("type" =>$name, "inittype" =>$name, @@ -122,7 +128,8 @@ class servdns extends plugin } } - /* If there is at least one entry in this -> types, we have DNS enabled */ + /* If there is at least one entry in this -> types, we have DNS enabled + */ $this->Zones = $types; if(count($this->Zones) == 0){ $this->is_account = false; @@ -130,7 +137,8 @@ class servdns extends plugin $this->is_account = true; } - /* Store initally account settings */ + /* Store initally account settings + */ $this->DNSinitially_was_account = $this->is_account; } @@ -152,19 +160,23 @@ class servdns extends plugin function execute() { - /* Call parent execute */ + /* Call parent execute + */ plugin::execute(); - /* Fill templating stuff */ + /* Fill templating stuff + */ $smarty= get_smarty(); $display= ""; - /* Do we need to flip is_account state? */ + /* Do we need to flip is_account state? + */ if (isset($_POST['modify_state'])){ $this->is_account= !$this->is_account; } - /* Show tab dialog headers */ + /* Show tab dialog headers + */ if ($this->is_account){ $display= $this->show_header(_("Remove DNS service"), _("This server has DNS features enabled. You can disable them by clicking below.")); @@ -174,40 +186,49 @@ class servdns extends plugin return ($display); } - /* Edited or Added zone hould be saved saved */ + /* Edited or Added zone hould be saved saved + */ if(isset($_POST['SaveZoneChanges'])){ $this->dialog->save_object(); - /* Check if noting went wrong */ + /* Check if noting went wrong + */ if(count($this->dialog->check())){ foreach($this->dialog->check() as $msgs){ print_red($msgs); } }else{ - /* add new/edited zone */ + /* add new/edited zone + */ $ret = $this->dialog->save(); + $ret['InitialzoneName']= $this->dialog->InitiallyZoneName; + $ret['InitialreverseZone']= $this->dialog->InitiallyReverseZone; unset($this->Zones[$this->dialog->InitiallyZoneName]); $this->Zones[$ret['zoneName']] = $ret; $this->dialog = NULL; } } - /* Cancel zone edit / new */ + /* Cancel zone edit / new + */ if(isset($_POST['CancelZoneChanges'])){ $this->dialog = NULL; } - /* Add empty new zone */ + /* Add empty new zone + */ if(isset($_POST['AddZone'])){ $this->dialog = new servdnseditZone($this->config,$this->dn,$this->RecordTypes); } - /* Check for edit zone request */ + /* Check for edit zone request + */ $once = false; foreach( $_POST as $name => $value){ - /* check all post for edit request */ + /* check all post for edit request + */ if(preg_match("/^editZone_/",$name)&&!$once){ $once =true; $tmp = preg_replace("/^editZone_/","",$name); @@ -215,10 +236,9 @@ class servdns extends plugin $this->dialog= new servdnseditZone($this->config,$this->dn,$this->RecordTypes,$this->Zones[$tmp]); } - /* check posts for delete zone */ + /* check posts for delete zone + */ if(preg_match("/^delZone_/",$name)&&!$once){ - - $once =true; $tmp = preg_replace("/^delZone_/","",$name); $tmp = base64_decode(preg_replace("/_.*$/","",$tmp)); @@ -244,18 +264,21 @@ class servdns extends plugin } } - /* Show dialog */ + /* Show dialog + */ if($this->dialog!= NULL){ $this->dialog->save_object(); $this->dialog->parent = $this; return($this->dialog->execute()); } - /* Create Listbox with existing Zones */ + /* Create Listbox with existing Zones + */ $ZoneList = new divSelectBox("dNSZones"); $ZoneList -> SetHeight(254); - /* Add entries to divlist*/ + /* Add entries to divlist + */ $editImg = " "; foreach($this->Zones as $zone => $values ){ @@ -268,14 +291,16 @@ class servdns extends plugin )); } - /* Display tempalte */ + /* Display tempalte + */ $smarty->assign("ZoneList",$ZoneList->DrawList()); $display.= $smarty->fetch(get_template_path('servdns.tpl', TRUE)); return($display); } - /* This funtion returns all used Zonenames */ + /* This funtion returns all used Zonenames + */ function getUsedZoneNames() { $ret = array(); @@ -293,7 +318,8 @@ class servdns extends plugin } - /* Remove dns service */ + /* Remove dns service + */ function remove_from_parent() { if(!$this->DNSinitially_was_account){ @@ -337,18 +363,49 @@ class servdns extends plugin /* Save to LDAP */ function save() { - /* Ldap conenction / var initialization */ + /* Ldap conenction / var initialization + */ $ldap = $this->config->get_ldap_link(); $ldap->cd($this->config->current['BASE']); $actions =array("update"=>array(),"add"=>array(),"delete"=>array()); - /* Generate entries for all zones, and check if they must be updated deleted added */ - foreach($this->Zones as $zone){ + /* Generate entries for all zones, and check if they must be updated deleted added + */ + foreach($this->Zones as $key => $zone){ + if(isset($zone['InitialzoneName']) && ($zone['zoneName'] != $zone['InitialzoneName'])){ + $dst = "zoneName=".$zone['zoneName'].",".$this->dn; + $src = "zoneName=".$zone['InitialzoneName'].",".$this->dn; + $this->recursive_move($src,$dst); + + $tmp['zoneName'] = $zone['zoneName']; + $ldap->search ("(&(objectClass=dNSZone)(zoneName=".$zone['InitialzoneName']."))",array("relativeDomainName")); + while($attrs = $ldap->fetch()){ + $ldap->cd($attrs['dn']); + $ldap->modify($tmp); + show_ldap_error($ldap->get_error()); + } + } + if(isset($zone['InitialreverseZone']) &&($zone['InitialreverseZone'] != $zone['ReverseZone'])){ + $dst = "zoneName=".$zone['ReverseZone'].",".$this->dn; + $src = "zoneName=".$zone['InitialreverseZone'].",".$this->dn; + $this->recursive_move($src,$dst); + + $tmp['zoneName'] = $zone['zoneName']; + $ldap->search ("(&(objectClass=dNSZone)(zoneName=".$zone['InitialzoneName']."))",array("relativeDomainName")); + while($attrs = $ldap->fetch()){ + $ldap->cd($attrs['dn']); + $ldap->modify($tmp); + show_ldap_error($ldap->get_error()); + } + } - /* Get ldap syntax */ + + /* Get ldap syntax + */ $tmp = $this->generate_LDAP_entries($zone); - /* Check if dn is new, or if entry was edited */ + /* Check if dn is new, or if entry was edited + */ foreach($tmp as $key => $values){ if(isset($this->usedDNS[$key])){ $actions['update'][$key]=$values; @@ -359,32 +416,35 @@ class servdns extends plugin } } - /* Check which dns are not used anymore ...*/ + /* Check which dns are not used anymore ... + */ foreach($this->usedDNS as $key => $values){ $actions['delete'][$key] = $values; } - /* Remove deleted zones */ + /* Remove deleted zones + */ foreach($actions['delete'] as $dn => $attrs){ $ldap->cd($dn); $ldap->rmdir_recursive($dn); } - /* Add new zones */ + /* Add new zones + */ foreach($actions['add'] as $dn => $attrs){ $ldap->cd($this->config->current['BASE']); - // $ldap->create_missing_trees($dn); $ldap->cd($dn); $ldap->add($attrs); } - /* Update existing entries */ + /* Update existing entries + */ foreach($actions['update'] as $dn => $attrs){ $ldap->cd($dn); - //$this->cleanup(); $ldap->modify ($attrs); } + show_ldap_error($ldap->get_error()); } @@ -406,7 +466,8 @@ class servdns extends plugin $tmp['sOARecord'] = $str; - /* Generate Record entries */ + /* Generate Record entries + */ $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(); @@ -420,7 +481,7 @@ class servdns extends plugin } } /* Check if there are records removed, - if there are some removed records, the append an array + if there are some removed records, then append an array to ensure that these record types are deleted */ if((isset($zone['Records']))&&(is_array($zone['Records']))){ @@ -433,12 +494,14 @@ class servdns extends plugin } } - /* generate forward entry */ + /* generate forward entry + */ $dn = "zoneName=".$zone['zoneName'].",".$this->dn; $tmp2[$dn] = $tmp; $tmp2[$dn]['zoneName'] = $zone['zoneName']; - /* generate reverse entry */ + /* generate reverse entry + */ $dn = "zoneName=".$this->FlipIp($zone['ReverseZone']).".in-addr.arpa,".$this->dn; $tmp2[$dn] = $tmp; $tmp2[$dn]['tXTRecord'] ="zoneName=".$zone['zoneName']; @@ -446,10 +509,6 @@ class servdns extends plugin return($tmp2); } - - - } - // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/plugins/admin/systems/class_servDNSeditZone.inc b/plugins/admin/systems/class_servDNSeditZone.inc index d563fc302..2ab894396 100644 --- a/plugins/admin/systems/class_servDNSeditZone.inc +++ b/plugins/admin/systems/class_servDNSeditZone.inc @@ -66,8 +66,8 @@ class servdnseditZone extends plugin foreach($this->Records as $key => $rec){ if($rec['type'] == "mXRecord"){ $tmp = split(" ",$rec['value']); - $rec['value'] = $tmp[0]; - $tmp2[$tmp[1]] = $rec; + $rec['value'] = $tmp[1]; + $tmp2[$tmp[0]] = $rec; unset($this->Records[$key]); } } @@ -80,6 +80,7 @@ class servdnseditZone extends plugin $this->mXRecords = array(); $this->Records = array(); } + $str = date("Ymd"); if(preg_match("/^".$str."/",$this->sOAserial)){ $this->sOAserial = $this->sOAserial + 1; @@ -168,7 +169,7 @@ class servdnseditZone extends plugin /* Open Zone Entry Edit Dialog */ if(isset($_POST['EditZoneEntries'])){ - $this->dialog= new servDNSeditZoneEntries($this->config,$this->dn,$this->zoneName,$this->FlipIp($this->ReverseZone),$this->RecordTypes); + $this->dialog= new servDNSeditZoneEntries($this->config,$this->dn,$this->InitiallyZoneName,$this->FlipIp($this->InitiallyReverseZone),$this->RecordTypes); } /* Save Zone Entry Edit Dialog @@ -289,12 +290,7 @@ 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()); @@ -437,8 +433,10 @@ class servdnseditZone extends plugin $ret[$name] = $this->$name; } + /* Create mx records + */ foreach($this->mXRecords as $key => $rec){ - $rec['value'].= " ".$key; + $rec['value']= $key." ".$rec['value']; $this->Records [] = $rec; } diff --git a/plugins/admin/systems/class_servDNSeditZoneEntries.inc b/plugins/admin/systems/class_servDNSeditZoneEntries.inc index 35b2143c1..f1f0d16e7 100644 --- a/plugins/admin/systems/class_servDNSeditZoneEntries.inc +++ b/plugins/admin/systems/class_servDNSeditZoneEntries.inc @@ -12,45 +12,134 @@ class servDNSeditZoneEntries extends plugin var $attributes= array("zoneName"); var $objectclasses= array("whatever"); - var $Devices = array(); - var $InitDevices = array(); - var $zoneName = ""; - var $reverseName = ""; - var $RecordTypes= array(); + var $Devices = array(); + var $InitDevices = array(); + + var $FreeHosts = array(); + var $InitFreeHosts= array(); + + var $zoneName = ""; // ZoneName of currently edited Zone + var $reverseName = ""; // ReverseZone of the currently edited Zone + + var $RecordTypes= array(); // Possible record type. They will be set in contrucktor + // and some types will be added later (cName/Ptr) function servDNSeditZoneEntries ($config, $dn= NULL,$zoneName,$reverseName,$RTypes) { plugin::plugin ($config, $dn); + /* Initialise class + */ $this->zoneName = $zoneName; $this->reverseName = $reverseName; $this->RecordTypes = $RTypes; + + /* Add records types which are not allowed in zones + */ $this->RecordTypes['cNAMERecord'] = "relativeDomainName"; - + $this->RecordTypes['pTRRecord'] = "relativeDomainName"; + $this->RecordTypes['tXTRecord'] = "tXTRecord"; + /* Get ldap connection + */ $ldap = $this->config->get_ldap_link(); $ldap->cd($this->config->current['BASE']); - /* Get all objects it this zone ... + /* Get all objects using this zone + * Workstations / Terminals */ $res = $ldap->search("(&(objectClass=dNSZone)(|(zoneName=".$zoneName.")(zoneName=".$reverseName.".in-addr.arpa))(!(relativeDomainName=@)))"); while($attrs = $ldap->fetch($res)){ + if(preg_match("/zoneName=/",$attrs['dn'])) continue; 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]; + $this->Devices[$dn]['Type'] = "Exists"; } } } - + /* Add additional informations - to all catched objects + to all catched objects ( ObjectInformations) */ foreach($this->Devices as $dn => $Recs){ - $this->Devices[$dn]['OBJECT'] = $ldap->fetch($ldap->cat($dn,array("objectClass","cn"))); + $attrs = $ldap->fetch($ldap->cat($dn,array("objectClass","cn"))); + $this->Devices[$dn]['OBJECT'] = $attrs; + $this->Devices[$dn]['OrigCn'] = $attrs['cn'][0]; } + /* Add Free Hand entries + * Free hand entries are entries which are not directly assigned + * to an existing network object like a WS or a Terminal. + * They will be found in a subtree within this zone. + * For example : + * The object name is FreeHand1, + * zoneName=test.de,cn=server ... + * // ObjectContainer + * relativeDomainName=FreeHand1,zoneName=.... + * // Dns entry + * relativeDomainName=FreeHand1, relativeDomainName=FreeHand1,zoneName=.... + * // cName entry .... + * relativeDomainName=terminal12, relativeDomainName=FreeHand1,zone... + */ + $ldap->cd ("zoneName=".$this->zoneName.",".$this->dn); + $ldap->ls ("(&(objectClass=dNSZone)(!(relativeDomainName=@)))","zoneName=".$this->zoneName.",".$this->dn,array("*")); + + $GetSubInformations = array(); + while($attrs = $ldap->fetch()){ + + unset($attrs[$val]['count']); + + $dn = $attrs['dn']; + + /* Split dn into relativeDomainNames + */ + $tmp = split("relativeDomainName=",trim(preg_replace("/,zoneName=.*$/","\\1",$dn))); + $tmp2 = array(); + foreach($tmp as $t){ + if(empty($t)) continue; + $tmp2[] = preg_replace("/,$/","",$t); + } + + /* Set object Name + */ + $cn = $tmp2[0]; + $dn = "relativeDomainName=".$cn.",zoneName=".$this->zoneName.",".$this->dn; + + /* Create entry + */ + $this->Devices[$dn]['OBJECT'] = $attrs; + $this->Devices[$dn]['OBJECT']['cn'][0] = $cn;//attrs['relativeDomainName']; + $this->Devices[$dn]['OBJECT']['OrigCn'] = $cn;//attrs['relativeDomainName'][0]; + $this->Devices[$dn]['Type'] = "Free"; + + $GetSubInformations [] = $dn; + } + + /* Get sub informations + CName or pTR records are stored in a sub entry. + + // The base entry with aRecords/tXTrecords/.... + relativeDomainName=Keks, relativeDomainName=Keks, zoneName=.... + + // And the sub entries like this one + relativeDomainName=10.2.64.in-addr.arpa, relativeDomainName=Keks, zoneName =... + ( They can't be stored in a single entry, so i decided to store them this way ). + */ + foreach($GetSubInformations as $dn){ + $ldap->ls("(&(objectClass=dNSZone)(!(relativeDomainName=@)))",$dn,array("*")); + while($attrs= $ldap->fetch()){ + foreach($this->RecordTypes as $atr => $val){ + if((isset($attrs[$atr])) && (is_array($attrs[$atr]))){ + unset($attrs[$val]['count']); + $this->Devices[$dn]['RECORDS'][$atr] = $attrs[$val]; + } + } + } + } + $this->Devices; $this->InitDevices = $this->Devices; } @@ -91,26 +180,28 @@ class servDNSeditZoneEntries extends plugin $record = $tmp2[1]; $numrec = $tmp2[2]; - unset($this->Devices[$dn]['RECORDS'][$record][$numrec]); + unset($this->Devices[$dn]['RECORDS'][$record][$numrec]); + + if(count($this->Devices[$dn]['RECORDS'][$record]) == 0){ + unset($this->Devices[$dn]['RECORDS'][$record]); + if(count($this->Devices[$dn]['RECORDS']) ==0){ + unset($this->Devices[$dn]); + } + } + } /* 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] = ""; + $once = false; + $tmp['RECORDS']['aRecord'][0] = 'empty'; + $tmp['Type'] = 'Free'; + $tmp['OBJECT']['cn'][0] = 'Free'; + $this->Devices[] = $tmp; } } - /* Fill templating stuff */ $smarty= get_smarty(); $display= ""; @@ -124,6 +215,7 @@ class servDNSeditZoneEntries extends plugin $display.= $smarty->fetch(get_template_path('servDNSeditZoneEntries.tpl', TRUE)); return($display); } + /* Create html table out of given entry */ @@ -134,16 +226,22 @@ class servDNSeditZoneEntries extends plugin $obj = $this->Devices[$obj_dn]; $objectName = $obj['OBJECT']['cn'][0]; - // set title - $str = "

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

"; - + /* Set title + */ + if($obj['Type'] == "Free"){ + $str = "

".sprintf(_("Settings for free host entry # %s"),($obj_dn +1))." :

"; + }else{ + $str = "

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

"; + } + + $hostNameOnce = true; /* Walk through all defined records */ + $str.= ""; foreach($obj['RECORDS'] as $id => $types){ /* Create table */ - $str.= "
"; foreach($types as $key => $type){ /* Create unique post name @@ -151,8 +249,16 @@ class servDNSeditZoneEntries extends plugin $name = base64_encode($obj_dn)."|".$id."|".$key; $str .= " - "; } - $str .="
- ".$objectName." + "; + + if($hostNameOnce){ + $hostNameOnce = false; + $str .=""; + }else{ + $str .=$objectName; + } + + $str .=" ".$this->createRecordTypeSelection($id,$name)." @@ -169,15 +275,19 @@ class servDNSeditZoneEntries extends plugin
"; } + $str .=""; return($str); } /* Create selectbox with all available option types */ - function createRecordTypeSelection($id,$refID){ - $str = "\n"; + }else{ + $str = "\n - {html_options values=$ZoneKeys output=$Zones} + {html_options values=$ZoneKeys output=$Zones selected=$zoneName} diff --git a/plugins/admin/systems/servDNSeditZoneEntries.tpl b/plugins/admin/systems/servDNSeditZoneEntries.tpl index 2ab4f2aa4..a16f4f017 100644 --- a/plugins/admin/systems/servDNSeditZoneEntries.tpl +++ b/plugins/admin/systems/servDNSeditZoneEntries.tpl @@ -1,10 +1,11 @@ -

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

+

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

+{t}Be carefull editing record types with this dialog. All changes will be saved immediately when using the save button.{/t} +
+
+

 

{$table} - - -