commit | author | age
|
4e17e6
|
1 |
<?php |
T |
2 |
/* |
|
3 |
+-----------------------------------------------------------------------+ |
|
4 |
| RoundCube Webmail IMAP Client | |
719a25
|
5 |
| Version 0.1-20070809 | |
4e17e6
|
6 |
| | |
ff52be
|
7 |
| Copyright (C) 2005-2007, RoundCube Dev. - Switzerland | |
15fee7
|
8 |
| Licensed under the GNU GPL | |
4e17e6
|
9 |
| | |
T |
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 |
*/ |
15a9d1
|
42 |
|
f11541
|
43 |
// application constants |
719a25
|
44 |
define('RCMAIL_VERSION', '0.1-20070809'); |
f11541
|
45 |
define('RCMAIL_CHARSET', 'UTF-8'); |
T |
46 |
define('JS_OBJECT_NAME', 'rcmail'); |
15a9d1
|
47 |
|
4e17e6
|
48 |
// define global vars |
T |
49 |
$OUTPUT_TYPE = 'html'; |
321302
|
50 |
$INSTALL_PATH = dirname(__FILE__); |
8c2e58
|
51 |
$MAIN_TASKS = array('mail','settings','addressbook','logout'); |
4e17e6
|
52 |
|
7cc38e
|
53 |
if (empty($INSTALL_PATH)) |
T |
54 |
$INSTALL_PATH = './'; |
|
55 |
else |
|
56 |
$INSTALL_PATH .= '/'; |
bac7d1
|
57 |
|
T |
58 |
|
|
59 |
// make sure path_separator is defined |
|
60 |
if (!defined('PATH_SEPARATOR')) |
|
61 |
define('PATH_SEPARATOR', (eregi('win', PHP_OS) ? ';' : ':')); |
|
62 |
|
|
63 |
|
d7cb77
|
64 |
// RC include folders MUST be included FIRST to avoid other |
S |
65 |
// possible not compatible libraries (i.e PEAR) to be included |
|
66 |
// instead the ones provided by RC |
7cc38e
|
67 |
ini_set('include_path', $INSTALL_PATH.PATH_SEPARATOR.$INSTALL_PATH.'program'.PATH_SEPARATOR.$INSTALL_PATH.'program/lib'.PATH_SEPARATOR.ini_get('include_path')); |
d7cb77
|
68 |
|
4e17e6
|
69 |
ini_set('session.name', 'sessid'); |
T |
70 |
ini_set('session.use_cookies', 1); |
977a29
|
71 |
ini_set('session.gc_maxlifetime', 21600); |
T |
72 |
ini_set('session.gc_divisor', 500); |
|
73 |
ini_set('error_reporting', E_ALL&~E_NOTICE); |
4e17e6
|
74 |
|
T |
75 |
// increase maximum execution time for php scripts |
00fd33
|
76 |
// (does not work in safe mode) |
024797
|
77 |
if (!ini_get('safe_mode')) @set_time_limit(120); |
4e17e6
|
78 |
|
T |
79 |
// include base files |
|
80 |
require_once('include/rcube_shared.inc'); |
|
81 |
require_once('include/rcube_imap.inc'); |
|
82 |
require_once('include/bugs.inc'); |
|
83 |
require_once('include/main.inc'); |
7902df
|
84 |
require_once('PEAR.php'); |
T |
85 |
|
|
86 |
|
|
87 |
// set PEAR error handling |
|
88 |
// PEAR::setErrorHandling(PEAR_ERROR_TRIGGER, E_USER_NOTICE); |
4e17e6
|
89 |
|
T |
90 |
|
|
91 |
// catch some url/post parameters |
e34ae1
|
92 |
$_task = strip_quotes(get_input_value('_task', RCUBE_INPUT_GPC)); |
T |
93 |
$_action = strip_quotes(get_input_value('_action', RCUBE_INPUT_GPC)); |
597170
|
94 |
$_framed = (!empty($_GET['_framed']) || !empty($_POST['_framed'])); |
42b113
|
95 |
|
e34ae1
|
96 |
// use main task if empty or invalid value |
T |
97 |
if (empty($_task) || !in_array($_task, $MAIN_TASKS)) |
03f855
|
98 |
$_task = 'mail'; |
T |
99 |
|
2f2f15
|
100 |
|
T |
101 |
// set output buffering |
|
102 |
if ($_action != 'get' && $_action != 'viewsource') |
f11541
|
103 |
{ |
2f2f15
|
104 |
// use gzip compression if supported |
ff52be
|
105 |
if (function_exists('ob_gzhandler') && ini_get('zlib.output_compression')) |
2f2f15
|
106 |
ob_start('ob_gzhandler'); |
T |
107 |
else |
|
108 |
ob_start(); |
f11541
|
109 |
} |
2f2f15
|
110 |
|
42b113
|
111 |
|
4e17e6
|
112 |
// start session with requested task |
T |
113 |
rcmail_startup($_task); |
|
114 |
|
|
115 |
// set session related variables |
bac7d1
|
116 |
$COMM_PATH = sprintf('./?_task=%s', $_task); |
T |
117 |
$SESS_HIDDEN_FIELD = ''; |
4e17e6
|
118 |
|
T |
119 |
|
|
120 |
// add framed parameter |
597170
|
121 |
if ($_framed) |
f11541
|
122 |
{ |
T |
123 |
$COMM_PATH .= '&_framed=1'; |
ccfda8
|
124 |
$SESS_HIDDEN_FIELD .= "\n".'<input type="hidden" name="_framed" value="1" />'; |
f11541
|
125 |
} |
4e17e6
|
126 |
|
T |
127 |
|
|
128 |
// init necessary objects for GUI |
f11541
|
129 |
rcmail_load_gui(); |
4e17e6
|
130 |
|
8affba
|
131 |
|
T |
132 |
// check DB connections and exit on failure |
|
133 |
if ($err_str = $DB->is_error()) |
f11541
|
134 |
{ |
T |
135 |
raise_error(array( |
|
136 |
'code' => 603, |
|
137 |
'type' => 'db', |
|
138 |
'message' => $err_str), FALSE, TRUE); |
|
139 |
} |
8affba
|
140 |
|
T |
141 |
|
4e17e6
|
142 |
// error steps |
597170
|
143 |
if ($_action=='error' && !empty($_GET['_code'])) |
4e17e6
|
144 |
raise_error(array('code' => hexdec($_GET['_code'])), FALSE, TRUE); |
570f0b
|
145 |
|
S |
146 |
|
4e17e6
|
147 |
// try to log in |
T |
148 |
if ($_action=='login' && $_task=='mail') |
f11541
|
149 |
{ |
0a020c
|
150 |
$host = rcmail_autoselect_host(); |
4e17e6
|
151 |
|
T |
152 |
// check if client supports cookies |
597170
|
153 |
if (empty($_COOKIE)) |
f11541
|
154 |
{ |
T |
155 |
$OUTPUT->show_message("cookiesdisabled", 'warning'); |
|
156 |
} |
f15c26
|
157 |
else if ($_SESSION['temp'] && !empty($_POST['_user']) && isset($_POST['_pass']) && |
0a020c
|
158 |
rcmail_login(get_input_value('_user', RCUBE_INPUT_POST), |
T |
159 |
get_input_value('_pass', RCUBE_INPUT_POST, true, 'ISO-8859-1'), $host)) |
f11541
|
160 |
{ |
aad6e2
|
161 |
// create new session ID |
T |
162 |
unset($_SESSION['temp']); |
|
163 |
sess_regenerate_id(); |
|
164 |
|
|
165 |
// send auth cookie if necessary |
|
166 |
rcmail_authenticate_session(); |
|
167 |
|
4e17e6
|
168 |
// send redirect |
T |
169 |
header("Location: $COMM_PATH"); |
|
170 |
exit; |
|
171 |
} |
f11541
|
172 |
else |
T |
173 |
{ |
|
174 |
$OUTPUT->show_message("loginfailed", 'warning'); |
|
175 |
$_SESSION['user_id'] = ''; |
|
176 |
} |
|
177 |
} |
4e17e6
|
178 |
|
T |
179 |
// end session |
f11541
|
180 |
else if (($_task=='logout' || $_action=='logout') && isset($_SESSION['user_id'])) |
T |
181 |
{ |
|
182 |
$OUTPUT->show_message('loggedout'); |
4e17e6
|
183 |
rcmail_kill_session(); |
f11541
|
184 |
} |
4e17e6
|
185 |
|
bac7d1
|
186 |
// check session and auth cookie |
86958f
|
187 |
else if ($_action != 'login' && $_SESSION['user_id'] && $_action != 'send') |
f11541
|
188 |
{ |
aad6e2
|
189 |
if (!rcmail_authenticate_session()) |
f11541
|
190 |
{ |
T |
191 |
$OUTPUT->show_message('sessionerror', 'error'); |
4e17e6
|
192 |
rcmail_kill_session(); |
T |
193 |
} |
f11541
|
194 |
} |
4e17e6
|
195 |
|
T |
196 |
|
|
197 |
// log in to imap server |
597170
|
198 |
if (!empty($_SESSION['user_id']) && $_task=='mail') |
f11541
|
199 |
{ |
7902df
|
200 |
$conn = $IMAP->connect($_SESSION['imap_host'], $_SESSION['username'], decrypt_passwd($_SESSION['password']), $_SESSION['imap_port'], $_SESSION['imap_ssl']); |
4e17e6
|
201 |
if (!$conn) |
f11541
|
202 |
{ |
T |
203 |
$OUTPUT->show_message('imaperror', 'error'); |
4e17e6
|
204 |
$_SESSION['user_id'] = ''; |
f11541
|
205 |
} |
7902df
|
206 |
else |
T |
207 |
rcmail_set_imap_prop(); |
f11541
|
208 |
} |
4e17e6
|
209 |
|
T |
210 |
|
|
211 |
// not logged in -> set task to 'login |
597170
|
212 |
if (empty($_SESSION['user_id'])) |
f11541
|
213 |
{ |
T |
214 |
if ($OUTPUT->ajax_call) |
|
215 |
$OUTPUT->remote_response("setTimeout(\"location.href='\"+this.env.comm_path+\"'\", 2000);"); |
42b113
|
216 |
|
4e17e6
|
217 |
$_task = 'login'; |
f11541
|
218 |
} |
4e17e6
|
219 |
|
T |
220 |
|
719a25
|
221 |
// check client X-header to verify request origin |
T |
222 |
if ($OUTPUT->ajax_call) |
|
223 |
{ |
88f66e
|
224 |
if (empty($CONFIG['devel_mode']) && !rc_request_header('X-RoundCube-Referer')) |
719a25
|
225 |
{ |
T |
226 |
header('HTTP/1.1 404 Not Found'); |
|
227 |
die("Invalid Request"); |
|
228 |
} |
|
229 |
} |
|
230 |
|
4e17e6
|
231 |
|
597170
|
232 |
// set task and action to client |
f11541
|
233 |
$OUTPUT->set_env('task', $_task); |
4e17e6
|
234 |
if (!empty($_action)) |
f11541
|
235 |
$OUTPUT->set_env('action', $_action); |
4e17e6
|
236 |
|
T |
237 |
|
|
238 |
|
|
239 |
// not logged in -> show login page |
|
240 |
if (!$_SESSION['user_id']) |
f11541
|
241 |
{ |
T |
242 |
$OUTPUT->task = 'login'; |
|
243 |
$OUTPUT->send('login'); |
4e17e6
|
244 |
exit; |
f11541
|
245 |
} |
4e17e6
|
246 |
|
T |
247 |
|
1cded8
|
248 |
// handle keep-alive signal |
T |
249 |
if ($_action=='keep-alive') |
f11541
|
250 |
{ |
T |
251 |
$OUTPUT->reset(); |
|
252 |
$OUTPUT->send(''); |
1cded8
|
253 |
exit; |
f11541
|
254 |
} |
4e17e6
|
255 |
|
T |
256 |
// include task specific files |
|
257 |
if ($_task=='mail') |
f11541
|
258 |
{ |
4e17e6
|
259 |
include_once('program/steps/mail/func.inc'); |
88375f
|
260 |
|
b19097
|
261 |
if ($_action=='show' || $_action=='preview' || $_action=='print') |
4e17e6
|
262 |
include('program/steps/mail/show.inc'); |
T |
263 |
|
|
264 |
if ($_action=='get') |
|
265 |
include('program/steps/mail/get.inc'); |
|
266 |
|
|
267 |
if ($_action=='moveto' || $_action=='delete') |
|
268 |
include('program/steps/mail/move_del.inc'); |
|
269 |
|
|
270 |
if ($_action=='mark') |
|
271 |
include('program/steps/mail/mark.inc'); |
|
272 |
|
|
273 |
if ($_action=='viewsource') |
|
274 |
include('program/steps/mail/viewsource.inc'); |
|
275 |
|
|
276 |
if ($_action=='send') |
|
277 |
include('program/steps/mail/sendmail.inc'); |
|
278 |
|
|
279 |
if ($_action=='upload') |
|
280 |
include('program/steps/mail/upload.inc'); |
|
281 |
|
a894ba
|
282 |
if ($_action=='compose' || $_action=='remove-attachment') |
4e17e6
|
283 |
include('program/steps/mail/compose.inc'); |
T |
284 |
|
|
285 |
if ($_action=='addcontact') |
|
286 |
include('program/steps/mail/addcontact.inc'); |
15a9d1
|
287 |
|
5e3512
|
288 |
if ($_action=='expunge' || $_action=='purge') |
15a9d1
|
289 |
include('program/steps/mail/folders.inc'); |
T |
290 |
|
|
291 |
if ($_action=='check-recent') |
|
292 |
include('program/steps/mail/check_recent.inc'); |
|
293 |
|
|
294 |
if ($_action=='getunread') |
|
295 |
include('program/steps/mail/getunread.inc'); |
4e17e6
|
296 |
|
8d0758
|
297 |
if ($_action=='list' && isset($_REQUEST['_remote'])) |
4e17e6
|
298 |
include('program/steps/mail/list.inc'); |
T |
299 |
|
4647e1
|
300 |
if ($_action=='search') |
dd53e2
|
301 |
include('program/steps/mail/search.inc'); |
T |
302 |
|
|
303 |
if ($_action=='spell') |
|
304 |
include('program/steps/mail/spell.inc'); |
4647e1
|
305 |
|
88375f
|
306 |
if ($_action=='rss') |
T |
307 |
include('program/steps/mail/rss.inc'); |
3ea0e3
|
308 |
|
23796e
|
309 |
if ($_action=='quotadisplay') |
S |
310 |
include('program/steps/mail/quotadisplay.inc'); |
|
311 |
|
aade7b
|
312 |
|
01c86f
|
313 |
// make sure the message count is refreshed |
T |
314 |
$IMAP->messagecount($_SESSION['mbox'], 'ALL', TRUE); |
f11541
|
315 |
} |
4e17e6
|
316 |
|
T |
317 |
|
|
318 |
// include task specific files |
|
319 |
if ($_task=='addressbook') |
f11541
|
320 |
{ |
4e17e6
|
321 |
include_once('program/steps/addressbook/func.inc'); |
T |
322 |
|
|
323 |
if ($_action=='save') |
|
324 |
include('program/steps/addressbook/save.inc'); |
|
325 |
|
|
326 |
if ($_action=='edit' || $_action=='add') |
|
327 |
include('program/steps/addressbook/edit.inc'); |
|
328 |
|
|
329 |
if ($_action=='delete') |
|
330 |
include('program/steps/addressbook/delete.inc'); |
|
331 |
|
|
332 |
if ($_action=='show') |
|
333 |
include('program/steps/addressbook/show.inc'); |
|
334 |
|
8d0758
|
335 |
if ($_action=='list' && $_REQUEST['_remote']) |
4e17e6
|
336 |
include('program/steps/addressbook/list.inc'); |
d1d2c4
|
337 |
|
f11541
|
338 |
if ($_action=='search') |
T |
339 |
include('program/steps/addressbook/search.inc'); |
|
340 |
|
|
341 |
if ($_action=='copy') |
|
342 |
include('program/steps/addressbook/copy.inc'); |
|
343 |
|
|
344 |
if ($_action=='mailto') |
|
345 |
include('program/steps/addressbook/mailto.inc'); |
|
346 |
} |
4e17e6
|
347 |
|
T |
348 |
|
|
349 |
// include task specific files |
|
350 |
if ($_task=='settings') |
f11541
|
351 |
{ |
4e17e6
|
352 |
include_once('program/steps/settings/func.inc'); |
T |
353 |
|
|
354 |
if ($_action=='save-identity') |
|
355 |
include('program/steps/settings/save_identity.inc'); |
|
356 |
|
|
357 |
if ($_action=='add-identity' || $_action=='edit-identity') |
|
358 |
include('program/steps/settings/edit_identity.inc'); |
|
359 |
|
|
360 |
if ($_action=='delete-identity') |
|
361 |
include('program/steps/settings/delete_identity.inc'); |
|
362 |
|
|
363 |
if ($_action=='identities') |
|
364 |
include('program/steps/settings/identities.inc'); |
|
365 |
|
|
366 |
if ($_action=='save-prefs') |
|
367 |
include('program/steps/settings/save_prefs.inc'); |
|
368 |
|
aade7b
|
369 |
if ($_action=='folders' || $_action=='subscribe' || $_action=='unsubscribe' || |
T |
370 |
$_action=='create-folder' || $_action=='rename-folder' || $_action=='delete-folder') |
4e17e6
|
371 |
include('program/steps/settings/manage_folders.inc'); |
T |
372 |
|
f11541
|
373 |
} |
ecf759
|
374 |
|
T |
375 |
|
539cd4
|
376 |
// parse main template |
f11541
|
377 |
$OUTPUT->send($_task); |
539cd4
|
378 |
|
T |
379 |
|
|
380 |
// if we arrive here, something went wrong |
f11541
|
381 |
raise_error(array( |
T |
382 |
'code' => 404, |
|
383 |
'type' => 'php', |
|
384 |
'line' => __LINE__, |
|
385 |
'file' => __FILE__, |
|
386 |
'message' => "Invalid request"), TRUE, TRUE); |
539cd4
|
387 |
|
d1d2c4
|
388 |
?> |