[gosa.git] / trunk / gosa-plugins / dhcp / admin / systems / services / dhcp / class_dhcpSharedNetwork.inc
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($parent,$attrs)
27 {
28 dhcpPlugin::dhcpPlugin($parent,$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", "allow unknown-clients",
33 "allow bootp", "allow booting"));
34 }
37 function execute()
38 {
39 $smarty= get_smarty();
41 /* Assign ACLs */
42 $smarty->assign("acl",$this->parent->getacl(""));
44 /* Fill template */
45 $smarty->assign ("cn", $this->cn);
46 foreach (array("server-identifier", "default-lease-time", "max-lease-time", "min-lease-time") as $attr){
47 if (isset($this->statements[$attr])){
48 $smarty->assign(preg_replace('/-/', '_', $attr), $this->statements[$attr]);
49 } else {
50 $smarty->assign(preg_replace('/-/', '_', $attr), "");
51 }
52 }
53 if (isset($this->statements["authoritative"])){
54 $smarty->assign("authoritative", "checked");
55 } else {
56 $smarty->assign("authoritative", "");
57 }
58 if (!isset($this->statements["deny unknown-clients"])){
59 $smarty->assign("allow_unknown_state", "checked");
60 } else {
61 $smarty->assign("allow_unknown_state", "");
62 }
63 if (!isset($this->statements["deny bootp"])){
64 $smarty->assign("allow_bootp_state", "checked");
65 } else {
66 $smarty->assign("allow_bootp_state", "");
67 }
68 if (!isset($this->statements["deny booting"])){
69 $smarty->assign("allow_booting_state", "checked");
70 } else {
71 $smarty->assign("allow_booting_state", "");
72 }
74 /* Show main page */
75 $display= $smarty->fetch(get_template_path('dhcp_sharedNetwork.tpl', TRUE,dirname(__FILE__))).$this->network->execute();
77 /* Merge arrays for advanced view */
78 $this->fix_options();
80 /* Remove states configured by checkboxes.
81 */
82 foreach(array("deny unknown-clients",
83 "deny bootp", "deny booting", "allow unknown-clients",
84 "allow bootp", "allow booting") as $name){
85 if(isset($this->advanced->statements[$name])){
86 unset($this->advanced->statements[$name]);
87 unset($this->network->statements[$name]);
88 }
89 }
91 foreach (array("options", "statements") as $type){
92 $this->advanced->$type= $this->$type + $this->network->$type;
93 }
95 $display.= $this->advanced->execute();
97 /* Merge back for removals */
98 foreach (array("options", "statements") as $type){
99 $this->$type= $this->advanced->$type;
100 $this->network->$type= $this->advanced->$type;
101 }
103 /* Add footer */
104 $display.= "<div style='width:100%;text-align:right;margin-top:5px;'>";
105 if(preg_match("/w/",$this->parent->getacl(""))){
106 $display.= "<input type=submit name='save_dhcp' value='".msgPool::saveButton()."'> ";
107 }
108 $display.= "<input type=submit name='cancel_dhcp' value='".msgPool::cancelButton()."'>";
109 $display.= "</div>";
111 return ($display);
112 }
115 function remove_from_parent()
116 {
117 }
120 /* Save data to object */
121 function save_object()
122 {
123 /* Check permissions, don't touch anything if we do not have write permissions
124 */
125 if (!preg_match("/w/",$this->parent->getacl(""))){
126 dhcpPlugin::save_object();
127 }elseif(isset($_POST['cn'])){
129 $this->cn= validate(get_post('cn'));
130 dhcpPlugin::save_object();
132 foreach (array("server-identifier", "default-lease-time",
133 "max-lease-time", "min-lease-time") as $attr){
134 if (isset($_POST[$attr]) && $_POST[$attr] != ""){
135 $this->statements[$attr]= get_post($attr);
136 } else {
137 unset($this->statements[$attr]);
138 }
139 }
141 if (isset($_POST["authoritative"])){
142 $this->statements["authoritative"]= "";
143 } else {
144 unset ($this->statements["authoritative"]);
145 }
147 foreach(array("unknown-clients", "bootp", "booting") as $name){
148 if (isset($_POST[$name])){
149 $this->statements["allow $name"]= "";
150 unset($this->statements["deny $name"]);
151 } else {
152 $this->statements["deny $name"]= "";
153 unset($this->statements["allow $name"]);
154 }
155 }
156 }
157 }
160 /* Check values */
161 function check()
162 {
163 $message= array();
165 $cache = $this->parent->dhcpObjectCache;
167 /* All required fields are set? */
168 if ($this->cn == ""){
169 $message[]= msgPool::required(_("Name"));
170 }
172 /* Check lease times */
173 foreach (array("default-lease-time" => _("Default lease time"),
174 "max-lease-time" => _("Max. lease time"),
175 "min-lease-time" => _("Min. lease time")) as $key => $val){
176 if (isset($this->statements[$key]) && $this->statements[$key] != "" &&
177 !tests::is_id($this->statements[$key])){
178 $message[]= msgPool::invalid($val,$this->statements[$key],"/[0-9]/");
179 }
180 }
182 /* cn already used? */
183 if ($this->orig_cn != $this->cn || $this->new){
185 foreach($cache as $dn => $dummy){
186 if (preg_match("/^cn=".$this->cn.",/", $dn) && count($dummy)){
187 $message[]= msgPool::duplicated(_("Name"));
188 break;
189 }
190 }
191 }
193 /* Check external plugins */
194 $net= $this->network->check();
195 $adv= $this->advanced->check();
196 $message= array_merge($message, $net, $adv);
198 return $message;
199 }
202 /* Save to LDAP */
203 function save()
204 {
205 dhcpPlugin::save();
207 return ($this->attrs);
208 }
210 }
212 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
213 ?>