-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Password plugin, cPanel driver #5252
Changes from all commits
a4c6aec
16d5dcb
6651a6c
e34e267
8042955
7ed0d33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,18 @@ public function save($curpas, $newpass) | |
// Setup the xmlapi connection | ||
$this->xmlapi = new xmlapi($rcmail->config->get('password_cpanel_host')); | ||
$this->xmlapi->set_port($rcmail->config->get('password_cpanel_port')); | ||
$this->xmlapi->password_auth($this->cuser, $rcmail->config->get('password_cpanel_password')); | ||
// Hash auth | ||
if (!empty($cpanel_hash = $rcmail->config->get('password_cpanel_hash'))) { | ||
$this->xmlapi->hash_auth( $this->cuser, $cpanel_hash); | ||
} | ||
// Pass auth | ||
else if (!empty($cpanel_password = $rcmail->config->get('password_cpanel_password'))) { | ||
$this->xmlapi->hash_auth( $this->cuser, $cpanel_password); | ||
} | ||
else { | ||
return false; | ||
} | ||
|
||
$this->xmlapi->set_output('json'); | ||
$this->xmlapi->set_debug(0); | ||
|
||
|
@@ -70,8 +81,16 @@ function setPassword($address, $password) | |
} | ||
|
||
$data['password'] = $password; | ||
|
||
// Get the cPanel user | ||
$query = $this->xmlapi->listaccts( 'domain', $data['domain'] ); | ||
$query = json_decode( $query, true ); | ||
if ( $query['status'] != 1 ) { | ||
return false; | ||
} | ||
$cpanel_user = $query['acct'][0]['user']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have username from config, why we need to overwrite it here? I don't know cPanel API, but can you call listaccts() when using user/password auth. Do we need it at all when not using hash auth? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's required whether the password or the hash is used. The username retrieved from config is the API user (root user or reseller user). The cPanel user needs to be retrieved using listaccts() because otherwise, the following error will be returned:
(Even if authenticated as root). This can easily be tested on a cPanel server, using the following example URL:
|
||
|
||
$query = $this->xmlapi->api2_query($this->cuser, 'Email', 'passwdpop', $data); | ||
$query = $this->xmlapi->api2_query($cpanel_user, 'Email', 'passwdpop', $data); | ||
$query = json_decode($query, true); | ||
$result = $query['cpanelresult']['data'][0]; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, would be nice to return error code and message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too familiar with the error handling. Would it be done using the following?
$rcmail->output->command('display_message', 'message, 'error');