Code

Completed generic tab for dojo testing
[gosa.git] / setup / class_setupStep_Config2.inc
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_methods   = array();
32   var $mail_settings = array("vacationdir"        => "/etc/gosa/vacation",
33                              "vacationdir_active" => FALSE);
35   var $generic_settings  = array( "enableCopyPaste" => false,
36                                   "enableDNS"      => false,
37                                   "enableDHCP"      => false,
38                                   "wws_ou"        => "ou=winstations",
39                                   "wws_ou_active" => FALSE,
40                                   "snapshot_active"     => FALSE,
41                                   "snapshot_base"       => "ou=snapshots,%base%",
42                                   "snapshot_user"       => "%admin%",
43                                   "snapshot_password"   => "",
44                                   "snapshot_server"     => "%connection%");
46   var $samba_settings    = array( "samba_sid"        => "0-815-4711",
47                                   "samba_sid_active" => FALSE,
48                                   "samba_rid"        => 1000,
49                                   "smbhash"          => 'SMBHASH',
50                                   "samba_rid_active" => FALSE); 
52   var $sambaDomain_found    = FALSE;
53   var $use_netatalk         = FALSE;
54   var $enableFAI_management = FALSE;
55   var $enableMimeType       = FALSE;
57   var $timezone       = "Europe/Berlin";
58   var $timezones      = array();
60   var $attributes = array("governmentmode","sambaidmapping","cyrusunixstyle","mail","use_netatalk","enableFAI_management","timezone","enableMimeType");
61   var $called = FALSE;
63   function Step_Config2()
64   {
65     $this->update_strings();
66     $tmp = $this->get_available_mail_classes();
67     foreach($tmp['name'] as $name){
68       $this->mail_methods[$name] = $name;
69     }
71     /* Look for samba password generation method */
72     if(file_exists("/usr/bin/mkntpasswd")){
73       $pwdhash  = "/usr/bin/mkntpasswd";
74     } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
75       $pwdhash= "mkntpwd";
76     } else {
77       $pwdhash= 'perl -MCrypt::SmbHash -e "print join(q[:], ntlmgen \$ARGV[0]), $/;"';
78     }
80     $this->timezones = _get_tz_zones();
81     $this->samba_settings['smbhash'] = $pwdhash;
82   }
84  
85   function update_strings()
86   {
87     $this->s_title      = _("GOsa settings 2/3");
88     $this->s_title_long = _("GOsa settings 2/3");
89     $this->s_info       = _("Customize special parameters");
90   }
92  
93   function execute()
94   {
95     /* On first call check for rid/sid base */
96     $cv = $this->parent->captured_values;
97     $ldap = new LDAP($cv['admin'],
98         $cv['password'],
99         $cv['connection'],
100         FALSE,
101         $cv['tls']);
103     $ldap->cd($cv['base']);
104     $ldap->search("(objectClass=sambaDomain)",array("dn"));
105     if($ldap->count()){
106       $this->sambaDomain_found =TRUE;
107     }else{
108       $this->sambaDomain_found =FALSE;
109     }
111     if(!$this->called){
112       if(!$this->sambaDomain_found){
113         $this->samba_settings['samba_sid_active'] = TRUE;
114         $this->samba_settings['samba_rid_active'] = TRUE;
115       }
116   
117       /* Check if we can enable netatalk plugin */
118       $tmp = $ldap->get_objectclasses();
119       if(is_array($tmp) && isset($tmp['apple-user'])) {
120         $this->use_netatalk = TRUE;
121       }
123       /* Check the FAI schema is used */
124       if(is_array($tmp) && isset($tmp['FAIclass'])){
125 #        $this->enableFAI_management = TRUE;
126       }
128       /* Check the MimeType schema is used */
129       if(is_array($tmp) && isset($tmp['gotoMimeType'])){
130         $this->enableMimeType = TRUE;
131       }
133       if(is_array($tmp) && isset($tmp['dhcpClass'])){
134         $this->generic_settings['enableDHCP'] = TRUE;
135       }
137       if(is_array($tmp) && isset($tmp['dNSZone'])){
138         $this->generic_settings['enableDNS'] = TRUE;
139       }
141       $this->called = TRUE;
142     }
144     /* Update snapshot values, with already collected values */
145     foreach($this->generic_settings as $key => $value){
146       foreach(array("snapshot_base","snapshot_user","snapshot_server") as $attr){
147         foreach($this->parent->captured_values as $replace_name => $replace_value){
148           if(is_string($replace_value))  {
149             $this->generic_settings[$attr] = preg_replace("/%".$replace_name."%/",$replace_value,$this->generic_settings[$attr]);
150           }
151         }
152       }
153     }
155     $smarty = get_smarty();
156     $smarty->assign("sambaDomain_found",$this->sambaDomain_found);
157     $smarty->assign("generic_settings",$this->generic_settings);
158     $smarty->assign("mail_settings",$this->mail_settings);
159     $smarty->assign("mail_methods",$this->mail_methods);
160     $smarty->assign("samba_settings",$this->samba_settings);
161     $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
162         foreach($this->attributes as $attr){
163       $smarty->assign($attr,$this->$attr);
164     }
165     $smarty->assign("timezone"     ,$this->timezone);
166     $smarty->assign("timezones"    ,$this->timezones);
167     return($smarty -> fetch (get_template_path("../setup/setup_config2.tpl")));
168   }
170   function save_object()
171   {
172     if(isset($_POST['step6_posted'])){
174       if(isset($_POST['timezone']) && isset($this->timezones['TIMEZONES'][$_POST['timezone']])){
175         $this->timezone = $_POST['timezone'];
176       }
178       /* Get attributes */
179       foreach($this->attributes as $attr){
180         if(isset($_POST[$attr])){
181           $this->$attr = validate(get_post($attr));
182         }
183       }
185       /* Mail settings */
186       if(isset($_POST['vacationdir_active'])){
187         $this->mail_settings['vacationdir_active'] = TRUE;
188         if(isset($_POST['vacationdir'])){
189           $this->mail_settings['vacationdir'] = get_post('vacationdir');
190         }
191       }else{
192         $this->mail_settings['vacationdir_active'] = FALSE;
193       }
195       if(isset($_POST['enableCopyPaste'])){
196         $this->generic_settings['enableCopyPaste'] = get_post('enableCopyPaste');
197       }
198       if(isset($_POST['enableDNS'])){
199         $this->generic_settings['enableDNS'] = get_post('enableDNS');
200       }
201       if(isset($_POST['enableDHCP'])){
202         $this->generic_settings['enableDHCP'] = get_post('enableDHCP');
203       }
205       if(isset($_POST['wws_ou_active'])){
206         $this->generic_settings['wws_ou_active'] = TRUE;
207         if(isset($_POST['wws_ou'])){
208           $this->generic_settings['wws_ou'] = get_post('wws_ou');
209         }
210       }else{
211         $this->generic_settings['wws_ou_active'] = FALSE;
212       }
214       if(isset($_POST['snapshot_active'])){
215         $this->generic_settings['snapshot_active'] = TRUE;
216         if(isset($_POST['snapshot_base'])){
217           $this->generic_settings['snapshot_base'] = get_post('snapshot_base');
218         }
219         if(isset($_POST['snapshot_user'])){
220           $this->generic_settings['snapshot_user'] = get_post('snapshot_user');
221         }
222         if(isset($_POST['snapshot_password'])){
223           $this->generic_settings['snapshot_password'] = get_post('snapshot_password');
224         }
225         if(isset($_POST['snapshot_server'])){
226           $this->generic_settings['snapshot_server'] = get_post('snapshot_server');
227         }
228       }else{
229         $this->generic_settings['snapshot_active'] = FALSE;
230       }
232       /* Samba settings */
233       if(isset($_POST['samba_sid_active'])){
234         $this->samba_settings['samba_sid_active'] = TRUE;
235         if(isset($_POST['samba_sid'])){
236           $this->samba_settings['samba_sid'] = get_post('samba_sid');
237         }
238       }else{
239         $this->samba_settings['samba_sid_active'] = FALSE;
240       }
241       if(isset($_POST['samba_rid_active'])){
242         $this->samba_settings['samba_rid_active'] = TRUE;
243         if(isset($_POST['samba_rid'])){
244           $this->samba_settings['samba_rid'] = get_post('samba_rid');
245         }
246       }else{
247         $this->samba_settings['samba_rid_active'] = FALSE;
248       }
249       if(isset($_POST['smbhash'])){
250         $this->samba_settings['smbhash'] = get_post('smbhash');
251       }
253       if(!$this->sambaDomain_found){
254         $this->samba_settings['samba_sid_active'] = TRUE;
255         $this->samba_settings['samba_rid_active'] = TRUE;
256       }
257     }
259     $tmp = $this->check();
260     if(count($tmp) == 0){
261       $this->is_completed = TRUE;
262     }else{
263       $this->is_completed = FALSE;
264     }
265   }
268   function check()
269   {
270     $message = array();
271     return($message);
272   }
273   
275   /* Attributes that are interesting for configuration generation */
276   function get_attributes()
277   {
278     $tmp = setup_step::get_attributes();
279     foreach(array("samba_settings","generic_settings","mail_settings") as $attr){
280       $tmp[$attr]= $this->$attr;
281     }
282     return($tmp);
283   }
285 /* Returns the classnames auf the mail classes */
286   function get_available_mail_classes()
287   {
288     $dir = opendir( "../include");
289     $methods = array();
290     $suffix = "class_mail-methods-";
291     $lensuf = strlen($suffix);
292     $prefix = ".inc";
293     $lenpre = strlen($prefix);
294     $i = 0;
295     while (($file = readdir($dir)) !== false){
297       if(stristr($file,$suffix)) {
298         $lenfile = strlen($file);
299         $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
300         $methods['file'][$i] = $file;
301         $methods[$i]['file'] = $file;
302         $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
303         $i++;
304       }
305     }
306     return($methods);
307   }
311 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
312 ?>