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