PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/mail/plugins/password/drivers/virtualmin.php

https://bitbucket.org/alisher/itworks
PHP | 80 lines | 59 code | 8 blank | 13 comment | 4 complexity | e4a558885d8f772ec8264b37f6d33c11 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
  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. class rcube_virtualmin_password
  16. {
  17. function save($currpass, $newpass)
  18. {
  19. $rcmail = rcmail::get_instance();
  20. $format = $rcmail->config->get('password_virtualmin_format', 0);
  21. $username = $_SESSION['username'];
  22. switch ($format) {
  23. case 1: // username%domain
  24. $domain = substr(strrchr($username, "%"), 1);
  25. break;
  26. case 2: // username.domain (could be bogus)
  27. $pieces = explode(".", $username);
  28. $domain = $pieces[count($pieces)-2]. "." . end($pieces);
  29. break;
  30. case 3: // domain.username (could be bogus)
  31. $pieces = explode(".", $username);
  32. $domain = $pieces[0]. "." . $pieces[1];
  33. break;
  34. case 4: // username-domain
  35. $domain = substr(strrchr($username, "-"), 1);
  36. break;
  37. case 5: // domain-username
  38. $domain = str_replace(strrchr($username, "-"), "", $username);
  39. break;
  40. case 6: // username_domain
  41. $domain = substr(strrchr($username, "_"), 1);
  42. break;
  43. case 7: // domain_username
  44. $pieces = explode("_", $username);
  45. $domain = $pieces[0];
  46. break;
  47. case 8: // domain taken from alias, username left as it was
  48. $email = $rcmail->user->data['alias'];
  49. $domain = substr(strrchr($email, "@"), 1);
  50. break;
  51. default: // username@domain
  52. $domain = substr(strrchr($username, "@"), 1);
  53. }
  54. $username = escapeshellcmd($username);
  55. $domain = escapeshellcmd($domain);
  56. $newpass = escapeshellcmd($newpass);
  57. $curdir = INSTALL_PATH . 'plugins/password/helpers';
  58. exec("$curdir/chgvirtualminpasswd modify-user --domain $domain --user $username --pass $newpass", $output, $returnvalue);
  59. if ($returnvalue == 0) {
  60. return PASSWORD_SUCCESS;
  61. }
  62. else {
  63. raise_error(array(
  64. 'code' => 600,
  65. 'type' => 'php',
  66. 'file' => __FILE__, 'line' => __LINE__,
  67. 'message' => "Password plugin: Unable to execute $curdir/chgvirtualminpasswd"
  68. ), true, false);
  69. }
  70. return PASSWORD_ERROR;
  71. }
  72. }