ebf9211b |
1 | <?php |
4b4abf93 |
2 | |
ebf9211b |
3 | /** |
4 | * Change password vmailmgrd backend |
5 | * |
d04cab42 |
6 | * Backend won't work, if vmail.inc file is not included. vmail.inc file |
7 | * should be part of your vmailmgr install. In some cases it is included in |
ebf9211b |
8 | * separate package. |
9 | * |
d04cab42 |
10 | * If you use modified vmail.inc, it must provide vchpass() function that |
11 | * acts same way as stock (vmailmgr v.0.96.9) vmail.inc function call |
12 | * and other vmail.inc functions should use same $vm_tcphost and |
ebf9211b |
13 | * $vm_tcphost_port globals as used by stock vm_daemon_raw() function call. |
d04cab42 |
14 | * If you have heavily modified vmail.inc and this backend does not work |
15 | * correctly - recheck, if you can reproduce your problem with stock |
ebf9211b |
16 | * vmail.inc or adjust backend configuration for your site. |
17 | * |
d04cab42 |
18 | * Backend also needs vmailmgrd service. You can find information about |
ebf9211b |
19 | * installing this service in vmailmgr FAQ and vmailmgrd.html. |
20 | * |
d04cab42 |
21 | * Backend might require functions, that are available only in SquirrelMail |
ebf9211b |
22 | * v.1.5.1 and v.1.4.4. |
23 | * |
4b4abf93 |
24 | * @author Tomas Kuliavas <tokul at users.sourceforge.net> |
47ccfad4 |
25 | * @copyright © 2005-2006 The SquirrelMail Project Team |
4b4abf93 |
26 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
ebf9211b |
27 | * @version $Id$ |
28 | * @link http://www.vmailmgr.org vmailmgr site |
29 | * @package plugins |
30 | * @subpackage change_password |
31 | */ |
32 | |
a391f3af |
33 | /* Default backend configuration */ |
ebf9211b |
34 | |
35 | /** |
36 | * path to vmail.inc |
37 | * |
38 | * This variable must provide full path to vmail.inc file including filename. |
d04cab42 |
39 | * |
40 | * WARNING: Don't disable this variable. It must be set to correct value or |
41 | * to empty string. If variable is missing, backend can have security problems |
42 | * in some PHP configurations. |
ebf9211b |
43 | * @global string $vmail_inc_path |
44 | */ |
45 | global $vmail_inc_path; |
46 | $vmail_inc_path=''; |
47 | |
48 | /** |
49 | * address of vmailmgrd host. |
50 | * |
51 | * Leave it empty, if you want to use unix socket |
52 | * global is used by vmail.inc functions |
53 | * @global string $vm_tcphost |
54 | */ |
55 | global $vm_tcphost; |
56 | $vm_tcphost=''; |
57 | |
58 | /** |
59 | * port of vmailmgrd |
60 | * |
61 | * global is used by vmail.inc functions. |
62 | * @global integer $vm_tcphost_port |
63 | */ |
64 | global $vm_tcphost_port; |
65 | $vm_tcphost_port=322; |
66 | |
67 | /** |
68 | * Option that controls use of 8bit passwords |
69 | * Use of such passwords is not safe, because squirrelmail interface |
70 | * can be running in different charsets. |
71 | * @global boolean |
72 | */ |
73 | global $cpw_vmailmgrd_8bitpw; |
74 | $cpw_vmailmgrd_8bitpw=false; |
75 | |
76 | /* end of backend configuration */ |
77 | |
a391f3af |
78 | /** load configuration from config.php */ |
76063016 |
79 | if ( isset($cpw_vmailmgrd) && is_array($cpw_vmailmgrd) && !empty($cpw_vmailmgrd) ) { |
80 | if (isset($cpw_vmailmgrd['vmail_inc_path'])) |
81 | $vmail_inc_path=$cpw_vmailmgrd['vmail_inc_path']; |
82 | if (isset($cpw_vmailmgrd['vm_tcphost'])) |
83 | $vm_tcphost=$cpw_vmailmgrd['vm_tcphost']; |
84 | if (isset($cpw_vmailmgrd['vm_tcphost_port'])) |
85 | $vm_tcphost_port=$cpw_vmailmgrd['vm_tcphost_port']; |
86 | if (isset($cpw_vmailmgrd['8bitpw'])) |
87 | $cpw_vmailmgrd_8bitpw=$cpw_vmailmgrd['8bitpw']; |
a391f3af |
88 | } |
89 | |
ebf9211b |
90 | |
91 | /** |
d04cab42 |
92 | * Init change_password plugin hooks. |
ebf9211b |
93 | */ |
94 | global $squirrelmail_plugin_hooks; |
95 | $squirrelmail_plugin_hooks['change_password_dochange']['vmailmgrd'] = |
96 | 'cpw_vmailmgrd_dochange'; |
97 | $squirrelmail_plugin_hooks['change_password_init']['vmailmgrd'] = |
98 | 'cpw_vmailmgrd_init'; |
99 | |
100 | |
101 | /** |
102 | * Use this function to do any backend-specific initialisation, |
103 | * e.g. checking requirements, before the password change form |
104 | * is displayed to the user. |
105 | */ |
106 | function cpw_vmailmgrd_init(){ |
107 | global $vmail_inc_path, $color, $username; |
108 | |
109 | /** |
110 | * If SM_PATH isn't defined, define it. Required to include files. |
111 | * @ignore |
112 | */ |
113 | if (!defined('SM_PATH')) { |
114 | define('SM_PATH','../../../'); |
115 | } |
116 | |
117 | // load error_box() function |
118 | include_once(SM_PATH . 'functions/display_messages.php'); |
119 | |
120 | if ($vmail_inc_path=='' || ! file_exists($vmail_inc_path)) { |
121 | // $vmail_inc_path is not set or file does not exist |
122 | error_box(_("Incorrent path to vmail.inc file."),$color); |
123 | // close html and stop script execution |
124 | echo "</body></html>\n"; |
125 | exit(); |
126 | } |
127 | |
128 | include_once($vmail_inc_path); |
129 | |
130 | if (! function_exists('vchpass')) { |
131 | // included vmail.inc does not have required functions. |
132 | error_box(_("Invalid or corrupted vmail.inc file."),$color); |
133 | // close html and stop script execution |
134 | echo "</body></html>\n"; |
135 | exit(); |
136 | } |
137 | |
138 | if (! preg_match("/(.*)\@(.*)/", $username)) { |
139 | // username does not match vmailmgr syntax |
140 | error_box(_("Invalid user."),$color); |
141 | // close html and stop script execution |
142 | echo "</body></html>\n"; |
143 | exit(); |
144 | } |
145 | } |
146 | |
147 | |
148 | /** |
149 | * function used to change password in change_password plugin hooks. |
150 | * |
06f1fc3a |
151 | * @param array $data The username/curpw/newpw data. |
ebf9211b |
152 | * @return array Array of error messages. |
153 | */ |
154 | function cpw_vmailmgrd_dochange($data) |
155 | { |
156 | global $cpw_vmailmgrd_8bitpw; |
157 | |
158 | /** |
159 | * getting params from hook function. |
160 | */ |
161 | $username = $data['username']; |
162 | $curpw = $data['curpw']; |
163 | $newpw = $data['newpw']; |
164 | |
165 | $msgs = array(); |
166 | |
167 | // check for new 8bit password |
168 | if (! $cpw_vmailmgrd_8bitpw && sq_is8bit($newpw)) { |
169 | // 8bit chars in password when backend is configured to block them |
170 | array_push($msgs,CPW_INVALID_PW); |
171 | return $msgs; |
172 | } |
173 | |
174 | // extract username and domain |
175 | if (preg_match("/(.*)\@(.*)/", $username, $parts)) { |
176 | $vm_user=$parts[1]; |
177 | $vm_domain=$parts[2]; |
178 | } |
179 | |
180 | // check if old password matches |
181 | $vmgrd_response1 = cpw_vmailmgrd_passwd($vm_user,$vm_domain,$curpw,$curpw); |
182 | if ($vmgrd_response1[0]!=0) { |
183 | array_push($msgs, CPW_CURRENT_NOMATCH); |
184 | return $msgs; |
185 | } |
186 | |
187 | // change password |
188 | $vmgrd_response2 = cpw_vmailmgrd_passwd($vm_user,$vm_domain,$curpw,$newpw); |
189 | if ($vmgrd_response2[0]!=0) { |
190 | // TODO: add vmail.inc error message parser. |
47a29972 |
191 | array_push($msgs, cpw_i18n_vmail_response($vmgrd_response2[1])); |
ebf9211b |
192 | } |
193 | |
194 | return $msgs; |
195 | } |
196 | |
197 | /** |
198 | * function that calls required vmail.inc functions and returns error codes. |
199 | * |
200 | * Information about vmailmgr return codes. |
201 | * vmailmgr functions return array with two keys. |
202 | * Array( |
203 | * [0] => error code, integer (0=no error) |
204 | * [1] => error message, string |
205 | * ) |
206 | * @return array |
207 | */ |
208 | function cpw_vmailmgrd_passwd($user,$domain,$oldpass,$newpass) { |
209 | global $vmail_inc_path; |
210 | |
211 | // variable should be checked by cpw_vmailmgrd_init function |
212 | include_once($vmail_inc_path); |
213 | |
214 | return vchpass($domain,$oldpass,$user,$newpass); |
215 | } |
47a29972 |
216 | |
217 | /** |
c683d87f |
218 | * Function is used to translate messages returned by vmailmgr |
47a29972 |
219 | * php library and vmailmgr daemon. |
220 | * @param string $string vmailmrgd message. |
221 | * @return string translated string. |
222 | */ |
223 | function cpw_i18n_vmail_response($string) { |
224 | if ($string=='Empty domain') { |
225 | // block one: vchpass responses |
226 | $ret = _("Empty domain"); |
227 | } elseif ($string=='Empty domain password') { |
228 | $ret = _("Empty domain password"); |
229 | } elseif ($string=='Empty username') { |
230 | $ret = _("Empty username"); |
231 | } elseif ($string=='Empty new password') { |
232 | $ret = _("Empty new password"); |
233 | /* |
234 | * block is disabled in order to reduce load on translators. |
235 | * these error messages should be very rare. |
236 | } elseif ($string=='Invalid or unknown base user or domain') { |
237 | // block two: vmailmgr daemon strings |
238 | $ret = _("Invalid or unknown base user or domain"); |
239 | } elseif ($string=='Invalid or unknown virtual user') { |
240 | $ret = _("Invalid or unknown virtual user"); |
241 | } elseif ($string=='Invalid or incorrect password') { |
242 | $ret = _("Invalid or incorrect password"); |
243 | } elseif ($string=='Unknown operation to stat') { |
244 | $ret = _("Unknown operation to stat"); |
245 | } elseif (preg_match("/^Incorrect number of parameters to command (.+)/",$string,$match)) { |
246 | $ret = sprintf(_("Incorrect number of parameters to command %s"),$match[1]); |
247 | } elseif (preg_match("/^Invalid or unknown domain name: (.+)/",$string,$match)) { |
248 | $ret = sprintf(_("Invalid or unknown domain name: %s"),$match[1]); |
249 | } elseif ($string=='Invalid operation') { |
250 | $ret = _("Invalid operation"); |
251 | } elseif (preg_match("/^Invalid or unknown base user name: (.+)/",$string,$match)) { |
252 | $ret = sprintf(_("Invalid or unknown base user name: %s"),$match[1]); |
253 | } elseif ($string=='Invalid or incorrect password') { |
254 | $ret = _("Invalid or incorrect password"); |
255 | } elseif ($string=='Base user has no virtual password table') { |
256 | $ret = _("Base user has no virtual password table"); |
257 | } elseif ($string=='Failed while writing initial OK response') { |
258 | $ret = _("Failed while writing initial OK response"); |
259 | } elseif ($string=='Failed while writing list entry') { |
260 | $ret = _("Failed while writing list entry"); |
261 | } elseif ($string=='Internal error -- userpass && !mustexist') { |
262 | $ret = _("Internal error -- userpass && !mustexist"); |
263 | } elseif ($string=='Invalid or unknown base user or domain') { |
264 | $ret = _("Invalid or unknown base user or domain"); |
265 | } elseif ($string=='Incorrect password') { |
266 | $ret = CPW_INVALID_PW; |
267 | } elseif ($string=='User name does not refer to a virtual user') { |
268 | $ret = _("User name does not refer to a virtual user"); |
269 | } elseif ($string=='Invalid or unknown virtual user') { |
270 | $ret = _("Invalid or unknown virtual user"); |
271 | } elseif ($string=='Virtual user already exists') { |
272 | $ret = _("Virtual user already exists"); |
273 | } elseif ($string=='Timed out waiting for remote') { |
274 | $ret = _("Timed out waiting for remote"); |
275 | } elseif ($string=='Connection to client lost') { |
276 | $ret = _("Connection to client lost"); |
277 | } elseif ($string=="Couldn't decode the command string") { |
278 | $ret = _("Couldn't decode the command string"); |
279 | } elseif ($string=='Empty command string') { |
280 | $ret = _("Empty command string"); |
281 | } elseif ($string=='Error decoding a command parameter') { |
282 | $ret = _("Error decoding a command parameter"); |
283 | } elseif ($string=='read system call failed or was interrupted') { |
284 | $ret = _("read system call failed or was interrupted"); |
285 | } elseif ($string=='Short read while reading protocol header') { |
286 | $ret = _("Short read while reading protocol header"); |
287 | } elseif ($string=='Invalid protocol from client') { |
288 | $ret = _("Invalid protocol from client"); |
289 | } elseif ($string=='Short read while reading message data') { |
290 | $ret = _("Short read while reading message data"); |
291 | } elseif ($string=='Error writing response') { |
292 | $ret = _("Error writing response"); |
293 | */ |
294 | } else { |
295 | // return unknown strings |
296 | $ret = $string; |
297 | } |
298 | return $ret; |
299 | } |
ebf9211b |
300 | ?> |