From cc360e7b28679a6d36a83268b38559a0af390fcf Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 28 Aug 2007 08:57:02 +0000 Subject: [PATCH] Updated dns stuff. -Dhcp client, list of available nodes will display all nodes now. -Dhcp service, can be created on a new server now. -Dhcp service, can be renamend without losing dhcp config. git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@7152 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/admin/systems/class_servDHCP.inc | 65 +++++++++++++++--------- plugins/admin/systems/class_termDNS.inc | 14 +++-- 2 files changed, 49 insertions(+), 30 deletions(-) diff --git a/plugins/admin/systems/class_servDHCP.inc b/plugins/admin/systems/class_servDHCP.inc index 60436ef03..6538952b1 100644 --- a/plugins/admin/systems/class_servDHCP.inc +++ b/plugins/admin/systems/class_servDHCP.inc @@ -17,11 +17,14 @@ class servdhcp extends plugin var $quote_option = array("domain-name"); + var $orig_dn = ""; + function servdhcp ($config, $dn= NULL, $parent= NULL) { plugin::plugin ($config, $dn, $parent); $this->serviceDN = "cn=dhcp,".$dn; + $this->orig_dn = $dn; $this->types= array( "dhcpLog" => _("Logging"), "dhcpService" => _("Global options"), @@ -346,6 +349,10 @@ class servdhcp extends plugin foreach ($this->dhcpObjectCache as $dn => $data){ + if($this->dn != $this->orig_dn){ + $dn = preg_replace("/".normalizePreg($this->orig_dn)."$/i",$this->dn,$dn); + } + /* Remove entry? */ if (count($data) == 0){ /* Check if exists, then remove... */ @@ -357,7 +364,7 @@ class servdhcp extends plugin } /* Modify existing entry? */ - if (isset($data['MODIFIED'])){ + if (isset($data['MODIFIED']) || $this->orig_dn != $this->dn){ if($ldap->cat($dn)){ $modify= TRUE; @@ -371,17 +378,24 @@ class servdhcp extends plugin if ($attribute == "MODIFIED" || $attribute == "dn"){ continue; } + + if(in_array($attribute,array("dhcpPrimaryDN","dhcpSecondaryDN","dhcpServerDN","dhcpFailOverPeerDN"))){ + foreach($values as $v_key => $value){ + $values[$v_key] = preg_replace("/".normalizePreg($this->orig_dn)."$/i",$this->dn,$value); + } + } + if (count($values)){ - - if($attribute == "dhcpOption"){ - foreach($values as $key => $value){ - $option_name = trim(preg_replace("/[^ ]*$/","",$value)); - $option_value= trim(preg_replace("/^[^ ]*/","",$value)); - if(in_array($option_name,$this->quote_option)){ - $values[$key] = $option_name." \"".$option_value."\""; - } - } - } + + if($attribute == "dhcpOption"){ + foreach($values as $key => $value){ + $option_name = trim(preg_replace("/[^ ]*$/","",$value)); + $option_value= trim(preg_replace("/^[^ ]*/","",$value)); + if(in_array($option_name,$this->quote_option)){ + $values[$key] = $option_name." \"".$option_value."\""; + } + } + } if (count($values) == 1){ $attrs[$attribute]= $values[0]; } else { @@ -406,7 +420,8 @@ class servdhcp extends plugin } /* Self modify and place service dn entry */ - $this->dhcpServiceDN= $this->serviceDN; + $this->dhcpServiceDN= $this->dn; + plugin::save(); /* Save data to LDAP */ @@ -459,19 +474,19 @@ class servdhcp extends plugin } $sattrs['dn']= $ldap->getDN(); - foreach($sattrs as $name => $values){ - if($name == "dhcpOption"){ - foreach($values as $key => $value){ - $value_name = trim(preg_replace("/[^ ]*$/","",$value)); - $value_value= trim(preg_replace("/^[^ ]*/","",$value)); - if(in_array($value_name,$this->quote_option)){ - $value_value = preg_replace("/^\"/","",$value_value); - $value_value = preg_replace("/\"$/","",$value_value); - $sattrs[$name][$key] = $value_name." ".$value_value; - } - } - } - } + foreach($sattrs as $name => $values){ + if($name == "dhcpOption"){ + foreach($values as $key => $value){ + $value_name = trim(preg_replace("/[^ ]*$/","",$value)); + $value_value= trim(preg_replace("/^[^ ]*/","",$value)); + if(in_array($value_name,$this->quote_option)){ + $value_value = preg_replace("/^\"/","",$value_value); + $value_value = preg_replace("/\"$/","",$value_value); + $sattrs[$name][$key] = $value_name." ".$value_value; + } + } + } + } $this->dhcpObjectCache[$ldap->getDN()]= $sattrs; $tmp= preg_replace("/".$this->serviceDN."/", "", $ldap->getDN()); diff --git a/plugins/admin/systems/class_termDNS.inc b/plugins/admin/systems/class_termDNS.inc index a0f2fd187..da1d331b6 100644 --- a/plugins/admin/systems/class_termDNS.inc +++ b/plugins/admin/systems/class_termDNS.inc @@ -765,22 +765,26 @@ class termDNS extends plugin while($attr = $ldap->fetch()){ $dhcp_dns[$attr['dn']] = $attr['dhcpPrimaryDN'][0]; } - + foreach($dhcp_dns as $key => $pri_dns){ $ldap->cat($pri_dns,array("cn")); $tmp = $ldap->fetch(); - $dhcp_dns[$key] = $tmp['cn'][0]; + if(isset($tmp['cn'][0])){ + $dhcp_dns[$key] = $tmp['cn'][0]; + }else{ + unset($dhcp_dns[$key]); + } } - + + $tmp = $tmp2 = array(); foreach($dhcp_dns as $dn => $cn){ $ldap->cd($dn); $ldap->search("(|(objectClass=dhcpService)(objectClass=dhcpGroup)". "(objectClass=dhcpSubnet)(objectClass=dhcpSharedNetwork))",array("cn")); - $tmp = array(); while($attr = $ldap->fetch()){ $tmp[$attr['dn']] = $attr['cn'][0]; } - $tmp2 = $this->create_tree($tmp,preg_replace("/^[^,]+,/i","",$dn),"(".$cn.") "); + $tmp2 = array_merge($tmp2,$this->create_tree($tmp,preg_replace("/^[^,]+,/i","",$dn),"(".$cn.") ")); } return($tmp2); } -- 2.30.2