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.

expect.php 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * expect driver
  4. *
  5. * Driver that adds functionality to change the systems user password via
  6. * the 'expect' command.
  7. *
  8. * For installation instructions please read the README file.
  9. *
  10. * @version 2.0
  11. * @author Andy Theuninck <gohanman@gmail.com)
  12. *
  13. * Based on chpasswd roundcubemail password driver by
  14. * @author Alex Cartwright <acartwright@mutinydesign.co.uk)
  15. * and expect horde passwd driver by
  16. * @author Gaudenz Steinlin <gaudenz@soziologie.ch>
  17. *
  18. * Configuration settings:
  19. * password_expect_bin => location of expect (e.g. /usr/bin/expect)
  20. * password_expect_script => path to "password-expect" file
  21. * password_expect_params => arguments for the expect script
  22. * see the password-expect file for details. This is probably
  23. * a good starting default:
  24. * -telent -host localhost -output /tmp/passwd.log -log /tmp/passwd.log
  25. *
  26. * Copyright (C) 2005-2014, The Roundcube Dev Team
  27. *
  28. * This program is free software: you can redistribute it and/or modify
  29. * it under the terms of the GNU General Public License as published by
  30. * the Free Software Foundation, either version 3 of the License, or
  31. * (at your option) any later version.
  32. *
  33. * This program is distributed in the hope that it will be useful,
  34. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  35. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  36. * GNU General Public License for more details.
  37. *
  38. * You should have received a copy of the GNU General Public License
  39. * along with this program. If not, see http://www.gnu.org/licenses/.
  40. */
  41. class rcube_expect_password
  42. {
  43. public function save($currpass, $newpass)
  44. {
  45. $rcmail = rcmail::get_instance();
  46. $bin = $rcmail->config->get('password_expect_bin');
  47. $script = $rcmail->config->get('password_expect_script');
  48. $params = $rcmail->config->get('password_expect_params');
  49. $username = $_SESSION['username'];
  50. $cmd = $bin . ' -f ' . $script . ' -- ' . $params;
  51. $handle = popen($cmd, "w");
  52. fwrite($handle, "$username\n");
  53. fwrite($handle, "$currpass\n");
  54. fwrite($handle, "$newpass\n");
  55. if (pclose($handle) == 0) {
  56. return PASSWORD_SUCCESS;
  57. }
  58. else {
  59. rcube::raise_error(array(
  60. 'code' => 600,
  61. 'type' => 'php',
  62. 'file' => __FILE__, 'line' => __LINE__,
  63. 'message' => "Password plugin: Unable to execute $cmd"
  64. ), true, false);
  65. }
  66. return PASSWORD_ERROR;
  67. }
  68. }