Remove sqsetcookieflush call (not needed)
[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 *
47ccfad4 8 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
4b4abf93 9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 */
202bcbcc 13$sInitLocation = 'redirect';
35586184 14
30967a1e 15/**
202bcbcc 16 * Include the SquirrelMail initialization file.
30967a1e 17 */
202bcbcc 18require('../include/init.php');
86725763 19
20/* SquirrelMail required files. */
202bcbcc 21require_once(SM_PATH . 'functions/imap_general.php');
86725763 22require_once(SM_PATH . 'functions/strings.php');
5c3b0995 23
24header('Pragma: no-cache');
25$location = get_location();
26
202bcbcc 27// session_set_cookie_params (0, $base_uri);
5c3b0995 28
ad839713 29sqsession_unregister ('user_is_logged_in');
30sqsession_register ($base_uri, 'base_uri');
5c3b0995 31
a32985a5 32/* get globals we me need */
5250f7e7 33sqGetGlobalVar('login_username', $login_username);
34sqGetGlobalVar('secretkey', $secretkey);
5250f7e7 35if(!sqGetGlobalVar('squirrelmail_language', $squirrelmail_language) || $squirrelmail_language == '') {
134e4174 36 $squirrelmail_language = $squirrelmail_default_language;
a32985a5 37}
7e2ff844 38if (!sqgetGlobalVar('mailtodata', $mailtodata)) {
39 $mailtodata = '';
c67e4479 40}
5250f7e7 41
a32985a5 42/* end of get globals */
43
5c3b0995 44set_up_language($squirrelmail_language, true);
45/* Refresh the language cookie. */
3a1de9f1 46sqsetcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,
85b454a0 47 $base_uri);
5c3b0995 48
49if (!isset($login_username)) {
91e0dccc 50 logout_error( _("You must be logged in to access this page.") );
5c3b0995 51 exit;
52}
53
d7c82551 54if (!sqsession_is_registered('user_is_logged_in')) {
6e515418 55 do_hook('login_before', $null);
5c3b0995 56
57 $onetimepad = OneTimePadCreate(strlen($secretkey));
58 $key = OneTimePadEncrypt($secretkey, $onetimepad);
5c3b0995 59
fd1b516b 60 /* remove redundant spaces */
61 $login_username = trim($login_username);
62
5c3b0995 63 /* Verify that username and password are correct. */
64 if ($force_username_lowercase) {
65 $login_username = strtolower($login_username);
23d6bd09 66 }
67
5c3b0995 68 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
202bcbcc 69 /* From now on we are logged it. If the login failed then sqimap_login handles it */
70
71 /* regenerate the session id to avoid session hyijacking */
72 sqsession_destroy();
66c7cd3f 73 @sqsession_is_active();
202bcbcc 74 session_regenerate_id();
75 /**
76 * The cookie part. session_start and session_regenerate_session normally set
77 * their own cookie. SquirrelMail sets another cookie which overwites the
78 * php cookies. The sqsetcookie function sets the cookie by using the header
79 * function which gives us full control how the cookie is set. We do that
80 * to add the HttpOnly cookie attribute which blocks javascript access on
81 * IE6 SP1.
202bcbcc 82 */
83 sqsetcookie(session_name(),session_id(),false,$base_uri);
84 sqsetcookie('key', $key, false, $base_uri);
202bcbcc 85
86 sqsession_register($onetimepad, 'onetimepad');
44925ab0 87
88 $sqimap_capabilities = sqimap_capability($imapConnection);
f027a882 89
90 /* Server side sorting control */
91 if (isset($sqimap_capabilities['SORT']) && $sqimap_capabilities['SORT'] == true &&
92 isset($disable_server_sort) && $disable_server_sort) {
93 unset($sqimap_capabilities['SORT']);
94 }
95
96 /* Thread sort control */
97 if (isset($sqimap_capabilities['THREAD']) && $sqimap_capabilities['THREAD'] == true &&
98 isset($disable_thread_sort) && $disable_thread_sort) {
99 unset($sqimap_capabilities['THREAD']);
100 }
101
44925ab0 102 sqsession_register($sqimap_capabilities, 'sqimap_capabilities');
103 $delimiter = sqimap_get_delimiter ($imapConnection);
104
6a645613 105 if (isset($sqimap_capabilities['NAMESPACE']) && $sqimap_capabilities['NAMESPACE'] == true) {
106 $namespace = sqimap_get_namespace($imapConnection);
107 sqsession_register($namespace, 'sqimap_namespace');
108 }
109
5c3b0995 110 sqimap_logout($imapConnection);
a32985a5 111 sqsession_register($delimiter, 'delimiter');
112
5c3b0995 113 $username = $login_username;
ad839713 114 sqsession_register ($username, 'username');
6e515418 115 do_hook('login_verified', $null);
5c3b0995 116}
117
118/* Set the login variables. */
119$user_is_logged_in = true;
120$just_logged_in = true;
121
122/* And register with them with the session. */
a32985a5 123sqsession_register ($user_is_logged_in, 'user_is_logged_in');
124sqsession_register ($just_logged_in, 'just_logged_in');
5c3b0995 125
126/* parse the accepted content-types of the client */
127$attachment_common_types = array();
128$attachment_common_types_parsed = array();
a32985a5 129sqsession_register($attachment_common_types, 'attachment_common_types');
130sqsession_register($attachment_common_types_parsed, 'attachment_common_types_parsed');
5c3b0995 131
132$debug = false;
a32985a5 133
1e12d1ff 134if ( sqgetGlobalVar('HTTP_ACCEPT', $http_accept, SQ_SERVER) &&
135 !isset($attachment_common_types_parsed[$http_accept]) ) {
136 attachment_common_parse($http_accept, $debug);
9be8198d 137}
5c3b0995 138
139/* Complete autodetection of Javascript. */
1a531551 140checkForJavascript();
5c3b0995 141
142/* Compute the URL to forward the user to. */
d7746ca5 143$redirect_url = $location . '/webmail.php';
cab6eaea 144
145if ( sqgetGlobalVar('session_expired_location', $session_expired_location, SQ_SESSION) ) {
146 sqsession_unregister('session_expired_location');
c6f28eb1 147 if ( strpos($session_expired_location, 'compose.php') !== FALSE ) {
148 $compose_new_win = getPref($data_dir, $username, 'compose_new_win', 0);
149 if ($compose_new_win) {
150 // do not prefix $location here because $session_expired_location is set to PHP_SELF
151 // of the last page
152 $redirect_url = $session_expired_location;
153 } else {
154 $redirect_url = $location.'/webmail.php?right_frame='.urldecode($session_expired_location);
155 }
8e54a58b 156 }
cab6eaea 157 unset($session_expired_location);
158}
202bcbcc 159
7e2ff844 160if($mailtodata != '') {
161 $redirect_url = $location . '/webmail.php?right_frame=compose.php&mailtodata=';
162 $redirect_url .= urlencode($mailtodata);
c67e4479 163}
177dde45 164
7bde5272 165/* Write session data and send them off to the appropriate page. */
166session_write_close();
5c3b0995 167header("Location: $redirect_url");
202bcbcc 168exit;
7baf86a9 169
cab99c3a 170/* --------------------- end main ----------------------- */
171
172function attachment_common_parse($str, $debug) {
173 global $attachment_common_types, $attachment_common_types_parsed;
174
175 $attachment_common_types_parsed[$str] = true;
91e0dccc 176
177 /*
178 * Replace ", " with "," and explode on that as Mozilla 1.x seems to
20511953 179 * use "," to seperate whilst IE, and earlier versions of Mozilla use
180 * ", " to seperate
181 */
91e0dccc 182
20511953 183 $str = str_replace( ', ' , ',' , $str );
6c817138 184 $types = explode(',', $str);
cab99c3a 185
186 foreach ($types as $val) {
187 // Ignore the ";q=1.0" stuff
188 if (strpos($val, ';') !== false)
189 $val = substr($val, 0, strpos($val, ';'));
190
191 if (! isset($attachment_common_types[$val])) {
192 $attachment_common_types[$val] = true;
193 }
194 }
39c7209f 195 sqsession_register($attachment_common_types, 'attachment_common_types');
cab99c3a 196}