Source for file _functions_antispam.php
Documentation is available at _functions_antispam.php
* Antispam handling functions
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );
* Insert a new abuse string into DB
global $DB, $querycount, $tableantispam;
// Cut the crap if the string is empty:
$abuse_string =
trim( $abuse_string );
if( empty( $abuse_string ) ) return false;
// Check if the string already is in the blacklist:
// Insert new string into DB:
$sql =
"INSERT INTO $tableantispam( aspm_string, aspm_source )
VALUES( '".
$DB->escape($abuse_string).
"', '$aspm_source' )";
* antispam_update_source(-)
* Note: We search by string because we sometimes don't know the ID
* (e-g when download already in list/cache)
global $DB, $tableantispam, $querycount;
$sql =
"UPDATE $tableantispam
SET aspm_source = '$aspm_source'
WHERE aspm_string = '".
$DB->escape($aspm_string).
"'";
* Remove an entry from the ban list
global $tableantispam, $DB;
$sql =
"DELETE FROM $tableantispam
WHERE aspm_ID = $string_ID";
* Check if a string contains abusive substrings
* Note: Letting the database do the LIKE %% match is a little faster than doing in it PHP,
* not to mention the incredibly long overhead of preloading the list into PHP
* @return string balcklisted keyword found or false if no spam detected
if( $block =
$DB->get_var( "SELECT aspm_string
WHERE ".
$DB->quote($haystack).
" LIKE CONCAT('%',aspm_string,'%')
LIMIT 0, 1", 0, 0, 'Check URL against antispam balcklist' ) )
return $block; // SPAM detected!
return false; // no problem.
global $DB, $querycount, $tableantispam, $res_stats;
$sql =
"SELECT aspm_ID, aspm_string, aspm_source
ORDER BY aspm_string ASC";
$res_stats =
$DB->get_results( $sql, ARRAY_A );
echo
$row_stats['aspm_ID'];
* {@internal antiSpam_domain(-)}}
* @param mixed max length or false if we don't want to display
$domain =
$row_stats['aspm_string'];
if( strlen( $domain ) >
$dispmax )
echo
substr( $domain, 0, $dispmax ), '...';
global $row_stats, $aspm_sources;
$asp_source =
$row_stats['aspm_source'];
$asp_source =
T_( $aspm_sources[$asp_source] );
// -------------------- XML-RPC callers ---------------------------
* b2evonet_report_abuse(-)
* pings b2evolution.net to report abuse from a particular domain
global $debug, $antispamsrv_host, $antispamsrv_port, $antispamsrv_uri;
echo
"<div class=\"panelinfo\">\n";
echo
'<h3>'.
T_('Reporting abuse to').
' '.
$antispamsrv_host.
"...</h3>\n";
if( !preg_match( '#^http://localhost[/:]#', $baseurl) ||
( $antispamsrv_host ==
'localhost' ) )
{ // Local install can only report to local test server
// Construct XML-RPC client:
$client =
new xmlrpc_client( $antispamsrv_uri, $antispamsrv_host, $antispamsrv_port);
// Construct XML-RPC message:
'b2evo.reportabuse', // Function to be called
new xmlrpcval('annonymous','string'), // Reserved
new xmlrpcval('nopassrequired','string'), // Reserved
new xmlrpcval($abuse_string,'string'), // The abusive string to report
new xmlrpcval($baseurl,'string'), // The base URL of this b2evo
$result =
$client->send($message);
{ // Remote operation successful:
if( $display ) echo
'<p>', T_('Done.'), "</p>\n</div>\n";
if( $display ) echo
"<p>", T_('Aborted (Running on localhost).'), "</p>\n</div>\n";
* request abuse list from central blacklist
global $Settings, $baseurl, $debug, $antispamsrv_host, $antispamsrv_port, $antispamsrv_uri;
echo
"<div class=\"panelinfo\">\n";
echo
'<h3>', T_('Requesting abuse list from').
' '.
$antispamsrv_host.
'...', "</h3>\n";
// Construct XML-RPC client:
$client =
new xmlrpc_client( $antispamsrv_uri, $antispamsrv_host, $antispamsrv_port);
// Get datetime from last update, because we only want newer stuff...
$m =
$Settings->get( 'antispam_last_update' );
// Encode it in the XML-RPC format
echo
'<p>', T_('Latest update timestamp'), ': ', $m, '</p>';
//$startat = iso8601_encode( mktime(substr($m,11,2),substr($m,14,2),substr($m,17,2),substr($m,5,2),substr($m,8,2),substr($m,0,4)) );
// Construct XML-RPC message:
'b2evo.pollabuse', // Function to be called
new xmlrpcval('annonymous','string'), // Reserved
new xmlrpcval('nopassrequired','string'), // Reserved
new xmlrpcval($startat,'dateTime.iso8601'), // Datetime to start at
$result =
$client->send($message);
{ // Response is not an error, let's process it:
$response =
$result->value();
if( $response->kindOf() ==
'struct' )
if( !isset
( $response['strings'] ) ||
!isset
( $response['lasttimestamp'] ) )
echo
T_('Incomplete reponse.').
"\n";
{ // Start registering strings:
$value =
$response['strings'];
echo
'<p>', T_('No new blacklisted strings are available.'), '</p>';
{ // We got an array of strings:
echo
'<p>', T_('Adding strings to local blacklist'), ':</p><ul>';
foreach($value as $banned_string)
echo
'<li>', T_('Adding:'), ' [', $banned_string, '] : ';
echo
T_('Not necessary! (Already handled)');
// Store latest timestamp:
echo
'<p>', T_('New latest update timestamp'), ': ', $endedat, '</p>';
$Settings->set( 'antispam_last_update', $endedat );
echo
T_('Invalid reponse.').
"\n";
if( $display ) echo
'<p>', T_('Done.'), "</p>\n</div>\n";