* Got bored and copied all the validate.php and define() stuff to 1.1
[squirrelmail.git] / src / redirect.php
CommitLineData
7392739d 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 **
245a6892 13 ** $Id$
7392739d 14 **/
15
f740c049 16 include ('../functions/strings.php');
91dc6e4e 17 include('../config/config.php');
7392739d 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
91dc6e4e 25 header('Pragma: no-cache');
7392739d 26 $location = get_location();
7392739d 27
28 session_set_cookie_params (0, $base_uri);
29 session_start();
30
f740c049 31 session_unregister ('user_is_logged_in');
91dc6e4e 32 session_register ('base_uri');
7392739d 33
74b4e396 34 if(!isset($login_username)) {
f740c049 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";
7392739d 42 exit;
43 }
44
45 // Refresh the language cookie.
46 if (isset($squirrelmail_language)) {
91dc6e4e 47 setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000);
7392739d 48 }
49
50
91dc6e4e 51 include ('../functions/prefs.php');
52 include ('../functions/imap.php');
f740c049 53 include ('../functions/plugin.php');
7392739d 54
91dc6e4e 55 if (!session_is_registered('user_is_logged_in') || $logged_in != 1) {
56 do_hook ('login_before');
7392739d 57
58 $onetimepad = OneTimePadCreate(strlen($secretkey));
8c42b963 59 $key = OneTimePadEncrypt($secretkey, $onetimepad);
91dc6e4e 60 session_register('onetimepad');
7392739d 61 // verify that username and password are correct
74b4e396 62 if ($force_username_lowercase)
8ddd44cd 63 $login_username = strtolower($login_username);
74b4e396 64 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
86bb3b47 65 if (!$imapConnection) {
f740c049 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;
86bb3b47 74 }
7392739d 75 sqimap_logout($imapConnection);
76
91dc6e4e 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');
7392739d 81 }
82
7392739d 83 $user_is_logged_in = true;
f740c049 84 session_register ('user_is_logged_in');
7392739d 85
f740c049 86 header("Location: webmail.php");
7392739d 87?>