phpBB
Statistics
| Revision:

root / tags / release_2_0_2 / phpBB / login.php

History | View | Annotate | Download (6.9 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 2648 dougk_ff7
                                        $redirect = str_replace("?", "&", $redirect);
102 2648 dougk_ff7
103 1490 psotfx
                                        $template->assign_vars(array(
104 2448 psotfx
                                                'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("login.$phpEx?redirect=$redirect") . '">')
105 1490 psotfx
                                        );
106 1263 psotfx
107 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>');
108 1511 psotfx
109 1490 psotfx
                                        message_die(GENERAL_MESSAGE, $message);
110 1490 psotfx
                                }
111 119 psotfx
                        }
112 119 psotfx
                }
113 119 psotfx
                else
114 119 psotfx
                {
115 1264 psotfx
                        $redirect = ( !empty($HTTP_POST_VARS['redirect']) ) ? $HTTP_POST_VARS['redirect'] : "";
116 2648 dougk_ff7
                        $redirect = str_replace("?", "&", $redirect);
117 1264 psotfx
118 1264 psotfx
                        $template->assign_vars(array(
119 2448 psotfx
                                'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("login.$phpEx?redirect=$redirect") . '">')
120 1264 psotfx
                        );
121 1264 psotfx
122 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>');
123 1511 psotfx
124 1264 psotfx
                        message_die(GENERAL_MESSAGE, $message);
125 119 psotfx
                }
126 106 thefinn
        }
127 1183 psotfx
        else if( ( isset($HTTP_GET_VARS['logout']) || isset($HTTP_POST_VARS['logout']) ) && $userdata['session_logged_in'] )
128 106 thefinn
        {
129 1183 psotfx
                if( $userdata['session_logged_in'] )
130 119 psotfx
                {
131 281 psotfx
                        session_end($userdata['session_id'], $userdata['user_id']);
132 106 thefinn
                }
133 1190 psotfx
134 1190 psotfx
                if( !empty($HTTP_POST_VARS['redirect']) )
135 223 thefinn
                {
136 1972 psotfx
                        header($header_location . append_sid($HTTP_POST_VARS['redirect'], true));
137 2575 psotfx
                        exit;
138 223 thefinn
                }
139 223 thefinn
                else
140 223 thefinn
                {
141 1972 psotfx
                        header($header_location . append_sid("index.$phpEx", true));
142 2575 psotfx
                        exit;
143 223 thefinn
                }
144 106 thefinn
        }
145 119 psotfx
        else
146 119 psotfx
        {
147 1190 psotfx
                if( !empty($HTTP_POST_VARS['redirect']) )
148 223 thefinn
                {
149 1972 psotfx
                        header($header_location . append_sid($HTTP_POST_VARS['redirect'], true));
150 2575 psotfx
                        exit;
151 223 thefinn
                }
152 223 thefinn
                else
153 223 thefinn
                {
154 1972 psotfx
                        header($header_location . append_sid("index.$phpEx", true));
155 2575 psotfx
                        exit;
156 223 thefinn
                }
157 119 psotfx
        }
158 65 thefinn
}
159 119 psotfx
else
160 65 thefinn
{
161 190 psotfx
        //
162 490 psotfx
        // Do a full login page dohickey if
163 490 psotfx
        // user not already logged in
164 190 psotfx
        //
165 1496 psotfx
        if( !$userdata['session_logged_in'] )
166 223 thefinn
        {
167 1999 psotfx
                $page_title = $lang['Login'];
168 646 psotfx
                include($phpbb_root_path . 'includes/page_header.'.$phpEx);
169 646 psotfx
170 490 psotfx
                $template->set_filenames(array(
171 2448 psotfx
                        'body' => 'login_body.tpl')
172 490 psotfx
                );
173 249 psotfx
174 1190 psotfx
                if( isset($HTTP_POST_VARS['redirect']) || isset($HTTP_GET_VARS['redirect']) )
175 490 psotfx
                {
176 1190 psotfx
                        $forward_to = $HTTP_SERVER_VARS['QUERY_STRING'];
177 943 thefinn
178 1190 psotfx
                        if( preg_match("/^redirect=(.*)$/si", $forward_to, $forward_matches) )
179 490 psotfx
                        {
180 1999 psotfx
                                $forward_to = ( !empty($forward_matches[3]) ) ? $forward_matches[3] : $forward_matches[1];
181 2448 psotfx
                                $forward_match = explode('&', $forward_to);
182 256 psotfx
183 490 psotfx
                                if(count($forward_match) > 1)
184 490 psotfx
                                {
185 2448 psotfx
                                        $forward_page = '';
186 256 psotfx
187 490 psotfx
                                        for($i = 1; $i < count($forward_match); $i++)
188 490 psotfx
                                        {
189 1190 psotfx
                                                if( !ereg("sid=", $forward_match[$i]) )
190 490 psotfx
                                                {
191 2448 psotfx
                                                        if( $forward_page != '' )
192 1190 psotfx
                                                        {
193 2448 psotfx
                                                                $forward_page .= '&';
194 1190 psotfx
                                                        }
195 1190 psotfx
                                                        $forward_page .= $forward_match[$i];
196 490 psotfx
                                                }
197 490 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
?>