3b25fff92a16a27fc3309feca5668a302752008a
[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-2003 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 /* Path for SquirrelMail required files. */
16 define('SM_PATH','../');
17
18 /* SquirrelMail required files. */
19 require_once(SM_PATH . 'functions/i18n.php');
20 require_once(SM_PATH . 'functions/strings.php');
21 require_once(SM_PATH . 'config/config.php');
22 require_once(SM_PATH . 'functions/prefs.php');
23 require_once(SM_PATH . 'functions/imap.php');
24 require_once(SM_PATH . 'functions/plugin.php');
25 require_once(SM_PATH . 'functions/constants.php');
26 require_once(SM_PATH . 'functions/page_header.php');
27 require_once(SM_PATH . 'functions/global.php');
28
29 // Remove slashes if PHP added them
30 $REQUEST_METHOD = $_SERVER['REQUEST_METHOD'];
31 if (get_magic_quotes_gpc()) {
32 if ($REQUEST_METHOD == 'POST') {
33 RemoveSlashes($_POST);
34 } else if ($REQUEST_METHOD == 'GET') {
35 RemoveSlashes($_GET);
36 }
37 }
38
39 /* Before starting the session, the base URI must be known. Assuming */
40 /* that this file is in the src/ subdirectory (or something). */
41 if (!function_exists('sqm_baseuri')){
42 require_once(SM_PATH . 'functions/display_messages.php');
43 }
44 $base_uri = sqm_baseuri();
45
46 header('Pragma: no-cache');
47 $location = get_location();
48
49 session_set_cookie_params (0, $base_uri);
50 session_start();
51
52 sqsession_unregister ('user_is_logged_in');
53 sqsession_register ($base_uri, 'base_uri');
54
55 /* get globals we me need */
56 if (isset($_POST['login_username'])) {
57 $login_username = $_POST['login_username'];
58 }
59 if (!isset($_COOKIE['squirrelmail_language']) ||
60 $squirrelmail_language == '' ) {
61 $squirrelmail_language = $squirrelmail_default_language;
62 }
63 else {
64 $squirrelmail_language = $_COOKIE['squirrelmail_language'];
65 }
66 if (isset($_POST['secretkey'])) {
67 $secretkey = $_POST['secretkey'];
68 }
69 if (isset($_POST['js_autodetect_results'])) {
70 $js_autodetect_results = $_POST['js_autodetect_results'];
71 }
72 /* end of get globals */
73
74 set_up_language($squirrelmail_language, true);
75 /* Refresh the language cookie. */
76 setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,
77 $base_uri);
78
79 if (!isset($login_username)) {
80 include_once( '../functions/display_messages.php' );
81 logout_error( _("You must be logged in to access this page.") );
82 exit;
83 }
84
85 if (!sqsession_is_registered('user_is_logged_in')) {
86 do_hook ('login_before');
87
88 $onetimepad = OneTimePadCreate(strlen($secretkey));
89 $key = OneTimePadEncrypt($secretkey, $onetimepad);
90 sqsession_register($onetimepad, 'onetimepad');
91
92 /* remove redundant spaces */
93 $login_username = trim($login_username);
94
95 /* Verify that username and password are correct. */
96 if ($force_username_lowercase) {
97 $login_username = strtolower($login_username);
98 }
99
100 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
101
102 $sqimap_capabilities = sqimap_capability($imapConnection);
103 sqsession_register($sqimap_capabilities, 'sqimap_capabilities');
104 $delimiter = sqimap_get_delimiter ($imapConnection);
105
106 sqimap_logout($imapConnection);
107 sqsession_register($delimiter, 'delimiter');
108
109 $username = $login_username;
110 sqsession_register ($username, 'username');
111 setcookie('key', $key, 0, $base_uri);
112 do_hook ('login_verified');
113
114 }
115
116 /* Set the login variables. */
117 $user_is_logged_in = true;
118 $just_logged_in = true;
119
120 /* And register with them with the session. */
121 sqsession_register ($user_is_logged_in, 'user_is_logged_in');
122 sqsession_register ($just_logged_in, 'just_logged_in');
123
124 /* parse the accepted content-types of the client */
125 $attachment_common_types = array();
126 $attachment_common_types_parsed = array();
127 sqsession_register($attachment_common_types, 'attachment_common_types');
128 sqsession_register($attachment_common_types_parsed, 'attachment_common_types_parsed');
129
130 $debug = false;
131
132 if (isset($_SERVER['HTTP_ACCEPT']) &&
133 !isset($attachment_common_types_parsed[$_SERVER['HTTP_ACCEPT']])) {
134 attachment_common_parse($_SERVER['HTTP_ACCEPT'], $debug);
135 }
136
137 /* Complete autodetection of Javascript. */
138 $javascript_setting = getPref
139 ($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT);
140 $js_autodetect_results = (isset($js_autodetect_results) ?
141 $js_autodetect_results : SMPREF_JS_OFF);
142 /* See if it's set to "Always on" */
143 $js_pref = SMPREF_JS_ON;
144 if ($javascript_setting != SMPREF_JS_ON){
145 if ($javascript_setting == SMPREF_JS_AUTODETECT) {
146 if ($js_autodetect_results == SMPREF_JS_OFF) {
147 $js_pref = SMPREF_JS_OFF;
148 }
149 } else {
150 $js_pref = SMPREF_JS_OFF;
151 }
152 }
153 /* Update the prefs */
154 setPref($data_dir, $username, 'javascript_on', $js_pref);
155
156 /* Compute the URL to forward the user to. */
157 if (isset($_SESSION['session_expired_location'])) {
158 $session_expired_location= $_SESSION['session_expired_location'];
159 } else {
160 $session_expired_location=false;
161 }
162 if (isset($session_expired_location) && $session_expired_location) {
163 $compose_new_win = getPref($data_dir, $username, 'compose_new_win', 0);
164 if ($compose_new_win) {
165 $redirect_url = $session_expired_location;
166 } else {
167 $redirect_url = 'webmail.php?right_frame='.urldecode($session_expired_location);
168 }
169 sqsession_unregister('session_expired_location');
170 unset($session_expired_location);
171 } else {
172 $redirect_url = 'webmail.php';
173 }
174
175 /* Write session data and send them off to the appropriate page. */
176 session_write_close();
177 header("Location: $redirect_url");
178
179 /* --------------------- end main ----------------------- */
180
181 function attachment_common_parse($str, $debug) {
182 global $attachment_common_types, $attachment_common_types_parsed;
183
184 $attachment_common_types_parsed[$str] = true;
185
186 /*
187 * Replace ", " with "," and explode on that as Mozilla 1.x seems to
188 * use "," to seperate whilst IE, and earlier versions of Mozilla use
189 * ", " to seperate
190 */
191
192 $str = str_replace( ', ' , ',' , $str );
193 $types = explode(',', $str);
194
195 foreach ($types as $val) {
196 // Ignore the ";q=1.0" stuff
197 if (strpos($val, ';') !== false)
198 $val = substr($val, 0, strpos($val, ';'));
199
200 if (! isset($attachment_common_types[$val])) {
201 $attachment_common_types[$val] = true;
202 }
203 }
204 $_SESSION['attachment_common_types'] = $attachment_common_types;
205 }
206
207
208 ?>