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