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