4 * Poppassd change password backend
6 * @author Seth Randall <sethr at missoulafcu.org>
7 * @copyright © 2004-2006 The SquirrelMail Project Team
8 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @subpackage change_password
19 * Set the address of the server your poppass daemon runs on.
20 * If it's the same as your imap server, you can leave it blank
22 global $poppassd_server;
24 $poppassd_server = '';
26 /* get overrides from config.php */
27 if (isset($cpw_poppassd['server'])) $poppassd_server=$cpw_poppassd['server'];
30 * Define here the name of your password changing function.
32 global $squirrelmail_plugin_hooks;
33 $squirrelmail_plugin_hooks['change_password_dochange']['poppassd'] = 'cpw_poppassd_dochange';
36 * This is the function that is specific to your backend. It takes
37 * the current password (as supplied by the user) and the desired
38 * new password. It will return an array of messages. If everything
39 * was successful, the array will be empty. Else, it will contain
40 * the errormessage(s).
41 * Constants to be used for these messages:
42 * CPW_CURRENT_NOMATCH -> "Your current password is not correct."
43 * CPW_INVALID_PW -> "Your new password contains invalid characters."
45 * @param array data The username/currentpw/newpw data.
46 * @return array Array of error messages.
48 function cpw_poppassd_dochange($data) {
49 // unfortunately, we can only pass one parameter to a hook function,
50 // so we have to pass it as an array.
51 $username = $data['username'];
52 $curpw = $data['curpw'];
53 $newpw = $data['newpw'];
57 // your code here to change the password for $username from
58 // $currentpw into $newpw.
59 $msgs = cpw_poppassd_go($username, $curpw, $newpw, 0);
64 function cpw_poppassd_closeport($pop_socket, &$messages, $debug = 0) {
66 array_push($messages, _("Closing Connection"));
68 fputs($pop_socket, "quit\r\n");
72 function cpw_poppassd_readfb($pop_socket, &$result, &$messages, $debug = 0) {
76 if (!feof($pop_socket)) {
77 $strResp = fgets($pop_socket, 1024);
78 $result = substr(trim($strResp), 0, 3); // 200, 500
79 if(!preg_match('/^[23]\d\d/', $result) ||
$debug) {
80 $messages[] = "--> $strResp";
85 function cpw_poppassd_go($username, $old_pw, $new_pw, $debug = 0) {
86 global $poppassd_server;
87 global $imapServerAddress;
89 /** sqimap_get_user_server() function */
90 include_once(SM_PATH
. '../functions/imap_general.php');
92 if($poppassd_server == '') {
93 // if poppassd address is not set, use imap server's address
94 // make sure that setting contains address and not mapping
95 $poppassd_server = sqimap_get_user_server($imapServerAddress,$username);
101 $messages[] = _("Connecting to Password Server");
103 $pop_socket = fsockopen($poppassd_server, 106, $errno, $errstr);
105 $messages[] = _("ERROR") . ': ' . "$errstr ($errno)";
109 cpw_poppassd_readfb($pop_socket, $result, $messages, $debug);
110 if(!preg_match('/^2\d\d/', $result) ) {
111 cpw_poppassd_closeport($pop_socket, $messages, $debug);
115 fputs($pop_socket, "user $username\r\n");
116 cpw_poppassd_readfb($pop_socket, $result, $messages, $debug);
117 if(!preg_match('/^[23]\d\d/', $result) ) {
118 cpw_poppassd_closeport($pop_socket, $messages, $debug);
122 fputs($pop_socket, "pass $old_pw\r\n");
123 cpw_poppassd_readfb($pop_socket, $result, $messages, $debug);
124 if(!preg_match('/^[23]\d\d/', $result) ) {
125 cpw_poppassd_closeport($pop_socket, $messages, $debug);
129 fputs($pop_socket, "newpass $new_pw\r\n");
130 cpw_poppassd_readfb($pop_socket, $result, $messages, $debug);
131 cpw_poppassd_closeport($pop_socket, $messages, $debug);
132 if(!preg_match('/^2\d\d/', $result) ) {