408b2f828f05ed66f79fd6e472a513d7363e42c9
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" => "cn=ldapadmin,%base%",
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;
52 var $attributes = array("governmentmode","sambaidmapping","cyrusunixstyle","mail");
53 var $called = FALSE;
56 function Step_Config2()
57 {
58 $this->update_strings();
59 $tmp = $this->get_available_mail_classes();
60 foreach($tmp['name'] as $name){
61 $this->mail_methods[$name] = $name;
62 }
64 /* Look for samba password generation method */
65 if(file_exists("/usr/bin/mkntpasswd")){
66 $pwdhash = "/usr/bin/mkntpasswd";
67 } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
68 $pwdhash= "mkntpwd";
69 } else {
70 $pwdhash= 'perl -MCrypt::SmbHash -e "print join(q[:], ntlmgen \$ARGV[0]), $/;"';
71 }
73 $this->samba_settings['smbhash'] = $pwdhash;
74 }
77 function update_strings()
78 {
79 $this->s_title = _("GOsa settings 2/3");
80 $this->s_title_long = _("GOsa settings 2/3");
81 $this->s_info = _("Customize special parameters");
82 }
85 function execute()
86 {
87 /* On first call check for rid/sid base */
88 $cv = $this->parent->captured_values;
89 $ldap = new LDAP($cv['admin'],
90 $cv['password'],
91 $cv['connection'],
92 FALSE,
93 $cv['tls']);
95 $ldap->cd($cv['base']);
96 $ldap->search("(objectClass=sambaDomain)",array("dn"));
97 if($ldap->count()){
98 $this->sambaDomain_found =TRUE;
99 }else{
100 $this->sambaDomain_found =FALSE;
101 }
103 if(!$this->called){
104 if(!$this->sambaDomain_found){
105 $this->samba_settings['samba_sid_active'] = TRUE;
106 $this->samba_settings['samba_rid_active'] = TRUE;
107 }
109 $this->called = TRUE;
110 }
112 /* Update snapshot values, with already collected values */
113 foreach($this->generic_settings as $key => $value){
114 foreach(array("snapshot_base","snapshot_user","snapshot_server") as $attr){
115 foreach($this->parent->captured_values as $replace_name => $replace_value){
116 if(is_string($replace_value)) {
117 $this->generic_settings[$attr] = preg_replace("/%".$replace_name."%/",$replace_value,$this->generic_settings[$attr]);
118 }
119 }
120 }
121 }
123 $smarty = get_smarty();
124 $smarty->assign("sambaDomain_found",$this->sambaDomain_found);
125 $smarty->assign("generic_settings",$this->generic_settings);
126 $smarty->assign("mail_settings",$this->mail_settings);
127 $smarty->assign("mail_methods",$this->mail_methods);
128 $smarty->assign("samba_settings",$this->samba_settings);
129 $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
130 foreach($this->attributes as $attr){
131 $smarty->assign($attr,$this->$attr);
132 }
133 return($smarty -> fetch (get_template_path("../setup/setup_config2.tpl")));
134 }
136 function save_object()
137 {
138 if(isset($_POST['step6_posted'])){
140 /* Get attributes */
141 foreach($this->attributes as $attr){
142 if(isset($_POST[$attr])){
143 $this->$attr = validate($_POST[$attr]);
144 }
145 }
147 /* Mail settings */
148 if(isset($_POST['vacationdir_active'])){
149 $this->mail_settings['vacationdir_active'] = TRUE;
150 if(isset($_POST['vacationdir'])){
151 $this->mail_settings['vacationdir'] = $_POST['vacationdir'];
152 }
153 }else{
154 $this->mail_settings['vacationdir_active'] = FALSE;
155 }
157 if(isset($_POST['enableCopyPaste'])){
158 $this->generic_settings['enableCopyPaste'] = $_POST['enableCopyPaste'];
159 }
161 if(isset($_POST['wws_ou_active'])){
162 $this->generic_settings['wws_ou_active'] = TRUE;
163 if(isset($_POST['wws_ou'])){
164 $this->generic_settings['wws_ou'] = $_POST['wws_ou'];
165 }
166 }else{
167 $this->generic_settings['wws_ou_active'] = FALSE;
168 }
170 if(isset($_POST['snapshot_active'])){
171 $this->generic_settings['snapshot_active'] = TRUE;
172 if(isset($_POST['snapshot_base'])){
173 $this->generic_settings['snapshot_base'] = $_POST['snapshot_base'];
174 }
175 if(isset($_POST['snapshot_user'])){
176 $this->generic_settings['snapshot_user'] = $_POST['snapshot_user'];
177 }
178 if(isset($_POST['snapshot_password'])){
179 $this->generic_settings['snapshot_password'] = $_POST['snapshot_password'];
180 }
181 if(isset($_POST['snapshot_server'])){
182 $this->generic_settings['snapshot_server'] = $_POST['snapshot_server'];
183 }
184 }else{
185 $this->generic_settings['snapshot_active'] = FALSE;
186 }
188 /* Samba settings */
189 if(isset($_POST['samba_sid_active'])){
190 $this->samba_settings['samba_sid_active'] = TRUE;
191 if(isset($_POST['samba_sid'])){
192 $this->samba_settings['samba_sid'] = $_POST['samba_sid'];
193 }
194 }else{
195 $this->samba_settings['samba_sid_active'] = FALSE;
196 }
197 if(isset($_POST['samba_rid_active'])){
198 $this->samba_settings['samba_rid_active'] = TRUE;
199 if(isset($_POST['samba_rid'])){
200 $this->samba_settings['samba_rid'] = $_POST['samba_rid'];
201 }
202 }else{
203 $this->samba_settings['samba_rid_active'] = FALSE;
204 }
205 if(isset($_POST['smbhash'])){
206 $this->samba_settings['smbhash'] = $_POST['smbhash'];
207 }
209 if(!$this->sambaDomain_found){
210 $this->samba_settings['samba_sid_active'] = TRUE;
211 $this->samba_settings['samba_rid_active'] = TRUE;
212 }
213 }
215 $tmp = $this->check();
216 if(count($tmp) == 0){
217 $this->is_completed = TRUE;
218 }else{
219 $this->is_completed = FALSE;
220 }
221 }
224 function check()
225 {
226 $message = array();
227 return($message);
228 }
231 /* Attributes that are interesting for configuration generation */
232 function get_attributes()
233 {
234 $tmp = setup_step::get_attributes();
235 foreach(array("samba_settings","generic_settings","mail_settings") as $attr){
236 $tmp[$attr]= $this->$attr;
237 }
238 return($tmp);
239 }
241 /* Returns the classnames auf the mail classes */
242 function get_available_mail_classes()
243 {
244 $dir = opendir( "../include");
245 $methods = array();
246 $suffix = "class_mail-methods-";
247 $lensuf = strlen($suffix);
248 $prefix = ".inc";
249 $lenpre = strlen($prefix);
250 $i = 0;
251 while (($file = readdir($dir)) !== false){
253 if(stristr($file,$suffix)) {
254 $lenfile = strlen($file);
255 $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
256 $methods['file'][$i] = $file;
257 $methods[$i]['file'] = $file;
258 $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
259 $i++;
260 }
261 }
262 return($methods);
263 }
265 }
267 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
268 ?>