3 +-------------------------------------------------------------------------+
4 | RoundCube Webmail IMAP Client |
7 | Copyright (C) 2005-2008, RoundCube Dev. - Switzerland |
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. |
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. |
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. |
22 +-------------------------------------------------------------------------+
23 | Author: Thomas Bruederli <roundcube@gmail.com> |
24 +-------------------------------------------------------------------------+
26 $Id: index.php 1499 2008-06-09 20:57:53Z thomasb $
30 // include environment
31 require_once 'program/include/iniset.php';
34 $OUTPUT_TYPE = 'html';
36 // set output buffering
37 if ($RCMAIL->action != 'get' && $RCMAIL->action != 'viewsource') {
38 // use gzip compression if supported
39 if (function_exists('ob_gzhandler')
40 && !ini_get('zlib.output_compression')
41 && ini_get('output_handler') != 'ob_gzhandler') {
42 ob_start('ob_gzhandler');
50 // init application and start session with requested task
51 $RCMAIL = rcmail::get_instance();
54 $OUTPUT = (!empty($_GET['_remote']) || !empty($_POST['_remote'])) ? $RCMAIL->init_json() : $RCMAIL->load_gui((!empty($_GET['_framed']) || !empty($_POST['_framed'])));
57 // check DB connections and exit on failure
58 if ($err_str = $DB->is_error()) {
62 'message' => $err_str), FALSE, TRUE);
67 if ($RCMAIL->action=='error' && !empty($_GET['_code'])) {
68 raise_error(array('code' => hexdec($_GET['_code'])), FALSE, TRUE);
72 if ($RCMAIL->action=='login' && $RCMAIL->task=='mail') {
73 $host = $RCMAIL->autoselect_host();
75 // check if client supports cookies
76 if (empty($_COOKIE)) {
77 $OUTPUT->show_message("cookiesdisabled", 'warning');
79 else if ($_SESSION['temp'] && !empty($_POST['_user']) && isset($_POST['_pass']) &&
80 $RCMAIL->login(trim(get_input_value('_user', RCUBE_INPUT_POST), ' '),
81 get_input_value('_pass', RCUBE_INPUT_POST, true, 'ISO-8859-1'), $host)) {
82 // create new session ID
83 unset($_SESSION['temp']);
86 // send auth cookie if necessary
87 $RCMAIL->authenticate_session();
89 // log successful login
90 if ($RCMAIL->config->get('log_logins') && $RCMAIL->config->get('debug_level') & 1)
91 console(sprintf('Successful login for %s (id %d) from %s',
92 trim(get_input_value('_user', RCUBE_INPUT_POST), ' '),
94 $_SERVER['REMOTE_ADDR']));
97 header("Location: {$RCMAIL->comm_path}");
101 $OUTPUT->show_message($IMAP->error_code == -1 ? 'imaperror' : 'loginfailed', 'warning');
102 $RCMAIL->kill_session();
107 else if (($RCMAIL->task=='logout' || $RCMAIL->action=='logout') && isset($_SESSION['user_id'])) {
108 $OUTPUT->show_message('loggedout');
109 $RCMAIL->logout_actions();
110 $RCMAIL->kill_session();
113 // check session and auth cookie
114 else if ($RCMAIL->action != 'login' && $_SESSION['user_id'] && $RCMAIL->action != 'send') {
115 if (!$RCMAIL->authenticate_session()) {
116 $OUTPUT->show_message('sessionerror', 'error');
117 $RCMAIL->kill_session();
122 // log in to imap server
123 if (!empty($RCMAIL->user->ID) && $RCMAIL->task == 'mail') {
124 if (!$RCMAIL->imap_connect()) {
125 $RCMAIL->kill_session();
130 // not logged in -> set task to 'login
131 if (empty($RCMAIL->user->ID)) {
132 if ($OUTPUT->ajax_call)
133 $OUTPUT->remote_response("setTimeout(\"location.href='\"+this.env.comm_path+\"'\", 2000);");
135 $RCMAIL->set_task('login');
139 // check client X-header to verify request origin
140 if ($OUTPUT->ajax_call) {
141 if (empty($CONFIG['devel_mode']) && !rc_request_header('X-RoundCube-Referer')) {
142 header('HTTP/1.1 404 Not Found');
143 die("Invalid Request");
148 // not logged in -> show login page
149 if (empty($RCMAIL->user->ID)) {
150 // check if installer is still active
151 if ($CONFIG['enable_installer'] && is_readable('./installer/index.php')) {
152 $OUTPUT->add_footer(html::div(array('style' => "background:#ef9398; border:2px solid #dc5757; padding:0.5em; margin:2em auto; width:50em"),
153 html::tag('h2', array('style' => "margin-top:0.2em"), "Installer script is still accessible") .
154 html::p(null, "The install script of your RoundCube installation is still stored in its default location!") .
155 html::p(null, "Please <b>remove</b> the whole <tt>installer</tt> folder from the RoundCube directory because .
156 these files may expose sensitive configuration data like server passwords and encryption keys
157 to the public. Make sure you cannot access the <a href=\"./installer/\">installer script</a> from your browser.")
162 $OUTPUT->set_env('task', 'login');
163 $OUTPUT->task = 'login';
164 $OUTPUT->send('login');
169 // handle keep-alive signal
170 if ($RCMAIL->action=='keep-alive') {
176 // include task specific files
177 if ($RCMAIL->task=='mail') {
178 include_once('program/steps/mail/func.inc');
180 if ($RCMAIL->action=='show' || $RCMAIL->action=='preview' || $RCMAIL->action=='print')
181 include('program/steps/mail/show.inc');
183 if ($RCMAIL->action=='get')
184 include('program/steps/mail/get.inc');
186 if ($RCMAIL->action=='moveto' || $RCMAIL->action=='delete')
187 include('program/steps/mail/move_del.inc');
189 if ($RCMAIL->action=='mark')
190 include('program/steps/mail/mark.inc');
192 if ($RCMAIL->action=='viewsource')
193 include('program/steps/mail/viewsource.inc');
195 if ($RCMAIL->action=='sendmdn')
196 include('program/steps/mail/sendmdn.inc');
198 if ($RCMAIL->action=='send')
199 include('program/steps/mail/sendmail.inc');
201 if ($RCMAIL->action=='upload')
202 include('program/steps/mail/upload.inc');
204 if ($RCMAIL->action=='compose' || $RCMAIL->action=='remove-attachment' || $RCMAIL->action=='display-attachment')
205 include('program/steps/mail/compose.inc');
207 if ($RCMAIL->action=='addcontact')
208 include('program/steps/mail/addcontact.inc');
210 if ($RCMAIL->action=='expunge' || $RCMAIL->action=='purge')
211 include('program/steps/mail/folders.inc');
213 if ($RCMAIL->action=='check-recent')
214 include('program/steps/mail/check_recent.inc');
216 if ($RCMAIL->action=='getunread')
217 include('program/steps/mail/getunread.inc');
219 if ($RCMAIL->action=='list' && isset($_REQUEST['_remote']))
220 include('program/steps/mail/list.inc');
222 if ($RCMAIL->action=='search')
223 include('program/steps/mail/search.inc');
225 if ($RCMAIL->action=='spell')
226 include('program/steps/mail/spell.inc');
228 if ($RCMAIL->action=='rss')
229 include('program/steps/mail/rss.inc');
231 // make sure the message count is refreshed
232 $IMAP->messagecount($_SESSION['mbox'], 'ALL', true);
236 // include task specific files
237 if ($RCMAIL->task=='addressbook') {
238 include_once('program/steps/addressbook/func.inc');
240 if ($RCMAIL->action=='save')
241 include('program/steps/addressbook/save.inc');
243 if ($RCMAIL->action=='edit' || $RCMAIL->action=='add')
244 include('program/steps/addressbook/edit.inc');
246 if ($RCMAIL->action=='delete')
247 include('program/steps/addressbook/delete.inc');
249 if ($RCMAIL->action=='show')
250 include('program/steps/addressbook/show.inc');
252 if ($RCMAIL->action=='list' && $_REQUEST['_remote'])
253 include('program/steps/addressbook/list.inc');
255 if ($RCMAIL->action=='search')
256 include('program/steps/addressbook/search.inc');
258 if ($RCMAIL->action=='copy')
259 include('program/steps/addressbook/copy.inc');
261 if ($RCMAIL->action=='mailto')
262 include('program/steps/addressbook/mailto.inc');
266 // include task specific files
267 if ($RCMAIL->task=='settings') {
268 include_once('program/steps/settings/func.inc');
270 if ($RCMAIL->action=='save-identity')
271 include('program/steps/settings/save_identity.inc');
273 if ($RCMAIL->action=='add-identity' || $RCMAIL->action=='edit-identity')
274 include('program/steps/settings/edit_identity.inc');
276 if ($RCMAIL->action=='delete-identity')
277 include('program/steps/settings/delete_identity.inc');
279 if ($RCMAIL->action=='identities')
280 include('program/steps/settings/identities.inc');
282 if ($RCMAIL->action=='save-prefs')
283 include('program/steps/settings/save_prefs.inc');
285 if ($RCMAIL->action=='folders' || $RCMAIL->action=='subscribe' || $RCMAIL->action=='unsubscribe' ||
286 $RCMAIL->action=='create-folder' || $RCMAIL->action=='rename-folder' || $RCMAIL->action=='delete-folder')
287 include('program/steps/settings/manage_folders.inc');
291 // parse main template
292 $OUTPUT->send($RCMAIL->task);
295 // if we arrive here, something went wrong
301 'message' => "Invalid request"), true, true);