make it possible again to disable thread sort and server sort.
[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 if (!function_exists('sqm_baseuri')){
34 require_once(SM_PATH . 'functions/display_messages.php');
35 }
36 $base_uri = sqm_baseuri();
37
38 header('Pragma: no-cache');
39 $location = get_location();
40
41 session_set_cookie_params (0, $base_uri);
42 sqsession_is_active();
43
44 sqsession_unregister ('user_is_logged_in');
45 sqsession_register ($base_uri, 'base_uri');
46
47 /* get globals we me need */
48 sqGetGlobalVar('login_username', $login_username);
49 sqGetGlobalVar('secretkey', $secretkey);
50 if(!sqGetGlobalVar('squirrelmail_language', $squirrelmail_language) || $squirrelmail_language == '') {
51 $squirrelmail_language = $squirrelmail_default_language;
52 }
53 if (!sqgetGlobalVar('mailto', $mailto)) {
54 $mailto = '';
55 }
56
57 /* end of get globals */
58
59 set_up_language($squirrelmail_language, true);
60 /* Refresh the language cookie. */
61 sqsetcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,
62 $base_uri);
63
64 if (!isset($login_username)) {
65 include_once(SM_PATH . 'functions/display_messages.php' );
66 logout_error( _("You must be logged in to access this page.") );
67 exit;
68 }
69
70 if (!sqsession_is_registered('user_is_logged_in')) {
71 do_hook ('login_before');
72
73 $onetimepad = OneTimePadCreate(strlen($secretkey));
74 $key = OneTimePadEncrypt($secretkey, $onetimepad);
75 sqsession_register($onetimepad, 'onetimepad');
76
77 /* remove redundant spaces */
78 $login_username = trim($login_username);
79
80 /* Verify that username and password are correct. */
81 if ($force_username_lowercase) {
82 $login_username = strtolower($login_username);
83 }
84
85 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
86
87 $sqimap_capabilities = sqimap_capability($imapConnection);
88 sqsession_register($sqimap_capabilities, 'sqimap_capabilities');
89 $delimiter = sqimap_get_delimiter ($imapConnection);
90
91 sqimap_logout($imapConnection);
92 sqsession_register($delimiter, 'delimiter');
93
94 $username = $login_username;
95 sqsession_register ($username, 'username');
96 sqsetcookie('key', $key, false, $base_uri);
97 do_hook ('login_verified');
98
99 }
100
101 /* Set the login variables. */
102 $user_is_logged_in = true;
103 $just_logged_in = true;
104
105 /* And register with them with the session. */
106 sqsession_register ($user_is_logged_in, 'user_is_logged_in');
107 sqsession_register ($just_logged_in, 'just_logged_in');
108
109 /* parse the accepted content-types of the client */
110 $attachment_common_types = array();
111 $attachment_common_types_parsed = array();
112 sqsession_register($attachment_common_types, 'attachment_common_types');
113 sqsession_register($attachment_common_types_parsed, 'attachment_common_types_parsed');
114
115 $debug = false;
116
117 if ( sqgetGlobalVar('HTTP_ACCEPT', $http_accept, SQ_SERVER) &&
118 !isset($attachment_common_types_parsed[$http_accept]) ) {
119 attachment_common_parse($http_accept, $debug);
120 }
121
122 /* Complete autodetection of Javascript. */
123 checkForJavascript();
124
125 /* Compute the URL to forward the user to. */
126 $redirect_url = $location . '/webmail.php';
127
128 if ( sqgetGlobalVar('session_expired_location', $session_expired_location, SQ_SESSION) ) {
129 sqsession_unregister('session_expired_location');
130 $compose_new_win = getPref($data_dir, $username, 'compose_new_win', 0);
131 if ($compose_new_win) {
132 // do not prefix $location here because $session_expired_location is set to PHP_SELF
133 // of the last page
134 $redirect_url = $session_expired_location;
135 } elseif ( strpos($session_expired_location, 'webmail.php') === FALSE ) {
136 $redirect_url = $location.'/webmail.php?right_frame='.urldecode($session_expired_location);
137 }
138 unset($session_expired_location);
139 }
140 if($mailto != '') {
141 $redirect_url = $location . '/webmail.php?right_frame=compose.php&mailto=';
142 $redirect_url .= urlencode($mailto);
143 }
144
145 /* Write session data and send them off to the appropriate page. */
146 session_write_close();
147 header("Location: $redirect_url");
148
149 /* --------------------- end main ----------------------- */
150
151 function attachment_common_parse($str, $debug) {
152 global $attachment_common_types, $attachment_common_types_parsed;
153
154 $attachment_common_types_parsed[$str] = true;
155
156 /*
157 * Replace ", " with "," and explode on that as Mozilla 1.x seems to
158 * use "," to seperate whilst IE, and earlier versions of Mozilla use
159 * ", " to seperate
160 */
161
162 $str = str_replace( ', ' , ',' , $str );
163 $types = explode(',', $str);
164
165 foreach ($types as $val) {
166 // Ignore the ";q=1.0" stuff
167 if (strpos($val, ';') !== false)
168 $val = substr($val, 0, strpos($val, ';'));
169
170 if (! isset($attachment_common_types[$val])) {
171 $attachment_common_types[$val] = true;
172 }
173 }
174 sqsession_register($attachment_common_types, 'attachment_common_types');
175 }
176
177 ?>