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