function spambot_account_is_spammer in Spambot 6.3
Same name and namespace in other branches
- 8 spambot.module \spambot_account_is_spammer()
- 7 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
Return value
positive if spammer, 0 if not spammer, negative if error
1 call to spambot_account_is_spammer()
- spambot_cron in ./
spambot.module - Implementation of hook_cron
File
- ./
spambot.module, line 272
Code
function spambot_account_is_spammer($account) {
$email_threshold = variable_get('spambot_criteria_email', 1);
$username_threshold = variable_get('spambot_criteria_username', 0);
$ip_threshold = variable_get('spambot_criteria_ip', 20);
// Build request parameters according to the criteria to use
$request = array();
if (!empty($account->mail) && $email_threshold > 0) {
$request['email'] = $account->mail;
}
if (!empty($account->name) && $username_threshold > 0) {
$request['username'] = $account->name;
}
// Only do a remote API request if there is anything to check
if (count($request)) {
$data = array();
if (spambot_sfs_request($request, $data)) {
if ($email_threshold > 0 && !empty($data['email']['appears']) && $data['email']['frequency'] >= $email_threshold || $username_threshold > 0 && !empty($data['username']['appears']) && $data['username']['frequency'] >= $username_threshold) {
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) === 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;
}