From af8e2b64f81982f0fdfaf284f6c6434e06c996f2 Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Tue, 22 Mar 2016 21:43:25 +0100 Subject: [PATCH] Added Passwd Driver for ISPConfig SOAP API --- passwd/config/backends.php | 22 +++++++ passwd/lib/Driver/Ispconfig.php | 105 ++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) mode change 100644 => 100755 passwd/config/backends.php create mode 100755 passwd/lib/Driver/Ispconfig.php diff --git a/passwd/config/backends.php b/passwd/config/backends.php old mode 100644 new mode 100755 index e34d3394d2e..33657a0e477 --- a/passwd/config/backends.php +++ b/passwd/config/backends.php @@ -20,6 +20,7 @@ * - adsi: ADSI COM interface. * - expect: Expect script. * - horde: Horde authentication driver. + * - ispconfig: ISPConfig SOAP Server. * - ldap: LDAP server. * - pine: Pine-encoded file. * - poppassd: Poppassd server. @@ -551,3 +552,24 @@ ), )), ); + +/* ISPConfig Example */ +$backends['ispconfig'] = array( + 'disabled' => true, + 'name' => 'ISPConfig Server', + 'driver' => 'Ispconfig', + 'policy' => array( + 'minLength' => 7, + 'maxLength' => 64, + 'maxSpace' => 0, + 'minNumeric' => 1, + ), + 'params' => array( + 'soap_uri' => 'http://ispconfig-webinterface.example.com:8080/remote/', + // This user must be created in the ISPConfig webinterface + // under System -> Remote Users. The required permissions + // ("functions") is "mail user functions" only. + 'soap_user' => 'horde', + 'soap_pass' => 'secret', + ), +); diff --git a/passwd/lib/Driver/Ispconfig.php b/passwd/lib/Driver/Ispconfig.php new file mode 100755 index 00000000000..04345dc5278 --- /dev/null +++ b/passwd/lib/Driver/Ispconfig.php @@ -0,0 +1,105 @@ + + * @category Horde + * @copyright 2009-2016 Horde LLC + * @license http://www.horde.org/licenses/gpl GPL + * @package Passwd + */ +class Passwd_Driver_Ispconfig extends Passwd_Driver +{ + /** + */ + public function __construct(array $params = array()) + { + // Default ISPConfig encryption settings + parent::__construct(array_merge(array( + 'encryption' => 'crypt-md5', + 'show_encryption' => false, + ), $params)); + + if (!class_exists('SoapClient')) { + throw new Passwd_Exception('You need the soap PHP extension to use this driver.'); + } + if (empty($this->_params['soap_uri']) || + empty($this->_params['soap_user']) ) { + throw new Passwd_Exception('The Passwd Ispconfig driver is not properly configured, edit your passwd/config/backends.local.php.'); + } + } + /** + */ + protected function _changePassword($user, $oldpass, $newpass) + { + // Connect + $soap_uri = $this->_params['soap_uri']; + $client = new SoapClient(null, array( + 'location' => $soap_uri . 'index.php', + 'uri' => $soap_uri)); + + // Login + try { + if (!$session_id = $client->login( + $this->_params['soap_user'], + $this->_params['soap_pass'])) { + throw new Passwd_Exception( + sprintf(_("Login to %s failed."), $soap_uri)); + } + } catch (SoapFault $e) { + throw new Passwd_Exception($e); + } + + // Get user information + try { + $users = $client->mail_user_get( + $session_id, + array('login' => $user)); + } catch (SoapFault $e) { + throw new Passwd_Exception($e); + } + if (count($users) != 1) { + throw new Passwd_Exception( + sprintf(_("%d users with login %s found, one expected."), + count($users), + $user)); + } + $user = $users[0]; + + // Check the passwords match + $this->_comparePasswords($user['password'], $oldpass); + + // Set new password + $user['password'] = $newpass; + + // Save information + try { + $client->mail_user_update( + $session_id, $user['client_id'], + $user['mailuser_id'], $user); + } catch (SoapFault $e) { + throw new Passwd_Exception($e); + } + + // Logout + try { + $client->logout( + $session_id); + } catch (SoapFault $e) { + throw new Passwd_Exception($e); + } + + + } +} \ No newline at end of file