From 5157a980082cbfbeab06cc7de477f8da8d3fe9f1 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Thu, 2 Sep 2010 18:21:59 +0000 Subject: [PATCH] password sync for self service --- lam/lib/modules/asteriskAccount.inc | 43 +++++++++++++++++++++++++++ lam/lib/modules/asteriskVoicemail.inc | 35 ++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/lam/lib/modules/asteriskAccount.inc b/lam/lib/modules/asteriskAccount.inc index ac638f4a..d5be7f20 100644 --- a/lam/lib/modules/asteriskAccount.inc +++ b/lam/lib/modules/asteriskAccount.inc @@ -73,6 +73,10 @@ class asteriskAccount extends baseModule implements passwordService { 'AstAccountRealmedPassword', 'AstAccountContext'); // icon $return['icon'] = 'asterisk.png'; + // self service + $return['selfServiceFieldSettings'] = array( + 'syncAsteriskPassword' => _('Sync Asterisk password with Unix password'), + ); // help $return['help'] = array( 'AstAccountCallerID' => array( @@ -104,6 +108,14 @@ class asteriskAccount extends baseModule implements passwordService { array('kind' => 'help', 'value' => 'AsteriskRealm') ) ); + // self service options + $return['selfServiceSettings'] = array( + array( + array('kind' => 'text', 'text' => _('Asterisk realm')), + array('kind' => 'input', 'name' => 'asteriskAccount_AsteriskRealm', 'type' => 'text', 'size' => '30', 'maxlength' => '255'), + array('kind' => 'help', 'value' => 'AsteriskRealm') + ) + ); // profile options $return['profile_options'] = array( array( @@ -405,6 +417,37 @@ class asteriskAccount extends baseModule implements passwordService { return "{MD5}" . md5($password); } + /** + * Checks if all input values are correct and returns the LDAP commands which should be executed. + * + * @param string $fields input fields + * @param array $attributes LDAP attributes + * @return array messages and LDAP commands (array('messages' => array(), 'add' => array(), 'del' => array(), 'mod' => array())) + */ + function checkSelfServiceOptions($fields, $attributes) { + $return = array('messages' => array(), 'add' => array(), 'del' => array(), 'mod' => array()); + if (!in_array_ignore_case('AsteriskSIPUser', $attributes['objectClass'])) { + return $return; + } + if (isset($_POST['posixAccount_password']) && ($_POST['posixAccount_password'] != '')) { + if ($_POST['posixAccount_password'] != $_POST['posixAccount_password2']) { + return $return; + } + else { + if (!get_preg($_POST['posixAccount_password'], 'password')) { + return $return; + } + else { + // sync password + if (in_array('syncAsteriskPassword', $fields)) { + $return['mod']['AstAccountRealmedPassword'][0] = asteriskAccount::buildPasswordString($attributes, $this->selfServiceSettings->moduleSettings, $_POST['posixAccount_password']); + } + } + } + } + return $return; + } + } ?> diff --git a/lam/lib/modules/asteriskVoicemail.inc b/lam/lib/modules/asteriskVoicemail.inc index e2900754..e237bc93 100644 --- a/lam/lib/modules/asteriskVoicemail.inc +++ b/lam/lib/modules/asteriskVoicemail.inc @@ -72,6 +72,10 @@ class asteriskVoicemail extends baseModule implements passwordService { 'AstVoicemailPager', 'AstVoicemailOptions', 'AstVoicemailContext'); // icon $return['icon'] = 'asterisk.png'; + // self service + $return['selfServiceFieldSettings'] = array( + 'syncAsteriskVoicemailPassword' => _('Sync Asterisk password with Unix password'), + ); // help $return['help'] = array( 'AstContext' => array( @@ -511,6 +515,37 @@ class asteriskVoicemail extends baseModule implements passwordService { return array(); } + /** + * Checks if all input values are correct and returns the LDAP commands which should be executed. + * + * @param string $fields input fields + * @param array $attributes LDAP attributes + * @return array messages and LDAP commands (array('messages' => array(), 'add' => array(), 'del' => array(), 'mod' => array())) + */ + function checkSelfServiceOptions($fields, $attributes) { + $return = array('messages' => array(), 'add' => array(), 'del' => array(), 'mod' => array()); + if (!in_array_ignore_case('AsteriskVoiceMail', $attributes['objectClass'])) { + return $return; + } + if (isset($_POST['posixAccount_password']) && ($_POST['posixAccount_password'] != '')) { + if ($_POST['posixAccount_password'] != $_POST['posixAccount_password2']) { + return $return; + } + else { + if (!get_preg($_POST['posixAccount_password'], 'password')) { + return $return; + } + else { + // sync password + if (in_array('syncAsteriskVoicemailPassword', $fields)) { + $return['mod']['AstVoicemailPassword'][0] = $_POST['posixAccount_password']; + } + } + } + } + return $return; + } + } ?>