thomascube
2008-06-09 f64f5f59077e3bffe4dd8b60ab4ff0d674d0fc26
commit | author | age
4e17e6 1 <?php
T 2 /*
a6f90e 3  +-------------------------------------------------------------------------+
A 4  | RoundCube Webmail IMAP Client                                           |
f64f5f 5  | Version 0.2-alpha                                                       |
a6f90e 6  |                                                                         |
A 7  | Copyright (C) 2005-2008, RoundCube Dev. - Switzerland                   |
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  +-------------------------------------------------------------------------+
4e17e6 25
T 26  $Id$
27
28 */
15a9d1 29
47124c 30 // include environment
T 31 require_once 'program/include/iniset.php';
15a9d1 32
4e17e6 33 // define global vars
T 34 $OUTPUT_TYPE = 'html';
2f2f15 35
T 36 // set output buffering
197601 37 if ($RCMAIL->action != 'get' && $RCMAIL->action != 'viewsource') {
2f2f15 38   // use gzip compression if supported
03fcc1 39   if (function_exists('ob_gzhandler')
47124c 40       && !ini_get('zlib.output_compression')
T 41       && ini_get('output_handler') != 'ob_gzhandler') {
2f2f15 42     ob_start('ob_gzhandler');
03fcc1 43   }
47124c 44   else {
2f2f15 45     ob_start();
47124c 46   }
f11541 47 }
2f2f15 48
42b113 49
197601 50 // init application and start session with requested task
T 51 $RCMAIL = rcmail::get_instance();
4e17e6 52
47124c 53 // init output class
197601 54 $OUTPUT = (!empty($_GET['_remote']) || !empty($_POST['_remote'])) ? $RCMAIL->init_json() : $RCMAIL->load_gui((!empty($_GET['_framed']) || !empty($_POST['_framed'])));
4e17e6 55
8affba 56
T 57 // check DB connections and exit on failure
47124c 58 if ($err_str = $DB->is_error()) {
f11541 59   raise_error(array(
T 60     'code' => 603,
61     'type' => 'db',
62     'message' => $err_str), FALSE, TRUE);
63 }
8affba 64
T 65
4e17e6 66 // error steps
197601 67 if ($RCMAIL->action=='error' && !empty($_GET['_code'])) {
4e17e6 68   raise_error(array('code' => hexdec($_GET['_code'])), FALSE, TRUE);
47124c 69 }
570f0b 70
4e17e6 71 // try to log in
197601 72 if ($RCMAIL->action=='login' && $RCMAIL->task=='mail') {
1854c4 73   $host = $RCMAIL->autoselect_host();
4e17e6 74   
T 75   // check if client supports cookies
47124c 76   if (empty($_COOKIE)) {
f11541 77     $OUTPUT->show_message("cookiesdisabled", 'warning');
T 78   }
f15c26 79   else if ($_SESSION['temp'] && !empty($_POST['_user']) && isset($_POST['_pass']) &&
197601 80            $RCMAIL->login(trim(get_input_value('_user', RCUBE_INPUT_POST), ' '),
47124c 81               get_input_value('_pass', RCUBE_INPUT_POST, true, 'ISO-8859-1'), $host)) {
aad6e2 82     // create new session ID
T 83     unset($_SESSION['temp']);
84     sess_regenerate_id();
85
86     // send auth cookie if necessary
1854c4 87     $RCMAIL->authenticate_session();
aad6e2 88
5e0045 89     // log successful login
S 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), ' '),
93                       $_SESSION['user_id'],
94                       $_SERVER['REMOTE_ADDR']));
95
4e17e6 96     // send redirect
197601 97     header("Location: {$RCMAIL->comm_path}");
4e17e6 98     exit;
T 99   }
47124c 100   else {
fc6725 101     $OUTPUT->show_message($IMAP->error_code == -1 ? 'imaperror' : 'loginfailed', 'warning');
1854c4 102     $RCMAIL->kill_session();
f11541 103   }
T 104 }
4e17e6 105
T 106 // end session
197601 107 else if (($RCMAIL->task=='logout' || $RCMAIL->action=='logout') && isset($_SESSION['user_id'])) {
f11541 108   $OUTPUT->show_message('loggedout');
1854c4 109   $RCMAIL->logout_actions();
T 110   $RCMAIL->kill_session();
f11541 111 }
4e17e6 112
bac7d1 113 // check session and auth cookie
197601 114 else if ($RCMAIL->action != 'login' && $_SESSION['user_id'] && $RCMAIL->action != 'send') {
1854c4 115   if (!$RCMAIL->authenticate_session()) {
f11541 116     $OUTPUT->show_message('sessionerror', 'error');
1854c4 117     $RCMAIL->kill_session();
4e17e6 118   }
f11541 119 }
4e17e6 120
T 121
122 // log in to imap server
197601 123 if (!empty($RCMAIL->user->ID) && $RCMAIL->task == 'mail') {
1854c4 124   if (!$RCMAIL->imap_connect()) {
T 125     $RCMAIL->kill_session();
47124c 126   }
f11541 127 }
4e17e6 128
T 129
130 // not logged in -> set task to 'login
197601 131 if (empty($RCMAIL->user->ID)) {
f11541 132   if ($OUTPUT->ajax_call)
T 133     $OUTPUT->remote_response("setTimeout(\"location.href='\"+this.env.comm_path+\"'\", 2000);");
42b113 134   
1854c4 135   $RCMAIL->set_task('login');
f11541 136 }
4e17e6 137
T 138
719a25 139 // check client X-header to verify request origin
47124c 140 if ($OUTPUT->ajax_call) {
T 141   if (empty($CONFIG['devel_mode']) && !rc_request_header('X-RoundCube-Referer')) {
719a25 142     header('HTTP/1.1 404 Not Found');
T 143     die("Invalid Request");
144   }
145 }
146
4e17e6 147
T 148 // not logged in -> show login page
197601 149 if (empty($RCMAIL->user->ID)) {
330127 150   // check if installer is still active
47124c 151   if ($CONFIG['enable_installer'] && is_readable('./installer/index.php')) {
T 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.")
158       )
159     );
160   }
330127 161   
bbf15d 162   $OUTPUT->set_env('task', 'login');
f11541 163   $OUTPUT->task = 'login';
T 164   $OUTPUT->send('login');
4e17e6 165   exit;
f11541 166 }
4e17e6 167
T 168
1cded8 169 // handle keep-alive signal
197601 170 if ($RCMAIL->action=='keep-alive') {
f11541 171   $OUTPUT->reset();
T 172   $OUTPUT->send('');
1cded8 173   exit;
f11541 174 }
4e17e6 175
T 176 // include task specific files
197601 177 if ($RCMAIL->task=='mail') {
4e17e6 178   include_once('program/steps/mail/func.inc');
88375f 179   
197601 180   if ($RCMAIL->action=='show' || $RCMAIL->action=='preview' || $RCMAIL->action=='print')
4e17e6 181     include('program/steps/mail/show.inc');
T 182
197601 183   if ($RCMAIL->action=='get')
4e17e6 184     include('program/steps/mail/get.inc');
T 185
197601 186   if ($RCMAIL->action=='moveto' || $RCMAIL->action=='delete')
4e17e6 187     include('program/steps/mail/move_del.inc');
T 188
197601 189   if ($RCMAIL->action=='mark')
4e17e6 190     include('program/steps/mail/mark.inc');
T 191
197601 192   if ($RCMAIL->action=='viewsource')
4e17e6 193     include('program/steps/mail/viewsource.inc');
T 194
197601 195   if ($RCMAIL->action=='sendmdn')
fba1f5 196     include('program/steps/mail/sendmdn.inc');
T 197
197601 198   if ($RCMAIL->action=='send')
4e17e6 199     include('program/steps/mail/sendmail.inc');
T 200
197601 201   if ($RCMAIL->action=='upload')
4e17e6 202     include('program/steps/mail/upload.inc');
T 203
197601 204   if ($RCMAIL->action=='compose' || $RCMAIL->action=='remove-attachment' || $RCMAIL->action=='display-attachment')
4e17e6 205     include('program/steps/mail/compose.inc');
T 206
197601 207   if ($RCMAIL->action=='addcontact')
4e17e6 208     include('program/steps/mail/addcontact.inc');
15a9d1 209
197601 210   if ($RCMAIL->action=='expunge' || $RCMAIL->action=='purge')
15a9d1 211     include('program/steps/mail/folders.inc');
T 212
197601 213   if ($RCMAIL->action=='check-recent')
15a9d1 214     include('program/steps/mail/check_recent.inc');
T 215
197601 216   if ($RCMAIL->action=='getunread')
15a9d1 217     include('program/steps/mail/getunread.inc');
4e17e6 218     
197601 219   if ($RCMAIL->action=='list' && isset($_REQUEST['_remote']))
4e17e6 220     include('program/steps/mail/list.inc');
T 221
197601 222    if ($RCMAIL->action=='search')
dd53e2 223      include('program/steps/mail/search.inc');
T 224      
197601 225   if ($RCMAIL->action=='spell')
dd53e2 226     include('program/steps/mail/spell.inc');
4647e1 227
197601 228   if ($RCMAIL->action=='rss')
88375f 229     include('program/steps/mail/rss.inc');
3ea0e3 230     
01c86f 231   // make sure the message count is refreshed
47124c 232   $IMAP->messagecount($_SESSION['mbox'], 'ALL', true);
f11541 233 }
4e17e6 234
T 235
236 // include task specific files
197601 237 if ($RCMAIL->task=='addressbook') {
4e17e6 238   include_once('program/steps/addressbook/func.inc');
T 239
197601 240   if ($RCMAIL->action=='save')
4e17e6 241     include('program/steps/addressbook/save.inc');
T 242   
197601 243   if ($RCMAIL->action=='edit' || $RCMAIL->action=='add')
4e17e6 244     include('program/steps/addressbook/edit.inc');
T 245   
197601 246   if ($RCMAIL->action=='delete')
4e17e6 247     include('program/steps/addressbook/delete.inc');
T 248
197601 249   if ($RCMAIL->action=='show')
4e17e6 250     include('program/steps/addressbook/show.inc');  
T 251
197601 252   if ($RCMAIL->action=='list' && $_REQUEST['_remote'])
4e17e6 253     include('program/steps/addressbook/list.inc');
d1d2c4 254
197601 255   if ($RCMAIL->action=='search')
f11541 256     include('program/steps/addressbook/search.inc');
T 257
197601 258   if ($RCMAIL->action=='copy')
f11541 259     include('program/steps/addressbook/copy.inc');
T 260
197601 261   if ($RCMAIL->action=='mailto')
f11541 262     include('program/steps/addressbook/mailto.inc');
T 263 }
4e17e6 264
T 265
266 // include task specific files
197601 267 if ($RCMAIL->task=='settings') {
4e17e6 268   include_once('program/steps/settings/func.inc');
T 269
197601 270   if ($RCMAIL->action=='save-identity')
4e17e6 271     include('program/steps/settings/save_identity.inc');
T 272
197601 273   if ($RCMAIL->action=='add-identity' || $RCMAIL->action=='edit-identity')
4e17e6 274     include('program/steps/settings/edit_identity.inc');
T 275
197601 276   if ($RCMAIL->action=='delete-identity')
4e17e6 277     include('program/steps/settings/delete_identity.inc');
T 278   
197601 279   if ($RCMAIL->action=='identities')
4e17e6 280     include('program/steps/settings/identities.inc');  
T 281
197601 282   if ($RCMAIL->action=='save-prefs')
4e17e6 283     include('program/steps/settings/save_prefs.inc');  
T 284
197601 285   if ($RCMAIL->action=='folders' || $RCMAIL->action=='subscribe' || $RCMAIL->action=='unsubscribe' ||
T 286       $RCMAIL->action=='create-folder' || $RCMAIL->action=='rename-folder' || $RCMAIL->action=='delete-folder')
4e17e6 287     include('program/steps/settings/manage_folders.inc');
f11541 288 }
ecf759 289
T 290
539cd4 291 // parse main template
197601 292 $OUTPUT->send($RCMAIL->task);
539cd4 293
T 294
295 // if we arrive here, something went wrong
f11541 296 raise_error(array(
T 297   'code' => 404,
298   'type' => 'php',
299   'line' => __LINE__,
300   'file' => __FILE__,
47124c 301   'message' => "Invalid request"), true, true);
539cd4 302                       
d1d2c4 303 ?>