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);
34 var $mail_attrib = "";
36 var $generic_settings = array(
37 "enableCopyPaste" => false,
38 "enableDNS" => false,
39 "enableDHCP" => false,
40 "wws_ou" => "ou=winstations",
41 "wws_ou_active" => FALSE);
43 var $samba_settings = array( "samba_sid" => "0-815-4711",
44 "samba_sid_active" => FALSE,
45 "samba_rid" => 1000,
46 "smbhash" => 'SMBHASH',
47 "samba_rid_active" => FALSE);
49 var $sambaDomain_found = FALSE;
50 var $use_netatalk = FALSE;
51 var $enableFAI_management = FALSE;
52 var $enableMimeType = FALSE;
54 var $timezone = "Europe/Berlin";
55 var $timezones = array();
57 var $attributes = array("mail_attrib","governmentmode","sambaidmapping","cyrusunixstyle","mail","use_netatalk","enableFAI_management","timezone","enableMimeType");
58 var $called = FALSE;
60 function Step_Config2()
61 {
62 $this->update_strings();
63 $this->mail_methods = $this->get_available_mail_classes();
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->timezones = _get_tz_zones();
75 $this->samba_settings['smbhash'] = $pwdhash;
76 }
79 function update_strings()
80 {
81 $this->s_title = _("GOsa settings 2/3");
82 $this->s_title_long = _("GOsa settings 2/3");
83 $this->s_info = _("Customize special parameters");
84 }
87 function execute()
88 {
89 /* On first call check for rid/sid base */
90 $cv = $this->parent->captured_values;
91 $ldap = new LDAP($cv['admin'],
92 $cv['password'],
93 $cv['connection'],
94 FALSE,
95 $cv['tls']);
97 $ldap->cd($cv['base']);
98 $ldap->search("(objectClass=sambaDomain)",array("dn"));
99 if($ldap->count()){
100 $this->sambaDomain_found =TRUE;
101 }else{
102 $this->sambaDomain_found =FALSE;
103 }
105 if(!$this->called){
106 if(!$this->sambaDomain_found){
107 $this->samba_settings['samba_sid_active'] = TRUE;
108 $this->samba_settings['samba_rid_active'] = TRUE;
109 }
111 /* Check if we can enable netatalk plugin */
112 $tmp = $ldap->get_objectclasses();
113 if(is_array($tmp) && isset($tmp['apple-user'])) {
114 $this->use_netatalk = TRUE;
115 }
117 /* Check the FAI schema is used */
118 if(is_array($tmp) && isset($tmp['FAIclass'])){
119 # $this->enableFAI_management = TRUE;
120 }
122 /* Check the MimeType schema is used */
123 if(is_array($tmp) && isset($tmp['gotoMimeType'])){
124 $this->enableMimeType = TRUE;
125 }
127 if(is_array($tmp) && isset($tmp['dhcpClass'])){
128 $this->generic_settings['enableDHCP'] = TRUE;
129 }
131 if(is_array($tmp) && isset($tmp['dNSZone'])){
132 $this->generic_settings['enableDNS'] = TRUE;
133 }
135 $this->called = TRUE;
136 }
138 $smarty = get_smarty();
139 $smarty->assign("sambaDomain_found",$this->sambaDomain_found);
140 $smarty->assign("generic_settings",$this->generic_settings);
141 $smarty->assign("mail_settings",$this->mail_settings);
142 $smarty->assign("mail_methods",$this->mail_methods);
143 $smarty->assign("samba_settings",$this->samba_settings);
144 $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
145 foreach($this->attributes as $attr){
146 $smarty->assign($attr,$this->$attr);
147 }
148 $smarty->assign("timezone" ,$this->timezone);
149 $smarty->assign("timezones" ,$this->timezones);
150 return($smarty -> fetch (get_template_path("../setup/setup_config2.tpl")));
151 }
153 function save_object()
154 {
155 if(isset($_POST['step6_posted'])){
157 if(isset($_POST['timezone']) && isset($this->timezones['TIMEZONES'][$_POST['timezone']])){
158 $this->timezone = $_POST['timezone'];
159 }
161 $old_mail = $this->mail;
163 /* Get attributes */
164 foreach($this->attributes as $attr){
165 if(isset($_POST[$attr])){
166 $this->$attr = validate(get_post($attr));
167 }
168 }
170 /* Mail settings */
171 if(isset($_POST['vacationdir_active'])){
172 $this->mail_settings['vacationdir_active'] = TRUE;
173 if(isset($_POST['vacationdir'])){
174 $this->mail_settings['vacationdir'] = get_post('vacationdir');
175 }
176 }else{
177 $this->mail_settings['vacationdir_active'] = FALSE;
178 }
180 if(isset($_POST['enableCopyPaste'])){
181 $this->generic_settings['enableCopyPaste'] = get_post('enableCopyPaste');
182 }
183 if(isset($_POST['enableDNS'])){
184 $this->generic_settings['enableDNS'] = get_post('enableDNS');
185 }
186 if(isset($_POST['enableDHCP'])){
187 $this->generic_settings['enableDHCP'] = get_post('enableDHCP');
188 }
190 if(isset($_POST['wws_ou_active'])){
191 $this->generic_settings['wws_ou_active'] = TRUE;
192 if(isset($_POST['wws_ou'])){
193 $this->generic_settings['wws_ou'] = get_post('wws_ou');
194 }
195 }else{
196 $this->generic_settings['wws_ou_active'] = FALSE;
197 }
199 /* Samba settings */
200 if(isset($_POST['samba_sid_active'])){
201 $this->samba_settings['samba_sid_active'] = TRUE;
202 if(isset($_POST['samba_sid'])){
203 $this->samba_settings['samba_sid'] = get_post('samba_sid');
204 }
205 }else{
206 $this->samba_settings['samba_sid_active'] = FALSE;
207 }
208 if(isset($_POST['samba_rid_active'])){
209 $this->samba_settings['samba_rid_active'] = TRUE;
210 if(isset($_POST['samba_rid'])){
211 $this->samba_settings['samba_rid'] = get_post('samba_rid');
212 }
213 }else{
214 $this->samba_settings['samba_rid_active'] = FALSE;
215 }
216 if(isset($_POST['smbhash'])){
217 $this->samba_settings['smbhash'] = get_post('smbhash');
218 }
220 if(!$this->sambaDomain_found){
221 $this->samba_settings['samba_sid_active'] = TRUE;
222 $this->samba_settings['samba_rid_active'] = TRUE;
223 }
224 }
226 $tmp = $this->check();
227 if(count($tmp) == 0){
228 $this->is_completed = TRUE;
229 }else{
230 $this->is_completed = FALSE;
231 }
233 /* Reload mail naming attribute */
234 if($old_mail != $this->mail && isset($this->mail_methods[$this->mail]['uattrib'])){
235 $this->mail_attrib = $this->mail_methods[$this->mail]['uattrib'];
236 }
237 }
240 function check()
241 {
242 $message = array();
243 return($message);
244 }
247 /* Attributes that are interesting for configuration generation */
248 function get_attributes()
249 {
250 $tmp = setup_step::get_attributes();
251 foreach(array("samba_settings","generic_settings","mail_settings") as $attr){
252 $tmp[$attr]= $this->$attr;
253 }
254 return($tmp);
255 }
257 /* Returns the classnames auf the mail classes */
258 function get_available_mail_classes()
259 {
260 $dir = opendir( "../include");
261 $methods = array();
262 $suffix = "class_mail-methods-";
263 $lensuf = strlen($suffix);
264 $prefix = ".inc";
265 $lenpre = strlen($prefix);
267 $default_uattrib = "";
268 $m_class_vars = get_class_vars("mailMethod");
269 if(isset($m_class_vars['uattrib'])){
270 $default_uattrib = $m_class_vars['uattrib'];
271 }
273 while (($file = readdir($dir)) !== false){
274 if(stristr($file,$suffix)) {
276 require_once($file);
277 $lenfile = strlen($file);
278 $name = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
279 $methods[$name]['file'] = $file;
280 $methods[$name]['name'] = $name;
282 $m_class_vars = get_class_vars("mailMethod".$methods[$name]['name']);
283 if(isset($m_class_vars['uattrib'])){
284 $methods[$name]['uattrib'] = $m_class_vars['uattrib'];
285 }else{
286 $methods[$name]['uattrib'] = $default_uattrib;
287 }
288 }
289 }
290 return($methods);
291 }
293 }
295 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
296 ?>