* Got bored and copied all the validate.php and define() stuff to 1.1
[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 include ('../functions/strings.php');
17 include('../config/config.php');
18
19 // Before starting the session, the base URI must be known.
20 // Assuming that this file is in the src/ subdirectory (or
21 // something).
22 ereg ("(^.*/)[^/]+/[^/]+$", $PHP_SELF, $regs);
23 $base_uri = $regs[1];
24
25 header('Pragma: no-cache');
26 $location = get_location();
27
28 session_set_cookie_params (0, $base_uri);
29 session_start();
30
31 session_unregister ('user_is_logged_in');
32 session_register ('base_uri');
33
34 if(!isset($login_username)) {
35 echo "<html><body bgcolor=\"ffffff\">\n";
36 echo "<br><br>";
37 echo "<center>";
38 echo "<b>"._("You must be logged in to access this page.")."</b><br>";
39 echo "<a href=\"../src/login.php\">"._("Go to the login page")."</a>\n";
40 echo "</center>";
41 echo "</body></html>\n";
42 exit;
43 }
44
45 // Refresh the language cookie.
46 if (isset($squirrelmail_language)) {
47 setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000);
48 }
49
50
51 include ('../functions/prefs.php');
52 include ('../functions/imap.php');
53 include ('../functions/plugin.php');
54
55 if (!session_is_registered('user_is_logged_in') || $logged_in != 1) {
56 do_hook ('login_before');
57
58 $onetimepad = OneTimePadCreate(strlen($secretkey));
59 $key = OneTimePadEncrypt($secretkey, $onetimepad);
60 session_register('onetimepad');
61 // verify that username and password are correct
62 if ($force_username_lowercase)
63 $login_username = strtolower($login_username);
64 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
65 if (!$imapConnection) {
66 echo "<html><body bgcolor=\"ffffff\">\n";
67 echo "<br><br>";
68 echo "<center>";
69 echo "<b>"._("There was an error contacting the mail server.")."</b><br>";
70 echo _("Contact your administrator for help.")."\n";
71 echo "</center>";
72 echo "</body></html>\n";
73 exit;
74 }
75 sqimap_logout($imapConnection);
76
77 setcookie('username', $login_username, 0, $base_uri);
78 setcookie('key', $key, 0, $base_uri);
79 setcookie('logged_in', 1, 0, $base_uri);
80 do_hook ('login_verified');
81 }
82
83 $user_is_logged_in = true;
84 session_register ('user_is_logged_in');
85
86 header("Location: webmail.php");
87 ?>