phpBB
Statistics
| Revision:

root / tags / release_2_0_1 / phpBB / login.php

History | View | Annotate | Download (6.8 kB)

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