Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 263 lines (221 sloc) 9.367 kb
4e17e6c9 »
2005-09-25 Initial revision
1 <?php
2 /*
a6f90e1b »
2008-05-11 -fixed disclaimer
3 +-------------------------------------------------------------------------+
4 | RoundCube Webmail IMAP Client |
d0026078 »
2009-08-14 Implemented logout_after plugin hook
5 | Version 0.3-20090814 |
a6f90e1b »
2008-05-11 -fixed disclaimer
6 | |
cbbef379 »
2009-01-17 * bumping up copyright (happy new year ;-))
7 | Copyright (C) 2005-2009, RoundCube Dev. - Switzerland |
a6f90e1b »
2008-05-11 -fixed disclaimer
8 | |
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 +-------------------------------------------------------------------------+
4e17e6c9 »
2005-09-25 Initial revision
25
26 $Id$
27
28 */
29
47124c22 »
2008-04-12 Changed codebase to PHP5 with autoloader + added some new classes fro…
30 // include environment
31 require_once 'program/include/iniset.php';
15a9d1ce »
2006-01-05 Optimized loading time; added periodic mail check; added EXPUNGE command
32
83a76368 »
2008-06-14 More code cleanup
33 // init application and start session with requested task
34 $RCMAIL = rcmail::get_instance();
35
36 // init output class
37 $OUTPUT = !empty($_REQUEST['_remote']) ? $RCMAIL->init_json() : $RCMAIL->load_gui(!empty($_REQUEST['_framed']));
38
cc97ea05 »
2009-04-19 Merged branch devel-api (from r2208 to r2387) back into trunk (omitti…
39 // init plugin API
40 $RCMAIL->plugins->init();
41
d51c93b4 »
2009-06-01 - get rid of some hardcoded action names and move decission about out…
42 // turn on output buffering
43 ob_start();
2f2f15b7 »
2006-09-04 Little improvements for message parsing and encoding
44
8c72e33d »
2008-07-28 Show appropriate error message if config files are missing
45 // check if config files had errors
46 if ($err_str = $RCMAIL->config->get_error()) {
47 raise_error(array(
48 'code' => 601,
49 'type' => 'php',
50 'message' => $err_str), false, true);
51 }
52
8affba5b »
2006-03-14 Improved error handling in DB connection failure
53 // check DB connections and exit on failure
47124c22 »
2008-04-12 Changed codebase to PHP5 with autoloader + added some new classes fro…
54 if ($err_str = $DB->is_error()) {
f1154163 »
2007-04-28 Merged branch devel-addressbook from r443 back to trunk
55 raise_error(array(
56 'code' => 603,
57 'type' => 'db',
58 'message' => $err_str), FALSE, TRUE);
59 }
8affba5b »
2006-03-14 Improved error handling in DB connection failure
60
4e17e6c9 »
2005-09-25 Initial revision
61 // error steps
197601ef »
2008-04-30 Next step: introduce the application class 'rcmail' and get rid of so…
62 if ($RCMAIL->action=='error' && !empty($_GET['_code'])) {
4e17e6c9 »
2005-09-25 Initial revision
63 raise_error(array('code' => hexdec($_GET['_code'])), FALSE, TRUE);
47124c22 »
2008-04-12 Changed codebase to PHP5 with autoloader + added some new classes fro…
64 }
4e17e6c9 »
2005-09-25 Initial revision
65
cc97ea05 »
2009-04-19 Merged branch devel-api (from r2208 to r2387) back into trunk (omitti…
66 // trigger startup plugin hook
67 $startup = $RCMAIL->plugins->exec_hook('startup', array('task' => $RCMAIL->task, 'action' => $RCMAIL->action));
68 $RCMAIL->set_task($startup['task']);
69 $RCMAIL->action = $startup['action'];
70
4e17e6c9 »
2005-09-25 Initial revision
71 // try to log in
197601ef »
2008-04-30 Next step: introduce the application class 'rcmail' and get rid of so…
72 if ($RCMAIL->action=='login' && $RCMAIL->task=='mail') {
0129d7c9 »
2009-01-19 - Fix authentication when submitting form with existing session (#148…
73 // purge the session in case of new login when a session already exists
cc97ea05 »
2009-04-19 Merged branch devel-api (from r2208 to r2387) back into trunk (omitti…
74 $RCMAIL->kill_session();
4e17e6c9 »
2005-09-25 Initial revision
75
cc97ea05 »
2009-04-19 Merged branch devel-api (from r2208 to r2387) back into trunk (omitti…
76 $auth = $RCMAIL->plugins->exec_hook('authenticate', array(
77 'host' => $RCMAIL->autoselect_host(),
78 'user' => trim(get_input_value('_user', RCUBE_INPUT_POST)),
44636484 »
2009-08-05 Allow a plugin to disable the cookie check
79 'cookiecheck' => true,
cc97ea05 »
2009-04-19 Merged branch devel-api (from r2208 to r2387) back into trunk (omitti…
80 )) + array('pass' => get_input_value('_pass', RCUBE_INPUT_POST, true, 'ISO-8859-1'));
81
4e17e6c9 »
2005-09-25 Initial revision
82 // check if client supports cookies
44636484 »
2009-08-05 Allow a plugin to disable the cookie check
83 if ($auth['cookiecheck'] && empty($_COOKIE)) {
f1154163 »
2007-04-28 Merged branch devel-addressbook from r443 back to trunk
84 $OUTPUT->show_message("cookiesdisabled", 'warning');
85 }
44636484 »
2009-08-05 Allow a plugin to disable the cookie check
86 else if ($_SESSION['temp'] && !$auth['abort'] && !empty($auth['host']) &&
87 !empty($auth['user']) && isset($auth['pass']) &&
cc97ea05 »
2009-04-19 Merged branch devel-api (from r2208 to r2387) back into trunk (omitti…
88 $RCMAIL->login($auth['user'], $auth['pass'], $auth['host'])) {
aad6e2a9 »
2007-03-27 New session authentication, should fix bugs #1483951 and #1484299; te…
89 // create new session ID
f22c2cef »
2009-05-12 Really, really logout (fixes r2467).
90 rcube_sess_unset('temp');
2e3ce3e7 »
2008-08-28 Add rcube name prefixes + codestyle
91 rcube_sess_regenerate_id();
aad6e2a9 »
2007-03-27 New session authentication, should fix bugs #1483951 and #1484299; te…
92
93 // send auth cookie if necessary
1854c452 »
2008-05-07 More code cleanup + oop-ization
94 $RCMAIL->authenticate_session();
aad6e2a9 »
2007-03-27 New session authentication, should fix bugs #1483951 and #1484299; te…
95
5e0045b1 »
2008-06-06 Add option to log successful logins.
96 // log successful login
c8a21d64 »
2008-09-05 Killed one more global var + log logins to a separate file (not console)
97 if ($RCMAIL->config->get('log_logins')) {
98 write_log('userlogins', sprintf('Successful login for %s (id %d) from %s',
99 $RCMAIL->user->get_username(),
100 $RCMAIL->user->ID,
101 $_SERVER['REMOTE_ADDR']));
102 }
cc97ea05 »
2009-04-19 Merged branch devel-api (from r2208 to r2387) back into trunk (omitti…
103
104 // restore original request parameters
105 $query = array();
106 if ($url = get_input_value('_url', RCUBE_INPUT_POST))
107 parse_str($url, $query);
108
109 // allow plugins to control the redirect url after login success
110 $redir = $RCMAIL->plugins->exec_hook('login_after', $query + array('task' => $RCMAIL->task));
111 unset($redir['abort']);
5e0045b1 »
2008-06-06 Add option to log successful logins.
112
4e17e6c9 »
2005-09-25 Initial revision
113 // send redirect
cc97ea05 »
2009-04-19 Merged branch devel-api (from r2208 to r2387) back into trunk (omitti…
114 $OUTPUT->redirect($redir);
f1154163 »
2007-04-28 Merged branch devel-addressbook from r443 back to trunk
115 }
47124c22 »
2008-04-12 Changed codebase to PHP5 with autoloader + added some new classes fro…
116 else {
7342d7ef »
2008-11-28 - re-fix r2095
117 $OUTPUT->show_message($IMAP->error_code < -1 ? 'imaperror' : 'loginfailed', 'warning');
cc97ea05 »
2009-04-19 Merged branch devel-api (from r2208 to r2387) back into trunk (omitti…
118 $RCMAIL->plugins->exec_hook('login_failed', array('code' => $IMAP->error_code, 'host' => $auth['host'], 'user' => $auth['user']));
1854c452 »
2008-05-07 More code cleanup + oop-ization
119 $RCMAIL->kill_session();
4e17e6c9 »
2005-09-25 Initial revision
120 }
f1154163 »
2007-04-28 Merged branch devel-addressbook from r443 back to trunk
121 }
4e17e6c9 »
2005-09-25 Initial revision
122
123 // end session
3a2b270c »
2009-06-15 - always call logout action as task (#1485919)
124 else if ($RCMAIL->task=='logout' && isset($_SESSION['user_id'])) {
7ef47e59 »
2009-08-14 Add some arguments to the logout_after hook
125 $userdata = array('user' => $_SESSION['username'], 'host' => $_SESSION['imap_host'], 'lang' => $RCMAIL->user->language);
f1154163 »
2007-04-28 Merged branch devel-addressbook from r443 back to trunk
126 $OUTPUT->show_message('loggedout');
1854c452 »
2008-05-07 More code cleanup + oop-ization
127 $RCMAIL->logout_actions();
128 $RCMAIL->kill_session();
7ef47e59 »
2009-08-14 Add some arguments to the logout_after hook
129 $RCMAIL->plugins->exec_hook('logout_after', $userdata);
f1154163 »
2007-04-28 Merged branch devel-addressbook from r443 back to trunk
130 }
4e17e6c9 »
2005-09-25 Initial revision
131
bac7d174 »
2006-07-18 Fixed bugs #1364122, #1468895, ticket #1483811 and other minor bugs
132 // check session and auth cookie
197601ef »
2008-04-30 Next step: introduce the application class 'rcmail' and get rid of so…
133 else if ($RCMAIL->action != 'login' && $_SESSION['user_id'] && $RCMAIL->action != 'send') {
1854c452 »
2008-05-07 More code cleanup + oop-ization
134 if (!$RCMAIL->authenticate_session()) {
f1154163 »
2007-04-28 Merged branch devel-addressbook from r443 back to trunk
135 $OUTPUT->show_message('sessionerror', 'error');
1854c452 »
2008-05-07 More code cleanup + oop-ization
136 $RCMAIL->kill_session();
4e17e6c9 »
2005-09-25 Initial revision
137 }
f1154163 »
2007-04-28 Merged branch devel-addressbook from r443 back to trunk
138 }
4e17e6c9 »
2005-09-25 Initial revision
139
0ddf59ae »
2009-08-07 Fix spell check (#1486036)
140 // don't check for valid request tokens in these actions
141 $request_check_whitelist = array('login'=>1, 'spell'=>1);
4e17e6c9 »
2005-09-25 Initial revision
142
719a257f »
2007-08-10 Some bugfixes, security issues + minor improvements
143 // check client X-header to verify request origin
47124c22 »
2008-04-12 Changed codebase to PHP5 with autoloader + added some new classes fro…
144 if ($OUTPUT->ajax_call) {
ccc80d1c »
2009-10-14 - Fix login page loading into an iframe when session expires (#1485952)
145 if (!$RCMAIL->config->get('devel_mode') && rc_request_header('X-RoundCube-Request') != $RCMAIL->get_request_token() && !empty($RCMAIL->user->ID)) {
719a257f »
2007-08-10 Some bugfixes, security issues + minor improvements
146 header('HTTP/1.1 404 Not Found');
147 die("Invalid Request");
148 }
149 }
5499336f »
2009-07-21 Use global request tokens and automatically protect all POST requests
150 // check request token in POST form submissions
0ddf59ae »
2009-08-07 Fix spell check (#1486036)
151 else if (!empty($_POST) && !$request_check_whitelist[$RCMAIL->action] && !$RCMAIL->check_request()) {
5499336f »
2009-07-21 Use global request tokens and automatically protect all POST requests
152 $OUTPUT->show_message('invalidrequest', 'error');
153 $OUTPUT->send($RCMAIL->task);
154 }
719a257f »
2007-08-10 Some bugfixes, security issues + minor improvements
155
4e17e6c9 »
2005-09-25 Initial revision
156 // not logged in -> show login page
197601ef »
2008-04-30 Next step: introduce the application class 'rcmail' and get rid of so…
157 if (empty($RCMAIL->user->ID)) {
83a76368 »
2008-06-14 More code cleanup
158 if ($OUTPUT->ajax_call)
c719f3c1 »
2008-06-20 Store compose parameters in session and redirect to a unique URL
159 $OUTPUT->redirect(array(), 2000);
83a76368 »
2008-06-14 More code cleanup
160
ccc80d1c »
2009-10-14 - Fix login page loading into an iframe when session expires (#1485952)
161 if (!empty($_REQUEST['_framed']))
b5713396 »
2009-10-14 - fix last commit
162 $OUTPUT->command('redirect', '?');
ccc80d1c »
2009-10-14 - Fix login page loading into an iframe when session expires (#1485952)
163
330127a6 »
2008-03-02 Disable PHP notices + check for installer script on login page
164 // check if installer is still active
83a76368 »
2008-06-14 More code cleanup
165 if ($RCMAIL->config->get('enable_installer') && is_readable('./installer/index.php')) {
47124c22 »
2008-04-12 Changed codebase to PHP5 with autoloader + added some new classes fro…
166 $OUTPUT->add_footer(html::div(array('style' => "background:#ef9398; border:2px solid #dc5757; padding:0.5em; margin:2em auto; width:50em"),
167 html::tag('h2', array('style' => "margin-top:0.2em"), "Installer script is still accessible") .
168 html::p(null, "The install script of your RoundCube installation is still stored in its default location!") .
169 html::p(null, "Please <b>remove</b> the whole <tt>installer</tt> folder from the RoundCube directory because .
170 these files may expose sensitive configuration data like server passwords and encryption keys
171 to the public. Make sure you cannot access the <a href=\"./installer/\">installer script</a> from your browser.")
172 )
173 );
174 }
330127a6 »
2008-03-02 Disable PHP notices + check for installer script on login page
175
bbf15d81 »
2008-05-02 - fixed task setting on login
176 $OUTPUT->set_env('task', 'login');
f1154163 »
2007-04-28 Merged branch devel-addressbook from r443 back to trunk
177 $OUTPUT->send('login');
178 }
4e17e6c9 »
2005-09-25 Initial revision
179
180
1cded857 »
2005-12-03 Re-design of caching (new database table added\!); some bugfixes; Pos…
181 // handle keep-alive signal
48aff91f »
2008-08-29 Moved code block to a more appropriate position + codestyle
182 if ($RCMAIL->action == 'keep-alive') {
183 $OUTPUT->reset();
184 $OUTPUT->send();
185 }
186 // save preference value
187 else if ($RCMAIL->action == 'save-pref') {
188 $RCMAIL->user->save_prefs(array(get_input_value('_name', RCUBE_INPUT_POST) => get_input_value('_value', RCUBE_INPUT_POST)));
f1154163 »
2007-04-28 Merged branch devel-addressbook from r443 back to trunk
189 $OUTPUT->reset();
83a76368 »
2008-06-14 More code cleanup
190 $OUTPUT->send();
f1154163 »
2007-04-28 Merged branch devel-addressbook from r443 back to trunk
191 }
1cded857 »
2005-12-03 Re-design of caching (new database table added\!); some bugfixes; Pos…
192
4e17e6c9 »
2005-09-25 Initial revision
193
6ea6c9b9 »
2008-06-20 Simplify step inclusion in controller (index.php)
194 // map task/action to a certain include file
195 $action_map = array(
196 'mail' => array(
197 'preview' => 'show.inc',
198 'print' => 'show.inc',
199 'moveto' => 'move_del.inc',
200 'delete' => 'move_del.inc',
201 'send' => 'sendmail.inc',
202 'expunge' => 'folders.inc',
203 'purge' => 'folders.inc',
133bb07f »
2008-12-05 - performance: skip imap connection for attachments actions
204 'remove-attachment' => 'attachments.inc',
205 'display-attachment' => 'attachments.inc',
206 'upload' => 'attachments.inc',
6ea6c9b9 »
2008-06-20 Simplify step inclusion in controller (index.php)
207 ),
4e17e6c9 »
2005-09-25 Initial revision
208
6ea6c9b9 »
2008-06-20 Simplify step inclusion in controller (index.php)
209 'addressbook' => array(
210 'add' => 'edit.inc',
211 ),
4e17e6c9 »
2005-09-25 Initial revision
212
6ea6c9b9 »
2008-06-20 Simplify step inclusion in controller (index.php)
213 'settings' => array(
214 'folders' => 'manage_folders.inc',
215 'create-folder' => 'manage_folders.inc',
216 'rename-folder' => 'manage_folders.inc',
217 'delete-folder' => 'manage_folders.inc',
218 'subscribe' => 'manage_folders.inc',
219 'unsubscribe' => 'manage_folders.inc',
220 'add-identity' => 'edit_identity.inc',
221 )
222 );
223
224 // include task specific functions
564a2ba7 »
2009-07-22 - Help plugin
225 if (is_file($incfile = 'program/steps/'.$RCMAIL->task.'/func.inc'))
226 include_once($incfile);
6ea6c9b9 »
2008-06-20 Simplify step inclusion in controller (index.php)
227
228 // allow 5 "redirects" to another action
229 $redirects = 0; $incstep = null;
230 while ($redirects < 5) {
231 $stepfile = !empty($action_map[$RCMAIL->task][$RCMAIL->action]) ?
232 $action_map[$RCMAIL->task][$RCMAIL->action] : strtr($RCMAIL->action, '-', '_') . '.inc';
cc97ea05 »
2009-04-19 Merged branch devel-api (from r2208 to r2387) back into trunk (omitti…
233
234 // execute a plugin action
0ce11986 »
2009-06-01 - use preg functions instead of ereg functions
235 if (preg_match('/^plugin\./', $RCMAIL->action)) {
cc97ea05 »
2009-04-19 Merged branch devel-api (from r2208 to r2387) back into trunk (omitti…
236 $RCMAIL->plugins->exec_action($RCMAIL->action);
237 break;
238 }
6ea6c9b9 »
2008-06-20 Simplify step inclusion in controller (index.php)
239 // try to include the step file
564a2ba7 »
2009-07-22 - Help plugin
240 else if (is_file($incfile = 'program/steps/'.$RCMAIL->task.'/'.$stepfile)) {
6ea6c9b9 »
2008-06-20 Simplify step inclusion in controller (index.php)
241 include($incfile);
242 $redirects++;
243 }
244 else {
245 break;
246 }
f1154163 »
2007-04-28 Merged branch devel-addressbook from r443 back to trunk
247 }
4e17e6c9 »
2005-09-25 Initial revision
248
249
6ea6c9b9 »
2008-06-20 Simplify step inclusion in controller (index.php)
250 // parse main template (default)
197601ef »
2008-04-30 Next step: introduce the application class 'rcmail' and get rid of so…
251 $OUTPUT->send($RCMAIL->task);
539cd478 »
2005-09-29 Fix for URL injection vulnerability (Bug #1307966)
252
4e17e6c9 »
2005-09-25 Initial revision
253
539cd478 »
2005-09-29 Fix for URL injection vulnerability (Bug #1307966)
254 // if we arrive here, something went wrong
f1154163 »
2007-04-28 Merged branch devel-addressbook from r443 back to trunk
255 raise_error(array(
256 'code' => 404,
257 'type' => 'php',
258 'line' => __LINE__,
259 'file' => __FILE__,
47124c22 »
2008-04-12 Changed codebase to PHP5 with autoloader + added some new classes fro…
260 'message' => "Invalid request"), true, true);
539cd478 »
2005-09-29 Fix for URL injection vulnerability (Bug #1307966)
261
d1d2c4fb »
2006-01-08 adding files and modifications for public ldap search
262 ?>
Something went wrong with that request. Please try again.