Code

6dca19771618fe0b7a997b4bf08f480f6a0ab27b
[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                                   "wws_ou"        => "ou=winstations",
37                                   "wws_ou_active" => FALSE,
38                                   "snapshot_active"     => FALSE,
39                                   "snapshot_base"       => "ou=snapshots,%base%",
40                                   "snapshot_user"       => "%admin%",
41                                   "snapshot_password"   => "",
42                                   "snapshot_server"     => "%connection%");
44   var $samba_settings    = array( "samba_sid"        => "0-815-4711",
45                                   "samba_sid_active" => FALSE,
46                                   "samba_rid"        => 1000,
47                                   "smbhash"          => 'SMBHASH',
48                                   "samba_rid_active" => FALSE); 
50   var $sambaDomain_found = FALSE;
51   var $use_netatalk = FALSE;
53   var $attributes = array("governmentmode","sambaidmapping","cyrusunixstyle","mail","use_netatalk");
54   var $called = FALSE;
56   function Step_Config2()
57   {
58     $this->update_strings();
59     $tmp = $this->get_available_mail_classes();
60     foreach($tmp['name'] as $name){
61       $this->mail_methods[$name] = $name;
62     }
64     /* Look for samba password generation method */
65     if(file_exists("/usr/bin/mkntpasswd")){
66       $pwdhash  = "/usr/bin/mkntpasswd";
67     } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
68       $pwdhash= "mkntpwd";
69     } else {
70       $pwdhash= 'perl -MCrypt::SmbHash -e "print join(q[:], ntlmgen \$ARGV[0]), $/;"';
71     }
73     $this->samba_settings['smbhash'] = $pwdhash;
74   }
76  
77   function update_strings()
78   {
79     $this->s_title      = _("GOsa settings 2/3");
80     $this->s_title_long = _("GOsa settings 2/3");
81     $this->s_info       = _("Customize special parameters");
82   }
84  
85   function execute()
86   {
87     /* On first call check for rid/sid base */
88     $cv = $this->parent->captured_values;
89     $ldap = new LDAP($cv['admin'],
90         $cv['password'],
91         $cv['connection'],
92         FALSE,
93         $cv['tls']);
95     $ldap->cd($cv['base']);
96     $ldap->search("(objectClass=sambaDomain)",array("dn"));
97     if($ldap->count()){
98       $this->sambaDomain_found =TRUE;
99     }else{
100       $this->sambaDomain_found =FALSE;
101     }
103     if(!$this->called){
104       if(!$this->sambaDomain_found){
105         $this->samba_settings['samba_sid_active'] = TRUE;
106         $this->samba_settings['samba_rid_active'] = TRUE;
107       }
108   
109       /* Check if we can enable netatalk plugin */
110       $tmp = $ldap->get_objectclasses();
111       if(is_array($tmp) && isset($tmp['apple-user'])) {
112         $this->use_netatalk = TRUE;
113       }
114       $this->called = TRUE;
115     }
117     /* Update snapshot values, with already collected values */
118     foreach($this->generic_settings as $key => $value){
119       foreach(array("snapshot_base","snapshot_user","snapshot_server") as $attr){
120         foreach($this->parent->captured_values as $replace_name => $replace_value){
121           if(is_string($replace_value))  {
122             $this->generic_settings[$attr] = preg_replace("/%".$replace_name."%/",$replace_value,$this->generic_settings[$attr]);
123           }
124         }
125       }
126     }
128     $smarty = get_smarty();
129     $smarty->assign("sambaDomain_found",$this->sambaDomain_found);
130     $smarty->assign("generic_settings",$this->generic_settings);
131     $smarty->assign("mail_settings",$this->mail_settings);
132     $smarty->assign("mail_methods",$this->mail_methods);
133     $smarty->assign("samba_settings",$this->samba_settings);
134     $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
135         foreach($this->attributes as $attr){
136       $smarty->assign($attr,$this->$attr);
137     }
138     return($smarty -> fetch (get_template_path("../setup/setup_config2.tpl")));
139   }
141   function save_object()
142   {
143     if(isset($_POST['step6_posted'])){
145       /* Get attributes */
146       foreach($this->attributes as $attr){
147         if(isset($_POST[$attr])){
148           $this->$attr = validate(get_post($attr));
149         }
150       }
152       /* Mail settings */
153       if(isset($_POST['vacationdir_active'])){
154         $this->mail_settings['vacationdir_active'] = TRUE;
155         if(isset($_POST['vacationdir'])){
156           $this->mail_settings['vacationdir'] = get_post('vacationdir');
157         }
158       }else{
159         $this->mail_settings['vacationdir_active'] = FALSE;
160       }
162       if(isset($_POST['enableCopyPaste'])){
163         $this->generic_settings['enableCopyPaste'] = get_post('enableCopyPaste');
164       }
166       if(isset($_POST['wws_ou_active'])){
167         $this->generic_settings['wws_ou_active'] = TRUE;
168         if(isset($_POST['wws_ou'])){
169           $this->generic_settings['wws_ou'] = get_post('wws_ou');
170         }
171       }else{
172         $this->generic_settings['wws_ou_active'] = FALSE;
173       }
175       if(isset($_POST['snapshot_active'])){
176         $this->generic_settings['snapshot_active'] = TRUE;
177         if(isset($_POST['snapshot_base'])){
178           $this->generic_settings['snapshot_base'] = get_post('snapshot_base');
179         }
180         if(isset($_POST['snapshot_user'])){
181           $this->generic_settings['snapshot_user'] = get_post('snapshot_user');
182         }
183         if(isset($_POST['snapshot_password'])){
184           $this->generic_settings['snapshot_password'] = get_post('snapshot_password');
185         }
186         if(isset($_POST['snapshot_server'])){
187           $this->generic_settings['snapshot_server'] = get_post('snapshot_server');
188         }
189       }else{
190         $this->generic_settings['snapshot_active'] = FALSE;
191       }
193       /* Samba settings */
194       if(isset($_POST['samba_sid_active'])){
195         $this->samba_settings['samba_sid_active'] = TRUE;
196         if(isset($_POST['samba_sid'])){
197           $this->samba_settings['samba_sid'] = get_post('samba_sid');
198         }
199       }else{
200         $this->samba_settings['samba_sid_active'] = FALSE;
201       }
202       if(isset($_POST['samba_rid_active'])){
203         $this->samba_settings['samba_rid_active'] = TRUE;
204         if(isset($_POST['samba_rid'])){
205           $this->samba_settings['samba_rid'] = get_post('samba_rid');
206         }
207       }else{
208         $this->samba_settings['samba_rid_active'] = FALSE;
209       }
210       if(isset($_POST['smbhash'])){
211         $this->samba_settings['smbhash'] = get_post('smbhash');
212       }
214       if(!$this->sambaDomain_found){
215         $this->samba_settings['samba_sid_active'] = TRUE;
216         $this->samba_settings['samba_rid_active'] = TRUE;
217       }
218     }
220     $tmp = $this->check();
221     if(count($tmp) == 0){
222       $this->is_completed = TRUE;
223     }else{
224       $this->is_completed = FALSE;
225     }
226   }
229   function check()
230   {
231     $message = array();
232     return($message);
233   }
234   
236   /* Attributes that are interesting for configuration generation */
237   function get_attributes()
238   {
239     $tmp = setup_step::get_attributes();
240     foreach(array("samba_settings","generic_settings","mail_settings") as $attr){
241       $tmp[$attr]= $this->$attr;
242     }
243     return($tmp);
244   }
246 /* Returns the classnames auf the mail classes */
247   function get_available_mail_classes()
248   {
249     $dir = opendir( "../include");
250     $methods = array();
251     $suffix = "class_mail-methods-";
252     $lensuf = strlen($suffix);
253     $prefix = ".inc";
254     $lenpre = strlen($prefix);
255     $i = 0;
256     while (($file = readdir($dir)) !== false){
258       if(stristr($file,$suffix)) {
259         $lenfile = strlen($file);
260         $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
261         $methods['file'][$i] = $file;
262         $methods[$i]['file'] = $file;
263         $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
264         $i++;
265       }
266     }
267     return($methods);
268   }
272 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
273 ?>