summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f8f70e1)
raw | patch | inline | side by side (parent: f8f70e1)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 26 Jun 2009 11:14:07 +0000 (11:14 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 26 Jun 2009 11:14:07 +0000 (11:14 +0000) |
-Modifying the dhcp plugin to supprot multiple options of the same type, is not that easy.
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13802 594d385d-05f5-0310-b6e9-bd551577e9d8
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13802 594d385d-05f5-0310-b6e9-bd551577e9d8
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 8dd90a62774767c2d53641b9caaf539082c78e1f..755214411ca6755a50ef79febf51316bd4c0c99d 100644 (file)
var $objectclasses= array();
var $parent;
- static function getOption($needle, $heystack, $value_only = false){
- foreach($heystack as $key => $val){
- if($val != $key){
- echo "<b>$key => $val</b>";
- }
-
- 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 */
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'] != ""){
- $val= trim(get_post('addoption'));
- $this->options[$val]= $val;
+ $key= preg_replace('/^([a-z0-9-]+)\s(.*)$/', '\\1', get_post('addoption'));
+ $val= preg_replace("/^$key\s*/", '', get_post('addoption'));
+ $this->options[$key]= $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[$val]);
+ unset($this->options[$key]);
}
}
$smarty->assign("dhcpstatements", $statements);
$options= array();
foreach ($this->options as $key => $val){
- $key = preg_replace("/ .*$/","",$val);
if (in_array($key, $this->autoOptions)){
- $options[$val]= "$val ["._("automatic")."]";
+ $options[$key]= "$key $val ["._("automatic")."]";
} else {
- $options[$val]= "$val";
+ $options[$key]= "$key $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 e407ba54d2bbbaed06379cb6438916c56f9c704f..c7569d2c95f46da2445ff64076f60cc721ba2dd5 100644 (file)
unset ($this->statements['fixed-address']);
}
}
- $hn = "host-name {$this->cn}";
- $this->options[$hn]= $hn;
+ $this->options['host-name']= $this->cn;
}
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 dce548ba3a5af1b64fb58e103c8ca6ee4613dc91..0f99ce23b3b6ec4f4b99525ef4bc26391b78b756 100644 (file)
htmlentities(get_post('addserver')),"/[0-9a-z.-]/"), ERROR_DIALOG);
} else {
$servers= array();
- $chk = dhcpAdvanced::getOption('domain-name-servers',$this->options,true);
- if($chk != ""){
- foreach(split(",", $chk) as $val){
+ if (isset($this->options['domain-name-servers'])){
+ foreach(split(",", $this->options['domain-name-servers']) as $val){
$servers[$val]= $val;
}
}
foreach($servers as $val){
$tmp.= $val.",";
}
- $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;
+ $this->options['domain-name-servers']= preg_replace('/,$/', '', $tmp);
}
}
if ($acl_writeable && isset($_POST['delete_dns']) && isset($_POST['dnsserver'])){
- $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;
- }
+ $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']);
}
-
}
/* Show main page */
*/
/* Router */
- $smarty->assign("routers", dhcpAdvanced::getOption('router',$this->options));
+ if (isset($this->options['routers'])){
+ $smarty->assign("routers", $this->options['routers']);
+ } else {
+ $smarty->assign("routers", "");
+ }
/* DNS */
- $smarty->assign("domain", dhcpAdvanced::getOption('domain-name',$this->options));
- if (dhcpAdvanced::getOption('domain-name-servers',$this->options) != ""){
+ 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'])){
$servers= array();
- foreach(split(",", dhcpAdvanced::getOption('domain-name-servers',$this->options, true)) as $val){
+ foreach(split(",", $this->options['domain-name-servers']) as $val){
$servers[$val]= $val;
}
$smarty->assign("dnsservers", $servers);
}
/* Netmask / Broadcast */
- 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);
+ if (isset($this->options['subnet-mask'])){
+ $this->options['subnet-mask']= normalize_netmask($this->options['subnet-mask']);
+ $smarty->assign("subnet_mask", $this->options['subnet-mask']);
} else {
$smarty->assign("subnet_mask", "");
}
- $smarty->assign("broadcast_address", dhcpAdvanced::getOption('broadcast-address',$this->options));
+ if (isset($this->options['broadcast-address'])){
+ $smarty->assign("broadcast_address", $this->options['broadcast-address']);
+ } else {
+ $smarty->assign("broadcast_address", "");
+ }
/* Boot stuff */
if (isset($this->statements['filename'])){
foreach (array("routers" => "routers", "domain-name" => "domain", "subnet-mask" => "subnet_mask",
"broadcast-address" => "broadcast_address") as $key => $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;
+ if ($_POST["$val"] == ''){
+ unset($this->options["$key"]);
+ } else {
+ $this->options["$key"]= get_post("$val");
}
}
/* Check netmask and broadcast */
foreach(array("subnet-mask" => _("Netmask"), "broadcast-address" => _("Broadcast")) as $key => $typ){
- $ikey = dhcpAdvanced::getOption($key,$this->options);
- $ival = dhcpAdvanced::getOption($key,$this->options,true);
- if ($ikey == ""){
+ if (!isset($this->options["$key"])){
continue;
}
- $tmp= preg_replace('/^[^\s]+\s/', '', $ival);
+ $tmp= preg_replace('/^[^\s]+\s/', '', $this->options["$key"]);
+
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 89575229dc8911978a0ad446a71643cf9ab9a8f7..f6b9f39b3c5d0e819e37e97b388cce5d35ae349e 100644 (file)
/* Load options */
if (isset($attrs['dhcpOption'])){
foreach ($attrs['dhcpOption'] as $opt){
- $opt = trim($opt);
- $this->options[$opt]= $opt;
+ $idx= preg_replace('/\s.+$/', '', $opt);
+ if ($idx == $opt){
+ $value= "";
+ } else {
+ $value= preg_replace('/^[^\s]+\s/', '', $opt);
+ }
+ $this->options[$idx]= $value;
}
}
{
/* Strip network objects */
foreach (array("routers", "domain-name", "subnet-mask", "broadcast-address") as $toberemoved){
- $ikey = dhcpAdvanced::getOption($toberemoved, $this->options);
- if($ikey != ""){
- unset($this->options[$ikey]);
- }
+ unset($this->options[$toberemoved]);
}
foreach (array("filename", "next-server","get-lease-hostnames","use-host-decl-names") as $toberemoved){
unset($this->statements[$toberemoved]);
$this->attrs['dhcpOption']= array();
if (isset ($this->options) && count ($this->options)){
foreach ($this->options as $key => $val){
- $this->attrs['dhcpOption'][]= "$val";
+ $this->attrs['dhcpOption'][]= "$key $val";
}
}
function fix_options()
{
foreach (array('domain-name-servers') as $key){
- $ikey = dhcpAdvanced::getOption($key,$this->options);
- if($ikey != ""){
- unset ($this->options[$ikey]);
- }
+ unset ($this->options[$key]);
}
}