4f5dd86780400c59a23150e2380ec91a3c7c1bd9
[squirrelmail.git] / src / redirect.php
1 <?php
2
3 /**
4 * redirect.php
5 * Derived from webmail.php by Ralf Kraudelt <kraude@wiwi.uni-rostock.de>
6 *
7 * Copyright (c) 1999-2004 The SquirrelMail Project Team
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 *
12 * @version $Id$
13 * @package squirrelmail
14 */
15
16 /**
17 * Path for SquirrelMail required files.
18 * @ignore
19 */
20 define('SM_PATH','../');
21
22 /* SquirrelMail required files. */
23 require_once(SM_PATH . 'functions/global.php');
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');
32
33 /* Before starting the session, the base URI must be known. Assuming */
34 /* that this file is in the src/ subdirectory (or something). */
35 if (!function_exists('sqm_baseuri')){
36 require_once(SM_PATH . 'functions/display_messages.php');
37 }
38 $base_uri = sqm_baseuri();
39
40 header('Pragma: no-cache');
41 $location = get_location();
42
43 sqsession_is_active();
44
45 sqsession_unregister ('user_is_logged_in');
46 sqsession_register ($base_uri, 'base_uri');
47
48 /* get globals we me need */
49 sqGetGlobalVar('login_username', $login_username);
50 sqGetGlobalVar('secretkey', $secretkey);
51 if(!sqGetGlobalVar('squirrelmail_language', $squirrelmail_language) || $squirrelmail_language == '') {
52 $squirrelmail_language = $squirrelmail_default_language;
53 }
54 if (!sqgetGlobalVar('mailto', $mailto)) {
55 $mailto = '';
56 }
57
58 /* end of get globals */
59
60 set_up_language($squirrelmail_language, true);
61 /* Refresh the language cookie. */
62 setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,
63 $base_uri);
64
65 if (!isset($login_username)) {
66 include_once(SM_PATH . 'functions/display_messages.php' );
67 logout_error( _("You must be logged in to access this page.") );
68 exit;
69 }
70
71 if (!sqsession_is_registered('user_is_logged_in')) {
72 do_hook ('login_before');
73
74 $onetimepad = OneTimePadCreate(strlen($secretkey));
75 $key = OneTimePadEncrypt($secretkey, $onetimepad);
76 sqsession_register($onetimepad, 'onetimepad');
77
78 /* remove redundant spaces */
79 $login_username = trim($login_username);
80
81 /* Verify that username and password are correct. */
82 if ($force_username_lowercase) {
83 $login_username = strtolower($login_username);
84 }
85
86 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
87
88 $sqimap_capabilities = sqimap_capability($imapConnection);
89 sqsession_register($sqimap_capabilities, 'sqimap_capabilities');
90 $delimiter = sqimap_get_delimiter ($imapConnection);
91
92 sqimap_logout($imapConnection);
93 sqsession_register($delimiter, 'delimiter');
94
95 $username = $login_username;
96 sqsession_register ($username, 'username');
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. */
107 sqsession_register ($user_is_logged_in, 'user_is_logged_in');
108 sqsession_register ($just_logged_in, 'just_logged_in');
109
110 /* parse the accepted content-types of the client */
111 $attachment_common_types = array();
112 $attachment_common_types_parsed = array();
113 sqsession_register($attachment_common_types, 'attachment_common_types');
114 sqsession_register($attachment_common_types_parsed, 'attachment_common_types_parsed');
115
116 $debug = false;
117
118 if ( sqgetGlobalVar('HTTP_ACCEPT', $http_accept, SQ_SERVER) &&
119 !isset($attachment_common_types_parsed[$http_accept]) ) {
120 attachment_common_parse($http_accept, $debug);
121 }
122
123 /* Complete autodetection of Javascript. */
124 checkForJavascript();
125
126 /* Compute the URL to forward the user to. */
127 $redirect_url = $location . '/webmail.php';
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) {
133 // do not prefix $location here because $session_expired_location is set to PHP_SELF
134 // of the last page
135 $redirect_url = $session_expired_location;
136 } elseif ( strpos($session_expired_location, 'webmail.php') === FALSE ) {
137 $redirect_url = $location.'/webmail.php?right_frame='.urldecode($session_expired_location);
138 }
139 unset($session_expired_location);
140 }
141 if($mailto != '') {
142 $redirect_url = $location . '/webmail.php?right_frame=compose.php&mailto=';
143 $redirect_url .= $mailto;
144 }
145
146 /* Write session data and send them off to the appropriate page. */
147 session_write_close();
148 header("Location: $redirect_url");
149
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;
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 );
164 $types = explode(',', $str);
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 }
175 sqsession_register($attachment_common_types, 'attachment_common_types');
176 }
177
178 ?>