added information about header calls in displayHtmlHeader and integration
[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 */
35586184 13
30967a1e 14/**
15 * Path for SquirrelMail required files.
16 * @ignore
17 */
86725763 18define('SM_PATH','../');
19
20/* SquirrelMail required files. */
1e12d1ff 21require_once(SM_PATH . 'functions/global.php');
86725763 22require_once(SM_PATH . 'functions/i18n.php');
23require_once(SM_PATH . 'functions/strings.php');
24require_once(SM_PATH . 'config/config.php');
25require_once(SM_PATH . 'functions/prefs.php');
26require_once(SM_PATH . 'functions/imap.php');
27require_once(SM_PATH . 'functions/plugin.php');
28require_once(SM_PATH . 'functions/constants.php');
29require_once(SM_PATH . 'functions/page_header.php');
cb48c245 30
5c3b0995 31/* Before starting the session, the base URI must be known. Assuming */
32/* that this file is in the src/ subdirectory (or something). */
f3bc099d 33if (!function_exists('sqm_baseuri')){
86725763 34 require_once(SM_PATH . 'functions/display_messages.php');
f3bc099d 35}
36$base_uri = sqm_baseuri();
5c3b0995 37
38header('Pragma: no-cache');
39$location = get_location();
40
dce66e00 41session_set_cookie_params (0, $base_uri);
748ba6c0 42sqsession_is_active();
5c3b0995 43
ad839713 44sqsession_unregister ('user_is_logged_in');
45sqsession_register ($base_uri, 'base_uri');
5c3b0995 46
a32985a5 47/* get globals we me need */
5250f7e7 48sqGetGlobalVar('login_username', $login_username);
49sqGetGlobalVar('secretkey', $secretkey);
5250f7e7 50if(!sqGetGlobalVar('squirrelmail_language', $squirrelmail_language) || $squirrelmail_language == '') {
134e4174 51 $squirrelmail_language = $squirrelmail_default_language;
a32985a5 52}
c67e4479 53if (!sqgetGlobalVar('mailto', $mailto)) {
54 $mailto = '';
55}
5250f7e7 56
a32985a5 57/* end of get globals */
58
5c3b0995 59set_up_language($squirrelmail_language, true);
60/* Refresh the language cookie. */
3a1de9f1 61sqsetcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,
85b454a0 62 $base_uri);
5c3b0995 63
64if (!isset($login_username)) {
1e12d1ff 65 include_once(SM_PATH . 'functions/display_messages.php' );
91e0dccc 66 logout_error( _("You must be logged in to access this page.") );
5c3b0995 67 exit;
68}
69
d7c82551 70if (!sqsession_is_registered('user_is_logged_in')) {
5c3b0995 71 do_hook ('login_before');
72
73 $onetimepad = OneTimePadCreate(strlen($secretkey));
74 $key = OneTimePadEncrypt($secretkey, $onetimepad);
a32985a5 75 sqsession_register($onetimepad, 'onetimepad');
5c3b0995 76
fd1b516b 77 /* remove redundant spaces */
78 $login_username = trim($login_username);
79
5c3b0995 80 /* Verify that username and password are correct. */
81 if ($force_username_lowercase) {
82 $login_username = strtolower($login_username);
23d6bd09 83 }
84
5c3b0995 85 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
44925ab0 86
87 $sqimap_capabilities = sqimap_capability($imapConnection);
f027a882 88
89 /* Server side sorting control */
90 if (isset($sqimap_capabilities['SORT']) && $sqimap_capabilities['SORT'] == true &&
91 isset($disable_server_sort) && $disable_server_sort) {
92 unset($sqimap_capabilities['SORT']);
93 }
94
95 /* Thread sort control */
96 if (isset($sqimap_capabilities['THREAD']) && $sqimap_capabilities['THREAD'] == true &&
97 isset($disable_thread_sort) && $disable_thread_sort) {
98 unset($sqimap_capabilities['THREAD']);
99 }
100
44925ab0 101 sqsession_register($sqimap_capabilities, 'sqimap_capabilities');
102 $delimiter = sqimap_get_delimiter ($imapConnection);
103
5c3b0995 104 sqimap_logout($imapConnection);
a32985a5 105 sqsession_register($delimiter, 'delimiter');
106
5c3b0995 107 $username = $login_username;
ad839713 108 sqsession_register ($username, 'username');
3a1de9f1 109 sqsetcookie('key', $key, false, $base_uri);
5c3b0995 110 do_hook ('login_verified');
111
112}
113
114/* Set the login variables. */
115$user_is_logged_in = true;
116$just_logged_in = true;
117
118/* And register with them with the session. */
a32985a5 119sqsession_register ($user_is_logged_in, 'user_is_logged_in');
120sqsession_register ($just_logged_in, 'just_logged_in');
5c3b0995 121
122/* parse the accepted content-types of the client */
123$attachment_common_types = array();
124$attachment_common_types_parsed = array();
a32985a5 125sqsession_register($attachment_common_types, 'attachment_common_types');
126sqsession_register($attachment_common_types_parsed, 'attachment_common_types_parsed');
5c3b0995 127
128$debug = false;
a32985a5 129
1e12d1ff 130if ( sqgetGlobalVar('HTTP_ACCEPT', $http_accept, SQ_SERVER) &&
131 !isset($attachment_common_types_parsed[$http_accept]) ) {
132 attachment_common_parse($http_accept, $debug);
9be8198d 133}
5c3b0995 134
135/* Complete autodetection of Javascript. */
1a531551 136checkForJavascript();
5c3b0995 137
138/* Compute the URL to forward the user to. */
d7746ca5 139$redirect_url = $location . '/webmail.php';
cab6eaea 140
141if ( sqgetGlobalVar('session_expired_location', $session_expired_location, SQ_SESSION) ) {
142 sqsession_unregister('session_expired_location');
143 $compose_new_win = getPref($data_dir, $username, 'compose_new_win', 0);
144 if ($compose_new_win) {
d7746ca5 145 // do not prefix $location here because $session_expired_location is set to PHP_SELF
146 // of the last page
cab6eaea 147 $redirect_url = $session_expired_location;
148 } elseif ( strpos($session_expired_location, 'webmail.php') === FALSE ) {
d7746ca5 149 $redirect_url = $location.'/webmail.php?right_frame='.urldecode($session_expired_location);
8e54a58b 150 }
cab6eaea 151 unset($session_expired_location);
152}
c67e4479 153if($mailto != '') {
d7746ca5 154 $redirect_url = $location . '/webmail.php?right_frame=compose.php&mailto=';
3e56c08d 155 $redirect_url .= urlencode($mailto);
c67e4479 156}
177dde45 157
7bde5272 158/* Write session data and send them off to the appropriate page. */
159session_write_close();
5c3b0995 160header("Location: $redirect_url");
7baf86a9 161
cab99c3a 162/* --------------------- end main ----------------------- */
163
164function attachment_common_parse($str, $debug) {
165 global $attachment_common_types, $attachment_common_types_parsed;
166
167 $attachment_common_types_parsed[$str] = true;
91e0dccc 168
169 /*
170 * Replace ", " with "," and explode on that as Mozilla 1.x seems to
20511953 171 * use "," to seperate whilst IE, and earlier versions of Mozilla use
172 * ", " to seperate
173 */
91e0dccc 174
20511953 175 $str = str_replace( ', ' , ',' , $str );
6c817138 176 $types = explode(',', $str);
cab99c3a 177
178 foreach ($types as $val) {
179 // Ignore the ";q=1.0" stuff
180 if (strpos($val, ';') !== false)
181 $val = substr($val, 0, strpos($val, ';'));
182
183 if (! isset($attachment_common_types[$val])) {
184 $attachment_common_types[$val] = true;
185 }
186 }
39c7209f 187 sqsession_register($attachment_common_types, 'attachment_common_types');
cab99c3a 188}
189
f8a1ed5a 190?>