Verzeichnisstruktur phpBB-2.0.0


Veröffentlicht
03.04.2002

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

login.php

Zuletzt modifiziert: 09.10.2024, 12:50 - Dateigröße: 9.28 KiB


 001  <?php
 002  /***************************************************************************
 003   *                                login.php
 004   *                            -------------------
 005   *   begin                : Saturday, Feb 13, 2001
 006   *   copyright            : (C) 2001 The phpBB Group
 007   *   email                : support@phpbb.com
 008   *
 009   *   $Id$
 010   *
 011   *
 012   ***************************************************************************/
 013   
 014  /***************************************************************************
 015   *
 016   *   This program is free software; you can redistribute it and/or modify
 017   *   it under the terms of the GNU General Public License as published by
 018   *   the Free Software Foundation; either version 2 of the License, or
 019   *   (at your option) any later version.
 020   *
 021   ***************************************************************************/
 022   
 023  //
 024  // Allow people to reach login page if
 025  // board is shut down
 026  //
 027  define("IN_LOGIN", true);
 028   
 029  define('IN_PHPBB', true);
 030  $phpbb_root_path = './';
 031  include($phpbb_root_path . 'extension.inc');
 032  include($phpbb_root_path . 'common.'.$phpEx);
 033   
 034  //
 035  // Set page ID for session management
 036  //
 037  $userdata = session_pagestart($user_ip, PAGE_LOGIN);
 038  init_userprefs($userdata);
 039  //
 040  // End session management
 041  //
 042   
 043  // session id check
 044  if (!empty($HTTP_POST_VARS['sid']) || !empty($HTTP_GET_VARS['sid']))
 045  {
 046      $sid = (!empty($HTTP_POST_VARS['sid'])) ? $HTTP_POST_VARS['sid'] : $HTTP_GET_VARS['sid'];
 047  }
 048  else
 049  {
 050      $sid = '';
 051  }
 052   
 053  if( isset($HTTP_POST_VARS['login']) || isset($HTTP_GET_VARS['login']) || isset($HTTP_POST_VARS['logout']) || isset($HTTP_GET_VARS['logout']) )
 054  {
 055      if( ( isset($HTTP_POST_VARS['login']) || isset($HTTP_GET_VARS['login']) ) && (!$userdata['session_logged_in'] || isset($HTTP_POST_VARS['admin'])) )
 056      {
 057          $username = isset($HTTP_POST_VARS['username']) ? phpbb_clean_username($HTTP_POST_VARS['username']) : '';
 058          $password = isset($HTTP_POST_VARS['password']) ? $HTTP_POST_VARS['password'] : '';
 059   
 060          $sql = "SELECT user_id, username, user_password, user_active, user_level, user_login_tries, user_last_login_try
 061              FROM " . USERS_TABLE . "
 062              WHERE username = '" . str_replace("\\'", "''", $username) . "'";
 063          if ( !($result = $db->sql_query($sql)) )
 064          {
 065              message_die(GENERAL_ERROR, 'Error in obtaining userdata', '', __LINE__, __FILE__, $sql);
 066          }
 067   
 068          if( $row = $db->sql_fetchrow($result) )
 069          {
 070              if( $row['user_level'] != ADMIN && $board_config['board_disable'] )
 071              {
 072                  redirect(append_sid("index.$phpEx", true));
 073              }
 074              else
 075              {
 076                  // If the last login is more than x minutes ago, then reset the login tries/time
 077                  if ($row['user_last_login_try'] && $board_config['login_reset_time'] && $row['user_last_login_try'] < (time() - ($board_config['login_reset_time'] * 60)))
 078                  {
 079                      $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_login_tries = 0, user_last_login_try = 0 WHERE user_id = ' . $row['user_id']);
 080                      $row['user_last_login_try'] = $row['user_login_tries'] = 0;
 081                  }
 082                  
 083                  // Check to see if user is allowed to login again... if his tries are exceeded
 084                  if ($row['user_last_login_try'] && $board_config['login_reset_time'] && $board_config['max_login_attempts'] && 
 085                      $row['user_last_login_try'] >= (time() - ($board_config['login_reset_time'] * 60)) && $row['user_login_tries'] >= $board_config['max_login_attempts'] && $userdata['user_level'] != ADMIN)
 086                  {
 087                      message_die(GENERAL_MESSAGE, sprintf($lang['Login_attempts_exceeded'], $board_config['max_login_attempts'], $board_config['login_reset_time']));
 088                  }
 089   
 090                  if( md5($password) == $row['user_password'] && $row['user_active'] )
 091                  {
 092                      $autologin = ( isset($HTTP_POST_VARS['autologin']) ) ? TRUE : 0;
 093   
 094                      $admin = (isset($HTTP_POST_VARS['admin'])) ? 1 : 0;
 095                      $session_id = session_begin($row['user_id'], $user_ip, PAGE_INDEX, FALSE, $autologin, $admin);
 096   
 097                      // Reset login tries
 098                      $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_login_tries = 0, user_last_login_try = 0 WHERE user_id = ' . $row['user_id']);
 099   
 100                      if( $session_id )
 101                      {
 102                          $url = ( !empty($HTTP_POST_VARS['redirect']) ) ? str_replace('&amp;', '&', htmlspecialchars($HTTP_POST_VARS['redirect'])) : "index.$phpEx";
 103                          redirect(append_sid($url, true));
 104                      }
 105                      else
 106                      {
 107                          message_die(CRITICAL_ERROR, "Couldn't start session : login", "", __LINE__, __FILE__);
 108                      }
 109                  }
 110                  // Only store a failed login attempt for an active user - inactive users can't login even with a correct password
 111                  elseif( $row['user_active'] )
 112                  {
 113                      // Save login tries and last login
 114                      if ($row['user_id'] != ANONYMOUS)
 115                      {
 116                          $sql = 'UPDATE ' . USERS_TABLE . '
 117                              SET user_login_tries = user_login_tries + 1, user_last_login_try = ' . time() . '
 118                              WHERE user_id = ' . $row['user_id'];
 119                          $db->sql_query($sql);
 120                      }
 121                  }
 122   
 123                  $redirect = ( !empty($HTTP_POST_VARS['redirect']) ) ? str_replace('&amp;', '&', htmlspecialchars($HTTP_POST_VARS['redirect'])) : '';
 124                  $redirect = str_replace('?', '&', $redirect);
 125   
 126                  if (strstr(urldecode($redirect), "\n") || strstr(urldecode($redirect), "\r") || strstr(urldecode($redirect), ';url'))
 127                  {
 128                      message_die(GENERAL_ERROR, 'Tried to redirect to potentially insecure url.');
 129                  }
 130   
 131                  $template->assign_vars(array(
 132                      'META' => "<meta http-equiv=\"refresh\" content=\"3;url=login.$phpEx?redirect=$redirect\">")
 133                  );
 134   
 135                  $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>');
 136   
 137                  message_die(GENERAL_MESSAGE, $message);
 138              }
 139          }
 140          else
 141          {
 142              $redirect = ( !empty($HTTP_POST_VARS['redirect']) ) ? str_replace('&amp;', '&', htmlspecialchars($HTTP_POST_VARS['redirect'])) : "";
 143              $redirect = str_replace("?", "&", $redirect);
 144   
 145              if (strstr(urldecode($redirect), "\n") || strstr(urldecode($redirect), "\r") || strstr(urldecode($redirect), ';url'))
 146              {
 147                  message_die(GENERAL_ERROR, 'Tried to redirect to potentially insecure url.');
 148              }
 149   
 150              $template->assign_vars(array(
 151                  'META' => "<meta http-equiv=\"refresh\" content=\"3;url=login.$phpEx?redirect=$redirect\">")
 152              );
 153   
 154              $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>');
 155   
 156              message_die(GENERAL_MESSAGE, $message);
 157          }
 158      }
 159      else if( ( isset($HTTP_GET_VARS['logout']) || isset($HTTP_POST_VARS['logout']) ) && $userdata['session_logged_in'] )
 160      {
 161          // session id check
 162          if ($sid == '' || $sid != $userdata['session_id'])
 163          {
 164              message_die(GENERAL_ERROR, 'Invalid_session');
 165          }
 166   
 167          if( $userdata['session_logged_in'] )
 168          {
 169              session_end($userdata['session_id'], $userdata['user_id']);
 170          }
 171   
 172          if (!empty($HTTP_POST_VARS['redirect']) || !empty($HTTP_GET_VARS['redirect']))
 173          {
 174              $url = (!empty($HTTP_POST_VARS['redirect'])) ? htmlspecialchars($HTTP_POST_VARS['redirect']) : htmlspecialchars($HTTP_GET_VARS['redirect']);
 175              $url = str_replace('&amp;', '&', $url);
 176              redirect(append_sid($url, true));
 177          }
 178          else
 179          {
 180              redirect(append_sid("index.$phpEx", true));
 181          }
 182      }
 183      else
 184      {
 185          $url = ( !empty($HTTP_POST_VARS['redirect']) ) ? str_replace('&amp;', '&', htmlspecialchars($HTTP_POST_VARS['redirect'])) : "index.$phpEx";
 186          redirect(append_sid($url, true));
 187      }
 188  }
 189  else
 190  {
 191      //
 192      // Do a full login page dohickey if
 193      // user not already logged in
 194      //
 195      if( !$userdata['session_logged_in'] || (isset($HTTP_GET_VARS['admin']) && $userdata['session_logged_in'] && $userdata['user_level'] == ADMIN))
 196      {
 197          $page_title = $lang['Login'];
 198          include($phpbb_root_path . 'includes/page_header.'.$phpEx);
 199   
 200          $template->set_filenames(array(
 201              'body' => 'login_body.tpl')
 202          );
 203   
 204          $forward_page = '';
 205   
 206          if( isset($HTTP_POST_VARS['redirect']) || isset($HTTP_GET_VARS['redirect']) )
 207          {
 208              $forward_to = $HTTP_SERVER_VARS['QUERY_STRING'];
 209   
 210              if( preg_match("/^redirect=([a-z0-9\.#\/\?&=\+\-_]+)/si", $forward_to, $forward_matches) )
 211              {
 212                  $forward_to = ( !empty($forward_matches[3]) ) ? $forward_matches[3] : $forward_matches[1];
 213                  $forward_match = explode('&', $forward_to);
 214   
 215                  if(count($forward_match) > 1)
 216                  {
 217                      for($i = 1; $i < count($forward_match); $i++)
 218                      {
 219                          if( !ereg("sid=", $forward_match[$i]) )
 220                          {
 221                              if( $forward_page != '' )
 222                              {
 223                                  $forward_page .= '&';
 224                              }
 225                              $forward_page .= $forward_match[$i];
 226                          }
 227                      }
 228                      $forward_page = $forward_match[0] . '?' . $forward_page;
 229                  }
 230                  else
 231                  {
 232                      $forward_page = $forward_match[0];
 233                  }
 234              }
 235          }
 236   
 237          $username = ( $userdata['user_id'] != ANONYMOUS ) ? $userdata['username'] : '';
 238   
 239          $s_hidden_fields = '<input type="hidden" name="redirect" value="' . $forward_page . '" />';
 240          $s_hidden_fields .= (isset($HTTP_GET_VARS['admin'])) ? '<input type="hidden" name="admin" value="1" />' : '';
 241   
 242          make_jumpbox('viewforum.'.$phpEx);
 243          $template->assign_vars(array(
 244              'USERNAME' => $username,
 245   
 246              'L_ENTER_PASSWORD' => (isset($HTTP_GET_VARS['admin'])) ? $lang['Admin_reauthenticate'] : $lang['Enter_password'],
 247              'L_SEND_PASSWORD' => $lang['Forgotten_password'],
 248   
 249              'U_SEND_PASSWORD' => append_sid("profile.$phpEx?mode=sendpassword"),
 250   
 251              'S_HIDDEN_FIELDS' => $s_hidden_fields)
 252          );
 253   
 254          $template->pparse('body');
 255   
 256          include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
 257      }
 258      else
 259      {
 260          redirect(append_sid("index.$phpEx", true));
 261      }
 262   
 263  }
 264   
 265  ?>