Code

Updated dhcp plugin
[gosa.git] / 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     /* Remove states configured by checkboxes. 
78      */
79     foreach(array("deny unknown-clients",
80           "deny bootp", "deny booting", "allow unknown-clients",
81           "allow bootp", "allow booting") as $name){
82       if(isset($this->advanced->statements[$name])){
83         unset($this->advanced->statements[$name]);
84         unset($this->network->statements[$name]);
85       }
86     }
88     foreach (array("statements") as $type){
89       $this->advanced->$type= $this->$type + $this->network->$type;
90     }
92     $display.= $this->advanced->execute();
94     /* Merge back for removals */
95     foreach (array("statements") as $type){
96       $this->$type= $this->advanced->$type;
97       $this->network->$type= $this->advanced->$type;
98     }
100     /* Add footer */
101     $display.= "<div style='width:100%;text-align:right;margin-top:5px;'>";
102     if(preg_match("/w/",$this->parent->getacl(""))){
103         $display.=   "<input type=submit name='save_dhcp' value='".msgPool::saveButton()."'>&nbsp;";
104     }
105     $display.=   "<input type=submit name='cancel_dhcp' value='".msgPool::cancelButton()."'>";
106     $display.= "</div>";
108     return ($display);
109   }
112   function remove_from_parent()
113   {
114   }
117   /* Save data to object */
118   function save_object()
119   {
120         /* Check permissions, don't touch anything if we do not have write permissions 
121      */
122     if (!preg_match("/w/",$this->parent->getacl(""))){
123       dhcpPlugin::save_object();
124         }elseif(isset($_POST['cn'])){
126       $this->cn= validate(get_post('cn'));
127       dhcpPlugin::save_object();
129       foreach (array("server-identifier", "default-lease-time",
130             "max-lease-time", "min-lease-time") as $attr){
131         if (isset($_POST[$attr]) && $_POST[$attr] != ""){
132           $this->statements[$attr]= get_post($attr);
133         } else {
134           unset($this->statements[$attr]);
135         }
136       }
138       if (isset($_POST["authoritative"])){
139         $this->statements["authoritative"]= "";
140       } else {
141         unset ($this->statements["authoritative"]);
142       }
144       foreach(array("unknown-clients", "bootp", "booting") as $name){
145         if (isset($_POST[$name])){
146           $this->statements["allow $name"]= "";
147           unset($this->statements["deny $name"]);
148         } else {
149           $this->statements["deny $name"]= "";
150           unset($this->statements["allow $name"]);
151         }
152       }
153     }
154   }
157   /* Check values */
158   function check()
159   {
160     $message= array();
162         $cache = $this->parent->dhcpObjectCache;
164     /* All required fields are set? */
165     if ($this->cn == ""){
166       $message[]= msgPool::required(_("Name"));
167     }
169     /* Check lease times */
170     foreach (array("default-lease-time" => _("Default lease time"),
171           "max-lease-time" => _("Max. lease time"),
172           "min-lease-time" => _("Min. lease time")) as $key => $val){
173       if (isset($this->statements[$key]) && $this->statements[$key] != "" && 
174           !tests::is_id($this->statements[$key])){
175         $message[]= msgPool::invalid($val,$this->statements[$key],"/[0-9]/");
176       }
177     }
179     /* cn already used? */
180     if ($this->orig_cn != $this->cn || $this->new){
182       foreach($cache as $dn => $dummy){
183         if (preg_match("/^cn=".$this->cn.",/", $dn) && count($dummy)){
184           $message[]= msgPool::duplicated(_("Name"));
185           break;
186         }
187       }
188     }
190     /* Check external plugins */
191     $net= $this->network->check();
192     $adv= $this->advanced->check();
193     $message= array_merge($message, $net, $adv);
195     return $message;
196   }
199   /* Save to LDAP */
200   function save()
201   {
202     dhcpPlugin::save();
204     return ($this->attrs);
205   }
209 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
210 ?>