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