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