2010-03-28 17:00:24 +00:00
< ? php
/*
This code is part of LDAP Account Manager ( http :// www . sourceforge . net / projects / lam )
2011-02-26 13:14:10 +00:00
Copyright ( C ) 2010 Pavel Pozdnyak
2019-08-17 08:27:18 +00:00
2010 - 2019 Roland Gruber
2010-03-28 17:00:24 +00:00
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 2 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 , write to the Free Software
Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
/**
* Manages the Asterisk extension of user accounts .
*
* @ package modules
*
* @ author Pavel Pozdnyak
* @ author Roland Gruber
*/
/**
* Manages the Asterisk extension of user accounts .
*
* @ package modules
*/
class asteriskVoicemail extends baseModule implements passwordService {
/**
* Creates a new asteriskVoicemail object .
*
* @ param string $scope account type ( user , group , host )
*/
function __construct ( $scope ) {
// call parent constructor
parent :: __construct ( $scope );
$this -> autoAddObjectClasses = false ;
}
2014-04-20 12:59:36 +00:00
/**
* Returns true if this module can manage accounts of the current type , otherwise false .
2015-07-13 16:33:56 +00:00
*
2014-04-20 12:59:36 +00:00
* @ return boolean true if module fits
*/
public function can_manage () {
return in_array ( $this -> get_scope (), array ( 'user' ));
}
2010-03-28 17:00:24 +00:00
/**
* Returns meta data that is interpreted by parent class
*
* @ return array array with meta data
*/
function get_metaData () {
$return = array ();
$return [ " is_base " ] = false ;
// alias name
$return [ " alias " ] = _ ( " Asterisk voicemail " );
// module dependencies
$return [ 'dependencies' ] = array ( 'depends' => array ( 'inetOrgPerson' ), 'conflicts' => array ());
// managed object classes
$return [ 'objectClasses' ] = array ( 'AsteriskVoiceMail' );
// managed attributes
$return [ 'attributes' ] = array ( 'AstContext' , 'AstVoicemailMailbox' ,
'AstVoicemailPassword' , 'AstVoicemailFullname' , 'AstVoicemailEmail' ,
2010-04-01 17:31:55 +00:00
'AstVoicemailPager' , 'AstVoicemailOptions' , 'AstVoicemailContext' );
2010-03-28 17:00:24 +00:00
// icon
$return [ 'icon' ] = 'asterisk.png' ;
2010-09-02 18:21:59 +00:00
// self service
$return [ 'selfServiceFieldSettings' ] = array (
'syncAsteriskVoicemailPassword' => _ ( 'Sync Asterisk password with Unix password' ),
);
2013-11-30 15:02:06 +00:00
// self service: fields that cannot be relabeled
$return [ 'selfServiceNoRelabelFields' ] = array ( 'syncAsteriskVoicemailPassword' );
2010-03-28 17:00:24 +00:00
// help
$return [ 'help' ] = array (
'AstContext' => array (
2012-02-04 15:56:31 +00:00
" Headline " => _ ( " Account context " ), 'attr' => 'AstContext' ,
2010-03-28 17:00:24 +00:00
" Text " => _ ( " The account context stores information about the dial plan. " )
),
'AstVoicemailMailbox' => array (
2012-02-04 15:56:31 +00:00
" Headline " => _ ( " Mailbox " ), 'attr' => 'AstVoicemailMailbox' ,
2010-03-28 17:00:24 +00:00
" Text " => _ ( " Voicemail mailbox for this account. " )
),
'AstVoicemailPassword' => array (
2012-02-04 15:56:31 +00:00
" Headline " => _ ( " Password " ), 'attr' => 'AstVoicemailPassword' ,
2010-03-28 17:00:24 +00:00
" Text " => _ ( " Password for voicemail mailbox. " )
),
'AstVoicemailFullname' => array (
2012-02-04 15:56:31 +00:00
" Headline " => _ ( " Full name " ), 'attr' => 'AstVoicemailFullname' ,
2010-03-28 17:00:24 +00:00
" Text " => _ ( " Full name for Asterisk voicemail mailbox. " )
),
'AstVoicemailEmail' => array (
2012-02-04 15:56:31 +00:00
" Headline " => _ ( " Email address " ), 'attr' => 'AstVoicemailEmail' ,
2010-03-28 17:10:37 +00:00
" Text " => _ ( " Email address for this voicemail account. " )
2010-03-28 17:00:24 +00:00
),
'AstVoicemailPager' => array (
2012-02-04 15:56:31 +00:00
" Headline " => _ ( " Pager " ), 'attr' => 'AstVoicemailPager' ,
2010-03-28 17:10:37 +00:00
" Text " => _ ( " Pager number for Asterisk voicemail. " )
2010-03-28 17:00:24 +00:00
),
'AstVoicemailOptions' => array (
2012-02-04 15:56:31 +00:00
" Headline " => _ ( " Options " ), 'attr' => 'AstVoicemailOptions' ,
2010-03-28 17:10:37 +00:00
" Text " => _ ( " Options for Asterisk voicemail account (e.g. sendvoicemail=yes). " )
2010-03-28 17:00:24 +00:00
),
'AstVoicemailContext' => array (
2012-02-04 15:56:31 +00:00
" Headline " => _ ( " Voicemail context " ), 'attr' => 'AstVoicemailContext' ,
2010-03-28 17:00:24 +00:00
" Text " => _ ( " Asterisk voicemail context. " )
),
);
// profile options
2018-05-19 06:15:34 +00:00
$profileContainer = new htmlResponsiveRow ();
$profileContainer -> add ( new htmlResponsiveInputField ( _ ( 'Options' ), 'asteriskVoicemail_AstVoicemailOptions' , null , 'AstVoicemailOptions' ), 12 );
$profileContainer -> add ( new htmlResponsiveInputField ( _ ( 'Voicemail context' ), 'asteriskVoicemail_AstVoicemailContext' , null , 'AstVoicemailContext' ), 12 );
$profileContainer -> add ( new htmlResponsiveInputField ( _ ( 'Account context' ), 'asteriskVoicemail_AstContext' , null , 'AstContext' ), 12 );
2010-09-15 18:31:56 +00:00
$return [ 'profile_options' ] = $profileContainer ;
2010-03-28 17:00:24 +00:00
// profile mappings
$return [ 'profile_mappings' ] = array (
2010-04-05 09:03:44 +00:00
'asteriskVoicemail_AstContext' => 'AstContext' ,
2010-03-28 17:00:24 +00:00
'asteriskVoicemail_AstVoicemailContext' => 'AstVoicemailContext' ,
'asteriskVoicemail_AstVoicemailOptions' => 'AstVoicemailOptions'
);
// available PDF fields
$return [ 'PDF_fields' ] = array (
2010-04-05 12:38:23 +00:00
'AstContext' => _ ( 'Account context' ),
'AstVoicemailMailbox' => _ ( 'Mailbox' ),
'AstVoicemailFullname' => _ ( 'Full name' ),
'AstVoicemailEmail' => _ ( 'Email address' ),
'AstVoicemailPager' => _ ( 'Pager' ),
'AstVoicemailOptions' => _ ( 'Options' ),
'AstVoicemailContext' => _ ( 'Voicemail context' )
2010-03-28 17:00:24 +00:00
);
// upload dependencies
$return [ 'upload_preDepends' ] = array ( 'posixAccount' , 'inetOrgPerson' );
// upload fields
$return [ 'upload_columns' ] = array (
array (
'name' => 'asteriskVoicemail_AstContext' ,
2010-03-28 17:10:37 +00:00
'description' => _ ( 'Account context' ),
2010-03-28 17:00:24 +00:00
'help' => 'AstContext' ,
'example' => 'default' ,
'required' => true
),
array (
'name' => 'asteriskVoicemail_AstVoicemailMailbox' ,
'description' => _ ( 'Mailbox' ),
'help' => 'AstVoicemailMailbox' ,
'example' => '12345' ,
'required' => true
),
array (
'name' => 'asteriskVoicemail_AstVoicemailPassword' ,
'description' => _ ( 'Password' ),
'help' => 'AstVoicemailPassword' ,
'example' => _ ( 'secret' ),
'required' => true
),
array (
'name' => 'asteriskVoicemail_AstVoicemailFullname' ,
'description' => _ ( 'Full name' ),
'help' => 'AstVoicemailFullname' ,
'example' => _ ( 'Steve Miller' )
),
array (
'name' => 'asteriskVoicemail_AstVoicemailEmail' ,
'description' => _ ( 'Email address' ),
'help' => 'AstVoicemailEmail' ,
'example' => _ ( 'user@company.com' )
),
array (
'name' => 'asteriskVoicemail_AstVoicemailPager' ,
'description' => _ ( 'Pager' ),
'help' => 'AstVoicemailPager' ,
'example' => _ ( '123-123-1234' )
),
array (
'name' => 'asteriskVoicemail_AstVoicemailOptions' ,
'description' => _ ( 'Options' ),
'help' => 'AstVoicemailOptions' ,
'example' => 'sendvoicemail=yes'
),
array (
'name' => 'asteriskVoicemail_AstVoicemailContext' ,
'description' => _ ( 'Voicemail context' ),
'help' => 'AstVoicemailContext' ,
'example' => 'default'
)
);
return $return ;
}
/**
* This function fills the error message array with messages
*/
function load_Messages () {
//messages for voicemail
2010-03-28 17:10:37 +00:00
$this -> messages [ 'AstVoicemailMailbox' ][ 0 ] = array ( 'ERROR' , _ ( 'Please enter a mailbox.' ));
$this -> messages [ 'AstVoicemailMailbox' ][ 1 ] = array ( 'ERROR' , _ ( 'The mailbox format is invalid.' ));
$this -> messages [ 'AstVoicemailMailbox' ][ 2 ] = array ( 'ERROR' , _ ( 'There is already another user with this mailbox name.' ));
2014-04-13 10:50:59 +00:00
$this -> messages [ 'AstVoicemailMailbox' ][ 3 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' asteriskVoicemail_AstVoicemailMailbox' , _ ( 'The mailbox format is invalid.' ));
2015-07-13 16:33:56 +00:00
2010-03-28 17:10:37 +00:00
$this -> messages [ 'AstContext' ][ 0 ] = array ( 'ERROR' , _ ( 'Please enter the account context.' ));
$this -> messages [ 'AstContext' ][ 1 ] = array ( 'ERROR' , _ ( 'The account context is invalid.' ));
$this -> messages [ 'AstContext' ][ 2 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' asteriskVoicemail_AstContext' , _ ( 'The account context is invalid.' ));
2010-03-28 17:00:24 +00:00
2010-06-21 17:34:20 +00:00
$this -> messages [ 'AstVoicemailFullname' ][ 0 ] = array ( 'ERROR' , _ ( 'The full name is invalid.' ));
2014-04-13 10:50:59 +00:00
$this -> messages [ 'AstVoicemailFullname' ][ 1 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' asteriskVoicemail_AstVoicemailFullname' , _ ( 'The full name is invalid.' ));
$this -> messages [ 'AstVoicemailEmail' ][ 0 ] = array ( 'ERROR' , _ ( 'The email address is invalid.' ));
$this -> messages [ 'AstVoicemailEmail' ][ 1 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' asteriskVoicemail_AstVoicemailEmail' , _ ( 'The email address is invalid.' ));
2010-04-02 11:39:09 +00:00
$this -> messages [ 'AstVoicemailPager' ][ 0 ] = array ( 'ERROR' , _ ( 'The pager number has bad format.' ));
2014-04-13 10:50:59 +00:00
$this -> messages [ 'AstVoicemailPager' ][ 1 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' asteriskVoicemail_AstVoicemailPager' , _ ( 'The pager number has bad format.' ));
2010-03-28 17:00:24 +00:00
$this -> messages [ 'AstVoicemailOptions' ][ 0 ] = array ( 'ERROR' , _ ( 'The options have bad format.' ));
2010-03-28 17:10:37 +00:00
$this -> messages [ 'AstVoicemailOptions' ][ 1 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' asteriskVoicemail_AstVoicemailOptions' , _ ( 'The options have bad format.' ));
$this -> messages [ 'AstVoicemailContext' ][ 0 ] = array ( 'ERROR' , _ ( 'The voicemail context name is invalid.' ));
$this -> messages [ 'AstVoicemailContext' ][ 1 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' asteriskVoicemail_AstVoicemailContext' , _ ( 'The voicemail context name is invalid.' ));
2010-03-28 17:00:24 +00:00
$this -> messages [ 'AstVoicemailPassword' ][ 0 ] = array ( 'INFO' , _ ( 'Please set the voicemail password with "Set password" before saving.' ));
}
/**
2010-09-18 11:37:22 +00:00
* Returns the HTML meta data for the main account page .
2015-07-13 16:33:56 +00:00
*
2010-09-18 11:37:22 +00:00
* @ return htmlElement HTML meta data
2010-03-28 17:00:24 +00:00
*/
function display_html_attributes () {
2019-08-17 08:27:18 +00:00
$return = new htmlResponsiveRow ();
2010-03-28 17:00:24 +00:00
if ( in_array ( 'AsteriskVoiceMail' , $this -> attributes [ 'objectClass' ])) {
if ( ! isset ( $this -> attributes [ 'AstVoicemailPassword' ])) {
2010-09-15 18:31:56 +00:00
$message = new htmlStatusMessage ( $this -> messages [ 'AstVoicemailPassword' ][ 0 ][ 0 ], $this -> messages [ 'AstVoicemailPassword' ][ 0 ][ 1 ]);
2019-08-17 08:27:18 +00:00
$return -> add ( $message , 12 );
2010-03-28 17:00:24 +00:00
}
2010-09-15 18:31:56 +00:00
// mailbox
2013-10-19 10:25:39 +00:00
$this -> addSimpleInputTextField ( $return , 'AstVoicemailMailbox' , _ ( " Mailbox " ), true );
2010-09-15 18:31:56 +00:00
// account context
2013-10-19 10:25:39 +00:00
$this -> addSimpleInputTextField ( $return , 'AstContext' , _ ( " Account context " ), true );
2015-07-13 16:33:56 +00:00
2019-08-17 08:27:18 +00:00
$return -> addVerticalSpacer ( '1rem' );
2010-03-28 17:00:24 +00:00
2010-09-15 18:31:56 +00:00
// full name
2013-10-19 10:25:39 +00:00
$this -> addSimpleInputTextField ( $return , 'AstVoicemailFullname' , _ ( " Full name " ));
2010-09-15 18:31:56 +00:00
// email
2013-10-19 10:25:39 +00:00
$this -> addSimpleInputTextField ( $return , 'AstVoicemailEmail' , _ ( " Email address " ));
2010-09-15 18:31:56 +00:00
// pager
2013-10-19 10:25:39 +00:00
$this -> addSimpleInputTextField ( $return , 'AstVoicemailPager' , _ ( " Pager " ));
2010-09-15 18:31:56 +00:00
// options
2013-10-19 10:25:39 +00:00
$this -> addSimpleInputTextField ( $return , 'AstVoicemailOptions' , _ ( " Options " ));
2010-09-15 18:31:56 +00:00
// voicemail context
2013-10-19 10:25:39 +00:00
$this -> addSimpleInputTextField ( $return , 'AstVoicemailContext' , _ ( " Voicemail context " ));
2010-09-15 18:31:56 +00:00
// remove button
2019-08-17 08:27:18 +00:00
$return -> addVerticalSpacer ( '2rem' );
2010-09-15 18:31:56 +00:00
$remButton = new htmlButton ( 'remVoicemailObjectClass' , _ ( 'Remove Asterisk voicemail extension' ));
2019-08-17 08:27:18 +00:00
$return -> add ( $remButton , 12 , 12 , 12 , 'text-center' );
2010-03-28 17:00:24 +00:00
}
else {
2010-09-15 18:31:56 +00:00
// add button
2019-08-17 08:27:18 +00:00
$return -> add ( new htmlButton ( 'addVoicemailObjectClass' , _ ( 'Add Asterisk voicemail extension' )), 12 );
2010-03-28 17:00:24 +00:00
}
return $return ;
}
/**
* Write variables into object and do some regex checks
*/
function process_attributes () {
2010-09-15 18:31:56 +00:00
if ( isset ( $_POST [ 'addVoicemailObjectClass' ])) {
2010-03-28 17:00:24 +00:00
$this -> attributes [ 'objectClass' ][] = 'AsteriskVoiceMail' ;
return array ();
}
// remove extension
2010-09-15 18:31:56 +00:00
elseif ( isset ( $_POST [ 'remVoicemailObjectClass' ])) {
2010-03-28 17:00:24 +00:00
$this -> attributes [ 'objectClass' ] = array_delete ( array ( 'AsteriskVoiceMail' ), $this -> attributes [ 'objectClass' ]);
$attrKeys = array_keys ( $this -> attributes );
for ( $k = 0 ; $k < sizeof ( $attrKeys ); $k ++ ) {
if ( strpos ( $attrKeys [ $k ], 'AstVoicemail' ) > - 1 ) {
unset ( $this -> attributes [ $attrKeys [ $k ]]);
}
}
if ( isset ( $this -> attributes [ 'AstContext' ])) {
unset ( $this -> attributes [ 'AstContext' ]);
}
return array ();
}
$errors = array ();
if ( ! in_array ( 'AsteriskVoiceMail' , $this -> attributes [ 'objectClass' ])) {
return array ();
}
$this -> attributes [ 'AstVoicemailMailbox' ] = array ();
$this -> attributes [ 'AstVoicemailFullname' ] = array ();
$this -> attributes [ 'AstVoicemailEmail' ] = array ();
$this -> attributes [ 'AstVoicemailPager' ] = array ();
$this -> attributes [ 'AstVoicemailOptions' ] = array ();
$this -> attributes [ 'AstVoicemailContext' ] = array ();
if ( isset ( $_POST [ 'AstContext' ])) {
$this -> attributes [ 'AstContext' ][ 0 ] = $_POST [ 'AstContext' ];
if ( $this -> attributes [ 'AstContext' ][ 0 ] == '' ) {
$errors [] = $this -> messages [ 'AstContext' ][ 0 ];
}
elseif ( ! get_preg ( $this -> attributes [ 'AstContext' ][ 0 ], 'realname' )) {
$errors [] = $this -> messages [ 'AstContext' ][ 1 ];
}
}
if ( isset ( $_POST [ 'AstVoicemailMailbox' ])) {
$this -> attributes [ 'AstVoicemailMailbox' ][ 0 ] = $_POST [ 'AstVoicemailMailbox' ];
// check if caller ID is empty
if ( $this -> attributes [ 'AstVoicemailMailbox' ][ 0 ] == '' ) {
$errors [] = $this -> messages [ 'AstVoicemailMailbox' ][ 0 ];
}
// check format
else if ( ! get_preg ( $this -> attributes [ 'AstVoicemailMailbox' ][ 0 ], 'username' )) {
$errors [] = $this -> messages [ 'AstVoicemailMailbox' ][ 1 ];
}
// check for duplicate Voicemail ID
2018-12-28 10:19:15 +00:00
else if ( ! isset ( $this -> orig [ 'AstVoicemailMailbox' ][ 0 ]) || ( $this -> orig [ 'AstVoicemailMailbox' ][ 0 ] != $this -> attributes [ 'AstVoicemailMailbox' ][ 0 ])) {
2010-03-28 17:00:24 +00:00
$entries = searchLDAPByAttribute ( 'AstVoicemailMailbox' , $this -> attributes [ 'AstVoicemailMailbox' ][ 0 ], 'AstVoicemailMailbox' , array ( 'dn' ), array ( 'user' ));
if ( sizeof ( $entries ) > 0 ) {
$errors [] = $this -> messages [ 'AstVoicemailMailbox' ][ 2 ];
}
}
}
if ( isset ( $_POST [ 'AstVoicemailFullname' ])) {
$this -> attributes [ 'AstVoicemailFullname' ][ 0 ] = $_POST [ 'AstVoicemailFullname' ];
if ( $this -> attributes [ 'AstVoicemailFullname' ][ 0 ] != '' && ! get_preg ( $this -> attributes [ 'AstVoicemailFullname' ][ 0 ], 'realname' )) {
$errors [] = $this -> messages [ 'AstVoicemailFullname' ][ 0 ];
}
}
if ( isset ( $_POST [ 'AstVoicemailEmail' ])) {
$this -> attributes [ 'AstVoicemailEmail' ][ 0 ] = $_POST [ 'AstVoicemailEmail' ];
if ( $this -> attributes [ 'AstVoicemailEmail' ][ 0 ] != '' && ! get_preg ( $this -> attributes [ 'AstVoicemailEmail' ][ 0 ], 'email' )) {
$errors [] = $this -> messages [ 'AstVoicemailEmail' ][ 0 ];
}
}
if ( isset ( $_POST [ 'AstVoicemailPager' ])) {
$this -> attributes [ 'AstVoicemailPager' ][ 0 ] = $_POST [ 'AstVoicemailPager' ];
if ( $this -> attributes [ 'AstVoicemailPager' ][ 0 ] != '' && ! get_preg ( $this -> attributes [ 'AstVoicemailPager' ][ 0 ], 'telephone' )) {
$errors [] = $this -> messages [ 'AstVoicemailPager' ][ 0 ];
}
}
if ( isset ( $_POST [ 'AstVoicemailOptions' ])) {
$this -> attributes [ 'AstVoicemailOptions' ][ 0 ] = $_POST [ 'AstVoicemailOptions' ];
}
if ( isset ( $_POST [ 'AstVoicemailContext' ])) {
$this -> attributes [ 'AstVoicemailContext' ][ 0 ] = $_POST [ 'AstVoicemailContext' ];
if ( $this -> attributes [ 'AstVoicemailContext' ][ 0 ] != '' && ! get_preg ( $this -> attributes [ 'AstVoicemailContext' ][ 0 ], 'realname' )) {
$errors [] = $this -> messages [ 'AstVoicemailContext' ][ 0 ];
}
}
return $errors ;
}
/**
2017-02-19 08:14:11 +00:00
* { @ inheritDoc }
* @ see baseModule :: get_pdfEntries ()
2010-03-28 17:00:24 +00:00
*/
2017-04-01 07:57:03 +00:00
function get_pdfEntries ( $pdfKeys , $typeId ) {
2010-03-28 17:00:24 +00:00
$return = array ();
2013-05-05 13:50:19 +00:00
$this -> addSimplePDFField ( $return , 'AstVoicemailMailbox' , _ ( 'Mailbox' ));
$this -> addSimplePDFField ( $return , 'AstContext' , _ ( 'Account context' ));
$this -> addSimplePDFField ( $return , 'AstVoicemailFullname' , _ ( 'Full name' ));
$this -> addSimplePDFField ( $return , 'AstVoicemailContext' , _ ( 'Voicemail context' ));
$this -> addSimplePDFField ( $return , 'AstVoicemailPager' , _ ( 'Pager' ));
$this -> addSimplePDFField ( $return , 'AstVoicemailEmail' , _ ( 'Email address' ));
$this -> addSimplePDFField ( $return , 'AstVoicemailOptions' , _ ( 'Options' ));
2010-03-28 17:00:24 +00:00
return $return ;
}
/**
2017-05-20 09:46:49 +00:00
* { @ inheritDoc }
* @ see baseModule :: build_uploadAccounts ()
2010-03-28 17:00:24 +00:00
*/
2017-05-20 09:46:49 +00:00
function build_uploadAccounts ( $rawAccounts , $ids , & $partialAccounts , $selectedModules , & $type ) {
2010-03-28 17:00:24 +00:00
$messages = array ();
for ( $i = 0 ; $i < sizeof ( $rawAccounts ); $i ++ ) {
// add object class
2019-08-17 08:27:18 +00:00
if ( ! in_array ( " AsteriskVoiceMail " , $partialAccounts [ $i ][ 'objectClass' ])) {
$partialAccounts [ $i ][ 'objectClass' ][] = " AsteriskVoiceMail " ;
}
2015-07-13 16:33:56 +00:00
2010-11-20 19:57:32 +00:00
//add context
2014-04-13 10:50:59 +00:00
if ( empty ( $rawAccounts [ $i ][ $ids [ 'asteriskVoicemail_AstContext' ]])) {
2010-11-20 19:57:32 +00:00
// default value
$partialAccounts [ $i ][ 'AstContext' ] = 'default' ;
}
else {
2014-04-13 10:50:59 +00:00
$this -> mapSimpleUploadField ( $rawAccounts , $ids , $partialAccounts , $i , 'asteriskVoicemail_AstContext' , 'AstContext' ,
'realname' , $this -> messages [ 'AstContext' ][ 2 ], $messages );
2010-03-28 17:00:24 +00:00
}
2015-07-13 16:33:56 +00:00
2014-04-13 10:50:59 +00:00
$this -> mapSimpleUploadField ( $rawAccounts , $ids , $partialAccounts , $i , 'asteriskVoicemail_AstVoicemailMailbox' , 'AstVoicemailMailbox' ,
'realname' , $this -> messages [ 'AstVoicemailMailbox' ][ 3 ], $messages );
2015-07-13 16:33:56 +00:00
2014-04-13 10:50:59 +00:00
$this -> mapSimpleUploadField ( $rawAccounts , $ids , $partialAccounts , $i , 'asteriskVoicemail_AstVoicemailEmail' , 'AstVoicemailEmail' ,
'email' , $this -> messages [ 'AstVoicemailEmail' ][ 1 ], $messages );
2010-03-28 17:00:24 +00:00
2014-04-13 10:50:59 +00:00
$this -> mapSimpleUploadField ( $rawAccounts , $ids , $partialAccounts , $i , 'asteriskVoicemail_AstVoicemailPager' , 'AstVoicemailPager' ,
'telephone' , $this -> messages [ 'AstVoicemailPager' ][ 1 ], $messages );
2010-03-28 17:00:24 +00:00
2014-04-13 10:50:59 +00:00
$this -> mapSimpleUploadField ( $rawAccounts , $ids , $partialAccounts , $i , 'asteriskVoicemail_AstVoicemailOptions' , 'AstVoicemailOptions' );
2010-03-28 17:00:24 +00:00
2014-04-13 10:50:59 +00:00
$this -> mapSimpleUploadField ( $rawAccounts , $ids , $partialAccounts , $i , 'asteriskVoicemail_AstVoicemailFullname' , 'AstVoicemailFullname' ,
'realname' , $this -> messages [ 'AstVoicemailFullname' ][ 1 ], $messages );
2010-03-28 17:00:24 +00:00
2014-04-13 10:50:59 +00:00
$this -> mapSimpleUploadField ( $rawAccounts , $ids , $partialAccounts , $i , 'asteriskVoicemail_AstVoicemailContext' , 'AstVoicemailContext' ,
'realname' , $this -> messages [ 'AstVoicemailContext' ][ 1 ], $messages );
2010-03-28 17:00:24 +00:00
2015-07-13 16:33:56 +00:00
$this -> mapSimpleUploadField ( $rawAccounts , $ids , $partialAccounts , $i , 'asteriskVoicemail_AstVoicemailPassword' , 'AstVoicemailPassword' );
2010-03-28 17:00:24 +00:00
}
return $messages ;
}
/**
* This functions returns true if all needed settings are done .
*
* @ return boolean true if LDAP operation can be done
*/
function module_complete () {
2019-08-17 08:27:18 +00:00
if ( in_array ( 'AsteriskVoiceMail' , $this -> attributes [ 'objectClass' ]) && empty ( $this -> attributes [ 'AstVoicemailPassword' ][ 0 ])) {
return false ;
2015-07-13 16:33:56 +00:00
}
2010-03-28 17:00:24 +00:00
return true ;
}
2010-10-02 12:30:35 +00:00
/**
* Returns a list of modifications which have to be made to the LDAP account .
*
* @ return array list of modifications
* < br > This function returns an array with 3 entries :
* < br > array ( DN1 ( 'add' => array ( $attr ), 'remove' => array ( $attr ), 'modify' => array ( $attr )), DN2 .... )
* < br > DN is the DN to change . It may be possible to change several DNs ( e . g . create a new user and add him to some groups via attribute memberUid )
* < br > " add " are attributes which have to be added to LDAP entry
* < br > " remove " are attributes which have to be removed from LDAP entry
* < br > " modify " are attributes which have to been modified in LDAP entry
2011-02-26 13:14:10 +00:00
* < br > " info " are values with informational value ( e . g . to be used later by pre / postModify actions )
2010-10-02 12:30:35 +00:00
*/
function save_attributes () {
if ( ! in_array ( 'AsteriskVoiceMail' , $this -> attributes [ 'objectClass' ]) && ! in_array ( 'AsteriskVoiceMail' , $this -> orig [ 'objectClass' ])) {
// skip saving if the extension was not added/modified
return array ();
}
return $this -> getAccountContainer () -> save_module_attributes ( $this -> attributes , $this -> orig );
}
2010-03-28 17:00:24 +00:00
/**
* This method specifies if a module manages password attributes .
* @ see passwordService :: managesPasswordAttributes
*
* @ return boolean true if this module manages password attributes
*/
public function managesPasswordAttributes () {
2010-04-01 17:31:55 +00:00
if ( ! in_array ( 'AsteriskVoiceMail' , $this -> attributes [ 'objectClass' ])) {
return false ;
}
2010-03-28 17:00:24 +00:00
return true ;
}
2012-01-15 19:34:14 +00:00
/**
* Specifies if this module supports to force that a user must change his password on next login .
2015-07-13 16:33:56 +00:00
*
2012-01-15 19:34:14 +00:00
* @ return boolean force password change supported
*/
public function supportsForcePasswordChange () {
return false ;
}
2015-07-13 16:33:56 +00:00
2010-03-28 17:00:24 +00:00
/**
* This function is called whenever the password should be changed . Account modules
* must change their password attributes only if the modules list contains their module name .
*
* @ param String $password new password
* @ param $modules list of modules for which the password should be changed
2012-01-15 19:34:14 +00:00
* @ param boolean $forcePasswordChange force the user to change his password at next login
2010-03-28 17:00:24 +00:00
* @ return array list of error messages if any as parameter array for StatusMessage
* e . g . return arrray ( array ( 'ERROR' , 'Password change failed.' ))
* @ see passwordService :: passwordChangeRequested
*/
2012-01-15 19:34:14 +00:00
public function passwordChangeRequested ( $password , $modules , $forcePasswordChange ) {
2010-03-28 17:00:24 +00:00
if ( ! in_array ( get_class ( $this ), $modules )) {
return array ();
}
$this -> attributes [ 'AstVoicemailPassword' ][ 0 ] = $password ;
return array ();
}
2015-07-13 16:33:56 +00:00
2010-09-02 18:21:59 +00:00
/**
2011-02-26 13:14:10 +00:00
* Checks if all input values are correct and returns the LDAP attributes which should be changed .
* < br > Return values :
* < br > messages : array of parameters to create status messages
* < br > add : array of attributes to add
* < br > del : array of attributes to remove
* < br > mod : array of attributes to modify
* < br > info : array of values with informational value ( e . g . to be used later by pre / postModify actions )
2015-07-13 16:33:56 +00:00
*
2011-02-26 13:14:10 +00:00
* Calling this method does not require the existence of an enclosing { @ link accountContainer } .
2010-09-02 18:21:59 +00:00
*
* @ param string $fields input fields
* @ param array $attributes LDAP attributes
2012-02-08 17:55:00 +00:00
* @ param boolean $passwordChangeOnly indicates that the user is only allowed to change his password and no LDAP content is readable
2012-08-18 15:55:43 +00:00
* @ param array $readOnlyFields list of read - only fields
2011-02-26 13:14:10 +00:00
* @ return array messages and attributes ( array ( 'messages' => array (), 'add' => array ( 'mail' => array ( 'test@test.com' )), 'del' => array (), 'mod' => array (), 'info' => array ()))
2010-09-02 18:21:59 +00:00
*/
2012-08-18 15:55:43 +00:00
function checkSelfServiceOptions ( $fields , $attributes , $passwordChangeOnly , $readOnlyFields ) {
2011-02-26 13:14:10 +00:00
$return = array ( 'messages' => array (), 'add' => array (), 'del' => array (), 'mod' => array (), 'info' => array ());
2012-02-08 17:55:00 +00:00
if ( ! isset ( $attributes [ 'objectClass' ]) || ! in_array_ignore_case ( 'AsteriskVoiceMail' , $attributes [ 'objectClass' ])) {
2010-09-02 18:21:59 +00:00
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 ;
}
2010-03-28 17:00:24 +00:00
}
?>