3.) Simultanes bzw. dualer User-Login:
Egal, ob sich ein User über das Typo3 oder aber über das phpbb-Forum einloggt, er ist automatisch nach dem jeweiligen Login auch am anderen System angemeldet!
Dieses Feature stellte bei diesem Interface die größte Herausforderung dar!
Um dies zu bewerkstelligen, musste einerseits die Typo3-Login-Extension modifiziert und gleichzeitig ein eigenes File für den phpbb-Login vom Typo3-System gecodet werden, welches beim Login über Typo3 von diesem included bzw. aufgerufen wird!
Der Login erfolgt also immer über Typo3 und Typo3 meldet den User dann automatisch am phpbb an und erzeugt die notwendige User-Session usw....
Typo3-Extension: New front end login box
Extension Key: newloginbox
Version: 2.2.9
Extension Ordner: newloginbox
File Name: class.tx_newloginbox_pi1.php
Download des kompletten File inkl. MOD:
http://www.mwa-networks.com/typo3_to_phpbb/class.tx_newloginbox_pi1.zip
Source-Code:
Zeile 381:
########
#### START hook by mwa-networks for auto-login on phpbb after typo3-login is ok and typo3-session is created successfully and active
########
define('IN_PHPBB', true);
include('typo3_to_phpbb_login_mwa.php');
########
#### END hook by mwa-networks for auto-login on phpbb
########
Folgendes File muss direkt im Typo3-Root-Verzeichnis "/html" plaziert werden und wird von der "New front end login box"-Extension aufgerufen!
File-Name: typo3_to_phpbb_login_mwa.php
Download des kompletten File:
http://www.mwa-networks.com/typo3_to_phpbb/typo3_to_phpbb_login_mwa.zip
Source-Code:
<?php
/***************************************************************************
* typo3_to_phpbb_login_mwa.php
* -------------------
* begin : Friday', May 13', 2005
* copyright : ('C) 2005 mwa-networks, Ing. Roland Maldoner-Jäger
* email : office@mwa-networks.com
*
* $Id: typo3_to_phpbb_login_mwa.php,v 1.0 2005/05/13 17:49:42 roli Exp $
*
*
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License', or
* ('at your option) any later version.
*
***************************************************************************/
#### vars definition
// activating autologon on phpbb
$autologin_mwa = TRUE;
// path from typo3 to phpbb root-directory
$phpbb_root_path = './mwa/phpbb/';
// php file-extension
$phpEx = 'php';
// get username and password from typo3
$username_mwa = $GLOBALS['TSFE']->fe_user->user['username'];
$password_mwa = $GLOBALS['TSFE']->fe_user->user['password'];
//$email_mwa = $GLOBALS['TSFE']->fe_user->user['email'];
//$city_mwa = $GLOBALS['TSFE']->fe_user->user['city'];
//$www_mwa = $GLOBALS['TSFE']->fe_user->user['www'];
#### function definition for outputfile
function read_testfile() {
$fh_mwa=fopen("mwa_login_output.txt","r");
$str_mwa=fread($fh_mwa,200000);
fclose($fh_mwa);
return $str_mwa;
}
function write_testfile($str_mwa) {
$fh_mwa=fopen("mwa_login_output.txt","w");
fwrite($fh_mwa,$str_mwa);
fclose($fh_mwa);
}
function testfile($str_new) {
$str_old = read_testfile();
$str_old .= $str_new;
write_testfile($str_old);
}
#### include phpbb-files
// include function library
include($phpbb_root_path . 'includes/functions.' . $phpEx);
// include of main language file
include($phpbb_root_path . 'language/lang_english/lang_main.' . $phpEx);
// include database login datas
include($phpbb_root_path . 'config.' . $phpEx);
// include database selector and sql-layer for db-communication
include($phpbb_root_path . 'includes/db.' . $phpEx);
// include of phpbb constants
include($phpbb_root_path . 'includes/constants.' . $phpEx);
// include session library
//include($phpbb_root_path . 'includes/sessions.' . $phpEx);
// include template library
//include($phpbb_root_path . 'includes/template.' . $phpEx);
#### start coding
// checking hack-attack
if (!defined('IN_PHPBB')) {
die('hacking attempt on typo3_to_phpbb_login.php script');
}
// disable magic_quotes_runtime for secure phpbb runtime environment
$tmp_magic_quotes_mwa = false;
if (get_magic_quotes_runtime() == 1) {
set_magic_quotes_runtime(0);
$tmp_magic_quotes_mwa = true;
}
//testfile("check IN_PHPBB: " . IN_PHPBB . " / username_mwa: " . $username_mwa . " / password_mwa: " . $password_mwa . " \n");
// import forum wide options settings, if this fails we have to stop because there are the basic configuration settings
$sql_mwa = "SELECT *
FROM " . CONFIG_TABLE;
if (!($result = $db->sql_query($sql_mwa))) {
testfile("Could not query basic config information and settings from phpbb! \n sql-mwa: " . $sql_mwa . "\n Line-Nr.: " . __LINE__ . " IN FILE: " . __FILE__ . " \n");
}
while ($row = $db->sql_fetchrow($result)) {
$board_config[$row['config_name']] = $row['config_value'];
}
// obtain and encode users ip adress for session management and data-logging
$client_ip = (!empty($HTTP_SERVER_VARS['REMOTE_ADDR'])) ? $HTTP_SERVER_VARS['REMOTE_ADDR'] : ((!empty($HTTP_ENV_VARS['REMOTE_ADDR'])) ? $HTTP_ENV_VARS['REMOTE_ADDR'] : getenv('REMOTE_ADDR'));
$user_ip = encode_ip($client_ip);
// get user data
$sql_mwa = "SELECT user_id, username, user_password, user_active, user_level
FROM " . USERS_TABLE . "
WHERE username = '" . str_replace("\\'", "''", $username_mwa) . "'";
// checking database connection and query-result
if (!($result = $db->sql_query($sql_mwa))) {
testfile("Error in obtaining userdata from phpbb-database! \n Line-Nr.: " . __LINE__ . " IN FILE: " . __FILE__ . "\n");
}
if ($row = $db->sql_fetchrow($result)) {
if (!$board_config['board_disable']) {
if (md5($password_mwa) == $row['user_password'] && $row['user_active']) {
// start phpbb-session
$user_id = $row['user_id'];
$auto_create = 0;
$enable_autologin = $autologin_mwa;
$page_id = 9999;
$cookiename = $board_config['cookie_name'];
$cookiepath = $board_config['cookie_path'];
$cookiedomain = $board_config['cookie_domain'];
$cookiesecure = $board_config['cookie_secure'];
if ( isset($HTTP_COOKIE_VARS[$cookiename . '_sid']) || isset($HTTP_COOKIE_VARS[$cookiename . '_data']) ) {
$session_id = isset($HTTP_COOKIE_VARS[$cookiename . '_sid']) ? $HTTP_COOKIE_VARS[$cookiename . '_sid'] : '';
$sessiondata = isset($HTTP_COOKIE_VARS[$cookiename . '_data']) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$cookiename . '_data'])) : array();
$sessionmethod = SESSION_METHOD_COOKIE;
} else {
$sessiondata = array();
$session_id = ( isset($HTTP_GET_VARS['sid']) ) ? $HTTP_GET_VARS['sid'] : '';
$sessionmethod = SESSION_METHOD_GET;
}
if (!preg_match('/^[A-Za-z0-9]*$/', $session_id)) {
$session_id = '';
}
$last_visit = 0;
$current_time = time();
$expiry_time = $current_time - $board_config['session_length'];
// try and pull the last time stored in a cookie, if it exists
$sql = "SELECT *
FROM " . USERS_TABLE . "
WHERE user_id = $user_id";
if ( !($result = $db->sql_query($sql)) ) {
testfile("Could not obtain lastvisit data from user table! \n Line-Nr.: " . __LINE__ . " IN FILE: " . __FILE__ . "\n");
}
$userdata = $db->sql_fetchrow($result);
if ( $user_id != ANONYMOUS ) {
$auto_login_key = $userdata['user_password'];
if ( $auto_create ) {
if ( isset($sessiondata['autologinid']) && $userdata['user_active'] ) {
// login automagically
if( $sessiondata['autologinid'] === $auto_login_key ) {
// autologin-id matches password
$login = 1;
$enable_autologin = 1;
} else {
// no match - don't login, set as anonymous user
$login = 0;
$enable_autologin = 0;
$user_id = $userdata['user_id'] = ANONYMOUS;
}
} else {
// autologin is not set - do not login, set as anonymous user
$login = 0;
$enable_autologin = 0;
$user_id = $userdata['user_id'] = ANONYMOUS;
}
} else {
$login = 1;
}
} else {
$login = 0;
$enable_autologin = 0;
}
// initializing the ban-checker against user id, ip and email address
preg_match('/(..)(..)(..)(..)/', $user_ip, $user_ip_parts);
$sql = "SELECT ban_ip, ban_userid, ban_email
FROM " . BANLIST_TABLE . "
WHERE ban_ip IN ('" . $user_ip_parts[1] . $user_ip_parts[2] . $user_ip_parts[3] . $user_ip_parts[4] . "', '" . $user_ip_parts[1] . $user_ip_parts[2] . $user_ip_parts[3] . "ff', '" . $user_ip_parts[1] . $user_ip_parts[2] . "ffff', '" . $user_ip_parts[1] . "ffffff')
OR ban_userid = $user_id";
if ( $user_id != ANONYMOUS ) {
$sql .= " OR ban_email LIKE '" . str_replace("\'", "''", $userdata['user_email']) . "'
OR ban_email LIKE '" . substr(str_replace("\'", "''", $userdata['user_email']), strpos(str_replace("\'", "''", $userdata['user_email']), "@")) . "'";
}
if ( !($result = $db->sql_query($sql)) ) {
testfile("Could not obtain ban information \n Line-Nr.: " . __LINE__ . " IN FILE: " . __FILE__ . "\n");
}
if ( $ban_info = $db->sql_fetchrow($result) ) {
if ( $ban_info['ban_ip'] || $ban_info['ban_userid'] || $ban_info['ban_email'] ) {
testfile("USER IS BANNED \n Line-Nr.: " . __LINE__ . " IN FILE: " . __FILE__ . "\n");
}
}
// create or update session
$sql = "UPDATE " . SESSIONS_TABLE . "
SET session_user_id = $user_id, session_start = $current_time, session_time = $current_time, session_page = $page_id, session_logged_in = $login
WHERE session_id = '" . $session_id . "'
AND session_ip = '$user_ip'";
if ( !$db->sql_query($sql) || !$db->sql_affectedrows() ) {
$session_id = md5(uniqid($user_ip));
$sql = "INSERT INTO " . SESSIONS_TABLE . "
(session_id, session_user_id, session_start, session_time, session_ip, session_page, session_logged_in)
VALUES ('$session_id', $user_id, $current_time, $current_time, '$user_ip', $page_id, $login)";
if ( !$db->sql_query($sql) ) {
testfile("Error creating new session \n Line-Nr.: " . __LINE__ . " IN FILE: " . __FILE__ . "\n");
}
}
if ( $user_id != ANONYMOUS ) {
// ( $userdata['user_session_time'] > $expiry_time && $auto_create ) ? $userdata['user_lastvisit'] : (
$last_visit = ( $userdata['user_session_time'] > 0 ) ? $userdata['user_session_time'] : $current_time;
$sql = "UPDATE " . USERS_TABLE . "
SET user_session_time = $current_time, user_session_page = $page_id, user_lastvisit = $last_visit
WHERE user_id = $user_id";
if ( !$db->sql_query($sql) ) {
testfile("Error updating last visit time \n Line-Nr.: " . __LINE__ . " IN FILE: " . __FILE__ . "\n");
}
$userdata['user_lastvisit'] = $last_visit;
$sessiondata['autologinid'] = ( $enable_autologin && $sessionmethod == SESSION_METHOD_COOKIE ) ? $auto_login_key : '';
$sessiondata['userid'] = $user_id;
}
$userdata['session_id'] = $session_id;
$userdata['session_ip'] = $user_ip;
$userdata['session_user_id'] = $user_id;
$userdata['session_logged_in'] = $login;
$userdata['session_page'] = $page_id;
$userdata['session_start'] = $current_time;
$userdata['session_time'] = $current_time;
setcookie($cookiename . '_data', serialize($sessiondata), $current_time + 31536000, $cookiepath, $cookiedomain, $cookiesecure);
setcookie($cookiename . '_sid', $session_id, 0, $cookiepath, $cookiedomain, $cookiesecure);
$SID = 'sid=' . $session_id;
$session_id = $userdata;
if ($session_id) {
// we do not need a redirection
//$url = (!empty($HTTP_POST_VARS['redirect'])) ? str_replace('&', '&', htmlspecialchars($HTTP_POST_VARS['redirect'])) : "index.$phpEx";
//redirect(append_sid($url, true));
}
else {
testfile("Could not start phpbb-session from typo3 on login \n Line-Nr.: " . __LINE__ . " IN FILE: " . __FILE__ . "\n");
}
}
else {
testfile("Wrong password on typo3-Login for phpbb! \n Line-Nr.: " . __LINE__ . " IN FILE: " . __FILE__ . "\n");
}
}
}
// reset magic_quotes_runtime for stable typo3 runtime environment
if ($tmp_magic_quotes_mwa) {
if (get_magic_quotes_runtime() == 0) {
set_magic_quotes_runtime(1);
}
}
?>
Download des kompletten File:
http://www.mwa-networks.com/typo3_to_phpbb/typo3_to_phpbb_login_mwa.zip
=> die minimalen anpassungen am phpbb folgen...
lg,
roli alias rmj13