From 07d0246de2be78b25f4bff4882ae24bad8fe638e Mon Sep 17 00:00:00 2001 From: cajus Date: Thu, 9 Aug 2007 08:05:05 +0000 Subject: [PATCH] Updated to manage shared networks git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@7015 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/admin/systems/class_dhcpHost.inc | 8 +- .../admin/systems/class_dhcpSharedNetwork.inc | 229 ++++++------------ plugins/admin/systems/dhcp_sharedNetwork.tpl | 3 +- 3 files changed, 83 insertions(+), 157 deletions(-) diff --git a/plugins/admin/systems/class_dhcpHost.inc b/plugins/admin/systems/class_dhcpHost.inc index ffc20e00c..41d58424d 100644 --- a/plugins/admin/systems/class_dhcpHost.inc +++ b/plugins/admin/systems/class_dhcpHost.inc @@ -30,13 +30,9 @@ class dhcpHost extends dhcpPlugin { dhcpPlugin::dhcpPlugin($attrs); + /* Load attributes */ if (!$this->new){ - /* Load attributes */ - foreach (array("cn", "dhcpHWAddress") as $attr){ - if (isset($attrs[$attr][0])){ - $this->$attr= $attrs[$attr][0]; - } - } + $this->dhcpHWaddress= $attrs['dhcpHWAddress'][0]; } $this->advanced->setAutoOptions(array("host-name")); diff --git a/plugins/admin/systems/class_dhcpSharedNetwork.inc b/plugins/admin/systems/class_dhcpSharedNetwork.inc index 30a800cca..27c79849d 100644 --- a/plugins/admin/systems/class_dhcpSharedNetwork.inc +++ b/plugins/admin/systems/class_dhcpSharedNetwork.inc @@ -1,7 +1,7 @@ dn= $attrs['dn']; - $this->cn= $attrs['cn'][0]; - $this->new= FALSE; - - /* Load options */ - if (isset($attrs['dhcpOption'])){ - foreach ($attrs['dhcpOption'] as $opt){ - $idx= preg_replace('/\s.+$/', '', $opt); - $value= preg_replace('/^[^\s]+\s/', '', $opt); - $this->options[$idx]= $value; - } - } - - /* Load statements */ - if (isset($attrs['dhcpStatements'])){ - foreach ($attrs['dhcpStatements'] as $opt){ - $idx= preg_replace('/\s.+$/', '', $opt); - $value= preg_replace('/^[^\s]+\s/', '', $opt); - $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; + dhcpPlugin::dhcpPlugin($attrs); - /* Save CN for later reference */ - $this->orig_cn= $this->cn; + $this->advanced->setAutoStatements(array("server-identifier", "default-lease-time", + "max-lease-time", "min-lease-time", "authoritative", "deny-unknown-clients", + "deny-bootp", "deny-booting")); } @@ -74,26 +39,32 @@ class dhcpSharedNetwork extends plugin /* Fill template */ $smarty->assign ("cn", $this->cn); - foreach (array("server-identifier", "default-lease-time", - "max-lease-time", "min-lease-time") as $attr){ + foreach (array("server-identifier", "default-lease-time", "max-lease-time", "min-lease-time") as $attr){ if (isset($this->statements[$attr])){ $smarty->assign(preg_replace('/-/', '_', $attr), $this->statements[$attr]); + } else { + $smarty->assign(preg_replace('/-/', '_', $attr), ""); } } - if ($this->dn != 'new'){ - $smarty->assign("mode", "readonly"); - } if (isset($this->statements["authoritative"])){ $smarty->assign("authoritative", "checked"); + } else { + $smarty->assign("authoritative", ""); } if (!isset($this->statements["deny-unknown-clients"])){ $smarty->assign("allow_unknown_state", "checked"); + } else { + $smarty->assign("allow_unknown_state", ""); } if (!isset($this->statements["deny-bootp"])){ $smarty->assign("allow_bootp_state", "checked"); + } else { + $smarty->assign("allow_bootp_state", ""); } if (!isset($this->statements["deny-booting"])){ $smarty->assign("allow_booting_state", "checked"); + } else { + $smarty->assign("allow_booting_state", ""); } /* Show main page */ @@ -124,127 +95,87 @@ class dhcpSharedNetwork extends plugin function remove_from_parent() { - /* Just remove the dn from the ldap, then we're done. Host - entries do not have any entries below themselfes. */ - $ldap= $this->config->get_ldap_link(); - $ldap->cd($this->dn); - $ldap->recursive_remove(); - show_ldap_error($ldap->get_error()); - - /* Optionally execute a command after we're done */ - $this->postremove(); } /* Save data to object */ function save_object() { - if (isset($_POST['cn'])){ - plugin::save_object(); - - foreach (array("server-identifier", "default-lease-time", - "max-lease-time", "min-lease-time") as $attr){ - if (isset($_POST[$attr]) && $_POST[$attr] != ""){ - $this->statements[$attr]= $_POST[$attr]; - } else { - unset($this->statements[$attr]); - } - } - - if (isset($_POST["authoritative"])){ - $this->statements["authoritative"]= ""; - } else { - unset ($this->statements["authoritative"]); - } - - foreach(array("unknown-clients", "bootp", "booting") as $name){ - if (isset($_POST[$name])){ - $this->statements["allow-$name"]= ""; - unset($this->statements["deny-$name"]); - } else { - $this->statements["deny-$name"]= ""; - unset($this->statements["allow-$name"]); - } - } - } + if (isset($_POST['cn'])){ + $this->cn= validate($_POST['cn']); + dhcpPlugin::save_object(); + + foreach (array("server-identifier", "default-lease-time", + "max-lease-time", "min-lease-time") as $attr){ + if (isset($_POST[$attr]) && $_POST[$attr] != ""){ + $this->statements[$attr]= $_POST[$attr]; + } else { + unset($this->statements[$attr]); + } + } + + if (isset($_POST["authoritative"])){ + $this->statements["authoritative"]= ""; + } else { + unset ($this->statements["authoritative"]); + } + + foreach(array("unknown-clients", "bootp", "booting") as $name){ + if (isset($_POST[$name])){ + $this->statements["allow-$name"]= ""; + unset($this->statements["deny-$name"]); + } else { + $this->statements["deny-$name"]= ""; + unset($this->statements["allow-$name"]); + } + } + } } /* Check values */ - function check() + function check($cache) { - $message= array(); - - /* Check lease times */ - foreach (array("default-lease-time" => _("Default lease time"), - "max-lease-time" => _("Max. lease time"), - "min-lease-time" => _("Min. lease time")) as $key => $val){ - if (isset($this->statements[$key]) && $this->statements[$key] != "" && - !is_id($this->statements[$key])){ - $message[]= sprintf(_("The value specified as '%s' is no valid integer!"), $val); - } - } - - return $message; - } + $message= array(); + /* All required fields are set? */ + if ($this->cn == ""){ + $message[]= _("Required field 'Name' is not filled."); + } - /* Save to LDAP */ - function save() - { - plugin::save(); + /* Check lease times */ + foreach (array("default-lease-time" => _("Default lease time"), + "max-lease-time" => _("Max. lease time"), + "min-lease-time" => _("Min. lease time")) as $key => $val){ + if (isset($this->statements[$key]) && $this->statements[$key] != "" && + !is_id($this->statements[$key])){ + $message[]= sprintf(_("The value specified as '%s' is no valid integer!"), $val); + } + } - /* Get ldap mode */ - if ($this->dn == "new"){ - $mode= "add"; - } else { - $mode= "modify"; - } + /* cn already used? */ + if ($this->orig_cn != $this->cn || $this->new){ - /* Generate new dn */ - if ($this->parent->parent != NULL && $this->dn == "new"){ - $this->dn= "cn=".$this->cn.",".$this->parent->parent; + foreach($cache as $dn => $dummy){ + if (preg_match("/^cn=".$this->cn.",/", $dn) && count($dummy)){ + $message[]= _("The name for this host section is already used!"); + break; } + } + } - /* 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(); - } - } + return $message; + } - /* Assemble new entry - statements */ - if (isset ($this->statements) && count ($this->statements)){ - $this->attrs['dhcpStatements']= array(); - foreach ($this->statements as $key => $val){ - if (preg_match('/^allow-/', $key) || preg_match('/^deny-/', $key)){ - $val= preg_replace('/^[^-]+-/', '', $key); - $key= preg_replace('/^([^-]+)-.*$/', '\\1', $key); - } - $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()); + + /* Save to LDAP */ + function save() + { + dhcpPlugin::save(); + + return ($this->attrs); } - + } ?> diff --git a/plugins/admin/systems/dhcp_sharedNetwork.tpl b/plugins/admin/systems/dhcp_sharedNetwork.tpl index 339db41e6..cf4ed6293 100644 --- a/plugins/admin/systems/dhcp_sharedNetwork.tpl +++ b/plugins/admin/systems/dhcp_sharedNetwork.tpl @@ -9,8 +9,7 @@ {t}Name{/t}{$must} - + -- 2.30.2