comparison plugins/password/drivers/cpanel.php @ 0:1e000243b222

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