4 * cPanel Password Driver
6 * Driver that adds functionality to change the users cPanel password.
7 * The cPanel PHP API code has been taken from: http://www.phpclasses.org/browse/package/3534.html
9 * This driver has been tested with Hostmonster hosting and seems to work fine.
13 * @author Fulvio Venturelli <fulvio@venturelli.org>
18 function HTTP($host, $username, $password, $port, $ssl, $theme)
20 $this->ssl = $ssl ? 'ssl://' : '';
21 $this->username = $username;
22 $this->password = $password;
23 $this->theme = $theme;
24 $this->auth = base64_encode($username . ':' . $password);
27 $this->path = '/frontend/' . $theme . '/';
30 function getData($url, $data = '')
32 $url = $this->path . $url;
36 foreach($data as $key=>$value)
38 $url .= urlencode($key) . '=' . urlencode($value) . '&';
40 $url = substr($url, 0, -1);
43 $fp = fsockopen($this->ssl . $this->host, $this->port);
48 $out = 'GET ' . $url . ' HTTP/1.0' . "\r\n";
49 $out .= 'Authorization: Basic ' . $this->auth . "\r\n";
50 $out .= 'Connection: Close' . "\r\n\r\n";
54 $response .= @fgets($fp);
64 function emailAccount($host, $username, $password, $port, $ssl, $theme, $address)
66 $this->HTTP = new HTTP($host, $username, $password, $port, $ssl, $theme);
67 if(strpos($address, '@'))
69 list($this->email, $this->domain) = explode('@', $address);
73 list($this->email, $this->domain) = array($address, '');
78 * Change email account password
80 * Returns true on success or false on failure.
81 * @param string $password email account password
84 function setPassword($password)
86 $data['email'] = $this->email;
87 $data['domain'] = $this->domain;
88 $data['password'] = $password;
89 $response = $this->HTTP->getData('mail/dopasswdpop.html', $data);
90 if(strpos($response, 'success') && !strpos($response, 'failure'))
99 function password_save($curpas, $newpass)
101 $rcmail = rcmail::get_instance();
103 // Create a cPanel email object
104 $cPanel = new emailAccount($rcmail->config->get('password_cpanel_host'),
105 $rcmail->config->get('password_cpanel_username'),
106 $rcmail->config->get('password_cpanel_password'),
107 $rcmail->config->get('password_cpanel_port'),
108 $rcmail->config->get('password_cpanel_ssl'),
109 $rcmail->config->get('password_cpanel_theme'),
110 $_SESSION['username'] );
112 if ($cPanel->setPassword($newpass)){
113 return PASSWORD_SUCCESS;
117 return PASSWORD_ERROR;