]> git.vanrenterghem.biz Git - www.vanrenterghem.biz.git/blob - phpBB2_old/login.php
cb679bd9c732914216f889a597fc773ab76682f6
[www.vanrenterghem.biz.git] / phpBB2_old / login.php
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,v 1.47.2.17 2004/11/18 17:49:35 acydburn Exp $
10  *
11  *
12  ***************************************************************************/
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  ***************************************************************************/
23 //
24 // Allow people to reach login page if
25 // board is shut down
26 //
27 define("IN_LOGIN", true);
29 define('IN_PHPBB', true);
30 $phpbb_root_path = './';
31 include($phpbb_root_path . 'extension.inc');
32 include($phpbb_root_path . 'common.'.$phpEx);
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 //
43 // session id check
44 if (!empty($HTTP_POST_VARS['sid']) || !empty($HTTP_GET_VARS['sid']))
45 {
46         $sid = (!empty($HTTP_POST_VARS['sid'])) ? $HTTP_POST_VARS['sid'] : $HTTP_GET_VARS['sid'];
47 }
48 else
49 {
50         $sid = '';
51 }
53 if( isset($HTTP_POST_VARS['login']) || isset($HTTP_GET_VARS['login']) || isset($HTTP_POST_VARS['logout']) || isset($HTTP_GET_VARS['logout']) )
54 {
55         if( ( isset($HTTP_POST_VARS['login']) || isset($HTTP_GET_VARS['login']) ) && !$userdata['session_logged_in'] )
56         {
57                 $username = isset($HTTP_POST_VARS['username']) ? phpbb_clean_username($HTTP_POST_VARS['username']) : '';
58                 $password = isset($HTTP_POST_VARS['password']) ? $HTTP_POST_VARS['password'] : '';
60                 $sql = "SELECT user_id, username, user_password, user_active, user_level
61                         FROM " . USERS_TABLE . "
62                         WHERE username = '" . str_replace("\\'", "''", $username) . "'";
63                 if ( !($result = $db->sql_query($sql)) )
64                 {
65                         message_die(GENERAL_ERROR, 'Error in obtaining userdata', '', __LINE__, __FILE__, $sql);
66                 }
68                 if( $row = $db->sql_fetchrow($result) )
69                 {
70                         if( $row['user_level'] != ADMIN && $board_config['board_disable'] )
71                         {
72                                 redirect(append_sid("index.$phpEx", true));
73                         }
74                         else
75                         {
76                                 if( md5($password) == $row['user_password'] && $row['user_active'] )
77                                 {
78                                         $autologin = ( isset($HTTP_POST_VARS['autologin']) ) ? TRUE : 0;
80                                         $session_id = session_begin($row['user_id'], $user_ip, PAGE_INDEX, FALSE, $autologin);
82                                         if( $session_id )
83                                         {
84                                                 $url = ( !empty($HTTP_POST_VARS['redirect']) ) ? str_replace('&amp;', '&', htmlspecialchars($HTTP_POST_VARS['redirect'])) : "index.$phpEx";
85                                                 redirect(append_sid($url, true));
86                                         }
87                                         else
88                                         {
89                                                 message_die(CRITICAL_ERROR, "Couldn't start session : login", "", __LINE__, __FILE__);
90                                         }
91                                 }
92                                 else
93                                 {
94                                         $redirect = ( !empty($HTTP_POST_VARS['redirect']) ) ? str_replace('&amp;', '&', htmlspecialchars($HTTP_POST_VARS['redirect'])) : '';
95                                         $redirect = str_replace('?', '&', $redirect);
97                                         if (strstr(urldecode($redirect), "\n") || strstr(urldecode($redirect), "\r"))
98                                         {
99                                                 message_die(GENERAL_ERROR, 'Tried to redirect to potentially insecure url.');
100                                         }
102                                         $template->assign_vars(array(
103                                                 'META' => "<meta http-equiv=\"refresh\" content=\"3;url=login.$phpEx?redirect=$redirect\">")
104                                         );
106                                         $message = $lang['Error_login'] . '<br /><br />' . sprintf($lang['Click_return_login'], "<a href=\"login.$phpEx?redirect=$redirect\">", '</a>') . '<br /><br />' .  sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');
108                                         message_die(GENERAL_MESSAGE, $message);
109                                 }
110                         }
111                 }
112                 else
113                 {
114                         $redirect = ( !empty($HTTP_POST_VARS['redirect']) ) ? str_replace('&amp;', '&', htmlspecialchars($HTTP_POST_VARS['redirect'])) : "";
115                         $redirect = str_replace("?", "&", $redirect);
117                         if (strstr(urldecode($redirect), "\n") || strstr(urldecode($redirect), "\r"))
118                         {
119                                 message_die(GENERAL_ERROR, 'Tried to redirect to potentially insecure url.');
120                         }
122                         $template->assign_vars(array(
123                                 'META' => "<meta http-equiv=\"refresh\" content=\"3;url=login.$phpEx?redirect=$redirect\">")
124                         );
126                         $message = $lang['Error_login'] . '<br /><br />' . sprintf($lang['Click_return_login'], "<a href=\"login.$phpEx?redirect=$redirect\">", '</a>') . '<br /><br />' .  sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');
128                         message_die(GENERAL_MESSAGE, $message);
129                 }
130         }
131         else if( ( isset($HTTP_GET_VARS['logout']) || isset($HTTP_POST_VARS['logout']) ) && $userdata['session_logged_in'] )
132         {
133                 if( $userdata['session_logged_in'] )
134                 {
135                         session_end($userdata['session_id'], $userdata['user_id']);
136                 }
138                 if (!empty($HTTP_POST_VARS['redirect']) || !empty($HTTP_GET_VARS['redirect']))
139                 {
140                         $url = (!empty($HTTP_POST_VARS['redirect'])) ? htmlspecialchars($HTTP_POST_VARS['redirect']) : htmlspecialchars($HTTP_GET_VARS['redirect']);
141                         $url = str_replace('&amp;', '&', $url);
142                         redirect(append_sid($url, true));
143                 }
144                 else
145                 {
146                         redirect(append_sid("index.$phpEx", true));
147                 }
148         }
149         else
150         {
151                 $url = ( !empty($HTTP_POST_VARS['redirect']) ) ? str_replace('&amp;', '&', htmlspecialchars($HTTP_POST_VARS['redirect'])) : "index.$phpEx";
152                 redirect(append_sid($url, true));
153         }
155 else
157         //
158         // Do a full login page dohickey if
159         // user not already logged in
160         //
161         if( !$userdata['session_logged_in'] )
162         {
163                 $page_title = $lang['Login'];
164                 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
166                 $template->set_filenames(array(
167                         'body' => 'login_body.tpl')
168                 );
170                 if( isset($HTTP_POST_VARS['redirect']) || isset($HTTP_GET_VARS['redirect']) )
171                 {
172                         $forward_to = $HTTP_SERVER_VARS['QUERY_STRING'];
174                         if( preg_match("/^redirect=([a-z0-9\.#\/\?&=\+\-_]+)/si", $forward_to, $forward_matches) )
175                         {
176                                 $forward_to = ( !empty($forward_matches[3]) ) ? $forward_matches[3] : $forward_matches[1];
177                                 $forward_match = explode('&', $forward_to);
179                                 if(count($forward_match) > 1)
180                                 {
181                                         $forward_page = '';
183                                         for($i = 1; $i < count($forward_match); $i++)
184                                         {
185                                                 if( !ereg("sid=", $forward_match[$i]) )
186                                                 {
187                                                         if( $forward_page != '' )
188                                                         {
189                                                                 $forward_page .= '&';
190                                                         }
191                                                         $forward_page .= $forward_match[$i];
192                                                 }
193                                         }
194                                         $forward_page = $forward_match[0] . '?' . $forward_page;
195                                 }
196                                 else
197                                 {
198                                         $forward_page = $forward_match[0];
199                                 }
200                         }
201                 }
202                 else
203                 {
204                         $forward_page = '';
205                 }
207                 $username = ( $userdata['user_id'] != ANONYMOUS ) ? $userdata['username'] : '';
209                 $s_hidden_fields = '<input type="hidden" name="redirect" value="' . $forward_page . '" />';
211                 make_jumpbox('viewforum.'.$phpEx, $forum_id);
212                 $template->assign_vars(array(
213                         'USERNAME' => $username,
215                         'L_ENTER_PASSWORD' => $lang['Enter_password'],
216                         'L_SEND_PASSWORD' => $lang['Forgotten_password'],
218                         'U_SEND_PASSWORD' => append_sid("profile.$phpEx?mode=sendpassword"),
220                         'S_HIDDEN_FIELDS' => $s_hidden_fields)
221                 );
223                 $template->pparse('body');
225                 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
226         }
227         else
228         {
229                 redirect(append_sid("index.$phpEx", true));
230         }
234 ?>