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,
38 "snapshot_active" => FALSE,
39 "snapshot_base" => "ou=snapshots,%base%",
40 "snapshot_user" => "%admin%",
41 "snapshot_password" => "",
42 "snapshot_server" => "%connection%");
44 var $samba_settings = array( "samba_sid" => "0-815-4711",
45 "samba_sid_active" => FALSE,
46 "samba_rid" => 1000,
47 "smbhash" => 'SMBHASH',
48 "samba_rid_active" => FALSE);
50 var $sambaDomain_found = FALSE;
51 var $use_netatalk = FALSE;
52 var $enableFAI_management = FALSE;
54 var $timezone = "Europe/Berlin";
55 var $timezones = array();
57 var $attributes = array("governmentmode","sambaidmapping","cyrusunixstyle","mail","use_netatalk","enableFAI_management","timezone");
58 var $called = FALSE;
60 function Step_Config2()
61 {
62 $this->update_strings();
63 $tmp = $this->get_available_mail_classes();
64 foreach($tmp['name'] as $name){
65 $this->mail_methods[$name] = $name;
66 }
68 /* Look for samba password generation method */
69 if(file_exists("/usr/bin/mkntpasswd")){
70 $pwdhash = "/usr/bin/mkntpasswd";
71 } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
72 $pwdhash= "mkntpwd";
73 } else {
74 $pwdhash= 'perl -MCrypt::SmbHash -e "print join(q[:], ntlmgen \$ARGV[0]), $/;"';
75 }
77 $this->timezones = _get_tz_zones();
78 $this->samba_settings['smbhash'] = $pwdhash;
79 }
82 function update_strings()
83 {
84 $this->s_title = _("GOsa settings 2/3");
85 $this->s_title_long = _("GOsa settings 2/3");
86 $this->s_info = _("Customize special parameters");
87 }
90 function execute()
91 {
92 /* On first call check for rid/sid base */
93 $cv = $this->parent->captured_values;
94 $ldap = new LDAP($cv['admin'],
95 $cv['password'],
96 $cv['connection'],
97 FALSE,
98 $cv['tls']);
100 $ldap->cd($cv['base']);
101 $ldap->search("(objectClass=sambaDomain)",array("dn"));
102 if($ldap->count()){
103 $this->sambaDomain_found =TRUE;
104 }else{
105 $this->sambaDomain_found =FALSE;
106 }
108 if(!$this->called){
109 if(!$this->sambaDomain_found){
110 $this->samba_settings['samba_sid_active'] = TRUE;
111 $this->samba_settings['samba_rid_active'] = TRUE;
112 }
114 /* Check if we can enable netatalk plugin */
115 $tmp = $ldap->get_objectclasses();
116 if(is_array($tmp) && isset($tmp['apple-user'])) {
117 $this->use_netatalk = TRUE;
118 }
120 /* Check the FAI schema is used */
121 if(is_array($tmp) && isset($tmp['FAIclass'])){
122 # $this->enableFAI_management = TRUE;
123 }
125 $this->called = TRUE;
126 }
128 /* Update snapshot values, with already collected values */
129 foreach($this->generic_settings as $key => $value){
130 foreach(array("snapshot_base","snapshot_user","snapshot_server") as $attr){
131 foreach($this->parent->captured_values as $replace_name => $replace_value){
132 if(is_string($replace_value)) {
133 $this->generic_settings[$attr] = preg_replace("/%".$replace_name."%/",$replace_value,$this->generic_settings[$attr]);
134 }
135 }
136 }
137 }
139 $smarty = get_smarty();
140 $smarty->assign("sambaDomain_found",$this->sambaDomain_found);
141 $smarty->assign("generic_settings",$this->generic_settings);
142 $smarty->assign("mail_settings",$this->mail_settings);
143 $smarty->assign("mail_methods",$this->mail_methods);
144 $smarty->assign("samba_settings",$this->samba_settings);
145 $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
146 foreach($this->attributes as $attr){
147 $smarty->assign($attr,$this->$attr);
148 }
149 $smarty->assign("timezone" ,$this->timezone);
150 $smarty->assign("timezones" ,$this->timezones);
151 return($smarty -> fetch (get_template_path("../setup/setup_config2.tpl")));
152 }
154 function save_object()
155 {
156 if(isset($_POST['step6_posted'])){
158 if(isset($_POST['timezone']) && isset($this->timezones['TIMEZONES'][$_POST['timezone']])){
159 $this->timezone = $_POST['timezone'];
160 }
162 /* Get attributes */
163 foreach($this->attributes as $attr){
164 if(isset($_POST[$attr])){
165 $this->$attr = validate(get_post($attr));
166 }
167 }
169 /* Mail settings */
170 if(isset($_POST['vacationdir_active'])){
171 $this->mail_settings['vacationdir_active'] = TRUE;
172 if(isset($_POST['vacationdir'])){
173 $this->mail_settings['vacationdir'] = get_post('vacationdir');
174 }
175 }else{
176 $this->mail_settings['vacationdir_active'] = FALSE;
177 }
179 if(isset($_POST['enableCopyPaste'])){
180 $this->generic_settings['enableCopyPaste'] = get_post('enableCopyPaste');
181 }
183 if(isset($_POST['wws_ou_active'])){
184 $this->generic_settings['wws_ou_active'] = TRUE;
185 if(isset($_POST['wws_ou'])){
186 $this->generic_settings['wws_ou'] = get_post('wws_ou');
187 }
188 }else{
189 $this->generic_settings['wws_ou_active'] = FALSE;
190 }
192 if(isset($_POST['snapshot_active'])){
193 $this->generic_settings['snapshot_active'] = TRUE;
194 if(isset($_POST['snapshot_base'])){
195 $this->generic_settings['snapshot_base'] = get_post('snapshot_base');
196 }
197 if(isset($_POST['snapshot_user'])){
198 $this->generic_settings['snapshot_user'] = get_post('snapshot_user');
199 }
200 if(isset($_POST['snapshot_password'])){
201 $this->generic_settings['snapshot_password'] = get_post('snapshot_password');
202 }
203 if(isset($_POST['snapshot_server'])){
204 $this->generic_settings['snapshot_server'] = get_post('snapshot_server');
205 }
206 }else{
207 $this->generic_settings['snapshot_active'] = FALSE;
208 }
210 /* Samba settings */
211 if(isset($_POST['samba_sid_active'])){
212 $this->samba_settings['samba_sid_active'] = TRUE;
213 if(isset($_POST['samba_sid'])){
214 $this->samba_settings['samba_sid'] = get_post('samba_sid');
215 }
216 }else{
217 $this->samba_settings['samba_sid_active'] = FALSE;
218 }
219 if(isset($_POST['samba_rid_active'])){
220 $this->samba_settings['samba_rid_active'] = TRUE;
221 if(isset($_POST['samba_rid'])){
222 $this->samba_settings['samba_rid'] = get_post('samba_rid');
223 }
224 }else{
225 $this->samba_settings['samba_rid_active'] = FALSE;
226 }
227 if(isset($_POST['smbhash'])){
228 $this->samba_settings['smbhash'] = get_post('smbhash');
229 }
231 if(!$this->sambaDomain_found){
232 $this->samba_settings['samba_sid_active'] = TRUE;
233 $this->samba_settings['samba_rid_active'] = TRUE;
234 }
235 }
237 $tmp = $this->check();
238 if(count($tmp) == 0){
239 $this->is_completed = TRUE;
240 }else{
241 $this->is_completed = FALSE;
242 }
243 }
246 function check()
247 {
248 $message = array();
249 return($message);
250 }
253 /* Attributes that are interesting for configuration generation */
254 function get_attributes()
255 {
256 $tmp = setup_step::get_attributes();
257 foreach(array("samba_settings","generic_settings","mail_settings") as $attr){
258 $tmp[$attr]= $this->$attr;
259 }
260 return($tmp);
261 }
263 /* Returns the classnames auf the mail classes */
264 function get_available_mail_classes()
265 {
266 $dir = opendir( "../include");
267 $methods = array();
268 $suffix = "class_mail-methods-";
269 $lensuf = strlen($suffix);
270 $prefix = ".inc";
271 $lenpre = strlen($prefix);
272 $i = 0;
273 while (($file = readdir($dir)) !== false){
275 if(stristr($file,$suffix)) {
276 $lenfile = strlen($file);
277 $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
278 $methods['file'][$i] = $file;
279 $methods[$i]['file'] = $file;
280 $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
281 $i++;
282 }
283 }
284 return($methods);
285 }
287 }
289 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
290 ?>