Croatian Credits
[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-2001 The Squirrelmail Development 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 * $Id$
13 */
14
15 /*****************************************************************/
16 /*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
17 /*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
18 /*** + Base level indent should begin at left margin, as ***/
19 /*** the require_once below looks. ***/
20 /*** + All identation should consist of four space blocks ***/
21 /*** + Tab characters are evil. ***/
22 /*** + all comments should use "slash-star ... star-slash" ***/
23 /*** style -- no pound characters, no slash-slash style ***/
24 /*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
25 /*** ALWAYS USE { AND } CHARACTERS!!! ***/
26 /*** + Please use ' instead of ", when possible. Note " ***/
27 /*** should always be used in _( ) function calls. ***/
28 /*** Thank you for your help making the SM code more readable. ***/
29 /*****************************************************************/
30
31 require_once('../functions/i18n.php');
32 require_once('../functions/strings.php');
33 require_once('../config/config.php');
34 require_once('../functions/prefs.php');
35 require_once('../functions/imap.php');
36 require_once('../functions/plugin.php');
37 require_once('../functions/constants.php');
38 require_once('../functions/page_header.php');
39
40 function attachment_common_parse($str, $debug) {
41 global $attachment_common_types, $attachment_common_types_parsed;
42
43 $attachment_common_types_parsed[$str] = true;
44 $types = explode(', ', $str);
45
46 foreach ($types as $val) {
47 // Ignore the ";q=1.0" stuff
48 if (strpos($val, ';') !== false)
49 $val = substr($val, 0, strpos($val, ';'));
50
51 if (! isset($attachment_common_types[$val])) {
52 $attachment_common_types[$val] = true;
53 }
54 }
55 }
56
57
58 /* Before starting the session, the base URI must be known. Assuming */
59 /* that this file is in the src/ subdirectory (or something). */
60 ereg ("(^.*/)[^/]+/[^/]+$", $PHP_SELF, $regs);
61 $base_uri = $regs[1];
62
63 header('Pragma: no-cache');
64 $location = get_location();
65
66 session_set_cookie_params (0, $base_uri);
67 session_start();
68
69 session_unregister ('user_is_logged_in');
70 session_register ('base_uri');
71
72 if (! isset($squirrelmail_language) ||
73 $squirrelmail_language == '' ) {
74 $squirrelmail_language = $squirrelmail_default_language;
75 }
76 set_up_language($squirrelmail_language, true);
77 /* Refresh the language cookie. */
78 setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,$base_uri);
79
80 if (!isset($login_username)) {
81 displayHtmlHeader( _("You must be logged in to access this page.") );
82 echo "<BODY BGCOLOR=\"#ffffff\">\n" .
83 "<BR>&nbsp;<BR>\n" .
84 "<CENTER>\n" .
85 '<B>' . _("You must be logged in to access this page.") . "</B><BR>" .
86 '<A HREF="../src/login.php">' . _("Go to the login page") . "</A>\n" .
87 "</CENTER>\n" .
88 "</BODY></HTML>\n";
89 exit;
90 }
91
92 if (!session_is_registered('user_is_logged_in')) {
93 do_hook ('login_before');
94
95 $onetimepad = OneTimePadCreate(strlen($secretkey));
96 $key = OneTimePadEncrypt($secretkey, $onetimepad);
97 session_register('onetimepad');
98
99 /* Verify that username and password are correct. */
100 if ($force_username_lowercase) {
101 $login_username = strtolower($login_username);
102 }
103
104 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
105 if (!$imapConnection) {
106 displayHtmlHeader( _("There was an error contacting the mail server.") );
107 echo "<body bgcolor=\"#ffffff\">\n".
108 "<br> <br>\n".
109 "<center>\n".
110 '<b>' . _("There was an error contacting the mail server.") . "</b><br>\n".
111 _("Contact your administrator for help.") . "\n".
112 "</center>\n".
113 "</body></html>\n";
114 exit;
115 } else {
116 $delimiter = sqimap_get_delimiter ($imapConnection);
117 }
118 sqimap_logout($imapConnection);
119 session_register('delimiter');
120
121 $username = $login_username;
122 session_register ('username');
123 setcookie('key', $key, 0, $base_uri);
124 do_hook ('login_verified');
125
126 }
127
128 /* Set the login variables. */
129 $user_is_logged_in = true;
130 $just_logged_in = true;
131
132 /* And register with them with the session. */
133 session_register ('user_is_logged_in');
134 session_register ('just_logged_in');
135
136 /* parse the accepted content-types of the client */
137 $attachment_common_types = array();
138 $attachment_common_types_parsed = array();
139 session_register('attachment_common_types');
140 session_register('attachment_common_types_parsed');
141
142 $debug = false;
143 if (isset($HTTP_SERVER_VARS['HTTP_ACCEPT']) &&
144 !isset($attachment_common_types_parsed[$HTTP_SERVER_VARS['HTTP_ACCEPT']]))
145 attachment_common_parse($HTTP_SERVER_VARS['HTTP_ACCEPT'], $debug);
146 if (isset($HTTP_ACCEPT) &&
147 !isset($attachment_common_types_parsed[$HTTP_ACCEPT]))
148 attachment_common_parse($HTTP_ACCEPT, $debug);
149
150
151 /* Complete autodetection of Javascript. */
152 checkForPrefs($data_dir, $username);
153 $javascript_setting = getPref($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT);
154 $js_autodetect_results = (isset($js_autodetect_results) ? $js_autodetect_results : SMPREF_JS_OFF);
155 if ($javascript_setting == SMPREF_JS_AUTODETECT) {
156 if ($js_autodetect_results == SMPREF_JS_ON) {
157 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_ON);
158 } else {
159 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_OFF);
160 }
161 } else {
162 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_OFF);
163 }
164
165 /* Compute the URL to forward the user to. */
166 if(isset($rcptemail)) {
167 $redirect_url = 'webmail.php?right_frame=compose.php&rcptaddress=';
168 $redirect_url .= urlencode($rcptemail);
169 } else {
170 $redirect_url = 'webmail.php';
171 }
172
173 /* Send them off to the appropriate page. */
174 header("Location: $redirect_url");
175
176 ?>