diff options
author | thomascube <thomas@roundcube.net> | 2011-01-12 15:47:44 +0000 |
---|---|---|
committer | thomascube <thomas@roundcube.net> | 2011-01-12 15:47:44 +0000 |
commit | 62a83b3bd5813885d964d9fd1509d52bb9c4f12c (patch) | |
tree | 241e4407b51747889e63cc2d26219301639c238d /plugins/password/drivers/poppassd.php | |
parent | 28a4d4a49ebc4090155f97aeaf9a409f8e1549dc (diff) |
Copying plugins to release branch
Diffstat (limited to 'plugins/password/drivers/poppassd.php')
-rw-r--r-- | plugins/password/drivers/poppassd.php | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/plugins/password/drivers/poppassd.php b/plugins/password/drivers/poppassd.php new file mode 100644 index 000000000..fc105de47 --- /dev/null +++ b/plugins/password/drivers/poppassd.php @@ -0,0 +1,64 @@ +<?php + +/** + * Poppassd Password Driver + * + * Driver to change passwords via Poppassd/Courierpassd + * + * @version 1.1 + * @author Philip Weir + * + */ + +function format_error_result($code, $line) +{ + if (preg_match('/^\d\d\d\s+(\S.*)\s*$/', $line, $matches)) { + return array('code' => $code, 'message' => $matches[1]); + } else { + return $code; + } +} + +function password_save($curpass, $passwd) +{ + $rcmail = rcmail::get_instance(); +// include('Net/Socket.php'); + $poppassd = new Net_Socket(); + + $result = $poppassd->connect($rcmail->config->get('password_pop_host'), $rcmail->config->get('password_pop_port'), null); + if (PEAR::isError($result)) { + return format_error_result(PASSWORD_CONNECT_ERROR, $result->getMessage()); + } + else { + $result = $poppassd->readLine(); + if(!preg_match('/^2\d\d/', $result)) { + $poppassd->disconnect(); + return format_error_result(PASSWORD_ERROR, $result); + } + else { + $poppassd->writeLine("user ". $_SESSION['username']); + $result = $poppassd->readLine(); + if(!preg_match('/^[23]\d\d/', $result) ) { + $poppassd->disconnect(); + return format_error_result(PASSWORD_CONNECT_ERROR, $result); + } + else { + $poppassd->writeLine("pass ". $curpass); + $result = $poppassd->readLine(); + if(!preg_match('/^[23]\d\d/', $result) ) { + $poppassd->disconnect(); + return format_error_result(PASSWORD_ERROR, $result); + } + else { + $poppassd->writeLine("newpass ". $passwd); + $result = $poppassd->readLine(); + $poppassd->disconnect(); + if (!preg_match('/^2\d\d/', $result)) + return format_error_result(PASSWORD_ERROR, $result); + else + return PASSWORD_SUCCESS; + } + } + } + } +} |