argh! (forgot to remove debug code, done now)
[squirrelmail.git] / src / redirect.php
1 <?php
2
3 /**
4 ** redirect.php -- derived from webmail.php by Ralf Kraudelt
5 ** kraude@wiwi.uni-rostock.de
6 **
7 ** Copyright (c) 1999-2000 ...
8 ** Licensed under the GNU GPL. For full terms see the file COPYING.
9 **
10 ** prevents users from reposting their form data after a
11 ** successful logout
12 **
13 ** $Id$
14 **/
15
16 require_once('../functions/i18n.php');
17 require_once('../functions/strings.php');
18 require_once('../config/config.php');
19
20 // Before starting the session, the base URI must be known.
21 // Assuming that this file is in the src/ subdirectory (or
22 // something).
23 ereg ("(^.*/)[^/]+/[^/]+$", $PHP_SELF, $regs);
24 $base_uri = $regs[1];
25
26 header('Pragma: no-cache');
27 $location = get_location();
28
29 session_set_cookie_params (0, $base_uri);
30 session_start();
31
32 session_unregister ('user_is_logged_in');
33 session_register ('base_uri');
34
35 if (! isset($squirrelmail_language))
36 $squirrelmail_language = '';
37 set_up_language($squirrelmail_language, true);
38
39 if(!isset($login_username)) {
40 echo "<html><body bgcolor=\"#ffffff\">\n";
41 echo "<br><br>";
42 echo "<center>";
43 echo "<b>"._("You must be logged in to access this page.")."</b><br>";
44 echo "<a href=\"../src/login.php\">"._("Go to the login page")."</a>\n";
45 echo "</center>";
46 echo "</body></html>\n";
47 exit;
48 }
49
50 // Refresh the language cookie.
51 if (isset($squirrelmail_language)) {
52 setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,$base_uri);
53 }
54
55
56 require_once('../functions/prefs.php');
57 require_once('../functions/imap.php');
58 require_once('../functions/plugin.php');
59
60 if (!session_is_registered('user_is_logged_in')) {
61 do_hook ('login_before');
62
63 $onetimepad = OneTimePadCreate(strlen($secretkey));
64 $key = OneTimePadEncrypt($secretkey, $onetimepad);
65 session_register('onetimepad');
66 // verify that username and password are correct
67 if ($force_username_lowercase)
68 $login_username = strtolower($login_username);
69
70 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
71 if (!$imapConnection) {
72 echo "<html><body bgcolor=\"#ffffff\">\n";
73 echo "<br><br>";
74 echo "<center>";
75 echo "<b>"._("There was an error contacting the mail server.")."</b><br>";
76 echo _("Contact your administrator for help.")."\n";
77 echo "</center>";
78 echo "</body></html>\n";
79 exit;
80 } else {
81 $delimiter = sqimap_get_delimiter ($imapConnection);
82 }
83 sqimap_logout($imapConnection);
84
85 $username = $login_username;
86 session_register ('username');
87 setcookie('key', $key, 0, $base_uri);
88 setcookie('delimiter', $delimiter, 0, $base_uri);
89 do_hook ('login_verified');
90 }
91
92 $user_is_logged_in = true;
93 session_register ('user_is_logged_in');
94 $just_logged_in = true;
95 session_register ('just_logged_in');
96
97 if(isset($rcptemail))
98 header("Location: webmail.php?right_frame=compose.php&rcptaddress=" .
99 urlencode($rcptemail));
100 else
101 header("Location: webmail.php");
102 ?>