From: cajus Date: Wed, 8 Aug 2007 15:04:28 +0000 (+0000) Subject: Added non working version of sharedNetworks X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=15de8199fbee773bdd13f8e51cd3e613e4ee1076;p=gosa.git Added non working version of sharedNetworks git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@7005 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/plugins/admin/systems/class_dhcpNewSectionDialog.inc b/plugins/admin/systems/class_dhcpNewSectionDialog.inc index 26188f514..32291f83e 100644 --- a/plugins/admin/systems/class_dhcpNewSectionDialog.inc +++ b/plugins/admin/systems/class_dhcpNewSectionDialog.inc @@ -10,13 +10,13 @@ class dhcpNewSectionDialog extends plugin /* Mapping array */ var $types= array(); var $classtype= ""; - static $sectionMap= array( "dhcpService" => array("dhcpSharedNetwork", "dhcpSubnet", "dhcpGroup", "dhcpHost", "dhcpClass"), - "dhcpClass" => array("dhcpSubClass"), + static $sectionMap= array( "dhcpService" => array("dhcpSharedNetwork", "dhcpSubnet", "dhcpGroup", "dhcpHost" /*, "dhcpClass"*/), + #"dhcpClass" => array("dhcpSubClass"), "dhcpSubClass" => array(), "dhcpHost" => array(), "dhcpGroup" => array("dhcpHost"), "dhcpPool" => array(), - "dhcpSubnet" => array("dhcpPool", "dhcpGroup", "dhcpHost", "dhcpClass"), + "dhcpSubnet" => array("dhcpPool", "dhcpGroup", "dhcpHost" /*, "dhcpClass"*/), "dhcpSharedNetwork" => array("dhcpSubnet", "dhcpPool")); @@ -24,7 +24,7 @@ class dhcpNewSectionDialog extends plugin function dhcpNewSectionDialog($type) { $this->types= array( "dhcpService" => _("Global options"), - "dhcpClass" => _("Class"), + /*"dhcpClass" => _("Class"),*/ "dhcpSubClass" => _("Subclass"), "dhcpHost" => _("Host"), "dhcpGroup" => _("Group"), diff --git a/plugins/admin/systems/class_dhcpSharedNetwork.inc b/plugins/admin/systems/class_dhcpSharedNetwork.inc new file mode 100644 index 000000000..3e82b815a --- /dev/null +++ b/plugins/admin/systems/class_dhcpSharedNetwork.inc @@ -0,0 +1,260 @@ +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; + + /* Save CN for later reference */ + $this->orig_cn= $this->cn; + } + + + function execute() + { + $smarty= get_smarty(); + + /* Fill template */ + $smarty->assign ("cn", $this->cn); + 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]); + } + } + if ($this->dn != 'new'){ + $smarty->assign("mode", "readonly"); + } + if (isset($this->statements["authoritative"])){ + $smarty->assign("authoritative", "checked"); + } + if (!isset($this->statements["deny-unknown-clients"])){ + $smarty->assign("allow_unknown_state", "checked"); + } + if (!isset($this->statements["deny-bootp"])){ + $smarty->assign("allow_bootp_state", "checked"); + } + if (!isset($this->statements["deny-booting"])){ + $smarty->assign("allow_booting_state", "checked"); + } + + /* Show main page */ + $display= $smarty->fetch(get_template_path('dhcp_sharedNetwork.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() + { + /* 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"]); + } + } + } + } + + + /* Check values */ + function check() + { + $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; + } + + + /* Save to LDAP */ + function save() + { + plugin::save(); + + /* 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){ + 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()); + } + +} + +?> diff --git a/plugins/admin/systems/dhcp_sharedNetwork.tpl b/plugins/admin/systems/dhcp_sharedNetwork.tpl new file mode 100644 index 000000000..339db41e6 --- /dev/null +++ b/plugins/admin/systems/dhcp_sharedNetwork.tpl @@ -0,0 +1,108 @@ +{* GOsa dhcp sharedNetwork - smarty template *} +

{t}Generic{/t}

+ + + + + + + + +
+ + + + + + + + + + +
{t}Name{/t}{$must} + +
{t}Server identifier{/t} + +
+ +
+ + + + +
+ {t}Authoritative server{/t} +
+
+ +

 

+ + + + + + + + +
+ +

{t}Leases{/t}

+ + + + + + + + + + + + + +
{t}Default lease time{/t} +  {t}seconds{/t} +
{t}Max. lease time{/t} +  {t}seconds{/t} +
{t}Min. lease time{/t} +  {t}seconds{/t} +
+ +
+

{t}Access control{/t}

+ + + + + + + + + + +
+ {t}Allow unknown clients{/t} +
+ {t}Allow bootp clients{/t} +
+ {t}Allow booting{/t} +
+
+ +

 

+ + +