Skip to content

Commit

Permalink
Fix whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
W1zzardTPU committed Dec 2, 2015
1 parent aee7bd4 commit a203689
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 278 deletions.
134 changes: 67 additions & 67 deletions upload/library/TPUDetectSpamReg/AS.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,93 +27,93 @@ static function isIPv6($ip)
return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
}

static function getASNameAndNumber($ip, &$asNumber, &$asName)
{
static function getASNameAndNumber($ip, &$asNumber, &$asName)
{
if (self::isIPv6($ip))
$dns=dns_get_record(self::reverseIPv6($ip).'.origin6.asn.cymru.com', DNS_TXT);
else
$dns=dns_get_record(self::reverseIP($ip).'.origin.asn.cymru.com', DNS_TXT);
$dns=dns_get_record(self::reverseIP($ip).'.origin.asn.cymru.com', DNS_TXT);
if ((is_array($dns)) && (isset($dns[0])))
{
$items=explode('|', $dns[0]['txt'], 2);
$items=array_shift($items);
$asNumber=intval($items);
if ($asNumber>0)
{
$dns=dns_get_record('AS'.$asNumber.'.asn.cymru.com', DNS_TXT);
if ((is_array($dns)) && (isset($dns[0])))
{
$tokens=explode('|', $dns[0]['txt']);
$asName=trim($tokens[4]);

return TRUE;
}
}
$asNumber=intval($items);
if ($asNumber>0)
{
$dns=dns_get_record('AS'.$asNumber.'.asn.cymru.com', DNS_TXT);
if ((is_array($dns)) && (isset($dns[0])))
{
$tokens=explode('|', $dns[0]['txt']);
$asName=trim($tokens[4]);

return TRUE;
}
}
}

return FALSE;

// Old slow code
try {
$networkinfo=json_decode(file_get_contents('https://stat.ripe.net/data/network-info/data.json?resource='.$ip));
$asNumber=$networkinfo->data->asns[0];
$asInfo=json_decode(file_get_contents('https://stat.ripe.net/data/as-overview/data.json?resource=AS'.$asNumber));
$asName=$asInfo->data->holder;
try {
$networkinfo=json_decode(file_get_contents('https://stat.ripe.net/data/network-info/data.json?resource='.$ip));
$asNumber=$networkinfo->data->asns[0];
$asInfo=json_decode(file_get_contents('https://stat.ripe.net/data/as-overview/data.json?resource=AS'.$asNumber));
$asName=$asInfo->data->holder;

return TRUE;
} catch (Exception $e) {};
return TRUE;
} catch (Exception $e) {};

return FALSE;
}
return FALSE;
}

static function getRegSpamScore(&$score, array $user, $verbose, $debug, $model)
{
$o=XenForo_Application::getOptions();

if (trim($o->TPUDetectSpamRegAS)!='')
{
if (self::getASNameAndNumber($user['ip'], $asNumber, $asName))
{
if ($verbose)
$model->logScore('tpu_detectspamreg_as_detected', 0, array('number'=>$asNumber, 'name'=>$asName));

foreach (explode("\n", $o->TPUDetectSpamRegAS) as $entry)
{
$entry=explode('|', trim($entry));
if (count($entry)!=2)
continue;

list($points, $match)=$entry;

if ((is_numeric($match)) && ($match>0))
{
if ((int)$match==(int)$asNumber)
{
$model->logScore('tpu_detectspamreg_as_fail', $points, array('number'=>$asNumber, 'name'=>$asName));
if (is_numeric($points))
$score['points']+=$points;
else
$score[$points]=true;
}
} else
{
$asName=strtok($asName, ' ');
$regex=$model->buildWildcardRegex($match);

if (preg_match('/^'.$regex.'$/iU', $asName))
{
$model->logScore('tpu_detectspamreg_as_fail', $points, array('number'=>$asNumber, 'name'=>$asName));
if (trim($o->TPUDetectSpamRegAS)!='')
{
if (self::getASNameAndNumber($user['ip'], $asNumber, $asName))
{
if ($verbose)
$model->logScore('tpu_detectspamreg_as_detected', 0, array('number'=>$asNumber, 'name'=>$asName));

foreach (explode("\n", $o->TPUDetectSpamRegAS) as $entry)
{
$entry=explode('|', trim($entry));
if (count($entry)!=2)
continue;

list($points, $match)=$entry;

if ((is_numeric($match)) && ($match>0))
{
if ((int)$match==(int)$asNumber)
{
$model->logScore('tpu_detectspamreg_as_fail', $points, array('number'=>$asNumber, 'name'=>$asName));
if (is_numeric($points))
$score['points']+=$points;
else
$score[$points]=true;
}
} else
{
$asName=strtok($asName, ' ');
$regex=$model->buildWildcardRegex($match);

if (preg_match('/^'.$regex.'$/iU', $asName))
{
$model->logScore('tpu_detectspamreg_as_fail', $points, array('number'=>$asNumber, 'name'=>$asName));
if (is_numeric($points))
$score['points']+=$points;
$score['points']+=$points;
else
$score[$points]=true;
} else
if ($debug)
$model->logScore('tpu_detectspamreg_as_ok', 0, array('number'=>$asNumber, 'name'=>$match));
}
}
}
}
$score[$points]=true;
} else
if ($debug)
$model->logScore('tpu_detectspamreg_as_ok', 0, array('number'=>$asNumber, 'name'=>$match));
}
}
}
}
}
}
40 changes: 20 additions & 20 deletions upload/library/TPUDetectSpamReg/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ static function getRegSpamScore(&$score, array $user, $verbose, $debug, $model)
$o=XenForo_Application::getOptions();

if (trim($o->TPUDetectSpamRegEmail)!='')
{
$email=$user['email'];
{
$email=$user['email'];

foreach (explode("\n", $o->TPUDetectSpamRegEmail) as $entry)
{
foreach (explode("\n", $o->TPUDetectSpamRegEmail) as $entry)
{
$entry=explode('|', trim($entry));
if (count($entry)!=2)
continue;
if (count($entry)!=2)
continue;

list($points, $match)=$entry;
list($points, $match)=$entry;

$regex=$model->buildWildcardRegex($match);
$regex=$model->buildWildcardRegex($match);

if (preg_match('/^'.$regex.'$/iU', $email))
{
$model->logScore('tpu_detectspamreg_email_fail', $points, array('email'=>$match));
if (is_numeric($points))
$score['points']+=$points;
else
$score[$points]=true;
} else
if ($debug)
$model->logScore('tpu_detectspamreg_email_ok', 0, array('email'=>$match));
}
}
if (preg_match('/^'.$regex.'$/iU', $email))
{
$model->logScore('tpu_detectspamreg_email_fail', $points, array('email'=>$match));
if (is_numeric($points))
$score['points']+=$points;
else
$score[$points]=true;
} else
if ($debug)
$model->logScore('tpu_detectspamreg_email_ok', 0, array('email'=>$match));
}
}
}
}
40 changes: 20 additions & 20 deletions upload/library/TPUDetectSpamReg/EmailLength.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@ static function getRegSpamScore(&$score, array $user, $verbose, $debug, $model)
$email=array_shift($items);

if (trim($o->TPUDetectSpamRegEmailLen20)!=0)
{
if (strlen($email)>=20)
{
$model->logScore('tpu_detectspamreg_emaillen_fail', $o->TPUDetectSpamRegEmailLen20, array('length'=>20, 'email'=>$email));
$score['points']+=$o->TPUDetectSpamRegEmailLen20;
return;
} else
if ($debug)
$model->logScore('tpu_detectspamreg_emaillen_ok', 0, array('length'=>20, 'email'=>$email));
}
{
if (strlen($email)>=20)
{
$model->logScore('tpu_detectspamreg_emaillen_fail', $o->TPUDetectSpamRegEmailLen20, array('length'=>20, 'email'=>$email));
$score['points']+=$o->TPUDetectSpamRegEmailLen20;
return;
} else
if ($debug)
$model->logScore('tpu_detectspamreg_emaillen_ok', 0, array('length'=>20, 'email'=>$email));
}

if (trim($o->TPUDetectSpamRegEmailLen15)!=0)
{
if (strlen($email)>=15)
{
$model->logScore('tpu_detectspamreg_emaillen_fail', $o->TPUDetectSpamRegEmailLen15, array('length'=>15, 'email'=>$email));
$score['points']+=$o->TPUDetectSpamRegEmailLen15;
return;
} else
if ($debug)
$model->logScore('tpu_detectspamreg_emaillen_ok', 0, array('length'=>15, 'email'=>$email));
}
{
if (strlen($email)>=15)
{
$model->logScore('tpu_detectspamreg_emaillen_fail', $o->TPUDetectSpamRegEmailLen15, array('length'=>15, 'email'=>$email));
$score['points']+=$o->TPUDetectSpamRegEmailLen15;
return;
} else
if ($debug)
$model->logScore('tpu_detectspamreg_emaillen_ok', 0, array('length'=>15, 'email'=>$email));
}
}
}
14 changes: 7 additions & 7 deletions upload/library/TPUDetectSpamReg/HoneyPot.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ static function getRegSpamScore(&$score, array $user, $verbose, $debug, $model)
{
$o=XenForo_Application::getOptions();

if ($o->TPUDetectSpamRegHoneyPotEnabled)
{
// Only IPv4 supported
if (filter_var($user['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)==FALSE)
return;
if ($o->TPUDetectSpamRegHoneyPotEnabled)
{
// Only IPv4 supported
if (filter_var($user['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)==FALSE)
return;
$dnsBl=new XenForo_DnsBl($o->TPUDetectSpamRegHoneyPotAPIKey.'.%s.dnsbl.httpbl.org');
$res=$dnsBl->checkIp($user['ip']);
if (is_array($res))
Expand Down Expand Up @@ -46,6 +46,6 @@ static function getRegSpamScore(&$score, array $user, $verbose, $debug, $model)
$model->logScore('tpu_detectspamreg_honeypot_ok', 0);
}
}
}
}
}
}
44 changes: 22 additions & 22 deletions upload/library/TPUDetectSpamReg/Hostname.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,33 @@ static function getRegSpamScore(&$score, array $user, $verbose, $debug, $model)
$o=XenForo_Application::getOptions();

if (trim($o->TPUDetectSpamRegHostname)!='')
{
$hostname=gethostbyaddr($user['ip']);
{
$hostname=gethostbyaddr($user['ip']);

if ($verbose)
$model->logScore('tpu_detectspamreg_hostname_detected', 0, array('hostname'=>$hostname));
if ($verbose)
$model->logScore('tpu_detectspamreg_hostname_detected', 0, array('hostname'=>$hostname));

foreach (explode("\n", $o->TPUDetectSpamRegHostname) as $entry)
{
foreach (explode("\n", $o->TPUDetectSpamRegHostname) as $entry)
{
$entry=explode('|', trim($entry));
if (count($entry)!=2)
continue;
if (count($entry)!=2)
continue;

list($points, $match)=$entry;
list($points, $match)=$entry;

$regex=$model->buildWildcardRegex($match);
$regex=$model->buildWildcardRegex($match);

if (preg_match('/^'.$regex.'$/iU', $hostname))
{
$model->logScore('tpu_detectspamreg_hostname_fail', $points, array('hostname'=>$match));
if (is_numeric($points))
$score['points']+=$points;
else
$score[$points]=true;
} else
if ($debug)
$model->logScore('tpu_detectspamreg_hostname_ok', 0, array('hostname'=>$match));
}
}
if (preg_match('/^'.$regex.'$/iU', $hostname))
{
$model->logScore('tpu_detectspamreg_hostname_fail', $points, array('hostname'=>$match));
if (is_numeric($points))
$score['points']+=$points;
else
$score[$points]=true;
} else
if ($debug)
$model->logScore('tpu_detectspamreg_hostname_ok', 0, array('hostname'=>$match));
}
}
}
}
Loading

0 comments on commit a203689

Please sign in to comment.