2 /***************************************************************************
5 * begin : Saturday, Feb 13, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: login.php,v 1.47.2.17 2004/11/18 17:49:35 acydburn Exp $
12 ***************************************************************************/
14 /***************************************************************************
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.
21 ***************************************************************************/
24 // Allow people to reach login page if
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);
35 // Set page ID for session management
37 $userdata = session_pagestart($user_ip, PAGE_LOGIN);
38 init_userprefs($userdata);
40 // End session management
44 if (!empty($HTTP_POST_VARS['sid']) || !empty($HTTP_GET_VARS['sid']))
46 $sid = (!empty($HTTP_POST_VARS['sid'])) ? $HTTP_POST_VARS['sid'] : $HTTP_GET_VARS['sid'];
53 if( isset($HTTP_POST_VARS['login']) || isset($HTTP_GET_VARS['login']) || isset($HTTP_POST_VARS['logout']) || isset($HTTP_GET_VARS['logout']) )
55 if( ( isset($HTTP_POST_VARS['login']) || isset($HTTP_GET_VARS['login']) ) && !$userdata['session_logged_in'] )
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)) )
65 message_die(GENERAL_ERROR, 'Error in obtaining userdata', '', __LINE__, __FILE__, $sql);
68 if( $row = $db->sql_fetchrow($result) )
70 if( $row['user_level'] != ADMIN && $board_config['board_disable'] )
72 redirect(append_sid("index.$phpEx", true));
76 if( md5($password) == $row['user_password'] && $row['user_active'] )
78 $autologin = ( isset($HTTP_POST_VARS['autologin']) ) ? TRUE : 0;
80 $session_id = session_begin($row['user_id'], $user_ip, PAGE_INDEX, FALSE, $autologin);
84 $url = ( !empty($HTTP_POST_VARS['redirect']) ) ? str_replace('&', '&', htmlspecialchars($HTTP_POST_VARS['redirect'])) : "index.$phpEx";
85 redirect(append_sid($url, true));
89 message_die(CRITICAL_ERROR, "Couldn't start session : login", "", __LINE__, __FILE__);
94 $redirect = ( !empty($HTTP_POST_VARS['redirect']) ) ? str_replace('&', '&', htmlspecialchars($HTTP_POST_VARS['redirect'])) : '';
95 $redirect = str_replace('?', '&', $redirect);
97 if (strstr(urldecode($redirect), "\n") || strstr(urldecode($redirect), "\r"))
99 message_die(GENERAL_ERROR, 'Tried to redirect to potentially insecure url.');
102 $template->assign_vars(array(
103 'META' => "<meta http-equiv=\"refresh\" content=\"3;url=login.$phpEx?redirect=$redirect\">")
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);
114 $redirect = ( !empty($HTTP_POST_VARS['redirect']) ) ? str_replace('&', '&', htmlspecialchars($HTTP_POST_VARS['redirect'])) : "";
115 $redirect = str_replace("?", "&", $redirect);
117 if (strstr(urldecode($redirect), "\n") || strstr(urldecode($redirect), "\r"))
119 message_die(GENERAL_ERROR, 'Tried to redirect to potentially insecure url.');
122 $template->assign_vars(array(
123 'META' => "<meta http-equiv=\"refresh\" content=\"3;url=login.$phpEx?redirect=$redirect\">")
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);
131 else if( ( isset($HTTP_GET_VARS['logout']) || isset($HTTP_POST_VARS['logout']) ) && $userdata['session_logged_in'] )
133 if( $userdata['session_logged_in'] )
135 session_end($userdata['session_id'], $userdata['user_id']);
138 if (!empty($HTTP_POST_VARS['redirect']) || !empty($HTTP_GET_VARS['redirect']))
140 $url = (!empty($HTTP_POST_VARS['redirect'])) ? htmlspecialchars($HTTP_POST_VARS['redirect']) : htmlspecialchars($HTTP_GET_VARS['redirect']);
141 $url = str_replace('&', '&', $url);
142 redirect(append_sid($url, true));
146 redirect(append_sid("index.$phpEx", true));
151 $url = ( !empty($HTTP_POST_VARS['redirect']) ) ? str_replace('&', '&', htmlspecialchars($HTTP_POST_VARS['redirect'])) : "index.$phpEx";
152 redirect(append_sid($url, true));
158 // Do a full login page dohickey if
159 // user not already logged in
161 if( !$userdata['session_logged_in'] )
163 $page_title = $lang['Login'];
164 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
166 $template->set_filenames(array(
167 'body' => 'login_body.tpl')
170 if( isset($HTTP_POST_VARS['redirect']) || isset($HTTP_GET_VARS['redirect']) )
172 $forward_to = $HTTP_SERVER_VARS['QUERY_STRING'];
174 if( preg_match("/^redirect=([a-z0-9\.#\/\?&=\+\-_]+)/si", $forward_to, $forward_matches) )
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)
183 for($i = 1; $i < count($forward_match); $i++)
185 if( !ereg("sid=", $forward_match[$i]) )
187 if( $forward_page != '' )
189 $forward_page .= '&';
191 $forward_page .= $forward_match[$i];
194 $forward_page = $forward_match[0] . '?' . $forward_page;
198 $forward_page = $forward_match[0];
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)
223 $template->pparse('body');
225 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
229 redirect(append_sid("index.$phpEx", true));