phpBB
Statistics
| Revision:

root / tags / release_2_0_2 / phpBB / login.php

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