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 | * |
76911253 |
7 | * Copyright (c) 1999-2003 The SquirrelMail Project Team |
cab99c3a |
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 | |
86725763 |
15 | /* Path for SquirrelMail required files. */ |
16 | define('SM_PATH','../'); |
17 | |
18 | /* SquirrelMail required files. */ |
1e12d1ff |
19 | require_once(SM_PATH . 'functions/global.php'); |
86725763 |
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'); |
cb48c245 |
28 | |
5c3b0995 |
29 | /* Before starting the session, the base URI must be known. Assuming */ |
30 | /* that this file is in the src/ subdirectory (or something). */ |
f3bc099d |
31 | if (!function_exists('sqm_baseuri')){ |
86725763 |
32 | require_once(SM_PATH . 'functions/display_messages.php'); |
f3bc099d |
33 | } |
34 | $base_uri = sqm_baseuri(); |
5c3b0995 |
35 | |
36 | header('Pragma: no-cache'); |
37 | $location = get_location(); |
38 | |
39 | session_set_cookie_params (0, $base_uri); |
40 | session_start(); |
41 | |
ad839713 |
42 | sqsession_unregister ('user_is_logged_in'); |
43 | sqsession_register ($base_uri, 'base_uri'); |
5c3b0995 |
44 | |
a32985a5 |
45 | /* get globals we me need */ |
5250f7e7 |
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; |
a32985a5 |
51 | } |
c67e4479 |
52 | if (!sqgetGlobalVar('mailto', $mailto)) { |
53 | $mailto = ''; |
54 | } |
5250f7e7 |
55 | |
a32985a5 |
56 | /* end of get globals */ |
57 | |
5c3b0995 |
58 | set_up_language($squirrelmail_language, true); |
59 | /* Refresh the language cookie. */ |
85b454a0 |
60 | setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000, |
61 | $base_uri); |
5c3b0995 |
62 | |
63 | if (!isset($login_username)) { |
1e12d1ff |
64 | include_once(SM_PATH . 'functions/display_messages.php' ); |
9be8198d |
65 | logout_error( _("You must be logged in to access this page.") ); |
5c3b0995 |
66 | exit; |
67 | } |
68 | |
d7c82551 |
69 | if (!sqsession_is_registered('user_is_logged_in')) { |
5c3b0995 |
70 | do_hook ('login_before'); |
71 | |
72 | $onetimepad = OneTimePadCreate(strlen($secretkey)); |
73 | $key = OneTimePadEncrypt($secretkey, $onetimepad); |
a32985a5 |
74 | sqsession_register($onetimepad, 'onetimepad'); |
5c3b0995 |
75 | |
fd1b516b |
76 | /* remove redundant spaces */ |
77 | $login_username = trim($login_username); |
78 | |
5c3b0995 |
79 | /* Verify that username and password are correct. */ |
80 | if ($force_username_lowercase) { |
81 | $login_username = strtolower($login_username); |
23d6bd09 |
82 | } |
83 | |
5c3b0995 |
84 | $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0); |
44925ab0 |
85 | |
86 | $sqimap_capabilities = sqimap_capability($imapConnection); |
87 | sqsession_register($sqimap_capabilities, 'sqimap_capabilities'); |
88 | $delimiter = sqimap_get_delimiter ($imapConnection); |
89 | |
5c3b0995 |
90 | sqimap_logout($imapConnection); |
a32985a5 |
91 | sqsession_register($delimiter, 'delimiter'); |
92 | |
5c3b0995 |
93 | $username = $login_username; |
ad839713 |
94 | sqsession_register ($username, 'username'); |
5c3b0995 |
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. */ |
a32985a5 |
105 | sqsession_register ($user_is_logged_in, 'user_is_logged_in'); |
106 | sqsession_register ($just_logged_in, 'just_logged_in'); |
5c3b0995 |
107 | |
108 | /* parse the accepted content-types of the client */ |
109 | $attachment_common_types = array(); |
110 | $attachment_common_types_parsed = array(); |
a32985a5 |
111 | sqsession_register($attachment_common_types, 'attachment_common_types'); |
112 | sqsession_register($attachment_common_types_parsed, 'attachment_common_types_parsed'); |
5c3b0995 |
113 | |
114 | $debug = false; |
a32985a5 |
115 | |
1e12d1ff |
116 | if ( sqgetGlobalVar('HTTP_ACCEPT', $http_accept, SQ_SERVER) && |
117 | !isset($attachment_common_types_parsed[$http_accept]) ) { |
118 | attachment_common_parse($http_accept, $debug); |
9be8198d |
119 | } |
5c3b0995 |
120 | |
121 | /* Complete autodetection of Javascript. */ |
165829a3 |
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); |
18f734b9 |
126 | /* See if it's set to "Always on" */ |
127 | $js_pref = SMPREF_JS_ON; |
128 | if ($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 | } |
23d6bd09 |
133 | } else { |
18f734b9 |
134 | $js_pref = SMPREF_JS_OFF; |
23d6bd09 |
135 | } |
5c3b0995 |
136 | } |
18f734b9 |
137 | /* Update the prefs */ |
138 | setPref($data_dir, $username, 'javascript_on', $js_pref); |
5c3b0995 |
139 | |
140 | /* Compute the URL to forward the user to. */ |
cab6eaea |
141 | $redirect_url = 'webmail.php'; |
142 | |
143 | if ( 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); |
8e54a58b |
150 | } |
cab6eaea |
151 | unset($session_expired_location); |
152 | } |
c67e4479 |
153 | if($mailto != '') { |
154 | $redirect_url = 'webmail.php?right_frame=compose.php&mailto='; |
155 | $redirect_url .= $mailto; |
156 | } |
177dde45 |
157 | |
7bde5272 |
158 | /* Write session data and send them off to the appropriate page. */ |
159 | session_write_close(); |
5c3b0995 |
160 | header("Location: $redirect_url"); |
7baf86a9 |
161 | |
cab99c3a |
162 | /* --------------------- end main ----------------------- */ |
163 | |
164 | function attachment_common_parse($str, $debug) { |
165 | global $attachment_common_types, $attachment_common_types_parsed; |
166 | |
167 | $attachment_common_types_parsed[$str] = true; |
20511953 |
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 ); |
6c817138 |
176 | $types = explode(',', $str); |
cab99c3a |
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 | } |
e86403df |
187 | $_SESSION['attachment_common_types'] = $attachment_common_types; |
cab99c3a |
188 | } |
189 | |
190 | |
86725763 |
191 | ?> |