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.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. // include('Net/Socket.php');
  38. $poppassd = new Net_Socket();
  39. $result = $poppassd->connect($rcmail->config->get('password_pop_host'), $rcmail->config->get('password_pop_port'), null);
  40. if (is_a($result, 'PEAR_Error')) {
  41. return $this->format_error_result(PASSWORD_CONNECT_ERROR, $result->getMessage());
  42. }
  43. else {
  44. $result = $poppassd->readLine();
  45. if(!preg_match('/^2\d\d/', $result)) {
  46. $poppassd->disconnect();
  47. return $this->format_error_result(PASSWORD_ERROR, $result);
  48. }
  49. else {
  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. else {
  57. $poppassd->writeLine("pass ". $curpass);
  58. $result = $poppassd->readLine();
  59. if (!preg_match('/^[23]\d\d/', $result) ) {
  60. $poppassd->disconnect();
  61. return $this->format_error_result(PASSWORD_ERROR, $result);
  62. }
  63. else {
  64. $poppassd->writeLine("newpass ". $passwd);
  65. $result = $poppassd->readLine();
  66. $poppassd->disconnect();
  67. if (!preg_match('/^2\d\d/', $result)) {
  68. return $this->format_error_result(PASSWORD_ERROR, $result);
  69. }
  70. return PASSWORD_SUCCESS;
  71. }
  72. }
  73. }
  74. }
  75. }
  76. }