Add FIXME
[squirrelmail.git] / src / redirect.php
CommitLineData
7392739d 1<?php
895905c0 2
35586184 3/**
4b4abf93 4 * Prevents users from reposting their form data after a successful logout.
5 *
6 * Derived from webmail.php by Ralf Kraudelt <kraude@wiwi.uni-rostock.de>
7 *
d4e46166 8 * @copyright &copy; 1999-2009 The SquirrelMail Project Team
4b4abf93 9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 */
35586184 13
ebd2391c 14/** This is the redirect page */
15define('PAGE_NAME', 'redirect');
16
30967a1e 17/**
202bcbcc 18 * Include the SquirrelMail initialization file.
30967a1e 19 */
202bcbcc 20require('../include/init.php');
86725763 21
22/* SquirrelMail required files. */
202bcbcc 23require_once(SM_PATH . 'functions/imap_general.php');
86725763 24require_once(SM_PATH . 'functions/strings.php');
5c3b0995 25
26header('Pragma: no-cache');
27$location = get_location();
28
202bcbcc 29// session_set_cookie_params (0, $base_uri);
5c3b0995 30
ad839713 31sqsession_unregister ('user_is_logged_in');
32sqsession_register ($base_uri, 'base_uri');
5c3b0995 33
a32985a5 34/* get globals we me need */
5250f7e7 35sqGetGlobalVar('login_username', $login_username);
36sqGetGlobalVar('secretkey', $secretkey);
5250f7e7 37if(!sqGetGlobalVar('squirrelmail_language', $squirrelmail_language) || $squirrelmail_language == '') {
134e4174 38 $squirrelmail_language = $squirrelmail_default_language;
a32985a5 39}
7e2ff844 40if (!sqgetGlobalVar('mailtodata', $mailtodata)) {
41 $mailtodata = '';
c67e4479 42}
5250f7e7 43
a32985a5 44/* end of get globals */
45
5c3b0995 46set_up_language($squirrelmail_language, true);
47/* Refresh the language cookie. */
3a1de9f1 48sqsetcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,
85b454a0 49 $base_uri);
5c3b0995 50
51if (!isset($login_username)) {
91e0dccc 52 logout_error( _("You must be logged in to access this page.") );
5c3b0995 53 exit;
54}
55
9a02b0ef 56do_hook('login_before', $null);
5c3b0995 57
9a02b0ef 58$onetimepad = OneTimePadCreate(strlen($secretkey));
59$key = OneTimePadEncrypt($secretkey, $onetimepad);
5c3b0995 60
9a02b0ef 61/* remove redundant spaces */
62$login_username = trim($login_username);
fd1b516b 63
9a02b0ef 64/* Case-normalise username if so desired */
65if ($force_username_lowercase) {
66 $login_username = strtolower($login_username);
67}
44925ab0 68
9a02b0ef 69/* Verify that username and password are correct. */
70$imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
71/* From now on we are logged it. If the login failed then sqimap_login handles it */
f027a882 72
1f80d9f5 73/**
74 * Regenerate session id to make sure that authenticated session uses
75 * different ID than one used before user authenticated. This is a
76 * countermeasure against session fixation attacks.
77 * NB: session_regenerate_id() was added in PHP 4.3.2 (and new session
78 * cookie is only sent out in this call as of PHP 4.3.3), but PHP 4
79 * is not vulnerable to session fixation problems in SquirrelMail
80 * because it prioritizes $base_uri subdirectory cookies differently
81 * than PHP 5, which is otherwise vulnerable. If we really want to,
82 * we could define our own session_regenerate_id() when one does not
83 * exist, but there seems to be no reason to do so.
84 */
85sqsession_is_active();
86if (function_exists('session_regenerate_id')) {
87 session_regenerate_id();
88}
89
9a02b0ef 90/**
91* The cookie part. session_start and session_regenerate_session normally set
92* their own cookie. SquirrelMail sets another cookie which overwites the
93* php cookies. The sqsetcookie function sets the cookie by using the header
94* function which gives us full control how the cookie is set. We do that
95* to add the HttpOnly cookie attribute which blocks javascript access on
96* IE6 SP1.
97*/
98sqsetcookie(session_name(),session_id(),false,$base_uri);
99sqsetcookie('key', $key, false, $base_uri);
100
101sqsession_register($onetimepad, 'onetimepad');
102
103$sqimap_capabilities = sqimap_capability($imapConnection);
104
105/* Server side sorting control */
106if (isset($sqimap_capabilities['SORT']) && $sqimap_capabilities['SORT'] == true &&
107 isset($disable_server_sort) && $disable_server_sort) {
108 unset($sqimap_capabilities['SORT']);
109}
f027a882 110
9a02b0ef 111/* Thread sort control */
112if (isset($sqimap_capabilities['THREAD']) && $sqimap_capabilities['THREAD'] == true &&
113 isset($disable_thread_sort) && $disable_thread_sort) {
114 unset($sqimap_capabilities['THREAD']);
115}
f027a882 116
9a02b0ef 117sqsession_register($sqimap_capabilities, 'sqimap_capabilities');
118$delimiter = sqimap_get_delimiter ($imapConnection);
44925ab0 119
9a02b0ef 120if (isset($sqimap_capabilities['NAMESPACE']) && $sqimap_capabilities['NAMESPACE'] == true) {
121 $namespace = sqimap_get_namespace($imapConnection);
122 sqsession_register($namespace, 'sqimap_namespace');
123}
6a645613 124
9a02b0ef 125sqimap_logout($imapConnection);
126sqsession_register($delimiter, 'delimiter');
a32985a5 127
9a02b0ef 128$username = $login_username;
129sqsession_register ($username, 'username');
130do_hook('login_verified', $null);
5c3b0995 131
132/* Set the login variables. */
133$user_is_logged_in = true;
134$just_logged_in = true;
135
136/* And register with them with the session. */
a32985a5 137sqsession_register ($user_is_logged_in, 'user_is_logged_in');
138sqsession_register ($just_logged_in, 'just_logged_in');
5c3b0995 139
140/* parse the accepted content-types of the client */
141$attachment_common_types = array();
142$attachment_common_types_parsed = array();
a32985a5 143sqsession_register($attachment_common_types, 'attachment_common_types');
144sqsession_register($attachment_common_types_parsed, 'attachment_common_types_parsed');
5c3b0995 145
1e12d1ff 146if ( sqgetGlobalVar('HTTP_ACCEPT', $http_accept, SQ_SERVER) &&
147 !isset($attachment_common_types_parsed[$http_accept]) ) {
d9f8b0cc 148 attachment_common_parse($http_accept);
9be8198d 149}
5c3b0995 150
ef33def6 151// having just logged in, need to synch the template file cache
152// so the right template set is displayed (per user prefs)
153require(SM_PATH . 'include/load_prefs.php');
d81572f7 154global $sTemplateID;
155Template::cache_template_file_hierarchy($sTemplateID, TRUE);
ef33def6 156
5c3b0995 157/* Complete autodetection of Javascript. */
1a531551 158checkForJavascript();
5c3b0995 159
160/* Compute the URL to forward the user to. */
d7746ca5 161$redirect_url = $location . '/webmail.php';
cab6eaea 162
163if ( sqgetGlobalVar('session_expired_location', $session_expired_location, SQ_SESSION) ) {
164 sqsession_unregister('session_expired_location');
de219480 165 if ( $session_expired_location == 'compose' ) {
c6f28eb1 166 $compose_new_win = getPref($data_dir, $username, 'compose_new_win', 0);
167 if ($compose_new_win) {
de219480 168 // do not prefix $location here because $session_expired_location is set to the PAGE_NAME
c6f28eb1 169 // of the last page
319ad3c0 170 $redirect_url = $location . '/' . $session_expired_location . '.php';
c6f28eb1 171 } else {
319ad3c0 172 $redirect_url = $location . '/webmail.php?right_frame=' . urlencode($session_expired_location . '.php');
c6f28eb1 173 }
ef33def6 174 } else if ($session_expired_location != 'webmail'
175 && $session_expired_location != 'left_main') {
319ad3c0 176 $redirect_url = $location . '/webmail.php?right_frame=' . urlencode($session_expired_location . '.php');
8e54a58b 177 }
cab6eaea 178 unset($session_expired_location);
179}
202bcbcc 180
7e2ff844 181if($mailtodata != '') {
182 $redirect_url = $location . '/webmail.php?right_frame=compose.php&mailtodata=';
183 $redirect_url .= urlencode($mailtodata);
c67e4479 184}
177dde45 185
7bde5272 186/* Write session data and send them off to the appropriate page. */
187session_write_close();
5c3b0995 188header("Location: $redirect_url");
202bcbcc 189exit;
7baf86a9 190
cab99c3a 191/* --------------------- end main ----------------------- */
192
d9f8b0cc 193function attachment_common_parse($str) {
cab99c3a 194 global $attachment_common_types, $attachment_common_types_parsed;
195
91e0dccc 196 /*
197 * Replace ", " with "," and explode on that as Mozilla 1.x seems to
20511953 198 * use "," to seperate whilst IE, and earlier versions of Mozilla use
199 * ", " to seperate
200 */
91e0dccc 201
20511953 202 $str = str_replace( ', ' , ',' , $str );
6c817138 203 $types = explode(',', $str);
cab99c3a 204
205 foreach ($types as $val) {
206 // Ignore the ";q=1.0" stuff
9a02b0ef 207 if (strpos($val, ';') !== false) {
cab99c3a 208 $val = substr($val, 0, strpos($val, ';'));
9a02b0ef 209 }
cab99c3a 210 if (! isset($attachment_common_types[$val])) {
211 $attachment_common_types[$val] = true;
212 }
213 }
39c7209f 214 sqsession_register($attachment_common_types, 'attachment_common_types');
856e58ef 215
216 /* mark as parsed */
217 $attachment_common_types_parsed[$str] = true;
cab99c3a 218}