Skip to content

Instantly share code, notes, and snippets.

@k0nsl
Created February 11, 2015 15:02
Show Gist options
  • Save k0nsl/f5e1be192f61b3730898 to your computer and use it in GitHub Desktop.
Save k0nsl/f5e1be192f61b3730898 to your computer and use it in GitHub Desktop.
A hook to query if an IP is located in the database of stopforumspam.com
<?php
/**
* Copyright (C) 2013 by k0nsl ([email protected])
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* This hook queries stopforumspam.com to check if the IP is listed in their DB
*/
function hook_stop_forumspam(&$hook)
{
$req_uri = $_SERVER['REQUEST_URI'];
$reg_pattern = '/mode=register/';
if (preg_match($reg_pattern, $req_uri)) {
$addr = $_SERVER['REMOTE_ADDR'];
$response = curl_get('http://www.stopforumspam.com/api?ip='.$addr);
$pattern = '/<appears>yes<\/appears>/';
if (preg_match($pattern, $response)) {
/* IP is listed, so we inform the user, then exit. */
echo '
<html>
<head>
<title>Spammer detected</title>
</head>
<body>
<h1>IP Detected As Spam Source</h1>
We are sorry, but you are not allowed to register at this
<br>message board as long as your IP address is listed
<br>at stopforumspam.com.
<p>
Once your IP address is removed, you will be allowed. If you think this is an error, please write to mail[at]domain.tld
</body>
</html>
';
exit();
}
}
}
/**
* Replaced file_get_contents with cURL
*/
function curl_get($url) {
if (!function_exists('curl_init')){
die('Error: cURL is not installed.');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
/**
* We want it only on normal pages and not administrative ones.
*/
if (!defined('ADMIN_START'))
{
$phpbb_hook->register(array('template', 'display'), 'hook_stop_forumspam');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment