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