Finding account username from parked domain
Hi all
Context:
I've got roundcube installed on our server separate to the default cPanel installation. It serves all sites on our server. However this is an API question rather than a roundcube question.
I've just employed their password plugin which makes use of the cpanel api2. However it's only really designed to work with a single cPanel account. i.e. it doesn't cope with multiple accounts as it needs to know the username of the account which owns the email address whose password you need to change.
I've made modifications to their code to achieve this successfully. I'm not connecting to port 2087 with the server admin account rather than an individual account. I'm searching listaccts for the domain of the email address and then using the returned username in passwdpop to update the users password.
Here's their code
[url=http://trac.roundcube.net/browser/github/plugins/password/drivers/cpanel.php]cpanel.php in github/plugins/password/drivers
Here are my modifications
[PHP]
class rcube_cpanel_password
{
public function save($curpas, $newpass)
{
require_once 'xmlapi.php';
$rcmail = rcmail::get_instance();
// 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($rcmail->config->get('password_cpanel_username'), $rcmail->config->get('password_cpanel_password'));
$this->xmlapi->set_output('json');
$this->xmlapi->set_debug(1);
if ($this->setPassword($_SESSION['username">, $newpass)) {
return PASSWORD_SUCCESS;
}
else {
return PASSWORD_ERROR;
}
}
/**
* Change email account password
*
* Returns true on success or false on failure.
* @param string $password email account password
* @return bool
*/
function setPassword($address, $password)
{
if (strpos($address, '@')) {
list($data['email">, $data['domain">) = explode('@', $address);
}
else {
list($data['email">, $data['domain">) = array($address, '');
}
$data['password"> = $password;
$current_account = $this->xmlapi->listaccts('domain',$data['domain">);
$current_account = json_decode($current_account, true);
$this->cuser = $current_account['acct">[0]['user">;
$query = $this->xmlapi->api2_query($this->cuser, 'Email', 'passwdpop', $data);
$query = json_decode($query, true);
if ($query['cpanelresult">['data">[0]['result"> == 1) {
return true;
}
return false;
}
}
[/PHP]
The main change is that once I've got the domain from the email address, I find the account username using listaccts by searching by domain then I retrieve the user from the response.
[PHP]$current_account = $this->xmlapi->listaccts('domain',$data['domain">);[/PHP]
This works perfectly where the email domain is the same as the main domain on the account. However it doesn't work where the domain is parked. This is the case for a number of our accounts.
Does anyone know of a way in the API to find the main domain or user from a parked domain? listparkeddomains doesn't look like it will do the job.
Or perhaps there is a way to access passwdpop without knowing the username of the account?
Many thanks,
Matt
Please sign in to leave a comment.
Comments
0 comments