| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* |
|---|
| 4 | +-----------------------------------------------------------------------+ |
|---|
| 5 | | RoundCube Webmail IMAP Client | |
|---|
| 6 | | Version 0.1-20051007 | |
|---|
| 7 | | | |
|---|
| 8 | | Copyright (C) 2005, RoundCube Dev. - Switzerland | |
|---|
| 9 | | Licensed under the GNU GPL | |
|---|
| 10 | | | |
|---|
| 11 | | Redistribution and use in source and binary forms, with or without | |
|---|
| 12 | | modification, are permitted provided that the following conditions | |
|---|
| 13 | | are met: | |
|---|
| 14 | | | |
|---|
| 15 | | o Redistributions of source code must retain the above copyright | |
|---|
| 16 | | notice, this list of conditions and the following disclaimer. | |
|---|
| 17 | | o Redistributions in binary form must reproduce the above copyright | |
|---|
| 18 | | notice, this list of conditions and the following disclaimer in the | |
|---|
| 19 | | documentation and/or other materials provided with the distribution.| |
|---|
| 20 | | o The names of the authors may not be used to endorse or promote | |
|---|
| 21 | | products derived from this software without specific prior written | |
|---|
| 22 | | permission. | |
|---|
| 23 | | | |
|---|
| 24 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
|---|
| 25 | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
|---|
| 26 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
|---|
| 27 | | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
|---|
| 28 | | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
|---|
| 29 | | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
|---|
| 30 | | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
|---|
| 31 | | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
|---|
| 32 | | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
|---|
| 33 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
|---|
| 34 | | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
|---|
| 35 | | | |
|---|
| 36 | +-----------------------------------------------------------------------+ |
|---|
| 37 | | Author: Thomas Bruederli <roundcube@gmail.com> | |
|---|
| 38 | +-----------------------------------------------------------------------+ |
|---|
| 39 | |
|---|
| 40 | $Id$ |
|---|
| 41 | |
|---|
| 42 | */ |
|---|
| 43 | |
|---|
| 44 | // define global vars |
|---|
| 45 | $INSTALL_PATH = './'; |
|---|
| 46 | $OUTPUT_TYPE = 'html'; |
|---|
| 47 | $JS_OBJECT_NAME = 'rcmail'; |
|---|
| 48 | $CURRENT_PATH=dirname($_SERVER['SCRIPT_FILENAME']); |
|---|
| 49 | |
|---|
| 50 | if ($CURRENT_PATH!='') |
|---|
| 51 | $CURRENT_PATH.='/'; |
|---|
| 52 | |
|---|
| 53 | // set environment first |
|---|
| 54 | ini_set('include_path', $INSTALL_PATH.PATH_SEPARATOR.$CURRENT_PATH.'program'.PATH_SEPARATOR.$CURRENT_PATH.'program/lib'.PATH_SEPARATOR.ini_get('include_path')); |
|---|
| 55 | ini_set('session.name', 'sessid'); |
|---|
| 56 | ini_set('session.use_cookies', 1); |
|---|
| 57 | ini_set('error_reporting', E_ALL&~E_NOTICE); |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | // increase maximum execution time for php scripts |
|---|
| 61 | // (does not work in safe mode) |
|---|
| 62 | @set_time_limit('120'); |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | // include base files |
|---|
| 66 | require_once('include/rcube_shared.inc'); |
|---|
| 67 | require_once('include/rcube_imap.inc'); |
|---|
| 68 | require_once('include/bugs.inc'); |
|---|
| 69 | require_once('include/main.inc'); |
|---|
| 70 | require_once('include/cache.inc'); |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | // catch some url/post parameters |
|---|
| 74 | $_auth = !empty($_POST['_auth']) ? $_POST['_auth'] : $_GET['_auth']; |
|---|
| 75 | $_task = !empty($_POST['_task']) ? $_POST['_task'] : (!empty($_GET['_task']) ? $_GET['_task'] : 'mail'); |
|---|
| 76 | $_action = !empty($_POST['_action']) ? $_POST['_action'] : (!empty($_GET['_action']) ? $_GET['_action'] : ''); |
|---|
| 77 | $_framed = (!empty($_GET['_framed']) || !empty($_POST['_framed'])); |
|---|
| 78 | |
|---|
| 79 | if (!empty($_GET['_remote'])) |
|---|
| 80 | $REMOTE_REQUEST = TRUE; |
|---|
| 81 | |
|---|
| 82 | // start session with requested task |
|---|
| 83 | rcmail_startup($_task); |
|---|
| 84 | |
|---|
| 85 | // set session related variables |
|---|
| 86 | $COMM_PATH = sprintf('./?_auth=%s&_task=%s', $sess_auth, $_task); |
|---|
| 87 | $SESS_HIDDEN_FIELD = sprintf('<input type="hidden" name="_auth" value="%s" />', $sess_auth); |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | // add framed parameter |
|---|
| 91 | if ($_framed) |
|---|
| 92 | { |
|---|
| 93 | $COMM_PATH .= '&_framed=1'; |
|---|
| 94 | $SESS_HIDDEN_FIELD = "\n".'<input type="hidden" name="_framed" value="1" />'; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | // init necessary objects for GUI |
|---|
| 99 | load_gui(); |
|---|
| 100 | |
|---|
| 101 | // error steps |
|---|
| 102 | if ($_action=='error' && !empty($_GET['_code'])) |
|---|
| 103 | { |
|---|
| 104 | raise_error(array('code' => hexdec($_GET['_code'])), FALSE, TRUE); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | // try to log in |
|---|
| 109 | if ($_action=='login' && $_task=='mail') |
|---|
| 110 | { |
|---|
| 111 | $host = $_POST['_host'] ? $_POST['_host'] : $CONFIG['default_host']; |
|---|
| 112 | |
|---|
| 113 | // check if client supports cookies |
|---|
| 114 | if (empty($_COOKIE)) |
|---|
| 115 | { |
|---|
| 116 | show_message("cookiesdisabled", 'warning'); |
|---|
| 117 | } |
|---|
| 118 | else if (isset($_POST['_user']) && isset($_POST['_pass']) && rcmail_login($_POST['_user'], $_POST['_pass'], $host)) |
|---|
| 119 | { |
|---|
| 120 | // send redirect |
|---|
| 121 | header("Location: $COMM_PATH"); |
|---|
| 122 | exit; |
|---|
| 123 | } |
|---|
| 124 | else |
|---|
| 125 | { |
|---|
| 126 | show_message("loginfailed", 'warning'); |
|---|
| 127 | $_SESSION['user_id'] = ''; |
|---|
| 128 | } |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | // end session |
|---|
| 132 | else if ($_action=='logout' && isset($_SESSION['user_id'])) |
|---|
| 133 | { |
|---|
| 134 | show_message('loggedout'); |
|---|
| 135 | rcmail_kill_session(); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | // check session cookie and auth string |
|---|
| 139 | else if ($_action!='login' && $_auth && $sess_auth) |
|---|
| 140 | { |
|---|
| 141 | if ($_auth !== $sess_auth || $_auth != rcmail_auth_hash($_SESSION['client_id'], $_SESSION['auth_time'])) |
|---|
| 142 | { |
|---|
| 143 | $message = show_message('sessionerror', 'error'); |
|---|
| 144 | rcmail_kill_session(); |
|---|
| 145 | } |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | // log in to imap server |
|---|
| 150 | if (!empty($_SESSION['user_id']) && $_task=='mail') |
|---|
| 151 | { |
|---|
| 152 | $conn = $IMAP->connect($_SESSION['imap_host'], $_SESSION['username'], decrypt_passwd($_SESSION['password'])); |
|---|
| 153 | if (!$conn) |
|---|
| 154 | { |
|---|
| 155 | show_message('imaperror', 'error'); |
|---|
| 156 | $_SESSION['user_id'] = ''; |
|---|
| 157 | } |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | // not logged in -> set task to 'login |
|---|
| 162 | if (empty($_SESSION['user_id'])) |
|---|
| 163 | { |
|---|
| 164 | if ($REMOTE_REQUEST) |
|---|
| 165 | { |
|---|
| 166 | $message .= "setTimeout(\"location.href='\"+this.env.comm_path+\"'\", 2000);"; |
|---|
| 167 | rcube_remote_response($message); |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | $_task = 'login'; |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | // set task and action to client |
|---|
| 176 | $script = sprintf("%s.set_env('task', '%s');", $JS_OBJECT_NAME, $_task); |
|---|
| 177 | if (!empty($_action)) |
|---|
| 178 | $script .= sprintf("\n%s.set_env('action', '%s');", $JS_OBJECT_NAME, $_action); |
|---|
| 179 | |
|---|
| 180 | $OUTPUT->add_script($script); |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | // not logged in -> show login page |
|---|
| 185 | if (!$_SESSION['user_id']) |
|---|
| 186 | { |
|---|
| 187 | parse_template('login'); |
|---|
| 188 | exit; |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | // include task specific files |
|---|
| 194 | if ($_task=='mail') |
|---|
| 195 | { |
|---|
| 196 | include_once('program/steps/mail/func.inc'); |
|---|
| 197 | |
|---|
| 198 | if ($_action=='show' || $_action=='print') |
|---|
| 199 | include('program/steps/mail/show.inc'); |
|---|
| 200 | |
|---|
| 201 | if ($_action=='get') |
|---|
| 202 | include('program/steps/mail/get.inc'); |
|---|
| 203 | |
|---|
| 204 | if ($_action=='moveto' || $_action=='delete') |
|---|
| 205 | include('program/steps/mail/move_del.inc'); |
|---|
| 206 | |
|---|
| 207 | if ($_action=='mark') |
|---|
| 208 | include('program/steps/mail/mark.inc'); |
|---|
| 209 | |
|---|
| 210 | if ($_action=='viewsource') |
|---|
| 211 | include('program/steps/mail/viewsource.inc'); |
|---|
| 212 | |
|---|
| 213 | if ($_action=='send') |
|---|
| 214 | include('program/steps/mail/sendmail.inc'); |
|---|
| 215 | |
|---|
| 216 | if ($_action=='upload') |
|---|
| 217 | include('program/steps/mail/upload.inc'); |
|---|
| 218 | |
|---|
| 219 | if ($_action=='compose') |
|---|
| 220 | include('program/steps/mail/compose.inc'); |
|---|
| 221 | |
|---|
| 222 | if ($_action=='addcontact') |
|---|
| 223 | include('program/steps/mail/addcontact.inc'); |
|---|
| 224 | |
|---|
| 225 | if ($_action=='list' && $_GET['_remote']) |
|---|
| 226 | include('program/steps/mail/list.inc'); |
|---|
| 227 | |
|---|
| 228 | // kill compose entry from session |
|---|
| 229 | if (isset($_SESSION['compose'])) |
|---|
| 230 | rcmail_compose_cleanup(); |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | // include task specific files |
|---|
| 235 | if ($_task=='addressbook') |
|---|
| 236 | { |
|---|
| 237 | include_once('program/steps/addressbook/func.inc'); |
|---|
| 238 | |
|---|
| 239 | if ($_action=='save') |
|---|
| 240 | include('program/steps/addressbook/save.inc'); |
|---|
| 241 | |
|---|
| 242 | if ($_action=='edit' || $_action=='add') |
|---|
| 243 | include('program/steps/addressbook/edit.inc'); |
|---|
| 244 | |
|---|
| 245 | if ($_action=='delete') |
|---|
| 246 | include('program/steps/addressbook/delete.inc'); |
|---|
| 247 | |
|---|
| 248 | if ($_action=='show') |
|---|
| 249 | include('program/steps/addressbook/show.inc'); |
|---|
| 250 | |
|---|
| 251 | if ($_action=='list' && $_GET['_remote']) |
|---|
| 252 | include('program/steps/addressbook/list.inc'); |
|---|
| 253 | } |
|---|
| 254 | |
|---|
| 255 | |
|---|
| 256 | // include task specific files |
|---|
| 257 | if ($_task=='settings') |
|---|
| 258 | { |
|---|
| 259 | include_once('program/steps/settings/func.inc'); |
|---|
| 260 | |
|---|
| 261 | if ($_action=='save-identity') |
|---|
| 262 | include('program/steps/settings/save_identity.inc'); |
|---|
| 263 | |
|---|
| 264 | if ($_action=='add-identity' || $_action=='edit-identity') |
|---|
| 265 | include('program/steps/settings/edit_identity.inc'); |
|---|
| 266 | |
|---|
| 267 | if ($_action=='delete-identity') |
|---|
| 268 | include('program/steps/settings/delete_identity.inc'); |
|---|
| 269 | |
|---|
| 270 | if ($_action=='identities') |
|---|
| 271 | include('program/steps/settings/identities.inc'); |
|---|
| 272 | |
|---|
| 273 | if ($_action=='save-prefs') |
|---|
| 274 | include('program/steps/settings/save_prefs.inc'); |
|---|
| 275 | |
|---|
| 276 | if ($_action=='folders' || $_action=='subscribe' || $_action=='unsubscribe' || $_action=='create-folder' || $_action=='delete-folder') |
|---|
| 277 | include('program/steps/settings/manage_folders.inc'); |
|---|
| 278 | |
|---|
| 279 | } |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | // only allow these templates to be included |
|---|
| 283 | $valid_tasks = array('mail','settings','addressbook'); |
|---|
| 284 | |
|---|
| 285 | // parse main template |
|---|
| 286 | if (in_array($_task, $valid_tasks)) |
|---|
| 287 | parse_template($_task); |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | // if we arrive here, something went wrong |
|---|
| 291 | raise_error(array('code' => 404, |
|---|
| 292 | 'type' => 'php', |
|---|
| 293 | 'line' => __LINE__, |
|---|
| 294 | 'file' => __FILE__, |
|---|
| 295 | 'message' => "Invalid request"), TRUE, TRUE); |
|---|
| 296 | |
|---|
| 297 | ?> |
|---|