commit | author | age
|
4e17e6
|
1 |
<?php |
T |
2 |
/* |
a6f90e
|
3 |
+-------------------------------------------------------------------------+ |
A |
4 |
| RoundCube Webmail IMAP Client | |
d00260
|
5 |
| Version 0.3-20090814 | |
a6f90e
|
6 |
| | |
cbbef3
|
7 |
| Copyright (C) 2005-2009, RoundCube Dev. - Switzerland | |
a6f90e
|
8 |
| | |
A |
9 |
| This program is free software; you can redistribute it and/or modify | |
|
10 |
| it under the terms of the GNU General Public License version 2 | |
|
11 |
| as published by the Free Software Foundation. | |
|
12 |
| | |
|
13 |
| This program is distributed in the hope that it will be useful, | |
|
14 |
| but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
15 |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
16 |
| GNU General Public License for more details. | |
|
17 |
| | |
|
18 |
| You should have received a copy of the GNU General Public License along | |
|
19 |
| with this program; if not, write to the Free Software Foundation, Inc., | |
|
20 |
| 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
|
21 |
| | |
|
22 |
+-------------------------------------------------------------------------+ |
|
23 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
24 |
+-------------------------------------------------------------------------+ |
4e17e6
|
25 |
|
T |
26 |
$Id$ |
|
27 |
|
|
28 |
*/ |
15a9d1
|
29 |
|
47124c
|
30 |
// include environment |
T |
31 |
require_once 'program/include/iniset.php'; |
15a9d1
|
32 |
|
48bc52
|
33 |
// init application, start session, init output class, etc. |
83a763
|
34 |
$RCMAIL = rcmail::get_instance(); |
T |
35 |
|
d51c93
|
36 |
// turn on output buffering |
A |
37 |
ob_start(); |
8affba
|
38 |
|
8c72e3
|
39 |
// check if config files had errors |
T |
40 |
if ($err_str = $RCMAIL->config->get_error()) { |
|
41 |
raise_error(array( |
|
42 |
'code' => 601, |
|
43 |
'type' => 'php', |
|
44 |
'message' => $err_str), false, true); |
|
45 |
} |
|
46 |
|
8affba
|
47 |
// check DB connections and exit on failure |
47124c
|
48 |
if ($err_str = $DB->is_error()) { |
f11541
|
49 |
raise_error(array( |
T |
50 |
'code' => 603, |
|
51 |
'type' => 'db', |
|
52 |
'message' => $err_str), FALSE, TRUE); |
|
53 |
} |
8affba
|
54 |
|
4e17e6
|
55 |
// error steps |
197601
|
56 |
if ($RCMAIL->action=='error' && !empty($_GET['_code'])) { |
4e17e6
|
57 |
raise_error(array('code' => hexdec($_GET['_code'])), FALSE, TRUE); |
47124c
|
58 |
} |
570f0b
|
59 |
|
f5d61d
|
60 |
// check if https is required (for login) and redirect if necessary |
T |
61 |
if (empty($_SESSION['user_id']) && ($force_https = $RCMAIL->config->get('force_https', false))) { |
|
62 |
$https_port = is_bool($force_https) ? 443 : $force_https; |
5818e4
|
63 |
if (!rcube_https_check($https_port)) { |
76c94b
|
64 |
$host = preg_replace('/:[0-9]+$/', '', $_SERVER['HTTP_HOST']); |
A |
65 |
$host .= ($https_port != 443 ? ':' . $https_port : ''); |
|
66 |
header('Location: https://' . $host . $_SERVER['REQUEST_URI']); |
f5d61d
|
67 |
exit; |
T |
68 |
} |
|
69 |
} |
|
70 |
|
cc97ea
|
71 |
// trigger startup plugin hook |
T |
72 |
$startup = $RCMAIL->plugins->exec_hook('startup', array('task' => $RCMAIL->task, 'action' => $RCMAIL->action)); |
|
73 |
$RCMAIL->set_task($startup['task']); |
|
74 |
$RCMAIL->action = $startup['action']; |
|
75 |
|
4e17e6
|
76 |
// try to log in |
9b94eb
|
77 |
if ($RCMAIL->task == 'login' && $RCMAIL->action == 'login') { |
0129d7
|
78 |
// purge the session in case of new login when a session already exists |
cc97ea
|
79 |
$RCMAIL->kill_session(); |
0129d7
|
80 |
|
cc97ea
|
81 |
$auth = $RCMAIL->plugins->exec_hook('authenticate', array( |
T |
82 |
'host' => $RCMAIL->autoselect_host(), |
|
83 |
'user' => trim(get_input_value('_user', RCUBE_INPUT_POST)), |
446364
|
84 |
'cookiecheck' => true, |
64608b
|
85 |
)); |
A |
86 |
|
|
87 |
if (!isset($auth['pass'])) |
|
88 |
$auth['pass'] = get_input_value('_pass', RCUBE_INPUT_POST, true, |
|
89 |
$RCMAIL->config->get('password_charset', 'ISO-8859-1')); |
cc97ea
|
90 |
|
4e17e6
|
91 |
// check if client supports cookies |
446364
|
92 |
if ($auth['cookiecheck'] && empty($_COOKIE)) { |
f11541
|
93 |
$OUTPUT->show_message("cookiesdisabled", 'warning'); |
T |
94 |
} |
64608b
|
95 |
else if ($_SESSION['temp'] && !$auth['abort'] && |
A |
96 |
!empty($auth['host']) && !empty($auth['user']) && |
|
97 |
$RCMAIL->login($auth['user'], $auth['pass'], $auth['host'])) { |
aad6e2
|
98 |
// create new session ID |
929a50
|
99 |
$RCMAIL->session->remove('temp'); |
A |
100 |
$RCMAIL->session->regenerate_id(); |
aad6e2
|
101 |
|
T |
102 |
// send auth cookie if necessary |
1854c4
|
103 |
$RCMAIL->authenticate_session(); |
aad6e2
|
104 |
|
5e0045
|
105 |
// log successful login |
c8a21d
|
106 |
if ($RCMAIL->config->get('log_logins')) { |
T |
107 |
write_log('userlogins', sprintf('Successful login for %s (id %d) from %s', |
|
108 |
$RCMAIL->user->get_username(), |
|
109 |
$RCMAIL->user->ID, |
|
110 |
$_SERVER['REMOTE_ADDR'])); |
|
111 |
} |
10eedb
|
112 |
|
cc97ea
|
113 |
// restore original request parameters |
T |
114 |
$query = array(); |
|
115 |
if ($url = get_input_value('_url', RCUBE_INPUT_POST)) |
|
116 |
parse_str($url, $query); |
|
117 |
|
|
118 |
// allow plugins to control the redirect url after login success |
7481dd
|
119 |
$redir = $RCMAIL->plugins->exec_hook('login_after', $query); |
cc97ea
|
120 |
unset($redir['abort']); |
5e0045
|
121 |
|
4e17e6
|
122 |
// send redirect |
cc97ea
|
123 |
$OUTPUT->redirect($redir); |
4e17e6
|
124 |
} |
47124c
|
125 |
else { |
7342d7
|
126 |
$OUTPUT->show_message($IMAP->error_code < -1 ? 'imaperror' : 'loginfailed', 'warning'); |
cc97ea
|
127 |
$RCMAIL->plugins->exec_hook('login_failed', array('code' => $IMAP->error_code, 'host' => $auth['host'], 'user' => $auth['user'])); |
1854c4
|
128 |
$RCMAIL->kill_session(); |
f11541
|
129 |
} |
T |
130 |
} |
4e17e6
|
131 |
|
T |
132 |
// end session |
9b94eb
|
133 |
else if ($RCMAIL->task == 'logout' && isset($_SESSION['user_id'])) { |
7ef47e
|
134 |
$userdata = array('user' => $_SESSION['username'], 'host' => $_SESSION['imap_host'], 'lang' => $RCMAIL->user->language); |
f11541
|
135 |
$OUTPUT->show_message('loggedout'); |
1854c4
|
136 |
$RCMAIL->logout_actions(); |
T |
137 |
$RCMAIL->kill_session(); |
7ef47e
|
138 |
$RCMAIL->plugins->exec_hook('logout_after', $userdata); |
f11541
|
139 |
} |
4e17e6
|
140 |
|
bac7d1
|
141 |
// check session and auth cookie |
9b94eb
|
142 |
else if ($RCMAIL->task != 'login' && $_SESSION['user_id'] && $RCMAIL->action != 'send') { |
1854c4
|
143 |
if (!$RCMAIL->authenticate_session()) { |
f11541
|
144 |
$OUTPUT->show_message('sessionerror', 'error'); |
1854c4
|
145 |
$RCMAIL->kill_session(); |
4e17e6
|
146 |
} |
f11541
|
147 |
} |
4e17e6
|
148 |
|
0ddf59
|
149 |
// don't check for valid request tokens in these actions |
T |
150 |
$request_check_whitelist = array('login'=>1, 'spell'=>1); |
4e17e6
|
151 |
|
719a25
|
152 |
// check client X-header to verify request origin |
47124c
|
153 |
if ($OUTPUT->ajax_call) { |
ccc80d
|
154 |
if (!$RCMAIL->config->get('devel_mode') && rc_request_header('X-RoundCube-Request') != $RCMAIL->get_request_token() && !empty($RCMAIL->user->ID)) { |
719a25
|
155 |
header('HTTP/1.1 404 Not Found'); |
T |
156 |
die("Invalid Request"); |
|
157 |
} |
|
158 |
} |
549933
|
159 |
// check request token in POST form submissions |
0ddf59
|
160 |
else if (!empty($_POST) && !$request_check_whitelist[$RCMAIL->action] && !$RCMAIL->check_request()) { |
549933
|
161 |
$OUTPUT->show_message('invalidrequest', 'error'); |
T |
162 |
$OUTPUT->send($RCMAIL->task); |
|
163 |
} |
4e17e6
|
164 |
|
T |
165 |
// not logged in -> show login page |
197601
|
166 |
if (empty($RCMAIL->user->ID)) { |
83a763
|
167 |
if ($OUTPUT->ajax_call) |
c719f3
|
168 |
$OUTPUT->redirect(array(), 2000); |
9b94eb
|
169 |
|
ccc80d
|
170 |
if (!empty($_REQUEST['_framed'])) |
b57133
|
171 |
$OUTPUT->command('redirect', '?'); |
ccc80d
|
172 |
|
330127
|
173 |
// check if installer is still active |
83a763
|
174 |
if ($RCMAIL->config->get('enable_installer') && is_readable('./installer/index.php')) { |
47124c
|
175 |
$OUTPUT->add_footer(html::div(array('style' => "background:#ef9398; border:2px solid #dc5757; padding:0.5em; margin:2em auto; width:50em"), |
T |
176 |
html::tag('h2', array('style' => "margin-top:0.2em"), "Installer script is still accessible") . |
|
177 |
html::p(null, "The install script of your RoundCube installation is still stored in its default location!") . |
|
178 |
html::p(null, "Please <b>remove</b> the whole <tt>installer</tt> folder from the RoundCube directory because . |
|
179 |
these files may expose sensitive configuration data like server passwords and encryption keys |
|
180 |
to the public. Make sure you cannot access the <a href=\"./installer/\">installer script</a> from your browser.") |
|
181 |
) |
|
182 |
); |
|
183 |
} |
330127
|
184 |
|
bbf15d
|
185 |
$OUTPUT->set_env('task', 'login'); |
f11541
|
186 |
$OUTPUT->send('login'); |
T |
187 |
} |
4e17e6
|
188 |
|
T |
189 |
|
1cded8
|
190 |
// handle keep-alive signal |
48aff9
|
191 |
if ($RCMAIL->action == 'keep-alive') { |
T |
192 |
$OUTPUT->reset(); |
|
193 |
$OUTPUT->send(); |
|
194 |
} |
|
195 |
// save preference value |
|
196 |
else if ($RCMAIL->action == 'save-pref') { |
|
197 |
$RCMAIL->user->save_prefs(array(get_input_value('_name', RCUBE_INPUT_POST) => get_input_value('_value', RCUBE_INPUT_POST))); |
f11541
|
198 |
$OUTPUT->reset(); |
83a763
|
199 |
$OUTPUT->send(); |
f11541
|
200 |
} |
4e17e6
|
201 |
|
6ea6c9
|
202 |
|
T |
203 |
// map task/action to a certain include file |
|
204 |
$action_map = array( |
|
205 |
'mail' => array( |
|
206 |
'preview' => 'show.inc', |
|
207 |
'print' => 'show.inc', |
|
208 |
'moveto' => 'move_del.inc', |
|
209 |
'delete' => 'move_del.inc', |
|
210 |
'send' => 'sendmail.inc', |
|
211 |
'expunge' => 'folders.inc', |
|
212 |
'purge' => 'folders.inc', |
133bb0
|
213 |
'remove-attachment' => 'attachments.inc', |
A |
214 |
'display-attachment' => 'attachments.inc', |
|
215 |
'upload' => 'attachments.inc', |
c0297f
|
216 |
'group-expand' => 'autocomplete.inc', |
6ea6c9
|
217 |
), |
88375f
|
218 |
|
6ea6c9
|
219 |
'addressbook' => array( |
T |
220 |
'add' => 'edit.inc', |
3baa72
|
221 |
'group-create' => 'groups.inc', |
T |
222 |
'group-rename' => 'groups.inc', |
|
223 |
'group-delete' => 'groups.inc', |
aa12df
|
224 |
'group-addmembers' => 'groups.inc', |
T |
225 |
'group-delmembers' => 'groups.inc', |
6ea6c9
|
226 |
), |
T |
227 |
|
|
228 |
'settings' => array( |
|
229 |
'folders' => 'manage_folders.inc', |
|
230 |
'create-folder' => 'manage_folders.inc', |
|
231 |
'rename-folder' => 'manage_folders.inc', |
|
232 |
'delete-folder' => 'manage_folders.inc', |
|
233 |
'subscribe' => 'manage_folders.inc', |
|
234 |
'unsubscribe' => 'manage_folders.inc', |
f52c93
|
235 |
'enable-threading' => 'manage_folders.inc', |
T |
236 |
'disable-threading' => 'manage_folders.inc', |
6ea6c9
|
237 |
'add-identity' => 'edit_identity.inc', |
T |
238 |
) |
|
239 |
); |
f5aa16
|
240 |
|
6ea6c9
|
241 |
// include task specific functions |
564a2b
|
242 |
if (is_file($incfile = 'program/steps/'.$RCMAIL->task.'/func.inc')) |
A |
243 |
include_once($incfile); |
4e17e6
|
244 |
|
6ea6c9
|
245 |
// allow 5 "redirects" to another action |
T |
246 |
$redirects = 0; $incstep = null; |
|
247 |
while ($redirects < 5) { |
|
248 |
$stepfile = !empty($action_map[$RCMAIL->task][$RCMAIL->action]) ? |
|
249 |
$action_map[$RCMAIL->task][$RCMAIL->action] : strtr($RCMAIL->action, '-', '_') . '.inc'; |
cc97ea
|
250 |
|
T |
251 |
// execute a plugin action |
0ce119
|
252 |
if (preg_match('/^plugin\./', $RCMAIL->action)) { |
cc97ea
|
253 |
$RCMAIL->plugins->exec_action($RCMAIL->action); |
T |
254 |
break; |
|
255 |
} |
6ea6c9
|
256 |
// try to include the step file |
564a2b
|
257 |
else if (is_file($incfile = 'program/steps/'.$RCMAIL->task.'/'.$stepfile)) { |
6ea6c9
|
258 |
include($incfile); |
T |
259 |
$redirects++; |
|
260 |
} |
|
261 |
else { |
|
262 |
break; |
|
263 |
} |
|
264 |
} |
4e17e6
|
265 |
|
T |
266 |
|
6ea6c9
|
267 |
// parse main template (default) |
197601
|
268 |
$OUTPUT->send($RCMAIL->task); |
539cd4
|
269 |
|
T |
270 |
|
|
271 |
// if we arrive here, something went wrong |
f11541
|
272 |
raise_error(array( |
T |
273 |
'code' => 404, |
|
274 |
'type' => 'php', |
|
275 |
'line' => __LINE__, |
|
276 |
'file' => __FILE__, |
47124c
|
277 |
'message' => "Invalid request"), true, true); |
539cd4
|
278 |
|
d1d2c4
|
279 |
?> |