Advertisement:

Author Topic: StopForumSpam added to /root/sources/Register.php  (Read 441 times)

Offline rho_simafo

  • Semi-Newbie
  • *
  • Posts: 21
StopForumSpam added to /root/sources/Register.php
« on: July 21, 2018, 05:40:31 AM »
Since I could not find an uptodate mod for using stopforumspam I simple added my own code to the file which seems to be processed when user try to register a new account. So far spammer were no longer successfull in registering new accounts. :laugh:

Since I'm not an expert in SMF programming I kindly ask experienced users to check the file in the appendix:
1) Is the file the right location for applying stopforumspam?
2) If there is a better place or a better strategy I kindly ask for a reommendation

PS: The changes in detail
At the beginning of the file /sources/Register.php before function Register($reg_errors = array()) add these two functions:
Code: [Select]
function HTTP_Fetch($http)
{
$t = explode ("?",$http);
$url=$t[0];

if (isset($t[1]))
$query = "?".$t[1];
else
$query = "";

$canFopen  = (@ini_get('allow_url_fopen') == 1) ? 'YES' : 'NO';
$canSocket = (@is_callable('fsockopen')) ? 'YES' : 'NO';
$canCurl   = (@function_exists("curl_init")) ? 'YES' : 'NO';
$response  = array("data"=>"","mode"=>"");

if ($canFopen=='YES') {
$handle = @fopen($url.$query, 'r');
if ($handle) {
while (!feof($handle)) {
$response['data'] .= fread($handle, 128);
}
fclose($handle);
}
$response['mode']="Fopen";
return ($response);
} elseif ($canSocket=='YES') {
$buff=str_replace ("http://","",$url);
$ext = explode ("/",$buff);
$buff1 = $ext[0];
unset ($ext[0]);
$add = implode ("/",$ext);
//echo $buff1;
$fp = fsockopen($buff1, 80, $errno, $errstr, 10);
if(!$fp) {
$response['mode']="Fsocket - ".'Socket Error : '.$errstr . " - ". $errno;
$response['data'] = 'Socket Error : '.$errstr . " - ". $errno;
return ($response);
}
if(@function_exists('stream_set_timeout')) @stream_set_timeout($fp,10);
@fwrite($fp,
"GET /".$add.$query." HTTP/1.0\r\n".
"Host: ".$buff1."\r\n".
"User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:2.0.1) Gecko/20100101 Firefox/4.0.1\r\n".
"Referer: .\r\n".
"Connection: close\r\n".
"\r\n"
);
$response['data'] = '';
while (!feof($fp)) { $response['data'] .= @fread($fp,10240); }
@fclose($fp);
$response['data'] = trim((string)strstr($response['data'],"\r\n\r\n"));
$response['mode']="Fsocket";
return ($response);
} elseif ($canCurl=='YES') {
$curlHandle = curl_init();
curl_setopt($curlHandle, CURLOPT_URL,$url.$query);
curl_setopt($curlHandle, CURLOPT_HEADER, 0);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlHandle, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.0; rv:2.0.1) Gecko/20100101 Firefox/4.0.1");
curl_setopt($curlHandle, CURLOPT_REFERER, $url);
if (ini_get("safe_mode") || ini_get("open_basedir"))
{ ; } else
{
  curl_setopt($curlHandle, CURLOPT_FOLLOWLOCATION, 1);
}
curl_setopt($curlHandle, CURLOPT_MAXREDIRS, 10);
$response['data'] = curl_exec($curlHandle);
        curl_close($curlHandle);
$response['mode']="Curl";
return ($response);
} else {
$response['mode']="none";
$response['data'] = 'No connection possible !!!';
return ($response);
}
}
function getUserIP()
{
    // Get real visitor IP behind CloudFlare network
    if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
              $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
              $_SERVER['HTTP_CLIENT_IP'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
    }
    $client  = @$_SERVER['HTTP_CLIENT_IP'];
    $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
    $remote  = $_SERVER['REMOTE_ADDR'];

    if(filter_var($client, FILTER_VALIDATE_IP))
    {
        $ip = $client;
    }
    elseif(filter_var($forward, FILTER_VALIDATE_IP))
    {
        $ip = $forward;
    }
    else
    {
        $ip = $remote;
    }

    return $ip;
}


At the beginning of function Register (...) add:
Code: [Select]
/**********************************************************************************
 * Begin: StopforumSpam
 * added by rho and rst
 */
$answer= array();
$url = "https://www.stopforumspam.com/api?ip=".getUserIP();
$answer = HTTP_Fetch($url);
if(preg_match("/yes/",$answer['data'])) { /* If answer == yes, it is a known spammer who tries to register */
/* **************************************
 * begin: record registration infos
 * Remove the following lines if you don't need recording of registration events
 */
If (!file_exists('./spam_events/')) mkdir ('spam_events');
$RecordFilePath = './spam_events/record.dat';
If (file_exists($RecordFilePath)) {
$recordDat = file_get_contents($RecordFilePath).date('Y.m.d G:i:s').':: IP = '.getUserIP().' / _GET = '.print_r($_GET,TRUE).PHP_EOL;

} Else {
$recordDat = date('Y.m.d G:i:s').':: IP = '.getUserIP().' / _GET = '.print_r($_GET,TRUE).PHP_EOL;
}
file_put_contents($RecordFilePath, $recordDat );
/*
 * end: record registration infos
 * **************************************/
$_POST = array();
$_GET = array();
exit();
}
/*
 * End: StopforumSpam
 ********************************************************************************* */


Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 8,326
  • Riding the long highway in the sky.
Re: StopForumSpam added to /root/sources/Register.php
« Reply #1 on: July 21, 2018, 11:16:56 PM »
Stop forum spam 1.0 installs and works fine in 2.0.15, why are you dicking around with the code?

Offline rho_simafo

  • Semi-Newbie
  • *
  • Posts: 21
Re: StopForumSpam added to /root/sources/Register.php
« Reply #2 on: July 22, 2018, 02:57:58 AM »
Sir Osis,

Thank you for this hint with stopforumspam 1.0. So far I could find StopSpammer_v2_3_9 only, which I was unable to install. stopforumspam 1.0 I could install successfully.

So my problems seem to be solved!