Remove sqsetcookieflush call (not needed)
[squirrelmail.git] / src / redirect.php
... / ...
CommitLineData
1<?php
2
3/**
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 *
8 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 */
13$sInitLocation = 'redirect';
14
15/**
16 * Include the SquirrelMail initialization file.
17 */
18require('../include/init.php');
19
20/* SquirrelMail required files. */
21require_once(SM_PATH . 'functions/imap_general.php');
22require_once(SM_PATH . 'functions/strings.php');
23
24header('Pragma: no-cache');
25$location = get_location();
26
27// session_set_cookie_params (0, $base_uri);
28
29sqsession_unregister ('user_is_logged_in');
30sqsession_register ($base_uri, 'base_uri');
31
32/* get globals we me need */
33sqGetGlobalVar('login_username', $login_username);
34sqGetGlobalVar('secretkey', $secretkey);
35if(!sqGetGlobalVar('squirrelmail_language', $squirrelmail_language) || $squirrelmail_language == '') {
36 $squirrelmail_language = $squirrelmail_default_language;
37}
38if (!sqgetGlobalVar('mailtodata', $mailtodata)) {
39 $mailtodata = '';
40}
41
42/* end of get globals */
43
44set_up_language($squirrelmail_language, true);
45/* Refresh the language cookie. */
46sqsetcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,
47 $base_uri);
48
49if (!isset($login_username)) {
50 logout_error( _("You must be logged in to access this page.") );
51 exit;
52}
53
54if (!sqsession_is_registered('user_is_logged_in')) {
55 do_hook('login_before', $null);
56
57 $onetimepad = OneTimePadCreate(strlen($secretkey));
58 $key = OneTimePadEncrypt($secretkey, $onetimepad);
59
60 /* remove redundant spaces */
61 $login_username = trim($login_username);
62
63 /* Verify that username and password are correct. */
64 if ($force_username_lowercase) {
65 $login_username = strtolower($login_username);
66 }
67
68 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
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();
73 @sqsession_is_active();
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.
82 */
83 sqsetcookie(session_name(),session_id(),false,$base_uri);
84 sqsetcookie('key', $key, false, $base_uri);
85
86 sqsession_register($onetimepad, 'onetimepad');
87
88 $sqimap_capabilities = sqimap_capability($imapConnection);
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
102 sqsession_register($sqimap_capabilities, 'sqimap_capabilities');
103 $delimiter = sqimap_get_delimiter ($imapConnection);
104
105 if (isset($sqimap_capabilities['NAMESPACE']) && $sqimap_capabilities['NAMESPACE'] == true) {
106 $namespace = sqimap_get_namespace($imapConnection);
107 sqsession_register($namespace, 'sqimap_namespace');
108 }
109
110 sqimap_logout($imapConnection);
111 sqsession_register($delimiter, 'delimiter');
112
113 $username = $login_username;
114 sqsession_register ($username, 'username');
115 do_hook('login_verified', $null);
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. */
123sqsession_register ($user_is_logged_in, 'user_is_logged_in');
124sqsession_register ($just_logged_in, 'just_logged_in');
125
126/* parse the accepted content-types of the client */
127$attachment_common_types = array();
128$attachment_common_types_parsed = array();
129sqsession_register($attachment_common_types, 'attachment_common_types');
130sqsession_register($attachment_common_types_parsed, 'attachment_common_types_parsed');
131
132$debug = false;
133
134if ( sqgetGlobalVar('HTTP_ACCEPT', $http_accept, SQ_SERVER) &&
135 !isset($attachment_common_types_parsed[$http_accept]) ) {
136 attachment_common_parse($http_accept, $debug);
137}
138
139/* Complete autodetection of Javascript. */
140checkForJavascript();
141
142/* Compute the URL to forward the user to. */
143$redirect_url = $location . '/webmail.php';
144
145if ( sqgetGlobalVar('session_expired_location', $session_expired_location, SQ_SESSION) ) {
146 sqsession_unregister('session_expired_location');
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 }
156 }
157 unset($session_expired_location);
158}
159
160if($mailtodata != '') {
161 $redirect_url = $location . '/webmail.php?right_frame=compose.php&mailtodata=';
162 $redirect_url .= urlencode($mailtodata);
163}
164
165/* Write session data and send them off to the appropriate page. */
166session_write_close();
167header("Location: $redirect_url");
168exit;
169
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;
176
177 /*
178 * Replace ", " with "," and explode on that as Mozilla 1.x seems to
179 * use "," to seperate whilst IE, and earlier versions of Mozilla use
180 * ", " to seperate
181 */
182
183 $str = str_replace( ', ' , ',' , $str );
184 $types = explode(',', $str);
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 }
195 sqsession_register($attachment_common_types, 'attachment_common_types');
196}