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 "snapshot_server" => "%connection%");
47 var $samba_settings = array( "samba_sid" => "0-815-4711",
48 "samba_sid_active" => FALSE,
49 "samba_rid" => 1000,
50 "smbhash" => 'SMBHASH',
51 "samba_rid_active" => FALSE);
53 var $sambaDomain_found = FALSE;
54 var $use_netatalk = FALSE;
55 var $enableFAI_management = FALSE;
56 var $enableMimeType = FALSE;
58 var $timezone = "Europe/Berlin";
59 var $timezones = array();
61 var $attributes = array("mail_attrib","governmentmode","sambaidmapping","cyrusunixstyle","mail","use_netatalk","enableFAI_management","timezone","enableMimeType");
62 var $called = FALSE;
64 function Step_Config2()
65 {
66 $this->update_strings();
67 $this->mail_methods = $this->get_available_mail_classes();
69 /* Look for samba password generation method */
70 if(file_exists("/usr/bin/mkntpasswd")){
71 $pwdhash = "/usr/bin/mkntpasswd";
72 } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
73 $pwdhash= "mkntpwd";
74 } else {
75 $pwdhash= 'perl -MCrypt::SmbHash -e "print join(q[:], ntlmgen \$ARGV[0]), $/;"';
76 }
78 $this->timezones = timezone::_get_tz_zones();
79 $this->samba_settings['smbhash'] = $pwdhash;
80 }
83 function update_strings()
84 {
85 $this->s_title = _("GOsa settings 2/3");
86 $this->s_title_long = _("GOsa settings 2/3");
87 $this->s_info = _("Customize special parameters");
88 }
91 function execute()
92 {
93 $this->mail_methods = $this->get_available_mail_classes();
94 /* On first call check for rid/sid base */
95 $cv = $this->parent->captured_values;
96 $ldap = new LDAP($cv['admin'],
97 $cv['password'],
98 $cv['connection'],
99 FALSE,
100 $cv['tls']);
102 $ldap->cd($cv['base']);
103 $ldap->search("(objectClass=sambaDomain)",array("dn"));
104 if($ldap->count()){
105 $this->sambaDomain_found =TRUE;
106 }else{
107 $this->sambaDomain_found =FALSE;
108 }
110 if(!$this->called){
111 if(!$this->sambaDomain_found){
112 $this->samba_settings['samba_sid_active'] = TRUE;
113 $this->samba_settings['samba_rid_active'] = TRUE;
114 }
116 /* Check if we can enable netatalk plugin */
117 $tmp = $ldap->get_objectclasses();
118 if(is_array($tmp) && isset($tmp['apple-user'])) {
119 $this->use_netatalk = TRUE;
120 }
122 /* Check the FAI schema is used */
123 if(is_array($tmp) && isset($tmp['FAIclass'])){
124 # $this->enableFAI_management = TRUE;
125 }
127 /* Check the MimeType schema is used */
128 if(is_array($tmp) && isset($tmp['gotoMimeType'])){
129 $this->enableMimeType = TRUE;
130 }
132 if(is_array($tmp) && isset($tmp['dhcpClass'])){
133 $this->generic_settings['enableDHCP'] = TRUE;
134 }
136 if(is_array($tmp) && isset($tmp['dNSZone'])){
137 $this->generic_settings['enableDNS'] = TRUE;
138 }
140 $this->called = TRUE;
141 }
143 /* Update snapshot values, with already collected values */
144 foreach($this->generic_settings as $key => $value){
145 foreach(array("snapshot_base","snapshot_user","snapshot_server") as $attr){
146 foreach($this->parent->captured_values as $replace_name => $replace_value){
147 if(is_string($replace_value)) {
148 $this->generic_settings[$attr] = preg_replace("/%".$replace_name."%/",$replace_value,$this->generic_settings[$attr]);
149 }
150 }
151 }
152 }
154 $smarty = get_smarty();
155 $smarty->assign("sambaDomain_found",$this->sambaDomain_found);
156 $smarty->assign("generic_settings",$this->generic_settings);
157 $smarty->assign("mail_settings",$this->mail_settings);
158 $smarty->assign("mail_methods",$this->mail_methods);
159 $smarty->assign("samba_settings",$this->samba_settings);
160 $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
161 foreach($this->attributes as $attr){
162 $smarty->assign($attr,$this->$attr);
163 }
164 $smarty->assign("timezone" ,$this->timezone);
165 $smarty->assign("timezones" ,$this->timezones);
166 return($smarty -> fetch (get_template_path("../setup/setup_config2.tpl")));
167 }
169 function save_object()
170 {
171 if(isset($_POST['step6_posted'])){
173 if(isset($_POST['timezone']) && isset($this->timezones['TIMEZONES'][$_POST['timezone']])){
174 $this->timezone = $_POST['timezone'];
175 }
177 $old_mail = $this->mail;
179 /* Get attributes */
180 foreach($this->attributes as $attr){
181 if(isset($_POST[$attr])){
182 $this->$attr = validate(get_post($attr));
183 }
184 }
186 /* Mail settings */
187 if(isset($_POST['vacationdir_active'])){
188 $this->mail_settings['vacationdir_active'] = TRUE;
189 if(isset($_POST['vacationdir'])){
190 $this->mail_settings['vacationdir'] = get_post('vacationdir');
191 }
192 }else{
193 $this->mail_settings['vacationdir_active'] = FALSE;
194 }
196 if(isset($_POST['enableCopyPaste'])){
197 $this->generic_settings['enableCopyPaste'] = get_post('enableCopyPaste');
198 }
199 if(isset($_POST['enableDNS'])){
200 $this->generic_settings['enableDNS'] = get_post('enableDNS');
201 }
202 if(isset($_POST['enableDHCP'])){
203 $this->generic_settings['enableDHCP'] = get_post('enableDHCP');
204 }
206 if(isset($_POST['wws_ou_active'])){
207 $this->generic_settings['wws_ou_active'] = TRUE;
208 if(isset($_POST['wws_ou'])){
209 $this->generic_settings['wws_ou'] = get_post('wws_ou');
210 }
211 }else{
212 $this->generic_settings['wws_ou_active'] = FALSE;
213 }
215 if(isset($_POST['snapshot_active'])){
216 $this->generic_settings['snapshot_active'] = TRUE;
217 if(isset($_POST['snapshot_base'])){
218 $this->generic_settings['snapshot_base'] = get_post('snapshot_base');
219 }
220 if(isset($_POST['snapshot_user'])){
221 $this->generic_settings['snapshot_user'] = get_post('snapshot_user');
222 }
223 if(isset($_POST['snapshot_password'])){
224 $this->generic_settings['snapshot_password'] = get_post('snapshot_password');
225 }
226 if(isset($_POST['snapshot_server'])){
227 $this->generic_settings['snapshot_server'] = get_post('snapshot_server');
228 }
229 }else{
230 $this->generic_settings['snapshot_active'] = FALSE;
231 }
233 /* Samba settings */
234 if(isset($_POST['samba_sid_active'])){
235 $this->samba_settings['samba_sid_active'] = TRUE;
236 if(isset($_POST['samba_sid'])){
237 $this->samba_settings['samba_sid'] = get_post('samba_sid');
238 }
239 }else{
240 $this->samba_settings['samba_sid_active'] = FALSE;
241 }
242 if(isset($_POST['samba_rid_active'])){
243 $this->samba_settings['samba_rid_active'] = TRUE;
244 if(isset($_POST['samba_rid'])){
245 $this->samba_settings['samba_rid'] = get_post('samba_rid');
246 }
247 }else{
248 $this->samba_settings['samba_rid_active'] = FALSE;
249 }
250 if(isset($_POST['smbhash'])){
251 $this->samba_settings['smbhash'] = get_post('smbhash');
252 }
254 if(!$this->sambaDomain_found){
255 $this->samba_settings['samba_sid_active'] = TRUE;
256 $this->samba_settings['samba_rid_active'] = TRUE;
257 }
259 /* Reload mail naming attribute */
260 if($old_mail != $this->mail && isset($this->mail_methods[$this->mail]['uattrib'])){
261 $this->mail_attrib = $this->mail_methods[$this->mail]['uattrib'];
262 }
263 }
265 $tmp = $this->check();
266 if(count($tmp) == 0){
267 $this->is_completed = TRUE;
268 }else{
269 $this->is_completed = FALSE;
270 }
271 }
274 function check()
275 {
276 $message = array();
277 return($message);
278 }
281 /* Attributes that are interesting for configuration generation */
282 function get_attributes()
283 {
284 $tmp = setup_step::get_attributes();
285 foreach(array("samba_settings","generic_settings","mail_settings") as $attr){
286 $tmp[$attr]= $this->$attr;
287 }
288 return($tmp);
289 }
292 /* Returns the classnames auf the mail classes */
293 function get_available_mail_classes()
294 {
295 global $class_mapping;
297 $default_uattrib = "";
298 $m_class_vars = get_class_vars("mailMethod");
299 if(isset($m_class_vars['uattrib'])){
300 $default_uattrib = $m_class_vars['uattrib'];
301 }
303 foreach($class_mapping as $name => $file){
304 if(preg_match("/^mailMethod[a-z]*$/i",$name)){
305 $name = preg_replace("/^mailMethod/","",$name);
306 if(!empty($name)){
307 $methods[$name]['name'] = $name;
308 $m_class_vars = get_class_vars("mailMethod".$methods[$name]['name']);
309 if(isset($m_class_vars['uattrib'])){
310 $methods[$name]['uattrib'] = $m_class_vars['uattrib'];
311 }else{
312 $methods[$name]['uattrib'] = $default_uattrib;
313 }
314 }
315 }
316 }
317 return($methods);
318 }
319 }
321 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
322 ?>