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/setup/server.png";
29 var $cyrusunixstyle = FALSE;
30 var $mail = "none";
31 var $mail_attrib = "";
32 var $mail_methods = array();
33 var $mail_settings = array("vacationdir" => "/etc/gosa/vacation",
34 "vacationdir_active" => FALSE);
36 var $generic_settings = array( "enableCopyPaste" => false,
37 "wws_ou" => "ou=winstations",
38 "wws_ou_active" => FALSE,
39 "snapshot_active" => FALSE,
40 "snapshot_base" => "ou=snapshots,%base%",
41 "snapshot_user" => "%admin%",
42 "snapshot_password" => "",
43 "logging" => TRUE,
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 $timezone = "Europe/Berlin";
54 var $timezones = array();
56 var $attributes = array("mail_attrib","governmentmode","sambaidmapping","cyrusunixstyle","mail","timezone");
57 var $called = FALSE;
59 function __construct()
60 {
61 $this->update_strings();
62 $this->mail_methods = $this->get_available_mail_classes();
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->timezones = timezone::_get_tz_zones();
74 $this->samba_settings['smbhash'] = $pwdhash;
75 }
78 function update_strings()
79 {
80 $this->s_title = _("GOsa settings 2/3");
81 $this->s_title_long = _("GOsa settings 2/3");
82 $this->s_info = _("Customize special parameters");
83 }
86 function execute()
87 {
88 $this->mail_methods = $this->get_available_mail_classes();
89 /* On first call check for rid/sid base */
90 $cv = $this->parent->captured_values;
91 $ldap_l = new LDAP($cv['admin'],
92 $cv['password'],
93 $cv['connection'],
94 FALSE,
95 $cv['tls']);
97 $ldap = new ldapMultiplexer($ldap_l);
99 $ldap->cd($cv['base']);
100 $ldap->search("(objectClass=sambaDomain)",array("dn"));
101 if($ldap->count()){
102 $this->sambaDomain_found =TRUE;
103 }else{
104 $this->sambaDomain_found =FALSE;
105 }
107 if(!$this->called){
108 if(!$this->sambaDomain_found){
109 $this->samba_settings['samba_sid_active'] = TRUE;
110 $this->samba_settings['samba_rid_active'] = TRUE;
111 }
113 $this->called = TRUE;
114 }
116 /* Update snapshot values, with already collected values */
117 foreach($this->generic_settings as $key => $value){
118 foreach(array("snapshot_base","snapshot_user","snapshot_server") as $attr){
119 foreach($this->parent->captured_values as $replace_name => $replace_value){
120 if(is_string($replace_value)) {
121 $this->generic_settings[$attr] = preg_replace("/%".$replace_name."%/",$replace_value,$this->generic_settings[$attr]);
122 }
123 }
124 }
125 }
127 $smarty = get_smarty();
128 $smarty->assign("sambaDomain_found", $this->sambaDomain_found);
129 $smarty->assign("generic_settings", reverse_html_entities($this->generic_settings));
130 $smarty->assign("mail_settings", reverse_html_entities($this->mail_settings));
131 $smarty->assign("mail_methods", reverse_html_entities($this->mail_methods));
132 $smarty->assign("samba_settings", reverse_html_entities($this->samba_settings));
134 $smarty->assign("logging",$this->generic_settings['logging']);
136 $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
137 foreach($this->attributes as $attr){
138 $smarty->assign($attr,reverse_html_entities($this->$attr));
139 }
140 $smarty->assign("timezone" ,$this->timezone);
141 $smarty->assign("timezones" ,$this->timezones);
142 return($smarty -> fetch (get_template_path("../setup/setup_config2.tpl")));
143 }
145 function save_object()
146 {
147 if(isset($_POST['step6_posted'])){
149 if(isset($_POST['timezone']) && isset($this->timezones['TIMEZONES'][$_POST['timezone']])){
150 $this->timezone = $_POST['timezone'];
151 }
153 $old_mail = $this->mail;
155 /* Get attributes */
156 foreach($this->attributes as $attr){
157 if(isset($_POST[$attr])){
158 $this->$attr = validate(get_post($attr));
159 }
160 }
162 /* Get logging */
163 $this->generic_settings['logging'] = isset($_POST['logging']);
165 /* Mail settings */
166 if(isset($_POST['vacationdir_active'])){
167 $this->mail_settings['vacationdir_active'] = TRUE;
168 if(isset($_POST['vacationdir'])){
169 $this->mail_settings['vacationdir'] = get_post('vacationdir');
170 }
171 }else{
172 $this->mail_settings['vacationdir_active'] = FALSE;
173 }
175 if(isset($_POST['enableCopyPaste'])){
176 $this->generic_settings['enableCopyPaste'] = get_post('enableCopyPaste');
177 }
179 if(isset($_POST['wws_ou_active'])){
180 $this->generic_settings['wws_ou_active'] = TRUE;
181 if(isset($_POST['wws_ou'])){
182 $this->generic_settings['wws_ou'] = get_post('wws_ou');
183 }
184 }else{
185 $this->generic_settings['wws_ou_active'] = FALSE;
186 }
188 if(isset($_POST['snapshot_active'])){
189 $this->generic_settings['snapshot_active'] = TRUE;
190 if(isset($_POST['snapshot_base'])){
191 $this->generic_settings['snapshot_base'] = get_post('snapshot_base');
192 }
193 if(isset($_POST['snapshot_user'])){
194 $this->generic_settings['snapshot_user'] = get_post('snapshot_user');
195 }
196 if(isset($_POST['snapshot_password'])){
197 $this->generic_settings['snapshot_password'] = get_post('snapshot_password');
198 }
199 if(isset($_POST['snapshot_server'])){
200 $this->generic_settings['snapshot_server'] = get_post('snapshot_server');
201 }
202 }else{
203 $this->generic_settings['snapshot_active'] = FALSE;
204 }
206 /* Samba settings */
207 if(isset($_POST['samba_sid_active'])){
208 $this->samba_settings['samba_sid_active'] = TRUE;
209 if(isset($_POST['samba_sid'])){
210 $this->samba_settings['samba_sid'] = get_post('samba_sid');
211 }
212 }else{
213 $this->samba_settings['samba_sid_active'] = FALSE;
214 }
215 if(isset($_POST['samba_rid_active'])){
216 $this->samba_settings['samba_rid_active'] = TRUE;
217 if(isset($_POST['samba_rid'])){
218 $this->samba_settings['samba_rid'] = get_post('samba_rid');
219 }
220 }else{
221 $this->samba_settings['samba_rid_active'] = FALSE;
222 }
223 if(isset($_POST['smbhash'])){
224 $this->samba_settings['smbhash'] = get_post('smbhash');
225 }
227 if(!$this->sambaDomain_found){
228 $this->samba_settings['samba_sid_active'] = TRUE;
229 $this->samba_settings['samba_rid_active'] = TRUE;
230 }
231 }
233 $tmp = $this->check();
234 if(count($tmp) == 0){
235 $this->is_completed = TRUE;
236 }else{
237 $this->is_completed = FALSE;
238 }
239 }
242 function check()
243 {
244 $message = array();
245 return($message);
246 }
249 /* Attributes that are interesting for configuration generation */
250 function get_attributes()
251 {
252 $tmp = setup_step::get_attributes();
253 foreach(array("samba_settings","generic_settings","mail_settings") as $attr){
254 $tmp[$attr]= $this->$attr;
255 }
256 return($tmp);
257 }
260 /* Returns the classnames auf the mail classes */
261 function get_available_mail_classes()
262 {
263 global $class_mapping;
265 /* Check if we have the mail classes/plugins installed */
266 if(!class_available("mailMethod")){
267 return(array());
268 }
269 $methods = array();
270 foreach($class_mapping as $name => $file){
271 if(preg_match("/^mailMethod.*$/i",$name)){
272 $name = preg_replace("/^mailMethod/","",$name);
273 if(!empty($name)){
274 $methods[$name]['name'] = $name;
275 }
276 }
277 }
278 return($methods);
279 }
280 }
282 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
283 ?>