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.

gearman.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Gearman Password Driver
  4. *
  5. * Payload is json string containing username, oldPassword and newPassword
  6. * Return value is a json string saying result: true if success.
  7. *
  8. * @version 1.0
  9. * @author Mohammad Anwari <mdamt@mdamt.net>
  10. *
  11. * Copyright (C) 2005-2014, 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. class rcube_gearman_password
  27. {
  28. function save($currpass, $newpass)
  29. {
  30. if (extension_loaded('gearman')) {
  31. $rcmail = rcmail::get_instance();
  32. $user = $_SESSION['username'];
  33. $payload = array(
  34. 'username' => $user,
  35. 'oldPassword' => $currpass,
  36. 'newPassword' => $newpass,
  37. );
  38. $gmc = new GearmanClient();
  39. $gmc->addServer($rcmail->config->get('password_gearman_host'));
  40. $result = $gmc->doNormal('setPassword', json_encode($payload));
  41. $success = json_decode($result);
  42. if ($success && $success->result == 1) {
  43. return PASSWORD_SUCCESS;
  44. }
  45. else {
  46. rcube::raise_error(array(
  47. 'code' => 600,
  48. 'type' => 'php',
  49. 'file' => __FILE__, 'line' => __LINE__,
  50. 'message' => "Password plugin: Gearman authentication failed for user $user: $error"
  51. ), true, false);
  52. }
  53. }
  54. else {
  55. rcube::raise_error(array(
  56. 'code' => 600,
  57. 'type' => 'php',
  58. 'file' => __FILE__, 'line' => __LINE__,
  59. 'message' => "Password plugin: PECL Gearman module not loaded"
  60. ), true, false);
  61. }
  62. return PASSWORD_ERROR;
  63. }
  64. }