X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Fsystems%2Fclass_servDNSeditZoneEntries.inc;h=3a13bde7dbfac17fc1f0b18238cb336979970ad1;hb=7f51b7c557fe5fb3c73b5bde15856fbfdb08efbb;hp=35b2143c12cb74743152c18e957844b611ad98aa;hpb=f8dc0335d722acf93a5175786c9217621894e475;p=gosa.git diff --git a/plugins/admin/systems/class_servDNSeditZoneEntries.inc b/plugins/admin/systems/class_servDNSeditZoneEntries.inc index 35b2143c1..3a13bde7d 100644 --- a/plugins/admin/systems/class_servDNSeditZoneEntries.inc +++ b/plugins/admin/systems/class_servDNSeditZoneEntries.inc @@ -8,109 +8,102 @@ class servDNSeditZoneEntries extends plugin var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser"); /* attribute list for save action */ - var $ignore_account= TRUE; - var $attributes= array("zoneName"); - var $objectclasses= array("whatever"); + var $ignore_account = TRUE; + var $attributes = array(); + var $objectclasses = array("whatever"); - var $Devices = array(); - var $InitDevices = array(); - var $zoneName = ""; - var $reverseName = ""; - var $RecordTypes= array(); + var $Devices = array(); - function servDNSeditZoneEntries ($config, $dn= NULL,$zoneName,$reverseName,$RTypes) + var $zoneName = ""; // ZoneName of currently edited Zone + var $reverseName = ""; // ReverseZone of the currently edited Zone + + var $RecordTypes = array(); // Possible record type. + + var $disableDialog = false; // Dialog will be disabled, if this zone is new + + function servDNSeditZoneEntries ($config,$dn, $zoneObject) { plugin::plugin ($config, $dn); - $this->zoneName = $zoneName; - $this->reverseName = $reverseName; - $this->RecordTypes = $RTypes; - $this->RecordTypes['cNAMERecord'] = "relativeDomainName"; + /* Initialise class + */ + $this->RecordTypes = getDnsRecordTypes(); + $this->dn = "zoneName=".$zoneObject['InitialzoneName'].",".$dn; + $this->zoneName = $zoneObject['InitialzoneName']; + $this->reverseName = $zoneObject['InitialReverseZone']; - + /* Get ldap connection + */ $ldap = $this->config->get_ldap_link(); $ldap->cd($this->config->current['BASE']); - /* Get all objects it this zone ... + /* Get zone content */ - $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]; - } - } - } + $ldap->ls("(&(objectClass=dNSZone)(!(relativeDomainName=@)))",$this->dn,array("relativeDomainName")); - /* 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"))); + while($attrs = $ldap->fetch()){ + $this->Devices[$attrs['relativeDomainName'][0]] = getDNSHostEntries($config,$attrs['relativeDomainName'][0],true); + $this->Devices[$attrs['relativeDomainName'][0]]['OrigCn'] = $attrs['relativeDomainName'][0]; } - $this->Devices; - $this->InitDevices = $this->Devices; + $ldap->cat($this->dn,array("objectClass")); + + $this->disableDialog = true; + if(count($this->Devices)|| $ldap->count()){ + $this->disableDialog = false; + } } function execute() { - plugin::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][] = ""; + $tmp = preg_replace("/^.*_(.*)_.*$/","\\1",$name); + $tmp2 = split("\|",$tmp); + + /* Add new host entry + */ + if((preg_match("/^UserRecord_?/",$name)) && ($once)){ + $once = false; + $entry = getDNSHostEntries($this->config,"",true); + $entry['exists'] = true; + $entry['zoneName'] = $this->zoneName; + $entry['RECORDS'][] = array("type" => "aRecord" , "value"=>""); + $this->Devices[_("New entry")] = $entry; } - + + if(count($tmp2) != 2) continue; + + $Name = base64_decode($tmp2[0]); + $RecordID = $tmp2[1]; + + /* Add new REcord + */ + if((preg_match("/^AddRecord_/",$name)) && ($once)){ + $once = false; + $this->Devices[$Name]['RECORDS'][] = $this->Devices[$Name]['RECORDS'][$RecordID]; + } + /* 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]); + if(isset($this->Devices[$Name]['RECORDS'][$RecordID])){ + unset($this->Devices[$Name]['RECORDS'][$RecordID]); + } } - - /* 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= ""; @@ -120,156 +113,195 @@ class servDNSeditZoneEntries extends plugin $table .= $this->generateRecordConfigurationRow($key); } + $smarty->assign("disableDialog",$this->disableDialog); $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 + function save_object() + { + /* Possible attributes posted */ - foreach($obj['RECORDS'] as $id => $types){ + foreach($_POST as $name => $value){ - /* Create table + /* Extract informations out of post name */ - $str.= ""; - foreach($types as $key => $type){ + $tmp = preg_replace("/^.*_/","\\1",$name); + $tmp2 = split("\|",$tmp); + + if(count($tmp2) != 2) continue; - /* Create unique post name - */ - $name = base64_encode($obj_dn)."|".$id."|".$key; - - $str .= " - - - - - - "; - } - $str .="
- ".$objectName." - - ".$this->createRecordTypeSelection($id,$name)." - - - - - - - -
"; - } - return($str); - } + $Name = base64_decode($tmp2[0]); + $RecordID = $tmp2[1]; - /* Create selectbox with all available option types - */ - function createRecordTypeSelection($id,$refID){ - $str = "\n"; - return($str); - } + + /* check for renamed entries + */ + foreach($_POST as $name => $value){ - function remove_from_parent() - { - } + /* Extract informations out of post name + */ + $tmp = preg_replace("/^.*_/","\\1",$name); + $tmp2 = split("\|",$tmp); + + if(count($tmp2) != 2) continue; - function save_object() - { - /* Save all form fields - */ - - /* Possible attributes posted - */ - $arr = array("RecordTypeSelection_","ValueSelection_"); - - foreach($_POST as $name=>$value){ - - foreach($arr as $type) + $Name = base64_decode($tmp2[0]); + $RecordID = $tmp2[1]; + + /* Host renamed + */ + if(preg_match("/RenameHost_/",$name)){ + if((isset($this->Devices[$Name])) && ($Name != $value)){ - /* 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; + if(isset($this->Devices[$value])){ + print_red(sprintf(_("Can't rename '%s' to '%s' there is already an entry with the same name in our zone editing dialog."),$Name,$value)); + }else{ + $this->Devices[$value] = $this->Devices[$Name]; + unset($this->Devices[$Name]); } } + } } } + /* check something */ function check() { - $message= array(); - // Nothing right now + /* Call common method to give check the hook */ + $message= plugin::check(); + + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + + $names = array(); + foreach($this->Devices as $DevName => $device){ + + /* Checking entry name + */ + if((!is_uid($DevName)) | (empty($DevName))){ + $message[] = sprintf(_("Entry name '%s' contains invalid characters."), $DevName); + } + + /* Renaming check for existing devices + */ + if(isset($device['OrigCn']) && ($DevName != $device['OrigCn'] )){ + $ldap->cd($this->config->current['BASE']); + $ldap->search("(relativeDomainName=".$DevName.")",array("relativeDomainName")); + if($ldap->count()){ + $message[] = sprintf(_("Can not rename '%s' to '%s',the destination name already exists."),$device['OrigCn'],$DevName); + } + }elseif(!isset($device['OrigCn'])){ + $ldap->cd($this->config->current['BASE']); + $ldap->search("(relativeDomainName=".$DevName.")",array("relativeDomainName")); + if($ldap->count()){ + $message[] = sprintf(_("Can not create '%s',the destination name already exists."),$DevName); + } + } + + /* Check names + */ + if(!isset($names[$DevName])){ + $names[$DevName] = ""; + }else{ + $message[] = sprintf(_("The name '%s' is used more than once."),$DevName); + } + + /* Names should be written in lowercase + */ + if(strtolower($DevName) != $DevName){ + $message[] = sprintf(_("The host name '%s' should be written in lowercase."), $DevName); + } + + /* Check records + */ + $singleEntries = array("cNAMERecord","pTRRecord"); + + $tmp = array(); + $tmp2 = array(); + foreach($device['RECORDS'] as $Num => $Rec){ + + /* Check for multiple use of unique record types + */ + if(in_array($Rec['type'],$singleEntries)){ + if(!isset($tmp[$Rec['type']])){ + $tmp[$Rec['type']] = ""; + }else{ + $message[] = sprintf(_("The record type '%s' is a unique type and can't be defined twice."),$type); + } + } + + /* Check for empty / duplicate entries in record array + */ + if(empty($Rec['value'])){ + $message[] = sprintf(_("There is an empty '%s' for host '%s'."),$Rec['type'],$DevName); + } + + /* Check for duplicate record entries + */ + if(!isset($tmp[$Rec['type']][$Rec['value']])){ + $tmp[$Rec['type']][$Rec['value']] = ""; + }else{ + $message[] = sprintf(_("There is a duplicate entry in '%s' for '%s'."),$Rec['type'],$DevName); + } + } + } return ($message); } function save() { - /* Set all initial records to array() - This means they will be removed from the entry + if($this->disableDialog) return; + + $todo = array(); + + /* Create todolist */ - foreach($this->InitDevices as $dn => $obj){ - $attrs[$dn]= array(); - foreach($obj['RECORDS'] as $rectype => $records){ - $attrs[$dn][$rectype] = array(); + foreach($this->Devices as $name => $dev){ + if(isset($dev['OrigCn'])){ + if(count($dev['RECORDS'])){ + $todo[] = getDNSHostEntriesDiff($this->config,$dev['OrigCn'],$dev,$name); + }else{ + $dev['exists'] = false; + $todo[] = getDNSHostEntriesDiff($this->config,$dev['OrigCn'],$dev,$name); + } + }else{ + if(count($dev['RECORDS'])){ + $todo[] = getDNSHostEntriesDiff($this->config,"",$dev,$name); + }else{ + $dev['exists'] = false; + $todo[] = getDNSHostEntriesDiff($this->config,"",$dev,$name); + } } } - /* 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; - } + $tmp = array(); + $tmp['del'] = array(); + $tmp['add'] = array(); + $tmp['move'] = array(); + foreach($todo as $to){ + foreach($to as $type => $entries){ + $tmp[$type] = array_merge($tmp[$type],$entries); } } @@ -278,107 +310,111 @@ class servDNSeditZoneEntries extends plugin $ldap = $this->config->get_ldap_link(); $ldap->cd ($this->config->current['BASE']); - /* Generate 'T odo' :-) + /* move follwoing entries */ - $tmp = ($this->generate_LDAP_entries($attrs)); + foreach($tmp['move'] as $src => $dst){ + $this->recursive_move($src,$dst); + } - /* Delete all objects which should be delted - */ - foreach($tmp['del'] as $key => $ntr){ - $ldap->rmdir($key); + /* Delete dns */ + foreach($tmp['del'] as $dn => $del){ + $ldap->cd($dn); + $ldap->rmdir_recursive($dn); } - /* Add append new / updated entries + /* Add || Update new DNS entries */ - foreach($tmp['addupdate'] as $key => $attrs){ - $ldap->cat($key); - if($ldap->count() > 0){ - $ldap->cd($key); - $ldap->modify($attrs); + foreach($tmp['add'] as $dn => $attrs){ + $ldap->cd($dn); + $ldap->cat($dn, array('dn')); + if(count($ldap->fetch())){ + $ldap->cd($dn); + $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); + $ldap->cd($dn); + $ldap->add($attrs); } } } - function generate_LDAP_entries($objs) - { - $entries = array(); - $delete = array(); + /* Create html table out of given entry + */ + function generateRecordConfigurationRow($objKey){ - /* these entries are added to base object ... + /* Get some basic informations */ - $normal = array("mDRecord","aRecord","tXTRecord","mXRecord","hInfoRecord","mInfoRecord","aFSDBRecord","SigRecord","KeyRecord","aAAARecord","nSRecord", - "LocRecord","nXTRecord","sRVRecord","nAPTRRecord","kXRecord","certRecord","a6Record","dSRecord","sSHFPRecord","rRSIGRecord","nSECRecord"); + $obj = $this->Devices[$objKey]; + $objectName = $objKey; - /* Create t odo + /* Abort if emtpy */ - foreach($objs as $dn => $recs){ - - /* Get basic info - */ - $obj = $this->Devices[$dn]; - $objectName = $obj['OBJECT']['cn'][0]; + if(count($obj['RECORDS']) == 0) return ""; + + /* Set title + */ + $str= "
"; + + $hostNameOnce = true; - /* Calculate records ... + /* Walk through all defined records + */ + $str.= ""; + foreach($obj['RECORDS'] as $id => $record){ + + /* Create unique post name */ - foreach($recs as $type => $rec){ - - /* Simply add normal entries - */ - if(in_array($type,$normal)){ - $entries['relativeDomainName='.$objectName.','.$dn][$type] = $rec ; - } + $name = base64_encode($objKey)."|".$id; - /* 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; - } - } - } + $str .= " + + + + "; } + $str .="
\n"; - /* 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"); - } - } - } + /* Only first host entry name should be editable + */ + if($hostNameOnce){ + $hostNameOnce = false; + $str .="\n"; } + + /* Create rest. Selectbox, icons ... + */ + $str .=" + + ".$this->createRecordTypeSelection($record['type'],$name)." + + + + + +
"; + return($str); + } + + + /* Create selectbox with all available option types + */ + function createRecordTypeSelection($id,$refID){ - return(array("del"=> $delete , "addupdate"=> $entries)); + $str = "\n"; + return($str); + } + + + function remove_from_parent() + { } }