5 * Derived from webmail.php by Ralf Kraudelt <kraude@wiwi.uni-rostock.de>
7 * Copyright (c) 1999-2003 The SquirrelMail Project Team
8 * Licensed under the GNU GPL. For full terms see the file COPYING.
10 * Prevents users from reposting their form data after a successful logout.
15 /* Path for SquirrelMail required files. */
16 define('SM_PATH','../');
18 /* SquirrelMail required files. */
19 require_once(SM_PATH
. 'functions/global.php');
20 require_once(SM_PATH
. 'functions/i18n.php');
21 require_once(SM_PATH
. 'functions/strings.php');
22 require_once(SM_PATH
. 'config/config.php');
23 require_once(SM_PATH
. 'functions/prefs.php');
24 require_once(SM_PATH
. 'functions/imap.php');
25 require_once(SM_PATH
. 'functions/plugin.php');
26 require_once(SM_PATH
. 'functions/constants.php');
27 require_once(SM_PATH
. 'functions/page_header.php');
29 // Remove slashes if PHP added them
30 sqgetGlobalVar('REQUEST_METHOD', $REQUEST_METHOD, SQ_SERVER
);
31 if (get_magic_quotes_gpc()) {
32 if ($REQUEST_METHOD == 'POST') {
33 RemoveSlashes($_POST);
34 } else if ($REQUEST_METHOD == 'GET') {
39 /* Before starting the session, the base URI must be known. Assuming */
40 /* that this file is in the src/ subdirectory (or something). */
41 if (!function_exists('sqm_baseuri')){
42 require_once(SM_PATH
. 'functions/display_messages.php');
44 $base_uri = sqm_baseuri();
46 header('Pragma: no-cache');
47 $location = get_location();
49 session_set_cookie_params (0, $base_uri);
52 sqsession_unregister ('user_is_logged_in');
53 sqsession_register ($base_uri, 'base_uri');
55 /* get globals we me need */
56 sqGetGlobalVar('login_username', $login_username);
57 sqGetGlobalVar('secretkey', $secretkey);
58 sqGetGlobalVar('js_autodetect_results', $js_autodetect_results);
59 if(!sqGetGlobalVar('squirrelmail_language', $squirrelmail_language) ||
$squirrelmail_language == '') {
60 $squirrelmail_language = $squirrelmail_default_language;
63 /* end of get globals */
65 set_up_language($squirrelmail_language, true);
66 /* Refresh the language cookie. */
67 setcookie('squirrelmail_language', $squirrelmail_language, time()+
2592000,
70 if (!isset($login_username)) {
71 include_once(SM_PATH
. 'functions/display_messages.php' );
72 logout_error( _("You must be logged in to access this page.") );
76 if (!sqsession_is_registered('user_is_logged_in')) {
77 do_hook ('login_before');
79 $onetimepad = OneTimePadCreate(strlen($secretkey));
80 $key = OneTimePadEncrypt($secretkey, $onetimepad);
81 sqsession_register($onetimepad, 'onetimepad');
83 /* remove redundant spaces */
84 $login_username = trim($login_username);
86 /* Verify that username and password are correct. */
87 if ($force_username_lowercase) {
88 $login_username = strtolower($login_username);
91 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
93 $sqimap_capabilities = sqimap_capability($imapConnection);
94 sqsession_register($sqimap_capabilities, 'sqimap_capabilities');
95 $delimiter = sqimap_get_delimiter ($imapConnection);
97 sqimap_logout($imapConnection);
98 sqsession_register($delimiter, 'delimiter');
100 $username = $login_username;
101 sqsession_register ($username, 'username');
102 setcookie('key', $key, 0, $base_uri);
103 do_hook ('login_verified');
107 /* Set the login variables. */
108 $user_is_logged_in = true;
109 $just_logged_in = true;
111 /* And register with them with the session. */
112 sqsession_register ($user_is_logged_in, 'user_is_logged_in');
113 sqsession_register ($just_logged_in, 'just_logged_in');
115 /* parse the accepted content-types of the client */
116 $attachment_common_types = array();
117 $attachment_common_types_parsed = array();
118 sqsession_register($attachment_common_types, 'attachment_common_types');
119 sqsession_register($attachment_common_types_parsed, 'attachment_common_types_parsed');
123 if ( sqgetGlobalVar('HTTP_ACCEPT', $http_accept, SQ_SERVER
) &&
124 !isset($attachment_common_types_parsed[$http_accept]) ) {
125 attachment_common_parse($http_accept, $debug);
128 /* Complete autodetection of Javascript. */
129 $javascript_setting = getPref
130 ($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT
);
131 $js_autodetect_results = (isset($js_autodetect_results) ?
132 $js_autodetect_results : SMPREF_JS_OFF
);
133 /* See if it's set to "Always on" */
134 $js_pref = SMPREF_JS_ON
;
135 if ($javascript_setting != SMPREF_JS_ON
){
136 if ($javascript_setting == SMPREF_JS_AUTODETECT
) {
137 if ($js_autodetect_results == SMPREF_JS_OFF
) {
138 $js_pref = SMPREF_JS_OFF
;
141 $js_pref = SMPREF_JS_OFF
;
144 /* Update the prefs */
145 setPref($data_dir, $username, 'javascript_on', $js_pref);
147 /* Compute the URL to forward the user to. */
148 $redirect_url = 'webmail.php';
150 if ( sqgetGlobalVar('session_expired_location', $session_expired_location, SQ_SESSION
) ) {
151 sqsession_unregister('session_expired_location');
152 $compose_new_win = getPref($data_dir, $username, 'compose_new_win', 0);
153 if ($compose_new_win) {
154 $redirect_url = $session_expired_location;
155 } elseif ( strpos($session_expired_location, 'webmail.php') === FALSE ) {
156 $redirect_url = 'webmail.php?right_frame='.urldecode($session_expired_location);
158 unset($session_expired_location);
161 /* Write session data and send them off to the appropriate page. */
162 session_write_close();
163 header("Location: $redirect_url");
165 /* --------------------- end main ----------------------- */
167 function attachment_common_parse($str, $debug) {
168 global $attachment_common_types, $attachment_common_types_parsed;
170 $attachment_common_types_parsed[$str] = true;
173 * Replace ", " with "," and explode on that as Mozilla 1.x seems to
174 * use "," to seperate whilst IE, and earlier versions of Mozilla use
178 $str = str_replace( ', ' , ',' , $str );
179 $types = explode(',', $str);
181 foreach ($types as $val) {
182 // Ignore the ";q=1.0" stuff
183 if (strpos($val, ';') !== false)
184 $val = substr($val, 0, strpos($val, ';'));
186 if (! isset($attachment_common_types[$val])) {
187 $attachment_common_types[$val] = true;
190 $_SESSION['attachment_common_types'] = $attachment_common_types;