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 | */ |
202bcbcc |
13 | $sInitLocation = 'redirect'; |
35586184 |
14 | |
30967a1e |
15 | /** |
202bcbcc |
16 | * Include the SquirrelMail initialization file. |
30967a1e |
17 | */ |
202bcbcc |
18 | require('../include/init.php'); |
86725763 |
19 | |
20 | /* SquirrelMail required files. */ |
202bcbcc |
21 | require_once(SM_PATH . 'functions/imap_general.php'); |
86725763 |
22 | require_once(SM_PATH . 'functions/strings.php'); |
5c3b0995 |
23 | |
24 | header('Pragma: no-cache'); |
25 | $location = get_location(); |
26 | |
202bcbcc |
27 | // session_set_cookie_params (0, $base_uri); |
5c3b0995 |
28 | |
ad839713 |
29 | sqsession_unregister ('user_is_logged_in'); |
30 | sqsession_register ($base_uri, 'base_uri'); |
5c3b0995 |
31 | |
a32985a5 |
32 | /* get globals we me need */ |
5250f7e7 |
33 | sqGetGlobalVar('login_username', $login_username); |
34 | sqGetGlobalVar('secretkey', $secretkey); |
5250f7e7 |
35 | if(!sqGetGlobalVar('squirrelmail_language', $squirrelmail_language) || $squirrelmail_language == '') { |
134e4174 |
36 | $squirrelmail_language = $squirrelmail_default_language; |
a32985a5 |
37 | } |
7e2ff844 |
38 | if (!sqgetGlobalVar('mailtodata', $mailtodata)) { |
39 | $mailtodata = ''; |
c67e4479 |
40 | } |
5250f7e7 |
41 | |
a32985a5 |
42 | /* end of get globals */ |
43 | |
5c3b0995 |
44 | set_up_language($squirrelmail_language, true); |
45 | /* Refresh the language cookie. */ |
3a1de9f1 |
46 | sqsetcookie('squirrelmail_language', $squirrelmail_language, time()+2592000, |
85b454a0 |
47 | $base_uri); |
5c3b0995 |
48 | |
49 | if (!isset($login_username)) { |
91e0dccc |
50 | logout_error( _("You must be logged in to access this page.") ); |
5c3b0995 |
51 | exit; |
52 | } |
53 | |
d7c82551 |
54 | if (!sqsession_is_registered('user_is_logged_in')) { |
6e515418 |
55 | do_hook('login_before', $null); |
5c3b0995 |
56 | |
57 | $onetimepad = OneTimePadCreate(strlen($secretkey)); |
58 | $key = OneTimePadEncrypt($secretkey, $onetimepad); |
5c3b0995 |
59 | |
fd1b516b |
60 | /* remove redundant spaces */ |
61 | $login_username = trim($login_username); |
62 | |
5c3b0995 |
63 | /* Verify that username and password are correct. */ |
64 | if ($force_username_lowercase) { |
65 | $login_username = strtolower($login_username); |
23d6bd09 |
66 | } |
67 | |
5c3b0995 |
68 | $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0); |
202bcbcc |
69 | /* From now on we are logged it. If the login failed then sqimap_login handles it */ |
70 | |
71 | /* regenerate the session id to avoid session hyijacking */ |
72 | sqsession_destroy(); |
66c7cd3f |
73 | @sqsession_is_active(); |
202bcbcc |
74 | session_regenerate_id(); |
75 | /** |
76 | * The cookie part. session_start and session_regenerate_session normally set |
77 | * their own cookie. SquirrelMail sets another cookie which overwites the |
78 | * php cookies. The sqsetcookie function sets the cookie by using the header |
79 | * function which gives us full control how the cookie is set. We do that |
80 | * to add the HttpOnly cookie attribute which blocks javascript access on |
81 | * IE6 SP1. |
202bcbcc |
82 | */ |
83 | sqsetcookie(session_name(),session_id(),false,$base_uri); |
84 | sqsetcookie('key', $key, false, $base_uri); |
202bcbcc |
85 | |
86 | sqsession_register($onetimepad, 'onetimepad'); |
44925ab0 |
87 | |
88 | $sqimap_capabilities = sqimap_capability($imapConnection); |
f027a882 |
89 | |
90 | /* Server side sorting control */ |
91 | if (isset($sqimap_capabilities['SORT']) && $sqimap_capabilities['SORT'] == true && |
92 | isset($disable_server_sort) && $disable_server_sort) { |
93 | unset($sqimap_capabilities['SORT']); |
94 | } |
95 | |
96 | /* Thread sort control */ |
97 | if (isset($sqimap_capabilities['THREAD']) && $sqimap_capabilities['THREAD'] == true && |
98 | isset($disable_thread_sort) && $disable_thread_sort) { |
99 | unset($sqimap_capabilities['THREAD']); |
100 | } |
101 | |
44925ab0 |
102 | sqsession_register($sqimap_capabilities, 'sqimap_capabilities'); |
103 | $delimiter = sqimap_get_delimiter ($imapConnection); |
104 | |
6a645613 |
105 | if (isset($sqimap_capabilities['NAMESPACE']) && $sqimap_capabilities['NAMESPACE'] == true) { |
106 | $namespace = sqimap_get_namespace($imapConnection); |
107 | sqsession_register($namespace, 'sqimap_namespace'); |
108 | } |
109 | |
5c3b0995 |
110 | sqimap_logout($imapConnection); |
a32985a5 |
111 | sqsession_register($delimiter, 'delimiter'); |
112 | |
5c3b0995 |
113 | $username = $login_username; |
ad839713 |
114 | sqsession_register ($username, 'username'); |
6e515418 |
115 | do_hook('login_verified', $null); |
5c3b0995 |
116 | } |
117 | |
118 | /* Set the login variables. */ |
119 | $user_is_logged_in = true; |
120 | $just_logged_in = true; |
121 | |
122 | /* And register with them with the session. */ |
a32985a5 |
123 | sqsession_register ($user_is_logged_in, 'user_is_logged_in'); |
124 | sqsession_register ($just_logged_in, 'just_logged_in'); |
5c3b0995 |
125 | |
126 | /* parse the accepted content-types of the client */ |
127 | $attachment_common_types = array(); |
128 | $attachment_common_types_parsed = array(); |
a32985a5 |
129 | sqsession_register($attachment_common_types, 'attachment_common_types'); |
130 | sqsession_register($attachment_common_types_parsed, 'attachment_common_types_parsed'); |
5c3b0995 |
131 | |
1e12d1ff |
132 | if ( sqgetGlobalVar('HTTP_ACCEPT', $http_accept, SQ_SERVER) && |
133 | !isset($attachment_common_types_parsed[$http_accept]) ) { |
d9f8b0cc |
134 | attachment_common_parse($http_accept); |
9be8198d |
135 | } |
5c3b0995 |
136 | |
137 | /* Complete autodetection of Javascript. */ |
1a531551 |
138 | checkForJavascript(); |
5c3b0995 |
139 | |
140 | /* Compute the URL to forward the user to. */ |
d7746ca5 |
141 | $redirect_url = $location . '/webmail.php'; |
cab6eaea |
142 | |
143 | if ( sqgetGlobalVar('session_expired_location', $session_expired_location, SQ_SESSION) ) { |
144 | sqsession_unregister('session_expired_location'); |
c6f28eb1 |
145 | if ( strpos($session_expired_location, 'compose.php') !== FALSE ) { |
146 | $compose_new_win = getPref($data_dir, $username, 'compose_new_win', 0); |
147 | if ($compose_new_win) { |
148 | // do not prefix $location here because $session_expired_location is set to PHP_SELF |
149 | // of the last page |
150 | $redirect_url = $session_expired_location; |
151 | } else { |
9a19cc66 |
152 | $redirect_url = $location.'/webmail.php?right_frame='.urlencode($session_expired_location); |
c6f28eb1 |
153 | } |
8e54a58b |
154 | } |
cab6eaea |
155 | unset($session_expired_location); |
156 | } |
202bcbcc |
157 | |
7e2ff844 |
158 | if($mailtodata != '') { |
159 | $redirect_url = $location . '/webmail.php?right_frame=compose.php&mailtodata='; |
160 | $redirect_url .= urlencode($mailtodata); |
c67e4479 |
161 | } |
177dde45 |
162 | |
7bde5272 |
163 | /* Write session data and send them off to the appropriate page. */ |
164 | session_write_close(); |
5c3b0995 |
165 | header("Location: $redirect_url"); |
202bcbcc |
166 | exit; |
7baf86a9 |
167 | |
cab99c3a |
168 | /* --------------------- end main ----------------------- */ |
169 | |
d9f8b0cc |
170 | function attachment_common_parse($str) { |
cab99c3a |
171 | global $attachment_common_types, $attachment_common_types_parsed; |
172 | |
91e0dccc |
173 | /* |
174 | * Replace ", " with "," and explode on that as Mozilla 1.x seems to |
20511953 |
175 | * use "," to seperate whilst IE, and earlier versions of Mozilla use |
176 | * ", " to seperate |
177 | */ |
91e0dccc |
178 | |
20511953 |
179 | $str = str_replace( ', ' , ',' , $str ); |
6c817138 |
180 | $types = explode(',', $str); |
cab99c3a |
181 | |
182 | foreach ($types as $val) { |
183 | // Ignore the ";q=1.0" stuff |
184 | if (strpos($val, ';') !== false) |
185 | $val = substr($val, 0, strpos($val, ';')); |
186 | |
187 | if (! isset($attachment_common_types[$val])) { |
188 | $attachment_common_types[$val] = true; |
189 | } |
190 | } |
39c7209f |
191 | sqsession_register($attachment_common_types, 'attachment_common_types'); |
856e58ef |
192 | |
193 | /* mark as parsed */ |
194 | $attachment_common_types_parsed[$str] = true; |
cab99c3a |
195 | } |