Code: Selecteer alles
================================================================================
INSTALLATION: PHP BOTS MOD (for phpBB 2.0.11)
================================================================================
This MOD has been written by Adam Marcus and is a vain attempt to reproduce what
is hopefully coming in PHP2.2 ( you can see the similarites =) ). After
installation you should be left with a page in the admin panel called "manage bots".
To install:
0) If you have installed any previous BOT related mods please uninstall them as it
may hinder this mod!!!
1) First copy all the files from this zip (with the exception of this file
"INSTALL.txt" and "UPDATE.TXT") to the root directory of your phpBB install.
2) Run "bot_install.php" - so for example in your web browser type:
www.yourdomain.com/yourphpinstall/bot_install.php
3) Follow the instructions and type in the required data, if any.
4) Delete "bot_install.php" from your server. This is just a security measure.
5) Lastly follow the MOD below to adjust your other core phpbb files.
6) The mod should be fully operational, enjoy your forum being indexed!
===============================================================================
#-----[ OPEN ]------------------------------------------------------
includes/sessions.php
#-----[ FIND ]-------------------------------------------------------
global $SID;
if ( !empty($SID) && !preg_match('#sid=#', $url) )
#-----[ REPLACE WITH ]-----------------------------------------------
global $SID;
if ( !empty($SID) && !preg_match('#sid=#', $url) && !IS_ROBOT )
#-----[ FIND ]-------------------------------------------------------
// Create or update the session
#-----[ INSERT BEFORE ]----------------------------------------------
$robot = ( ( defined('IS_ROBOT') ) ? IS_ROBOT : 0 );
#-----[ INLINE FIND ]------------------------------------------------
session_page = $page_id, session_logged_in = $login
#-----[ INLINE AFTER, ADD ]------------------------------------------
, is_robot = '$robot'
#-----[ INLINE FIND ]------------------------------------------------
session_page, session_logged_in
#-----[ INLINE AFTER, ADD ]------------------------------------------
, is_robot
#-----[ INLINE FIND ]------------------------------------------------
'$user_ip', $page_id, $login
#-----[ INLINE AFTER, ADD ]------------------------------------------
, '$robot'
#-----[ OPEN ]------------------------------------------------------
viewonline.php
#-----[ INLINE FIND ]------------------------------------------------
s.session_page, s.session_ip
#-----[ INLINE AFTER, ADD ]------------------------------------------
, s.is_robot
#-----[ FIND ]-------------------------------------------------------
$username = $lang['Guest'];
#-----[ REPLACE WITH ]-----------------------------------------------
if($row['is_robot'])
{
$username = $row['is_robot'] . ' ( Bots )';
} else {
$username = $lang['Guest'];
}
#-----[ OPEN ]------------------------------------------------------
includes/page_header.php
#-----[ INLINE FIND ]------------------------------------------------
s.session_logged_in, s.session_ip
#-----[ INLINE AFTER, ADD ]------------------------------------------
, s.is_robot
#-----[ FIND ]-------------------------------------------------------
$guests_online++;
#-----[ AFTER, ADD ]-----------------------------------------------
if( $row['is_robot'] )
{
$online_userlist = $row['is_robot'] . (($online_userlist!='') ? ', ' : '') . $online_userlist;
}
#-----[ OPEN ]------------------------------------------------------
common.php
#-----[ FIND ]-------------------------------------------------------
?>
#-----[ INSERT BEFORE ]----------------------------------------------
define('IS_ROBOT', is_robot() );
#-----[ OPEN ]------------------------------------------------------
includes/functions.php
#-----[ FIND ]------------------------------------------------------
global $board_config, $theme, $images;
#-----[ REPLACE WITH ]----------------------------------------------
global $board_config, $theme, $images, $db, $table_prefix;
#-----[ FIND ]------------------------------------------------------
$theme = setup_style($board_config['default_style']);
#-----[ REPLACE WITH ]----------------------------------------------
if (IS_ROBOT)
{
$sql = "SELECT bot_style FROM " . $table_prefix . "bots WHERE bot_name='" . IS_ROBOT . "'";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$theme = setup_style($row['bot_style']);
} else {
$theme = setup_style($board_config['default_style']);
}
#-----[ FIND ]------------------------------------------------------
?>
#-----[ INSERT BEFORE ]---------------------------------------------
//
// Part of bot MOD: This function checks whether the user agent or ip is
// listed as a bot and returns true otherwise false.
//
function is_robot()
{
global $db, $HTTP_SERVER_VARS, $table_prefix;
// define bots table - for the users who are to lazy to edit constants.php hehehe!
define('BOTS_TABLE', $table_prefix . "bots");
// get required user data
$user_ip = $HTTP_SERVER_VARS['REMOTE_ADDR'];
$user_agent = $HTTP_SERVER_VARS['HTTP_USER_AGENT'];
// get bot table data
$sql = "SELECT bot_agent, bot_ip, bot_id, bot_visits, last_visit, bot_pages, bot_name
FROM " . BOTS_TABLE;
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain bot data.', '', __LINE__, __FILE__, $sql);
}
// loop through bots table
while ($row = $db->sql_fetchrow($result))
{
// clear vars
$agent_match = 0;
$ip_match = 0;
// check for user agent match
foreach (explode('|', $row['bot_agent']) as $bot_agent)
{
if ($row['bot_agent'] && $bot_agent != '' && preg_match('#' . preg_quote($bot_agent, '#') . '#i', $user_agent)) $agent_match = 1;
}
// check for ip match
foreach (explode('|', $row['bot_ip']) as $bot_ip)
{
if ($row['bot_ip'] && $bot_ip != '' && strpos($user_ip, $bot_ip) === 0)
{
$ip_match = 1;
break;
}
}
// if both ip and agent matched update table and return true
if ($agent_match == 1 && $ip_match == 1)
{
// get time - seconds from epoch
$today = time();
$last_visits = explode('|', $row['last_visit']);
// if half an hour has passed since last visit
if (($today - (($last_visits[0] == '') ? 0 : $last_visits[0])) > 2700)
{
for ($i = ((4 > sizeof($last_visits)) ? sizeof($last_visits) : 4); $i >= 0; $i--)
{
if ($last_visits[$i-1] != '') $last_visits[$i] = $last_visits[$i-1];
}
// increment the new visit counter
$row['bot_visits']++;
// clear prior indexed pages
$row['bot_pages'] = 1;
} else {
// add to indexed pages
$row['bot_pages']++;
}
$last_visits[0] = $today;
// compress it all together
$last_visit = implode("|", $last_visits);
// update table
$sql = "UPDATE " . BOTS_TABLE . "
SET last_visit='$last_visit', bot_visits='" . $row['bot_visits'] . "', bot_pages='" . $row['bot_pages'] . "'
WHERE bot_id = " . $row['bot_id'];
if ( !($result2 = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Couldn\'t update data in bots table.', '', __LINE__, __FILE__, $sql);
}
return $row['bot_name'];
}
else
{
if ($agent_match == 1 || $ip_match == 1)
{
// get data from table
$sql = "SELECT pending_" . ((!$agent_match) ? 'agent' : 'ip') . "
FROM " . BOTS_TABLE . "
WHERE bot_id = " . $row['bot_id'];
if ( !($result2 = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain bot data.', '', __LINE__, __FILE__, $sql);
}
$row2 = $db->sql_fetchrow($result2);
// add ip/agent to the list
$pending_array = (( $row2['pending_' . ((!$agent_match) ? 'agent' : 'ip')] ) ? explode('|', $row2['pending_' . ((!$agent_match) ? 'agent' : 'ip')]) : array());
$found = 0;
if ( sizeof($pending_array) )
{
for ($loop = 0; $loop < count($pending_array); $loop+=2)
{
if ($pending_array[$loop] == ((!$agent_match) ? $user_agent : $user_ip)) $found = 1;
}
}
if ($found == 0)
{
$pending_array[] = ((!$agent_match) ? str_replace("|", "|", $user_agent) : $user_ip);
$pending_array[] = ((!$agent_match) ? $user_ip : str_replace("|", "|", $user_agent));
}
$pending = implode("|", $pending_array);
// update table
$sql = "UPDATE " . BOTS_TABLE . "
SET pending_" . ((!$agent_match) ? 'agent' : 'ip') . "='$pending'
WHERE bot_id = " . $row['bot_id'];
if ( !($result2 = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Couldn\'t update data in bots table.', '', __LINE__, __FILE__, $sql);
}
}
}
}
return 0;
}
#
#-----[ SAVE/CLOSE ALL FILES ]---------------------------------------
#
# EoM