commit | author | age
|
4e17e6
|
1 |
<?php |
T |
2 |
/* |
|
3 |
+-----------------------------------------------------------------------+ |
|
4 |
| RoundCube Webmail IMAP Client | |
15a9d1
|
5 |
| Version 0.1-20060104 | |
4e17e6
|
6 |
| | |
T |
7 |
| Copyright (C) 2005, 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 |
|
T |
43 |
define('RCMAIL_VERSION', '0.1-20060104'); |
|
44 |
|
4e17e6
|
45 |
|
T |
46 |
// define global vars |
7cc38e
|
47 |
$INSTALL_PATH = dirname($_SERVER['SCRIPT_FILENAME']); |
4e17e6
|
48 |
$OUTPUT_TYPE = 'html'; |
T |
49 |
$JS_OBJECT_NAME = 'rcmail'; |
d2006d
|
50 |
$CHARSET = 'UTF-8'; |
4e17e6
|
51 |
|
7cc38e
|
52 |
if (empty($INSTALL_PATH)) |
T |
53 |
$INSTALL_PATH = './'; |
|
54 |
else |
|
55 |
$INSTALL_PATH .= '/'; |
5abfcc
|
56 |
|
d7cb77
|
57 |
// RC include folders MUST be included FIRST to avoid other |
S |
58 |
// possible not compatible libraries (i.e PEAR) to be included |
|
59 |
// instead the ones provided by RC |
7cc38e
|
60 |
ini_set('include_path', $INSTALL_PATH.PATH_SEPARATOR.$INSTALL_PATH.'program'.PATH_SEPARATOR.$INSTALL_PATH.'program/lib'.PATH_SEPARATOR.ini_get('include_path')); |
d7cb77
|
61 |
|
4e17e6
|
62 |
ini_set('session.name', 'sessid'); |
T |
63 |
ini_set('session.use_cookies', 1); |
977a29
|
64 |
ini_set('session.gc_maxlifetime', 21600); |
T |
65 |
ini_set('session.gc_divisor', 500); |
58e360
|
66 |
ini_set('magic_quotes_gpc', 0); |
977a29
|
67 |
ini_set('error_reporting', E_ALL&~E_NOTICE); |
4e17e6
|
68 |
|
T |
69 |
// increase maximum execution time for php scripts |
00fd33
|
70 |
// (does not work in safe mode) |
1cded8
|
71 |
@set_time_limit(120); |
4e17e6
|
72 |
|
T |
73 |
// include base files |
|
74 |
require_once('include/rcube_shared.inc'); |
|
75 |
require_once('include/rcube_imap.inc'); |
|
76 |
require_once('include/bugs.inc'); |
|
77 |
require_once('include/main.inc'); |
|
78 |
require_once('include/cache.inc'); |
7902df
|
79 |
require_once('PEAR.php'); |
T |
80 |
|
|
81 |
|
|
82 |
// set PEAR error handling |
|
83 |
// PEAR::setErrorHandling(PEAR_ERROR_TRIGGER, E_USER_NOTICE); |
4e17e6
|
84 |
|
T |
85 |
|
|
86 |
// catch some url/post parameters |
597170
|
87 |
$_auth = !empty($_POST['_auth']) ? $_POST['_auth'] : $_GET['_auth']; |
T |
88 |
$_task = !empty($_POST['_task']) ? $_POST['_task'] : (!empty($_GET['_task']) ? $_GET['_task'] : 'mail'); |
|
89 |
$_action = !empty($_POST['_action']) ? $_POST['_action'] : (!empty($_GET['_action']) ? $_GET['_action'] : ''); |
|
90 |
$_framed = (!empty($_GET['_framed']) || !empty($_POST['_framed'])); |
42b113
|
91 |
|
T |
92 |
if (!empty($_GET['_remote'])) |
|
93 |
$REMOTE_REQUEST = TRUE; |
|
94 |
|
4e17e6
|
95 |
// start session with requested task |
T |
96 |
rcmail_startup($_task); |
|
97 |
|
|
98 |
// set session related variables |
|
99 |
$COMM_PATH = sprintf('./?_auth=%s&_task=%s', $sess_auth, $_task); |
|
100 |
$SESS_HIDDEN_FIELD = sprintf('<input type="hidden" name="_auth" value="%s" />', $sess_auth); |
|
101 |
|
|
102 |
|
|
103 |
// add framed parameter |
597170
|
104 |
if ($_framed) |
4e17e6
|
105 |
{ |
T |
106 |
$COMM_PATH .= '&_framed=1'; |
ccfda8
|
107 |
$SESS_HIDDEN_FIELD .= "\n".'<input type="hidden" name="_framed" value="1" />'; |
4e17e6
|
108 |
} |
T |
109 |
|
|
110 |
|
|
111 |
// init necessary objects for GUI |
|
112 |
load_gui(); |
|
113 |
|
|
114 |
// error steps |
597170
|
115 |
if ($_action=='error' && !empty($_GET['_code'])) |
4e17e6
|
116 |
{ |
T |
117 |
raise_error(array('code' => hexdec($_GET['_code'])), FALSE, TRUE); |
|
118 |
} |
|
119 |
|
|
120 |
|
|
121 |
// try to log in |
|
122 |
if ($_action=='login' && $_task=='mail') |
|
123 |
{ |
|
124 |
$host = $_POST['_host'] ? $_POST['_host'] : $CONFIG['default_host']; |
|
125 |
|
|
126 |
// check if client supports cookies |
597170
|
127 |
if (empty($_COOKIE)) |
4e17e6
|
128 |
{ |
T |
129 |
show_message("cookiesdisabled", 'warning'); |
|
130 |
} |
597170
|
131 |
else if (isset($_POST['_user']) && isset($_POST['_pass']) && rcmail_login($_POST['_user'], $_POST['_pass'], $host)) |
4e17e6
|
132 |
{ |
T |
133 |
// send redirect |
|
134 |
header("Location: $COMM_PATH"); |
|
135 |
exit; |
|
136 |
} |
|
137 |
else |
|
138 |
{ |
|
139 |
show_message("loginfailed", 'warning'); |
|
140 |
$_SESSION['user_id'] = ''; |
|
141 |
} |
|
142 |
} |
|
143 |
|
|
144 |
// end session |
00fd33
|
145 |
else if ($_action=='logout' && isset($_SESSION['user_id'])) |
4e17e6
|
146 |
{ |
T |
147 |
show_message('loggedout'); |
|
148 |
rcmail_kill_session(); |
|
149 |
} |
|
150 |
|
|
151 |
// check session cookie and auth string |
7cc38e
|
152 |
else if ($_action!='login' && $sess_auth && $_SESSION['user_id']) |
4e17e6
|
153 |
{ |
7902df
|
154 |
if ($_auth !== $sess_auth || $_auth != rcmail_auth_hash($_SESSION['client_id'], $_SESSION['auth_time']) || |
ccfda8
|
155 |
($CONFIG['session_lifetime'] && isset($SESS_CHANGED) && $SESS_CHANGED + $CONFIG['session_lifetime']*60 < mktime())) |
4e17e6
|
156 |
{ |
42b113
|
157 |
$message = show_message('sessionerror', 'error'); |
4e17e6
|
158 |
rcmail_kill_session(); |
T |
159 |
} |
|
160 |
} |
|
161 |
|
|
162 |
|
|
163 |
// log in to imap server |
597170
|
164 |
if (!empty($_SESSION['user_id']) && $_task=='mail') |
4e17e6
|
165 |
{ |
7902df
|
166 |
$conn = $IMAP->connect($_SESSION['imap_host'], $_SESSION['username'], decrypt_passwd($_SESSION['password']), $_SESSION['imap_port'], $_SESSION['imap_ssl']); |
4e17e6
|
167 |
if (!$conn) |
T |
168 |
{ |
|
169 |
show_message('imaperror', 'error'); |
|
170 |
$_SESSION['user_id'] = ''; |
|
171 |
} |
7902df
|
172 |
else |
T |
173 |
rcmail_set_imap_prop(); |
4e17e6
|
174 |
} |
T |
175 |
|
|
176 |
|
|
177 |
// not logged in -> set task to 'login |
597170
|
178 |
if (empty($_SESSION['user_id'])) |
42b113
|
179 |
{ |
T |
180 |
if ($REMOTE_REQUEST) |
|
181 |
{ |
|
182 |
$message .= "setTimeout(\"location.href='\"+this.env.comm_path+\"'\", 2000);"; |
|
183 |
rcube_remote_response($message); |
|
184 |
} |
|
185 |
|
4e17e6
|
186 |
$_task = 'login'; |
42b113
|
187 |
} |
4e17e6
|
188 |
|
T |
189 |
|
|
190 |
|
597170
|
191 |
// set task and action to client |
4e17e6
|
192 |
$script = sprintf("%s.set_env('task', '%s');", $JS_OBJECT_NAME, $_task); |
T |
193 |
if (!empty($_action)) |
|
194 |
$script .= sprintf("\n%s.set_env('action', '%s');", $JS_OBJECT_NAME, $_action); |
|
195 |
|
|
196 |
$OUTPUT->add_script($script); |
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
// not logged in -> show login page |
|
201 |
if (!$_SESSION['user_id']) |
|
202 |
{ |
|
203 |
parse_template('login'); |
|
204 |
exit; |
|
205 |
} |
|
206 |
|
|
207 |
|
1cded8
|
208 |
// handle keep-alive signal |
T |
209 |
if ($_action=='keep-alive') |
|
210 |
{ |
|
211 |
rcube_remote_response(''); |
|
212 |
exit; |
|
213 |
} |
|
214 |
|
4e17e6
|
215 |
|
T |
216 |
// include task specific files |
|
217 |
if ($_task=='mail') |
|
218 |
{ |
|
219 |
include_once('program/steps/mail/func.inc'); |
88375f
|
220 |
|
4e17e6
|
221 |
if ($_action=='show' || $_action=='print') |
T |
222 |
include('program/steps/mail/show.inc'); |
|
223 |
|
|
224 |
if ($_action=='get') |
|
225 |
include('program/steps/mail/get.inc'); |
|
226 |
|
|
227 |
if ($_action=='moveto' || $_action=='delete') |
|
228 |
include('program/steps/mail/move_del.inc'); |
|
229 |
|
|
230 |
if ($_action=='mark') |
|
231 |
include('program/steps/mail/mark.inc'); |
|
232 |
|
|
233 |
if ($_action=='viewsource') |
|
234 |
include('program/steps/mail/viewsource.inc'); |
|
235 |
|
|
236 |
if ($_action=='send') |
|
237 |
include('program/steps/mail/sendmail.inc'); |
|
238 |
|
|
239 |
if ($_action=='upload') |
|
240 |
include('program/steps/mail/upload.inc'); |
|
241 |
|
|
242 |
if ($_action=='compose') |
|
243 |
include('program/steps/mail/compose.inc'); |
|
244 |
|
|
245 |
if ($_action=='addcontact') |
|
246 |
include('program/steps/mail/addcontact.inc'); |
15a9d1
|
247 |
|
5e3512
|
248 |
if ($_action=='expunge' || $_action=='purge') |
15a9d1
|
249 |
include('program/steps/mail/folders.inc'); |
T |
250 |
|
|
251 |
if ($_action=='check-recent') |
|
252 |
include('program/steps/mail/check_recent.inc'); |
|
253 |
|
|
254 |
if ($_action=='getunread') |
|
255 |
include('program/steps/mail/getunread.inc'); |
4e17e6
|
256 |
|
T |
257 |
if ($_action=='list' && $_GET['_remote']) |
|
258 |
include('program/steps/mail/list.inc'); |
|
259 |
|
88375f
|
260 |
if ($_action=='rss') |
T |
261 |
include('program/steps/mail/rss.inc'); |
|
262 |
|
4e17e6
|
263 |
// kill compose entry from session |
T |
264 |
if (isset($_SESSION['compose'])) |
|
265 |
rcmail_compose_cleanup(); |
|
266 |
} |
|
267 |
|
|
268 |
|
|
269 |
// include task specific files |
|
270 |
if ($_task=='addressbook') |
|
271 |
{ |
|
272 |
include_once('program/steps/addressbook/func.inc'); |
|
273 |
|
|
274 |
if ($_action=='save') |
|
275 |
include('program/steps/addressbook/save.inc'); |
|
276 |
|
|
277 |
if ($_action=='edit' || $_action=='add') |
|
278 |
include('program/steps/addressbook/edit.inc'); |
|
279 |
|
|
280 |
if ($_action=='delete') |
|
281 |
include('program/steps/addressbook/delete.inc'); |
|
282 |
|
|
283 |
if ($_action=='show') |
|
284 |
include('program/steps/addressbook/show.inc'); |
|
285 |
|
|
286 |
if ($_action=='list' && $_GET['_remote']) |
|
287 |
include('program/steps/addressbook/list.inc'); |
d1d2c4
|
288 |
|
S |
289 |
if ($_action=='ldappublicsearch') |
|
290 |
include('program/steps/addressbook/ldapsearchform.inc'); |
4e17e6
|
291 |
} |
T |
292 |
|
|
293 |
|
|
294 |
// include task specific files |
|
295 |
if ($_task=='settings') |
|
296 |
{ |
|
297 |
include_once('program/steps/settings/func.inc'); |
|
298 |
|
|
299 |
if ($_action=='save-identity') |
|
300 |
include('program/steps/settings/save_identity.inc'); |
|
301 |
|
|
302 |
if ($_action=='add-identity' || $_action=='edit-identity') |
|
303 |
include('program/steps/settings/edit_identity.inc'); |
|
304 |
|
|
305 |
if ($_action=='delete-identity') |
|
306 |
include('program/steps/settings/delete_identity.inc'); |
|
307 |
|
|
308 |
if ($_action=='identities') |
|
309 |
include('program/steps/settings/identities.inc'); |
|
310 |
|
|
311 |
if ($_action=='save-prefs') |
|
312 |
include('program/steps/settings/save_prefs.inc'); |
|
313 |
|
|
314 |
if ($_action=='folders' || $_action=='subscribe' || $_action=='unsubscribe' || $_action=='create-folder' || $_action=='delete-folder') |
|
315 |
include('program/steps/settings/manage_folders.inc'); |
|
316 |
|
ecf759
|
317 |
} |
T |
318 |
|
|
319 |
|
539cd4
|
320 |
// only allow these templates to be included |
T |
321 |
$valid_tasks = array('mail','settings','addressbook'); |
4e17e6
|
322 |
|
539cd4
|
323 |
// parse main template |
T |
324 |
if (in_array($_task, $valid_tasks)) |
|
325 |
parse_template($_task); |
|
326 |
|
|
327 |
|
|
328 |
// if we arrive here, something went wrong |
|
329 |
raise_error(array('code' => 404, |
|
330 |
'type' => 'php', |
|
331 |
'line' => __LINE__, |
|
332 |
'file' => __FILE__, |
|
333 |
'message' => "Invalid request"), TRUE, TRUE); |
|
334 |
|
d1d2c4
|
335 |
?> |