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