From: kink Date: Mon, 17 Jul 2006 14:42:06 +0000 (+0000) Subject: Make the base for the SquirrelMail URL configurable. Adds a new variable X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=74530cf4e12212c9597a5f29c9f0ed1d31bdb65d;p=squirrelmail.git Make the base for the SquirrelMail URL configurable. Adds a new variable config_base_location to config.php and a new option to conf.pl. This is to prevent problems in installs where our heuristic doesn't work correctly (#1521299, #1460675, #1110064, #1000850, #1113791) I believe this is one of the most commonly reported issues in current stable. That's why I've created the code to be minimally invasive: it only allows to set the proto+host+port part, because this means all changes can remain within get_location(). I want to backport this bugfix to stable so I appreciate any feedback on it. And also of course if you think that this is the wrong way to solve it :) git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@11405 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/ChangeLog b/ChangeLog index ca8688ee..baa11fd7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -100,6 +100,10 @@ Version 1.5.2 - CVS type options from spamcop plugin. - Removed trailing ?> from function scripts. - Added checks for non-existent backend to AddressBook class. + - Make the base for the SquirrelMail URL configurable. Adds a new variable + config_base_location to config.php and a new option to conf.pl. This is + to prevent problems in installs where our heuristic doesn't work + correctly (#1521299, #1460675, #1110064, #1000850, #1113791). Version 1.5.1 (branched on 2006-02-12) -------------------------------------- diff --git a/config/conf.pl b/config/conf.pl index c19852bf..2684ab40 100755 --- a/config/conf.pl +++ b/config/conf.pl @@ -391,6 +391,7 @@ $abook_global_file_listing = 'true' if ( !$abook_global_file_listing ); $encode_header_key = '' if ( !$encode_header_key ); $hide_auth_header = 'false' if ( !$hide_auth_header ); $time_zone_type = '0' if ( !$time_zone_type ); +$config_location_base = '' if ( !$config_location_base ); $prefs_user_size = 128 if ( !$prefs_user_size ); $prefs_key_size = 64 if ( !$prefs_key_size ); $prefs_val_size = 65536 if ( !$prefs_val_size ); @@ -596,6 +597,7 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) && ( $command ne ":q" ) ) { print "13. Allow advanced search : $WHT$allow_advanced_search$NRM\n"; print "14. PHP session name : $WHT$session_name$NRM\n"; print "15. Time zone configuration : $WHT$time_zone_type$NRM\n"; + print "16. Location base : $WHT$config_location_base$NRM\n"; print "\n"; print "R Return to Main Menu\n"; } elsif ( $menu == 5 ) { @@ -831,6 +833,7 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) && ( $command ne ":q" ) ) { elsif ( $command == 13 ) { $allow_advanced_search = command316(); } elsif ( $command == 14 ) { $session_name = command317(); } elsif ( $command == 15 ) { $time_zone_type = command318(); } + elsif ( $command == 16 ) { $config_location_base = command319(); } } elsif ( $menu == 5 ) { if ( $command == 1 ) { $templateset_default = command_templates(); } elsif ( $command == 2 ) { $theme_css = command42(); } @@ -2441,6 +2444,25 @@ sub command318 { return $time_zone_type; } +# set the location base for redirects (since 1.5.2) +sub command319 { + print "Here you can set the base part of the SquirrelMail URL.\n"; + print "It is normally autodetected but if that fails, use this\n"; + print "option to override.\n"; + print "It should contain only the protocol and hostname/port parts\n"; + print "of the URL; the full path will be appended automatically.\n\n"; + print "Examples:\nhttp://webmail.example.org\nhttp://webmail.example.com:8080\nhttps://webmail.example.com:6691\n\n"; + print "Do not add any path elements.\n"; + + print "URL base? [" .$WHT."autodetect$NRM]: $WHT"; + $new_config_location_base = ; + chomp($new_config_location_base); + $config_location_base = $new_config_location_base; + + return $config_location_base; +} + + sub command41 { print "\nDefine the themes that you wish to use. If you have added "; @@ -3971,9 +3993,9 @@ sub save_data { # boolean print CF "\$hide_auth_header = $hide_auth_header;\n"; # boolean - print CF "\$disable_thread_sort = $disable_thread_sort;\n"; + print CF "\$disable_thread_sort = $disable_thread_sort;\n"; # boolean - print CF "\$disable_server_sort = $disable_server_sort;\n"; + print CF "\$disable_server_sort = $disable_server_sort;\n"; # boolean print CF "\$allow_charset_search = $allow_charset_search;\n"; # integer @@ -3982,6 +4004,9 @@ sub save_data { # integer print CF "\$time_zone_type = $time_zone_type;\n"; print CF "\n"; + # string + print CF "\$config_location_base = '$config_location_base';\n"; + print CF "\n"; # all plugins are strings for ( $ct = 0 ; $ct <= $#plugins ; $ct++ ) { diff --git a/config/config_default.php b/config/config_default.php index 704d208b..91532256 100644 --- a/config/config_default.php +++ b/config/config_default.php @@ -1119,6 +1119,29 @@ $lossy_encoding = false; */ $time_zone_type = 0; +/** + * Location base + * + * This is used to build the URL to the SquirrelMail location. + * It should contain only the protocol and hostname/port parts + * of the URL; the full path will be appended automatically. + * + * If not specified or empty, it will be autodetected. + * + * Examples: + * http://webmail.example.org + * http://webmail.example.com:8080 + * https://webmail.example.com:6691 + * + * To be clear: do not include any of the path elements, so if + * SquirrelMail is at http://www.example.net/web/mail/src/login.php, you + * write: http://www.example.net + * + * @global string $config_location_base; + * @since 1.5.2 + */ +$config_location_base = ''; + /*** Tweaks ***/ /** * Iframe sandbox code control diff --git a/functions/strings.php b/functions/strings.php index 31813f3d..650b9c5b 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -460,18 +460,17 @@ function readShortMailboxName($haystack, $needle) { * * Determines the location to forward to, relative to your server. * This is used in HTTP Location: redirects. - * If this doesnt work correctly for you (although it should), you can - * remove all this code except the last two lines, and have it return - * the right URL for your site, something like: * - * http://www.example.com/squirrelmail/ + * If set, it uses $config_location_base as the first part of the URL, + * specifically, the protocol, hostname and port parts. The path is + * always autodetected. * * @return string the base url for this SquirrelMail installation * @since 1.0 */ function get_location () { - global $imap_server_type; + global $imap_server_type, $config_location_base; /* Get the path, handle virtual directories */ if(strpos(php_self(), '?')) { @@ -480,9 +479,16 @@ function get_location () { $path = php_self(); } $path = substr($path, 0, strrpos($path, '/')); + + // proto+host+port are already set in config: + if ( !empty($config_location_base) ) { + return $config_location_base . $path ; + } + // we computed it before, get it from the session: if ( sqgetGlobalVar('sq_base_url', $full_url, SQ_SESSION) ) { return $full_url . $path; } + // else: autodetect /* Check if this is a HTTPS or regular HTTP request. */ $proto = 'http://'; @@ -518,19 +524,19 @@ function get_location () { } } - /* this is a workaround for the weird macosx caching that - causes Apache to return 16080 as the port number, which causes - SM to bail */ + /* this is a workaround for the weird macosx caching that + * causes Apache to return 16080 as the port number, which causes + * SM to bail */ - if ($imap_server_type == 'macosx' && $port == ':16080') { + if ($imap_server_type == 'macosx' && $port == ':16080') { $port = ''; - } + } - /* Fallback is to omit the server name and use a relative */ - /* URI, although this is not RFC 2616 compliant. */ - $full_url = ($host ? $proto . $host . $port : ''); - sqsession_register($full_url, 'sq_base_url'); - return $full_url . $path; + /* Fallback is to omit the server name and use a relative */ + /* URI, although this is not RFC 2616 compliant. */ + $full_url = ($host ? $proto . $host . $port : ''); + sqsession_register($full_url, 'sq_base_url'); + return $full_url . $path; } diff --git a/src/configtest.php b/src/configtest.php index 1ffb18d2..0d5a0cc2 100644 --- a/src/configtest.php +++ b/src/configtest.php @@ -301,7 +301,9 @@ if ( $squirrelmail_default_language != 'en_US' ) { echo $IND . "Default language OK.
\n"; } -echo $IND . "Base URL detected as: " . htmlspecialchars($test_location) . "
\n"; +echo $IND . "Base URL detected as: " . htmlspecialchars($test_location) . + " (location base " . (empty($config_location_base) ? 'autodetected' : 'set to ' . + htmlspecialchars($config_location_base)."") . ")
\n"; /* check minimal requirements for other security options */