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 $this->fix_options();
75 foreach (array("options", "statements") as $type){
76 $this->advanced->$type= $this->$type + $this->network->$type;
77 }
79 $display.= $this->advanced->execute();
81 /* Merge back for removals */
82 foreach (array("options", "statements") as $type){
83 $this->$type= $this->advanced->$type;
84 $this->network->$type= $this->advanced->$type;
85 }
87 /* Add footer */
88 $display.= "<div style='width:100%;text-align:right;margin-top:5px;'><input type=submit name='save_dhcp' value='".msgPool::saveButton()."'>".
89 " <input type=submit name='cancel_dhcp' value='".msgPool::cancelButton()."'></div>";
92 return ($display);
93 }
96 function remove_from_parent()
97 {
98 }
101 /* Save data to object */
102 function save_object()
103 {
104 if (isset($_POST['cn'])){
105 $this->cn= validate(get_post('cn'));
106 dhcpPlugin::save_object();
108 foreach (array("server-identifier", "default-lease-time",
109 "max-lease-time", "min-lease-time") as $attr){
110 if (isset($_POST[$attr]) && $_POST[$attr] != ""){
111 $this->statements[$attr]= get_post($attr);
112 } else {
113 unset($this->statements[$attr]);
114 }
115 }
117 if (isset($_POST["authoritative"])){
118 $this->statements["authoritative"]= "";
119 } else {
120 unset ($this->statements["authoritative"]);
121 }
123 foreach(array("unknown-clients", "bootp", "booting") as $name){
124 if (isset($_POST[$name])){
125 $this->statements["allow $name"]= "";
126 unset($this->statements["deny $name"]);
127 } else {
128 $this->statements["deny $name"]= "";
129 unset($this->statements["allow $name"]);
130 }
131 }
132 }
133 }
136 /* Check values */
137 function check()
138 {
139 $message= array();
141 $cache = $this->parent->dhcpObjectCache;
143 /* All required fields are set? */
144 if ($this->cn == ""){
145 $message[]= msgPool::required(_("Name"));
146 }
148 /* Check lease times */
149 foreach (array("default-lease-time" => _("Default lease time"),
150 "max-lease-time" => _("Max. lease time"),
151 "min-lease-time" => _("Min. lease time")) as $key => $val){
152 if (isset($this->statements[$key]) && $this->statements[$key] != "" &&
153 !tests::is_id($this->statements[$key])){
154 $message[]= msgPool::invalid($val,$this->statements[$key],"/[0-9]/");
155 }
156 }
158 /* cn already used? */
159 if ($this->orig_cn != $this->cn || $this->new){
161 foreach($cache as $dn => $dummy){
162 if (preg_match("/^cn=".$this->cn.",/", $dn) && count($dummy)){
163 $message[]= msgPool::duplicated(_("Name"));
164 break;
165 }
166 }
167 }
169 /* Check external plugins */
170 $net= $this->network->check();
171 $adv= $this->advanced->check();
172 $message= array_merge($message, $net, $adv);
174 return $message;
175 }
178 /* Save to LDAP */
179 function save()
180 {
181 dhcpPlugin::save();
183 return ($this->attrs);
184 }
186 }
188 ?>