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['get-lease-hostnames']= 'on';
46 $this->statements['ddns-update-style']= 'none';
47 }
49 $this->advanced->setAutoStatements(array("default-lease-time", "max-lease-time", "authoritative", "get-lease-hostnames", "server-identifier", "ddns-update-style"));
50 $this->advanced->setAutoOptions(array("server-name"));
52 /* Save for later action */
53 $this->orig_dhcpPrimaryDN= $this->dhcpPrimaryDN;
54 }
57 function execute()
58 {
59 /* Show main page */
60 $smarty= get_smarty();
62 $smarty->assign('ddns_styles', $this->ddns_styles);
63 foreach (array('max_lease_time', 'default_lease_time', 'ddns_update_style') as $value){
64 if (isset($this->statements[preg_replace('/_/', '-', $value)])){
65 $smarty->assign("$value", $this->statements[preg_replace('/_/', '-', $value)]);
66 } else {
67 $smarty->assign("$value", "");
68 }
69 }
71 if (isset($this->statements['authoritative'])){
72 $smarty->assign("authoritative", "checked");
73 } else {
74 $smarty->assign("authoritative", "");
75 }
77 if (isset($this->statements['get-lease-hostnames']) && preg_match('/on/i', $this->statements['get-lease-hostnames'])){
78 $smarty->assign("get_lease_hostnames", "checked");
79 } else {
80 $smarty->assign("get_lease_hostnames", "");
81 }
83 /* Show main page */
84 $display= $smarty->fetch(get_template_path('dhcp_service.tpl', TRUE)).$this->network->execute();
86 /* Merge arrays for advanced view */
87 foreach (array("options", "statements") as $type){
88 $tmp= array_merge($this->$type, $this->network->$type);
89 $this->advanced->$type= $tmp;
90 }
92 $display.= $this->advanced->execute();
94 /* Merge back for removals */
95 foreach (array("options", "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;'><input type=submit name='save_dhcp' value='"._("Save")."'>".
102 " <input type=submit name='cancel_dhcp' value='"._("Cancel")."'></div>";
105 return ($display);
107 }
109 function remove_from_parent()
110 {
111 }
114 /* Save data to object */
115 function save_object()
116 {
117 /* No need to save in the first time */
118 if (!isset($_POST['ddns_update_style'])){
119 return;
120 }
122 /* Save remaining attributes */
123 foreach (array('max_lease_time', 'default_lease_time', 'ddns_update_style') as $val){
124 $tval= preg_replace('/_/', '-', $val);
125 if ($_POST[$val] != ""){
126 $this->statements[$tval]= validate($_POST[$val]);
127 } else {
128 unset ($this->statements[$tval]);
129 }
130 }
131 if (isset($_POST['authoritative'])){
132 $this->statements['authoritative']= "";
133 } else {
134 unset($this->statements['authoritative']);
135 }
136 if (isset($_POST['get_lease_hostnames'])){
137 $this->statements['get-lease-hostnames']= "on";
138 } else {
139 $this->statements['get-lease-hostnames']= "off";
140 }
142 dhcpPlugin::save_object();
143 }
146 /* Check values */
147 function check()
148 {
149 $message= array();
150 return $message;
151 }
154 /* Save to LDAP */
155 function save()
156 {
157 global $config;
158 $this->attrs= array();
160 /* Get and set server name */
161 $ldap= $config->get_ldap_link();
162 $ldap->cat($this->dhcpPrimaryDN, array('cn'));
163 $res= $ldap->fetch();
164 $server_name= $res['cn'][0];
166 dhcpPlugin::save();
168 $this->attrs['dhcpPrimaryDN']= array($this->dhcpPrimaryDN);
169 $this->removeOption('server-name');
170 $this->attrs['dhcpOption'][]= "server-name $server_name";
172 return ($this->attrs);
173 }
175 }
177 ?>