Modified sqimap_session_id to return something when there is no session ID
[squirrelmail.git] / src / redirect.php
CommitLineData
7392739d 1<?php
895905c0 2
23d6bd09 3 /**
895905c0 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 **/
23d6bd09 14
15 require_once('../functions/i18n.php');
16 require_once('../functions/strings.php');
17 require_once('../config/config.php');
18
19 /* Before starting the session, the base URI must be known. Assuming */
20 /* that this file is in the src/ subdirectory (or something). */
21 ereg ("(^.*/)[^/]+/[^/]+$", $PHP_SELF, $regs);
22 $base_uri = $regs[1];
23
24 header('Pragma: no-cache');
25 $location = get_location();
26
27 session_set_cookie_params (0, $base_uri);
28 session_start();
29
30 session_unregister ('user_is_logged_in');
31 session_register ('base_uri');
32
33 if (! isset($squirrelmail_language)) {
34 $squirrelmail_language = '';
35 }
36 set_up_language($squirrelmail_language, true);
37
38 if (!isset($login_username)) {
39 echo "<HTML><BODY BGCOLOR=\"#ffffff\">\n";
40 echo "<BR><BR>\n";
41 echo "<CENTER>\n";
42 echo ' <B>' . _("You must be logged in to access this page.") . "</B><BR>";
43 echo ' <A HREF="../src/login.php">' . _("Go to the login page") . "</A>\n";
44 echo "</CENTER>\n";
45 echo "</BODY></HTML>\n";
46 exit;
47 }
48
49 /* Refresh the language cookie. */
50 if (isset($squirrelmail_language)) {
51 setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,$base_uri);
52 }
53
54 require_once('../functions/prefs.php');
55 require_once('../functions/imap.php');
56 require_once('../functions/plugin.php');
57 require_once('../functions/constants.php');
58
59 if (!session_is_registered('user_is_logged_in')) {
60 do_hook ('login_before');
61
62 $onetimepad = OneTimePadCreate(strlen($secretkey));
63 $key = OneTimePadEncrypt($secretkey, $onetimepad);
64 session_register('onetimepad');
65
66 /* Verify that username and password are correct. */
67 if ($force_username_lowercase) {
68 $login_username = strtolower($login_username);
69 }
70
71 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
72 if (!$imapConnection) {
73 echo "<html><body bgcolor=\"#ffffff\">\n";
74 echo "<br><br>";
75 echo "<center>";
76 echo "<b>"._("There was an error contacting the mail server.")."</b><br>";
77 echo _("Contact your administrator for help.")."\n";
78 echo "</center>";
79 echo "</body></html>\n";
80 exit;
81 } else {
82 $delimiter = sqimap_get_delimiter ($imapConnection);
83 }
84 sqimap_logout($imapConnection);
525b7ae6 85 session_register('delimiter');
23d6bd09 86
87 $username = $login_username;
88 session_register ('username');
89 setcookie('key', $key, 0, $base_uri);
23d6bd09 90 do_hook ('login_verified');
91 }
92
93 /* Set the login variables. */
94 $user_is_logged_in = true;
95 $just_logged_in = true;
96
97 /* And register with them with the session. */
98 session_register ('user_is_logged_in');
99 session_register ('just_logged_in');
100
7baf86a9 101 /* parse the accepted content-types of the client */
102 $attachment_common_types = array();
103 $attachment_common_types_parsed = array();
104 session_register('attachment_common_types');
105 session_register('attachment_common_types_parsed');
106
107 if (isset($HTTP_SERVER_VARS['HTTP_ACCEPT']) &&
108 !isset($attachment_common_types_parsed[$HTTP_SERVER_VARS['HTTP_ACCEPT']]))
109 attachment_common_parse($HTTP_SERVER_VARS['HTTP_ACCEPT'], $debug);
110 if (isset($HTTP_ACCEPT) &&
111 !isset($attachment_common_types_parsed[$HTTP_ACCEPT]))
112 attachment_common_parse($HTTP_ACCEPT, $debug);
113
114
23d6bd09 115 /* Complete autodetection of Javascript. */
357f1ae0 116 checkForPrefs($data_dir, $username);
23d6bd09 117 $javascript_setting = getPref($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT);
118 $js_autodetect_results = (isset($js_autodetect_results) ? $js_autodetect_results : SMPREF_JS_OFF);
119 if ($javascript_setting == SMPREF_JS_AUTODETECT) {
120 if ($js_autodetect_results == SMPREF_JS_ON) {
121 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_ON);
122 } else {
123 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_OFF);
124 }
125 } else {
126 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_OFF);
127 }
128
129 /* Compute the URL to forward the user to. */
130 if(isset($rcptemail)) {
131 $redirect_url = 'webmail.php?right_frame=compose.php&rcptaddress=';
132 $redirect_url .= urlencode($rcptemail);
133 } else {
134 $redirect_url = 'webmail.php';
135 }
136
137 /* Send them off to the appropriate page. */
138 header("Location: $redirect_url");
7baf86a9 139
140
141function attachment_common_parse($str, $debug)
142{
143 global $attachment_common_types, $attachment_common_types_parsed;
144
145 $attachment_common_types_parsed[$str] = true;
146 $types = explode(', ', $str);
147
148 foreach ($types as $val)
149 {
150 // Ignore the ";q=1.0" stuff
151 if (strpos($val, ';') !== false)
152 $val = substr($val, 0, strpos($val, ';'));
153
154 if (! isset($attachment_common_types[$val])) {
155 $attachment_common_types[$val] = true;
156 }
157 }
158}
159
e0dcff78 160?>