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 |
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 */ |
56 | if (isset($_POST['login_username'])) { |
57 | $login_username = $_POST['login_username']; |
58 | } |
59 | if (!isset($_COOKIE['squirrelmail_language']) || |
5c3b0995 |
60 | $squirrelmail_language == '' ) { |
61 | $squirrelmail_language = $squirrelmail_default_language; |
62 | } |
a32985a5 |
63 | else { |
64 | $squirrelmail_language = $_COOKIE['squirrelmail_language']; |
65 | } |
66 | if (isset($_POST['secretkey'])) { |
67 | $secretkey = $_POST['secretkey']; |
68 | } |
69 | if (isset($_POST['js_autodetect_results'])) { |
70 | $js_autodetect_results = $_POST['js_autodetect_results']; |
71 | } |
72 | /* end of get globals */ |
73 | |
5c3b0995 |
74 | set_up_language($squirrelmail_language, true); |
75 | /* Refresh the language cookie. */ |
85b454a0 |
76 | setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000, |
77 | $base_uri); |
5c3b0995 |
78 | |
79 | if (!isset($login_username)) { |
9be8198d |
80 | include_once( '../functions/display_messages.php' ); |
81 | logout_error( _("You must be logged in to access this page.") ); |
5c3b0995 |
82 | exit; |
83 | } |
84 | |
85 | if (!session_is_registered('user_is_logged_in')) { |
86 | do_hook ('login_before'); |
87 | |
88 | $onetimepad = OneTimePadCreate(strlen($secretkey)); |
89 | $key = OneTimePadEncrypt($secretkey, $onetimepad); |
a32985a5 |
90 | sqsession_register($onetimepad, 'onetimepad'); |
5c3b0995 |
91 | |
fd1b516b |
92 | /* remove redundant spaces */ |
93 | $login_username = trim($login_username); |
94 | |
5c3b0995 |
95 | /* Verify that username and password are correct. */ |
96 | if ($force_username_lowercase) { |
97 | $login_username = strtolower($login_username); |
23d6bd09 |
98 | } |
99 | |
5c3b0995 |
100 | $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0); |
101 | if (!$imapConnection) { |
9be8198d |
102 | $errTitle = _("There was an error contacting the mail server."); |
103 | $errString = $errTitle . "<br>\n". |
104 | _("Contact your administrator for help."); |
105 | include_once( '../functions/display_messages.php' ); |
9640af33 |
106 | logout_error( $errString, $errTitle ); |
5c3b0995 |
107 | exit; |
23d6bd09 |
108 | } else { |
8e54a58b |
109 | $sqimap_capabilities = sqimap_capability($imapConnection); |
ad839713 |
110 | sqsession_register($sqimap_capabilities, 'sqimap_capabilities'); |
5c3b0995 |
111 | $delimiter = sqimap_get_delimiter ($imapConnection); |
23d6bd09 |
112 | } |
5c3b0995 |
113 | sqimap_logout($imapConnection); |
a32985a5 |
114 | sqsession_register($delimiter, 'delimiter'); |
115 | |
5c3b0995 |
116 | $username = $login_username; |
ad839713 |
117 | sqsession_register ($username, 'username'); |
5c3b0995 |
118 | setcookie('key', $key, 0, $base_uri); |
119 | do_hook ('login_verified'); |
120 | |
121 | } |
122 | |
123 | /* Set the login variables. */ |
124 | $user_is_logged_in = true; |
125 | $just_logged_in = true; |
126 | |
127 | /* And register with them with the session. */ |
a32985a5 |
128 | sqsession_register ($user_is_logged_in, 'user_is_logged_in'); |
129 | sqsession_register ($just_logged_in, 'just_logged_in'); |
5c3b0995 |
130 | |
131 | /* parse the accepted content-types of the client */ |
132 | $attachment_common_types = array(); |
133 | $attachment_common_types_parsed = array(); |
a32985a5 |
134 | sqsession_register($attachment_common_types, 'attachment_common_types'); |
135 | sqsession_register($attachment_common_types_parsed, 'attachment_common_types_parsed'); |
5c3b0995 |
136 | |
137 | $debug = false; |
a32985a5 |
138 | |
139 | if (isset($_SERVER['HTTP_ACCEPT']) && |
140 | !isset($attachment_common_types_parsed[$_SERVER['HTTP_ACCEPT']])) { |
141 | attachment_common_parse($_SERVER['HTTP_ACCEPT'], $debug); |
9be8198d |
142 | } |
a32985a5 |
143 | if (isset($_SERVER['HTTP_ACCEPT']) && |
144 | !isset($attachment_common_types_parsed[$_SERVER['HTTP_ACCEPT']])) { |
145 | attachment_common_parse($_SERVER['HTTP_ACCEPT'], $debug); |
9be8198d |
146 | } |
5c3b0995 |
147 | |
148 | /* Complete autodetection of Javascript. */ |
165829a3 |
149 | $javascript_setting = getPref |
150 | ($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT); |
151 | $js_autodetect_results = (isset($js_autodetect_results) ? |
152 | $js_autodetect_results : SMPREF_JS_OFF); |
18f734b9 |
153 | /* See if it's set to "Always on" */ |
154 | $js_pref = SMPREF_JS_ON; |
155 | if ($javascript_setting != SMPREF_JS_ON){ |
156 | if ($javascript_setting == SMPREF_JS_AUTODETECT) { |
157 | if ($js_autodetect_results == SMPREF_JS_OFF) { |
158 | $js_pref = SMPREF_JS_OFF; |
159 | } |
23d6bd09 |
160 | } else { |
18f734b9 |
161 | $js_pref = SMPREF_JS_OFF; |
23d6bd09 |
162 | } |
5c3b0995 |
163 | } |
18f734b9 |
164 | /* Update the prefs */ |
165 | setPref($data_dir, $username, 'javascript_on', $js_pref); |
5c3b0995 |
166 | |
177dde45 |
167 | global $attachments; |
168 | $attachments = unserialize(getPref($data_dir, $username, 'attachments', 0)); |
5c3b0995 |
169 | /* Compute the URL to forward the user to. */ |
8e54a58b |
170 | global $session_expired_location, $session_expired_post; |
171 | if (isset($session_expired_location) && $session_expired_location) { |
172 | $compose_new_win = getPref($data_dir, $username, 'compose_new_win', 0); |
173 | if ($compose_new_win) { |
174 | $redirect_url = $session_expired_location; |
175 | } else { |
176 | $redirect_url = 'webmail.php?right_frame='.urldecode($session_expired_location); |
177 | } |
e86403df |
178 | sqsession_unregister('session_expired_location'); |
8e54a58b |
179 | unset($session_expired_location); |
e86403df |
180 | if (is_array($compose_messages)) { |
181 | sqsession_register('compose_messages'); |
177dde45 |
182 | } |
8e54a58b |
183 | } else { |
e86403df |
184 | /* need to be adapted to compose_messages. |
177dde45 |
185 | if (is_array($attachments)) { |
186 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
187 | foreach ($attachments as $attachment) { |
188 | $attached_file = $hashed_attachment_dir.'/'.$attachment['localfilename']; |
189 | if (file_exists($attached_file)) { |
190 | unlink($attached_file); |
191 | } |
192 | } |
193 | removePref($data_dir, $username, 'attachments'); |
194 | } |
e86403df |
195 | */ |
8e54a58b |
196 | $redirect_url = 'webmail.php'; |
197 | } |
177dde45 |
198 | |
5c3b0995 |
199 | /* Send them off to the appropriate page. */ |
200 | header("Location: $redirect_url"); |
7baf86a9 |
201 | |
cab99c3a |
202 | /* --------------------- end main ----------------------- */ |
203 | |
204 | function attachment_common_parse($str, $debug) { |
205 | global $attachment_common_types, $attachment_common_types_parsed; |
206 | |
207 | $attachment_common_types_parsed[$str] = true; |
208 | $types = explode(', ', $str); |
209 | |
210 | foreach ($types as $val) { |
211 | // Ignore the ";q=1.0" stuff |
212 | if (strpos($val, ';') !== false) |
213 | $val = substr($val, 0, strpos($val, ';')); |
214 | |
215 | if (! isset($attachment_common_types[$val])) { |
216 | $attachment_common_types[$val] = true; |
217 | } |
218 | } |
e86403df |
219 | $_SESSION['attachment_common_types'] = $attachment_common_types; |
cab99c3a |
220 | } |
221 | |
222 | |
86725763 |
223 | ?> |