commit | author | age
|
48e9c1
|
1 |
<?php |
T |
2 |
|
|
3 |
/** |
|
4 |
* cPanel Password Driver |
|
5 |
* |
|
6 |
* Driver that adds functionality to change the users cPanel password. |
30ff85
|
7 |
* Originally written by Fulvio Venturelli <fulvio@venturelli.org> |
48e9c1
|
8 |
* |
30ff85
|
9 |
* Completely rewritten using the cPanel API2 call Email::passwdpop |
AM |
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 http://trac.roundcube.net/ticket/1487015 |
48e9c1
|
13 |
* |
30ff85
|
14 |
* This driver has been tested with o2switch hosting and seems to work fine. |
AM |
15 |
* |
|
16 |
* @version 3.0 |
|
17 |
* @author Christian Chech <christian@chech.fr> |
48e9c1
|
18 |
*/ |
T |
19 |
|
|
20 |
class rcube_cpanel_password |
|
21 |
{ |
|
22 |
public function save($curpas, $newpass) |
|
23 |
{ |
30ff85
|
24 |
require_once 'xmlapi.php'; |
AM |
25 |
|
48e9c1
|
26 |
$rcmail = rcmail::get_instance(); |
T |
27 |
|
30ff85
|
28 |
$this->cuser = $rcmail->config->get('password_cpanel_username'); |
48e9c1
|
29 |
|
30ff85
|
30 |
// Setup the xmlapi connection |
AM |
31 |
$this->xmlapi = new xmlapi($rcmail->config->get('password_cpanel_host')); |
|
32 |
$this->xmlapi->set_port($rcmail->config->get('password_cpanel_port')); |
|
33 |
$this->xmlapi->password_auth($this->cuser, $rcmail->config->get('password_cpanel_password')); |
|
34 |
$this->xmlapi->set_output('json'); |
|
35 |
$this->xmlapi->set_debug(0); |
|
36 |
|
|
37 |
if ($this->setPassword($_SESSION['username'], $newpass)) { |
48e9c1
|
38 |
return PASSWORD_SUCCESS; |
T |
39 |
} |
|
40 |
else { |
|
41 |
return PASSWORD_ERROR; |
d6938b
|
42 |
} |
AM |
43 |
} |
48e9c1
|
44 |
|
T |
45 |
/** |
|
46 |
* Change email account password |
|
47 |
* |
|
48 |
* Returns true on success or false on failure. |
|
49 |
* @param string $password email account password |
|
50 |
* @return bool |
|
51 |
*/ |
30ff85
|
52 |
function setPassword($address, $password) |
d6938b
|
53 |
{ |
30ff85
|
54 |
if (strpos($address, '@')) { |
AM |
55 |
list($data['email'], $data['domain']) = explode('@', $address); |
|
56 |
} |
|
57 |
else { |
|
58 |
list($data['email'], $data['domain']) = array($address, ''); |
|
59 |
} |
d6938b
|
60 |
|
30ff85
|
61 |
$data['password'] = $password; |
AM |
62 |
|
|
63 |
$query = $this->xmlapi->api2_query($this->cuser, 'Email', 'passwdpop', $data); |
|
64 |
$query = json_decode($query, true); |
|
65 |
|
|
66 |
if ($query['cpanelresult']['data'][0]['result'] == 1) { |
d6938b
|
67 |
return true; |
AM |
68 |
} |
30ff85
|
69 |
|
d6938b
|
70 |
return false; |
AM |
71 |
} |
48e9c1
|
72 |
} |