squirrelmail-Bugs-488332
[squirrelmail.git] / src / redirect.php
CommitLineData
7392739d 1<?php
895905c0 2
35586184 3/**
4 * redirect.php
5 * Derived from webmail.php by Ralf Kraudelt <kraude@wiwi.uni-rostock.de>
6 *
7 * Copyright (c) 1999-2001 The Squirrelmail Development 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/*****************************************************************/
16/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
17/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
18/*** + Base level indent should begin at left margin, as ***/
19/*** the require_once below looks. ***/
20/*** + All identation should consist of four space blocks ***/
21/*** + Tab characters are evil. ***/
22/*** + all comments should use "slash-star ... star-slash" ***/
23/*** style -- no pound characters, no slash-slash style ***/
24/*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
25/*** ALWAYS USE { AND } CHARACTERS!!! ***/
26/*** + Please use ' instead of ", when possible. Note " ***/
27/*** should always be used in _( ) function calls. ***/
28/*** Thank you for your help making the SM code more readable. ***/
29/*****************************************************************/
30
31require_once('../functions/i18n.php');
32require_once('../functions/strings.php');
33require_once('../config/config.php');
34require_once('../functions/prefs.php');
35require_once('../functions/imap.php');
36require_once('../functions/plugin.php');
37require_once('../functions/constants.php');
cb48c245 38
5c3b0995 39function attachment_common_parse($str, $debug) {
40 global $attachment_common_types, $attachment_common_types_parsed;
cb48c245 41
5c3b0995 42 $attachment_common_types_parsed[$str] = true;
43 $types = explode(', ', $str);
cb48c245 44
5c3b0995 45 foreach ($types as $val)
46 {
47 // Ignore the ";q=1.0" stuff
48 if (strpos($val, ';') !== false)
49 $val = substr($val, 0, strpos($val, ';'));
cb48c245 50
5c3b0995 51 if (! isset($attachment_common_types[$val])) {
52 $attachment_common_types[$val] = true;
cb48c245 53 }
54 }
5c3b0995 55}
56
57
58/* Before starting the session, the base URI must be known. Assuming */
59/* that this file is in the src/ subdirectory (or something). */
60ereg ("(^.*/)[^/]+/[^/]+$", $PHP_SELF, $regs);
61$base_uri = $regs[1];
62
63header('Pragma: no-cache');
64$location = get_location();
65
66session_set_cookie_params (0, $base_uri);
67session_start();
68
69session_unregister ('user_is_logged_in');
70session_register ('base_uri');
71
72if (! isset($squirrelmail_language) ||
73 $squirrelmail_language == '' ) {
74 $squirrelmail_language = $squirrelmail_default_language;
75}
76set_up_language($squirrelmail_language, true);
77/* Refresh the language cookie. */
78setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,$base_uri);
79
80if (!isset($login_username)) {
81 echo "<HTML><BODY BGCOLOR=\"#ffffff\">\n" .
82 "<BR>&nbsp;<BR>\n" .
83 "<CENTER>\n" .
84 '<B>' . _("You must be logged in to access this page.") . "</B><BR>" .
85 '<A HREF="../src/login.php">' . _("Go to the login page") . "</A>\n" .
86 "</CENTER>\n" .
87 "</BODY></HTML>\n";
88 exit;
89}
90
91if (!session_is_registered('user_is_logged_in')) {
92 do_hook ('login_before');
93
94 $onetimepad = OneTimePadCreate(strlen($secretkey));
95 $key = OneTimePadEncrypt($secretkey, $onetimepad);
96 session_register('onetimepad');
97
98 /* Verify that username and password are correct. */
99 if ($force_username_lowercase) {
100 $login_username = strtolower($login_username);
23d6bd09 101 }
102
5c3b0995 103 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
104 if (!$imapConnection) {
105 echo "<html><body bgcolor=\"#ffffff\">\n".
106 "<br> <br>\n".
107 "<center>\n".
108 '<b>' . _("There was an error contacting the mail server.") . "</b><br>\n".
109 _("Contact your administrator for help.") . "\n".
110 "</center>\n".
111 "</body></html>\n";
112 exit;
23d6bd09 113 } else {
5c3b0995 114 $delimiter = sqimap_get_delimiter ($imapConnection);
23d6bd09 115 }
5c3b0995 116 sqimap_logout($imapConnection);
117 session_register('delimiter');
118
119 $username = $login_username;
120 session_register ('username');
121 setcookie('key', $key, 0, $base_uri);
122 do_hook ('login_verified');
123
124}
125
126/* Set the login variables. */
127$user_is_logged_in = true;
128$just_logged_in = true;
129
130/* And register with them with the session. */
131session_register ('user_is_logged_in');
132session_register ('just_logged_in');
133
134/* parse the accepted content-types of the client */
135$attachment_common_types = array();
136$attachment_common_types_parsed = array();
137session_register('attachment_common_types');
138session_register('attachment_common_types_parsed');
139
140$debug = false;
141if (isset($HTTP_SERVER_VARS['HTTP_ACCEPT']) &&
142 !isset($attachment_common_types_parsed[$HTTP_SERVER_VARS['HTTP_ACCEPT']]))
143 attachment_common_parse($HTTP_SERVER_VARS['HTTP_ACCEPT'], $debug);
144if (isset($HTTP_ACCEPT) &&
145 !isset($attachment_common_types_parsed[$HTTP_ACCEPT]))
146 attachment_common_parse($HTTP_ACCEPT, $debug);
147
148
149/* Complete autodetection of Javascript. */
150checkForPrefs($data_dir, $username);
151$javascript_setting = getPref($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT);
152$js_autodetect_results = (isset($js_autodetect_results) ? $js_autodetect_results : SMPREF_JS_OFF);
153if ($javascript_setting == SMPREF_JS_AUTODETECT) {
154 if ($js_autodetect_results == SMPREF_JS_ON) {
155 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_ON);
23d6bd09 156 } else {
5c3b0995 157 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_OFF);
23d6bd09 158 }
5c3b0995 159} else {
160 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_OFF);
161}
162
163/* Compute the URL to forward the user to. */
164if(isset($rcptemail)) {
165 $redirect_url = 'webmail.php?right_frame=compose.php&rcptaddress=';
166 $redirect_url .= urlencode($rcptemail);
167} else {
168 $redirect_url = 'webmail.php';
169}
170
171/* Send them off to the appropriate page. */
172header("Location: $redirect_url");
7baf86a9 173
e0dcff78 174?>