1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003-2007 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 dhcpSharedNetwork extends dhcpPlugin
22 {
23 /* attribute list for save action */
24 var $objectclasses= array('top', 'dhcpSharedNetwork');
26 function dhcpSharedNetwork($attrs)
27 {
28 dhcpPlugin::dhcpPlugin($attrs);
30 $this->advanced->setAutoStatements(array("server-identifier", "default-lease-time",
31 "max-lease-time", "min-lease-time", "authoritative", "deny-unknown-clients",
32 "deny-bootp", "deny-booting"));
33 }
36 function execute()
37 {
38 $smarty= get_smarty();
40 /* Fill template */
41 $smarty->assign ("cn", $this->cn);
42 foreach (array("server-identifier", "default-lease-time", "max-lease-time", "min-lease-time") as $attr){
43 if (isset($this->statements[$attr])){
44 $smarty->assign(preg_replace('/-/', '_', $attr), $this->statements[$attr]);
45 } else {
46 $smarty->assign(preg_replace('/-/', '_', $attr), "");
47 }
48 }
49 if (isset($this->statements["authoritative"])){
50 $smarty->assign("authoritative", "checked");
51 } else {
52 $smarty->assign("authoritative", "");
53 }
54 if (!isset($this->statements["deny-unknown-clients"])){
55 $smarty->assign("allow_unknown_state", "checked");
56 } else {
57 $smarty->assign("allow_unknown_state", "");
58 }
59 if (!isset($this->statements["deny-bootp"])){
60 $smarty->assign("allow_bootp_state", "checked");
61 } else {
62 $smarty->assign("allow_bootp_state", "");
63 }
64 if (!isset($this->statements["deny-booting"])){
65 $smarty->assign("allow_booting_state", "checked");
66 } else {
67 $smarty->assign("allow_booting_state", "");
68 }
70 /* Show main page */
71 $display= $smarty->fetch(get_template_path('dhcp_sharedNetwork.tpl', TRUE)).$this->network->execute();
73 /* Merge arrays for advanced view */
74 foreach (array("options", "statements") as $type){
75 $this->advanced->$type= $this->$type + $this->network->$type;
76 }
78 $display.= $this->advanced->execute();
80 /* Merge back for removals */
81 foreach (array("options", "statements") as $type){
82 $this->$type= $this->advanced->$type;
83 $this->network->$type= $this->advanced->$type;
84 }
86 /* Add footer */
87 $display.= "<div style='width:100%;text-align:right;margin-top:5px;'><input type=submit name='save_dhcp' value='"._("Save")."'>".
88 " <input type=submit name='cancel_dhcp' value='"._("Cancel")."'></div>";
91 return ($display);
92 }
95 function remove_from_parent()
96 {
97 }
100 /* Save data to object */
101 function save_object()
102 {
103 if (isset($_POST['cn'])){
104 $this->cn= validate($_POST['cn']);
105 dhcpPlugin::save_object();
107 foreach (array("server-identifier", "default-lease-time",
108 "max-lease-time", "min-lease-time") as $attr){
109 if (isset($_POST[$attr]) && $_POST[$attr] != ""){
110 $this->statements[$attr]= $_POST[$attr];
111 } else {
112 unset($this->statements[$attr]);
113 }
114 }
116 if (isset($_POST["authoritative"])){
117 $this->statements["authoritative"]= "";
118 } else {
119 unset ($this->statements["authoritative"]);
120 }
122 foreach(array("unknown-clients", "bootp", "booting") as $name){
123 if (isset($_POST[$name])){
124 $this->statements["allow-$name"]= "";
125 unset($this->statements["deny-$name"]);
126 } else {
127 $this->statements["deny-$name"]= "";
128 unset($this->statements["allow-$name"]);
129 }
130 }
131 }
132 }
135 /* Check values */
136 function check($cache)
137 {
138 $message= array();
140 /* All required fields are set? */
141 if ($this->cn == ""){
142 $message[]= _("Required field 'Name' is not filled.");
143 }
145 /* Check lease times */
146 foreach (array("default-lease-time" => _("Default lease time"),
147 "max-lease-time" => _("Max. lease time"),
148 "min-lease-time" => _("Min. lease time")) as $key => $val){
149 if (isset($this->statements[$key]) && $this->statements[$key] != "" &&
150 !is_id($this->statements[$key])){
151 $message[]= sprintf(_("The value specified as '%s' is no valid integer!"), $val);
152 }
153 }
155 /* cn already used? */
156 if ($this->orig_cn != $this->cn || $this->new){
158 foreach($cache as $dn => $dummy){
159 if (preg_match("/^cn=".$this->cn.",/", $dn) && count($dummy)){
160 $message[]= _("The name for this host section is already used!");
161 break;
162 }
163 }
164 }
166 return $message;
167 }
170 /* Save to LDAP */
171 function save()
172 {
173 dhcpPlugin::save();
175 return ($this->attrs);
176 }
178 }
180 ?>