8eab8885f68696eb644f538ff0bad3ff01c94abf
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 $attributes = array("governmentmode","sambaidmapping","cyrusunixstyle","mail");
52 function Step_Config2()
53 {
54 $this->update_strings();
55 $tmp = $this->get_available_mail_classes();
56 foreach($tmp['name'] as $name){
57 $this->mail_methods[$name] = $name;
58 }
60 /* Look for samba password generation method */
61 if(file_exists("/usr/bin/mkntpasswd")){
62 $pwdhash = "/usr/bin/mkntpasswd";
63 } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
64 $pwdhash= "mkntpwd";
65 } else {
66 $pwdhash= 'perl -MCrypt::SmbHash -e "print join(q[:], ntlmgen \$ARGV[0]), $/;"';
67 }
69 $this->samba_settings['smbhash'] = $pwdhash;
70 }
73 function update_strings()
74 {
75 $this->s_title = _("GOsa settings 2/3");
76 $this->s_title_long = _("GOsa settings 2/3");
77 $this->s_info = _("Customize special parameters");
78 }
81 function execute()
82 {
83 /* Update snapshot values, with already collected values */
84 foreach($this->generic_settings as $key => $value){
85 foreach(array("snapshot_base","snapshot_user","snapshot_server") as $attr){
86 foreach($this->parent->captured_values as $replace_name => $replace_value){
87 if(is_string($replace_value)) {
88 $this->generic_settings[$attr] = preg_replace("/%".$replace_name."%/",$replace_value,$this->generic_settings[$attr]);
89 }
90 }
91 }
92 }
94 $smarty = get_smarty();
95 $smarty->assign("generic_settings",$this->generic_settings);
96 $smarty->assign("mail_settings",$this->mail_settings);
97 $smarty->assign("mail_methods",$this->mail_methods);
98 $smarty->assign("samba_settings",$this->samba_settings);
99 $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
100 foreach($this->attributes as $attr){
101 $smarty->assign($attr,$this->$attr);
102 }
103 return($smarty -> fetch (get_template_path("../setup/setup_config2.tpl")));
104 }
106 function save_object()
107 {
108 if(isset($_POST['step6_posted'])){
110 /* Get attributes */
111 foreach($this->attributes as $attr){
112 if(isset($_POST[$attr])){
113 $this->$attr = validate($_POST[$attr]);
114 }
115 }
117 /* Mail settings */
118 if(isset($_POST['vacationdir_active'])){
119 $this->mail_settings['vacationdir_active'] = TRUE;
120 if(isset($_POST['vacationdir'])){
121 $this->mail_settings['vacationdir'] = $_POST['vacationdir'];
122 }
123 }else{
124 $this->mail_settings['vacationdir_active'] = FALSE;
125 }
127 if(isset($_POST['enableCopyPaste'])){
128 $this->generic_settings['enableCopyPaste'] = $_POST['enableCopyPaste'];
129 }
131 if(isset($_POST['wws_ou_active'])){
132 $this->generic_settings['wws_ou_active'] = TRUE;
133 if(isset($_POST['wws_ou'])){
134 $this->generic_settings['wws_ou'] = $_POST['wws_ou'];
135 }
136 }else{
137 $this->generic_settings['wws_ou_active'] = FALSE;
138 }
140 if(isset($_POST['snapshot_active'])){
141 $this->generic_settings['snapshot_active'] = TRUE;
142 if(isset($_POST['snapshot_base'])){
143 $this->generic_settings['snapshot_base'] = $_POST['snapshot_base'];
144 }
145 if(isset($_POST['snapshot_user'])){
146 $this->generic_settings['snapshot_user'] = $_POST['snapshot_user'];
147 }
148 if(isset($_POST['snapshot_password'])){
149 $this->generic_settings['snapshot_password'] = $_POST['snapshot_password'];
150 }
151 if(isset($_POST['snapshot_server'])){
152 $this->generic_settings['snapshot_server'] = $_POST['snapshot_server'];
153 }
154 }else{
155 $this->generic_settings['snapshot_active'] = FALSE;
156 }
158 /* Samba settings */
159 if(isset($_POST['samba_sid_active'])){
160 $this->samba_settings['samba_sid_active'] = TRUE;
161 if(isset($_POST['samba_sid'])){
162 $this->samba_settings['samba_sid'] = $_POST['samba_sid'];
163 }
164 }else{
165 $this->samba_settings['samba_sid_active'] = FALSE;
166 }
167 if(isset($_POST['samba_rid_active'])){
168 $this->samba_settings['samba_rid_active'] = TRUE;
169 if(isset($_POST['samba_rid'])){
170 $this->samba_settings['samba_rid'] = $_POST['samba_rid'];
171 }
172 }else{
173 $this->samba_settings['samba_rid_active'] = FALSE;
174 }
175 if(isset($_POST['smbhash'])){
176 $this->samba_settings['smbhash'] = $_POST['smbhash'];
177 }
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 ?>