Skip to content

Commit

Permalink
Added Passwd Driver for ISPConfig SOAP API
Browse files Browse the repository at this point in the history
  • Loading branch information
tbnobody committed Mar 22, 2016
1 parent bb5ef07 commit af8e2b6
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
22 changes: 22 additions & 0 deletions passwd/config/backends.php 100644 → 100755
Expand Up @@ -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.
Expand Down Expand Up @@ -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',
),
);
105 changes: 105 additions & 0 deletions passwd/lib/Driver/Ispconfig.php
@@ -0,0 +1,105 @@
<?php
/**
* Copyright 2009-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @category Horde
* @copyright 2009-2016 Horde LLC
* @license http://www.horde.org/licenses/gpl GPL
* @package Passwd
*/
/**
* Changes a email password using the IspConfig 3 API.
*
* @author Thomas Basler <tbasler@oprago.com>
* @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);
}


}
}

0 comments on commit af8e2b6

Please sign in to comment.