allow to use HTTP_HOST (without optional port) or SERVER_NAME to find matching instance

This commit is contained in:
Ralf Becker 2012-10-12 15:11:42 +00:00
parent 870d49f881
commit 4c5b764347
2 changed files with 24 additions and 17 deletions

View File

@ -1336,21 +1336,25 @@ class egw_session
* @param string $login on login $_POST['login'], $_SERVER['PHP_AUTH_USER'] or $_SERVER['REMOTE_USER']
* @param string $domain_requested usually self::get_request('domain')
* @param string &$default_domain usually $default_domain get's set eg. by sitemgr
* @param string $server_name usually $_SERVER['SERVER_NAME']
* @param string|array $server_name usually array($_SERVER['HTTP_HOST'], $_SERVER['SERVER_NAME'])
* @param array $domains=null defaults to $GLOBALS['egw_domain'] from the header
* @return string $GLOBALS['egw_info']['user']['domain'] set with the domain/instance to use
*/
public static function search_instance($login,$domain_requested,&$default_domain,$server_name,array $domains=null)
public static function search_instance($login,$domain_requested,&$default_domain,$server_names,array $domains=null)
{
if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".'$server_name'.".array2string($domains).")");
if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")");
if (is_null($domains)) $domains = $GLOBALS['egw_domain'];
if (!isset($default_domain) || !isset($domains[$default_domain])) // allow to overwrite the default domain
{
foreach((array)$server_names as $server_name)
{
list($server_name) = explode(':', $server_name); // remove port from HTTP_HOST
if(isset($domains[$server_name]))
{
$default_domain = $server_name;
break;
}
else
{
@ -1360,6 +1364,7 @@ class egw_session
if(isset($domains[$domain_part]))
{
$default_domain = $domain_part;
break;
}
else
{
@ -1369,6 +1374,7 @@ class egw_session
unset($domain_part);
}
}
}
if (isset($login)) // on login
{
if (strpos($login,'@') === false || count($domains) == 1)

View File

@ -115,7 +115,8 @@ print_debug('sane environment','messageonly','api');
$GLOBALS['egw_info']['user']['domain'] = egw_session::search_instance(
isset($_POST['login']) ? $_POST['login'] : (isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : $_SERVER['REMOTE_USER']),
egw_session::get_request('domain'),$GLOBALS['egw_info']['server']['default_domain'],$_SERVER['SERVER_NAME'],$GLOBALS['egw_domain']);
egw_session::get_request('domain'),$GLOBALS['egw_info']['server']['default_domain'],
array($_SERVER['HTTP_HOST'], $_SERVER['SERVER_NAME']),$GLOBALS['egw_domain']);
$GLOBALS['egw_info']['server']['db_host'] = $GLOBALS['egw_domain'][$GLOBALS['egw_info']['user']['domain']]['db_host'];
$GLOBALS['egw_info']['server']['db_port'] = $GLOBALS['egw_domain'][$GLOBALS['egw_info']['user']['domain']]['db_port'];