phpBB
Statistics
| Revision:

root / tags / release_2_0_1 / phpBB / login.php

History | View | Annotate | Download (6.8 kB)

1 65 thefinn
<?php
2 943 thefinn
/***************************************************************************
3 932 psotfx
 *                                login.php
4 943 thefinn
 *                            -------------------
5 943 thefinn
 *   begin                : Saturday, Feb 13, 2001
6 943 thefinn
 *   copyright            : (C) 2001 The phpBB Group
7 943 thefinn
 *   email                : support@phpbb.com
8 943 thefinn
 *
9 65 thefinn
 *   $Id$
10 943 thefinn
 *
11 943 thefinn
 *
12 943 thefinn
 ***************************************************************************/
13 65 thefinn
14 943 thefinn
/***************************************************************************
15 943 thefinn
 *
16 943 thefinn
 *   This program is free software; you can redistribute it and/or modify
17 943 thefinn
 *   it under the terms of the GNU General Public License as published by
18 943 thefinn
 *   the Free Software Foundation; either version 2 of the License, or
19 943 thefinn
 *   (at your option) any later version.
20 943 thefinn
 *
21 943 thefinn
 ***************************************************************************/
22 943 thefinn
23 1490 psotfx
//
24 1490 psotfx
// Allow people to reach login page if
25 1490 psotfx
// board is shut down
26 1490 psotfx
//
27 1511 psotfx
define("IN_LOGIN", true);
28 1490 psotfx
29 2305 psotfx
define('IN_PHPBB', true);
30 2448 psotfx
$phpbb_root_path = './';
31 646 psotfx
include($phpbb_root_path . 'extension.inc');
32 646 psotfx
include($phpbb_root_path . 'common.'.$phpEx);
33 65 thefinn
34 145 psotfx
//
35 145 psotfx
// Set page ID for session management
36 145 psotfx
//
37 1999 psotfx
$userdata = session_pagestart($user_ip, PAGE_LOGIN);
38 145 psotfx
init_userprefs($userdata);
39 145 psotfx
//
40 145 psotfx
// End session management
41 145 psotfx
//
42 145 psotfx
43 2448 psotfx
$header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
44 2448 psotfx
45 1183 psotfx
if( isset($HTTP_POST_VARS['login']) || isset($HTTP_GET_VARS['login']) || isset($HTTP_POST_VARS['logout']) || isset($HTTP_GET_VARS['logout']) )
46 65 thefinn
{
47 1972 psotfx
        //
48 1972 psotfx
        // This appears to work for IIS5 CGI under Win2K. Uses getenv
49 1972 psotfx
        // since this doesn't exist for ISAPI mode and therefore the
50 1972 psotfx
        // normal Location redirector is used in preference
51 1972 psotfx
        //
52 1183 psotfx
        if( ( isset($HTTP_POST_VARS['login']) || isset($HTTP_GET_VARS['login']) ) && !$userdata['session_logged_in'] )
53 119 psotfx
        {
54 2448 psotfx
                $username = isset($HTTP_POST_VARS['username']) ? $HTTP_POST_VARS['username'] : '';
55 2448 psotfx
                $password = isset($HTTP_POST_VARS['password']) ? $HTTP_POST_VARS['password'] : '';
56 119 psotfx
57 1490 psotfx
                $sql = "SELECT user_id, username, user_password, user_active, user_level
58 2166 psotfx
                        FROM " . USERS_TABLE . "
59 1661 psotfx
                        WHERE username = '" . str_replace("\'", "''", $username) . "'";
60 2166 psotfx
                if ( !($result = $db->sql_query($sql)) )
61 119 psotfx
                {
62 2448 psotfx
                        message_die(GENERAL_ERROR, 'Error in obtaining userdata', '', __LINE__, __FILE__, $sql);
63 119 psotfx
                }
64 943 thefinn
65 2166 psotfx
                if( $row = $db->sql_fetchrow($result) )
66 119 psotfx
                {
67 2166 psotfx
                        if( $row['user_level'] != ADMIN && $board_config['board_disable'] )
68 943 thefinn
                        {
69 1972 psotfx
                                header($header_location . append_sid("index.$phpEx", true));
70 2575 psotfx
                                exit;
71 1490 psotfx
                        }
72 1490 psotfx
                        else
73 1490 psotfx
                        {
74 2166 psotfx
                                if( md5($password) == $row['user_password'] && $row['user_active'] )
75 1490 psotfx
                                {
76 1490 psotfx
                                        $autologin = ( isset($HTTP_POST_VARS['autologin']) ) ? TRUE : 0;
77 208 psotfx
78 2166 psotfx
                                        $session_id = session_begin($row['user_id'], $user_ip, PAGE_INDEX, FALSE, $autologin);
79 490 psotfx
80 1490 psotfx
                                        if( $session_id )
81 223 thefinn
                                        {
82 1490 psotfx
                                                if( !empty($HTTP_POST_VARS['redirect']) )
83 1490 psotfx
                                                {
84 1972 psotfx
                                                        header($header_location . append_sid($HTTP_POST_VARS['redirect'], true));
85 2575 psotfx
                                                        exit;
86 1490 psotfx
                                                }
87 1490 psotfx
                                                else
88 1490 psotfx
                                                {
89 1972 psotfx
                                                        header($header_location . append_sid("index.$phpEx", true));
90 2575 psotfx
                                                        exit;
91 1490 psotfx
                                                }
92 223 thefinn
                                        }
93 223 thefinn
                                        else
94 223 thefinn
                                        {
95 1496 psotfx
                                                message_die(CRITICAL_ERROR, "Couldn't start session : login", "", __LINE__, __FILE__);
96 223 thefinn
                                        }
97 119 psotfx
                                }
98 119 psotfx
                                else
99 119 psotfx
                                {
100 2448 psotfx
                                        $redirect = ( !empty($HTTP_POST_VARS['redirect']) ) ? $HTTP_POST_VARS['redirect'] : '';
101 1264 psotfx
102 1490 psotfx
                                        $template->assign_vars(array(
103 2448 psotfx
                                                'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("login.$phpEx?redirect=$redirect") . '">')
104 1490 psotfx
                                        );
105 1263 psotfx
106 2351 dougk_ff7
                                        $message = $lang['Error_login'] . '<br /><br />' . sprintf($lang['Click_return_login'], '<a href="' . append_sid("login.$phpEx?redirect=$redirect") . '">', '</a>') . '<br /><br />' .  sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');
107 1511 psotfx
108 1490 psotfx
                                        message_die(GENERAL_MESSAGE, $message);
109 1490 psotfx
                                }
110 119 psotfx
                        }
111 119 psotfx
                }
112 119 psotfx
                else
113 119 psotfx
                {
114 1264 psotfx
                        $redirect = ( !empty($HTTP_POST_VARS['redirect']) ) ? $HTTP_POST_VARS['redirect'] : "";
115 1264 psotfx
116 1264 psotfx
                        $template->assign_vars(array(
117 2448 psotfx
                                'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("login.$phpEx?redirect=$redirect") . '">')
118 1264 psotfx
                        );
119 1264 psotfx
120 2351 dougk_ff7
                        $message = $lang['Error_login'] . '<br /><br />' . sprintf($lang['Click_return_login'], '<a href="' . append_sid("login.$phpEx?redirect=$redirect") . '">', '</a>') . '<br /><br />' .  sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');
121 1511 psotfx
122 1264 psotfx
                        message_die(GENERAL_MESSAGE, $message);
123 119 psotfx
                }
124 106 thefinn
        }
125 1183 psotfx
        else if( ( isset($HTTP_GET_VARS['logout']) || isset($HTTP_POST_VARS['logout']) ) && $userdata['session_logged_in'] )
126 106 thefinn
        {
127 1183 psotfx
                if( $userdata['session_logged_in'] )
128 119 psotfx
                {
129 281 psotfx
                        session_end($userdata['session_id'], $userdata['user_id']);
130 106 thefinn
                }
131 1190 psotfx
132 1190 psotfx
                if( !empty($HTTP_POST_VARS['redirect']) )
133 223 thefinn
                {
134 1972 psotfx
                        header($header_location . append_sid($HTTP_POST_VARS['redirect'], true));
135 2575 psotfx
                        exit;
136 223 thefinn
                }
137 223 thefinn
                else
138 223 thefinn
                {
139 1972 psotfx
                        header($header_location . append_sid("index.$phpEx", true));
140 2575 psotfx
                        exit;
141 223 thefinn
                }
142 106 thefinn
        }
143 119 psotfx
        else
144 119 psotfx
        {
145 1190 psotfx
                if( !empty($HTTP_POST_VARS['redirect']) )
146 223 thefinn
                {
147 1972 psotfx
                        header($header_location . append_sid($HTTP_POST_VARS['redirect'], true));
148 2575 psotfx
                        exit;
149 223 thefinn
                }
150 223 thefinn
                else
151 223 thefinn
                {
152 1972 psotfx
                        header($header_location . append_sid("index.$phpEx", true));
153 2575 psotfx
                        exit;
154 223 thefinn
                }
155 119 psotfx
        }
156 65 thefinn
}
157 119 psotfx
else
158 65 thefinn
{
159 190 psotfx
        //
160 490 psotfx
        // Do a full login page dohickey if
161 490 psotfx
        // user not already logged in
162 190 psotfx
        //
163 1496 psotfx
        if( !$userdata['session_logged_in'] )
164 223 thefinn
        {
165 1999 psotfx
                $page_title = $lang['Login'];
166 646 psotfx
                include($phpbb_root_path . 'includes/page_header.'.$phpEx);
167 646 psotfx
168 490 psotfx
                $template->set_filenames(array(
169 2448 psotfx
                        'body' => 'login_body.tpl')
170 490 psotfx
                );
171 249 psotfx
172 1190 psotfx
                if( isset($HTTP_POST_VARS['redirect']) || isset($HTTP_GET_VARS['redirect']) )
173 490 psotfx
                {
174 1190 psotfx
                        $forward_to = $HTTP_SERVER_VARS['QUERY_STRING'];
175 943 thefinn
176 1190 psotfx
                        if( preg_match("/^redirect=(.*)$/si", $forward_to, $forward_matches) )
177 490 psotfx
                        {
178 1999 psotfx
                                $forward_to = ( !empty($forward_matches[3]) ) ? $forward_matches[3] : $forward_matches[1];
179 249 psotfx
180 2448 psotfx
                                $forward_match = explode('&', $forward_to);
181 256 psotfx
182 490 psotfx
                                if(count($forward_match) > 1)
183 490 psotfx
                                {
184 2448 psotfx
                                        $forward_page = '';
185 256 psotfx
186 490 psotfx
                                        for($i = 1; $i < count($forward_match); $i++)
187 490 psotfx
                                        {
188 1190 psotfx
                                                if( !ereg("sid=", $forward_match[$i]) )
189 490 psotfx
                                                {
190 2448 psotfx
                                                        if( $forward_page != '' )
191 1190 psotfx
                                                        {
192 2448 psotfx
                                                                $forward_page .= '&';
193 1190 psotfx
                                                        }
194 1190 psotfx
                                                        $forward_page .= $forward_match[$i];
195 490 psotfx
                                                }
196 490 psotfx
                                        }
197 1190 psotfx
198 2448 psotfx
                                        $forward_page = $forward_match[0] . '?' . $forward_page;
199 490 psotfx
                                }
200 646 psotfx
                                else
201 646 psotfx
                                {
202 646 psotfx
                                        $forward_page = $forward_match[0];
203 646 psotfx
                                }
204 490 psotfx
                        }
205 490 psotfx
                }
206 646 psotfx
                else
207 646 psotfx
                {
208 2448 psotfx
                        $forward_page = '';
209 646 psotfx
                }
210 190 psotfx
211 2448 psotfx
                $username = ( $userdata['user_id'] != ANONYMOUS ) ? $userdata['username'] : '';
212 943 thefinn
213 1190 psotfx
                $s_hidden_fields = '<input type="hidden" name="redirect" value="' . $forward_page . '" />';
214 1190 psotfx
215 2448 psotfx
                make_jumpbox('viewforum.'.$phpEx, $forum_id);
216 490 psotfx
                $template->assign_vars(array(
217 2448 psotfx
                        'USERNAME' => $username,
218 190 psotfx
219 2448 psotfx
                        'L_ENTER_PASSWORD' => $lang['Enter_password'],
220 2448 psotfx
                        'L_SEND_PASSWORD' => $lang['Forgotten_password'],
221 190 psotfx
222 2448 psotfx
                        'U_SEND_PASSWORD' => append_sid("profile.$phpEx?mode=sendpassword"),
223 1190 psotfx
224 2448 psotfx
                        'S_HIDDEN_FIELDS' => $s_hidden_fields)
225 490 psotfx
                );
226 490 psotfx
227 2448 psotfx
                $template->pparse('body');
228 490 psotfx
229 646 psotfx
                include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
230 490 psotfx
        }
231 490 psotfx
        else
232 490 psotfx
        {
233 2448 psotfx
                header($header_location . append_sid("index.$phpEx", true));
234 2575 psotfx
                exit;
235 490 psotfx
        }
236 490 psotfx
237 65 thefinn
}
238 119 psotfx
239 2448 psotfx
?>