59c56588406aff5e7e34b3558deaec7a2153586e
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 dhcpService extends dhcpPlugin
22 {
23 /* Used attributes */
24 var $dhcpPrimaryDN= "";
25 var $orig_dhcpPrimaryDN= "";
26 var $ddns_styles= array('none', 'interim', 'ad-hoc');
28 /* attribute list for save action */
29 var $objectclasses= array('top', 'dhcpService');
32 function dhcpService($attrs)
33 {
34 dhcpPlugin::dhcpPlugin($attrs);
36 /* Load statements / options */
37 if (!$this->new){
38 /* Load attributes */
39 $this->dhcpPrimaryDN= $attrs['dhcpPrimaryDN'][0];
40 } else {
41 /* We keep the parent dn here if it's new */
42 $this->statements['default-lease-time']= 600;
43 $this->statements['max-lease-time']= 1700;
44 $this->statements['authoritative']= TRUE;
45 $this->statements['ddns-update-style']= 'none';
46 }
48 $this->advanced->setAutoStatements(array("default-lease-time", "max-lease-time", "authoritative", "server-identifier", "ddns-update-style"));
49 $this->advanced->setAutoOptions(array("server-name"));
51 /* Save for later action */
52 $this->orig_dhcpPrimaryDN= $this->dhcpPrimaryDN;
53 }
56 function execute()
57 {
58 /* Show main page */
59 $smarty= get_smarty();
61 /* Assign ACLs */
62 $smarty->assign("acl",$this->parent->getacl(""));
64 $smarty->assign('ddns_styles', $this->ddns_styles);
65 foreach (array('max_lease_time', 'default_lease_time', 'ddns_update_style') as $value){
66 if (isset($this->statements[preg_replace('/_/', '-', $value)])){
67 $smarty->assign("$value", $this->statements[preg_replace('/_/', '-', $value)]);
68 } else {
69 $smarty->assign("$value", "");
70 }
71 }
73 if (isset($this->statements['authoritative'])){
74 $smarty->assign("authoritative", "checked");
75 } else {
76 $smarty->assign("authoritative", "");
77 }
79 /* Show main page */
80 $display= $smarty->fetch(get_template_path('dhcp_service.tpl', TRUE, dirname(__FILE__))).$this->network->execute();
82 /* Merge arrays for advanced view */
83 $this->fix_options();
84 foreach (array("options", "statements") as $type){
85 $this->advanced->$type= $this->$type + $this->network->$type;;
86 }
88 $display.= $this->advanced->execute();
90 /* Merge back for removals */
91 foreach (array("options", "statements") as $type){
92 $this->$type= $this->advanced->$type;
93 $this->network->$type= $this->advanced->$type;
94 }
96 /* Add footer */
97 $display.= "<div style='width:100%;text-align:right;margin-top:5px;'><input type=submit name='save_dhcp' value='".msgPool::saveButton()."'>".
98 " <input type=submit name='cancel_dhcp' value='".msgPool::cancelButton()."'></div>";
101 return ($display);
103 }
105 function remove_from_parent()
106 {
107 }
110 /* Save data to object */
111 function save_object()
112 {
113 /* No need to save in the first time */
114 if (!isset($_POST['ddns_update_style'])){
115 return;
116 }
118 /* Save remaining attributes */
119 foreach (array('max_lease_time', 'default_lease_time', 'ddns_update_style') as $val){
120 $tval= preg_replace('/_/', '-', $val);
121 if ($_POST[$val] != ""){
122 $this->statements[$tval]= validate(get_post($val));
123 } else {
124 unset ($this->statements[$tval]);
125 }
126 }
127 if (isset($_POST['authoritative'])){
128 $this->statements['authoritative']= "";
129 } else {
130 unset($this->statements['authoritative']);
131 }
133 dhcpPlugin::save_object();
134 }
137 /* Check values */
138 function check()
139 {
140 $message= array();
142 if (!tests::is_id($this->statements['default-lease-time'])){
143 $message[]= msgPool::invalid(_("Lease time"),$this->statements['default-lease-time'],"/[0-9]/");
144 }
145 if (!tests::is_id($this->statements['max-lease-time'])){
146 $message[]= msgPool::invalid(_("Max lease time"),$this->statements['max-lease-time'],"/[0-9]/");
147 }
148 if ($this->statements['default-lease-time'] > $this->statements['max-lease-time']){
149 $message[]= msgPool::toobig(_("Default lease time"),_("Maximum lease time"));
150 }
152 /* Check external plugins */
153 $net= $this->network->check();
154 $adv= $this->advanced->check();
155 $message= array_merge($message, $net, $adv);
157 return $message;
158 }
161 /* Save to LDAP */
162 function save()
163 {
164 global $config;
165 $this->attrs= array();
167 /* Get and set server name */
168 $ldap= $config->get_ldap_link();
169 $ldap->cat($this->dhcpPrimaryDN, array('cn'));
170 $res= $ldap->fetch();
171 if(isset($res['cn'][0])){
172 $server_name= $res['cn'][0];
173 }
175 dhcpPlugin::save();
177 $this->attrs['dhcpPrimaryDN']= array($this->dhcpPrimaryDN);
178 $this->removeOption('server-name');
179 # $this->attrs['dhcpOption'][]= "server-name $server_name";
181 return ($this->attrs);
182 }
184 }
185 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
186 ?>