Mercurial > hg > rc1
comparison plugins/password/drivers/poppassd.php @ 0:1e000243b222
vanilla 1.3.3 distro, I hope
author | Charlie Root |
---|---|
date | Thu, 04 Jan 2018 15:50:29 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1e000243b222 |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * Poppassd Password Driver | |
5 * | |
6 * Driver to change passwords via Poppassd/Courierpassd | |
7 * | |
8 * @version 2.0 | |
9 * @author Philip Weir | |
10 * | |
11 * Copyright (C) 2005-2013, The Roundcube Dev Team | |
12 * | |
13 * This program is free software: you can redistribute it and/or modify | |
14 * it under the terms of the GNU General Public License as published by | |
15 * the Free Software Foundation, either version 3 of the License, or | |
16 * (at your option) any later version. | |
17 * | |
18 * This program is distributed in the hope that it will be useful, | |
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 * GNU General Public License for more details. | |
22 * | |
23 * You should have received a copy of the GNU General Public License | |
24 * along with this program. If not, see http://www.gnu.org/licenses/. | |
25 */ | |
26 | |
27 class rcube_poppassd_password | |
28 { | |
29 function format_error_result($code, $line) | |
30 { | |
31 if (preg_match('/^\d\d\d\s+(\S.*)\s*$/', $line, $matches)) { | |
32 return array('code' => $code, 'message' => $matches[1]); | |
33 } | |
34 | |
35 return $code; | |
36 } | |
37 | |
38 function save($curpass, $passwd) | |
39 { | |
40 $rcmail = rcmail::get_instance(); | |
41 $poppassd = new Net_Socket(); | |
42 | |
43 $port = $rcmail->config->get('password_pop_port', 106); | |
44 $host = $rcmail->config->get('password_pop_host', 'localhost'); | |
45 $host = rcube_utils::parse_host($host); | |
46 | |
47 $result = $poppassd->connect($host, $port, null); | |
48 | |
49 if (is_a($result, 'PEAR_Error')) { | |
50 return $this->format_error_result(PASSWORD_CONNECT_ERROR, $result->getMessage()); | |
51 } | |
52 | |
53 $result = $poppassd->readLine(); | |
54 | |
55 if (!preg_match('/^2\d\d/', $result)) { | |
56 $poppassd->disconnect(); | |
57 return $this->format_error_result(PASSWORD_ERROR, $result); | |
58 } | |
59 | |
60 $poppassd->writeLine("user ". $_SESSION['username']); | |
61 $result = $poppassd->readLine(); | |
62 | |
63 if (!preg_match('/^[23]\d\d/', $result)) { | |
64 $poppassd->disconnect(); | |
65 return $this->format_error_result(PASSWORD_CONNECT_ERROR, $result); | |
66 } | |
67 | |
68 $poppassd->writeLine("pass ". $curpass); | |
69 $result = $poppassd->readLine(); | |
70 | |
71 if (!preg_match('/^[23]\d\d/', $result)) { | |
72 $poppassd->disconnect(); | |
73 return $this->format_error_result(PASSWORD_ERROR, $result); | |
74 } | |
75 | |
76 $poppassd->writeLine("newpass ". $passwd); | |
77 $result = $poppassd->readLine(); | |
78 $poppassd->disconnect(); | |
79 | |
80 if (!preg_match('/^2\d\d/', $result)) { | |
81 return $this->format_error_result(PASSWORD_ERROR, $result); | |
82 } | |
83 | |
84 return PASSWORD_SUCCESS; | |
85 } | |
86 } |