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(
36 "enableCopyPaste" => false,
37 "enableDNS" => false,
38 "enableDHCP" => false,
39 "wws_ou" => "ou=winstations",
40 "wws_ou_active" => FALSE);
42 var $samba_settings = array( "samba_sid" => "0-815-4711",
43 "samba_sid_active" => FALSE,
44 "samba_rid" => 1000,
45 "smbhash" => 'SMBHASH',
46 "samba_rid_active" => FALSE);
48 var $sambaDomain_found = FALSE;
49 var $use_netatalk = FALSE;
50 var $enableFAI_management = FALSE;
52 var $timezone = "Europe/Berlin";
53 var $timezones = array();
55 var $attributes = array("governmentmode","sambaidmapping","cyrusunixstyle","mail","use_netatalk","enableFAI_management","timezone");
56 var $called = FALSE;
58 function Step_Config2()
59 {
60 $this->update_strings();
61 $tmp = $this->get_available_mail_classes();
62 foreach($tmp['name'] as $name){
63 $this->mail_methods[$name] = $name;
64 }
66 /* Look for samba password generation method */
67 if(file_exists("/usr/bin/mkntpasswd")){
68 $pwdhash = "/usr/bin/mkntpasswd";
69 } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
70 $pwdhash= "mkntpwd";
71 } else {
72 $pwdhash= 'perl -MCrypt::SmbHash -e "print join(q[:], ntlmgen \$ARGV[0]), $/;"';
73 }
75 $this->timezones = _get_tz_zones();
76 $this->samba_settings['smbhash'] = $pwdhash;
77 }
80 function update_strings()
81 {
82 $this->s_title = _("GOsa settings 2/3");
83 $this->s_title_long = _("GOsa settings 2/3");
84 $this->s_info = _("Customize special parameters");
85 }
88 function execute()
89 {
90 /* On first call check for rid/sid base */
91 $cv = $this->parent->captured_values;
92 $ldap = new LDAP($cv['admin'],
93 $cv['password'],
94 $cv['connection'],
95 FALSE,
96 $cv['tls']);
98 $ldap->cd($cv['base']);
99 $ldap->search("(objectClass=sambaDomain)",array("dn"));
100 if($ldap->count()){
101 $this->sambaDomain_found =TRUE;
102 }else{
103 $this->sambaDomain_found =FALSE;
104 }
106 if(!$this->called){
107 if(!$this->sambaDomain_found){
108 $this->samba_settings['samba_sid_active'] = TRUE;
109 $this->samba_settings['samba_rid_active'] = TRUE;
110 }
112 /* Check if we can enable netatalk plugin */
113 $tmp = $ldap->get_objectclasses();
114 if(is_array($tmp) && isset($tmp['apple-user'])) {
115 $this->use_netatalk = TRUE;
116 }
118 /* Check the FAI schema is used */
119 if(is_array($tmp) && isset($tmp['FAIclass'])){
120 # $this->enableFAI_management = TRUE;
121 }
123 if(is_array($tmp) && isset($tmp['dhcpClass'])){
124 $this->generic_settings['enableDHCP'] = TRUE;
125 }
127 if(is_array($tmp) && isset($tmp['dNSZone'])){
128 $this->generic_settings['enableDNS'] = TRUE;
129 }
131 $this->called = TRUE;
132 }
134 $smarty = get_smarty();
135 $smarty->assign("sambaDomain_found",$this->sambaDomain_found);
136 $smarty->assign("generic_settings",$this->generic_settings);
137 $smarty->assign("mail_settings",$this->mail_settings);
138 $smarty->assign("mail_methods",$this->mail_methods);
139 $smarty->assign("samba_settings",$this->samba_settings);
140 $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
141 foreach($this->attributes as $attr){
142 $smarty->assign($attr,$this->$attr);
143 }
144 $smarty->assign("timezone" ,$this->timezone);
145 $smarty->assign("timezones" ,$this->timezones);
146 return($smarty -> fetch (get_template_path("../setup/setup_config2.tpl")));
147 }
149 function save_object()
150 {
151 if(isset($_POST['step6_posted'])){
153 if(isset($_POST['timezone']) && isset($this->timezones['TIMEZONES'][$_POST['timezone']])){
154 $this->timezone = $_POST['timezone'];
155 }
157 /* Get attributes */
158 foreach($this->attributes as $attr){
159 if(isset($_POST[$attr])){
160 $this->$attr = validate(get_post($attr));
161 }
162 }
164 /* Mail settings */
165 if(isset($_POST['vacationdir_active'])){
166 $this->mail_settings['vacationdir_active'] = TRUE;
167 if(isset($_POST['vacationdir'])){
168 $this->mail_settings['vacationdir'] = get_post('vacationdir');
169 }
170 }else{
171 $this->mail_settings['vacationdir_active'] = FALSE;
172 }
174 if(isset($_POST['enableCopyPaste'])){
175 $this->generic_settings['enableCopyPaste'] = get_post('enableCopyPaste');
176 }
177 if(isset($_POST['enableDNS'])){
178 $this->generic_settings['enableDNS'] = get_post('enableDNS');
179 }
180 if(isset($_POST['enableDHCP'])){
181 $this->generic_settings['enableDHCP'] = get_post('enableDHCP');
182 }
184 if(isset($_POST['wws_ou_active'])){
185 $this->generic_settings['wws_ou_active'] = TRUE;
186 if(isset($_POST['wws_ou'])){
187 $this->generic_settings['wws_ou'] = get_post('wws_ou');
188 }
189 }else{
190 $this->generic_settings['wws_ou_active'] = FALSE;
191 }
193 /* Samba settings */
194 if(isset($_POST['samba_sid_active'])){
195 $this->samba_settings['samba_sid_active'] = TRUE;
196 if(isset($_POST['samba_sid'])){
197 $this->samba_settings['samba_sid'] = get_post('samba_sid');
198 }
199 }else{
200 $this->samba_settings['samba_sid_active'] = FALSE;
201 }
202 if(isset($_POST['samba_rid_active'])){
203 $this->samba_settings['samba_rid_active'] = TRUE;
204 if(isset($_POST['samba_rid'])){
205 $this->samba_settings['samba_rid'] = get_post('samba_rid');
206 }
207 }else{
208 $this->samba_settings['samba_rid_active'] = FALSE;
209 }
210 if(isset($_POST['smbhash'])){
211 $this->samba_settings['smbhash'] = get_post('smbhash');
212 }
214 if(!$this->sambaDomain_found){
215 $this->samba_settings['samba_sid_active'] = TRUE;
216 $this->samba_settings['samba_rid_active'] = TRUE;
217 }
218 }
220 $tmp = $this->check();
221 if(count($tmp) == 0){
222 $this->is_completed = TRUE;
223 }else{
224 $this->is_completed = FALSE;
225 }
226 }
229 function check()
230 {
231 $message = array();
232 return($message);
233 }
236 /* Attributes that are interesting for configuration generation */
237 function get_attributes()
238 {
239 $tmp = setup_step::get_attributes();
240 foreach(array("samba_settings","generic_settings","mail_settings") as $attr){
241 $tmp[$attr]= $this->$attr;
242 }
243 return($tmp);
244 }
246 /* Returns the classnames auf the mail classes */
247 function get_available_mail_classes()
248 {
249 $dir = opendir( "../include");
250 $methods = array();
251 $suffix = "class_mail-methods-";
252 $lensuf = strlen($suffix);
253 $prefix = ".inc";
254 $lenpre = strlen($prefix);
255 $i = 0;
256 while (($file = readdir($dir)) !== false){
258 if(stristr($file,$suffix)) {
259 $lenfile = strlen($file);
260 $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
261 $methods['file'][$i] = $file;
262 $methods[$i]['file'] = $file;
263 $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
264 $i++;
265 }
266 }
267 return($methods);
268 }
270 }
272 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
273 ?>