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