1 <?php
3 /*
4 This code is part of GOsa (https://gosa.gonicus.de)
5 Copyright (C) 2007 Fabian Hickert
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
23 class Step_Config2 extends setup_step
24 {
25 var $governmentmode = FALSE;
26 var $sambaidmapping = FALSE;
27 var $header_image = "images/ldapserver.png";
29 var $cyrusunixstyle = FALSE;
30 var $mail = "none";
31 var $mail_attrib = "";
32 var $mail_methods = array();
33 var $mail_settings = array("vacationdir" => "/etc/gosa/vacation",
34 "vacationdir_active" => FALSE);
36 var $generic_settings = array( "enableCopyPaste" => false,
37 "enableDNS" => false,
38 "enableDHCP" => false,
39 "wws_ou" => "ou=winstations",
40 "wws_ou_active" => FALSE,
41 "snapshot_active" => FALSE,
42 "snapshot_base" => "ou=snapshots,%base%",
43 "snapshot_user" => "%admin%",
44 "snapshot_password" => "",
45 "snapshot_server" => "%connection%");
47 var $samba_settings = array( "samba_sid" => "0-815-4711",
48 "samba_sid_active" => FALSE,
49 "samba_rid" => 1000,
50 "smbhash" => 'SMBHASH',
51 "samba_rid_active" => FALSE);
53 var $sambaDomain_found = FALSE;
54 var $use_netatalk = FALSE;
55 var $enableFAI_management = FALSE;
56 var $enableMimeType = FALSE;
58 var $timezone = "Europe/Berlin";
59 var $timezones = array();
61 var $attributes = array("mail_attrib","governmentmode","sambaidmapping","cyrusunixstyle","mail","use_netatalk","enableFAI_management","timezone","enableMimeType");
62 var $called = FALSE;
64 function Step_Config2()
65 {
66 $this->update_strings();
67 $this->mail_methods = $this->get_available_mail_classes();
69 /* Look for samba password generation method */
70 if(file_exists("/usr/bin/mkntpasswd")){
71 $pwdhash = "/usr/bin/mkntpasswd";
72 } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
73 $pwdhash= "mkntpwd";
74 } else {
75 $pwdhash= 'perl -MCrypt::SmbHash -e "print join(q[:], ntlmgen \$ARGV[0]), $/;"';
76 }
78 $this->timezones = timezone::_get_tz_zones();
79 $this->samba_settings['smbhash'] = $pwdhash;
80 }
83 function update_strings()
84 {
85 $this->s_title = _("GOsa settings 2/3");
86 $this->s_title_long = _("GOsa settings 2/3");
87 $this->s_info = _("Customize special parameters");
88 }
91 function execute()
92 {
93 $this->mail_methods = $this->get_available_mail_classes();
94 /* On first call check for rid/sid base */
95 $cv = $this->parent->captured_values;
96 $ldap_l = new LDAP($cv['admin'],
97 $cv['password'],
98 $cv['connection'],
99 FALSE,
100 $cv['tls']);
102 $ldap = new ldapMultiplexer($ldap_l);
104 $ldap->cd($cv['base']);
105 $ldap->search("(objectClass=sambaDomain)",array("dn"));
106 if($ldap->count()){
107 $this->sambaDomain_found =TRUE;
108 }else{
109 $this->sambaDomain_found =FALSE;
110 }
112 if(!$this->called){
113 if(!$this->sambaDomain_found){
114 $this->samba_settings['samba_sid_active'] = TRUE;
115 $this->samba_settings['samba_rid_active'] = TRUE;
116 }
118 /* Check if we can enable netatalk plugin */
119 $tmp = $ldap->get_objectclasses();
120 if(is_array($tmp) && isset($tmp['apple-user'])) {
121 $this->use_netatalk = TRUE;
122 }
124 /* Check the FAI schema is used */
125 if(is_array($tmp) && isset($tmp['FAIclass'])){
126 # $this->enableFAI_management = TRUE;
127 }
129 /* Check the MimeType schema is used */
130 if(is_array($tmp) && isset($tmp['gotoMimeType'])){
131 $this->enableMimeType = TRUE;
132 }
134 if(is_array($tmp) && isset($tmp['dhcpClass'])){
135 $this->generic_settings['enableDHCP'] = TRUE;
136 }
138 if(is_array($tmp) && isset($tmp['dNSZone'])){
139 $this->generic_settings['enableDNS'] = TRUE;
140 }
142 $this->called = TRUE;
143 }
145 /* Update snapshot values, with already collected values */
146 foreach($this->generic_settings as $key => $value){
147 foreach(array("snapshot_base","snapshot_user","snapshot_server") as $attr){
148 foreach($this->parent->captured_values as $replace_name => $replace_value){
149 if(is_string($replace_value)) {
150 $this->generic_settings[$attr] = preg_replace("/%".$replace_name."%/",$replace_value,$this->generic_settings[$attr]);
151 }
152 }
153 }
154 }
156 $smarty = get_smarty();
157 $smarty->assign("sambaDomain_found",$this->sambaDomain_found);
158 $smarty->assign("generic_settings",$this->generic_settings);
159 $smarty->assign("mail_settings",$this->mail_settings);
160 $smarty->assign("mail_methods",$this->mail_methods);
161 $smarty->assign("samba_settings",$this->samba_settings);
162 $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
163 foreach($this->attributes as $attr){
164 $smarty->assign($attr,xmlentities($this->$attr));
165 }
166 $smarty->assign("timezone" ,$this->timezone);
167 $smarty->assign("timezones" ,$this->timezones);
168 return($smarty -> fetch (get_template_path("../setup/setup_config2.tpl")));
169 }
171 function save_object()
172 {
173 if(isset($_POST['step6_posted'])){
175 if(isset($_POST['timezone']) && isset($this->timezones['TIMEZONES'][$_POST['timezone']])){
176 $this->timezone = $_POST['timezone'];
177 }
179 $old_mail = $this->mail;
181 /* Get attributes */
182 foreach($this->attributes as $attr){
183 if(isset($_POST[$attr])){
184 $this->$attr = validate(get_post($attr));
185 }
186 }
188 /* Mail settings */
189 if(isset($_POST['vacationdir_active'])){
190 $this->mail_settings['vacationdir_active'] = TRUE;
191 if(isset($_POST['vacationdir'])){
192 $this->mail_settings['vacationdir'] = get_post('vacationdir');
193 }
194 }else{
195 $this->mail_settings['vacationdir_active'] = FALSE;
196 }
198 if(isset($_POST['enableCopyPaste'])){
199 $this->generic_settings['enableCopyPaste'] = get_post('enableCopyPaste');
200 }
201 if(isset($_POST['enableDNS'])){
202 $this->generic_settings['enableDNS'] = get_post('enableDNS');
203 }
204 if(isset($_POST['enableDHCP'])){
205 $this->generic_settings['enableDHCP'] = get_post('enableDHCP');
206 }
208 if(isset($_POST['wws_ou_active'])){
209 $this->generic_settings['wws_ou_active'] = TRUE;
210 if(isset($_POST['wws_ou'])){
211 $this->generic_settings['wws_ou'] = get_post('wws_ou');
212 }
213 }else{
214 $this->generic_settings['wws_ou_active'] = FALSE;
215 }
217 if(isset($_POST['snapshot_active'])){
218 $this->generic_settings['snapshot_active'] = TRUE;
219 if(isset($_POST['snapshot_base'])){
220 $this->generic_settings['snapshot_base'] = get_post('snapshot_base');
221 }
222 if(isset($_POST['snapshot_user'])){
223 $this->generic_settings['snapshot_user'] = get_post('snapshot_user');
224 }
225 if(isset($_POST['snapshot_password'])){
226 $this->generic_settings['snapshot_password'] = get_post('snapshot_password');
227 }
228 if(isset($_POST['snapshot_server'])){
229 $this->generic_settings['snapshot_server'] = get_post('snapshot_server');
230 }
231 }else{
232 $this->generic_settings['snapshot_active'] = FALSE;
233 }
235 /* Samba settings */
236 if(isset($_POST['samba_sid_active'])){
237 $this->samba_settings['samba_sid_active'] = TRUE;
238 if(isset($_POST['samba_sid'])){
239 $this->samba_settings['samba_sid'] = get_post('samba_sid');
240 }
241 }else{
242 $this->samba_settings['samba_sid_active'] = FALSE;
243 }
244 if(isset($_POST['samba_rid_active'])){
245 $this->samba_settings['samba_rid_active'] = TRUE;
246 if(isset($_POST['samba_rid'])){
247 $this->samba_settings['samba_rid'] = get_post('samba_rid');
248 }
249 }else{
250 $this->samba_settings['samba_rid_active'] = FALSE;
251 }
252 if(isset($_POST['smbhash'])){
253 $this->samba_settings['smbhash'] = get_post('smbhash');
254 }
256 if(!$this->sambaDomain_found){
257 $this->samba_settings['samba_sid_active'] = TRUE;
258 $this->samba_settings['samba_rid_active'] = TRUE;
259 }
261 /* Reload mail naming attribute */
262 if($old_mail != $this->mail && isset($this->mail_methods[$this->mail]['uattrib'])){
263 $this->mail_attrib = $this->mail_methods[$this->mail]['uattrib'];
264 }
265 }
267 $tmp = $this->check();
268 if(count($tmp) == 0){
269 $this->is_completed = TRUE;
270 }else{
271 $this->is_completed = FALSE;
272 }
273 }
276 function check()
277 {
278 $message = array();
279 return($message);
280 }
283 /* Attributes that are interesting for configuration generation */
284 function get_attributes()
285 {
286 $tmp = setup_step::get_attributes();
287 foreach(array("samba_settings","generic_settings","mail_settings") as $attr){
288 $tmp[$attr]= $this->$attr;
289 }
290 return($tmp);
291 }
294 /* Returns the classnames auf the mail classes */
295 function get_available_mail_classes()
296 {
297 global $class_mapping;
299 $default_uattrib = "";
300 $m_class_vars = get_class_vars("mailMethod");
301 if(isset($m_class_vars['uattrib'])){
302 $default_uattrib = $m_class_vars['uattrib'];
303 }
305 foreach($class_mapping as $name => $file){
306 if(preg_match("/^mailMethod[a-z]*$/i",$name)){
307 $name = preg_replace("/^mailMethod/","",$name);
308 if(!empty($name)){
309 $methods[$name]['name'] = $name;
310 $m_class_vars = get_class_vars("mailMethod".$methods[$name]['name']);
311 if(isset($m_class_vars['uattrib'])){
312 $methods[$name]['uattrib'] = $m_class_vars['uattrib'];
313 }else{
314 $methods[$name]['uattrib'] = $default_uattrib;
315 }
316 }
317 }
318 }
319 return($methods);
320 }
321 }
323 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
324 ?>