X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=include%2Finit.php;h=e7f0f1d921da041c7f90a0f8fb06eeee27d2475e;hb=f0d28f448867777aafe13b1106204765c229c17a;hp=cc2b8e43a2eae012b28e9ca86c394674a30c480b;hpb=f8e686053e1aaefc590e0dac537bdcaf92fde20f;p=squirrelmail.git diff --git a/include/init.php b/include/init.php index cc2b8e43..e7f0f1d9 100644 --- a/include/init.php +++ b/include/init.php @@ -18,6 +18,13 @@ error_reporting(E_ALL); +/** + * Make sure we have a page name + * + */ +if ( !defined('PAGE_NAME') ) define('PAGE_NAME', NULL); + + /** * If register_globals are on, unregister globals. * Second test covers boolean set as string (php_value register_globals off). @@ -78,6 +85,7 @@ if (!(bool)ini_get('session.use_cookies') || ini_set('session.use_cookies','1'); } + /** * calculate SM_PATH and calculate the base_uri * assumptions made: init.php is only called from plugins or from the src dir. @@ -85,27 +93,29 @@ if (!(bool)ini_get('session.use_cookies') || * */ if (isset($_SERVER['SCRIPT_NAME'])) { - $a = explode('/',$_SERVER['SCRIPT_NAME']); + $a = explode('/', $_SERVER['SCRIPT_NAME']); } elseif (isset($HTTP_SERVER_VARS['SCRIPT_NAME'])) { - $a = explode('/',$HTTP_SERVER_VARS['SCRIPT_NAME']); + $a = explode('/', $HTTP_SERVER_VARS['SCRIPT_NAME']); } else { - $error = 'Unable to detect script environment. ' - .'Please test your PHP settings and send PHP core config, $_SERVER ' - .'and $HTTP_SERVER_VARS to SquirrelMail developers.'; + $error = 'Unable to detect script environment. Please test your PHP ' + . 'settings and send your PHP core configuration, $_SERVER and ' + . '$HTTP_SERVER_VARS contents to the SquirrelMail developers.'; die($error); } $sSM_PATH = ''; -for($i = count($a) -2;$i > -1; --$i) { +for($i = count($a) -2; $i > -1; --$i) { $sSM_PATH .= '../'; if ($a[$i] === 'src' || $a[$i] === 'plugins') { break; } } -$base_uri = implode('/',array_slice($a,0,$i)). '/'; +$base_uri = implode('/', array_slice($a, 0, $i)). '/'; define('SM_PATH',$sSM_PATH); define('SM_BASE_URI', $base_uri); + + /** * global var $bInit is used to check if initialisation took place. * At this moment it's a workarounf for the include of addrbook_search_html @@ -199,12 +209,11 @@ if (!isset($session_name) || !$session_name) { } /** - * if session.auto_start is On then close the session + * When session.auto_start is On we want to destroy/close the session */ $sSessionAutostartName = session_name(); $sCookiePath = null; -if ((isset($sSessionAutostartName) || $sSessionAutostartName == '') && - $sSessionAutostartName !== $session_name) { +if (isset($sSessionAutostartName) && $sSessionAutostartName !== $session_name) { $sCookiePath = ini_get('session.cookie_path'); $sCookieDomain = ini_get('session.cookie_domain'); // reset the cookie @@ -222,6 +231,82 @@ ini_set('session.name' , $session_name); session_set_cookie_params (0, $base_uri); sqsession_is_active(); +/** + * When on login page, have to reset the user session, making + * sure to save session restore data first + */ +if (PAGE_NAME == 'login') { + if (!sqGetGlobalVar('session_expired_post', $sep, SQ_SESSION)) + $sep = ''; + if (!sqGetGlobalVar('session_expired_location', $sel, SQ_SESSION)) + $sel = ''; + sqsession_destroy(); + session_write_close(); + + /** + * in some rare instances, the session seems to stick + * around even after destroying it (!!), so if it does, + * we'll manually flatten the $_SESSION data + */ + if (!empty($_SESSION)) + $_SESSION = array(); + + /** + * Allow administrators to define custom session handlers + * for SquirrelMail without needing to change anything in + * php.ini (application-level). + * + * In config_local.php, admin needs to put: + * + * $custom_session_handlers = array( + * 'my_open_handler', + * 'my_close_handler', + * 'my_read_handler', + * 'my_write_handler', + * 'my_destroy_handler', + * 'my_gc_handler', + * ); + * session_module_name('user'); + * session_set_save_handler( + * $custom_session_handlers[0], + * $custom_session_handlers[1], + * $custom_session_handlers[2], + * $custom_session_handlers[3], + * $custom_session_handlers[4], + * $custom_session_handlers[5] + * ); + * + * We need to replicate that code once here because PHP has + * long had a bug that resets the session handler mechanism + * when the session data is also destroyed. Because of this + * bug, even administrators who define custom session handlers + * via a PHP pre-load defined in php.ini (auto_prepend_file) + * will still need to define the $custom_session_handlers array + * in config_local.php. + */ + global $custom_session_handlers; + if (!empty($custom_session_handlers)) { + $open = $custom_session_handlers[0]; + $close = $custom_session_handlers[1]; + $read = $custom_session_handlers[2]; + $write = $custom_session_handlers[3]; + $destroy = $custom_session_handlers[4]; + $gc = $custom_session_handlers[5]; + session_module_name('user'); + session_set_save_handler($open, $close, $read, $write, $destroy, $gc); + } + + sqsession_is_active(); + session_regenerate_id(); + + // put session restore data back into session if necessary + if (!empty($sel)) { + sqsession_register($sel, 'session_expired_location'); + if (!empty($sep)) + sqsession_register($sep, 'session_expired_post'); + } +} + /** * SquirrelMail internal version number -- DO NOT CHANGE * $sm_internal_version = array (release, major, minor) @@ -233,6 +318,7 @@ $SQM_INTERNAL_VERSION[2] = intval($SQM_INTERNAL_VERSION[2]); /* load prefs system; even when user not logged in, should be OK to do this here */ require(SM_PATH . 'functions/prefs.php'); +// FIXME: config/plugin_hooks.php has not yet been loaded (see a few lines below); so this hook call should I think not be working -- has anyone actually tested it? Is there any reason we cannot move this prefs code block down below "MAIN PLUGIN LOADING CODE HERE" (see below)? Reading the code, I *think* it should be OK, but.... Also, note that this code would then be placed immediately next to the config_override hook, and since it makes little sense to execute two hooks in a row, I will propose removing config_override (although sadly, it is less clear to plugin authors that they should use the prefs_backend hook to do any configuration override work in their plugin) $prefs_backend = do_hook('prefs_backend', $null); if (isset($prefs_backend) && !empty($prefs_backend) && file_exists(SM_PATH . $prefs_backend)) { require(SM_PATH . $prefs_backend); @@ -308,10 +394,9 @@ if (! sqgetGlobalVar('squirrelmail_language',$squirrelmail_language,SQ_COOKIE)) /** - * Do something special for some pages. This is based on the PAGE_NAME constand + * Do something special for some pages. This is based on the PAGE_NAME constant * set at the top of every page. */ -if ( !defined('PAGE_NAME') ) define('PAGE_NAME', NULL); switch (PAGE_NAME) { case 'style': @@ -345,6 +430,10 @@ switch (PAGE_NAME) { session_write_close(); break; + case 'mailto': + // nothing to do + break; + case 'redirect': require(SM_PATH . 'functions/auth.php'); //nobreak; @@ -446,8 +535,6 @@ switch (PAGE_NAME) { exit; } -//FIXME: remove next line if the placement of the copy of this line above does not prove to be problematic - sqgetGlobalVar('username',$username,SQ_SESSION); sqgetGlobalVar('authz',$authz,SQ_SESSION); /** @@ -588,6 +675,12 @@ if (version_compare(PHP_VERSION, "4.3.0", ">=")) { $oldErrorHandler = set_error_handler('SquirrelMailErrorhandler'); } + +// ============================================================================ +// ================= End of Live Code, Beginning of Functions ================= +// ============================================================================ + + /** * Javascript support detection function * @param boolean $reset recheck javascript support if set to true.