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