| 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 | */ |
|---|
| 12 | |
|---|
| 13 | class rcube_poppassd_password |
|---|
| 14 | { |
|---|
| 15 | function format_error_result($code, $line) |
|---|
| 16 | { |
|---|
| 17 | if (preg_match('/^\d\d\d\s+(\S.*)\s*$/', $line, $matches)) { |
|---|
| 18 | return array('code' => $code, 'message' => $matches[1]); |
|---|
| 19 | } else { |
|---|
| 20 | return $code; |
|---|
| 21 | } |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | function save($curpass, $passwd) |
|---|
| 25 | { |
|---|
| 26 | $rcmail = rcmail::get_instance(); |
|---|
| 27 | // include('Net/Socket.php'); |
|---|
| 28 | $poppassd = new Net_Socket(); |
|---|
| 29 | |
|---|
| 30 | $result = $poppassd->connect($rcmail->config->get('password_pop_host'), $rcmail->config->get('password_pop_port'), null); |
|---|
| 31 | if (PEAR::isError($result)) { |
|---|
| 32 | return $this->format_error_result(PASSWORD_CONNECT_ERROR, $result->getMessage()); |
|---|
| 33 | } |
|---|
| 34 | else { |
|---|
| 35 | $result = $poppassd->readLine(); |
|---|
| 36 | if(!preg_match('/^2\d\d/', $result)) { |
|---|
| 37 | $poppassd->disconnect(); |
|---|
| 38 | return $this->format_error_result(PASSWORD_ERROR, $result); |
|---|
| 39 | } |
|---|
| 40 | else { |
|---|
| 41 | $poppassd->writeLine("user ". $_SESSION['username']); |
|---|
| 42 | $result = $poppassd->readLine(); |
|---|
| 43 | if(!preg_match('/^[23]\d\d/', $result) ) { |
|---|
| 44 | $poppassd->disconnect(); |
|---|
| 45 | return $this->format_error_result(PASSWORD_CONNECT_ERROR, $result); |
|---|
| 46 | } |
|---|
| 47 | else { |
|---|
| 48 | $poppassd->writeLine("pass ". $curpass); |
|---|
| 49 | $result = $poppassd->readLine(); |
|---|
| 50 | if(!preg_match('/^[23]\d\d/', $result) ) { |
|---|
| 51 | $poppassd->disconnect(); |
|---|
| 52 | return $this->format_error_result(PASSWORD_ERROR, $result); |
|---|
| 53 | } |
|---|
| 54 | else { |
|---|
| 55 | $poppassd->writeLine("newpass ". $passwd); |
|---|
| 56 | $result = $poppassd->readLine(); |
|---|
| 57 | $poppassd->disconnect(); |
|---|
| 58 | if (!preg_match('/^2\d\d/', $result)) |
|---|
| 59 | return $this->format_error_result(PASSWORD_ERROR, $result); |
|---|
| 60 | else |
|---|
| 61 | return PASSWORD_SUCCESS; |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | } |
|---|
| 65 | } |
|---|
| 66 | } |
|---|
| 67 | } |
|---|