You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

poppassd.php 2.6KB

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