summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5911441)
raw | patch | inline | side by side (parent: 5911441)
author | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 8 Aug 2007 12:43:36 +0000 (12:43 +0000) | ||
committer | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 8 Aug 2007 12:43:36 +0000 (12:43 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@7003 594d385d-05f5-0310-b6e9-bd551577e9d8
plugins/admin/systems/class_dhcpPool.inc | [new file with mode: 0644] | patch | blob |
plugins/admin/systems/dhcp_pool.tpl | [new file with mode: 0644] | patch | blob |
diff --git a/plugins/admin/systems/class_dhcpPool.inc b/plugins/admin/systems/class_dhcpPool.inc
--- /dev/null
@@ -0,0 +1,225 @@
+<?php
+/*
+ This code is part of GOsa (https://gosa.gonicus.de)
+ Copyright (C) 2003 Cajus Pollmeier
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+class dhcpPool extends plugin
+{
+ /* Used attributes */
+ var $cn= "";
+ var $dhcpRange= "";
+ var $range_start= "";
+ var $range_stop= "";
+ var $options= array();
+ var $statements= array();
+
+ /* Subobjects */
+ var $network;
+ var $advanced;
+
+ /* attribute list for save action */
+ var $attributes= array();
+ var $objectclasses= array();
+
+ function dhcpPool($attrs)
+ {
+ /* Load statements / options */
+ if (is_array($attrs)){
+ $this->dn= $attrs['dn'];
+ $this->new= FALSE;
+
+ /* Load attributes */
+ $this->cn= $attrs['cn'][0];
+ $this->dhcpRange= $attrs['dhcpRange'][0];
+ list($this->range_start, $this->range_stop)= preg_split('/\s+/', $this->dhcpRange);
+
+ /* 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->setAutoOptions(array("host-name"));
+ $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);
+ $smarty->assign("range_start", $this->range_start);
+ $smarty->assign("range_stop", $this->range_stop);
+
+ /* Show main page */
+ $display= $smarty->fetch(get_template_path('dhcp_pool.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.= "<div style='width:100%;text-align:right;margin-top:5px;'><input type=submit name='save_dhcp' value='"._("Save")."'>".
+ " <input type=submit name='cancel_dhcp' value='"._("Cancel")."'></div>";
+
+ return ($display);
+ }
+
+ function remove_from_parent()
+ {
+ }
+
+
+ /* Save data to object */
+ function save_object()
+ {
+ if (isset($_POST['cn'])){
+ $this->cn= validate($_POST['cn']);
+ $this->range_start= validate($_POST['range_start']);
+ $this->range_stop= validate($_POST['range_stop']);
+ }
+
+ /* 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;
+ }
+
+ /* Move range to internal variable */
+ $this->dhcpRange= $this->range_start." ".$this->range_stop;
+ }
+
+
+ /* Check values */
+ function check($cache)
+ {
+ $message= array();
+
+ /* All required fields are set? */
+ if ($this->cn == ""){
+ $message[]= _("Required field 'Name' is not filled.");
+ }
+
+ /* cn already used? */
+ if ($this->orig_cn != $this->cn || $this->new){
+
+ foreach($cache as $dn => $dummy){
+ if (preg_match("/^cn=".$this->cn.",/", $dn) && count($dummy)){
+ $message[]= _("The name for this section is already used!");
+ break;
+ }
+ }
+ }
+
+ if ($this->dhcpRange == ""){
+ $message[]= _("Required field 'Range' is not filled.");
+ }
+
+ if (!is_ip($this->range_start) || !is_ip($this->range_stop)){
+ $message[]= _("Field 'Range' contains invalid IP addresses.");
+ }
+
+ return $message;
+ }
+
+ /* Save to LDAP */
+ function save()
+ {
+ /* Merge arrays for network and advanced view */
+ foreach (array("options", "statements") as $type){
+ $tmp= array_merge($this->$type, $this->network->$type, $this->advanced->$type);
+ $this->$type= $tmp;
+ }
+
+ /* Add cn if we're new */
+ if ($this->new){
+ $this->dn= "cn=".$this->cn.",".$this->dn;
+ } else {
+ $this->dn= "cn=".$this->cn.preg_replace('/^cn=[^,]+/', '', $this->dn);
+ }
+
+ /* 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";
+ }
+ }
+
+ /* Assemble new entry - statements */
+ $this->attrs['dhcpStatements']= array();
+ if (isset ($this->statements) && count ($this->statements)){
+ foreach ($this->statements as $key => $val){
+ $this->attrs['dhcpStatements'][]= "$key $val";
+ }
+ }
+
+ /* Move dn to the result */
+ $this->attrs['dn']= $this->dn;
+ $this->attrs['cn']= array($this->cn);
+ $this->attrs['dhcpRange']= array($this->dhcpRange);
+ $this->attrs['objectClass']= array('top', 'dhcpPool');
+ $this->attrs['MODIFIED']= TRUE;
+
+ return ($this->attrs);
+ }
+
+}
+
+?>
diff --git a/plugins/admin/systems/dhcp_pool.tpl b/plugins/admin/systems/dhcp_pool.tpl
--- /dev/null
@@ -0,0 +1,26 @@
+{* GOsa dhcp sharedNetwork - smarty template *}
+<p><b>{t}Generic{/t}</b></p>
+<table width="100%">
+ <tr>
+ <td width="50%">
+ {t}Name{/t}{$must}
+ <input type='text' name='cn' size='25' maxlength='80' value='{$cn}'
+ title='{t}Name of pool{/t}'>
+ </td>
+ <td>
+ {t}Range{/t}{$must}
+ <input type='text' name='range_start' size='25' maxlength='30' value='{$range_start}'>
+ -
+ <input type='text' name='range_stop' size='25' maxlength='30' value='{$range_stop}'>
+ </td>
+ </tr>
+</table>
+
+<p class="seperator"> </p>
+
+<!-- Place cursor in correct field -->
+<script language="JavaScript" type="text/javascript">
+ <!-- // First input field on page
+ document.mainform.cn.focus();
+ -->
+</script>