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 | * |
7 | * Copyright (c) 1999-2002 The SquirrelMail Project Team |
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 |
30 | if (get_magic_quotes_gpc()) { |
31 | global $REQUEST_METHOD; |
cab99c3a |
32 | |
5cc0b70e |
33 | if ($REQUEST_METHOD == 'POST') { |
26707265 |
34 | global $HTTP_POST_VARS; |
35 | RemoveSlashes($HTTP_POST_VARS); |
5cc0b70e |
36 | } else if ($REQUEST_METHOD == 'GET') { |
26707265 |
37 | global $HTTP_GET_VARS; |
38 | RemoveSlashes($HTTP_GET_VARS); |
39 | } |
40 | } |
41 | |
5c3b0995 |
42 | /* Before starting the session, the base URI must be known. Assuming */ |
43 | /* that this file is in the src/ subdirectory (or something). */ |
f3bc099d |
44 | if (!function_exists('sqm_baseuri')){ |
86725763 |
45 | require_once(SM_PATH . 'functions/display_messages.php'); |
f3bc099d |
46 | } |
47 | $base_uri = sqm_baseuri(); |
5c3b0995 |
48 | |
49 | header('Pragma: no-cache'); |
50 | $location = get_location(); |
51 | |
52 | session_set_cookie_params (0, $base_uri); |
53 | session_start(); |
54 | |
55 | session_unregister ('user_is_logged_in'); |
56 | session_register ('base_uri'); |
57 | |
58 | if (! isset($squirrelmail_language) || |
59 | $squirrelmail_language == '' ) { |
60 | $squirrelmail_language = $squirrelmail_default_language; |
61 | } |
62 | set_up_language($squirrelmail_language, true); |
63 | /* Refresh the language cookie. */ |
85b454a0 |
64 | setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000, |
65 | $base_uri); |
5c3b0995 |
66 | |
67 | if (!isset($login_username)) { |
9be8198d |
68 | include_once( '../functions/display_messages.php' ); |
69 | logout_error( _("You must be logged in to access this page.") ); |
5c3b0995 |
70 | exit; |
71 | } |
72 | |
73 | if (!session_is_registered('user_is_logged_in')) { |
74 | do_hook ('login_before'); |
75 | |
76 | $onetimepad = OneTimePadCreate(strlen($secretkey)); |
77 | $key = OneTimePadEncrypt($secretkey, $onetimepad); |
78 | session_register('onetimepad'); |
79 | |
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); |
86 | if (!$imapConnection) { |
9be8198d |
87 | $errTitle = _("There was an error contacting the mail server."); |
88 | $errString = $errTitle . "<br>\n". |
89 | _("Contact your administrator for help."); |
90 | include_once( '../functions/display_messages.php' ); |
91 | logout_error( _("You must be logged in to access this page.") ); |
5c3b0995 |
92 | exit; |
23d6bd09 |
93 | } else { |
8e54a58b |
94 | $sqimap_capabilities = sqimap_capability($imapConnection); |
95 | session_register('sqimap_capabilities'); |
5c3b0995 |
96 | $delimiter = sqimap_get_delimiter ($imapConnection); |
23d6bd09 |
97 | } |
5c3b0995 |
98 | sqimap_logout($imapConnection); |
99 | session_register('delimiter'); |
8e54a58b |
100 | global $username; |
5c3b0995 |
101 | $username = $login_username; |
102 | session_register ('username'); |
103 | setcookie('key', $key, 0, $base_uri); |
104 | do_hook ('login_verified'); |
105 | |
106 | } |
107 | |
108 | /* Set the login variables. */ |
109 | $user_is_logged_in = true; |
110 | $just_logged_in = true; |
111 | |
112 | /* And register with them with the session. */ |
113 | session_register ('user_is_logged_in'); |
114 | session_register ('just_logged_in'); |
115 | |
116 | /* parse the accepted content-types of the client */ |
117 | $attachment_common_types = array(); |
118 | $attachment_common_types_parsed = array(); |
119 | session_register('attachment_common_types'); |
120 | session_register('attachment_common_types_parsed'); |
121 | |
122 | $debug = false; |
123 | if (isset($HTTP_SERVER_VARS['HTTP_ACCEPT']) && |
9be8198d |
124 | !isset($attachment_common_types_parsed[$HTTP_SERVER_VARS['HTTP_ACCEPT']])) { |
5c3b0995 |
125 | attachment_common_parse($HTTP_SERVER_VARS['HTTP_ACCEPT'], $debug); |
9be8198d |
126 | } |
5c3b0995 |
127 | if (isset($HTTP_ACCEPT) && |
9be8198d |
128 | !isset($attachment_common_types_parsed[$HTTP_ACCEPT])) { |
5c3b0995 |
129 | attachment_common_parse($HTTP_ACCEPT, $debug); |
9be8198d |
130 | } |
5c3b0995 |
131 | |
132 | /* Complete autodetection of Javascript. */ |
165829a3 |
133 | $javascript_setting = getPref |
134 | ($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT); |
135 | $js_autodetect_results = (isset($js_autodetect_results) ? |
136 | $js_autodetect_results : SMPREF_JS_OFF); |
18f734b9 |
137 | /* See if it's set to "Always on" */ |
138 | $js_pref = SMPREF_JS_ON; |
139 | if ($javascript_setting != SMPREF_JS_ON){ |
140 | if ($javascript_setting == SMPREF_JS_AUTODETECT) { |
141 | if ($js_autodetect_results == SMPREF_JS_OFF) { |
142 | $js_pref = SMPREF_JS_OFF; |
143 | } |
23d6bd09 |
144 | } else { |
18f734b9 |
145 | $js_pref = SMPREF_JS_OFF; |
23d6bd09 |
146 | } |
5c3b0995 |
147 | } |
18f734b9 |
148 | /* Update the prefs */ |
149 | setPref($data_dir, $username, 'javascript_on', $js_pref); |
5c3b0995 |
150 | |
177dde45 |
151 | global $attachments; |
152 | $attachments = unserialize(getPref($data_dir, $username, 'attachments', 0)); |
5c3b0995 |
153 | /* Compute the URL to forward the user to. */ |
8e54a58b |
154 | global $session_expired_location, $session_expired_post; |
155 | if (isset($session_expired_location) && $session_expired_location) { |
156 | $compose_new_win = getPref($data_dir, $username, 'compose_new_win', 0); |
157 | if ($compose_new_win) { |
158 | $redirect_url = $session_expired_location; |
159 | } else { |
160 | $redirect_url = 'webmail.php?right_frame='.urldecode($session_expired_location); |
161 | } |
162 | session_unregister('session_expired_location'); |
163 | unset($session_expired_location); |
177dde45 |
164 | if (is_array($attachments)) { |
165 | session_register('attachments'); |
166 | } |
8e54a58b |
167 | } else { |
177dde45 |
168 | if (is_array($attachments)) { |
169 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
170 | foreach ($attachments as $attachment) { |
171 | $attached_file = $hashed_attachment_dir.'/'.$attachment['localfilename']; |
172 | if (file_exists($attached_file)) { |
173 | unlink($attached_file); |
174 | } |
175 | } |
176 | removePref($data_dir, $username, 'attachments'); |
177 | } |
8e54a58b |
178 | $redirect_url = 'webmail.php'; |
179 | } |
177dde45 |
180 | |
5c3b0995 |
181 | /* Send them off to the appropriate page. */ |
182 | header("Location: $redirect_url"); |
7baf86a9 |
183 | |
cab99c3a |
184 | /* --------------------- end main ----------------------- */ |
185 | |
186 | function attachment_common_parse($str, $debug) { |
187 | global $attachment_common_types, $attachment_common_types_parsed; |
188 | |
189 | $attachment_common_types_parsed[$str] = true; |
190 | $types = explode(', ', $str); |
191 | |
192 | foreach ($types as $val) { |
193 | // Ignore the ";q=1.0" stuff |
194 | if (strpos($val, ';') !== false) |
195 | $val = substr($val, 0, strpos($val, ';')); |
196 | |
197 | if (! isset($attachment_common_types[$val])) { |
198 | $attachment_common_types[$val] = true; |
199 | } |
200 | } |
201 | } |
202 | |
203 | |
86725763 |
204 | ?> |