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.

cpanel.php 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 http://trac.roundcube.net/ticket/1487015
  12. *
  13. * This driver has been tested with o2switch hosting and seems to work fine.
  14. *
  15. * @version 3.0
  16. * @author Christian Chech <christian@chech.fr>
  17. *
  18. * Copyright (C) 2005-2013, 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. // Setup the xmlapi connection
  41. $this->xmlapi = new xmlapi($rcmail->config->get('password_cpanel_host'));
  42. $this->xmlapi->set_port($rcmail->config->get('password_cpanel_port'));
  43. $this->xmlapi->password_auth($this->cuser, $rcmail->config->get('password_cpanel_password'));
  44. $this->xmlapi->set_output('json');
  45. $this->xmlapi->set_debug(0);
  46. return $this->setPassword($_SESSION['username'], $newpass);
  47. }
  48. /**
  49. * Change email account password
  50. *
  51. * @param string $address Email address/username
  52. * @param string $password Email account password
  53. *
  54. * @return int|array Operation status
  55. */
  56. function setPassword($address, $password)
  57. {
  58. if (strpos($address, '@')) {
  59. list($data['email'], $data['domain']) = explode('@', $address);
  60. }
  61. else {
  62. list($data['email'], $data['domain']) = array($address, '');
  63. }
  64. $data['password'] = $password;
  65. $query = $this->xmlapi->api2_query($this->cuser, 'Email', 'passwdpop', $data);
  66. $query = json_decode($query, true);
  67. $result = $query['cpanelresult']['data'][0];
  68. if ($result['result'] == 1) {
  69. return PASSWORD_SUCCESS;
  70. }
  71. if ($result['reason']) {
  72. return array(
  73. 'code' => PASSWORD_ERROR,
  74. 'message' => $result['reason'],
  75. );
  76. }
  77. return PASSWORD_ERROR;
  78. }
  79. }