91addea8dc801ee87f716c4335e77b41b0fa9023
[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 /* Verify that username and password are correct. */
81 if ($force_username_lowercase) {
82 $login_username = strtolower($login_username);
83 }
84
85 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
86 if (!$imapConnection) {
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( $errString, $errTitle );
92 exit;
93 } else {
94 $sqimap_capabilities = sqimap_capability($imapConnection);
95 session_register('sqimap_capabilities');
96 $delimiter = sqimap_get_delimiter ($imapConnection);
97 }
98 sqimap_logout($imapConnection);
99 session_register('delimiter');
100 global $username;
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']) &&
124 !isset($attachment_common_types_parsed[$HTTP_SERVER_VARS['HTTP_ACCEPT']])) {
125 attachment_common_parse($HTTP_SERVER_VARS['HTTP_ACCEPT'], $debug);
126 }
127 if (isset($HTTP_ACCEPT) &&
128 !isset($attachment_common_types_parsed[$HTTP_ACCEPT])) {
129 attachment_common_parse($HTTP_ACCEPT, $debug);
130 }
131
132 /* Complete autodetection of Javascript. */
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);
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 }
144 } else {
145 $js_pref = SMPREF_JS_OFF;
146 }
147 }
148 /* Update the prefs */
149 setPref($data_dir, $username, 'javascript_on', $js_pref);
150
151 global $attachments;
152 $attachments = unserialize(getPref($data_dir, $username, 'attachments', 0));
153 /* Compute the URL to forward the user to. */
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);
164 if (is_array($attachments)) {
165 session_register('attachments');
166 }
167 } else {
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 }
178 $redirect_url = 'webmail.php';
179 }
180
181 /* Send them off to the appropriate page. */
182 header("Location: $redirect_url");
183
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
204 ?>