Code Cleaning
[squirrelmail.git] / src / redirect.php
CommitLineData
7392739d 1<?php
895905c0 2
35586184 3/**
cab99c3a 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*/
35586184 14
15require_once('../functions/i18n.php');
16require_once('../functions/strings.php');
17require_once('../config/config.php');
18require_once('../functions/prefs.php');
19require_once('../functions/imap.php');
20require_once('../functions/plugin.php');
21require_once('../functions/constants.php');
5a545dda 22require_once('../functions/page_header.php');
cb48c245 23
26707265 24// Remove slashes if PHP added them
25if (get_magic_quotes_gpc()) {
26 global $REQUEST_METHOD;
cab99c3a 27
26707265 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
5c3b0995 37/* Before starting the session, the base URI must be known. Assuming */
38/* that this file is in the src/ subdirectory (or something). */
39ereg ("(^.*/)[^/]+/[^/]+$", $PHP_SELF, $regs);
40$base_uri = $regs[1];
41
42header('Pragma: no-cache');
43$location = get_location();
44
45session_set_cookie_params (0, $base_uri);
46session_start();
47
48session_unregister ('user_is_logged_in');
49session_register ('base_uri');
50
51if (! isset($squirrelmail_language) ||
52 $squirrelmail_language == '' ) {
53 $squirrelmail_language = $squirrelmail_default_language;
54}
55set_up_language($squirrelmail_language, true);
56/* Refresh the language cookie. */
57setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,$base_uri);
58
59if (!isset($login_username)) {
5a545dda 60 displayHtmlHeader( _("You must be logged in to access this page.") );
61 echo "<BODY BGCOLOR=\"#ffffff\">\n" .
5c3b0995 62 "<BR>&nbsp;<BR>\n" .
63 "<CENTER>\n" .
64 '<B>' . _("You must be logged in to access this page.") . "</B><BR>" .
65 '<A HREF="../src/login.php">' . _("Go to the login page") . "</A>\n" .
66 "</CENTER>\n" .
67 "</BODY></HTML>\n";
68 exit;
69}
70
71if (!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);
23d6bd09 81 }
82
5c3b0995 83 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
84 if (!$imapConnection) {
5a545dda 85 displayHtmlHeader( _("There was an error contacting the mail server.") );
86 echo "<body bgcolor=\"#ffffff\">\n".
5c3b0995 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;
23d6bd09 94 } else {
5c3b0995 95 $delimiter = sqimap_get_delimiter ($imapConnection);
23d6bd09 96 }
5c3b0995 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. */
112session_register ('user_is_logged_in');
113session_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();
118session_register('attachment_common_types');
119session_register('attachment_common_types_parsed');
120
121$debug = false;
122if (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);
125if (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. */
165829a3 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);
18f734b9 135/* See if it's set to "Always on" */
136$js_pref = SMPREF_JS_ON;
137if ($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 }
23d6bd09 142 } else {
18f734b9 143 $js_pref = SMPREF_JS_OFF;
23d6bd09 144 }
5c3b0995 145}
18f734b9 146/* Update the prefs */
147setPref($data_dir, $username, 'javascript_on', $js_pref);
5c3b0995 148
149/* Compute the URL to forward the user to. */
150if(isset($rcptemail)) {
151 $redirect_url = 'webmail.php?right_frame=compose.php&rcptaddress=';
152 $redirect_url .= urlencode($rcptemail);
153} else {
154 $redirect_url = 'webmail.php';
155}
156
157/* Send them off to the appropriate page. */
158header("Location: $redirect_url");
7baf86a9 159
cab99c3a 160/* --------------------- end main ----------------------- */
161
162function 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
e0dcff78 180?>