commit | author | age
|
4e17e6
|
1 |
<?php |
T |
2 |
/* |
a6f90e
|
3 |
+-------------------------------------------------------------------------+ |
e019f2
|
4 |
| Roundcube Webmail IMAP Client | |
9456ea
|
5 |
| Version 0.8-rc | |
a6f90e
|
6 |
| | |
7fe381
|
7 |
| Copyright (C) 2005-2012, The Roundcube Dev Team | |
a6f90e
|
8 |
| | |
7fe381
|
9 |
| This program is free software: you can redistribute it and/or modify | |
T |
10 |
| it under the terms of the GNU General Public License (with exceptions | |
|
11 |
| for skins & plugins) as published by the Free Software Foundation, | |
|
12 |
| either version 3 of the License, or (at your option) any later version. | |
|
13 |
| | |
|
14 |
| This file forms part of the Roundcube Webmail Software for which the | |
|
15 |
| following exception is added: Plugins and Skins which merely make | |
|
16 |
| function calls to the Roundcube Webmail Software, and for that purpose | |
|
17 |
| include it by reference shall not be considered modifications of | |
|
18 |
| the software. | |
|
19 |
| | |
|
20 |
| If you wish to use this file in another project or create a modified | |
|
21 |
| version that will not be part of the Roundcube Webmail Software, you | |
|
22 |
| may remove the exception above and use this source code under the | |
|
23 |
| original version of the license. | |
a6f90e
|
24 |
| | |
A |
25 |
| This program is distributed in the hope that it will be useful, | |
|
26 |
| but WITHOUT ANY WARRANTY; without even the implied warranty of | |
7fe381
|
27 |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
a6f90e
|
28 |
| GNU General Public License for more details. | |
A |
29 |
| | |
7fe381
|
30 |
| You should have received a copy of the GNU General Public License | |
T |
31 |
| along with this program. If not, see http://www.gnu.org/licenses/. | |
a6f90e
|
32 |
| | |
A |
33 |
+-------------------------------------------------------------------------+ |
|
34 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
35 |
+-------------------------------------------------------------------------+ |
4e17e6
|
36 |
|
T |
37 |
$Id$ |
|
38 |
|
|
39 |
*/ |
15a9d1
|
40 |
|
47124c
|
41 |
// include environment |
T |
42 |
require_once 'program/include/iniset.php'; |
15a9d1
|
43 |
|
48bc52
|
44 |
// init application, start session, init output class, etc. |
83a763
|
45 |
$RCMAIL = rcmail::get_instance(); |
T |
46 |
|
9e54e6
|
47 |
// Make the whole PHP output non-cacheable (#1487797) |
A |
48 |
send_nocacheing_headers(); |
|
49 |
|
d51c93
|
50 |
// turn on output buffering |
A |
51 |
ob_start(); |
8affba
|
52 |
|
8c72e3
|
53 |
// check if config files had errors |
T |
54 |
if ($err_str = $RCMAIL->config->get_error()) { |
|
55 |
raise_error(array( |
|
56 |
'code' => 601, |
|
57 |
'type' => 'php', |
|
58 |
'message' => $err_str), false, true); |
|
59 |
} |
|
60 |
|
8affba
|
61 |
// check DB connections and exit on failure |
c321a9
|
62 |
if ($err_str = $RCMAIL->db->is_error()) { |
f11541
|
63 |
raise_error(array( |
T |
64 |
'code' => 603, |
|
65 |
'type' => 'db', |
|
66 |
'message' => $err_str), FALSE, TRUE); |
|
67 |
} |
8affba
|
68 |
|
4e17e6
|
69 |
// error steps |
197601
|
70 |
if ($RCMAIL->action=='error' && !empty($_GET['_code'])) { |
4e17e6
|
71 |
raise_error(array('code' => hexdec($_GET['_code'])), FALSE, TRUE); |
47124c
|
72 |
} |
570f0b
|
73 |
|
f5d61d
|
74 |
// check if https is required (for login) and redirect if necessary |
T |
75 |
if (empty($_SESSION['user_id']) && ($force_https = $RCMAIL->config->get('force_https', false))) { |
|
76 |
$https_port = is_bool($force_https) ? 443 : $force_https; |
5818e4
|
77 |
if (!rcube_https_check($https_port)) { |
76c94b
|
78 |
$host = preg_replace('/:[0-9]+$/', '', $_SERVER['HTTP_HOST']); |
A |
79 |
$host .= ($https_port != 443 ? ':' . $https_port : ''); |
|
80 |
header('Location: https://' . $host . $_SERVER['REQUEST_URI']); |
f5d61d
|
81 |
exit; |
T |
82 |
} |
|
83 |
} |
|
84 |
|
cc97ea
|
85 |
// trigger startup plugin hook |
T |
86 |
$startup = $RCMAIL->plugins->exec_hook('startup', array('task' => $RCMAIL->task, 'action' => $RCMAIL->action)); |
|
87 |
$RCMAIL->set_task($startup['task']); |
|
88 |
$RCMAIL->action = $startup['action']; |
|
89 |
|
4e17e6
|
90 |
// try to log in |
9b94eb
|
91 |
if ($RCMAIL->task == 'login' && $RCMAIL->action == 'login') { |
784a42
|
92 |
$request_valid = $_SESSION['temp'] && $RCMAIL->check_request(RCUBE_INPUT_POST, 'login'); |
T |
93 |
|
0129d7
|
94 |
// purge the session in case of new login when a session already exists |
cc97ea
|
95 |
$RCMAIL->kill_session(); |
5f560e
|
96 |
|
cc97ea
|
97 |
$auth = $RCMAIL->plugins->exec_hook('authenticate', array( |
T |
98 |
'host' => $RCMAIL->autoselect_host(), |
|
99 |
'user' => trim(get_input_value('_user', RCUBE_INPUT_POST)), |
5f560e
|
100 |
'pass' => get_input_value('_pass', RCUBE_INPUT_POST, true, |
A |
101 |
$RCMAIL->config->get('password_charset', 'ISO-8859-1')), |
446364
|
102 |
'cookiecheck' => true, |
784a42
|
103 |
'valid' => $request_valid, |
64608b
|
104 |
)); |
cc97ea
|
105 |
|
4e17e6
|
106 |
// check if client supports cookies |
446364
|
107 |
if ($auth['cookiecheck'] && empty($_COOKIE)) { |
f11541
|
108 |
$OUTPUT->show_message("cookiesdisabled", 'warning'); |
T |
109 |
} |
784a42
|
110 |
else if ($auth['valid'] && !$auth['abort'] && |
fdff34
|
111 |
$RCMAIL->login($auth['user'], $auth['pass'], $auth['host']) |
4cfe66
|
112 |
) { |
A |
113 |
// create new session ID, don't destroy the current session |
c294ea
|
114 |
// it was destroyed already by $RCMAIL->kill_session() above |
4cfe66
|
115 |
$RCMAIL->session->remove('temp'); |
c294ea
|
116 |
$RCMAIL->session->regenerate_id(false); |
aad6e2
|
117 |
|
T |
118 |
// send auth cookie if necessary |
cf2da2
|
119 |
$RCMAIL->session->set_auth_cookie(); |
aad6e2
|
120 |
|
5e0045
|
121 |
// log successful login |
354455
|
122 |
rcmail_log_login(); |
10eedb
|
123 |
|
cc97ea
|
124 |
// restore original request parameters |
88007c
|
125 |
$query = array(); |
32234d
|
126 |
if ($url = get_input_value('_url', RCUBE_INPUT_POST)) { |
cc97ea
|
127 |
parse_str($url, $query); |
c294ea
|
128 |
|
32234d
|
129 |
// prevent endless looping on login page |
T |
130 |
if ($query['_task'] == 'login') |
|
131 |
unset($query['_task']); |
f4698c
|
132 |
|
A |
133 |
// prevent redirect to compose with specified ID (#1488226) |
|
134 |
if ($query['_action'] == 'compose' && !empty($query['_id'])) |
|
135 |
$query = array(); |
32234d
|
136 |
} |
cc97ea
|
137 |
|
T |
138 |
// allow plugins to control the redirect url after login success |
32234d
|
139 |
$redir = $RCMAIL->plugins->exec_hook('login_after', $query + array('_task' => 'mail')); |
fcc7f8
|
140 |
unset($redir['abort'], $redir['_err']); |
5e0045
|
141 |
|
4e17e6
|
142 |
// send redirect |
cc97ea
|
143 |
$OUTPUT->redirect($redir); |
4e17e6
|
144 |
} |
47124c
|
145 |
else { |
c321a9
|
146 |
$error_code = is_object($RCMAIL->storage) ? $RCMAIL->storage->get_error_code() : 1; |
6d99f9
|
147 |
|
c321a9
|
148 |
$OUTPUT->show_message($error_code < -1 ? 'storageerror' : (!$auth['valid'] ? 'invalidrequest' : 'loginfailed'), 'warning'); |
8fcc3e
|
149 |
$RCMAIL->plugins->exec_hook('login_failed', array( |
6d99f9
|
150 |
'code' => $error_code, 'host' => $auth['host'], 'user' => $auth['user'])); |
1854c4
|
151 |
$RCMAIL->kill_session(); |
f11541
|
152 |
} |
T |
153 |
} |
4e17e6
|
154 |
|
de62f0
|
155 |
// end session (after optional referer check) |
T |
156 |
else if ($RCMAIL->task == 'logout' && isset($_SESSION['user_id']) && (!$RCMAIL->config->get('referer_check') || rcube_check_referer())) { |
c321a9
|
157 |
$userdata = array( |
T |
158 |
'user' => $_SESSION['username'], |
|
159 |
'host' => $_SESSION['storage_host'], |
|
160 |
'lang' => $RCMAIL->user->language, |
|
161 |
); |
f11541
|
162 |
$OUTPUT->show_message('loggedout'); |
1854c4
|
163 |
$RCMAIL->logout_actions(); |
T |
164 |
$RCMAIL->kill_session(); |
7ef47e
|
165 |
$RCMAIL->plugins->exec_hook('logout_after', $userdata); |
f11541
|
166 |
} |
4e17e6
|
167 |
|
bac7d1
|
168 |
// check session and auth cookie |
9b94eb
|
169 |
else if ($RCMAIL->task != 'login' && $_SESSION['user_id'] && $RCMAIL->action != 'send') { |
cf2da2
|
170 |
if (!$RCMAIL->session->check_auth()) { |
1854c4
|
171 |
$RCMAIL->kill_session(); |
fcc7f8
|
172 |
$session_error = true; |
4e17e6
|
173 |
} |
f11541
|
174 |
} |
4e17e6
|
175 |
|
T |
176 |
// not logged in -> show login page |
197601
|
177 |
if (empty($RCMAIL->user->ID)) { |
fcc7f8
|
178 |
// log session failures |
6354da
|
179 |
if (($task = get_input_value('_task', RCUBE_INPUT_GPC)) && !in_array($task, array('login','logout')) && !$session_error && ($sess_id = $_COOKIE[ini_get('session.name')])) { |
fcc7f8
|
180 |
$RCMAIL->session->log("Aborted session " . $sess_id . "; no valid session data found"); |
T |
181 |
$session_error = true; |
|
182 |
} |
|
183 |
|
ec045b
|
184 |
if ($OUTPUT->ajax_call) |
fcc7f8
|
185 |
$OUTPUT->redirect(array('_err' => 'session'), 2000); |
9b94eb
|
186 |
|
ccc80d
|
187 |
if (!empty($_REQUEST['_framed'])) |
fcc7f8
|
188 |
$OUTPUT->command('redirect', $RCMAIL->url(array('_err' => 'session'))); |
ccc80d
|
189 |
|
330127
|
190 |
// check if installer is still active |
83a763
|
191 |
if ($RCMAIL->config->get('enable_installer') && is_readable('./installer/index.php')) { |
47124c
|
192 |
$OUTPUT->add_footer(html::div(array('style' => "background:#ef9398; border:2px solid #dc5757; padding:0.5em; margin:2em auto; width:50em"), |
T |
193 |
html::tag('h2', array('style' => "margin-top:0.2em"), "Installer script is still accessible") . |
e019f2
|
194 |
html::p(null, "The install script of your Roundcube installation is still stored in its default location!") . |
A |
195 |
html::p(null, "Please <b>remove</b> the whole <tt>installer</tt> folder from the Roundcube directory because . |
47124c
|
196 |
these files may expose sensitive configuration data like server passwords and encryption keys |
T |
197 |
to the public. Make sure you cannot access the <a href=\"./installer/\">installer script</a> from your browser.") |
|
198 |
) |
|
199 |
); |
|
200 |
} |
9e54e6
|
201 |
|
fcc7f8
|
202 |
if ($session_error || $_REQUEST['_err'] == 'session') |
T |
203 |
$OUTPUT->show_message('sessionerror', 'error', null, true, -1); |
249db1
|
204 |
|
784a42
|
205 |
$RCMAIL->set_task('login'); |
f11541
|
206 |
$OUTPUT->send('login'); |
T |
207 |
} |
249db1
|
208 |
// CSRF prevention |
A |
209 |
else { |
|
210 |
// don't check for valid request tokens in these actions |
|
211 |
$request_check_whitelist = array('login'=>1, 'spell'=>1); |
4e17e6
|
212 |
|
249db1
|
213 |
// check client X-header to verify request origin |
A |
214 |
if ($OUTPUT->ajax_call) { |
ec045b
|
215 |
if (rc_request_header('X-Roundcube-Request') != $RCMAIL->get_request_token() && !$RCMAIL->config->get('devel_mode')) { |
abdf31
|
216 |
header('HTTP/1.1 403 Forbidden'); |
249db1
|
217 |
die("Invalid Request"); |
A |
218 |
} |
|
219 |
} |
|
220 |
// check request token in POST form submissions |
|
221 |
else if (!empty($_POST) && !$request_check_whitelist[$RCMAIL->action] && !$RCMAIL->check_request()) { |
|
222 |
$OUTPUT->show_message('invalidrequest', 'error'); |
|
223 |
$OUTPUT->send($RCMAIL->task); |
|
224 |
} |
a77cf2
|
225 |
|
T |
226 |
// check referer if configured |
|
227 |
if (!$request_check_whitelist[$RCMAIL->action] && $RCMAIL->config->get('referer_check') && !rcube_check_referer()) { |
|
228 |
raise_error(array( |
|
229 |
'code' => 403, |
|
230 |
'type' => 'php', |
|
231 |
'message' => "Referer check failed"), true, true); |
|
232 |
} |
249db1
|
233 |
} |
4e17e6
|
234 |
|
370302
|
235 |
// we're ready, user is authenticated and the request is safe |
A |
236 |
$plugin = $RCMAIL->plugins->exec_hook('ready', array('task' => $RCMAIL->task, 'action' => $RCMAIL->action)); |
|
237 |
$RCMAIL->set_task($plugin['task']); |
|
238 |
$RCMAIL->action = $plugin['action']; |
|
239 |
|
|
240 |
|
249db1
|
241 |
// handle special actions |
48aff9
|
242 |
if ($RCMAIL->action == 'keep-alive') { |
T |
243 |
$OUTPUT->reset(); |
28ac5c
|
244 |
$RCMAIL->plugins->exec_hook('keep_alive', array()); |
48aff9
|
245 |
$OUTPUT->send(); |
T |
246 |
} |
249db1
|
247 |
else if ($RCMAIL->action == 'save-pref') { |
4351f7
|
248 |
include INSTALL_PATH . 'program/steps/utils/save_pref.inc'; |
249db1
|
249 |
} |
4e17e6
|
250 |
|
6ea6c9
|
251 |
|
T |
252 |
// include task specific functions |
4351f7
|
253 |
if (is_file($incfile = INSTALL_PATH . 'program/steps/'.$RCMAIL->task.'/func.inc')) |
A |
254 |
include_once $incfile; |
4e17e6
|
255 |
|
6ea6c9
|
256 |
// allow 5 "redirects" to another action |
T |
257 |
$redirects = 0; $incstep = null; |
|
258 |
while ($redirects < 5) { |
cc97ea
|
259 |
// execute a plugin action |
05a631
|
260 |
if ($RCMAIL->plugins->is_plugin_task($RCMAIL->task)) { |
87e58c
|
261 |
if (!$RCMAIL->action) $RCMAIL->action = 'index'; |
05a631
|
262 |
$RCMAIL->plugins->exec_action($RCMAIL->task.'.'.$RCMAIL->action); |
T |
263 |
break; |
|
264 |
} |
|
265 |
else if (preg_match('/^plugin\./', $RCMAIL->action)) { |
cc97ea
|
266 |
$RCMAIL->plugins->exec_action($RCMAIL->action); |
T |
267 |
break; |
|
268 |
} |
6ea6c9
|
269 |
// try to include the step file |
68d2d5
|
270 |
else if (($stepfile = $RCMAIL->get_action_file()) |
4351f7
|
271 |
&& is_file($incfile = INSTALL_PATH . 'program/steps/'.$RCMAIL->task.'/'.$stepfile) |
68d2d5
|
272 |
) { |
4351f7
|
273 |
include $incfile; |
6ea6c9
|
274 |
$redirects++; |
T |
275 |
} |
|
276 |
else { |
|
277 |
break; |
|
278 |
} |
|
279 |
} |
4e17e6
|
280 |
|
T |
281 |
|
6ea6c9
|
282 |
// parse main template (default) |
197601
|
283 |
$OUTPUT->send($RCMAIL->task); |
539cd4
|
284 |
|
T |
285 |
|
|
286 |
// if we arrive here, something went wrong |
f11541
|
287 |
raise_error(array( |
T |
288 |
'code' => 404, |
|
289 |
'type' => 'php', |
|
290 |
'line' => __LINE__, |
|
291 |
'file' => __FILE__, |
47124c
|
292 |
'message' => "Invalid request"), true, true); |
b25dfd
|
293 |
|