Fixed typo.
[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
39 function attachment_common_parse($str, $debug) {
40 global $attachment_common_types, $attachment_common_types_parsed;
41
42 $attachment_common_types_parsed[$str] = true;
43 $types = explode(', ', $str);
44
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, ';'));
50
51 if (! isset($attachment_common_types[$val])) {
52 $attachment_common_types[$val] = true;
53 }
54 }
55 }
56
23d6bd09 57
58 /* Before starting the session, the base URI must be known. Assuming */
59 /* that this file is in the src/ subdirectory (or something). */
60 ereg ("(^.*/)[^/]+/[^/]+$", $PHP_SELF, $regs);
61 $base_uri = $regs[1];
62
63 header('Pragma: no-cache');
64 $location = get_location();
65
66 session_set_cookie_params (0, $base_uri);
67 session_start();
68
69 session_unregister ('user_is_logged_in');
70 session_register ('base_uri');
71
cb48c245 72 if (! isset($squirrelmail_language) ||
73 $squirrelmail_language == '' ) {
74 $squirrelmail_language = $squirrelmail_default_language;
23d6bd09 75 }
76 set_up_language($squirrelmail_language, true);
cb48c245 77 /* Refresh the language cookie. */
78 setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,$base_uri);
23d6bd09 79
80 if (!isset($login_username)) {
cb48c245 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";
23d6bd09 88 exit;
89 }
90
23d6bd09 91 if (!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);
101 }
cb48c245 102
23d6bd09 103 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
104 if (!$imapConnection) {
cb48c245 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";
23d6bd09 112 exit;
113 } else {
114 $delimiter = sqimap_get_delimiter ($imapConnection);
115 }
116 sqimap_logout($imapConnection);
525b7ae6 117 session_register('delimiter');
23d6bd09 118
119 $username = $login_username;
120 session_register ('username');
121 setcookie('key', $key, 0, $base_uri);
23d6bd09 122 do_hook ('login_verified');
fb120846 123
71257f8b 124 setPref( $data_dir, $username, 'counter',
125 getPref( $data_dir, $username, 'counter', 0 ) + 1 );
23d6bd09 126 }
127
128 /* Set the login variables. */
129 $user_is_logged_in = true;
130 $just_logged_in = true;
131
132 /* And register with them with the session. */
133 session_register ('user_is_logged_in');
134 session_register ('just_logged_in');
135
7baf86a9 136 /* parse the accepted content-types of the client */
137 $attachment_common_types = array();
138 $attachment_common_types_parsed = array();
139 session_register('attachment_common_types');
140 session_register('attachment_common_types_parsed');
141
bbdd6ddb 142 $debug = false;
7baf86a9 143 if (isset($HTTP_SERVER_VARS['HTTP_ACCEPT']) &&
144 !isset($attachment_common_types_parsed[$HTTP_SERVER_VARS['HTTP_ACCEPT']]))
145 attachment_common_parse($HTTP_SERVER_VARS['HTTP_ACCEPT'], $debug);
146 if (isset($HTTP_ACCEPT) &&
147 !isset($attachment_common_types_parsed[$HTTP_ACCEPT]))
148 attachment_common_parse($HTTP_ACCEPT, $debug);
149
150
23d6bd09 151 /* Complete autodetection of Javascript. */
357f1ae0 152 checkForPrefs($data_dir, $username);
23d6bd09 153 $javascript_setting = getPref($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT);
154 $js_autodetect_results = (isset($js_autodetect_results) ? $js_autodetect_results : SMPREF_JS_OFF);
155 if ($javascript_setting == SMPREF_JS_AUTODETECT) {
156 if ($js_autodetect_results == SMPREF_JS_ON) {
157 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_ON);
158 } else {
159 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_OFF);
160 }
161 } else {
162 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_OFF);
163 }
164
165 /* Compute the URL to forward the user to. */
166 if(isset($rcptemail)) {
167 $redirect_url = 'webmail.php?right_frame=compose.php&rcptaddress=';
168 $redirect_url .= urlencode($rcptemail);
169 } else {
170 $redirect_url = 'webmail.php';
171 }
172
173 /* Send them off to the appropriate page. */
174 header("Location: $redirect_url");
7baf86a9 175
e0dcff78 176?>