7392739d |
1 | <?php |
895905c0 |
2 | |
35586184 |
3 | /** |
4b4abf93 |
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 | * |
4b5049de |
8 | * @copyright © 1999-2007 The SquirrelMail Project Team |
4b4abf93 |
9 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
10 | * @version $Id$ |
11 | * @package squirrelmail |
12 | */ |
35586184 |
13 | |
ebd2391c |
14 | /** This is the redirect page */ |
15 | define('PAGE_NAME', 'redirect'); |
16 | |
30967a1e |
17 | /** |
202bcbcc |
18 | * Include the SquirrelMail initialization file. |
30967a1e |
19 | */ |
202bcbcc |
20 | require('../include/init.php'); |
86725763 |
21 | |
22 | /* SquirrelMail required files. */ |
202bcbcc |
23 | require_once(SM_PATH . 'functions/imap_general.php'); |
86725763 |
24 | require_once(SM_PATH . 'functions/strings.php'); |
5c3b0995 |
25 | |
26 | header('Pragma: no-cache'); |
27 | $location = get_location(); |
28 | |
202bcbcc |
29 | // session_set_cookie_params (0, $base_uri); |
5c3b0995 |
30 | |
ad839713 |
31 | sqsession_unregister ('user_is_logged_in'); |
32 | sqsession_register ($base_uri, 'base_uri'); |
5c3b0995 |
33 | |
a32985a5 |
34 | /* get globals we me need */ |
5250f7e7 |
35 | sqGetGlobalVar('login_username', $login_username); |
36 | sqGetGlobalVar('secretkey', $secretkey); |
5250f7e7 |
37 | if(!sqGetGlobalVar('squirrelmail_language', $squirrelmail_language) || $squirrelmail_language == '') { |
134e4174 |
38 | $squirrelmail_language = $squirrelmail_default_language; |
a32985a5 |
39 | } |
7e2ff844 |
40 | if (!sqgetGlobalVar('mailtodata', $mailtodata)) { |
41 | $mailtodata = ''; |
c67e4479 |
42 | } |
5250f7e7 |
43 | |
a32985a5 |
44 | /* end of get globals */ |
45 | |
5c3b0995 |
46 | set_up_language($squirrelmail_language, true); |
47 | /* Refresh the language cookie. */ |
3a1de9f1 |
48 | sqsetcookie('squirrelmail_language', $squirrelmail_language, time()+2592000, |
85b454a0 |
49 | $base_uri); |
5c3b0995 |
50 | |
51 | if (!isset($login_username)) { |
91e0dccc |
52 | logout_error( _("You must be logged in to access this page.") ); |
5c3b0995 |
53 | exit; |
54 | } |
55 | |
9a02b0ef |
56 | do_hook('login_before', $null); |
5c3b0995 |
57 | |
9a02b0ef |
58 | $onetimepad = OneTimePadCreate(strlen($secretkey)); |
59 | $key = OneTimePadEncrypt($secretkey, $onetimepad); |
5c3b0995 |
60 | |
9a02b0ef |
61 | /* remove redundant spaces */ |
62 | $login_username = trim($login_username); |
fd1b516b |
63 | |
9a02b0ef |
64 | /* Case-normalise username if so desired */ |
65 | if ($force_username_lowercase) { |
66 | $login_username = strtolower($login_username); |
67 | } |
44925ab0 |
68 | |
9a02b0ef |
69 | /* Verify that username and password are correct. */ |
70 | $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0); |
71 | /* From now on we are logged it. If the login failed then sqimap_login handles it */ |
f027a882 |
72 | |
9a02b0ef |
73 | /* regenerate the session id to avoid session hyijacking */ |
c7ebdfcf |
74 | //FIXME! IMPORTANT! SOMEONE PLEASE EXPLAIN THE SECURITY CONCERN HERE; THIS session_destroy() BORKS ANY SESSION INFORMATION ADDED ON THE LOGIN PAGE (SPECIFICALLY THE SESSION RESTORE DATA, BUT ALSO ANYTHING ADDED BY PLUGINS, ETC)... I HAVE DISABLED THIS (AND NOTE THAT THE LOGIN PAGE ALREADY EXECUTES A session_destroy() (see includes/init.php)), SO PLEASE, WHOEVER ADDED THIS, PLEASE ANALYSE THIS SITUATION AND COMMENT ON IF IT IS OK LIKE THIS!! WHAT HIJACKING ISSUES ARE WE SUPPOSED TO BE PREVENTING HERE? |
75 | //sqsession_destroy(); |
76 | //@sqsession_is_active(); |
77 | //session_regenerate_id(); |
9a02b0ef |
78 | /** |
79 | * The cookie part. session_start and session_regenerate_session normally set |
80 | * their own cookie. SquirrelMail sets another cookie which overwites the |
81 | * php cookies. The sqsetcookie function sets the cookie by using the header |
82 | * function which gives us full control how the cookie is set. We do that |
83 | * to add the HttpOnly cookie attribute which blocks javascript access on |
84 | * IE6 SP1. |
85 | */ |
86 | sqsetcookie(session_name(),session_id(),false,$base_uri); |
87 | sqsetcookie('key', $key, false, $base_uri); |
88 | |
89 | sqsession_register($onetimepad, 'onetimepad'); |
90 | |
91 | $sqimap_capabilities = sqimap_capability($imapConnection); |
92 | |
93 | /* Server side sorting control */ |
94 | if (isset($sqimap_capabilities['SORT']) && $sqimap_capabilities['SORT'] == true && |
95 | isset($disable_server_sort) && $disable_server_sort) { |
96 | unset($sqimap_capabilities['SORT']); |
97 | } |
f027a882 |
98 | |
9a02b0ef |
99 | /* Thread sort control */ |
100 | if (isset($sqimap_capabilities['THREAD']) && $sqimap_capabilities['THREAD'] == true && |
101 | isset($disable_thread_sort) && $disable_thread_sort) { |
102 | unset($sqimap_capabilities['THREAD']); |
103 | } |
f027a882 |
104 | |
9a02b0ef |
105 | sqsession_register($sqimap_capabilities, 'sqimap_capabilities'); |
106 | $delimiter = sqimap_get_delimiter ($imapConnection); |
44925ab0 |
107 | |
9a02b0ef |
108 | if (isset($sqimap_capabilities['NAMESPACE']) && $sqimap_capabilities['NAMESPACE'] == true) { |
109 | $namespace = sqimap_get_namespace($imapConnection); |
110 | sqsession_register($namespace, 'sqimap_namespace'); |
111 | } |
6a645613 |
112 | |
9a02b0ef |
113 | sqimap_logout($imapConnection); |
114 | sqsession_register($delimiter, 'delimiter'); |
a32985a5 |
115 | |
9a02b0ef |
116 | $username = $login_username; |
117 | sqsession_register ($username, 'username'); |
118 | do_hook('login_verified', $null); |
5c3b0995 |
119 | |
120 | /* Set the login variables. */ |
121 | $user_is_logged_in = true; |
122 | $just_logged_in = true; |
123 | |
124 | /* And register with them with the session. */ |
a32985a5 |
125 | sqsession_register ($user_is_logged_in, 'user_is_logged_in'); |
126 | sqsession_register ($just_logged_in, 'just_logged_in'); |
5c3b0995 |
127 | |
128 | /* parse the accepted content-types of the client */ |
129 | $attachment_common_types = array(); |
130 | $attachment_common_types_parsed = array(); |
a32985a5 |
131 | sqsession_register($attachment_common_types, 'attachment_common_types'); |
132 | sqsession_register($attachment_common_types_parsed, 'attachment_common_types_parsed'); |
5c3b0995 |
133 | |
1e12d1ff |
134 | if ( sqgetGlobalVar('HTTP_ACCEPT', $http_accept, SQ_SERVER) && |
135 | !isset($attachment_common_types_parsed[$http_accept]) ) { |
d9f8b0cc |
136 | attachment_common_parse($http_accept); |
9be8198d |
137 | } |
5c3b0995 |
138 | |
ef33def6 |
139 | // having just logged in, need to synch the template file cache |
140 | // so the right template set is displayed (per user prefs) |
141 | require(SM_PATH . 'include/load_prefs.php'); |
142 | Template::cache_template_file_hierarchy(TRUE); |
143 | |
5c3b0995 |
144 | /* Complete autodetection of Javascript. */ |
1a531551 |
145 | checkForJavascript(); |
5c3b0995 |
146 | |
147 | /* Compute the URL to forward the user to. */ |
d7746ca5 |
148 | $redirect_url = $location . '/webmail.php'; |
cab6eaea |
149 | |
150 | if ( sqgetGlobalVar('session_expired_location', $session_expired_location, SQ_SESSION) ) { |
151 | sqsession_unregister('session_expired_location'); |
de219480 |
152 | if ( $session_expired_location == 'compose' ) { |
c6f28eb1 |
153 | $compose_new_win = getPref($data_dir, $username, 'compose_new_win', 0); |
154 | if ($compose_new_win) { |
de219480 |
155 | // do not prefix $location here because $session_expired_location is set to the PAGE_NAME |
c6f28eb1 |
156 | // of the last page |
319ad3c0 |
157 | $redirect_url = $location . '/' . $session_expired_location . '.php'; |
c6f28eb1 |
158 | } else { |
319ad3c0 |
159 | $redirect_url = $location . '/webmail.php?right_frame=' . urlencode($session_expired_location . '.php'); |
c6f28eb1 |
160 | } |
ef33def6 |
161 | } else if ($session_expired_location != 'webmail' |
162 | && $session_expired_location != 'left_main') { |
319ad3c0 |
163 | $redirect_url = $location . '/webmail.php?right_frame=' . urlencode($session_expired_location . '.php'); |
8e54a58b |
164 | } |
cab6eaea |
165 | unset($session_expired_location); |
166 | } |
202bcbcc |
167 | |
7e2ff844 |
168 | if($mailtodata != '') { |
169 | $redirect_url = $location . '/webmail.php?right_frame=compose.php&mailtodata='; |
170 | $redirect_url .= urlencode($mailtodata); |
c67e4479 |
171 | } |
177dde45 |
172 | |
7bde5272 |
173 | /* Write session data and send them off to the appropriate page. */ |
174 | session_write_close(); |
5c3b0995 |
175 | header("Location: $redirect_url"); |
202bcbcc |
176 | exit; |
7baf86a9 |
177 | |
cab99c3a |
178 | /* --------------------- end main ----------------------- */ |
179 | |
d9f8b0cc |
180 | function attachment_common_parse($str) { |
cab99c3a |
181 | global $attachment_common_types, $attachment_common_types_parsed; |
182 | |
91e0dccc |
183 | /* |
184 | * Replace ", " with "," and explode on that as Mozilla 1.x seems to |
20511953 |
185 | * use "," to seperate whilst IE, and earlier versions of Mozilla use |
186 | * ", " to seperate |
187 | */ |
91e0dccc |
188 | |
20511953 |
189 | $str = str_replace( ', ' , ',' , $str ); |
6c817138 |
190 | $types = explode(',', $str); |
cab99c3a |
191 | |
192 | foreach ($types as $val) { |
193 | // Ignore the ";q=1.0" stuff |
9a02b0ef |
194 | if (strpos($val, ';') !== false) { |
cab99c3a |
195 | $val = substr($val, 0, strpos($val, ';')); |
9a02b0ef |
196 | } |
cab99c3a |
197 | if (! isset($attachment_common_types[$val])) { |
198 | $attachment_common_types[$val] = true; |
199 | } |
200 | } |
39c7209f |
201 | sqsession_register($attachment_common_types, 'attachment_common_types'); |
856e58ef |
202 | |
203 | /* mark as parsed */ |
204 | $attachment_common_types_parsed[$str] = true; |
cab99c3a |
205 | } |