From: hickert Date: Fri, 26 Jun 2009 13:24:35 +0000 (+0000) Subject: Updated dhcp plugin X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=90d7644eb403b65a829a0526813bdaf35106810e;p=gosa.git Updated dhcp plugin -Allow to set multiple options. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13805 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 755214411..46eda0f6e 100644 --- a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpAdvanced.inc +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpAdvanced.inc @@ -21,7 +21,7 @@ class dhcpAdvanced extends plugin { /* Used attributes */ - var $options= array(); + var $options= null; var $statements= array(); var $show_advanced= FALSE; var $autoStatements= array(); @@ -61,14 +61,15 @@ class dhcpAdvanced extends plugin 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; + $this->options->add($key,$val); } if ($acl_writeable && isset($_POST['delete_option']) && isset($_POST['dhcpoptions'])){ - $key= preg_replace('/([a-z0-9-]+)\s(.*)$/', '\\1', get_post('dhcpoptions')); - if (in_array($key, $this->autoOptions)){ - msg_dialog::display(_("Error"), _("Cannot delete automatic statements!"), ERROR_DIALOG); + $name = preg_replace('/_[0-9]*$/', '', get_post('dhcpoptions')); + $key = preg_replace('/^.*_/', '', get_post('dhcpoptions')); + if (in_array($name, $this->autoOptions)){ + msg_dialog::display(_("Error"), _("Cannot delete automatic statements!"), ERROR_DIALOG); } else { - unset($this->options[$key]); + $this->options->remove($name,$key); } } @@ -88,11 +89,15 @@ class dhcpAdvanced extends plugin } $smarty->assign("dhcpstatements", $statements); $options= array(); - foreach ($this->options as $key => $val){ + foreach ($this->options->getAll() as $key => $val){ if (in_array($key, $this->autoOptions)){ - $options[$key]= "$key $val ["._("automatic")."]"; + foreach($val as $id => $entry){ + $options[$key."_".$id]= "$key $entry ["._("automatic")."]"; + } } else { - $options[$key]= "$key $val"; + foreach($val as $id => $entry){ + $options[$key."_".$id]= "$key $entry"; + } } } $smarty->assign("dhcpoptions", $options); diff --git a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpGroup.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpGroup.inc index 6a0d78b00..29148fdf9 100644 --- a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpGroup.inc +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpGroup.inc @@ -41,15 +41,14 @@ class dhcpGroup extends dhcpPlugin $display= $smarty->fetch (get_template_path('dhcp_group.tpl', TRUE, dirname(__FILE__))).$this->network->execute(); /* Merge arrays for advanced view */ - $this->fix_options(); - foreach (array("options", "statements") as $type){ + foreach (array("statements") as $type){ $this->advanced->$type= $this->$type + $this->network->$type; } $display.= $this->advanced->execute(); /* Merge back for removals */ - foreach (array("options", "statements") as $type){ + foreach (array("statements") as $type){ $this->$type= $this->advanced->$type; $this->network->$type= $this->advanced->$type; } 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..12f4f559e 100644 --- a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpHost.inc +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpHost.inc @@ -69,14 +69,13 @@ class dhcpHost extends dhcpPlugin $display= $smarty->fetch(get_template_path('dhcp_host.tpl', TRUE,dirname(__FILE__))).$this->network->execute(); /* Merge arrays for advanced view */ - $this->fix_options(); - foreach (array("options", "statements") as $type){ + foreach (array("statements") as $type){ $this->advanced->$type= $this->$type + $this->network->$type; } $display.= $this->advanced->execute(); /* Merge back for removals */ - foreach (array("options", "statements") as $type){ + foreach (array("statements") as $type){ $this->$type= $this->advanced->$type; $this->network->$type= $this->advanced->$type; } @@ -121,7 +120,7 @@ class dhcpHost extends dhcpPlugin unset ($this->statements['fixed-address']); } } - $this->options['host-name']= $this->cn; + $this->options->set('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 0f99ce23b..a19cb1d26 100644 --- a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpNetwork.inc +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpNetwork.inc @@ -21,7 +21,7 @@ class dhcpNetwork extends plugin { /* Used attributes */ - var $options= array(); + var $options= null; var $statements= array(); /* attribute list for save action */ @@ -46,8 +46,8 @@ 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){ + if($this->options->exists('domain-name-servers')){ + foreach(split(",", $this->options->get('domain-name-servers')) as $val){ $servers[$val]= $val; } } @@ -57,17 +57,18 @@ class dhcpNetwork extends plugin foreach($servers as $val){ $tmp.= $val.","; } - $this->options['domain-name-servers']= preg_replace('/,$/', '', $tmp); + $this->options->removeAll('domain-name-servers'); + $this->options->set('domain-name-servers',preg_replace('/,$/', '', $tmp)); } } 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*)?".get_post('dnsserver')."/i", '', + $this->options->get('domain-name-servers')); $tmp= preg_replace("/(\s*)?,(\s*)?$/", '', $tmp); if ($tmp != ""){ - $this->options['domain-name-servers']= $tmp; + $this->options->set('domain-name-servers', $tmp); } else { - unset($this->options['domain-name-servers']); + $this->options->remove('domain-name-servers'); } } @@ -82,21 +83,14 @@ class dhcpNetwork extends plugin */ /* Router */ - if (isset($this->options['routers'])){ - $smarty->assign("routers", $this->options['routers']); - } else { - $smarty->assign("routers", ""); - } + $smarty->assign("routers", $this->options->get('routers')); /* 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",$this->options->get('domain-name')); + + if($this->options->exists('domain-name-servers')){ $servers= array(); - foreach(split(",", $this->options['domain-name-servers']) as $val){ + foreach(split(",", $this->options->get('domain-name-servers')) as $val){ $servers[$val]= $val; } $smarty->assign("dnsservers", $servers); @@ -105,17 +99,12 @@ 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']); - } else { - $smarty->assign("subnet_mask", ""); - } - if (isset($this->options['broadcast-address'])){ - $smarty->assign("broadcast_address", $this->options['broadcast-address']); - } else { - $smarty->assign("broadcast_address", ""); + if ($this->options->exists('subnet-mask')){ + $this->options->removeAll('subnet-mask'); + $this->options->set('subnet-mask',normalize_netmask($this->options->get('subnet-mask'))); } + $smarty->assign("subnet_mask", $this->options->get('subnet-mask')); + $smarty->assign("broadcast_address", $this->options->get('broadcast-address')); /* Boot stuff */ if (isset($this->statements['filename'])){ @@ -164,11 +153,10 @@ class dhcpNetwork extends plugin /* Options */ 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"]); + $this->options->remove($key); } else { - $this->options["$key"]= get_post("$val"); + $this->options->set($key,get_post($val)); } } @@ -209,16 +197,13 @@ class dhcpNetwork extends plugin /* Check netmask and broadcast */ foreach(array("subnet-mask" => _("Netmask"), "broadcast-address" => _("Broadcast")) as $key => $typ){ - if (!isset($this->options["$key"])){ + if (!$this->options->exists("$key")){ continue; } - $tmp= preg_replace('/^[^\s]+\s/', '', $this->options["$key"]); - - if (!tests::is_ip($tmp)){ + if (!tests::is_ip($this->options->get($key))){ $message[]= sprintf(_("Error in definition of '%s'!"), $typ); } } - return $message; } diff --git a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpOption.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpOption.inc new file mode 100644 index 000000000..8db57ff54 --- /dev/null +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpOption.inc @@ -0,0 +1,96 @@ +options); + } + + function get($name){ + if(isset($this->options[$name])){ + if(count($this->options[$name]) == 0){ + return(""); + }elseif(count($this->options[$name]) == 1){ + return($this->options[$name][0]); + }else{ + return($this->options[$name]); + } + } + } + + function removeAll($name){ + if(isset($this->options[$name])){ + unset($this->options[$name]); + } + } + + function remove($name,$entry = 0){ + if(!isset($this->options[$name])){ + return; + } + if(isset($this->options[$name][$entry])){ + unset($this->options[$name][$entry]); + } + if(count($this->options[$name]) == 0){ + unset($this->options[$name]); + }else{ + $this->options[$name] = array_unique($this->options[$name]); + $this->options[$name] = array_values($this->options[$name]); + } + } + + function set($name,$value = null){ + if($value == null){ + $value = trim(preg_replace("/^[^ ]*/",'',$name)); + $name = trim(preg_replace("/ .*$/",'',$name)); + } + + if(!isset($this->options[$name])){ + $this->options[$name] = array(); + } + + $this->options[$name] = array($value); + } + + function add($name,$value = null){ + if($value == null){ + $value = trim(preg_replace("/^[^ ]*/",'',$name)); + $name = trim(preg_replace("/ .*$/",'',$name)); + } + + if(!isset($this->options[$name])){ + $this->options[$name] = array(); + } + + $this->options[$name][] = $value; + $this->options[$name] = array_unique($this->options[$name]); + $this->options[$name] = array_values($this->options[$name]); + } + + function save(){ + $res = array(); + foreach($this->options as $key => $values){ + foreach($values as $value){ + $res[] = $key." ".$value; + } + } + $res=array_unique($res); + return($res); + } + + function exists($name){ + if(isset($this->options[$name]) && count($this->options[$name]) == 0){ + return(false); + } + return(isset($this->options[$name])); + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> 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..b4fc0b6c5 100644 --- a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpPlugin.inc +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpPlugin.inc @@ -23,7 +23,8 @@ class dhcpPlugin extends plugin /* Used attributes */ var $cn= ""; var $orig_cn= ""; - var $options= array(); + var $orig_dn= ""; + var $options= null; var $statements= array(); /* Subobjects */ @@ -36,7 +37,9 @@ class dhcpPlugin extends plugin function dhcpPlugin(&$parent,$attrs) { - $this->parent = $parent; + $this->parent = $parent; + + $this->options = new dhcpOption(); /* Load statements / options */ if (is_array($attrs)){ @@ -46,14 +49,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; + foreach($attrs['dhcpOption'] as $opt){ + $this->options->add(trim($opt)); } } @@ -82,17 +79,18 @@ class dhcpPlugin extends plugin /* Load network module */ $this->network= new dhcpNetwork(); - $this->network->options= $this->options; + $this->network->options= &$this->options; $this->network->statements= $this->statements; $this->advanced= new dhcpAdvanced(); - $this->advanced->options= $this->options; + $this->advanced->options= &$this->options; $this->advanced->statements= $this->statements; - $this->network->parent = $parent; - $this->advanced->parent = $parent; + $this->network->parent = $parent; + $this->advanced->parent = $parent; /* Save CN for later reference */ $this->orig_cn= $this->cn; + $this->orig_dn= $this->dn; } function execute() @@ -109,10 +107,6 @@ class dhcpPlugin extends plugin /* Save data to object */ function save_object() { - /* Strip network objects */ - foreach (array("routers", "domain-name", "subnet-mask", "broadcast-address") as $toberemoved){ - unset($this->options[$toberemoved]); - } foreach (array("filename", "next-server","get-lease-hostnames","use-host-decl-names") as $toberemoved){ unset($this->statements[$toberemoved]); } @@ -122,7 +116,7 @@ class dhcpPlugin extends plugin $this->advanced->save_object(); /* Merge arrays for advanced view */ - foreach (array("options", "statements") as $type){ + foreach (array("statements") as $type){ $this->advanced->$type= $this->$type + $this->network->$type;; } } @@ -140,24 +134,21 @@ class dhcpPlugin extends plugin function save() { /* Merge arrays for network and advanced view */ - foreach (array("options", "statements") as $type){ + foreach (array("statements") as $type){ $this->$type= $this->$type + $this->network->$type + $this->advanced->$type; } /* Add cn if we're new */ if ($this->new){ - $this->dn= "cn=".$this->cn.",".$this->dn; + $this->dn= "cn=".$this->cn.",".$this->orig_dn; } else { - $this->dn= "cn=".$this->cn.preg_replace('/^cn=[^,]+/', '', $this->dn); + $this->dn= "cn=".$this->cn.preg_replace('/^cn=[^,]+/', '', $this->orig_dn); } + print_a($this); + /* Assemble new entry - options */ - $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']= $this->options->save(); /* Assemble new entry - statements */ $this->attrs['dhcpStatements']= array(); @@ -176,7 +167,6 @@ class dhcpPlugin extends plugin $this->attrs['cn']= array($this->cn); $this->attrs['objectClass']= $this->objectclasses; $this->attrs['MODIFIED']= TRUE; - return ($this->attrs); } @@ -204,14 +194,6 @@ class dhcpPlugin extends plugin $this->removeAttrs($name, 'dhcpStatement'); } - - function fix_options() - { - foreach (array('domain-name-servers') as $key){ - unset ($this->options[$key]); - } - } - } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: diff --git a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpPool.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpPool.inc index 067b07c0b..4d0a5c791 100644 --- a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpPool.inc +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpPool.inc @@ -56,15 +56,14 @@ class dhcpPool extends dhcpPlugin $display= $smarty->fetch(get_template_path('dhcp_pool.tpl', TRUE, dirname(__FILE__))).$this->network->execute(); /* Merge arrays for advanced view */ - $this->fix_options(); - foreach (array("options", "statements") as $type){ + foreach (array("statements") as $type){ $this->advanced->$type= $this->$type + $this->network->$type;; } $display.= $this->advanced->execute(); /* Merge back for removals */ - foreach (array("options", "statements") as $type){ + foreach (array("statements") as $type){ $this->$type= $this->advanced->$type; $this->network->$type= $this->advanced->$type; } diff --git a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpService.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpService.inc index 5260b743f..36ca95763 100644 --- a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpService.inc +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpService.inc @@ -80,15 +80,14 @@ class dhcpService extends dhcpPlugin $display= $smarty->fetch(get_template_path('dhcp_service.tpl', TRUE, dirname(__FILE__))).$this->network->execute(); /* Merge arrays for advanced view */ - $this->fix_options(); - foreach (array("options", "statements") as $type){ + foreach (array("statements") as $type){ $this->advanced->$type= $this->$type + $this->network->$type;; } $display.= $this->advanced->execute(); /* Merge back for removals */ - foreach (array("options", "statements") as $type){ + foreach (array("statements") as $type){ $this->$type= $this->advanced->$type; $this->network->$type= $this->advanced->$type; } diff --git a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpSharedNetwork.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpSharedNetwork.inc index a2b4d69f9..b60ebdd33 100644 --- a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpSharedNetwork.inc +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpSharedNetwork.inc @@ -74,28 +74,25 @@ class dhcpSharedNetwork extends dhcpPlugin /* Show main page */ $display= $smarty->fetch(get_template_path('dhcp_sharedNetwork.tpl', TRUE,dirname(__FILE__))).$this->network->execute(); - /* Merge arrays for advanced view */ - $this->fix_options(); - - /* Remove states configured by checkboxes. + /* Remove states configured by checkboxes. */ - foreach(array("deny unknown-clients", + foreach(array("deny unknown-clients", "deny bootp", "deny booting", "allow unknown-clients", "allow bootp", "allow booting") as $name){ - if(isset($this->advanced->statements[$name])){ - unset($this->advanced->statements[$name]); - unset($this->network->statements[$name]); - } - } + if(isset($this->advanced->statements[$name])){ + unset($this->advanced->statements[$name]); + unset($this->network->statements[$name]); + } + } - foreach (array("options", "statements") as $type){ + foreach (array("statements") as $type){ $this->advanced->$type= $this->$type + $this->network->$type; } $display.= $this->advanced->execute(); /* Merge back for removals */ - foreach (array("options", "statements") as $type){ + foreach (array("statements") as $type){ $this->$type= $this->advanced->$type; $this->network->$type= $this->advanced->$type; } diff --git a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpSubnet.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpSubnet.inc index 2227e14f4..1a900cdf6 100644 --- a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpSubnet.inc +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpSubnet.inc @@ -75,15 +75,14 @@ class dhcpSubnet extends dhcpPlugin $display= $smarty->fetch(get_template_path('dhcp_subnet.tpl', TRUE, dirname(__FILE__))).$this->network->execute(); /* Merge arrays for advanced view */ - $this->fix_options(); - foreach (array("options", "statements") as $type){ + foreach (array("statements") as $type){ $this->advanced->$type= $this->$type + $this->network->$type; } $display.= $this->advanced->execute(); /* Merge back for removals */ - foreach (array("options", "statements") as $type){ + foreach (array("statements") as $type){ $this->$type= $this->advanced->$type; $this->network->$type= $this->advanced->$type; } diff --git a/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_advanced.tpl b/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_advanced.tpl index 0669b20fd..cfed5f334 100644 --- a/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_advanced.tpl +++ b/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_advanced.tpl @@ -37,7 +37,7 @@
{render acl=$acl} {/render}