squirrelmail-Bugs-488332
[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-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
31 require_once('../functions/i18n.php');
32 require_once('../functions/strings.php');
33 require_once('../config/config.php');
34 require_once('../functions/prefs.php');
35 require_once('../functions/imap.php');
36 require_once('../functions/plugin.php');
37 require_once('../functions/constants.php');
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
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
72 if (! isset($squirrelmail_language) ||
73 $squirrelmail_language == '' ) {
74 $squirrelmail_language = $squirrelmail_default_language;
75 }
76 set_up_language($squirrelmail_language, true);
77 /* Refresh the language cookie. */
78 setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,$base_uri);
79
80 if (!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
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 }
102
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;
113 } else {
114 $delimiter = sqimap_get_delimiter ($imapConnection);
115 }
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. */
131 session_register ('user_is_logged_in');
132 session_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();
137 session_register('attachment_common_types');
138 session_register('attachment_common_types_parsed');
139
140 $debug = false;
141 if (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);
144 if (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. */
150 checkForPrefs($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);
153 if ($javascript_setting == SMPREF_JS_AUTODETECT) {
154 if ($js_autodetect_results == SMPREF_JS_ON) {
155 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_ON);
156 } else {
157 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_OFF);
158 }
159 } else {
160 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_OFF);
161 }
162
163 /* Compute the URL to forward the user to. */
164 if(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. */
172 header("Location: $redirect_url");
173
174 ?>