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);
39 var $samba_settings = array( "samba_sid" => "0-815-4711",
40 "samba_sid_active" => FALSE,
41 "samba_rid" => 1000,
42 "smbhash" => 'SMBHASH',
43 "samba_rid_active" => FALSE);
45 var $sambaDomain_found = FALSE;
46 var $use_netatalk = FALSE;
47 var $enableFAI_management = FALSE;
49 var $timezone = "Europe/Berlin";
50 var $timezones = array();
52 var $attributes = array("governmentmode","sambaidmapping","cyrusunixstyle","mail","use_netatalk","enableFAI_management","timezone");
53 var $called = FALSE;
55 function Step_Config2()
56 {
57 $this->update_strings();
58 $tmp = $this->get_available_mail_classes();
59 foreach($tmp['name'] as $name){
60 $this->mail_methods[$name] = $name;
61 }
63 /* Look for samba password generation method */
64 if(file_exists("/usr/bin/mkntpasswd")){
65 $pwdhash = "/usr/bin/mkntpasswd";
66 } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
67 $pwdhash= "mkntpwd";
68 } else {
69 $pwdhash= 'perl -MCrypt::SmbHash -e "print join(q[:], ntlmgen \$ARGV[0]), $/;"';
70 }
72 $this->timezones = _get_tz_zones();
73 $this->samba_settings['smbhash'] = $pwdhash;
74 }
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 }
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 }
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 }
115 /* Check the FAI schema is used */
116 if(is_array($tmp) && isset($tmp['FAIclass'])){
117 # $this->enableFAI_management = TRUE;
118 }
120 $this->called = TRUE;
121 }
123 $smarty = get_smarty();
124 $smarty->assign("sambaDomain_found",$this->sambaDomain_found);
125 $smarty->assign("generic_settings",$this->generic_settings);
126 $smarty->assign("mail_settings",$this->mail_settings);
127 $smarty->assign("mail_methods",$this->mail_methods);
128 $smarty->assign("samba_settings",$this->samba_settings);
129 $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
130 foreach($this->attributes as $attr){
131 $smarty->assign($attr,$this->$attr);
132 }
133 $smarty->assign("timezone" ,$this->timezone);
134 $smarty->assign("timezones" ,$this->timezones);
135 return($smarty -> fetch (get_template_path("../setup/setup_config2.tpl")));
136 }
138 function save_object()
139 {
140 if(isset($_POST['step6_posted'])){
142 if(isset($_POST['timezone']) && isset($this->timezones['TIMEZONES'][$_POST['timezone']])){
143 $this->timezone = $_POST['timezone'];
144 }
146 /* Get attributes */
147 foreach($this->attributes as $attr){
148 if(isset($_POST[$attr])){
149 $this->$attr = validate(get_post($attr));
150 }
151 }
153 /* Mail settings */
154 if(isset($_POST['vacationdir_active'])){
155 $this->mail_settings['vacationdir_active'] = TRUE;
156 if(isset($_POST['vacationdir'])){
157 $this->mail_settings['vacationdir'] = get_post('vacationdir');
158 }
159 }else{
160 $this->mail_settings['vacationdir_active'] = FALSE;
161 }
163 if(isset($_POST['enableCopyPaste'])){
164 $this->generic_settings['enableCopyPaste'] = get_post('enableCopyPaste');
165 }
167 if(isset($_POST['wws_ou_active'])){
168 $this->generic_settings['wws_ou_active'] = TRUE;
169 if(isset($_POST['wws_ou'])){
170 $this->generic_settings['wws_ou'] = get_post('wws_ou');
171 }
172 }else{
173 $this->generic_settings['wws_ou_active'] = FALSE;
174 }
176 /* Samba settings */
177 if(isset($_POST['samba_sid_active'])){
178 $this->samba_settings['samba_sid_active'] = TRUE;
179 if(isset($_POST['samba_sid'])){
180 $this->samba_settings['samba_sid'] = get_post('samba_sid');
181 }
182 }else{
183 $this->samba_settings['samba_sid_active'] = FALSE;
184 }
185 if(isset($_POST['samba_rid_active'])){
186 $this->samba_settings['samba_rid_active'] = TRUE;
187 if(isset($_POST['samba_rid'])){
188 $this->samba_settings['samba_rid'] = get_post('samba_rid');
189 }
190 }else{
191 $this->samba_settings['samba_rid_active'] = FALSE;
192 }
193 if(isset($_POST['smbhash'])){
194 $this->samba_settings['smbhash'] = get_post('smbhash');
195 }
197 if(!$this->sambaDomain_found){
198 $this->samba_settings['samba_sid_active'] = TRUE;
199 $this->samba_settings['samba_rid_active'] = TRUE;
200 }
201 }
203 $tmp = $this->check();
204 if(count($tmp) == 0){
205 $this->is_completed = TRUE;
206 }else{
207 $this->is_completed = FALSE;
208 }
209 }
212 function check()
213 {
214 $message = array();
215 return($message);
216 }
219 /* Attributes that are interesting for configuration generation */
220 function get_attributes()
221 {
222 $tmp = setup_step::get_attributes();
223 foreach(array("samba_settings","generic_settings","mail_settings") as $attr){
224 $tmp[$attr]= $this->$attr;
225 }
226 return($tmp);
227 }
229 /* Returns the classnames auf the mail classes */
230 function get_available_mail_classes()
231 {
232 $dir = opendir( "../include");
233 $methods = array();
234 $suffix = "class_mail-methods-";
235 $lensuf = strlen($suffix);
236 $prefix = ".inc";
237 $lenpre = strlen($prefix);
238 $i = 0;
239 while (($file = readdir($dir)) !== false){
241 if(stristr($file,$suffix)) {
242 $lenfile = strlen($file);
243 $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
244 $methods['file'][$i] = $file;
245 $methods[$i]['file'] = $file;
246 $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
247 $i++;
248 }
249 }
250 return($methods);
251 }
253 }
255 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
256 ?>