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 $attributes = array("governmentmode","sambaidmapping","cyrusunixstyle","mail","use_netatalk","enableFAI_management");
50 var $called = FALSE;
52 function Step_Config2()
53 {
54 $this->update_strings();
55 $tmp = $this->get_available_mail_classes();
56 foreach($tmp['name'] as $name){
57 $this->mail_methods[$name] = $name;
58 }
60 /* Look for samba password generation method */
61 if(file_exists("/usr/bin/mkntpasswd")){
62 $pwdhash = "/usr/bin/mkntpasswd";
63 } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
64 $pwdhash= "mkntpwd";
65 } else {
66 $pwdhash= 'perl -MCrypt::SmbHash -e "print join(q[:], ntlmgen \$ARGV[0]), $/;"';
67 }
69 $this->samba_settings['smbhash'] = $pwdhash;
70 }
73 function update_strings()
74 {
75 $this->s_title = _("GOsa settings 2/3");
76 $this->s_title_long = _("GOsa settings 2/3");
77 $this->s_info = _("Customize special parameters");
78 }
81 function execute()
82 {
83 /* On first call check for rid/sid base */
84 $cv = $this->parent->captured_values;
85 $ldap = new LDAP($cv['admin'],
86 $cv['password'],
87 $cv['connection'],
88 FALSE,
89 $cv['tls']);
91 $ldap->cd($cv['base']);
92 $ldap->search("(objectClass=sambaDomain)",array("dn"));
93 if($ldap->count()){
94 $this->sambaDomain_found =TRUE;
95 }else{
96 $this->sambaDomain_found =FALSE;
97 }
99 if(!$this->called){
100 if(!$this->sambaDomain_found){
101 $this->samba_settings['samba_sid_active'] = TRUE;
102 $this->samba_settings['samba_rid_active'] = TRUE;
103 }
105 /* Check if we can enable netatalk plugin */
106 $tmp = $ldap->get_objectclasses();
107 if(is_array($tmp) && isset($tmp['apple-user'])) {
108 $this->use_netatalk = TRUE;
109 }
111 /* Check the FAI schema is used */
112 if(is_array($tmp) && isset($tmp['FAIclass'])){
113 # $this->enableFAI_management = TRUE;
114 }
116 $this->called = TRUE;
117 }
119 $smarty = get_smarty();
120 $smarty->assign("sambaDomain_found",$this->sambaDomain_found);
121 $smarty->assign("generic_settings",$this->generic_settings);
122 $smarty->assign("mail_settings",$this->mail_settings);
123 $smarty->assign("mail_methods",$this->mail_methods);
124 $smarty->assign("samba_settings",$this->samba_settings);
125 $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
126 foreach($this->attributes as $attr){
127 $smarty->assign($attr,$this->$attr);
128 }
129 return($smarty -> fetch (get_template_path("../setup/setup_config2.tpl")));
130 }
132 function save_object()
133 {
134 if(isset($_POST['step6_posted'])){
136 /* Get attributes */
137 foreach($this->attributes as $attr){
138 if(isset($_POST[$attr])){
139 $this->$attr = validate(get_post($attr));
140 }
141 }
143 /* Mail settings */
144 if(isset($_POST['vacationdir_active'])){
145 $this->mail_settings['vacationdir_active'] = TRUE;
146 if(isset($_POST['vacationdir'])){
147 $this->mail_settings['vacationdir'] = get_post('vacationdir');
148 }
149 }else{
150 $this->mail_settings['vacationdir_active'] = FALSE;
151 }
153 if(isset($_POST['enableCopyPaste'])){
154 $this->generic_settings['enableCopyPaste'] = get_post('enableCopyPaste');
155 }
157 if(isset($_POST['wws_ou_active'])){
158 $this->generic_settings['wws_ou_active'] = TRUE;
159 if(isset($_POST['wws_ou'])){
160 $this->generic_settings['wws_ou'] = get_post('wws_ou');
161 }
162 }else{
163 $this->generic_settings['wws_ou_active'] = FALSE;
164 }
166 /* Samba settings */
167 if(isset($_POST['samba_sid_active'])){
168 $this->samba_settings['samba_sid_active'] = TRUE;
169 if(isset($_POST['samba_sid'])){
170 $this->samba_settings['samba_sid'] = get_post('samba_sid');
171 }
172 }else{
173 $this->samba_settings['samba_sid_active'] = FALSE;
174 }
175 if(isset($_POST['samba_rid_active'])){
176 $this->samba_settings['samba_rid_active'] = TRUE;
177 if(isset($_POST['samba_rid'])){
178 $this->samba_settings['samba_rid'] = get_post('samba_rid');
179 }
180 }else{
181 $this->samba_settings['samba_rid_active'] = FALSE;
182 }
183 if(isset($_POST['smbhash'])){
184 $this->samba_settings['smbhash'] = get_post('smbhash');
185 }
187 if(!$this->sambaDomain_found){
188 $this->samba_settings['samba_sid_active'] = TRUE;
189 $this->samba_settings['samba_rid_active'] = TRUE;
190 }
191 }
193 $tmp = $this->check();
194 if(count($tmp) == 0){
195 $this->is_completed = TRUE;
196 }else{
197 $this->is_completed = FALSE;
198 }
199 }
202 function check()
203 {
204 $message = array();
205 return($message);
206 }
209 /* Attributes that are interesting for configuration generation */
210 function get_attributes()
211 {
212 $tmp = setup_step::get_attributes();
213 foreach(array("samba_settings","generic_settings","mail_settings") as $attr){
214 $tmp[$attr]= $this->$attr;
215 }
216 return($tmp);
217 }
219 /* Returns the classnames auf the mail classes */
220 function get_available_mail_classes()
221 {
222 $dir = opendir( "../include");
223 $methods = array();
224 $suffix = "class_mail-methods-";
225 $lensuf = strlen($suffix);
226 $prefix = ".inc";
227 $lenpre = strlen($prefix);
228 $i = 0;
229 while (($file = readdir($dir)) !== false){
231 if(stristr($file,$suffix)) {
232 $lenfile = strlen($file);
233 $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
234 $methods['file'][$i] = $file;
235 $methods[$i]['file'] = $file;
236 $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
237 $i++;
238 }
239 }
240 return($methods);
241 }
243 }
245 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
246 ?>