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_attrib = "";
32 var $mail_methods = array();
33 var $mail_settings = array("vacationdir" => "/etc/gosa/vacation",
34 "vacationdir_active" => FALSE);
36 var $generic_settings = array( "enableCopyPaste" => false,
37 "enableDNS" => false,
38 "enableDHCP" => false,
39 "wws_ou" => "ou=winstations",
40 "wws_ou_active" => FALSE,
41 "snapshot_active" => FALSE,
42 "snapshot_base" => "ou=snapshots,%base%",
43 "snapshot_user" => "%admin%",
44 "snapshot_password" => "",
45 "logging" => "syslog,mysql",
46 "snapshot_server" => "%connection%");
48 var $samba_settings = array( "samba_sid" => "0-815-4711",
49 "samba_sid_active" => FALSE,
50 "samba_rid" => 1000,
51 "smbhash" => 'SMBHASH',
52 "samba_rid_active" => FALSE);
54 var $sambaDomain_found = FALSE;
55 var $use_netatalk = FALSE;
56 var $enableFAI_management = FALSE;
57 var $enableMimeType = FALSE;
59 var $timezone = "Europe/Berlin";
60 var $timezones = array();
62 var $attributes = array("mail_attrib","governmentmode","sambaidmapping","cyrusunixstyle","mail","use_netatalk","enableFAI_management","timezone","enableMimeType");
63 var $called = FALSE;
65 function Step_Config2()
66 {
67 $this->update_strings();
68 $this->mail_methods = $this->get_available_mail_classes();
70 /* Look for samba password generation method */
71 if(file_exists("/usr/bin/mkntpasswd")){
72 $pwdhash = "/usr/bin/mkntpasswd";
73 } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
74 $pwdhash= "mkntpwd";
75 } else {
76 $pwdhash= 'perl -MCrypt::SmbHash -e "print join(q[:], ntlmgen \$ARGV[0]), $/;"';
77 }
79 $this->timezones = timezone::_get_tz_zones();
80 $this->samba_settings['smbhash'] = $pwdhash;
81 }
84 function update_strings()
85 {
86 $this->s_title = _("GOsa settings 2/3");
87 $this->s_title_long = _("GOsa settings 2/3");
88 $this->s_info = _("Customize special parameters");
89 }
92 function execute()
93 {
94 $this->mail_methods = $this->get_available_mail_classes();
95 /* On first call check for rid/sid base */
96 $cv = $this->parent->captured_values;
97 $ldap_l = new LDAP($cv['admin'],
98 $cv['password'],
99 $cv['connection'],
100 FALSE,
101 $cv['tls']);
103 $ldap = new ldapMultiplexer($ldap_l);
105 $ldap->cd($cv['base']);
106 $ldap->search("(objectClass=sambaDomain)",array("dn"));
107 if($ldap->count()){
108 $this->sambaDomain_found =TRUE;
109 }else{
110 $this->sambaDomain_found =FALSE;
111 }
113 if(!$this->called){
114 if(!$this->sambaDomain_found){
115 $this->samba_settings['samba_sid_active'] = TRUE;
116 $this->samba_settings['samba_rid_active'] = TRUE;
117 }
119 /* Check if we can enable netatalk plugin */
120 $tmp = $ldap->get_objectclasses();
121 if(is_array($tmp) && isset($tmp['apple-user'])) {
122 $this->use_netatalk = TRUE;
123 }
125 /* Check the FAI schema is used */
126 if(is_array($tmp) && isset($tmp['FAIclass'])){
127 # $this->enableFAI_management = TRUE;
128 }
130 /* Check the MimeType schema is used */
131 if(is_array($tmp) && isset($tmp['gotoMimeType'])){
132 $this->enableMimeType = TRUE;
133 }
135 if(is_array($tmp) && isset($tmp['dhcpClass'])){
136 $this->generic_settings['enableDHCP'] = TRUE;
137 }
139 if(is_array($tmp) && isset($tmp['dNSZone'])){
140 $this->generic_settings['enableDNS'] = TRUE;
141 }
143 $this->called = TRUE;
144 }
146 /* Update snapshot values, with already collected values */
147 foreach($this->generic_settings as $key => $value){
148 foreach(array("snapshot_base","snapshot_user","snapshot_server") as $attr){
149 foreach($this->parent->captured_values as $replace_name => $replace_value){
150 if(is_string($replace_value)) {
151 $this->generic_settings[$attr] = preg_replace("/%".$replace_name."%/",$replace_value,$this->generic_settings[$attr]);
152 }
153 }
154 }
155 }
157 $smarty = get_smarty();
158 $smarty->assign("sambaDomain_found",$this->sambaDomain_found);
159 $smarty->assign("generic_settings",$this->generic_settings);
160 $smarty->assign("mail_settings",$this->mail_settings);
161 $smarty->assign("mail_methods",$this->mail_methods);
162 $smarty->assign("samba_settings",$this->samba_settings);
164 $smarty->assign("logging_mysql" ,preg_match("/mysql/",$this->generic_settings['logging']));
165 $smarty->assign("logging_syslog",preg_match("/syslog/",$this->generic_settings['logging']));
167 $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
168 foreach($this->attributes as $attr){
169 $smarty->assign($attr,$this->$attr);
170 }
171 $smarty->assign("timezone" ,$this->timezone);
172 $smarty->assign("timezones" ,$this->timezones);
173 return($smarty -> fetch (get_template_path("../setup/setup_config2.tpl")));
174 }
176 function save_object()
177 {
178 if(isset($_POST['step6_posted'])){
180 if(isset($_POST['timezone']) && isset($this->timezones['TIMEZONES'][$_POST['timezone']])){
181 $this->timezone = $_POST['timezone'];
182 }
184 $old_mail = $this->mail;
186 /* Get attributes */
187 foreach($this->attributes as $attr){
188 if(isset($_POST[$attr])){
189 $this->$attr = validate(get_post($attr));
190 }
191 }
193 /* Get logging */
194 $logging = "";
195 if(isset($_POST['logging_syslog'])){
196 $logging.= "syslog,";
197 }
198 if(isset($_POST['logging_mysql'])){
199 $logging.= "mysql,";
200 }
201 $this->generic_settings['logging'] = trim($logging,",");
203 /* Mail settings */
204 if(isset($_POST['vacationdir_active'])){
205 $this->mail_settings['vacationdir_active'] = TRUE;
206 if(isset($_POST['vacationdir'])){
207 $this->mail_settings['vacationdir'] = get_post('vacationdir');
208 }
209 }else{
210 $this->mail_settings['vacationdir_active'] = FALSE;
211 }
213 if(isset($_POST['enableCopyPaste'])){
214 $this->generic_settings['enableCopyPaste'] = get_post('enableCopyPaste');
215 }
216 if(isset($_POST['enableDNS'])){
217 $this->generic_settings['enableDNS'] = get_post('enableDNS');
218 }
219 if(isset($_POST['enableDHCP'])){
220 $this->generic_settings['enableDHCP'] = get_post('enableDHCP');
221 }
223 if(isset($_POST['wws_ou_active'])){
224 $this->generic_settings['wws_ou_active'] = TRUE;
225 if(isset($_POST['wws_ou'])){
226 $this->generic_settings['wws_ou'] = get_post('wws_ou');
227 }
228 }else{
229 $this->generic_settings['wws_ou_active'] = FALSE;
230 }
232 if(isset($_POST['snapshot_active'])){
233 $this->generic_settings['snapshot_active'] = TRUE;
234 if(isset($_POST['snapshot_base'])){
235 $this->generic_settings['snapshot_base'] = get_post('snapshot_base');
236 }
237 if(isset($_POST['snapshot_user'])){
238 $this->generic_settings['snapshot_user'] = get_post('snapshot_user');
239 }
240 if(isset($_POST['snapshot_password'])){
241 $this->generic_settings['snapshot_password'] = get_post('snapshot_password');
242 }
243 if(isset($_POST['snapshot_server'])){
244 $this->generic_settings['snapshot_server'] = get_post('snapshot_server');
245 }
246 }else{
247 $this->generic_settings['snapshot_active'] = FALSE;
248 }
250 /* Samba settings */
251 if(isset($_POST['samba_sid_active'])){
252 $this->samba_settings['samba_sid_active'] = TRUE;
253 if(isset($_POST['samba_sid'])){
254 $this->samba_settings['samba_sid'] = get_post('samba_sid');
255 }
256 }else{
257 $this->samba_settings['samba_sid_active'] = FALSE;
258 }
259 if(isset($_POST['samba_rid_active'])){
260 $this->samba_settings['samba_rid_active'] = TRUE;
261 if(isset($_POST['samba_rid'])){
262 $this->samba_settings['samba_rid'] = get_post('samba_rid');
263 }
264 }else{
265 $this->samba_settings['samba_rid_active'] = FALSE;
266 }
267 if(isset($_POST['smbhash'])){
268 $this->samba_settings['smbhash'] = get_post('smbhash');
269 }
271 if(!$this->sambaDomain_found){
272 $this->samba_settings['samba_sid_active'] = TRUE;
273 $this->samba_settings['samba_rid_active'] = TRUE;
274 }
276 /* Reload mail naming attribute */
277 if($old_mail != $this->mail && isset($this->mail_methods[$this->mail]['uattrib'])){
278 $this->mail_attrib = $this->mail_methods[$this->mail]['uattrib'];
279 }
280 }
282 $tmp = $this->check();
283 if(count($tmp) == 0){
284 $this->is_completed = TRUE;
285 }else{
286 $this->is_completed = FALSE;
287 }
288 }
291 function check()
292 {
293 $message = array();
294 return($message);
295 }
298 /* Attributes that are interesting for configuration generation */
299 function get_attributes()
300 {
301 $tmp = setup_step::get_attributes();
302 foreach(array("samba_settings","generic_settings","mail_settings") as $attr){
303 $tmp[$attr]= $this->$attr;
304 }
305 return($tmp);
306 }
309 /* Returns the classnames auf the mail classes */
310 function get_available_mail_classes()
311 {
312 global $class_mapping;
314 $default_uattrib = "";
315 $m_class_vars = get_class_vars("mailMethod");
316 if(isset($m_class_vars['uattrib'])){
317 $default_uattrib = $m_class_vars['uattrib'];
318 }
320 foreach($class_mapping as $name => $file){
321 if(preg_match("/^mailMethod[a-z]*$/i",$name)){
322 $name = preg_replace("/^mailMethod/","",$name);
323 if(!empty($name)){
324 $methods[$name]['name'] = $name;
325 $m_class_vars = get_class_vars("mailMethod".$methods[$name]['name']);
326 if(isset($m_class_vars['uattrib'])){
327 $methods[$name]['uattrib'] = $m_class_vars['uattrib'];
328 }else{
329 $methods[$name]['uattrib'] = $default_uattrib;
330 }
331 }
332 }
333 }
334 return($methods);
335 }
336 }
338 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
339 ?>