function spambot_account_is_spammer in Spambot 7
Same name and namespace in other branches
- 8 spambot.module \spambot_account_is_spammer()
- 6.3 spambot.module \spambot_account_is_spammer()
Checks an account to see if it's a spammer.
This one uses configurable automated criteria checking of email and username only.
Parameters
object $account: User account.
Return value
int Positive if spammer, 0 if not spammer, negative if error.
1 call to spambot_account_is_spammer()
- spambot_cron in ./
spambot.module - Implements hook_cron().
File
- ./
spambot.module, line 429 - Main module file.
Code
function spambot_account_is_spammer($account) {
$email_threshold = variable_get('spambot_criteria_email', SPAMBOT_DEFAULT_CRITERIA_EMAIL);
$username_threshold = variable_get('spambot_criteria_username', SPAMBOT_DEFAULT_CRITERIA_USERNAME);
$ip_threshold = variable_get('spambot_criteria_ip', SPAMBOT_DEFAULT_CRITERIA_IP);
// Build request parameters according to the criteria to use.
$request = array();
if ($email_threshold > 0) {
foreach (array(
'init',
'mail',
) as $_email_property) {
if (!empty($account->{$_email_property}) && !spambot_check_whitelist('email', $account->{$_email_property})) {
$request['email'][] = $account->{$_email_property};
}
}
}
if (!empty($account->name) && $username_threshold > 0 && !spambot_check_whitelist('username', $account->name)) {
$request['username'] = $account->name;
}
// Only do a remote API request if there is anything to check.
if ($request) {
$data = array();
if (spambot_sfs_request($request, $data)) {
$email_condition = FALSE;
if ($email_threshold > 0) {
foreach ($data['email'] as $_email) {
if (!empty($_email['appears']) && $_email['frequency'] >= $email_threshold) {
$email_condition = TRUE;
break;
}
}
}
$username_condition = $username_threshold > 0 && !empty($data['username']['appears']) && $data['username']['frequency'] >= $username_threshold;
if ($email_condition || $username_condition) {
return 1;
}
}
else {
// Return error.
return -1;
}
}
// Now check IP's
// If any IP matches the threshold, then flag as a spammer.
if ($ip_threshold > 0) {
$ips = spambot_account_ip_addresses($account);
foreach ($ips as $ip) {
// Skip the loopback interface.
if ($ip == '127.0.0.1') {
continue;
}
elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6) === FALSE) {
$link = l(t('user'), 'user/' . $account->uid);
watchdog('spambot', 'Invalid IP address: %ip (uid=%uid, name=%name, email=%email). Spambot will not rely on it.', array(
'%ip' => $ip,
'%name' => $account->name,
'%email' => $account->mail,
'%uid' => $account->uid,
), WATCHDOG_NOTICE, $link);
continue;
}
$request = array(
'ip' => $ip,
);
$data = array();
if (spambot_sfs_request($request, $data)) {
if (!empty($data['ip']['appears']) && $data['ip']['frequency'] >= $ip_threshold) {
return 1;
}
}
else {
// Abort on error.
return -1;
}
}
}
// Return no match.
return 0;
}