thomascube
2005-09-30 968bdc7c90f718560b84eb3b7e8e1d02cf4270f3
commit | author | age
4e17e6 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
5  | RoundCube Webmail IMAP Client                                         |
15fee7 6  | Version 0.1-20050929                                                  |
4e17e6 7  |                                                                       |
T 8  | Copyright (C) 2005, RoundCube Dev. - Switzerland                      |
15fee7 9  | Licensed under the GNU GPL                                            |
4e17e6 10  |                                                                       |
T 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
51 ini_set('include_path', ini_get('include_path').PATH_SEPARATOR.'program'.PATH_SEPARATOR.'program/lib');
52 ini_set('session.name', 'sessid');
53 ini_set('session.use_cookies', 1);
54 //ini_set('session.save_path', $INSTALL_PATH.'session');
55
56
57 // increase maximum execution time for php scripts
58 set_time_limit('120');
59
60
61 // include base files
62 require_once('include/rcube_shared.inc');
63 require_once('include/rcube_imap.inc');
64 require_once('include/rcube_mysql.inc');
65 require_once('include/bugs.inc');
66 require_once('include/main.inc');
67 require_once('include/cache.inc');
68
69
70 // catch some url/post parameters
71 $_auth = strlen($_POST['_auth']) ? $_POST['_auth'] : $_GET['_auth'];
72 $_task = strlen($_POST['_task']) ? $_POST['_task'] : ($_GET['_task'] ? $_GET['_task'] : 'mail');
73 $_action = strlen($_POST['_action']) ? $_POST['_action'] : $_GET['_action'];
74 $_framed = ($_GET['_framed'] || $_POST['_framed']);
75
76 // start session with requested task
77 rcmail_startup($_task);
78
79
80 // set session related variables
81 $COMM_PATH = sprintf('./?_auth=%s&_task=%s', $sess_auth, $_task);
82 $SESS_HIDDEN_FIELD = sprintf('<input type="hidden" name="_auth" value="%s" />', $sess_auth);
83
84
85 // add framed parameter
86 if ($_GET['_framed'] || $_POST['_framed'])
87   {
88   $COMM_PATH .= '&_framed=1';
89   $SESS_HIDDEN_FIELD = "\n".'<input type="hidden" name="_framed" value="1" />';
90   }
91
92
93 // init necessary objects for GUI
94 load_gui();
95
96
97 // error steps
98 if ($_action=='error' && strlen($_GET['_code']))
99   {
100   raise_error(array('code' => hexdec($_GET['_code'])), FALSE, TRUE);
101   }
102
103
104 // try to log in
105 if ($_action=='login' && $_task=='mail')
106   {
107   $host = $_POST['_host'] ? $_POST['_host'] : $CONFIG['default_host'];
108   
109   // check if client supports cookies
110   if (!$_COOKIE[session_name()])
111     {
112     show_message("cookiesdisabled", 'warning');
113     }
114   else if ($_POST['_user'] && $_POST['_pass'] && rcmail_login($_POST['_user'], $_POST['_pass'], $host))
115     {
116     // send redirect
117     header("Location: $COMM_PATH");
118     exit;
119     }
120   else
121     {
122     show_message("loginfailed", 'warning');
123     $_SESSION['user_id'] = '';
124     }
125   }
126
127 // end session
128 else if ($_action=='logout' && $_SESSION['user_id'])
129   {
130   show_message('loggedout');
131   rcmail_kill_session();
132   }
133
134 // check session cookie and auth string
135 else if ($_action!='login' && $_auth && $sess_auth)
136   {
137   if ($_auth !== $sess_auth || $_auth != rcmail_auth_hash($_SESSION['client_id'], $_SESSION['auth_time']))
138     {
139     show_message('sessionerror', 'error');
140     rcmail_kill_session();
141     }
142   }
143
144
145 // log in to imap server
146 if ($_SESSION['user_id'] && $_task=='mail')
147   {
148   $conn = $IMAP->connect($_SESSION['imap_host'], $_SESSION['username'], decrypt_passwd($_SESSION['password']));
149   if (!$conn)
150     {
151     show_message('imaperror', 'error');
152     $_SESSION['user_id'] = '';
153     }
154   }
155
156
157 // not logged in -> set task to 'login
158 if (!$_SESSION['user_id'])
159   $_task = 'login';
160
161
162
163 // set taask and action to client
164 $script = sprintf("%s.set_env('task', '%s');", $JS_OBJECT_NAME, $_task);
165 if (!empty($_action))
166   $script .= sprintf("\n%s.set_env('action', '%s');", $JS_OBJECT_NAME, $_action);
167
168 $OUTPUT->add_script($script);
169
170
171
172 // not logged in -> show login page
173 if (!$_SESSION['user_id'])
174   {
175   parse_template('login');
176   exit;
177   }
178
179
180
181 // include task specific files
182 if ($_task=='mail')
183   {
184   include_once('program/steps/mail/func.inc');
185
186   if ($_action=='show' || $_action=='print')
187     include('program/steps/mail/show.inc');
188
189   if ($_action=='get')
190     include('program/steps/mail/get.inc');
191
192   if ($_action=='moveto' || $_action=='delete')
193     include('program/steps/mail/move_del.inc');
194
195   if ($_action=='mark')
196     include('program/steps/mail/mark.inc');
197
198   if ($_action=='viewsource')
199     include('program/steps/mail/viewsource.inc');
200
201   if ($_action=='send')
202     include('program/steps/mail/sendmail.inc');
203
204   if ($_action=='upload')
205     include('program/steps/mail/upload.inc');
206
207   if ($_action=='compose')
208     include('program/steps/mail/compose.inc');
209
210   if ($_action=='addcontact')
211     include('program/steps/mail/addcontact.inc');
212     
213   if ($_action=='list' && $_GET['_remote'])
214     include('program/steps/mail/list.inc');
215
216   // kill compose entry from session
217   if (isset($_SESSION['compose']))
218     rcmail_compose_cleanup();
219   }
220
221
222 // include task specific files
223 if ($_task=='addressbook')
224   {
225   include_once('program/steps/addressbook/func.inc');
226
227   if ($_action=='save')
228     include('program/steps/addressbook/save.inc');
229   
230   if ($_action=='edit' || $_action=='add')
231     include('program/steps/addressbook/edit.inc');
232   
233   if ($_action=='delete')
234     include('program/steps/addressbook/delete.inc');
235
236   if ($_action=='show')
237     include('program/steps/addressbook/show.inc');  
238
239   if ($_action=='list' && $_GET['_remote'])
240     include('program/steps/addressbook/list.inc');
241   }
242
243
244 // include task specific files
245 if ($_task=='settings')
246   {
247   include_once('program/steps/settings/func.inc');
248
249   if ($_action=='save-identity')
250     include('program/steps/settings/save_identity.inc');
251
252   if ($_action=='add-identity' || $_action=='edit-identity')
253     include('program/steps/settings/edit_identity.inc');
254
255   if ($_action=='delete-identity')
256     include('program/steps/settings/delete_identity.inc');
257   
258   if ($_action=='identities')
259     include('program/steps/settings/identities.inc');  
260
261   if ($_action=='save-prefs')
262     include('program/steps/settings/save_prefs.inc');  
263
264   if ($_action=='folders' || $_action=='subscribe' || $_action=='unsubscribe' || $_action=='create-folder' || $_action=='delete-folder')
265     include('program/steps/settings/manage_folders.inc');
266
267   }
268
269
539cd4 270 // only allow these templates to be included
T 271 $valid_tasks = array('mail','settings','addressbook');
4e17e6 272
539cd4 273 // parse main template
T 274 if (in_array($_task, $valid_tasks))
275   parse_template($_task);
276
277
278 // if we arrive here, something went wrong
279 raise_error(array('code' => 404,
280                   'type' => 'php',
281                   'line' => __LINE__,
282                   'file' => __FILE__,
283                   'message' => "Invalid request"), TRUE, TRUE);
284                       
4e17e6 285 ?>