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.

virtualmin.php 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * Virtualmin Password Driver
  4. *
  5. * Driver that adds functionality to change the users Virtualmin password.
  6. * The code is derrived from the Squirrelmail "Change Cyrus/SASL Password" Plugin
  7. * by Thomas Bruederli.
  8. *
  9. * It only works with virtualmin on the same host where Roundcube runs
  10. * and requires shell access and gcc in order to compile the binary.
  11. *
  12. * @version 3.0
  13. * @author Martijn de Munnik
  14. *
  15. * Copyright (C) 2005-2013, The Roundcube Dev Team
  16. *
  17. * This program is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation, either version 3 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program. If not, see http://www.gnu.org/licenses/.
  29. */
  30. class rcube_virtualmin_password
  31. {
  32. function save($currpass, $newpass)
  33. {
  34. $rcmail = rcmail::get_instance();
  35. $format = $rcmail->config->get('password_virtualmin_format', 0);
  36. $username = $_SESSION['username'];
  37. switch ($format) {
  38. case 1: // username%domain
  39. $domain = substr(strrchr($username, "%"), 1);
  40. break;
  41. case 2: // username.domain (could be bogus)
  42. $pieces = explode(".", $username);
  43. $domain = $pieces[count($pieces)-2]. "." . end($pieces);
  44. break;
  45. case 3: // domain.username (could be bogus)
  46. $pieces = explode(".", $username);
  47. $domain = $pieces[0]. "." . $pieces[1];
  48. break;
  49. case 4: // username-domain
  50. $domain = substr(strrchr($username, "-"), 1);
  51. break;
  52. case 5: // domain-username
  53. $domain = str_replace(strrchr($username, "-"), "", $username);
  54. break;
  55. case 6: // username_domain
  56. $domain = substr(strrchr($username, "_"), 1);
  57. break;
  58. case 7: // domain_username
  59. $pieces = explode("_", $username);
  60. $domain = $pieces[0];
  61. break;
  62. default: // username@domain
  63. $domain = substr(strrchr($username, "@"), 1);
  64. }
  65. if (!$domain) {
  66. $domain = $rcmail->user->get_username('domain');
  67. }
  68. $username = escapeshellcmd($username);
  69. $domain = escapeshellcmd($domain);
  70. $newpass = escapeshellcmd($newpass);
  71. $curdir = RCUBE_PLUGINS_DIR . 'password/helpers';
  72. exec("$curdir/chgvirtualminpasswd modify-user --domain $domain --user $username --pass $newpass", $output, $returnvalue);
  73. if ($returnvalue == 0) {
  74. return PASSWORD_SUCCESS;
  75. }
  76. else {
  77. rcube::raise_error(array(
  78. 'code' => 600,
  79. 'type' => 'php',
  80. 'file' => __FILE__, 'line' => __LINE__,
  81. 'message' => "Password plugin: Unable to execute $curdir/chgvirtualminpasswd"
  82. ), true, false);
  83. }
  84. return PASSWORD_ERROR;
  85. }
  86. }