source: github/index.php @ 49afbf5

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since 49afbf5 was 8884477, checked in by thomascube <thomas@…>, 8 years ago

Latest updates for release

  • Property mode set to 100644
File size: 8.9 KB
Line 
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
49
50// set environment first
51ini_set('include_path', ini_get('include_path').PATH_SEPARATOR.$INSTALL_PATH.PATH_SEPARATOR.'program'.PATH_SEPARATOR.'program/lib');
52ini_set('session.name', 'sessid');
53ini_set('session.use_cookies', 1);
54ini_set('error_reporting', E_ALL&~E_NOTICE);
55
56
57// increase maximum execution time for php scripts
58set_time_limit('120');
59
60
61// include base files
62require_once('include/rcube_shared.inc');
63require_once('include/rcube_imap.inc');
64require_once('include/rcube_db.inc');
65require_once('include/bugs.inc');
66require_once('include/main.inc');
67require_once('include/cache.inc');
68
69
70// catch some url/post parameters
71$_auth = !empty($_POST['_auth']) ? $_POST['_auth'] : $_GET['_auth'];
72$_task = !empty($_POST['_task']) ? $_POST['_task'] : (!empty($_GET['_task']) ? $_GET['_task'] : 'mail');
73$_action = !empty($_POST['_action']) ? $_POST['_action'] : (!empty($_GET['_action']) ? $_GET['_action'] : '');
74$_framed = (!empty($_GET['_framed']) || !empty($_POST['_framed']));
75
76if (!empty($_GET['_remote']))
77  $REMOTE_REQUEST = TRUE;
78
79
80// start session with requested task
81rcmail_startup($_task);
82
83
84// set session related variables
85$COMM_PATH = sprintf('./?_auth=%s&_task=%s', $sess_auth, $_task);
86$SESS_HIDDEN_FIELD = sprintf('<input type="hidden" name="_auth" value="%s" />', $sess_auth);
87
88
89// add framed parameter
90if ($_framed)
91  {
92  $COMM_PATH .= '&_framed=1';
93  $SESS_HIDDEN_FIELD = "\n".'<input type="hidden" name="_framed" value="1" />';
94  }
95
96
97// init necessary objects for GUI
98load_gui();
99
100
101// error steps
102if ($_action=='error' && !empty($_GET['_code']))
103  {
104  raise_error(array('code' => hexdec($_GET['_code'])), FALSE, TRUE);
105  }
106
107
108// try to log in
109if ($_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
132else if ($_action=='logout' && $_SESSION['user_id'])
133  {
134  show_message('loggedout');
135  rcmail_kill_session();
136  }
137
138// check session cookie and auth string
139else 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
150if (!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
162if (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);
177if (!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
185if (!$_SESSION['user_id'])
186  {
187  parse_template('login');
188  exit;
189  }
190
191
192
193// include task specific files
194if ($_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
235if ($_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
257if ($_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
286if (in_array($_task, $valid_tasks))
287  parse_template($_task);
288
289
290// if we arrive here, something went wrong
291raise_error(array('code' => 404,
292                  'type' => 'php',
293                  'line' => __LINE__,
294                  'file' => __FILE__,
295                  'message' => "Invalid request"), TRUE, TRUE);
296                     
297?>
Note: See TracBrowser for help on using the repository browser.