From f765e93d6d1821cf76567d30cd8d7f0c3be7e825 Mon Sep 17 00:00:00 2001 From: cajus Date: Fri, 3 Aug 2007 15:04:27 +0000 Subject: [PATCH] Updated dhcp stuff. Bug when inserting single value options/statements. git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@6962 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/admin/systems/class_dhcpGroup.inc | 225 ++++++++++++++++++ plugins/admin/systems/class_dhcpHost.inc | 10 +- plugins/admin/systems/dhcp_group.tpl | 22 ++ .../systems/{dhcphost.tpl => dhcp_host.tpl} | 2 +- 4 files changed, 257 insertions(+), 2 deletions(-) create mode 100644 plugins/admin/systems/class_dhcpGroup.inc create mode 100644 plugins/admin/systems/dhcp_group.tpl rename plugins/admin/systems/{dhcphost.tpl => dhcp_host.tpl} (96%) diff --git a/plugins/admin/systems/class_dhcpGroup.inc b/plugins/admin/systems/class_dhcpGroup.inc new file mode 100644 index 000000000..8560650cd --- /dev/null +++ b/plugins/admin/systems/class_dhcpGroup.inc @@ -0,0 +1,225 @@ +dn= $attrs['dn']; + $this->new= FALSE; + + + /* Load options */ + if (isset($attrs['dhcpOption'])){ + for($i= 0; $i<$attrs['dhcpOption']['count']; $i++){ + $tmp= $attrs['dhcpOption'][$i]; + $idx= preg_replace('/\s.+$/', '', $tmp); + $value= preg_replace('/^[^\s]+\s/', '', $tmp); + $this->options[$idx]= $value; + } + } + + /* Load statements */ + if (isset($attrs['dhcpStatements'])){ + for($i= 0; $i<$attrs['dhcpStatements']['count']; $i++){ + $tmp= $attrs['dhcpStatements'][$i]; + $idx= preg_replace('/\s.+$/', '', $tmp); + $value= preg_replace('/^[^\s]+\s/', '', $tmp); + $this->statements[$idx]= $value; + } + } + + } else { + /* We keep the parent dn here if it's new */ + $this->dn= $attrs; + $this->new= TRUE; + } + + /* Load network module */ + $this->network= new dhcpNetwork(); + $this->network->options= $this->options; + $this->network->statements= $this->statements; + $this->advanced= new dhcpAdvanced(); + $this->advanced->options= $this->options; + $this->advanced->statements= $this->statements; + $this->advanced->setAutoStatements(array("fixed-address")); + + /* Save CN for later reference */ + $this->orig_cn= $this->cn; + } + + function execute() + { + $smarty= get_smarty(); + $smarty->assign("cn", $this->cn); + + if ($this->dn != "new"){ + $smarty->assign("mode", "readonly"); + } + + /* Show main page */ + $display= $smarty->fetch (get_template_path('dhcp_group.tpl', TRUE)).$this->network->execute(); + + /* Merge arrays for advanced view */ + foreach (array("options", "statements") as $type){ + $tmp= array_merge($this->$type, $this->network->$type); + $this->advanced->$type= $tmp; + } + + $display.= $this->advanced->execute(); + + /* Merge back for removals */ + foreach (array("options", "statements") as $type){ + $this->$type= $this->advanced->$type; + $this->network->$type= $this->advanced->$type; + } + + /* Add footer */ + $display.= "
". + " 
"; + + + return ($display); + } + + + function remove_from_parent() + { + } + + + /* Save data to object */ + function save_object() + { + /* Save sub-objects */ + $this->network->save_object(); + $this->advanced->save_object(); + + /* Merge arrays for advanced view */ + foreach (array("options", "statements") as $type){ + $tmp= array_merge($this->$type, $this->network->$type); + $this->advanced->$type= $tmp; + } + } + + + /* Check values */ + function check() + { + $message= array(); + + /* All required fields are set? */ + if ($this->cn == ""){ + $message[]= _("Required field 'Name' is not filled."); + } + + /* cn already used? */ + echo "TODO: no ldap check"; + if ($this->dn != "new"){ + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(&(objectClass=dhcpGroup)(cn=".$this->cn."))"); + if ($ldap->count() >= 1){ + while ($attrs= $ldap->fetch()){ + if ($ldap->getDN() != $this->dn){ + $message[]= _("The name for this group section is already used!"); + break; + } + + } + } + $ldap->fetch(); + } + + return $message; + } + + + /* Save to LDAP */ + function save() + { + echo "TODO: save"; + return; + + /* Get ldap mode */ + if ($this->dn == "new"){ + $mode= "add"; + } else { + $mode= "modify"; + } + + /* Generate new dn */ + if ($this->parent->parent != NULL && $this->dn == "new"){ + $this->dn= "cn=".$this->cn.",".$this->parent->parent; + } + + + /* Assemble new entry - options */ + if (isset ($this->options) && count ($this->options)){ + $this->attrs['dhcpOption']= array(); + foreach ($this->options as $key => $val){ + $this->attrs['dhcpOption'][]= "$key $val"; + } + } else { + if ($mode == "modify"){ + $this->attrs['dhcpOption']= array(); + } + } + + /* Assemble new entry - statements */ + if (isset ($this->statements) && count ($this->statements)){ + $this->attrs['dhcpStatements']= array(); + foreach ($this->statements as $key => $val){ + $this->attrs['dhcpStatements'][]= "$key $val"; + } + } else { + if ($mode == "modify"){ + $this->attrs['dhcpStatements']= array(); + } + } + + /* Do LDAP action */ + $ldap= $this->config->get_ldap_link(); + if ($mode == "add"){ + $ldap->cd($this->config->current['BASE']); + $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn)); + } + $ldap->cd($this->dn); + $ldap->$mode($this->attrs); + show_ldap_error($ldap->get_error()); + } + +} + +?> diff --git a/plugins/admin/systems/class_dhcpHost.inc b/plugins/admin/systems/class_dhcpHost.inc index cac159b2f..499e417fc 100644 --- a/plugins/admin/systems/class_dhcpHost.inc +++ b/plugins/admin/systems/class_dhcpHost.inc @@ -113,7 +113,7 @@ class dhcpHost extends plugin "fddi" => _("FDDI"), "token-ring" => _("Token Ring"))); /* Show main page */ - $display= $smarty->fetch(get_template_path('dhcphost.tpl', TRUE)).$this->network->execute(); + $display= $smarty->fetch(get_template_path('dhcp_host.tpl', TRUE)).$this->network->execute(); /* Merge arrays for advanced view */ foreach (array("options", "statements") as $type){ @@ -163,6 +163,14 @@ class dhcpHost extends plugin } } + /* Strip network objects */ + foreach (array("routers", "domain-name", "subnet-mask", "broadcast-address") as $toberemoved){ + unset($this->options[$toberemoved]); + } + foreach (array("filename", "next-server") as $toberemoved){ + unset($this->statements[$toberemoved]); + } + /* Save sub-objects */ $this->network->save_object(); $this->advanced->save_object(); diff --git a/plugins/admin/systems/dhcp_group.tpl b/plugins/admin/systems/dhcp_group.tpl new file mode 100644 index 000000000..d3725178a --- /dev/null +++ b/plugins/admin/systems/dhcp_group.tpl @@ -0,0 +1,22 @@ +{* GOsa dhcp sharedNetwork - smarty template *} +

{t}Generic{/t}

+ + + + + +
+ {t}Name{/t}{$must} + + +
+ +

 

+ + + diff --git a/plugins/admin/systems/dhcphost.tpl b/plugins/admin/systems/dhcp_host.tpl similarity index 96% rename from plugins/admin/systems/dhcphost.tpl rename to plugins/admin/systems/dhcp_host.tpl index a2a2915e0..e31a65f37 100644 --- a/plugins/admin/systems/dhcphost.tpl +++ b/plugins/admin/systems/dhcp_host.tpl @@ -31,7 +31,7 @@ - {t}Hardware address{/t} + {t}Hardware address{/t}{$must} -- 2.30.2