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