public function HttpblEvaluator::setIpLocalStatus in http:BL 8
Create and store new evaluated hosts to httpbl_host table.
(legacy name was "_httpbl_cache_set")
Overrides HttpblEvaluatorInterface::setIpLocalStatus
1 call to HttpblEvaluator::setIpLocalStatus()
- HttpblEvaluator::evaluateVisitor in src/
HttpblEvaluator.php - Manages remote and local lookups on visiting host IPs, evaluates their remote status as safe or suspicious and determines a locally stored status (safe / white-listed, grey-listed, or blacklisted) which is used (by other functions) to determine an…
File
- src/
HttpblEvaluator.php, line 440
Class
- HttpblEvaluator
- HttpblEvaluator evaluates visitor/host page requests.
Namespace
Drupal\httpblCode
public function setIpLocalStatus($ip, $status, $offset = 0) {
$hosts = HostQuery::loadHostsByIp($ip);
if (isset($hosts) && empty($hosts)) {
$host = Host::create([
'host_ip' => $ip,
'host_status' => $status,
'expire' => \Drupal::time()
->getRequestTime() + $offset,
'source' => HTTPBL_ORIGINAL_SOURCE,
]);
$host
->save();
$project_link = $host
->projectLink();
$source = $host
->getSource();
// If configured to also ban blacklisted IPs via Drupal Core Ban module...
if ($status == HTTPBL_LIST_BLACK && \Drupal::state()
->get('httpbl.storage') == HTTPBL_DB_HH_DRUPAL && \Drupal::moduleHandler()
->moduleExists('ban')) {
// Ban this IP!
$this->banManager
->banIp($ip);
$this->logTrapper
->trapNotice('Host: new blacklisted and banned @title. Source: @source.', array(
'@title' => $host
->label(),
'@source' => $source,
'link' => $project_link,
));
}
elseif ($status == HTTPBL_LIST_BLACK && \Drupal::state()
->get('httpbl.storage') == HTTPBL_DB_HH) {
$this->logTrapper
->trapNotice('Host: new blacklisted @title. Source: @source.', array(
'@title' => $host
->label(),
'@source' => $source,
'link' => $project_link,
));
}
elseif ($status == HTTPBL_LIST_GREY) {
$this->logTrapper
->trapNotice('Host: new grey-listed @title. Source: @source.', array(
'@title' => $host
->label(),
'@source' => $source,
'link' => $project_link,
));
}
elseif ($status == HTTPBL_LIST_SAFE) {
// Most IPs should be safe, so only log this as Info.
$this->logTrapper
->trapInfo('Host: new white-listed @title. Source: @source.', array(
'@title' => $host
->label(),
'@source' => $source,
'link' => $project_link,
));
}
return;
}
else {
$this->logTrapper
->trapError('Attempt to add host @ip, but it already exists!', [
'@ip' => $ip,
]);
}
return FALSE;
}