Spanish Update
[squirrelmail.git] / src / redirect.php
CommitLineData
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. */
16define('SM_PATH','../');
17
18/* SquirrelMail required files. */
19require_once(SM_PATH . 'functions/i18n.php');
20require_once(SM_PATH . 'functions/strings.php');
21require_once(SM_PATH . 'config/config.php');
22require_once(SM_PATH . 'functions/prefs.php');
23require_once(SM_PATH . 'functions/imap.php');
24require_once(SM_PATH . 'functions/plugin.php');
25require_once(SM_PATH . 'functions/constants.php');
26require_once(SM_PATH . 'functions/page_header.php');
27require_once(SM_PATH . 'functions/global.php');
cb48c245 28
26707265 29// Remove slashes if PHP added them
30if (get_magic_quotes_gpc()) {
31 global $REQUEST_METHOD;
cab99c3a 32
5cc0b70e 33 if ($REQUEST_METHOD == 'POST') {
26707265 34 global $HTTP_POST_VARS;
35 RemoveSlashes($HTTP_POST_VARS);
5cc0b70e 36 } else if ($REQUEST_METHOD == 'GET') {
26707265 37 global $HTTP_GET_VARS;
38 RemoveSlashes($HTTP_GET_VARS);
39 }
40}
41
5c3b0995 42/* Before starting the session, the base URI must be known. Assuming */
43/* that this file is in the src/ subdirectory (or something). */
f3bc099d 44if (!function_exists('sqm_baseuri')){
86725763 45 require_once(SM_PATH . 'functions/display_messages.php');
f3bc099d 46}
47$base_uri = sqm_baseuri();
5c3b0995 48
49header('Pragma: no-cache');
50$location = get_location();
51
52session_set_cookie_params (0, $base_uri);
53session_start();
54
55session_unregister ('user_is_logged_in');
56session_register ('base_uri');
57
58if (! isset($squirrelmail_language) ||
59 $squirrelmail_language == '' ) {
60 $squirrelmail_language = $squirrelmail_default_language;
61}
62set_up_language($squirrelmail_language, true);
63/* Refresh the language cookie. */
85b454a0 64setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,
65 $base_uri);
5c3b0995 66
67if (!isset($login_username)) {
9be8198d 68 include_once( '../functions/display_messages.php' );
69 logout_error( _("You must be logged in to access this page.") );
5c3b0995 70 exit;
71}
72
73if (!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
fd1b516b 80 /* remove redundant spaces */
81 $login_username = trim($login_username);
82
5c3b0995 83 /* Verify that username and password are correct. */
84 if ($force_username_lowercase) {
85 $login_username = strtolower($login_username);
23d6bd09 86 }
87
5c3b0995 88 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
89 if (!$imapConnection) {
9be8198d 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' );
9640af33 94 logout_error( $errString, $errTitle );
5c3b0995 95 exit;
23d6bd09 96 } else {
8e54a58b 97 $sqimap_capabilities = sqimap_capability($imapConnection);
98 session_register('sqimap_capabilities');
5c3b0995 99 $delimiter = sqimap_get_delimiter ($imapConnection);
23d6bd09 100 }
5c3b0995 101 sqimap_logout($imapConnection);
102 session_register('delimiter');
8e54a58b 103 global $username;
5c3b0995 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. */
116session_register ('user_is_logged_in');
117session_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();
122session_register('attachment_common_types');
123session_register('attachment_common_types_parsed');
124
125$debug = false;
126if (isset($HTTP_SERVER_VARS['HTTP_ACCEPT']) &&
9be8198d 127 !isset($attachment_common_types_parsed[$HTTP_SERVER_VARS['HTTP_ACCEPT']])) {
5c3b0995 128 attachment_common_parse($HTTP_SERVER_VARS['HTTP_ACCEPT'], $debug);
9be8198d 129}
5c3b0995 130if (isset($HTTP_ACCEPT) &&
9be8198d 131 !isset($attachment_common_types_parsed[$HTTP_ACCEPT])) {
5c3b0995 132 attachment_common_parse($HTTP_ACCEPT, $debug);
9be8198d 133}
5c3b0995 134
135/* Complete autodetection of Javascript. */
165829a3 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);
18f734b9 140/* See if it's set to "Always on" */
141$js_pref = SMPREF_JS_ON;
142if ($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 }
23d6bd09 147 } else {
18f734b9 148 $js_pref = SMPREF_JS_OFF;
23d6bd09 149 }
5c3b0995 150}
18f734b9 151/* Update the prefs */
152setPref($data_dir, $username, 'javascript_on', $js_pref);
5c3b0995 153
177dde45 154global $attachments;
155$attachments = unserialize(getPref($data_dir, $username, 'attachments', 0));
5c3b0995 156/* Compute the URL to forward the user to. */
8e54a58b 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);
177dde45 167 if (is_array($attachments)) {
168 session_register('attachments');
169 }
8e54a58b 170 } else {
177dde45 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 }
8e54a58b 181 $redirect_url = 'webmail.php';
182 }
177dde45 183
5c3b0995 184/* Send them off to the appropriate page. */
185header("Location: $redirect_url");
7baf86a9 186
cab99c3a 187/* --------------------- end main ----------------------- */
188
189function 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
86725763 207?>