From 12967c776ca7de75a4807b093f6be1cc33b05037 Mon Sep 17 00:00:00 2001 From: Cyrill von Wattenwyl Date: Thu, 8 May 2014 16:43:28 +0200 Subject: Added Plesk-Driver to Password-Plugin This Driver allows to change Passwords via Plesk RPC-API --- plugins/password/config.inc.php.dist | 21 ++++ plugins/password/drivers/plesk.php | 234 +++++++++++++++++++++++++++++++++++ 2 files changed, 255 insertions(+) create mode 100644 plugins/password/drivers/plesk.php (limited to 'plugins') diff --git a/plugins/password/config.inc.php.dist b/plugins/password/config.inc.php.dist index 8c83dd703..335ef7f2b 100644 --- a/plugins/password/config.inc.php.dist +++ b/plugins/password/config.inc.php.dist @@ -361,3 +361,24 @@ $config['password_expect_params'] = ''; $config['password_smb_host'] = 'localhost'; // Location of smbpasswd binary $config['password_smb_cmd'] = '/usr/bin/smbpasswd'; + + + +// Plesk/PPA Driver options +// -------------------- +// You need to allow RCP for IP of roundcube-server in Plesk/PPA Panel + +// Plesk RCP Host +$config['password_plesk_host'] = '10.0.0.5'; + +// Plesk RPC Username +$config['password_plesk_user'] = 'admin'; + +// Plesk RPC Password +$config['password_plesk_pass'] = 'password'; + +// Plesk RPC Port +$config['password_plesk_rcp_port'] = 8443; + +// Plesk RPC Path +$config['password_plesk_rcp_path'] = enterprise/control/agent.php; diff --git a/plugins/password/drivers/plesk.php b/plugins/password/drivers/plesk.php new file mode 100644 index 000000000..c5298a457 --- /dev/null +++ b/plugins/password/drivers/plesk.php @@ -0,0 +1,234 @@ + + * @copyright Adfinis SyGroup AG, 2014 + * @license GNU GPL v3 + * + * Config needed: + * $config['password_plesk_host'] = '192.168.0.15'; + * $config['password_plesk_user'] = 'admin'; + * $config['password_plesk_pass'] = 'yourRPCpass'; + * $config['password_plesk_rcp_port'] = 8443; + * $config['password_plesk_rcp_path'] = enterprise/control/agent.php; + * + */ + +/** + * Roundcube Password Driver Class + * + * See {ROUNDCUBE_ROOT}/plugins/password/README for API description + * + * @author Cyrill von Wattenwyl + */ +class rcube_plesk_password { + + /** + * this method is called from roundcube to change the password + * + * roundcube allready validated the old password so we just need to change it at this point + * + * @author Cyrill von Wattenwyl + * @param string $curpass current password + * @param string $newpass new password + * @returns PASSWORD_SUCCESS|PASSWORD_ERROR + */ + function save($currpass, $newpass) { + + // get config + $rcmail = rcmail::get_instance(); + $host = $rcmail->config->get('password_plesk_host'); + $user = $rcmail->config->get('password_plesk_user'); + $pass = $rcmail->config->get('password_plesk_pass'); + $port = $rcmail->config->get('password_plesk_rpc_port'); + $path = $rcmail->config->get('password_plesk_rpc_path'); + + // create plesk-object + $plesk = new plesk_rpc; + $plesk->init($host, $port, $path, $user, $pass); + + // try to change password and return the status + $result = $plesk->change_mailbox_password($_SESSION['username'], $newpass); + //$plesk->destroy(); + + if ($result) { + return PASSWORD_SUCCESS; + } + + return PASSWORD_ERROR; + } + +} + + +/** + * Plesk RPC-Class + * + * Striped down version of Plesk-RPC-Class + * Just functions for changing mail-passwords included + * + * Documentation of Plesk RPC-API: http://download1.parallels.com/Plesk/PP11/11.0/Doc/en-US/online/plesk-api-rpc/ + * + * @author Cyrill von Wattenwyl + */ +class plesk_rpc { + + /** + * init plesk-rpc via curl + * + * @author Cyrill von Wattenwyl + * @param string $host plesk host + * @param string $port plesk rpc port + * @param string $path plesk rpc path + * @param string $user plesk user + * @param string $user plesk password + * @returns void + */ + function init($host, $port, $path, $user, $pass) { + $headers = array( + sprintf("HTTP_AUTH_LOGIN: %s", $user), + sprintf("HTTP_AUTH_PASSWD: %s", $pass), + "Content-Type: text/xml" + ); + $url = sprintf("https://%s:%s/%s", $host, $port, $path); + $this->curl = curl_init(); + curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT , 5); + curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST , 0); + curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER , false); + curl_setopt($this->curl, CURLOPT_HTTPHEADER , $headers); + curl_setopt($this->curl, CURLOPT_URL , $url); + } + + + /** + * send a request to the plesk + * + * @author Cyrill von Wattenwyl + * @param string $packet XML-Packet to send to Plesk + * @returns bool request was successfull or not + */ + function send_request($packet) { + curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($this->curl, CURLOPT_POSTFIELDS, $packet); + $retval = curl_exec($this->curl); + + return $retval; + } + + + /** + * close curl + * + * @author Cyrill von Wattenwyl + * @returns void + */ + function destroy(){ + curl_close($this->curl); + } + + + /** + * Creates an Initial SimpleXML-Object for Plesk-RPC + * + * @author Cyrill von Wattenwyl + * @returns object SimpleXML object + */ + function get_request_obj(){ + $request = new SimpleXMLElement(""); + $request->addAttribute("version", "1.6.3.0"); + + return $request; + } + + /** + * Get all hosting-informations of a domain + * + * @author Cyrill von Wattenwyl + * @param string $domain domain-name + * @returns object SimpleXML object + */ + function domain_info($domain){ + // build xml + $request = $this->get_request_obj(); + $site = $request->addChild("site"); + $get = $site->addChild("get"); + $filter = $get->addChild("filter"); + + $filter->addChild("name", utf8_encode($domain)); + $dataset = $get->addChild("dataset"); + + $dataset->addChild("hosting"); + $packet = $request->asXML(); + + // send the request + $res = $this->send_request($packet); + + // make it to simple-xml-object + $xml = new SimpleXMLElement($res); + + return $xml; + } + + /** + * Get psa-id of a domain + * + * @author Cyrill von Wattenwyl + * @param string $domain domain-name + * @returns bool|int false if failed and integer if successed + */ + function get_domain_id($domain){ + $xml = $this->domain_info($domain); + $id = intval($xml->site->get->result->id); + $id = (is_int($id)) ? $id : false; + return $id; + } + + + /** + * Change Password of a mailbox + * + * @author Cyrill von Wattenwyl + * @param string $mailbox full email-adress (user@domain.tld) + * @param string $newpass new password of mailbox + * @returns bool + */ + function change_mailbox_password($mailbox, $newpass){ + + list($user, $domain) = explode("@", $mailbox); + $domain_id = $this->get_domain_id($domain); + + // if domain cannot be resolved to an id, do not continue + if (!$domain_id) { + return false; + } + + // build xml-packet + $request = $this -> get_request_obj(); + $mail = $request -> addChild("mail"); + $update = $mail -> addChild("update"); + $add = $update -> addChild("set"); + $filter = $add -> addChild("filter"); + $filter->addChild("site-id", $domain_id); + + $mailname = $filter->addChild("mailname"); + $mailname->addChild("name", $user); + + $password = $mailname->addChild("password"); + $password->addChild("value", $newpass); + $password->addChild("type", "plain"); + + $packet = $request->asXML(); + + // send the request to plesk + $res = $this->send_request($packet); + $xml = new SimpleXMLElement($res); + $res = strval($xml->mail->update->set->result->status); + + return $res == "ok"; + } +} + -- cgit v1.2.3 From 187fd666aa2f32dedfe544d69b7cb213698197f2 Mon Sep 17 00:00:00 2001 From: Cyrill von Wattenwyl Date: Mon, 12 May 2014 10:03:11 +0200 Subject: fixed typos and added section in README --- plugins/password/README | 22 ++++++++++++++++++++++ plugins/password/config.inc.php.dist | 4 ++-- plugins/password/drivers/plesk.php | 12 ++++++------ 3 files changed, 30 insertions(+), 8 deletions(-) (limited to 'plugins') diff --git a/plugins/password/README b/plugins/password/README index 262ebfd86..89ffeb320 100644 --- a/plugins/password/README +++ b/plugins/password/README @@ -43,6 +43,7 @@ 2.17. Expect (expect) 2.18. Samba (smb) 2.19. Vpopmail daemon (vpopmaild) + 2.20. Plesk (Plesk RPC-API) 3. Driver API @@ -311,6 +312,27 @@ Set $config['password_vpopmaild_port'] to the port of vpopmaild. + 2.20. Plesk (Plesk RPC-API) + --------------------------- + + Driver for changing Passwords via Plesk RPC-API. This Driver also works with + Parallels Plesk Automation (PPA). + + You need to allow the IP of the Roundcube-Server for RPC-Calls in the Panel. + + + Set $config['password_plesk_host'] to the Hostname / IP where Plesk runs + + Set your Admin or RPC User: $config['password_plesk_user'] + + Set the Password of the User: $config['password_plesk_pass'] + + Set $config['password_plesk_rpc_port'] for the RPC-Port. Usually its 8443 + + Set the RPC-Path in $config['password_plesk_rpc_path']. Normally this is: enterprise/control/agent.php; + + + 3. Driver API ------------- diff --git a/plugins/password/config.inc.php.dist b/plugins/password/config.inc.php.dist index 335ef7f2b..427d064a8 100644 --- a/plugins/password/config.inc.php.dist +++ b/plugins/password/config.inc.php.dist @@ -378,7 +378,7 @@ $config['password_plesk_user'] = 'admin'; $config['password_plesk_pass'] = 'password'; // Plesk RPC Port -$config['password_plesk_rcp_port'] = 8443; +$config['password_plesk_rpc_port'] = '8443'; // Plesk RPC Path -$config['password_plesk_rcp_path'] = enterprise/control/agent.php; +$config['password_plesk_rpc_path'] = 'enterprise/control/agent.php'; diff --git a/plugins/password/drivers/plesk.php b/plugins/password/drivers/plesk.php index c5298a457..6f646d229 100644 --- a/plugins/password/drivers/plesk.php +++ b/plugins/password/drivers/plesk.php @@ -10,11 +10,11 @@ * @license GNU GPL v3 * * Config needed: - * $config['password_plesk_host'] = '192.168.0.15'; - * $config['password_plesk_user'] = 'admin'; - * $config['password_plesk_pass'] = 'yourRPCpass'; - * $config['password_plesk_rcp_port'] = 8443; - * $config['password_plesk_rcp_path'] = enterprise/control/agent.php; + * $config['password_plesk_host'] = '10.0.0.5'; + * $config['password_plesk_user'] = 'admin'; + * $config['password_plesk_pass'] = 'pass'; + * $config['password_plesk_rpc_port'] = 8443; + * $config['password_plesk_rpc_path'] = enterprise/control/agent.php; * */ @@ -27,7 +27,7 @@ */ class rcube_plesk_password { - /** + /** * this method is called from roundcube to change the password * * roundcube allready validated the old password so we just need to change it at this point -- cgit v1.2.3 From 141d615f394853ceafe13ba79ac3043ed06e6013 Mon Sep 17 00:00:00 2001 From: Cyrill von Wattenwyl Date: Tue, 2 Sep 2014 11:21:25 +0200 Subject: Fixed merge conflicts --- plugins/password/config.inc.php.dist.orig | 397 ++++++++++++++++++++++++++++++ 1 file changed, 397 insertions(+) create mode 100644 plugins/password/config.inc.php.dist.orig (limited to 'plugins') diff --git a/plugins/password/config.inc.php.dist.orig b/plugins/password/config.inc.php.dist.orig new file mode 100644 index 000000000..7aeb3fd34 --- /dev/null +++ b/plugins/password/config.inc.php.dist.orig @@ -0,0 +1,397 @@ + /dev/null'; + + +// XMail Driver options +// --------------------- +$config['xmail_host'] = 'localhost'; +$config['xmail_user'] = 'YourXmailControlUser'; +$config['xmail_pass'] = 'YourXmailControlPass'; +$config['xmail_port'] = 6017; + + +// hMail Driver options +// ----------------------- +// Remote hMailServer configuration +// true: HMailserver is on a remote box (php.ini: com.allow_dcom = true) +// false: Hmailserver is on same box as PHP +$config['hmailserver_remote_dcom'] = false; +// Windows credentials +$config['hmailserver_server'] = array( + 'Server' => 'localhost', // hostname or ip address + 'Username' => 'administrator', // windows username + 'Password' => 'password' // windows user password +); + + +// Virtualmin Driver options +// ------------------------- +// Username format: +// 0: username@domain +// 1: username%domain +// 2: username.domain +// 3: domain.username +// 4: username-domain +// 5: domain-username +// 6: username_domain +// 7: domain_username +$config['password_virtualmin_format'] = 0; + + +// pw_usermod Driver options +// -------------------------- +// Use comma delimited exlist to disable password change for users +// Add the following line to visudo to tighten security: +// www ALL=NOPASSWORD: /usr/sbin/pw +$config['password_pw_usermod_cmd'] = 'sudo /usr/sbin/pw usermod -h 0 -n'; + + +// DBMail Driver options +// ------------------- +// Additional arguments for the dbmail-users call +$config['password_dbmail_args'] = '-p sha512'; + + +// Expect Driver options +// --------------------- +// Location of expect binary +$config['password_expect_bin'] = '/usr/bin/expect'; + +// Location of expect script (see helpers/passwd-expect) +$config['password_expect_script'] = ''; + +// Arguments for the expect script. See the helpers/passwd-expect file for details. +// This is probably a good starting default: +// -telent -host localhost -output /tmp/passwd.log -log /tmp/passwd.log +$config['password_expect_params'] = ''; + + +// smb Driver options +// --------------------- +// Samba host (default: localhost) +// Supported replacement variables: +// %n - hostname ($_SERVER['SERVER_NAME']) +// %t - hostname without the first part +// %d - domain (http hostname $_SERVER['HTTP_HOST'] without the first part) +$config['password_smb_host'] = 'localhost'; +// Location of smbpasswd binary +$config['password_smb_cmd'] = '/usr/bin/smbpasswd'; + +<<<<<<< HEAD + + +// Plesk/PPA Driver options +// -------------------- +// You need to allow RCP for IP of roundcube-server in Plesk/PPA Panel + +// Plesk RCP Host +$config['password_plesk_host'] = '10.0.0.5'; + +// Plesk RPC Username +$config['password_plesk_user'] = 'admin'; + +// Plesk RPC Password +$config['password_plesk_pass'] = 'password'; + +// Plesk RPC Port +$config['password_plesk_rpc_port'] = '8443'; + +// Plesk RPC Path +$config['password_plesk_rpc_path'] = 'enterprise/control/agent.php'; +======= +// gearman driver options +// --------------------- +// Gearman host (default: localhost) +$config['password_gearman_host'] = 'localhost'; +>>>>>>> ba084313bfc9c7a5a83e0611fe4376543cc1653d -- cgit v1.2.3 From 7dc269029d5f03e3ef9bf5d9f9fe787af3a85f63 Mon Sep 17 00:00:00 2001 From: Cyrill von Wattenwyl Date: Tue, 2 Sep 2014 11:48:55 +0200 Subject: removed unwanted file --- plugins/password/config.inc.php.dist.orig | 397 ------------------------------ 1 file changed, 397 deletions(-) delete mode 100644 plugins/password/config.inc.php.dist.orig (limited to 'plugins') diff --git a/plugins/password/config.inc.php.dist.orig b/plugins/password/config.inc.php.dist.orig deleted file mode 100644 index 7aeb3fd34..000000000 --- a/plugins/password/config.inc.php.dist.orig +++ /dev/null @@ -1,397 +0,0 @@ - /dev/null'; - - -// XMail Driver options -// --------------------- -$config['xmail_host'] = 'localhost'; -$config['xmail_user'] = 'YourXmailControlUser'; -$config['xmail_pass'] = 'YourXmailControlPass'; -$config['xmail_port'] = 6017; - - -// hMail Driver options -// ----------------------- -// Remote hMailServer configuration -// true: HMailserver is on a remote box (php.ini: com.allow_dcom = true) -// false: Hmailserver is on same box as PHP -$config['hmailserver_remote_dcom'] = false; -// Windows credentials -$config['hmailserver_server'] = array( - 'Server' => 'localhost', // hostname or ip address - 'Username' => 'administrator', // windows username - 'Password' => 'password' // windows user password -); - - -// Virtualmin Driver options -// ------------------------- -// Username format: -// 0: username@domain -// 1: username%domain -// 2: username.domain -// 3: domain.username -// 4: username-domain -// 5: domain-username -// 6: username_domain -// 7: domain_username -$config['password_virtualmin_format'] = 0; - - -// pw_usermod Driver options -// -------------------------- -// Use comma delimited exlist to disable password change for users -// Add the following line to visudo to tighten security: -// www ALL=NOPASSWORD: /usr/sbin/pw -$config['password_pw_usermod_cmd'] = 'sudo /usr/sbin/pw usermod -h 0 -n'; - - -// DBMail Driver options -// ------------------- -// Additional arguments for the dbmail-users call -$config['password_dbmail_args'] = '-p sha512'; - - -// Expect Driver options -// --------------------- -// Location of expect binary -$config['password_expect_bin'] = '/usr/bin/expect'; - -// Location of expect script (see helpers/passwd-expect) -$config['password_expect_script'] = ''; - -// Arguments for the expect script. See the helpers/passwd-expect file for details. -// This is probably a good starting default: -// -telent -host localhost -output /tmp/passwd.log -log /tmp/passwd.log -$config['password_expect_params'] = ''; - - -// smb Driver options -// --------------------- -// Samba host (default: localhost) -// Supported replacement variables: -// %n - hostname ($_SERVER['SERVER_NAME']) -// %t - hostname without the first part -// %d - domain (http hostname $_SERVER['HTTP_HOST'] without the first part) -$config['password_smb_host'] = 'localhost'; -// Location of smbpasswd binary -$config['password_smb_cmd'] = '/usr/bin/smbpasswd'; - -<<<<<<< HEAD - - -// Plesk/PPA Driver options -// -------------------- -// You need to allow RCP for IP of roundcube-server in Plesk/PPA Panel - -// Plesk RCP Host -$config['password_plesk_host'] = '10.0.0.5'; - -// Plesk RPC Username -$config['password_plesk_user'] = 'admin'; - -// Plesk RPC Password -$config['password_plesk_pass'] = 'password'; - -// Plesk RPC Port -$config['password_plesk_rpc_port'] = '8443'; - -// Plesk RPC Path -$config['password_plesk_rpc_path'] = 'enterprise/control/agent.php'; -======= -// gearman driver options -// --------------------- -// Gearman host (default: localhost) -$config['password_gearman_host'] = 'localhost'; ->>>>>>> ba084313bfc9c7a5a83e0611fe4376543cc1653d -- cgit v1.2.3