From 7bd6f436105d4f3513fbb9746b3d3b419ecb6638 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Fri, 10 Sep 2010 09:26:57 +0000 Subject: [PATCH] using one list of auth-types (in order of importance) and detecting additional ones in the filesystem --- setup/inc/class.setup_cmd_config.inc.php | 49 ++++++++++++++++++++++++ setup/inc/hook_config.inc.php | 47 ++++++++++++++++------- setup/templates/default/config.tpl | 31 ++------------- 3 files changed, 86 insertions(+), 41 deletions(-) diff --git a/setup/inc/class.setup_cmd_config.inc.php b/setup/inc/class.setup_cmd_config.inc.php index d1c41f6304..44b1c87bc2 100644 --- a/setup/inc/class.setup_cmd_config.inc.php +++ b/setup/inc/class.setup_cmd_config.inc.php @@ -59,6 +59,9 @@ class setup_cmd_config extends setup_cmd $this->check_installed($this->domain,15,$this->verbose); + // fixing authtypes in self::$options + self::auth_types(true); + $values = array(); if ($this->arguments) // we have command line arguments { @@ -317,6 +320,11 @@ class setup_cmd_config extends setup_cmd { if (is_array($data) && isset($data['allowed'])) { + if ($data['name'] == 'auth_type') + { + $options[$data['name']] = self::auth_types(); + continue; + } foreach($data['allowed'] as $label => $value) { if (is_int($label)) @@ -331,6 +339,47 @@ class setup_cmd_config extends setup_cmd } return $options; } + + /** + * Read auth-types (existing auth backends) from filesystem and fix our $options array + * + * @return array + */ + static function auth_types() + { + // default backends in order of importance + static $auth_types = array( + 'sql' => 'SQL', + 'ldap' => 'LDAP', + 'mail' => 'Mail', + 'ads' => 'Active Directory', + 'http' => 'HTTP', + 'fallback' => 'Fallback LDAP --> SQL', + 'sqlssl' => 'SQL / SSL', + ); + static $scan_done; + if (!$scan_done++) + { + // now add auth backends found in filesystem + foreach(scandir(EGW_INCLUDE_ROOT.'/phpgwapi/inc') as $class) + { + if (preg_match('/^class\.auth_([a-z]+)\.inc\.php$/',$class,$matches) && + !isset($auth_types[$matches[1]])) + { + $auth_types[$matches[1]] = ucfirst($matches[1]); + } + } + foreach(self::$options['--account-auth'] as &$param) + { + if ($param['name'] == 'auth_type') + { + $param['allowed'] = array_keys($auth_types); + break; + } + } + } + return $auth_types; + } /** * Return the defaults from the $options array diff --git a/setup/inc/hook_config.inc.php b/setup/inc/hook_config.inc.php index 4c2321b2b0..fe938cb2aa 100644 --- a/setup/inc/hook_config.inc.php +++ b/setup/inc/hook_config.inc.php @@ -239,20 +239,41 @@ function sql_passwdhashes($config) */ function mail_login_type($config) { - $types = emailadmin_ui::getIMAPLoginTypes('cyrusimap'); - unset($types['admin']); - - foreach($types as $value => $label) + return _options_from(emailadmin_ui::getIMAPLoginTypes('cyrusimap'),$config['mail_login_type']); +} + +/** + * Make auth-types from setup_cmd_config available + * + * @param array $config + * @return string + */ +function auth_type($config) +{ + return _options_from(setup_cmd_config::auth_types(),$config['auth_type']); +} +function auth_type_syncml($config) +{ + return _options_from(setup_cmd_config::auth_types(),$config['auth_type_syncml']); +} +function auth_type_groupdav($config) +{ + return _options_from(setup_cmd_config::auth_types(),$config['auth_type_groupdav']); +} + +/** + * Returns options string + * + * @param array $options value => label pairs + * @param string $selected value of selected optino + * @return string + */ +function _options_from(array $options,$selected) +{ + foreach($options as $value => $label) { - if($config['mail_login_type'] == $value) - { - $selected = ' selected="selected"'; - } - else - { - $selected = ''; - } - $out .= '' . "\n"; + $out .= '' . "\n"; } return $out; } diff --git a/setup/templates/default/config.tpl b/setup/templates/default/config.tpl index 79a3d0835e..5914b4d825 100644 --- a/setup/templates/default/config.tpl +++ b/setup/templates/default/config.tpl @@ -213,16 +213,7 @@ {lang_Select_which_type_of_authentication_you_are_using}: @@ -232,15 +223,7 @@ @@ -250,15 +233,7 @@