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" => "syslog,mysql",
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 Step_Config2()
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_mysql" ,preg_match("/mysql/",$this->generic_settings['logging']));
135 $smarty->assign("logging_syslog",preg_match("/syslog/",$this->generic_settings['logging']));
137 $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
138 foreach($this->attributes as $attr){
139 $smarty->assign($attr,reverse_html_entities($this->$attr));
140 }
141 $smarty->assign("timezone" ,$this->timezone);
142 $smarty->assign("timezones" ,$this->timezones);
143 return($smarty -> fetch (get_template_path("../setup/setup_config2.tpl")));
144 }
146 function save_object()
147 {
148 if(isset($_POST['step6_posted'])){
150 if(isset($_POST['timezone']) && isset($this->timezones['TIMEZONES'][$_POST['timezone']])){
151 $this->timezone = $_POST['timezone'];
152 }
154 $old_mail = $this->mail;
156 /* Get attributes */
157 foreach($this->attributes as $attr){
158 if(isset($_POST[$attr])){
159 $this->$attr = validate(get_post($attr));
160 }
161 }
163 /* Get logging */
164 $logging = "";
165 if(isset($_POST['logging_syslog'])){
166 $logging.= "syslog,";
167 }
168 if(isset($_POST['logging_mysql'])){
169 $logging.= "mysql,";
170 }
171 $this->generic_settings['logging'] = trim($logging,",");
173 /* Mail settings */
174 if(isset($_POST['vacationdir_active'])){
175 $this->mail_settings['vacationdir_active'] = TRUE;
176 if(isset($_POST['vacationdir'])){
177 $this->mail_settings['vacationdir'] = get_post('vacationdir');
178 }
179 }else{
180 $this->mail_settings['vacationdir_active'] = FALSE;
181 }
183 if(isset($_POST['enableCopyPaste'])){
184 $this->generic_settings['enableCopyPaste'] = get_post('enableCopyPaste');
185 }
187 if(isset($_POST['wws_ou_active'])){
188 $this->generic_settings['wws_ou_active'] = TRUE;
189 if(isset($_POST['wws_ou'])){
190 $this->generic_settings['wws_ou'] = get_post('wws_ou');
191 }
192 }else{
193 $this->generic_settings['wws_ou_active'] = FALSE;
194 }
196 if(isset($_POST['snapshot_active'])){
197 $this->generic_settings['snapshot_active'] = TRUE;
198 if(isset($_POST['snapshot_base'])){
199 $this->generic_settings['snapshot_base'] = get_post('snapshot_base');
200 }
201 if(isset($_POST['snapshot_user'])){
202 $this->generic_settings['snapshot_user'] = get_post('snapshot_user');
203 }
204 if(isset($_POST['snapshot_password'])){
205 $this->generic_settings['snapshot_password'] = get_post('snapshot_password');
206 }
207 if(isset($_POST['snapshot_server'])){
208 $this->generic_settings['snapshot_server'] = get_post('snapshot_server');
209 }
210 }else{
211 $this->generic_settings['snapshot_active'] = FALSE;
212 }
214 /* Samba settings */
215 if(isset($_POST['samba_sid_active'])){
216 $this->samba_settings['samba_sid_active'] = TRUE;
217 if(isset($_POST['samba_sid'])){
218 $this->samba_settings['samba_sid'] = get_post('samba_sid');
219 }
220 }else{
221 $this->samba_settings['samba_sid_active'] = FALSE;
222 }
223 if(isset($_POST['samba_rid_active'])){
224 $this->samba_settings['samba_rid_active'] = TRUE;
225 if(isset($_POST['samba_rid'])){
226 $this->samba_settings['samba_rid'] = get_post('samba_rid');
227 }
228 }else{
229 $this->samba_settings['samba_rid_active'] = FALSE;
230 }
231 if(isset($_POST['smbhash'])){
232 $this->samba_settings['smbhash'] = get_post('smbhash');
233 }
235 if(!$this->sambaDomain_found){
236 $this->samba_settings['samba_sid_active'] = TRUE;
237 $this->samba_settings['samba_rid_active'] = TRUE;
238 }
239 }
241 $tmp = $this->check();
242 if(count($tmp) == 0){
243 $this->is_completed = TRUE;
244 }else{
245 $this->is_completed = FALSE;
246 }
247 }
250 function check()
251 {
252 $message = array();
253 return($message);
254 }
257 /* Attributes that are interesting for configuration generation */
258 function get_attributes()
259 {
260 $tmp = setup_step::get_attributes();
261 foreach(array("samba_settings","generic_settings","mail_settings") as $attr){
262 $tmp[$attr]= $this->$attr;
263 }
264 return($tmp);
265 }
268 /* Returns the classnames auf the mail classes */
269 function get_available_mail_classes()
270 {
271 global $class_mapping;
273 /* Check if we have the mail classes/plugins installed */
274 if(!class_available("mailMethod")){
275 return(array());
276 }
277 $methods = array();
278 foreach($class_mapping as $name => $file){
279 if(preg_match("/^mailMethod.*$/i",$name)){
280 $name = preg_replace("/^mailMethod/","",$name);
281 if(!empty($name)){
282 $methods[$name]['name'] = $name;
283 }
284 }
285 }
286 return($methods);
287 }
288 }
290 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
291 ?>