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. This is an API question rather than a roundcube question.
I've just employed their password plugin (it allows users to change their own passwords) 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. As it stands, you hardcode the username and password of the cpanel account in their config.
I've modified their code to achieve this successfully. I'm now connecting to port 2087 as the server admin account (not an individual account user) so I can make changes to all accounts. I'm also querying the listaccts search to find the username for the email domain in question which I need to make the call to passwdpop.
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's a way to call passwdpop which means I don't need the username of the account.
Many thanks,
Matt
-
Hello :) This thread is older but it still might be helpful: Find User of Addon Domain The updated documentation URL is: WHM API 1 - domainuserdata Thank you. 0 -
Thank you Michael That's exactly what I needed. Final code here for reference. I'll pass onto the original author / roundcube for consideration [PHP] /** * cPanel Password Driver * * 3.0 * Driver that adds functionality to change the users cPanel password. * Originally written by Fulvio Venturelli * * Completely rewritten using the cPanel API2 call Email::passwdpop * as opposed to the original coding against the UI, which is a fragile method that * makes the driver to always return a failure message for any language other than English * see http://trac.roundcube.net/ticket/1487015 * * This driver has been tested with o2switch hosting and seems to work fine. * * 3.1 * I've made changes to the 3.1 code to work for multiple accounts. Previously the cPanel username & password were stored * For this version, the WHM username & password should be stored. Then any user from any domain accessing this webmail can modify their passwords. * * * @version 3.1 * @author Christian Chech * @author Matt Moore */ 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->domainuserdata($data['domain">); $current_account = json_decode($current_account, true); $this->cuser = $current_account['userdata">['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] 0
Please sign in to leave a comment.
Comments
2 comments