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