public function SFW::check_ip in Anti Spam by CleanTalk 8.3
File
- src/
lib/ Cleantalk/ Antispam/ SFW.php, line 59
Class
Namespace
Drupal\cleantalk\lib\Cleantalk\AntispamCode
public function check_ip() {
$this
->ip_get();
if (isset($_COOKIE['ct_sfw_pass_key']) && $_COOKIE['ct_sfw_pass_key'] == md5($this->ips_array['real']['ip'] . $this->api_key)) {
if (isset($_COOKIE['ct_sfw_passed'])) {
@setcookie('ct_sfw_passed');
//Deleting cookie
$this
->sfw_update_logs($this->ips_array['real']['ip'], false);
}
return;
}
foreach ($this->ips_array as $type => $ip) {
$current_ip_v4 = sprintf("%u", ip2long($ip['ip']));
for ($needles = array(), $m = 6; $m <= 32; $m++) {
$mask = sprintf("%u", ip2long(long2ip(-1 << 32 - (int) $m)));
$needles[] = bindec(decbin($mask) & decbin($current_ip_v4));
}
$needles = array_unique($needles);
$query = "SELECT \n\t\t\t\tnetwork, mask, status\n\t\t\t\tFROM " . $this->table_prefix . "cleantalk_sfw\n\t\t\t\tWHERE network IN (" . implode(',', $needles) . ")\n\t\t\t\tAND network = " . $current_ip_v4 . " & mask\n\t\t\t\tORDER BY status DESC LIMIT 1;";
$this
->universal_query($query);
$result = $this
->universal_fetch();
if ($result) {
if ($result['status'] == 0) {
$this->ips_array[$type]['in_list'] = true;
$this
->sfw_update_logs($this->ips_array[$type]['ip'], true);
}
}
}
if (isset($this->ips_array['test']) || $this->ips_array['real']['in_list']) {
$this
->sfw_die();
}
}