functions/global.php already strips slashes. Having this here twice would
[squirrelmail.git] / src / redirect.php
CommitLineData
7392739d 1<?php
895905c0 2
35586184 3/**
cab99c3a 4* redirect.php
5* Derived from webmail.php by Ralf Kraudelt <kraude@wiwi.uni-rostock.de>
6*
76911253 7* Copyright (c) 1999-2003 The SquirrelMail Project Team
cab99c3a 8* Licensed under the GNU GPL. For full terms see the file COPYING.
9*
10* Prevents users from reposting their form data after a successful logout.
11*
12* $Id$
13*/
35586184 14
86725763 15/* Path for SquirrelMail required files. */
16define('SM_PATH','../');
17
18/* SquirrelMail required files. */
1e12d1ff 19require_once(SM_PATH . 'functions/global.php');
86725763 20require_once(SM_PATH . 'functions/i18n.php');
21require_once(SM_PATH . 'functions/strings.php');
22require_once(SM_PATH . 'config/config.php');
23require_once(SM_PATH . 'functions/prefs.php');
24require_once(SM_PATH . 'functions/imap.php');
25require_once(SM_PATH . 'functions/plugin.php');
26require_once(SM_PATH . 'functions/constants.php');
27require_once(SM_PATH . 'functions/page_header.php');
cb48c245 28
5c3b0995 29/* Before starting the session, the base URI must be known. Assuming */
30/* that this file is in the src/ subdirectory (or something). */
f3bc099d 31if (!function_exists('sqm_baseuri')){
86725763 32 require_once(SM_PATH . 'functions/display_messages.php');
f3bc099d 33}
34$base_uri = sqm_baseuri();
5c3b0995 35
36header('Pragma: no-cache');
37$location = get_location();
38
39session_set_cookie_params (0, $base_uri);
40session_start();
41
ad839713 42sqsession_unregister ('user_is_logged_in');
43sqsession_register ($base_uri, 'base_uri');
5c3b0995 44
a32985a5 45/* get globals we me need */
5250f7e7 46sqGetGlobalVar('login_username', $login_username);
47sqGetGlobalVar('secretkey', $secretkey);
48sqGetGlobalVar('js_autodetect_results', $js_autodetect_results);
49if(!sqGetGlobalVar('squirrelmail_language', $squirrelmail_language) || $squirrelmail_language == '') {
50 $squirrelmail_language = $squirrelmail_default_language;
a32985a5 51}
5250f7e7 52
a32985a5 53/* end of get globals */
54
5c3b0995 55set_up_language($squirrelmail_language, true);
56/* Refresh the language cookie. */
85b454a0 57setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,
58 $base_uri);
5c3b0995 59
60if (!isset($login_username)) {
1e12d1ff 61 include_once(SM_PATH . 'functions/display_messages.php' );
9be8198d 62 logout_error( _("You must be logged in to access this page.") );
5c3b0995 63 exit;
64}
65
d7c82551 66if (!sqsession_is_registered('user_is_logged_in')) {
5c3b0995 67 do_hook ('login_before');
68
69 $onetimepad = OneTimePadCreate(strlen($secretkey));
70 $key = OneTimePadEncrypt($secretkey, $onetimepad);
a32985a5 71 sqsession_register($onetimepad, 'onetimepad');
5c3b0995 72
fd1b516b 73 /* remove redundant spaces */
74 $login_username = trim($login_username);
75
5c3b0995 76 /* Verify that username and password are correct. */
77 if ($force_username_lowercase) {
78 $login_username = strtolower($login_username);
23d6bd09 79 }
80
5c3b0995 81 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
44925ab0 82
83 $sqimap_capabilities = sqimap_capability($imapConnection);
84 sqsession_register($sqimap_capabilities, 'sqimap_capabilities');
85 $delimiter = sqimap_get_delimiter ($imapConnection);
86
5c3b0995 87 sqimap_logout($imapConnection);
a32985a5 88 sqsession_register($delimiter, 'delimiter');
89
5c3b0995 90 $username = $login_username;
ad839713 91 sqsession_register ($username, 'username');
5c3b0995 92 setcookie('key', $key, 0, $base_uri);
93 do_hook ('login_verified');
94
95}
96
97/* Set the login variables. */
98$user_is_logged_in = true;
99$just_logged_in = true;
100
101/* And register with them with the session. */
a32985a5 102sqsession_register ($user_is_logged_in, 'user_is_logged_in');
103sqsession_register ($just_logged_in, 'just_logged_in');
5c3b0995 104
105/* parse the accepted content-types of the client */
106$attachment_common_types = array();
107$attachment_common_types_parsed = array();
a32985a5 108sqsession_register($attachment_common_types, 'attachment_common_types');
109sqsession_register($attachment_common_types_parsed, 'attachment_common_types_parsed');
5c3b0995 110
111$debug = false;
a32985a5 112
1e12d1ff 113if ( sqgetGlobalVar('HTTP_ACCEPT', $http_accept, SQ_SERVER) &&
114 !isset($attachment_common_types_parsed[$http_accept]) ) {
115 attachment_common_parse($http_accept, $debug);
9be8198d 116}
5c3b0995 117
118/* Complete autodetection of Javascript. */
165829a3 119$javascript_setting = getPref
120 ($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT);
121$js_autodetect_results = (isset($js_autodetect_results) ?
122 $js_autodetect_results : SMPREF_JS_OFF);
18f734b9 123/* See if it's set to "Always on" */
124$js_pref = SMPREF_JS_ON;
125if ($javascript_setting != SMPREF_JS_ON){
126 if ($javascript_setting == SMPREF_JS_AUTODETECT) {
127 if ($js_autodetect_results == SMPREF_JS_OFF) {
128 $js_pref = SMPREF_JS_OFF;
129 }
23d6bd09 130 } else {
18f734b9 131 $js_pref = SMPREF_JS_OFF;
23d6bd09 132 }
5c3b0995 133}
18f734b9 134/* Update the prefs */
135setPref($data_dir, $username, 'javascript_on', $js_pref);
5c3b0995 136
137/* Compute the URL to forward the user to. */
cab6eaea 138$redirect_url = 'webmail.php';
139
140if ( sqgetGlobalVar('session_expired_location', $session_expired_location, SQ_SESSION) ) {
141 sqsession_unregister('session_expired_location');
142 $compose_new_win = getPref($data_dir, $username, 'compose_new_win', 0);
143 if ($compose_new_win) {
144 $redirect_url = $session_expired_location;
145 } elseif ( strpos($session_expired_location, 'webmail.php') === FALSE ) {
146 $redirect_url = 'webmail.php?right_frame='.urldecode($session_expired_location);
8e54a58b 147 }
cab6eaea 148 unset($session_expired_location);
149}
177dde45 150
7bde5272 151/* Write session data and send them off to the appropriate page. */
152session_write_close();
5c3b0995 153header("Location: $redirect_url");
7baf86a9 154
cab99c3a 155/* --------------------- end main ----------------------- */
156
157function attachment_common_parse($str, $debug) {
158 global $attachment_common_types, $attachment_common_types_parsed;
159
160 $attachment_common_types_parsed[$str] = true;
20511953 161
162 /*
163 * Replace ", " with "," and explode on that as Mozilla 1.x seems to
164 * use "," to seperate whilst IE, and earlier versions of Mozilla use
165 * ", " to seperate
166 */
167
168 $str = str_replace( ', ' , ',' , $str );
6c817138 169 $types = explode(',', $str);
cab99c3a 170
171 foreach ($types as $val) {
172 // Ignore the ";q=1.0" stuff
173 if (strpos($val, ';') !== false)
174 $val = substr($val, 0, strpos($val, ';'));
175
176 if (! isset($attachment_common_types[$val])) {
177 $attachment_common_types[$val] = true;
178 }
179 }
e86403df 180 $_SESSION['attachment_common_types'] = $attachment_common_types;
cab99c3a 181}
182
183
86725763 184?>