Code

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