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