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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * cPanel Password Driver
  4. *
  5. * Driver that adds functionality to change the users cPanel password.
  6. * Originally written by Fulvio Venturelli <fulvio@venturelli.org>
  7. *
  8. * Completely rewritten using the cPanel API2 call Email::passwdpop
  9. * as opposed to the original coding against the UI, which is a fragile method that
  10. * makes the driver to always return a failure message for any language other than English
  11. * see https://github.com/roundcube/roundcubemail/issues/3063
  12. *
  13. * This driver has been tested with o2switch hosting and seems to work fine.
  14. *
  15. * @version 3.1
  16. * @author Christian Chech <christian@chech.fr>
  17. *
  18. * Copyright (C) 2005-2016, The Roundcube Dev Team
  19. *
  20. * This program is free software: you can redistribute it and/or modify
  21. * it under the terms of the GNU General Public License as published by
  22. * the Free Software Foundation, either version 3 of the License, or
  23. * (at your option) any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License
  31. * along with this program. If not, see http://www.gnu.org/licenses/.
  32. */
  33. class rcube_cpanel_password
  34. {
  35. public function save($curpas, $newpass)
  36. {
  37. require_once 'xmlapi.php';
  38. $rcmail = rcmail::get_instance();
  39. $this->cuser = $rcmail->config->get('password_cpanel_username');
  40. $cpanel_host = $rcmail->config->get('password_cpanel_host');
  41. $cpanel_port = $rcmail->config->get('password_cpanel_port');
  42. $cpanel_hash = $rcmail->config->get('password_cpanel_hash');
  43. $cpanel_pass = $rcmail->config->get('password_cpanel_password');
  44. // Setup the xmlapi connection
  45. $this->xmlapi = new xmlapi($cpanel_host);
  46. $this->xmlapi->set_port($cpanel_port);
  47. // Hash auth
  48. if (!empty($cpanel_hash)) {
  49. $this->xmlapi->hash_auth($this->cuser, $cpanel_hash);
  50. }
  51. // Pass auth
  52. else if (!empty($cpanel_pass)) {
  53. $this->xmlapi->password_auth($this->cuser, $cpanel_pass);
  54. }
  55. else {
  56. return PASSWORD_ERROR;
  57. }
  58. $this->xmlapi->set_output('json');
  59. $this->xmlapi->set_debug(0);
  60. return $this->setPassword($_SESSION['username'], $newpass);
  61. }
  62. /**
  63. * Change email account password
  64. *
  65. * @param string $address Email address/username
  66. * @param string $password Email account password
  67. *
  68. * @return int|array Operation status
  69. */
  70. function setPassword($address, $password)
  71. {
  72. if (strpos($address, '@')) {
  73. list($data['email'], $data['domain']) = explode('@', $address);
  74. }
  75. else {
  76. list($data['email'], $data['domain']) = array($address, '');
  77. }
  78. $data['password'] = $password;
  79. // Get the cPanel user
  80. $query = $this->xmlapi->listaccts('domain', $data['domain']);
  81. $query = json_decode($query, true);
  82. if ( $query['status'] != 1) {
  83. return false;
  84. }
  85. $cpanel_user = $query['acct'][0]['user'];
  86. $query = $this->xmlapi->api2_query($cpanel_user, 'Email', 'passwdpop', $data);
  87. $query = json_decode($query, true);
  88. $result = $query['cpanelresult']['data'][0];
  89. if ($result['result'] == 1) {
  90. return PASSWORD_SUCCESS;
  91. }
  92. if ($result['reason']) {
  93. return array(
  94. 'code' => PASSWORD_ERROR,
  95. 'message' => $result['reason'],
  96. );
  97. }
  98. return PASSWORD_ERROR;
  99. }
  100. }