|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Roundcube Password Driver for Plesk-RPC.
|
|
|
|
|
*
|
|
|
|
@ -7,7 +8,6 @@
|
|
|
|
|
*
|
|
|
|
|
* @author Cyrill von Wattenwyl <cyrill.vonwattenwyl@adfinis-sygroup.ch>
|
|
|
|
|
* @copyright Adfinis SyGroup AG, 2014
|
|
|
|
|
* @license GNU GPL v3
|
|
|
|
|
*
|
|
|
|
|
* Config needed:
|
|
|
|
|
* $config['password_plesk_host'] = '10.0.0.5';
|
|
|
|
@ -16,6 +16,18 @@
|
|
|
|
|
* $config['password_plesk_rpc_port'] = 8443;
|
|
|
|
|
* $config['password_plesk_rpc_path'] = enterprise/control/agent.php;
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -25,20 +37,20 @@
|
|
|
|
|
*
|
|
|
|
|
* @author Cyrill von Wattenwyl <cyrill.vonwattenwyl@adfinis-sygroup.ch>
|
|
|
|
|
*/
|
|
|
|
|
class rcube_plesk_password {
|
|
|
|
|
|
|
|
|
|
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 <cyrill.vonwattenwyl@adfinis-sygroup.ch>
|
|
|
|
|
* @param string $curpass current password
|
|
|
|
|
* @param string $newpass new password
|
|
|
|
|
* @returns PASSWORD_SUCCESS|PASSWORD_ERROR
|
|
|
|
|
* @param string $curpass Current password
|
|
|
|
|
* @param string $newpass New password
|
|
|
|
|
* @returns int PASSWORD_SUCCESS|PASSWORD_ERROR
|
|
|
|
|
*/
|
|
|
|
|
function save($currpass, $newpass) {
|
|
|
|
|
|
|
|
|
|
function save($currpass, $newpass)\
|
|
|
|
|
{
|
|
|
|
|
// get config
|
|
|
|
|
$rcmail = rcmail::get_instance();
|
|
|
|
|
$host = $rcmail->config->get('password_plesk_host');
|
|
|
|
@ -61,7 +73,6 @@ class rcube_plesk_password {
|
|
|
|
|
|
|
|
|
|
return PASSWORD_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -75,12 +86,11 @@ class rcube_plesk_password {
|
|
|
|
|
*
|
|
|
|
|
* @author Cyrill von Wattenwyl <cyrill.vonwattenwyl@adfinis-sygroup.ch>
|
|
|
|
|
*/
|
|
|
|
|
class plesk_rpc {
|
|
|
|
|
|
|
|
|
|
class plesk_rpc
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* init plesk-rpc via curl
|
|
|
|
|
*
|
|
|
|
|
* @author Cyrill von Wattenwyl <cyrill.vonwattenwyl@adfinis-sygroup.ch>
|
|
|
|
|
* @param string $host plesk host
|
|
|
|
|
* @param string $port plesk rpc port
|
|
|
|
|
* @param string $path plesk rpc path
|
|
|
|
@ -88,14 +98,17 @@ class plesk_rpc {
|
|
|
|
|
* @param string $user plesk password
|
|
|
|
|
* @returns void
|
|
|
|
|
*/
|
|
|
|
|
function init($host, $port, $path, $user, $pass) {
|
|
|
|
|
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);
|
|
|
|
@ -103,15 +116,14 @@ class plesk_rpc {
|
|
|
|
|
curl_setopt($this->curl, CURLOPT_URL , $url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* send a request to the plesk
|
|
|
|
|
*
|
|
|
|
|
* @author Cyrill von Wattenwyl <cyrill.vonwattenwyl@adfinis-sygroup.ch>
|
|
|
|
|
* @param string $packet XML-Packet to send to Plesk
|
|
|
|
|
* @returns bool request was successfull or not
|
|
|
|
|
*/
|
|
|
|
|
function send_request($packet) {
|
|
|
|
|
function send_request($packet)
|
|
|
|
|
{
|
|
|
|
|
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
|
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $packet);
|
|
|
|
|
$retval = curl_exec($this->curl);
|
|
|
|
@ -119,25 +131,20 @@ class plesk_rpc {
|
|
|
|
|
return $retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* close curl
|
|
|
|
|
*
|
|
|
|
|
* @author Cyrill von Wattenwyl <cyrill.vonwattenwyl@adfinis-sygroup.ch>
|
|
|
|
|
* @returns void
|
|
|
|
|
*/
|
|
|
|
|
function destroy(){
|
|
|
|
|
curl_close($this->curl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates an Initial SimpleXML-Object for Plesk-RPC
|
|
|
|
|
*
|
|
|
|
|
* @author Cyrill von Wattenwyl <cyrill.vonwattenwyl@adfinis-sygroup.ch>
|
|
|
|
|
* @returns object SimpleXML object
|
|
|
|
|
*/
|
|
|
|
|
function get_request_obj(){
|
|
|
|
|
function get_request_obj()
|
|
|
|
|
{
|
|
|
|
|
$request = new SimpleXMLElement("<packet></packet>");
|
|
|
|
|
$request->addAttribute("version", "1.6.3.0");
|
|
|
|
|
|
|
|
|
@ -147,11 +154,11 @@ class plesk_rpc {
|
|
|
|
|
/**
|
|
|
|
|
* Get all hosting-informations of a domain
|
|
|
|
|
*
|
|
|
|
|
* @author Cyrill von Wattenwyl <cyrill.vonwattenwyl@adfinis-sygroup.ch>
|
|
|
|
|
* @param string $domain domain-name
|
|
|
|
|
* @returns object SimpleXML object
|
|
|
|
|
*/
|
|
|
|
|
function domain_info($domain){
|
|
|
|
|
function domain_info($domain)
|
|
|
|
|
{
|
|
|
|
|
// build xml
|
|
|
|
|
$request = $this->get_request_obj();
|
|
|
|
|
$site = $request->addChild("site");
|
|
|
|
@ -176,28 +183,29 @@ class plesk_rpc {
|
|
|
|
|
/**
|
|
|
|
|
* Get psa-id of a domain
|
|
|
|
|
*
|
|
|
|
|
* @author Cyrill von Wattenwyl <cyrill.vonwattenwyl@adfinis-sygroup.ch>
|
|
|
|
|
* @param string $domain domain-name
|
|
|
|
|
*
|
|
|
|
|
* @returns bool|int false if failed and integer if successed
|
|
|
|
|
*/
|
|
|
|
|
function get_domain_id($domain){
|
|
|
|
|
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 <cyrill.vonwattenwyl@adfinis-sygroup.ch>
|
|
|
|
|
* @param string $mailbox full email-adress (user@domain.tld)
|
|
|
|
|
* @param string $newpass new password of mailbox
|
|
|
|
|
*
|
|
|
|
|
* @returns bool
|
|
|
|
|
*/
|
|
|
|
|
function change_mailbox_password($mailbox, $newpass){
|
|
|
|
|
|
|
|
|
|
function change_mailbox_password($mailbox, $newpass)
|
|
|
|
|
{
|
|
|
|
|
list($user, $domain) = explode("@", $mailbox);
|
|
|
|
|
$domain_id = $this->get_domain_id($domain);
|
|
|
|
|
|
|
|
|
@ -231,4 +239,3 @@ class plesk_rpc {
|
|
|
|
|
return $res == "ok";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|