2007-12-11 02:28:07 +01:00
< ? php
/**
2018-04-11 15:13:21 +02:00
* eGgroupWare setup - create / change EGw configuration
2007-12-11 02:28:07 +01:00
*
* @ link http :// www . egroupware . org
* @ author Ralf Becker < RalfBecker - AT - outdoor - training . de >
* @ package setup
2016-04-05 18:51:43 +02:00
* @ copyright ( c ) 2007 - 16 by Ralf Becker < RalfBecker - AT - outdoor - training . de >
2007-12-11 02:28:07 +01:00
* @ license http :// opensource . org / licenses / gpl - license . php GPL - GNU General Public License
2008-06-30 09:50:29 +02:00
* @ version $Id $
2007-12-11 02:28:07 +01:00
*/
2016-04-05 18:51:43 +02:00
use EGroupware\Api ;
2007-12-11 02:28:07 +01:00
/**
2018-04-11 15:13:21 +02:00
* setup command : create / change EGw configuration
2007-12-11 02:28:07 +01:00
*/
2008-06-30 09:50:29 +02:00
class setup_cmd_config extends setup_cmd
2007-12-11 02:28:07 +01:00
{
2014-04-15 22:03:16 +02:00
/**
* Allow to run this command via setup - cli
*/
const SETUP_CLI_CALLABLE = true ;
2007-12-11 02:28:07 +01:00
/**
* Constructor
*
* @ param string $domain string with domain - name or array with all arguments
2014-11-07 14:16:30 +01:00
* @ param string $config_user = null user to config the domain ( or header_admin_user )
* @ param string $config_passwd = null pw of above user
* @ param string $arguments = null array with command line argruments
* @ param boolean $verbose = false if true , echos out some status information during the run
2007-12-11 02:28:07 +01:00
*/
function __construct ( $domain , $config_user = null , $config_passwd = null , $arguments = null , $verbose = false )
{
if ( ! is_array ( $domain ))
{
$domain = array (
'domain' => $domain ,
'config_user' => $config_user ,
'config_passwd' => $config_passwd ,
'arguments' => $arguments ,
'verbose' => $verbose ,
);
}
//echo __CLASS__.'::__construct()'; _debug_array($domain);
admin_cmd :: __construct ( $domain );
}
/**
2007-12-13 03:41:55 +01:00
* run the command : write the configuration to the database
2008-06-30 09:50:29 +02:00
*
2014-11-07 14:16:30 +01:00
* @ param boolean $check_only = false only run the checks ( and throw the exceptions ), but not the command itself
2007-12-13 03:41:55 +01:00
* @ return string success message
2007-12-11 02:28:07 +01:00
* @ throws Exception ( lang ( 'Wrong credentials to access the header.inc.php file!' ), 2 );
* @ throws Exception ( 'header.inc.php not found!' );
*/
protected function exec ( $check_only = false )
{
if ( $check_only && $this -> remote_id )
{
return true ; // can only check locally
}
// instanciate setup object and check authorisation
$this -> check_setup_auth ( $this -> config_user , $this -> config_passwd , $this -> domain );
2008-06-30 09:50:29 +02:00
2007-12-11 02:28:07 +01:00
$this -> check_installed ( $this -> domain , 15 , $this -> verbose );
2010-09-10 11:26:17 +02:00
// fixing authtypes in self::$options
self :: auth_types ( true );
2011-05-04 15:47:44 +02:00
2007-12-11 02:28:07 +01:00
$values = array ();
if ( $this -> arguments ) // we have command line arguments
{
2014-04-15 17:10:39 +02:00
$save_mail_account = $this -> _parse_cli_arguments ( $values );
2007-12-11 02:28:07 +01:00
}
else
{
2014-04-15 17:10:39 +02:00
$save_mail_account = $this -> _parse_properties ( $values );
2007-12-11 02:28:07 +01:00
}
// store the config
foreach ( $values as $name => $value )
{
2014-04-15 17:10:39 +02:00
if ( substr ( $name , 0 , 4 ) == 'acc_' ) continue ;
2014-11-05 21:27:52 +01:00
$app = 'phpgwapi' ;
if ( strpos ( $name , '/' ) !== false )
{
list ( $app , $name ) = explode ( '/' , $name );
}
2007-12-11 02:28:07 +01:00
self :: $egw_setup -> db -> insert ( self :: $egw_setup -> config_table , array (
'config_value' => $value ,
), array (
2014-11-05 21:27:52 +01:00
'config_app' => $app ,
2007-12-11 02:28:07 +01:00
'config_name' => $name ,
), __LINE__ , __FILE__ );
}
if ( count ( $values ))
{
2014-04-15 17:10:39 +02:00
if ( $save_mail_account ) $this -> _save_mail_account ( $values );
2008-06-30 09:50:29 +02:00
2014-04-16 19:57:44 +02:00
// flush instance cache, so above config get read from database not cache
2016-04-05 18:51:43 +02:00
Api\Cache :: flush ();
2014-04-16 19:57:44 +02:00
2009-10-28 22:59:49 +01:00
$this -> restore_db ();
2007-12-11 02:28:07 +01:00
return lang ( 'Configuration changed.' );
}
2007-12-14 02:28:33 +01:00
$this -> restore_db ();
2007-12-11 02:28:07 +01:00
return lang ( 'Nothing to change.' );
}
2008-06-30 09:50:29 +02:00
2007-12-11 02:28:07 +01:00
/**
* Return or echo the most common config options
*
2014-11-07 14:16:30 +01:00
* @ param boolean $echoit = false if true the config is additionally echo ' ed out
2007-12-11 02:28:07 +01:00
* @ return array with name => value pairs
*/
static function get_config ( $echoit = false )
{
self :: $egw_setup -> db -> select ( self :: $egw_setup -> config_table , 'config_name,config_value' , array (
'config_app' => 'phpgwapi' ,
" (config_name LIKE '% \\ _dir' OR (config_name LIKE 'mail%' AND config_name != 'mail_footer') OR config_name LIKE 'smtp \\ _%' OR config_name LIKE 'ldap%' OR config_name IN ('webserver_url','system_charset','auth_type','account_repository')) " ,
), __LINE__ , __FILE__ );
$config = array ();
while (( $row = self :: $egw_setup -> db -> row ( true )))
{
$config [ $row [ 'config_name' ]] = $row [ 'config_value' ];
}
if ( $echoit )
{
echo lang ( 'Current configuration:' ) . " \n " ;
foreach ( $config as $name => $value )
{
echo str_pad ( $name . ':' , 22 ) . $value . " \n " ;
}
}
return $config ;
}
2008-06-30 09:50:29 +02:00
2007-12-11 02:28:07 +01:00
/**
* Available options and allowed arguments
*
* @ var array
*/
static $options = array (
'--config' => array (), // name=value,...
'--files-dir' => 'files_dir' ,
2008-11-23 14:09:51 +01:00
'--vfs-root-user' => 'vfs_root_user' ,
2007-12-11 02:28:07 +01:00
'--backup-dir' => 'backup_dir' ,
'--temp-dir' => 'temp_dir' ,
'--webserver-url' => 'webserver_url' ,
2014-04-16 12:40:54 +02:00
// mail must NOT have any default, as it causes to store a mail profile!
2014-04-15 17:10:39 +02:00
'--mailserver' => array ( //server,{IMAP|IMAPS},[domain],[{standard(default)|vmailmgr = add domain for mailserver login|email = use email of user (Standard Maildomain should be set)}]
'acc_imap_host' ,
2014-04-16 12:40:54 +02:00
'acc_imap_port' ,
2014-04-15 17:10:39 +02:00
'acc_domain' ,
array ( 'name' => 'acc_imap_logintype' , 'allowed' => array (
2009-09-10 14:16:29 +02:00
'username (standard)' => 'standard' ,
'username@domain (virtual mail manager)' => 'vmailmgr' ,
2010-08-20 12:18:29 +02:00
'Username/Password defined by admin' => 'admin' ,
2010-08-31 12:13:28 +02:00
'userId@domain eg. u123@domain' => 'uidNumber' ,
2009-09-10 14:16:29 +02:00
'email (Standard Maildomain should be set)' => 'email' ,
2014-04-16 12:40:54 +02:00
)),
2014-04-15 22:03:16 +02:00
array ( 'name' => 'acc_imap_ssl' , 'allowed' => array ( 0 , 'no' , 1 , 'starttls' , 3 , 'ssl' , 2 , 'tls' )),
2007-12-11 02:28:07 +01:00
),
2013-06-20 16:48:53 +02:00
'--imap' => array (
2014-04-16 12:40:54 +02:00
'acc_imap_admin_username' ,
'acc_imap_admin_password' ,
'acc_imap_type' ,
2013-06-20 16:48:53 +02:00
),
2014-04-15 17:10:39 +02:00
'--folder' => array (
2017-06-13 13:52:31 +02:00
'acc_folder_sent' , 'acc_folder_trash' , 'acc_folder_draft' , 'acc_folder_template' , 'acc_folder_junk' , 'acc_folder_archive' , 'acc_folder_ham'
2007-12-11 02:28:07 +01:00
),
'--sieve' => array (
2014-04-15 17:10:39 +02:00
array ( 'name' => 'acc_sieve_host' ),
2014-04-16 12:40:54 +02:00
'acc_sieve_port' ,
'acc_sieve_enabled' ,
2014-04-15 22:03:16 +02:00
array ( 'name' => 'acc_sieve_ssl' , 'allowed' => array ( 0 , 'no' , 1 , 'starttls' , 3 , 'ssl' , 2 , 'tls' )),
2007-12-11 02:28:07 +01:00
),
2013-06-20 16:48:53 +02:00
'--smtp' => array (
array ( 'name' => 'editforwardingaddress' , 'allowed' => array ( 'yes' , null )),
2014-04-16 12:40:54 +02:00
'acc_smtp_type' ,
2007-12-11 02:28:07 +01:00
),
2014-11-07 14:16:30 +01:00
'--smtpserver' => array ( //smtp server,[smtp port],[smtp user],[smtp password],[auth session user/pw],[no|starttls|ssl|tls],[user editable],[further identities]
'acc_smtp_host' , 'acc_smtp_port' , 'acc_smtp_username' , 'acc_smtp_passwd' , 'acc_smtp_auth_session' ,
2014-04-15 22:03:16 +02:00
array ( 'name' => 'acc_smtp_ssl' , 'allowed' => array ( 0 , 'no' , 1 , 'starttls' , 3 , 'ssl' , 2 , 'tls' )),
2014-04-16 12:40:54 +02:00
'acc_user_editable' , 'acc_further_identities' ,
2007-12-11 02:28:07 +01:00
),
'--account-auth' => array (
2013-06-20 16:48:53 +02:00
array ( 'name' => 'account_repository' , 'allowed' => array ( 'sql' , 'ldap' , 'ads' ), 'default' => 'sql' ),
2007-12-11 02:28:07 +01:00
array ( 'name' => 'auth_type' , 'allowed' => array ( 'sql' , 'ldap' , 'mail' , 'ads' , 'http' , 'sqlssl' , 'nis' , 'pam' ), 'default' => 'sql' ),
2014-04-15 17:10:39 +02:00
array ( 'name' => 'sql_encryption' , 'allowed' => array ( 'blowfish_crypt' , 'sha512_crypt' , 'sha256_crypt' , 'md5_crypt' , 'crypt' , 'ssha' , 'smd5' , 'md5' ), 'default' => 'blowfish_crypt' ),
2007-12-11 02:28:07 +01:00
'check_save_password' , 'allow_cookie_auth' ),
'--ldap-host' => 'ldap_host' ,
'--ldap-root-dn' => 'ldap_root_dn' ,
'--ldap-root-pw' => 'ldap_root_pw' ,
'--ldap-context' => 'ldap_context' ,
'--ldap-search-filter' => 'ldap_search_filter' ,
'--ldap-group-context' => 'ldap_group_context' ,
2015-03-13 14:51:10 +01:00
'--sambaadmin-sid' => 'sambaadmin/sambasid' ,
2007-12-14 02:28:33 +01:00
'--allow-remote-admin' => 'allow_remote_admin' ,
2008-11-23 14:09:51 +01:00
'--install-id' => 'install_id' ,
2013-06-20 16:48:53 +02:00
'--ads-host' => 'ads_host' ,
'--ads-domain' => 'ads_domain' ,
'--ads-admin-user' => 'ads_domain_admin' , // eg. Administrator
'--ads-admin-pw' => 'ads_admin_pw' ,
'--ads-connection' => array (
array ( 'name' => 'ads_connection' , 'allowed' => array ( 'ssl' , 'tls' ))
),
'--ads-context' => 'ads_context' ,
2007-12-11 02:28:07 +01:00
);
2014-04-15 17:10:39 +02:00
/**
* Translate old EMailAdmin profile name to new mail account names
*
* @ var array
*/
var $old2new = array (
'mail_server' => 'acc_imap_host' ,
'mail_server_type' => 'acc_imap_port' ,
'mail_suffix' => 'acc_domain' ,
'mail_login_type' => 'acc_imap_logintype' ,
2014-04-16 12:40:54 +02:00
'imapAdminUsername' => 'acc_imap_admin_username' ,
'imapAdminPW' => 'acc_imap_admin_password' ,
2014-04-15 17:10:39 +02:00
'imapType' => 'acc_imap_type' ,
2014-04-15 22:03:16 +02:00
'imapTLSEncryption' => 'acc_imap_ssl' ,
2014-04-15 17:10:39 +02:00
'imapSieveServer' => 'acc_sieve_host' ,
'imapSievePort' => 'acc_sieve_port' ,
'imapEnableSieve' => 'acc_sieve_enabled' ,
'editforwardingaddress' => null ,
'smtpType' => 'acc_smtp_type' ,
'smtp_server' => 'acc_smtp_host' ,
'smtp_port' => 'acc_smtp_port' ,
'smtp_auth_user' => 'acc_smtp_username' ,
'smtp_auth_passwd' => 'acc_smtp_password' ,
'smtpAuth' => null ,
2014-04-15 22:03:16 +02:00
'organisationName' => 'ident_org' ,
2014-04-15 17:10:39 +02:00
);
2008-06-30 09:50:29 +02:00
2007-12-11 02:28:07 +01:00
/**
* Parses properties from this object
2008-06-30 09:50:29 +02:00
*
2007-12-11 02:28:07 +01:00
* @ param array & $value contains set values on return
2014-04-15 17:10:39 +02:00
* @ return boolean do we need to save a mail account
2007-12-11 02:28:07 +01:00
*/
private function _parse_properties ( & $values )
{
$this -> _merge_defaults ();
2014-04-15 17:10:39 +02:00
$save_mail_account = false ;
2007-12-11 02:28:07 +01:00
$values = array ();
foreach ( self :: $options as $arg => $option )
{
foreach ( is_array ( $option ) ? $option : array ( $option ) as $n => $data )
{
$name = is_array ( $data ) ? $data [ 'name' ] : $data ;
2014-04-15 17:10:39 +02:00
$oldname = array_key_exists ( $name , $this -> old2new );
2008-06-30 09:50:29 +02:00
2014-04-15 17:10:39 +02:00
if ( ! isset ( $this -> $name ) && $oldname && isset ( $this -> $oldname ))
{
$this -> $name = $this -> $oldname ;
2014-04-15 22:03:16 +02:00
unset ( $this -> $oldname );
2014-04-15 17:10:39 +02:00
}
2007-12-11 02:28:07 +01:00
if ( isset ( $this -> $name ))
2008-06-30 09:50:29 +02:00
{
2014-04-15 17:10:39 +02:00
$save_mail_account = $this -> _parse_value ( $arg , $n , $option , $this -> $name , $values ) || $save_mail_account ;
2007-12-11 02:28:07 +01:00
}
}
}
2014-04-15 17:10:39 +02:00
return $save_mail_account ;
2007-12-11 02:28:07 +01:00
}
/**
* Parses command line arguments in $this -> arguments
2008-06-30 09:50:29 +02:00
*
2007-12-11 02:28:07 +01:00
* @ param array & $value contains set values on return
2014-04-15 17:10:39 +02:00
* @ return boolean do we need to save a mail account
2007-12-11 02:28:07 +01:00
*/
private function _parse_cli_arguments ( & $values )
{
$values = array ();
2014-04-15 17:10:39 +02:00
$save_mail_account = false ;
2007-12-11 02:28:07 +01:00
$args = $this -> arguments ;
while (( $arg = array_shift ( $args )))
{
if ( ! isset ( self :: $options [ $arg ]))
{
2016-04-05 18:51:43 +02:00
throw new Api\Exception\WrongUserinput ( lang ( " Unknown option '%1' !!! " , $arg ), 90 );
2007-12-11 02:28:07 +01:00
}
$options = is_array ( self :: $options [ $arg ]) ? explode ( ',' , array_shift ( $args )) : array ( array_shift ( $args ));
2008-06-30 09:50:29 +02:00
2014-04-15 22:03:16 +02:00
if ( $arg == '--config' || $arg == '--setup_cmd_config' )
2007-12-11 02:28:07 +01:00
{
foreach ( $options as $option )
{
list ( $name , $value ) = explode ( '=' , $option , 2 );
$values [ $name ] = $value ;
}
continue ;
}
$options [] = '' ; $options [] = '' ;
foreach ( $options as $n => $value )
{
2014-04-15 17:10:39 +02:00
$save_mail_account = $this -> _parse_value ( $arg , $n , self :: $options [ $arg ], $value , $values ) || $save_mail_account ;
2007-12-11 02:28:07 +01:00
}
}
2014-04-15 17:10:39 +02:00
return $save_mail_account ;
2007-12-11 02:28:07 +01:00
}
2008-06-30 09:50:29 +02:00
2007-12-11 02:28:07 +01:00
/**
* Parses a single value
*
* @ param string $arg current cli argument processed
* @ param int $n number of the property
2014-04-15 17:10:39 +02:00
* @ param array | string $data string with type or array containing values for type , allowed
2007-12-11 02:28:07 +01:00
* @ param mixed $value value to set
* @ param array & $values where the values get set
2014-04-15 17:10:39 +02:00
* @ return boolean true if mail - accounts needs to be saved , false if not
2007-12-11 02:28:07 +01:00
*/
private function _parse_value ( $arg , $n , $data , $value , array & $values )
{
if ( $value === '' && is_array ( $data ) && ! isset ( $data [ $n ][ 'default' ])) return false ;
2008-06-30 09:50:29 +02:00
2007-12-11 02:28:07 +01:00
$name = is_array ( $data ) || $n ? $data [ $n ] : $data ;
2008-06-30 09:50:29 +02:00
2007-12-11 02:28:07 +01:00
if ( is_array ( $name ))
{
if ( ! $value && isset ( $name [ 'default' ])) $value = $name [ 'default' ];
if ( isset ( $name [ 'allowed' ]) && ! in_array ( $value , $name [ 'allowed' ]))
{
2016-04-05 18:51:43 +02:00
throw new Api\Exception\WrongUserinput ( lang ( " '%1' is not allowed as %2. arguments of option %3 !!! " , $value , 1 + $n , $arg ) . " ( $name[name] ) " , 91 );
2007-12-11 02:28:07 +01:00
}
$name = $name [ 'name' ];
}
$values [ $name ] = $value ;
2014-04-15 17:10:39 +02:00
return in_array ( $arg , array ( '--mailserver' , '--smtpserver' , '--imap' , '--smtp' , '--sieve' , '--folder' ));
2007-12-11 02:28:07 +01:00
}
2008-06-30 09:50:29 +02:00
2007-12-11 02:28:07 +01:00
/**
2014-04-15 17:10:39 +02:00
* Add new new mail account
*
* @ param array $data
2007-12-11 02:28:07 +01:00
*/
2014-04-15 17:10:39 +02:00
function _save_mail_account ( array $data )
2007-12-11 02:28:07 +01:00
{
2023-01-26 10:42:18 +01:00
// convert ssl textual values to numerical ones used in Api\Mail\Account
2014-04-15 17:10:39 +02:00
foreach ( array ( 'acc_imap_ssl' , 'acc_sieve_ssl' , 'acc_smtp_ssl' ) as $name )
2007-12-11 02:28:07 +01:00
{
2023-01-26 10:42:18 +01:00
switch ( strtolower ( $data [ $name ] ? ? '' ))
2014-04-15 17:10:39 +02:00
{
2016-04-05 18:51:43 +02:00
case 'no' : $data [ $name ] = Api\Mail\Account :: SSL_NONE ; break ;
case 'starttls' : $data [ $name ] = Api\Mail\Account :: SSL_STARTTLS ; break ;
case 'ssl' : $data [ $name ] = Api\Mail\Account :: SSL_SSL ; break ;
case 'tls' : $data [ $name ] = Api\Mail\Account :: SSL_TLS ; break ;
2014-04-15 17:10:39 +02:00
}
}
// convert 'yes', 'no' to boolean
2014-04-16 18:48:43 +02:00
foreach ( array ( 'acc_sieve_enabled' , 'acc_user_editable' , 'acc_further_identities' , 'acc_smtp_auth_session' ) as $name )
2014-04-15 17:10:39 +02:00
{
$data [ $name ] = $data [ $name ] && strtolower ( $data [ $name ]) != 'no' ;
2007-12-11 02:28:07 +01:00
}
2014-04-16 12:40:54 +02:00
// do NOT write empty usernames
foreach ( array ( 'acc_imap_username' , 'acc_smtp_username' ) as $name )
{
if ( empty ( $data [ $name ]))
{
unset ( $data [ $name ]);
unset ( $data [ str_replace ( 'username' , 'password' , $name )]);
}
}
2008-06-30 09:50:29 +02:00
2014-04-15 17:10:39 +02:00
$data [ 'acc_name' ] = 'Created by setup' ;
$data [ 'account_id' ] = 0 ; // 0 = valid for all users
2016-04-05 18:51:43 +02:00
Api\Mail\Account :: write ( $data );
2008-06-30 09:50:29 +02:00
2007-12-11 02:28:07 +01:00
if ( $this -> verbose )
{
2014-04-15 17:10:39 +02:00
echo " \n " . lang ( 'EMailAdmin mail account saved:' ) . " \n " ;
foreach ( $data as $name => $value )
2007-12-11 02:28:07 +01:00
{
echo str_pad ( $name . ':' , 22 ) . $value . " \n " ;
}
}
}
/**
* Return the options from the $options array
*
* @ return array with name => array ( value => label , ... ) pairs
*/
static function options ()
{
$options = array ();
foreach ( self :: $options as $option )
{
if ( is_array ( $option ))
{
2014-04-15 17:10:39 +02:00
foreach ( $option as $data )
2007-12-11 02:28:07 +01:00
{
if ( is_array ( $data ) && isset ( $data [ 'allowed' ]))
{
2014-11-05 21:27:52 +01:00
switch ( $data [ 'name' ])
2010-09-10 11:26:17 +02:00
{
2014-11-05 21:27:52 +01:00
case 'auth_type' :
$options [ $data [ 'name' ]] = self :: auth_types ();
continue 2 ;
case 'account_repository' :
2014-11-30 14:46:39 +01:00
$options [ $data [ 'name' ]] = self :: account_repositories ();
2014-11-05 21:27:52 +01:00
continue 2 ;
2010-09-10 11:26:17 +02:00
}
2007-12-11 02:28:07 +01:00
foreach ( $data [ 'allowed' ] as $label => $value )
{
if ( is_int ( $label ))
{
$label = ( string ) $value === '' ? 'No' : strtoupper ( $value );
}
$options [ $data [ 'name' ]][ $value ] = lang ( $label );
}
}
}
}
}
return $options ;
}
2011-05-04 15:47:44 +02:00
2010-09-10 11:26:17 +02:00
/**
* Read auth - types ( existing auth backends ) from filesystem and fix our $options array
2011-05-04 15:47:44 +02:00
*
2010-09-10 11:26:17 +02:00
* @ return array
*/
static function auth_types ()
{
// default backends in order of importance
static $auth_types = array (
'sql' => 'SQL' ,
'ldap' => 'LDAP' ,
'ads' => 'Active Directory' ,
2023-11-17 09:17:29 +01:00
'openidconnect' => 'OpenID Connect' ,
'saml' => 'SAML' ,
'mail' => 'Mail' ,
2010-09-10 11:26:17 +02:00
'http' => 'HTTP' ,
2023-11-17 09:17:29 +01:00
'fallback' => false , // do NOT show, they get migrated to fallback-auth automatic
'fallbackmail2sql' => false ,
2010-09-10 11:26:17 +02:00
'sqlssl' => 'SQL / SSL' ,
);
2014-04-15 17:10:39 +02:00
static $scan_done = null ;
2010-09-10 11:26:17 +02:00
if ( ! $scan_done ++ )
{
2023-07-02 07:34:22 +02:00
// now add auth backends found in filesystem (must be sub-class of Backend, but not just an interface)
2016-05-03 00:26:40 +02:00
foreach ( scandir ( EGW_INCLUDE_ROOT . '/api/src/Auth' ) as $file )
2010-09-10 11:26:17 +02:00
{
2014-04-15 17:10:39 +02:00
$matches = null ;
2016-06-09 08:48:18 +02:00
if ( preg_match ( '/^([a-z0-9]+)\.php$/i' , $file , $matches ) &&
2023-07-02 07:34:22 +02:00
! isset ( $auth_types [ strtolower ( $matches [ 1 ])]) &&
! interface_exists ( $class = 'EGroupware\\Api\\Auth\\' . $matches [ 1 ]) &&
2023-11-17 09:17:29 +01:00
is_subclass_of ( $class , Api\Auth\Backend :: class ) &&
$auth_types [ $matches [ 1 ]] !== false )
2010-09-10 11:26:17 +02:00
{
2016-05-03 00:26:40 +02:00
$auth_types [ strtolower ( $matches [ 1 ])] = $matches [ 1 ];
2010-09-10 11:26:17 +02:00
}
}
2023-11-17 09:17:29 +01:00
// remove (obsolete) auth-types marked with false
$auth_types = array_filter ( $auth_types );
2010-09-10 11:26:17 +02:00
foreach ( self :: $options [ '--account-auth' ] as & $param )
{
if ( $param [ 'name' ] == 'auth_type' )
{
$param [ 'allowed' ] = array_keys ( $auth_types );
break ;
}
}
}
return $auth_types ;
}
2007-12-11 02:28:07 +01:00
2014-11-05 21:27:52 +01:00
/**
* Read auth - types ( existing auth backends ) from filesystem and fix our $options array
*
2014-11-06 20:21:56 +01:00
* @ param string $current = null current value , to allways return it
2014-11-05 21:27:52 +01:00
* @ return array
*/
2014-11-06 20:21:56 +01:00
static function account_repositories ( $current = null )
2014-11-05 21:27:52 +01:00
{
static $account_repositories = array (
'sql' => 'SQL' ,
'ldap' => 'LDAP' ,
'ads' => 'Active Directory' ,
);
static $scan_done = null ;
if ( ! $scan_done ++ )
{
// now add auth backends found in filesystem
2016-05-03 00:26:40 +02:00
foreach ( scandir ( EGW_INCLUDE_ROOT . '/api/src/Accounts' ) as $file )
2014-11-05 21:27:52 +01:00
{
$matches = null ;
2017-08-25 09:00:46 +02:00
if ( preg_match ( '/^([a-z0-9]+)\.php$/i' , $file , $matches ) &&
2016-05-03 00:26:40 +02:00
! isset ( $account_repositories [ strtolower ( $matches [ 1 ])]) &&
class_exists ( $class = 'EGroupware\\Api\\Accounts\\' . $matches [ 1 ]) &&
( strtolower ( $matches [ 1 ]) == $current || ! is_callable ( $callable = $class . '::available' ) || call_user_func ( $callable )))
2014-11-05 21:27:52 +01:00
{
2016-05-03 00:26:40 +02:00
$account_repositories [ strtolower ( $matches [ 1 ])] = $matches [ 1 ];
2014-11-05 21:27:52 +01:00
}
}
}
return $account_repositories ;
}
2007-12-11 02:28:07 +01:00
/**
* Return the defaults from the $options array
*
* @ return array with name => $value pairs
*/
static function defaults ()
{
$defaults = array ();
// fetch the default from the cli options
foreach ( self :: $options as $option )
{
if ( is_array ( $option ))
{
2014-04-15 17:10:39 +02:00
foreach ( $option as $data )
2007-12-11 02:28:07 +01:00
{
if ( is_array ( $data ) && isset ( $data [ 'default' ]))
{
$defaults [ $data [ 'name' ]] = $data [ 'default' ];
}
}
}
}
// some extra defaults for non-cli operation
$defaults [ 'files_dir' ] = '/var/lib/egroupware/$domain/files' ;
$defaults [ 'backup_dir' ] = '/var/lib/egroupware/$domain/backup' ;
2009-08-27 14:46:12 +02:00
$defaults [ 'backup_mincount' ] = 0 ;
$defaults [ 'backup_files' ] = false ;
2007-12-11 02:28:07 +01:00
$defaults [ 'temp_dir' ] = '/tmp' ;
$defaults [ 'webserver_url' ] = '/egroupware' ;
2014-04-16 12:40:54 +02:00
// no more mail defaults, to not create a (2.) mail account during setup!
2008-06-30 09:50:29 +02:00
2007-12-11 02:28:07 +01:00
return $defaults ;
}
/**
* Merges the default into the current properties , if they are empty or contain placeholders
2008-06-30 09:50:29 +02:00
*
2007-12-11 02:28:07 +01:00
* Replacements like $domain , only work for values listed by self :: defaults ()
*/
private function _merge_defaults ()
{
foreach ( self :: defaults () as $name => $default )
{
if ( ! $this -> $name )
{
//echo "<p>setting $name='{$this->$name}' to it's default='$default'</p>\n";
$this -> set_defaults [ $name ] = $this -> $name = $default ;
}
if ( strpos ( $this -> $name , '$' ) !== false )
{
2010-08-25 14:24:11 +02:00
$this -> set_defaults [ $name ] = $this -> $name = str_replace ( array (
2007-12-11 02:28:07 +01:00
'$domain' ,
), array (
$this -> domain ,
), $this -> $name );
}
2008-06-30 09:50:29 +02:00
}
2007-12-11 02:28:07 +01:00
}
2023-01-26 10:42:18 +01:00
}