Adding template for error box.
[squirrelmail.git] / src / redirect.php
1 <?php
2
3 /**
4 * Prevents users from reposting their form data after a successful logout.
5 *
6 * Derived from webmail.php by Ralf Kraudelt <kraude@wiwi.uni-rostock.de>
7 *
8 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 */
13
14 /**
15 * Path for SquirrelMail required files.
16 * @ignore
17 */
18 define('SM_PATH','../');
19
20 /* SquirrelMail required files. */
21 require_once(SM_PATH . 'functions/global.php');
22 require_once(SM_PATH . 'functions/i18n.php');
23 require_once(SM_PATH . 'functions/strings.php');
24 require_once(SM_PATH . 'config/config.php');
25 require_once(SM_PATH . 'functions/prefs.php');
26 require_once(SM_PATH . 'functions/imap.php');
27 require_once(SM_PATH . 'functions/plugin.php');
28 require_once(SM_PATH . 'functions/constants.php');
29 require_once(SM_PATH . 'functions/page_header.php');
30
31 /* Before starting the session, the base URI must be known. Assuming */
32 /* that this file is in the src/ subdirectory (or something). */
33 $base_uri = sqm_baseuri();
34
35 header('Pragma: no-cache');
36 $location = get_location();
37
38 session_set_cookie_params (0, $base_uri);
39 sqsession_is_active();
40
41 sqsession_unregister ('user_is_logged_in');
42 sqsession_register ($base_uri, 'base_uri');
43
44 /* get globals we me need */
45 sqGetGlobalVar('login_username', $login_username);
46 sqGetGlobalVar('secretkey', $secretkey);
47 if(!sqGetGlobalVar('squirrelmail_language', $squirrelmail_language) || $squirrelmail_language == '') {
48 $squirrelmail_language = $squirrelmail_default_language;
49 }
50 if (!sqgetGlobalVar('mailto', $mailto)) {
51 $mailto = '';
52 }
53
54 /* end of get globals */
55
56 set_up_language($squirrelmail_language, true);
57 /* Refresh the language cookie. */
58 sqsetcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,
59 $base_uri);
60
61 if (!isset($login_username)) {
62 include_once(SM_PATH . 'functions/display_messages.php' );
63 logout_error( _("You must be logged in to access this page.") );
64 exit;
65 }
66
67 if (!sqsession_is_registered('user_is_logged_in')) {
68 do_hook ('login_before');
69
70 $onetimepad = OneTimePadCreate(strlen($secretkey));
71 $key = OneTimePadEncrypt($secretkey, $onetimepad);
72 sqsession_register($onetimepad, 'onetimepad');
73
74 /* remove redundant spaces */
75 $login_username = trim($login_username);
76
77 /* Verify that username and password are correct. */
78 if ($force_username_lowercase) {
79 $login_username = strtolower($login_username);
80 }
81
82 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
83
84 $sqimap_capabilities = sqimap_capability($imapConnection);
85
86 /* Server side sorting control */
87 if (isset($sqimap_capabilities['SORT']) && $sqimap_capabilities['SORT'] == true &&
88 isset($disable_server_sort) && $disable_server_sort) {
89 unset($sqimap_capabilities['SORT']);
90 }
91
92 /* Thread sort control */
93 if (isset($sqimap_capabilities['THREAD']) && $sqimap_capabilities['THREAD'] == true &&
94 isset($disable_thread_sort) && $disable_thread_sort) {
95 unset($sqimap_capabilities['THREAD']);
96 }
97
98 sqsession_register($sqimap_capabilities, 'sqimap_capabilities');
99 $delimiter = sqimap_get_delimiter ($imapConnection);
100
101 sqimap_logout($imapConnection);
102 sqsession_register($delimiter, 'delimiter');
103
104 $username = $login_username;
105 sqsession_register ($username, 'username');
106 sqsetcookie('key', $key, false, $base_uri);
107 do_hook ('login_verified');
108
109 }
110
111 /* Set the login variables. */
112 $user_is_logged_in = true;
113 $just_logged_in = true;
114
115 /* And register with them with the session. */
116 sqsession_register ($user_is_logged_in, 'user_is_logged_in');
117 sqsession_register ($just_logged_in, 'just_logged_in');
118
119 /* parse the accepted content-types of the client */
120 $attachment_common_types = array();
121 $attachment_common_types_parsed = array();
122 sqsession_register($attachment_common_types, 'attachment_common_types');
123 sqsession_register($attachment_common_types_parsed, 'attachment_common_types_parsed');
124
125 $debug = false;
126
127 if ( sqgetGlobalVar('HTTP_ACCEPT', $http_accept, SQ_SERVER) &&
128 !isset($attachment_common_types_parsed[$http_accept]) ) {
129 attachment_common_parse($http_accept, $debug);
130 }
131
132 /* Complete autodetection of Javascript. */
133 checkForJavascript();
134
135 /* Compute the URL to forward the user to. */
136 $redirect_url = $location . '/webmail.php';
137
138 if ( sqgetGlobalVar('session_expired_location', $session_expired_location, SQ_SESSION) ) {
139 sqsession_unregister('session_expired_location');
140 $compose_new_win = getPref($data_dir, $username, 'compose_new_win', 0);
141 if ($compose_new_win) {
142 // do not prefix $location here because $session_expired_location is set to PHP_SELF
143 // of the last page
144 $redirect_url = $session_expired_location;
145 } elseif ( strpos($session_expired_location, 'webmail.php') === FALSE ) {
146 $redirect_url = $location.'/webmail.php?right_frame='.urldecode($session_expired_location);
147 }
148 unset($session_expired_location);
149 }
150 if($mailto != '') {
151 $redirect_url = $location . '/webmail.php?right_frame=compose.php&mailto=';
152 $redirect_url .= urlencode($mailto);
153 }
154
155 /* Write session data and send them off to the appropriate page. */
156 session_write_close();
157 header("Location: $redirect_url");
158
159 /* --------------------- end main ----------------------- */
160
161 function attachment_common_parse($str, $debug) {
162 global $attachment_common_types, $attachment_common_types_parsed;
163
164 $attachment_common_types_parsed[$str] = true;
165
166 /*
167 * Replace ", " with "," and explode on that as Mozilla 1.x seems to
168 * use "," to seperate whilst IE, and earlier versions of Mozilla use
169 * ", " to seperate
170 */
171
172 $str = str_replace( ', ' , ',' , $str );
173 $types = explode(',', $str);
174
175 foreach ($types as $val) {
176 // Ignore the ";q=1.0" stuff
177 if (strpos($val, ';') !== false)
178 $val = substr($val, 0, strpos($val, ';'));
179
180 if (! isset($attachment_common_types[$val])) {
181 $attachment_common_types[$val] = true;
182 }
183 }
184 sqsession_register($attachment_common_types, 'attachment_common_types');
185 }
186
187 ?>