| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | +-------------------------------------------------------------------------+ |
|---|
| 4 | | RoundCube Webmail IMAP Client | |
|---|
| 5 | | Version 0.2-20080614 | |
|---|
| 6 | | | |
|---|
| 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 | +-------------------------------------------------------------------------+ |
|---|
| 25 | |
|---|
| 26 | $Id$ |
|---|
| 27 | |
|---|
| 28 | */ |
|---|
| 29 | |
|---|
| 30 | // include environment |
|---|
| 31 | require_once 'program/include/iniset.php'; |
|---|
| 32 | |
|---|
| 33 | // define global vars |
|---|
| 34 | $OUTPUT_TYPE = 'html'; |
|---|
| 35 | |
|---|
| 36 | // init application and start session with requested task |
|---|
| 37 | $RCMAIL = rcmail::get_instance(); |
|---|
| 38 | |
|---|
| 39 | // init output class |
|---|
| 40 | $OUTPUT = !empty($_REQUEST['_remote']) ? $RCMAIL->init_json() : $RCMAIL->load_gui(!empty($_REQUEST['_framed'])); |
|---|
| 41 | |
|---|
| 42 | // set output buffering |
|---|
| 43 | if ($RCMAIL->action != 'get' && $RCMAIL->action != 'viewsource') { |
|---|
| 44 | // use gzip compression if supported |
|---|
| 45 | if (function_exists('ob_gzhandler') |
|---|
| 46 | && !ini_get('zlib.output_compression') |
|---|
| 47 | && ini_get('output_handler') != 'ob_gzhandler') { |
|---|
| 48 | ob_start('ob_gzhandler'); |
|---|
| 49 | } |
|---|
| 50 | else { |
|---|
| 51 | ob_start(); |
|---|
| 52 | } |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | // check DB connections and exit on failure |
|---|
| 56 | if ($err_str = $DB->is_error()) { |
|---|
| 57 | raise_error(array( |
|---|
| 58 | 'code' => 603, |
|---|
| 59 | 'type' => 'db', |
|---|
| 60 | 'message' => $err_str), FALSE, TRUE); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | // error steps |
|---|
| 65 | if ($RCMAIL->action=='error' && !empty($_GET['_code'])) { |
|---|
| 66 | raise_error(array('code' => hexdec($_GET['_code'])), FALSE, TRUE); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | // try to log in |
|---|
| 70 | if ($RCMAIL->action=='login' && $RCMAIL->task=='mail') { |
|---|
| 71 | $host = $RCMAIL->autoselect_host(); |
|---|
| 72 | |
|---|
| 73 | // check if client supports cookies |
|---|
| 74 | if (empty($_COOKIE)) { |
|---|
| 75 | $OUTPUT->show_message("cookiesdisabled", 'warning'); |
|---|
| 76 | } |
|---|
| 77 | else if ($_SESSION['temp'] && !empty($_POST['_user']) && isset($_POST['_pass']) && |
|---|
| 78 | $RCMAIL->login(trim(get_input_value('_user', RCUBE_INPUT_POST), ' '), |
|---|
| 79 | get_input_value('_pass', RCUBE_INPUT_POST, true, 'ISO-8859-1'), $host)) { |
|---|
| 80 | // create new session ID |
|---|
| 81 | unset($_SESSION['temp']); |
|---|
| 82 | sess_regenerate_id(); |
|---|
| 83 | |
|---|
| 84 | // send auth cookie if necessary |
|---|
| 85 | $RCMAIL->authenticate_session(); |
|---|
| 86 | |
|---|
| 87 | // log successful login |
|---|
| 88 | if ($RCMAIL->config->get('log_logins') && $RCMAIL->config->get('debug_level') & 1) |
|---|
| 89 | console(sprintf('Successful login for %s (id %d) from %s', |
|---|
| 90 | trim(get_input_value('_user', RCUBE_INPUT_POST), ' '), |
|---|
| 91 | $_SESSION['user_id'], |
|---|
| 92 | $_SERVER['REMOTE_ADDR'])); |
|---|
| 93 | |
|---|
| 94 | // send redirect |
|---|
| 95 | header("Location: {$RCMAIL->comm_path}"); |
|---|
| 96 | exit; |
|---|
| 97 | } |
|---|
| 98 | else { |
|---|
| 99 | $OUTPUT->show_message($IMAP->error_code == -1 ? 'imaperror' : 'loginfailed', 'warning'); |
|---|
| 100 | $RCMAIL->kill_session(); |
|---|
| 101 | } |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | // end session |
|---|
| 105 | else if (($RCMAIL->task=='logout' || $RCMAIL->action=='logout') && isset($_SESSION['user_id'])) { |
|---|
| 106 | $OUTPUT->show_message('loggedout'); |
|---|
| 107 | $RCMAIL->logout_actions(); |
|---|
| 108 | $RCMAIL->kill_session(); |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | // check session and auth cookie |
|---|
| 112 | else if ($RCMAIL->action != 'login' && $_SESSION['user_id'] && $RCMAIL->action != 'send') { |
|---|
| 113 | if (!$RCMAIL->authenticate_session()) { |
|---|
| 114 | $OUTPUT->show_message('sessionerror', 'error'); |
|---|
| 115 | $RCMAIL->kill_session(); |
|---|
| 116 | } |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | // log in to imap server |
|---|
| 121 | if (!empty($RCMAIL->user->ID) && $RCMAIL->task == 'mail') { |
|---|
| 122 | if (!$RCMAIL->imap_connect()) { |
|---|
| 123 | $RCMAIL->kill_session(); |
|---|
| 124 | } |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | // check client X-header to verify request origin |
|---|
| 129 | if ($OUTPUT->ajax_call) { |
|---|
| 130 | if ($RCMAIL->config->get('devel_mode') && !rc_request_header('X-RoundCube-Referer')) { |
|---|
| 131 | header('HTTP/1.1 404 Not Found'); |
|---|
| 132 | die("Invalid Request"); |
|---|
| 133 | } |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | // not logged in -> show login page |
|---|
| 138 | if (empty($RCMAIL->user->ID)) { |
|---|
| 139 | |
|---|
| 140 | if ($OUTPUT->ajax_call) |
|---|
| 141 | $OUTPUT->remote_response("setTimeout(\"location.href='\"+this.env.comm_path+\"'\", 2000);"); |
|---|
| 142 | |
|---|
| 143 | // check if installer is still active |
|---|
| 144 | if ($RCMAIL->config->get('enable_installer') && is_readable('./installer/index.php')) { |
|---|
| 145 | $OUTPUT->add_footer(html::div(array('style' => "background:#ef9398; border:2px solid #dc5757; padding:0.5em; margin:2em auto; width:50em"), |
|---|
| 146 | html::tag('h2', array('style' => "margin-top:0.2em"), "Installer script is still accessible") . |
|---|
| 147 | html::p(null, "The install script of your RoundCube installation is still stored in its default location!") . |
|---|
| 148 | html::p(null, "Please <b>remove</b> the whole <tt>installer</tt> folder from the RoundCube directory because . |
|---|
| 149 | these files may expose sensitive configuration data like server passwords and encryption keys |
|---|
| 150 | to the public. Make sure you cannot access the <a href=\"./installer/\">installer script</a> from your browser.") |
|---|
| 151 | ) |
|---|
| 152 | ); |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | $OUTPUT->set_env('task', 'login'); |
|---|
| 156 | $OUTPUT->send('login'); |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | // handle keep-alive signal |
|---|
| 161 | if ($RCMAIL->action=='keep-alive') { |
|---|
| 162 | $OUTPUT->reset(); |
|---|
| 163 | $OUTPUT->send(); |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | // include task specific files |
|---|
| 167 | if ($RCMAIL->task=='mail') { |
|---|
| 168 | include_once('program/steps/mail/func.inc'); |
|---|
| 169 | |
|---|
| 170 | if ($RCMAIL->action=='show' || $RCMAIL->action=='preview' || $RCMAIL->action=='print') |
|---|
| 171 | include('program/steps/mail/show.inc'); |
|---|
| 172 | |
|---|
| 173 | if ($RCMAIL->action=='get') |
|---|
| 174 | include('program/steps/mail/get.inc'); |
|---|
| 175 | |
|---|
| 176 | if ($RCMAIL->action=='moveto' || $RCMAIL->action=='delete') |
|---|
| 177 | include('program/steps/mail/move_del.inc'); |
|---|
| 178 | |
|---|
| 179 | if ($RCMAIL->action=='mark') |
|---|
| 180 | include('program/steps/mail/mark.inc'); |
|---|
| 181 | |
|---|
| 182 | if ($RCMAIL->action=='viewsource') |
|---|
| 183 | include('program/steps/mail/viewsource.inc'); |
|---|
| 184 | |
|---|
| 185 | if ($RCMAIL->action=='sendmdn') |
|---|
| 186 | include('program/steps/mail/sendmdn.inc'); |
|---|
| 187 | |
|---|
| 188 | if ($RCMAIL->action=='send') |
|---|
| 189 | include('program/steps/mail/sendmail.inc'); |
|---|
| 190 | |
|---|
| 191 | if ($RCMAIL->action=='upload') |
|---|
| 192 | include('program/steps/mail/upload.inc'); |
|---|
| 193 | |
|---|
| 194 | if ($RCMAIL->action=='compose' || $RCMAIL->action=='remove-attachment' || $RCMAIL->action=='display-attachment') |
|---|
| 195 | include('program/steps/mail/compose.inc'); |
|---|
| 196 | |
|---|
| 197 | if ($RCMAIL->action=='addcontact') |
|---|
| 198 | include('program/steps/mail/addcontact.inc'); |
|---|
| 199 | |
|---|
| 200 | if ($RCMAIL->action=='expunge' || $RCMAIL->action=='purge') |
|---|
| 201 | include('program/steps/mail/folders.inc'); |
|---|
| 202 | |
|---|
| 203 | if ($RCMAIL->action=='check-recent') |
|---|
| 204 | include('program/steps/mail/check_recent.inc'); |
|---|
| 205 | |
|---|
| 206 | if ($RCMAIL->action=='getunread') |
|---|
| 207 | include('program/steps/mail/getunread.inc'); |
|---|
| 208 | |
|---|
| 209 | if ($RCMAIL->action=='list' && isset($_REQUEST['_remote'])) |
|---|
| 210 | include('program/steps/mail/list.inc'); |
|---|
| 211 | |
|---|
| 212 | if ($RCMAIL->action=='search') |
|---|
| 213 | include('program/steps/mail/search.inc'); |
|---|
| 214 | |
|---|
| 215 | if ($RCMAIL->action=='spell') |
|---|
| 216 | include('program/steps/mail/spell.inc'); |
|---|
| 217 | |
|---|
| 218 | if ($RCMAIL->action=='rss') |
|---|
| 219 | include('program/steps/mail/rss.inc'); |
|---|
| 220 | |
|---|
| 221 | // make sure the message count is refreshed |
|---|
| 222 | $IMAP->messagecount($_SESSION['mbox'], 'ALL', true); |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | // include task specific files |
|---|
| 227 | if ($RCMAIL->task=='addressbook') { |
|---|
| 228 | include_once('program/steps/addressbook/func.inc'); |
|---|
| 229 | |
|---|
| 230 | if ($RCMAIL->action=='save') |
|---|
| 231 | include('program/steps/addressbook/save.inc'); |
|---|
| 232 | |
|---|
| 233 | if ($RCMAIL->action=='edit' || $RCMAIL->action=='add') |
|---|
| 234 | include('program/steps/addressbook/edit.inc'); |
|---|
| 235 | |
|---|
| 236 | if ($RCMAIL->action=='delete') |
|---|
| 237 | include('program/steps/addressbook/delete.inc'); |
|---|
| 238 | |
|---|
| 239 | if ($RCMAIL->action=='show') |
|---|
| 240 | include('program/steps/addressbook/show.inc'); |
|---|
| 241 | |
|---|
| 242 | if ($RCMAIL->action=='list' && $_REQUEST['_remote']) |
|---|
| 243 | include('program/steps/addressbook/list.inc'); |
|---|
| 244 | |
|---|
| 245 | if ($RCMAIL->action=='search') |
|---|
| 246 | include('program/steps/addressbook/search.inc'); |
|---|
| 247 | |
|---|
| 248 | if ($RCMAIL->action=='copy') |
|---|
| 249 | include('program/steps/addressbook/copy.inc'); |
|---|
| 250 | |
|---|
| 251 | if ($RCMAIL->action=='mailto') |
|---|
| 252 | include('program/steps/addressbook/mailto.inc'); |
|---|
| 253 | } |
|---|
| 254 | |
|---|
| 255 | |
|---|
| 256 | // include task specific files |
|---|
| 257 | if ($RCMAIL->task=='settings') { |
|---|
| 258 | include_once('program/steps/settings/func.inc'); |
|---|
| 259 | |
|---|
| 260 | if ($RCMAIL->action=='save-identity') |
|---|
| 261 | include('program/steps/settings/save_identity.inc'); |
|---|
| 262 | |
|---|
| 263 | if ($RCMAIL->action=='add-identity' || $RCMAIL->action=='edit-identity') |
|---|
| 264 | include('program/steps/settings/edit_identity.inc'); |
|---|
| 265 | |
|---|
| 266 | if ($RCMAIL->action=='delete-identity') |
|---|
| 267 | include('program/steps/settings/delete_identity.inc'); |
|---|
| 268 | |
|---|
| 269 | if ($RCMAIL->action=='identities') |
|---|
| 270 | include('program/steps/settings/identities.inc'); |
|---|
| 271 | |
|---|
| 272 | if ($RCMAIL->action=='save-prefs') |
|---|
| 273 | include('program/steps/settings/save_prefs.inc'); |
|---|
| 274 | |
|---|
| 275 | if ($RCMAIL->action=='folders' || $RCMAIL->action=='subscribe' || $RCMAIL->action=='unsubscribe' || |
|---|
| 276 | $RCMAIL->action=='create-folder' || $RCMAIL->action=='rename-folder' || $RCMAIL->action=='delete-folder') |
|---|
| 277 | include('program/steps/settings/manage_folders.inc'); |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | // parse main template |
|---|
| 282 | $OUTPUT->send($RCMAIL->task); |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | // if we arrive here, something went wrong |
|---|
| 286 | raise_error(array( |
|---|
| 287 | 'code' => 404, |
|---|
| 288 | 'type' => 'php', |
|---|
| 289 | 'line' => __LINE__, |
|---|
| 290 | 'file' => __FILE__, |
|---|
| 291 | 'message' => "Invalid request"), true, true); |
|---|
| 292 | |
|---|
| 293 | ?> |
|---|