OK, so it wants a trailing slash...
[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 $base_uri = dirname(dirname($PHP_SELF)) . "/";
40
41 header('Pragma: no-cache');
42 $location = get_location();
43
44 session_set_cookie_params (0, $base_uri);
45 session_start();
46
47 session_unregister ('user_is_logged_in');
48 session_register ('base_uri');
49
50 if (! isset($squirrelmail_language) ||
51 $squirrelmail_language == '' ) {
52 $squirrelmail_language = $squirrelmail_default_language;
53 }
54 set_up_language($squirrelmail_language, true);
55 /* Refresh the language cookie. */
56 setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,
57 $base_uri);
58
59 if (!isset($login_username)) {
60 include_once( '../functions/display_messages.php' );
61 logout_error( _("You must be logged in to access this page.") );
62 exit;
63 }
64
65 if (!session_is_registered('user_is_logged_in')) {
66 do_hook ('login_before');
67
68 $onetimepad = OneTimePadCreate(strlen($secretkey));
69 $key = OneTimePadEncrypt($secretkey, $onetimepad);
70 session_register('onetimepad');
71
72 /* Verify that username and password are correct. */
73 if ($force_username_lowercase) {
74 $login_username = strtolower($login_username);
75 }
76
77 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
78 if (!$imapConnection) {
79 $errTitle = _("There was an error contacting the mail server.");
80 $errString = $errTitle . "<br>\n".
81 _("Contact your administrator for help.");
82 include_once( '../functions/display_messages.php' );
83 logout_error( _("You must be logged in to access this page.") );
84 exit;
85 } else {
86 $delimiter = sqimap_get_delimiter ($imapConnection);
87 }
88 sqimap_logout($imapConnection);
89 session_register('delimiter');
90
91 $username = $login_username;
92 session_register ('username');
93 setcookie('key', $key, 0, $base_uri);
94 do_hook ('login_verified');
95
96 }
97
98 /* Set the login variables. */
99 $user_is_logged_in = true;
100 $just_logged_in = true;
101
102 /* And register with them with the session. */
103 session_register ('user_is_logged_in');
104 session_register ('just_logged_in');
105
106 /* parse the accepted content-types of the client */
107 $attachment_common_types = array();
108 $attachment_common_types_parsed = array();
109 session_register('attachment_common_types');
110 session_register('attachment_common_types_parsed');
111
112 $debug = false;
113 if (isset($HTTP_SERVER_VARS['HTTP_ACCEPT']) &&
114 !isset($attachment_common_types_parsed[$HTTP_SERVER_VARS['HTTP_ACCEPT']])) {
115 attachment_common_parse($HTTP_SERVER_VARS['HTTP_ACCEPT'], $debug);
116 }
117 if (isset($HTTP_ACCEPT) &&
118 !isset($attachment_common_types_parsed[$HTTP_ACCEPT])) {
119 attachment_common_parse($HTTP_ACCEPT, $debug);
120 }
121
122 /* Complete autodetection of Javascript. */
123 $javascript_setting = getPref
124 ($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT);
125 $js_autodetect_results = (isset($js_autodetect_results) ?
126 $js_autodetect_results : SMPREF_JS_OFF);
127 /* See if it's set to "Always on" */
128 $js_pref = SMPREF_JS_ON;
129 if ($javascript_setting != SMPREF_JS_ON){
130 if ($javascript_setting == SMPREF_JS_AUTODETECT) {
131 if ($js_autodetect_results == SMPREF_JS_OFF) {
132 $js_pref = SMPREF_JS_OFF;
133 }
134 } else {
135 $js_pref = SMPREF_JS_OFF;
136 }
137 }
138 /* Update the prefs */
139 setPref($data_dir, $username, 'javascript_on', $js_pref);
140
141 /* Compute the URL to forward the user to. */
142 if(isset($rcptemail)) {
143 $redirect_url = 'webmail.php?right_frame=compose.php&rcptaddress=';
144 $redirect_url .= $rcptemail;
145 } else {
146 $redirect_url = 'webmail.php';
147 }
148
149 /* Send them off to the appropriate page. */
150 header("Location: $redirect_url");
151
152 /* --------------------- end main ----------------------- */
153
154 function attachment_common_parse($str, $debug) {
155 global $attachment_common_types, $attachment_common_types_parsed;
156
157 $attachment_common_types_parsed[$str] = true;
158 $types = explode(', ', $str);
159
160 foreach ($types as $val) {
161 // Ignore the ";q=1.0" stuff
162 if (strpos($val, ';') !== false)
163 $val = substr($val, 0, strpos($val, ';'));
164
165 if (! isset($attachment_common_types[$val])) {
166 $attachment_common_types[$val] = true;
167 }
168 }
169 }
170
171
172 ?>