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