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 "enableDNS" => false,
37 "enableDHCP" => false,
38 "wws_ou" => "ou=winstations",
39 "wws_ou_active" => FALSE,
40 "snapshot_active" => FALSE,
41 "snapshot_base" => "ou=snapshots,%base%",
42 "snapshot_user" => "%admin%",
43 "snapshot_password" => "",
44 "snapshot_server" => "%connection%");
46 var $samba_settings = array( "samba_sid" => "0-815-4711",
47 "samba_sid_active" => FALSE,
48 "samba_rid" => 1000,
49 "smbhash" => 'SMBHASH',
50 "samba_rid_active" => FALSE);
52 var $sambaDomain_found = FALSE;
53 var $use_netatalk = FALSE;
54 var $enableFAI_management = FALSE;
56 var $timezone = "Europe/Berlin";
57 var $timezones = array();
59 var $attributes = array("governmentmode","sambaidmapping","cyrusunixstyle","mail","use_netatalk","enableFAI_management","timezone");
60 var $called = FALSE;
62 function Step_Config2()
63 {
64 $this->update_strings();
65 $tmp = $this->get_available_mail_classes();
66 foreach($tmp['name'] as $name){
67 $this->mail_methods[$name] = $name;
68 }
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 = _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 /* 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 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 /* Update snapshot values, with already collected values */
139 foreach($this->generic_settings as $key => $value){
140 foreach(array("snapshot_base","snapshot_user","snapshot_server") as $attr){
141 foreach($this->parent->captured_values as $replace_name => $replace_value){
142 if(is_string($replace_value)) {
143 $this->generic_settings[$attr] = preg_replace("/%".$replace_name."%/",$replace_value,$this->generic_settings[$attr]);
144 }
145 }
146 }
147 }
149 $smarty = get_smarty();
150 $smarty->assign("sambaDomain_found",$this->sambaDomain_found);
151 $smarty->assign("generic_settings",$this->generic_settings);
152 $smarty->assign("mail_settings",$this->mail_settings);
153 $smarty->assign("mail_methods",$this->mail_methods);
154 $smarty->assign("samba_settings",$this->samba_settings);
155 $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
156 foreach($this->attributes as $attr){
157 $smarty->assign($attr,$this->$attr);
158 }
159 $smarty->assign("timezone" ,$this->timezone);
160 $smarty->assign("timezones" ,$this->timezones);
161 return($smarty -> fetch (get_template_path("../setup/setup_config2.tpl")));
162 }
164 function save_object()
165 {
166 if(isset($_POST['step6_posted'])){
168 if(isset($_POST['timezone']) && isset($this->timezones['TIMEZONES'][$_POST['timezone']])){
169 $this->timezone = $_POST['timezone'];
170 }
172 /* Get attributes */
173 foreach($this->attributes as $attr){
174 if(isset($_POST[$attr])){
175 $this->$attr = validate(get_post($attr));
176 }
177 }
179 /* Mail settings */
180 if(isset($_POST['vacationdir_active'])){
181 $this->mail_settings['vacationdir_active'] = TRUE;
182 if(isset($_POST['vacationdir'])){
183 $this->mail_settings['vacationdir'] = get_post('vacationdir');
184 }
185 }else{
186 $this->mail_settings['vacationdir_active'] = FALSE;
187 }
189 if(isset($_POST['enableCopyPaste'])){
190 $this->generic_settings['enableCopyPaste'] = get_post('enableCopyPaste');
191 }
192 if(isset($_POST['enableDNS'])){
193 $this->generic_settings['enableDNS'] = get_post('enableDNS');
194 }
195 if(isset($_POST['enableDHCP'])){
196 $this->generic_settings['enableDHCP'] = get_post('enableDHCP');
197 }
199 if(isset($_POST['wws_ou_active'])){
200 $this->generic_settings['wws_ou_active'] = TRUE;
201 if(isset($_POST['wws_ou'])){
202 $this->generic_settings['wws_ou'] = get_post('wws_ou');
203 }
204 }else{
205 $this->generic_settings['wws_ou_active'] = FALSE;
206 }
208 if(isset($_POST['snapshot_active'])){
209 $this->generic_settings['snapshot_active'] = TRUE;
210 if(isset($_POST['snapshot_base'])){
211 $this->generic_settings['snapshot_base'] = get_post('snapshot_base');
212 }
213 if(isset($_POST['snapshot_user'])){
214 $this->generic_settings['snapshot_user'] = get_post('snapshot_user');
215 }
216 if(isset($_POST['snapshot_password'])){
217 $this->generic_settings['snapshot_password'] = get_post('snapshot_password');
218 }
219 if(isset($_POST['snapshot_server'])){
220 $this->generic_settings['snapshot_server'] = get_post('snapshot_server');
221 }
222 }else{
223 $this->generic_settings['snapshot_active'] = FALSE;
224 }
226 /* Samba settings */
227 if(isset($_POST['samba_sid_active'])){
228 $this->samba_settings['samba_sid_active'] = TRUE;
229 if(isset($_POST['samba_sid'])){
230 $this->samba_settings['samba_sid'] = get_post('samba_sid');
231 }
232 }else{
233 $this->samba_settings['samba_sid_active'] = FALSE;
234 }
235 if(isset($_POST['samba_rid_active'])){
236 $this->samba_settings['samba_rid_active'] = TRUE;
237 if(isset($_POST['samba_rid'])){
238 $this->samba_settings['samba_rid'] = get_post('samba_rid');
239 }
240 }else{
241 $this->samba_settings['samba_rid_active'] = FALSE;
242 }
243 if(isset($_POST['smbhash'])){
244 $this->samba_settings['smbhash'] = get_post('smbhash');
245 }
247 if(!$this->sambaDomain_found){
248 $this->samba_settings['samba_sid_active'] = TRUE;
249 $this->samba_settings['samba_rid_active'] = TRUE;
250 }
251 }
253 $tmp = $this->check();
254 if(count($tmp) == 0){
255 $this->is_completed = TRUE;
256 }else{
257 $this->is_completed = FALSE;
258 }
259 }
262 function check()
263 {
264 $message = array();
265 return($message);
266 }
269 /* Attributes that are interesting for configuration generation */
270 function get_attributes()
271 {
272 $tmp = setup_step::get_attributes();
273 foreach(array("samba_settings","generic_settings","mail_settings") as $attr){
274 $tmp[$attr]= $this->$attr;
275 }
276 return($tmp);
277 }
279 /* Returns the classnames auf the mail classes */
280 function get_available_mail_classes()
281 {
282 $dir = opendir( "../include");
283 $methods = array();
284 $suffix = "class_mail-methods-";
285 $lensuf = strlen($suffix);
286 $prefix = ".inc";
287 $lenpre = strlen($prefix);
288 $i = 0;
289 while (($file = readdir($dir)) !== false){
291 if(stristr($file,$suffix)) {
292 $lenfile = strlen($file);
293 $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
294 $methods['file'][$i] = $file;
295 $methods[$i]['file'] = $file;
296 $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
297 $i++;
298 }
299 }
300 return($methods);
301 }
303 }
305 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
306 ?>