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", set_post($this->cn));
46 foreach (array("server-identifier", "default-lease-time", "max-lease-time", "min-lease-time") as $attr){
47 $name = preg_replace('/-/', '_', $attr);
48 $smarty->assign($name, set_post($this->statements->get($attr)));
49 }
50 if ($this->statements->exists("authoritative")){
51 $smarty->assign("authoritative", "checked");
52 } else {
53 $smarty->assign("authoritative", "");
54 }
56 $allow = $this->statements->get("allow");
57 if(!is_array($allow)) $allow=array($allow);
58 foreach(array(
59 "unknown-clients" => "allow_unknown_state",
60 "bootp" => "allow_bootp_state",
61 "booting" => "allow_booting_state") as $state => $target){
62 if(in_array_strict($state,$allow)){
63 $smarty->assign($target,"checked");
64 }else{
65 $smarty->assign($target,"");
66 }
67 }
69 /* Show main page */
70 $display= $smarty->fetch(get_template_path('dhcp_sharedNetwork.tpl', TRUE,dirname(__FILE__))).$this->network->execute();
72 /* Remove states configured by checkboxes.
73 */
74 foreach(array("deny unknown-clients",
75 "deny bootp", "deny booting", "allow unknown-clients",
76 "allow bootp", "allow booting") as $name){
77 if($this->statements->exists($name)){
78 $this->statements->remove($name);
79 }
80 }
82 $display.= $this->advanced->execute();
84 /* Add footer */
85 $display.= "<div style='width:100%;text-align:right;margin-top:5px;'>";
86 if(preg_match("/w/",$this->parent->getacl(""))){
87 $display.= "<button type='submit' name='save_dhcp'>".msgPool::saveButton()."</button> ";
88 }
89 $display.= "<button type='submit' name='cancel_dhcp'>".msgPool::cancelButton()."</button>";
90 $display.= "</div>";
92 return ($display);
93 }
96 function remove_from_parent()
97 {
98 }
101 /* Save data to object */
102 function save_object()
103 {
104 /* Check permissions, don't touch anything if we do not have write permissions
105 */
106 if (!preg_match("/w/",$this->parent->getacl(""))){
107 dhcpPlugin::save_object();
108 }elseif(isset($_POST['cn'])){
110 $this->cn= get_post('cn');
111 dhcpPlugin::save_object();
113 foreach (array("server-identifier", "default-lease-time",
114 "max-lease-time", "min-lease-time") as $attr){
115 if (isset($_POST[$attr]) && $_POST[$attr] != ""){
116 $this->statements->set($attr,get_post($attr));
117 } else {
118 $this->statements->removeAll($attr);
119 }
120 }
122 if (isset($_POST["authoritative"])){
123 $this->statements->set("authoritative", "");
124 } else {
125 $this->statements->removeAll("authoritative");
126 }
128 $this->statements->removeAll("deny");
129 $this->statements->removeAll("allow");
130 foreach(array("unknown-clients", "bootp", "booting") as $name){
131 if (isset($_POST[$name])){
132 $this->statements->add("allow",$name);
133 } else {
134 $this->statements->add("deny",$name);
135 }
136 }
137 }
138 }
141 /* Check values */
142 function check()
143 {
144 $message= array();
146 $cache = $this->parent->dhcpObjectCache;
148 /* All required fields are set? */
149 if ($this->cn == ""){
150 $message[]= msgPool::required(_("Name"));
151 }
153 /* Check lease times */
154 foreach (array("default-lease-time" => _("Default lease time"),
155 "max-lease-time" => _("Max. lease time"),
156 "min-lease-time" => _("Min. lease time")) as $key => $val){
157 if ($this->statements->exists($key) && $this->statements->get($key) != "" &&
158 !tests::is_id($this->statements->get($key))){
159 $message[]= msgPool::invalid($val,$this->statements->get($key),"/[0-9]/");
160 }
161 }
163 /* cn already used? */
164 if ($this->orig_cn != $this->cn || $this->new){
166 foreach($cache as $dn => $dummy){
167 if (preg_match("/^cn=".$this->cn.",/", $dn) && count($dummy)){
168 $message[]= msgPool::duplicated(_("Name"));
169 break;
170 }
171 }
172 }
174 /* Check external plugins */
175 $net= $this->network->check();
176 $adv= $this->advanced->check();
177 $message= array_merge($message, $net, $adv);
179 return $message;
180 }
183 /* Save to LDAP */
184 function save()
185 {
186 dhcpPlugin::save();
188 return ($this->attrs);
189 }
191 }
193 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
194 ?>