summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 667ac46)
raw | patch | inline | side by side (parent: 667ac46)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 26 Jun 2009 13:24:35 +0000 (13:24 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 26 Jun 2009 13:24:35 +0000 (13:24 +0000) |
-Allow to set multiple options.
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13805 594d385d-05f5-0310-b6e9-bd551577e9d8
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 755214411ca6755a50ef79febf51316bd4c0c99d..46eda0f6e96fe0dde7e970248d6307811cdf3373 100644 (file)
class dhcpAdvanced extends plugin
{
/* Used attributes */
- var $options= array();
+ var $options= null;
var $statements= array();
var $show_advanced= FALSE;
var $autoStatements= array();
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);
}
}
}
$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 6a0d78b00fe9a3f66c5ab507d790a116d14a18a3..29148fdf9504cf77c448b756b79c6e3b601b0e4b 100644 (file)
$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 c7569d2c95f46da2445ff64076f60cc721ba2dd5..12f4f559e58fc01b027e439d6f8ea63e35faec49 100644 (file)
$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;
}
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 0f99ce23b3b6ec4f4b99525ef4bc26391b78b756..a19cb1d26118c0f47803e980c48946d65836d077 100644 (file)
class dhcpNetwork extends plugin
{
/* Used attributes */
- var $options= array();
+ var $options= null;
var $statements= array();
/* attribute list for save action */
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;
}
}
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');
}
}
*/
/* 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);
}
/* 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'])){
/* 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));
}
}
/* 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
--- /dev/null
@@ -0,0 +1,96 @@
+<?php
+
+ /* This class represents a set of dhcpOptions, which are used over several dhcp plugins.
+ * E.g. 'dhcpHost' includes 'dhcpAdvanced', both use the same options.
+ * In other words, they use a references to an instance of this class.
+ */
+class dhcpOption{
+
+ var $options = array();
+
+ function getAll(){
+ return($this->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 f6b9f39b3c5d0e819e37e97b388cce5d35ae349e..b4fc0b6c5469b3c1d3fbace8e797e75337edaf82 100644 (file)
/* Used attributes */
var $cn= "";
var $orig_cn= "";
- var $options= array();
+ var $orig_dn= "";
+ var $options= null;
var $statements= array();
/* Subobjects */
function dhcpPlugin(&$parent,$attrs)
{
- $this->parent = $parent;
+ $this->parent = $parent;
+
+ $this->options = new dhcpOption();
/* Load statements / options */
if (is_array($attrs)){
/* 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));
}
}
/* 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()
/* 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]);
}
$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;;
}
}
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();
$this->attrs['cn']= array($this->cn);
$this->attrs['objectClass']= $this->objectclasses;
$this->attrs['MODIFIED']= TRUE;
-
return ($this->attrs);
}
$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 067b07c0b70f2d718f3b36c62b239714d8c82ed0..4d0a5c791bb08d79be9a9887c6ea1b3266b74a85 100644 (file)
$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 5260b743f0d1273edda195fe77de2347fa5212a1..36ca957630c74762579742e0af7253e548bfbdf8 100644 (file)
$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 a2b4d69f98aa5950f0a31a9d6b28d8e3a8ff06cd..b60ebdd33a3774e3664ebd5f92b63096d6d10a3f 100644 (file)
/* 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 2227e14f44d20ba76b12116c16e86b75259fb024..1a900cdf699e05b79b1e1fe2c8b545186fde5511 100644 (file)
$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 0669b20fd3943203f5634622e4f38db4912691ae..cfed5f334561571dae75cdc1dd88cb7c4560e3f4 100644 (file)
<br>
{render acl=$acl}
<select name='dhcpoptions' style="width:100%;" size="14">
- {html_options values=$dhcpoptions output=$dhcpoptions}
+ {html_options options=$dhcpoptions}
</select>
{/render}
<br>