From f8f70e1142efa8cab1f5a9a6b92f9103d39c74c1 Mon Sep 17 00:00:00 2001 From: hickert Date: Fri, 26 Jun 2009 09:27:14 +0000 Subject: [PATCH] Updated dhcp options -We are now able to set variables twice. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13800 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../services/dhcp/class_dhcpAdvanced.inc | 34 ++++++-- .../systems/services/dhcp/class_dhcpHost.inc | 3 +- .../services/dhcp/class_dhcpNetwork.inc | 82 ++++++++++--------- .../services/dhcp/class_dhcpPlugin.inc | 21 ++--- 4 files changed, 84 insertions(+), 56 deletions(-) diff --git a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpAdvanced.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpAdvanced.inc index 755214411..8dd90a627 100644 --- a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpAdvanced.inc +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpAdvanced.inc @@ -32,6 +32,23 @@ class dhcpAdvanced extends plugin var $objectclasses= array(); var $parent; + static function getOption($needle, $heystack, $value_only = false){ + foreach($heystack as $key => $val){ + if($val != $key){ + echo "$key => $val"; + } + + if(preg_match("/^{$needle} /i",$val)){ + if($value_only){ + return(trim(preg_replace('/^[^\s]*/'))); + }else{ + return($val); + } + } + } + return(""); + } + function dhcpAdvanced() { /* This is always an account */ @@ -53,22 +70,22 @@ class dhcpAdvanced extends plugin if ($acl_writeable && isset($_POST['delete_statement']) && isset($_POST['dhcpstatements'])){ $key= preg_replace('/([a-z0-9-]+)\s(.*)$/', '\\1', get_post('dhcpstatements')); if (in_array($key, $this->autoStatements)){ - msg_dialog::display(_("Error"), _("Cannot delete automatic statements!"), ERROR_DIALOG); + msg_dialog::display(_("Error"), _("Cannot delete automatic statements!"), ERROR_DIALOG); } else { unset($this->statements[$key]); } } if ($acl_writeable && isset($_POST['add_option']) && $_POST['addoption'] != ""){ - $key= preg_replace('/^([a-z0-9-]+)\s(.*)$/', '\\1', get_post('addoption')); - $val= preg_replace("/^$key\s*/", '', get_post('addoption')); - $this->options[$key]= $val; + $val= trim(get_post('addoption')); + $this->options[$val]= $val; } if ($acl_writeable && isset($_POST['delete_option']) && isset($_POST['dhcpoptions'])){ $key= preg_replace('/([a-z0-9-]+)\s(.*)$/', '\\1', get_post('dhcpoptions')); + $val= get_post('dhcpoptions'); if (in_array($key, $this->autoOptions)){ - msg_dialog::display(_("Error"), _("Cannot delete automatic statements!"), ERROR_DIALOG); + msg_dialog::display(_("Error"), _("Cannot delete automatic statements!"), ERROR_DIALOG); } else { - unset($this->options[$key]); + unset($this->options[$val]); } } @@ -89,10 +106,11 @@ class dhcpAdvanced extends plugin $smarty->assign("dhcpstatements", $statements); $options= array(); foreach ($this->options as $key => $val){ + $key = preg_replace("/ .*$/","",$val); if (in_array($key, $this->autoOptions)){ - $options[$key]= "$key $val ["._("automatic")."]"; + $options[$val]= "$val ["._("automatic")."]"; } else { - $options[$key]= "$key $val"; + $options[$val]= "$val"; } } $smarty->assign("dhcpoptions", $options); diff --git a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpHost.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpHost.inc index c7569d2c9..e407ba54d 100644 --- a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpHost.inc +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpHost.inc @@ -121,7 +121,8 @@ class dhcpHost extends dhcpPlugin unset ($this->statements['fixed-address']); } } - $this->options['host-name']= $this->cn; + $hn = "host-name {$this->cn}"; + $this->options[$hn]= $hn; } dhcpPlugin::save_object(); diff --git a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpNetwork.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpNetwork.inc index 0f99ce23b..dce548ba3 100644 --- a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpNetwork.inc +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpNetwork.inc @@ -46,8 +46,9 @@ class dhcpNetwork extends plugin htmlentities(get_post('addserver')),"/[0-9a-z.-]/"), ERROR_DIALOG); } else { $servers= array(); - if (isset($this->options['domain-name-servers'])){ - foreach(split(",", $this->options['domain-name-servers']) as $val){ + $chk = dhcpAdvanced::getOption('domain-name-servers',$this->options,true); + if($chk != ""){ + foreach(split(",", $chk) as $val){ $servers[$val]= $val; } } @@ -57,18 +58,28 @@ class dhcpNetwork extends plugin foreach($servers as $val){ $tmp.= $val.","; } - $this->options['domain-name-servers']= preg_replace('/,$/', '', $tmp); + $chk = dhcpAdvanced::getOption('domain-name-servers',$this->options); + if($chk != ""){ + unset($this->options[$chk]); + } + $new = "domain-name-servers ".preg_replace('/,$/', '', $tmp); + $this->options[$new]=$new; } } if ($acl_writeable && isset($_POST['delete_dns']) && isset($_POST['dnsserver'])){ - $tmp= preg_replace("/(\s*,\s*)?".get_post('dnsserver')."/i", '', - $this->options['domain-name-servers']); - $tmp= preg_replace("/(\s*)?,(\s*)?$/", '', $tmp); - if ($tmp != ""){ - $this->options['domain-name-servers']= $tmp; - } else { - unset($this->options['domain-name-servers']); + $val = dhcpAdvanced::getOption('domain-name-servers', $this->options, true); + $key = dhcpAdvanced::getOption('domain-name-servers', $this->options); + + if($key != ""){ + unset($this->options[$key]); + $tmp= preg_replace("/(\s*,\s*)?".get_post('dnsserver')."/i",'', $val); + $tmp= preg_replace("/(\s*)?,(\s*)?$/", '', $tmp); + if ($tmp != ""){ + $tmp ="domain-name-servers {$tmp}"; + $this->options[$tmp]= $tmp; + } } + } /* Show main page */ @@ -82,21 +93,13 @@ class dhcpNetwork extends plugin */ /* Router */ - if (isset($this->options['routers'])){ - $smarty->assign("routers", $this->options['routers']); - } else { - $smarty->assign("routers", ""); - } + $smarty->assign("routers", dhcpAdvanced::getOption('router',$this->options)); /* DNS */ - if (isset($this->options['domain-name'])){ - $smarty->assign("domain", trim($this->options['domain-name'], '"')); - } else { - $smarty->assign("domain", ""); - } - if (isset($this->options['domain-name-servers'])){ + $smarty->assign("domain", dhcpAdvanced::getOption('domain-name',$this->options)); + if (dhcpAdvanced::getOption('domain-name-servers',$this->options) != ""){ $servers= array(); - foreach(split(",", $this->options['domain-name-servers']) as $val){ + foreach(split(",", dhcpAdvanced::getOption('domain-name-servers',$this->options, true)) as $val){ $servers[$val]= $val; } $smarty->assign("dnsservers", $servers); @@ -105,17 +108,18 @@ class dhcpNetwork extends plugin } /* Netmask / Broadcast */ - if (isset($this->options['subnet-mask'])){ - $this->options['subnet-mask']= normalize_netmask($this->options['subnet-mask']); - $smarty->assign("subnet_mask", $this->options['subnet-mask']); + if (dhcpAdvanced::getOption('subnet-mask', $this->options) != ""){ + $key = dhcpAdvanced::getOption('subnet-mask', $this->options); + $val = dhcpAdvanced::getOption('subnet-mask', $this->options,true); + + unset($this->options[$key]); + $new = 'subnet-mask '.normalize_netmask($val); + $this->options[$new]=$new; + $smarty->assign("subnet_mask", $new); } else { $smarty->assign("subnet_mask", ""); } - if (isset($this->options['broadcast-address'])){ - $smarty->assign("broadcast_address", $this->options['broadcast-address']); - } else { - $smarty->assign("broadcast_address", ""); - } + $smarty->assign("broadcast_address", dhcpAdvanced::getOption('broadcast-address',$this->options)); /* Boot stuff */ if (isset($this->statements['filename'])){ @@ -165,10 +169,13 @@ class dhcpNetwork extends plugin foreach (array("routers" => "routers", "domain-name" => "domain", "subnet-mask" => "subnet_mask", "broadcast-address" => "broadcast_address") as $key => $val){ - if ($_POST["$val"] == ''){ - unset($this->options["$key"]); - } else { - $this->options["$key"]= get_post("$val"); + $ikey = dhcpAdvanced::getOption($key, $this->options); + if($ikey != ""){ + unset($this->options[$ikey]); + } + if ($_POST["$val"] != ''){ + $new = $key." ".$get_post($val); + $this->options[$new]=$new; } } @@ -209,11 +216,12 @@ class dhcpNetwork extends plugin /* Check netmask and broadcast */ foreach(array("subnet-mask" => _("Netmask"), "broadcast-address" => _("Broadcast")) as $key => $typ){ - if (!isset($this->options["$key"])){ + $ikey = dhcpAdvanced::getOption($key,$this->options); + $ival = dhcpAdvanced::getOption($key,$this->options,true); + if ($ikey == ""){ continue; } - $tmp= preg_replace('/^[^\s]+\s/', '', $this->options["$key"]); - + $tmp= preg_replace('/^[^\s]+\s/', '', $ival); if (!tests::is_ip($tmp)){ $message[]= sprintf(_("Error in definition of '%s'!"), $typ); } diff --git a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpPlugin.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpPlugin.inc index f6b9f39b3..89575229d 100644 --- a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpPlugin.inc +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpPlugin.inc @@ -47,13 +47,8 @@ class dhcpPlugin extends plugin /* Load options */ if (isset($attrs['dhcpOption'])){ foreach ($attrs['dhcpOption'] as $opt){ - $idx= preg_replace('/\s.+$/', '', $opt); - if ($idx == $opt){ - $value= ""; - } else { - $value= preg_replace('/^[^\s]+\s/', '', $opt); - } - $this->options[$idx]= $value; + $opt = trim($opt); + $this->options[$opt]= $opt; } } @@ -111,7 +106,10 @@ class dhcpPlugin extends plugin { /* Strip network objects */ foreach (array("routers", "domain-name", "subnet-mask", "broadcast-address") as $toberemoved){ - unset($this->options[$toberemoved]); + $ikey = dhcpAdvanced::getOption($toberemoved, $this->options); + if($ikey != ""){ + unset($this->options[$ikey]); + } } foreach (array("filename", "next-server","get-lease-hostnames","use-host-decl-names") as $toberemoved){ unset($this->statements[$toberemoved]); @@ -155,7 +153,7 @@ class dhcpPlugin extends plugin $this->attrs['dhcpOption']= array(); if (isset ($this->options) && count ($this->options)){ foreach ($this->options as $key => $val){ - $this->attrs['dhcpOption'][]= "$key $val"; + $this->attrs['dhcpOption'][]= "$val"; } } @@ -208,7 +206,10 @@ class dhcpPlugin extends plugin function fix_options() { foreach (array('domain-name-servers') as $key){ - unset ($this->options[$key]); + $ikey = dhcpAdvanced::getOption($key,$this->options); + if($ikey != ""){ + unset ($this->options[$ikey]); + } } } -- 2.30.2