| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | +-----------------------------------------------------------------------+ |
|---|
| 4 | | RoundCube Webmail IMAP Client | |
|---|
| 5 | | Version 0.1-20070301 | |
|---|
| 6 | | | |
|---|
| 7 | | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland | |
|---|
| 8 | | Licensed under the GNU GPL | |
|---|
| 9 | | | |
|---|
| 10 | | Redistribution and use in source and binary forms, with or without | |
|---|
| 11 | | modification, are permitted provided that the following conditions | |
|---|
| 12 | | are met: | |
|---|
| 13 | | | |
|---|
| 14 | | o Redistributions of source code must retain the above copyright | |
|---|
| 15 | | notice, this list of conditions and the following disclaimer. | |
|---|
| 16 | | o Redistributions in binary form must reproduce the above copyright | |
|---|
| 17 | | notice, this list of conditions and the following disclaimer in the | |
|---|
| 18 | | documentation and/or other materials provided with the distribution.| |
|---|
| 19 | | o The names of the authors may not be used to endorse or promote | |
|---|
| 20 | | products derived from this software without specific prior written | |
|---|
| 21 | | permission. | |
|---|
| 22 | | | |
|---|
| 23 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
|---|
| 24 | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
|---|
| 25 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
|---|
| 26 | | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
|---|
| 27 | | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
|---|
| 28 | | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
|---|
| 29 | | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
|---|
| 30 | | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
|---|
| 31 | | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
|---|
| 32 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
|---|
| 33 | | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
|---|
| 34 | | | |
|---|
| 35 | +-----------------------------------------------------------------------+ |
|---|
| 36 | | Author: Thomas Bruederli <roundcube@gmail.com> | |
|---|
| 37 | +-----------------------------------------------------------------------+ |
|---|
| 38 | |
|---|
| 39 | $Id$ |
|---|
| 40 | |
|---|
| 41 | */ |
|---|
| 42 | |
|---|
| 43 | define('RCMAIL_VERSION', '0.1-20070301'); |
|---|
| 44 | |
|---|
| 45 | // define global vars |
|---|
| 46 | $CHARSET = 'UTF-8'; |
|---|
| 47 | $OUTPUT_TYPE = 'html'; |
|---|
| 48 | $JS_OBJECT_NAME = 'rcmail'; |
|---|
| 49 | $INSTALL_PATH = dirname(__FILE__); |
|---|
| 50 | $MAIN_TASKS = array('mail','settings','addressbook','logout'); |
|---|
| 51 | |
|---|
| 52 | if (empty($INSTALL_PATH)) |
|---|
| 53 | $INSTALL_PATH = './'; |
|---|
| 54 | else |
|---|
| 55 | $INSTALL_PATH .= '/'; |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | // make sure path_separator is defined |
|---|
| 59 | if (!defined('PATH_SEPARATOR')) |
|---|
| 60 | define('PATH_SEPARATOR', (eregi('win', PHP_OS) ? ';' : ':')); |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | // RC include folders MUST be included FIRST to avoid other |
|---|
| 64 | // possible not compatible libraries (i.e PEAR) to be included |
|---|
| 65 | // instead the ones provided by RC |
|---|
| 66 | ini_set('include_path', $INSTALL_PATH.PATH_SEPARATOR.$INSTALL_PATH.'program'.PATH_SEPARATOR.$INSTALL_PATH.'program/lib'.PATH_SEPARATOR.ini_get('include_path')); |
|---|
| 67 | |
|---|
| 68 | ini_set('session.name', 'sessid'); |
|---|
| 69 | ini_set('session.use_cookies', 1); |
|---|
| 70 | ini_set('session.gc_maxlifetime', 21600); |
|---|
| 71 | ini_set('session.gc_divisor', 500); |
|---|
| 72 | ini_set('error_reporting', E_ALL&~E_NOTICE); |
|---|
| 73 | |
|---|
| 74 | // increase maximum execution time for php scripts |
|---|
| 75 | // (does not work in safe mode) |
|---|
| 76 | @set_time_limit(120); |
|---|
| 77 | |
|---|
| 78 | // include base files |
|---|
| 79 | require_once('include/rcube_shared.inc'); |
|---|
| 80 | require_once('include/rcube_imap.inc'); |
|---|
| 81 | require_once('include/bugs.inc'); |
|---|
| 82 | require_once('include/main.inc'); |
|---|
| 83 | require_once('include/cache.inc'); |
|---|
| 84 | require_once('lib/html2text.inc'); |
|---|
| 85 | require_once('PEAR.php'); |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | // set PEAR error handling |
|---|
| 89 | // PEAR::setErrorHandling(PEAR_ERROR_TRIGGER, E_USER_NOTICE); |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | // catch some url/post parameters |
|---|
| 93 | $_task = strip_quotes(get_input_value('_task', RCUBE_INPUT_GPC)); |
|---|
| 94 | $_action = strip_quotes(get_input_value('_action', RCUBE_INPUT_GPC)); |
|---|
| 95 | $_framed = (!empty($_GET['_framed']) || !empty($_POST['_framed'])); |
|---|
| 96 | |
|---|
| 97 | // use main task if empty or invalid value |
|---|
| 98 | if (empty($_task) || !in_array($_task, $MAIN_TASKS)) |
|---|
| 99 | $_task = 'mail'; |
|---|
| 100 | |
|---|
| 101 | if (!empty($_GET['_remote'])) |
|---|
| 102 | $REMOTE_REQUEST = TRUE; |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | // set output buffering |
|---|
| 106 | if ($_action != 'get' && $_action != 'viewsource') |
|---|
| 107 | { |
|---|
| 108 | // use gzip compression if supported |
|---|
| 109 | if (function_exists('ob_gzhandler') && ini_get('zlib.output_compression')) |
|---|
| 110 | ob_start('ob_gzhandler'); |
|---|
| 111 | else |
|---|
| 112 | ob_start(); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | // start session with requested task |
|---|
| 117 | rcmail_startup($_task); |
|---|
| 118 | |
|---|
| 119 | // set session related variables |
|---|
| 120 | $COMM_PATH = sprintf('./?_task=%s', $_task); |
|---|
| 121 | $SESS_HIDDEN_FIELD = ''; |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | // add framed parameter |
|---|
| 125 | if ($_framed) |
|---|
| 126 | { |
|---|
| 127 | $COMM_PATH .= '&_framed=1'; |
|---|
| 128 | $SESS_HIDDEN_FIELD .= "\n".'<input type="hidden" name="_framed" value="1" />'; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | // init necessary objects for GUI |
|---|
| 133 | load_gui(); |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | // check DB connections and exit on failure |
|---|
| 137 | if ($err_str = $DB->is_error()) |
|---|
| 138 | { |
|---|
| 139 | raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__, |
|---|
| 140 | 'message' => $err_str), FALSE, TRUE); |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | // error steps |
|---|
| 145 | if ($_action=='error' && !empty($_GET['_code'])) |
|---|
| 146 | { |
|---|
| 147 | raise_error(array('code' => hexdec($_GET['_code'])), FALSE, TRUE); |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | // handle HTML->text conversion |
|---|
| 151 | if ($_action=='html2text') |
|---|
| 152 | { |
|---|
| 153 | $htmlText = $HTTP_RAW_POST_DATA; |
|---|
| 154 | $converter = new html2text($htmlText); |
|---|
| 155 | |
|---|
| 156 | // TODO possibly replace with rcube_remote_response() |
|---|
| 157 | header('Content-Type: text/plain'); |
|---|
| 158 | $plaintext = $converter->get_text(); |
|---|
| 159 | print $plaintext; |
|---|
| 160 | |
|---|
| 161 | exit; |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | // try to log in |
|---|
| 166 | if ($_action=='login' && $_task=='mail') |
|---|
| 167 | { |
|---|
| 168 | $host = rcmail_autoselect_host(); |
|---|
| 169 | |
|---|
| 170 | // check if client supports cookies |
|---|
| 171 | if (empty($_COOKIE)) |
|---|
| 172 | { |
|---|
| 173 | show_message("cookiesdisabled", 'warning'); |
|---|
| 174 | } |
|---|
| 175 | else if (isset($_POST['_user']) && isset($_POST['_pass']) && |
|---|
| 176 | rcmail_login(get_input_value('_user', RCUBE_INPUT_POST), |
|---|
| 177 | get_input_value('_pass', RCUBE_INPUT_POST, true, 'ISO-8859-1'), $host)) |
|---|
| 178 | { |
|---|
| 179 | // send redirect |
|---|
| 180 | header("Location: $COMM_PATH"); |
|---|
| 181 | exit; |
|---|
| 182 | } |
|---|
| 183 | else |
|---|
| 184 | { |
|---|
| 185 | show_message("loginfailed", 'warning'); |
|---|
| 186 | $_SESSION['user_id'] = ''; |
|---|
| 187 | } |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | // end session |
|---|
| 191 | else if ($_action=='logout' && isset($_SESSION['user_id'])) |
|---|
| 192 | { |
|---|
| 193 | show_message('loggedout'); |
|---|
| 194 | rcmail_kill_session(); |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | // check session and auth cookie |
|---|
| 198 | else if ($_action!='login' && $_SESSION['user_id']) |
|---|
| 199 | { |
|---|
| 200 | if (!rcmail_authenticate_session() || |
|---|
| 201 | (!empty($CONFIG['session_lifetime']) && isset($SESS_CHANGED) && $SESS_CHANGED + $CONFIG['session_lifetime']*60 < mktime())) |
|---|
| 202 | { |
|---|
| 203 | $message = show_message('sessionerror', 'error'); |
|---|
| 204 | rcmail_kill_session(); |
|---|
| 205 | } |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | // log in to imap server |
|---|
| 210 | if (!empty($_SESSION['user_id']) && $_task=='mail') |
|---|
| 211 | { |
|---|
| 212 | $conn = $IMAP->connect($_SESSION['imap_host'], $_SESSION['username'], decrypt_passwd($_SESSION['password']), $_SESSION['imap_port'], $_SESSION['imap_ssl']); |
|---|
| 213 | if (!$conn) |
|---|
| 214 | { |
|---|
| 215 | show_message('imaperror', 'error'); |
|---|
| 216 | $_SESSION['user_id'] = ''; |
|---|
| 217 | } |
|---|
| 218 | else |
|---|
| 219 | rcmail_set_imap_prop(); |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | // not logged in -> set task to 'login |
|---|
| 224 | if (empty($_SESSION['user_id'])) |
|---|
| 225 | { |
|---|
| 226 | if ($REMOTE_REQUEST) |
|---|
| 227 | { |
|---|
| 228 | $message .= "setTimeout(\"location.href='\"+this.env.comm_path+\"'\", 2000);"; |
|---|
| 229 | rcube_remote_response($message); |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | $_task = 'login'; |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | // set task and action to client |
|---|
| 238 | $script = sprintf("%s.set_env('task', '%s');", $JS_OBJECT_NAME, $_task); |
|---|
| 239 | if (!empty($_action)) |
|---|
| 240 | $script .= sprintf("\n%s.set_env('action', '%s');", $JS_OBJECT_NAME, $_action); |
|---|
| 241 | |
|---|
| 242 | $OUTPUT->add_script($script); |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | // not logged in -> show login page |
|---|
| 247 | if (!$_SESSION['user_id']) |
|---|
| 248 | { |
|---|
| 249 | parse_template('login'); |
|---|
| 250 | exit; |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | // handle keep-alive signal |
|---|
| 255 | if ($_action=='keep-alive') |
|---|
| 256 | { |
|---|
| 257 | rcube_remote_response(''); |
|---|
| 258 | exit; |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | // include task specific files |
|---|
| 262 | if ($_task=='mail') |
|---|
| 263 | { |
|---|
| 264 | include_once('program/steps/mail/func.inc'); |
|---|
| 265 | |
|---|
| 266 | if ($_action=='show' || $_action=='preview' || $_action=='print') |
|---|
| 267 | include('program/steps/mail/show.inc'); |
|---|
| 268 | |
|---|
| 269 | if ($_action=='get') |
|---|
| 270 | include('program/steps/mail/get.inc'); |
|---|
| 271 | |
|---|
| 272 | if ($_action=='moveto' || $_action=='delete') |
|---|
| 273 | include('program/steps/mail/move_del.inc'); |
|---|
| 274 | |
|---|
| 275 | if ($_action=='mark') |
|---|
| 276 | include('program/steps/mail/mark.inc'); |
|---|
| 277 | |
|---|
| 278 | if ($_action=='viewsource') |
|---|
| 279 | include('program/steps/mail/viewsource.inc'); |
|---|
| 280 | |
|---|
| 281 | if ($_action=='send') |
|---|
| 282 | include('program/steps/mail/sendmail.inc'); |
|---|
| 283 | |
|---|
| 284 | if ($_action=='upload') |
|---|
| 285 | include('program/steps/mail/upload.inc'); |
|---|
| 286 | |
|---|
| 287 | if ($_action=='compose' || $_action=='remove-attachment') |
|---|
| 288 | include('program/steps/mail/compose.inc'); |
|---|
| 289 | |
|---|
| 290 | if ($_action=='addcontact') |
|---|
| 291 | include('program/steps/mail/addcontact.inc'); |
|---|
| 292 | |
|---|
| 293 | if ($_action=='expunge' || $_action=='purge') |
|---|
| 294 | include('program/steps/mail/folders.inc'); |
|---|
| 295 | |
|---|
| 296 | if ($_action=='check-recent') |
|---|
| 297 | include('program/steps/mail/check_recent.inc'); |
|---|
| 298 | |
|---|
| 299 | if ($_action=='getunread') |
|---|
| 300 | include('program/steps/mail/getunread.inc'); |
|---|
| 301 | |
|---|
| 302 | if ($_action=='list' && isset($_GET['_remote'])) |
|---|
| 303 | include('program/steps/mail/list.inc'); |
|---|
| 304 | |
|---|
| 305 | if ($_action=='search') |
|---|
| 306 | include('program/steps/mail/search.inc'); |
|---|
| 307 | |
|---|
| 308 | if ($_action=='spell') |
|---|
| 309 | include('program/steps/mail/spell.inc'); |
|---|
| 310 | |
|---|
| 311 | if ($_action=='rss') |
|---|
| 312 | include('program/steps/mail/rss.inc'); |
|---|
| 313 | |
|---|
| 314 | if ($_action=='quotaimg') |
|---|
| 315 | include('program/steps/mail/quotaimg.inc'); |
|---|
| 316 | |
|---|
| 317 | if ($_action=='quotadisplay') |
|---|
| 318 | include('program/steps/mail/quotadisplay.inc'); |
|---|
| 319 | |
|---|
| 320 | |
|---|
| 321 | // make sure the message count is refreshed |
|---|
| 322 | $IMAP->messagecount($_SESSION['mbox'], 'ALL', TRUE); |
|---|
| 323 | } |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | // include task specific files |
|---|
| 327 | if ($_task=='addressbook') |
|---|
| 328 | { |
|---|
| 329 | include_once('program/steps/addressbook/func.inc'); |
|---|
| 330 | |
|---|
| 331 | if ($_action=='save') |
|---|
| 332 | include('program/steps/addressbook/save.inc'); |
|---|
| 333 | |
|---|
| 334 | if ($_action=='edit' || $_action=='add') |
|---|
| 335 | include('program/steps/addressbook/edit.inc'); |
|---|
| 336 | |
|---|
| 337 | if ($_action=='delete') |
|---|
| 338 | include('program/steps/addressbook/delete.inc'); |
|---|
| 339 | |
|---|
| 340 | if ($_action=='show') |
|---|
| 341 | include('program/steps/addressbook/show.inc'); |
|---|
| 342 | |
|---|
| 343 | if ($_action=='list' && $_GET['_remote']) |
|---|
| 344 | include('program/steps/addressbook/list.inc'); |
|---|
| 345 | |
|---|
| 346 | if ($_action=='ldappublicsearch') |
|---|
| 347 | include('program/steps/addressbook/ldapsearchform.inc'); |
|---|
| 348 | } |
|---|
| 349 | |
|---|
| 350 | |
|---|
| 351 | // include task specific files |
|---|
| 352 | if ($_task=='settings') |
|---|
| 353 | { |
|---|
| 354 | include_once('program/steps/settings/func.inc'); |
|---|
| 355 | |
|---|
| 356 | if ($_action=='save-identity') |
|---|
| 357 | include('program/steps/settings/save_identity.inc'); |
|---|
| 358 | |
|---|
| 359 | if ($_action=='add-identity' || $_action=='edit-identity') |
|---|
| 360 | include('program/steps/settings/edit_identity.inc'); |
|---|
| 361 | |
|---|
| 362 | if ($_action=='delete-identity') |
|---|
| 363 | include('program/steps/settings/delete_identity.inc'); |
|---|
| 364 | |
|---|
| 365 | if ($_action=='identities') |
|---|
| 366 | include('program/steps/settings/identities.inc'); |
|---|
| 367 | |
|---|
| 368 | if ($_action=='save-prefs') |
|---|
| 369 | include('program/steps/settings/save_prefs.inc'); |
|---|
| 370 | |
|---|
| 371 | if ($_action=='folders' || $_action=='subscribe' || $_action=='unsubscribe' || |
|---|
| 372 | $_action=='create-folder' || $_action=='rename-folder' || $_action=='delete-folder') |
|---|
| 373 | include('program/steps/settings/manage_folders.inc'); |
|---|
| 374 | |
|---|
| 375 | } |
|---|
| 376 | |
|---|
| 377 | |
|---|
| 378 | // parse main template |
|---|
| 379 | parse_template($_task); |
|---|
| 380 | |
|---|
| 381 | |
|---|
| 382 | // if we arrive here, something went wrong |
|---|
| 383 | raise_error(array('code' => 404, |
|---|
| 384 | 'type' => 'php', |
|---|
| 385 | 'line' => __LINE__, |
|---|
| 386 | 'file' => __FILE__, |
|---|
| 387 | 'message' => "Invalid request"), TRUE, TRUE); |
|---|
| 388 | |
|---|
| 389 | ?> |
|---|