1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
21 class dhcpPool extends dhcpPlugin
22 {
23 /* Used attributes */
24 var $dhcpRange= "";
25 var $range_start= "";
26 var $range_stop= "";
28 /* attribute list for save action */
29 var $objectclasses= array('top', 'dhcpPool');
31 function dhcpPool($attrs)
32 {
33 dhcpPlugin::dhcpPlugin($attrs);
35 /* Load attributes */
36 if (!$this->new){
37 $this->dhcpRange= $attrs['dhcpRange'][0];
38 list($this->range_start, $this->range_stop)= preg_split('/\s+/', $this->dhcpRange);
39 }
41 $this->advanced->setAutoOptions(array("host-name"));
42 $this->advanced->setAutoStatements(array("fixed-address"));
43 }
45 function execute()
46 {
47 $smarty= get_smarty();
48 $smarty->assign("cn", $this->cn);
49 $smarty->assign("range_start", $this->range_start);
50 $smarty->assign("range_stop", $this->range_stop);
52 /* Show main page */
53 $display= $smarty->fetch(get_template_path('dhcp_pool.tpl', TRUE)).$this->network->execute();
55 /* Merge arrays for advanced view */
56 foreach (array("options", "statements") as $type){
57 $this->advanced->$type= $this->$type + $this->network->$type;;
58 }
60 $display.= $this->advanced->execute();
62 /* Merge back for removals */
63 foreach (array("options", "statements") as $type){
64 $this->$type= $this->advanced->$type;
65 $this->network->$type= $this->advanced->$type;
66 }
68 /* Add footer */
69 $display.= "<div style='width:100%;text-align:right;margin-top:5px;'><input type=submit name='save_dhcp' value='"._("Save")."'>".
70 " <input type=submit name='cancel_dhcp' value='"._("Cancel")."'></div>";
72 return ($display);
73 }
75 function remove_from_parent()
76 {
77 }
80 /* Save data to object */
81 function save_object()
82 {
83 if (isset($_POST['cn'])){
84 $this->cn= validate($_POST['cn']);
85 $this->range_start= validate($_POST['range_start']);
86 $this->range_stop= validate($_POST['range_stop']);
87 }
89 dhcpPlugin::save_object();
91 /* Move range to internal variable */
92 $this->dhcpRange= $this->range_start." ".$this->range_stop;
93 }
96 /* Check values */
97 function check($cache)
98 {
99 $message= array();
101 /* All required fields are set? */
102 if ($this->cn == ""){
103 $message[]= _("Required field 'Name' is not filled.");
104 }
106 /* cn already used? */
107 if ($this->orig_cn != $this->cn || $this->new){
109 foreach($cache as $dn => $dummy){
110 if (preg_match("/^cn=".$this->cn.",/", $dn) && count($dummy)){
111 $message[]= _("The name for this section is already used!");
112 break;
113 }
114 }
115 }
117 if ($this->dhcpRange == ""){
118 $message[]= _("Required field 'Range' is not filled.");
119 }
121 if (!is_ip($this->range_start) || !is_ip($this->range_stop)){
122 $message[]= _("Field 'Range' contains invalid IP addresses.");
123 }
125 if(!is_ip_range($this->range_start,$this->range_stop)){
126 $message[] = _("Field 'Range' contains invalid IP range.");
127 }
129 return $message;
130 }
132 /* Save to LDAP */
133 function save()
134 {
135 dhcpPlugin::save();
136 $this->attrs['dhcpRange']= array($this->dhcpRange);
138 return ($this->attrs);
139 }
141 }
143 ?>