477accb7ece67d002d7c3d98002e2605a764bdcc
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 $smarty->assign('ddns_styles', $this->ddns_styles);
62 foreach (array('max_lease_time', 'default_lease_time', 'ddns_update_style') as $value){
63 if (isset($this->statements[preg_replace('/_/', '-', $value)])){
64 $smarty->assign("$value", $this->statements[preg_replace('/_/', '-', $value)]);
65 } else {
66 $smarty->assign("$value", "");
67 }
68 }
70 if (isset($this->statements['authoritative'])){
71 $smarty->assign("authoritative", "checked");
72 } else {
73 $smarty->assign("authoritative", "");
74 }
76 /* Show main page */
77 $display= $smarty->fetch(get_template_path('dhcp_service.tpl', TRUE)).$this->network->execute();
79 /* Merge arrays for advanced view */
80 foreach (array("options", "statements") as $type){
81 $this->advanced->$type= $this->$type + $this->network->$type;;
82 }
84 $display.= $this->advanced->execute();
86 /* Merge back for removals */
87 foreach (array("options", "statements") as $type){
88 $this->$type= $this->advanced->$type;
89 $this->network->$type= $this->advanced->$type;
90 }
92 /* Add footer */
93 $display.= "<div style='width:100%;text-align:right;margin-top:5px;'><input type=submit name='save_dhcp' value='"._("Save")."'>".
94 " <input type=submit name='cancel_dhcp' value='"._("Cancel")."'></div>";
97 return ($display);
99 }
101 function remove_from_parent()
102 {
103 }
106 /* Save data to object */
107 function save_object()
108 {
109 /* No need to save in the first time */
110 if (!isset($_POST['ddns_update_style'])){
111 return;
112 }
114 /* Save remaining attributes */
115 foreach (array('max_lease_time', 'default_lease_time', 'ddns_update_style') as $val){
116 $tval= preg_replace('/_/', '-', $val);
117 if ($_POST[$val] != ""){
118 $this->statements[$tval]= validate(get_post($val));
119 } else {
120 unset ($this->statements[$tval]);
121 }
122 }
123 if (isset($_POST['authoritative'])){
124 $this->statements['authoritative']= "";
125 } else {
126 unset($this->statements['authoritative']);
127 }
129 dhcpPlugin::save_object();
130 }
133 /* Check values */
134 function check()
135 {
136 $message= array();
138 if (!is_id($this->statements['default-lease-time'])){
139 $message[]= _('Default lease time needs to be numeric.');
140 }
141 if (!is_id($this->statements['max-lease-time'])){
142 $message[]= _('Maximum lease time needs to be numeric.');
143 }
144 if ($this->statements['default-lease-time'] > $this->statements['max-lease-time']){
145 $message[]= _('Default lease time needs to smaller than the maximum lease time.');
146 }
148 /* Check external plugins */
149 $net= $this->network->check();
150 $adv= $this->advanced->check();
151 $message= array_merge($message, $net, $adv);
153 return $message;
154 }
157 /* Save to LDAP */
158 function save()
159 {
160 global $config;
161 $this->attrs= array();
163 /* Get and set server name */
164 $ldap= $config->get_ldap_link();
165 $ldap->cat($this->dhcpPrimaryDN, array('cn'));
166 $res= $ldap->fetch();
167 $server_name= $res['cn'][0];
169 dhcpPlugin::save();
171 $this->attrs['dhcpPrimaryDN']= array($this->dhcpPrimaryDN);
172 $this->removeOption('server-name');
173 $this->attrs['dhcpOption'][]= "server-name $server_name";
175 return ($this->attrs);
176 }
178 }
179 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
180 ?>