You are here

public function HttpblEvaluator::drushWhitelist in http:BL 8

Emergency White-list Update of Host IP.

Overrides HttpblEvaluatorInterface::drushWhitelist

File

src/HttpblEvaluator.php, line 503

Class

HttpblEvaluator
HttpblEvaluator evaluates visitor/host page requests.

Namespace

Drupal\httpbl

Code

public function drushWhitelist($ip) {

  // Set a default of 48 hours.
  $offset = 172800;

  // Take the higher of the default or the configured offset for safe hosts.
  $offsetConfig = \Drupal::state()
    ->get('httpbl.safe_offset');

  //$max <= $limit ?: $max = $limit;
  $offset >= $offsetConfig ?: ($offset = $offsetConfig);
  $hosts = HostQuery::loadHostsByIp($ip);
  if (isset($hosts) && !empty($hosts)) {
    foreach ($hosts as $host) {
      $host
        ->setHostStatus(0);
      $host
        ->setExpiry(\Drupal::time()
        ->getRequestTime() + $offset);
      $host
        ->setSource(HTTPBL_DRUSH_SOS_SOURCE);
      $host
        ->save();
    }
  }
  else {

    // Warning to identify any abuse.
    $this->logTrapper
      ->trapWarning('Drush whitelist did not find IP @ip.', [
      '@ip' => $ip,
    ]);
  }
}