You are here

private function FirewallUpdater::writeDbExclusions in Anti Spam by CleanTalk 8.4

Same name and namespace in other branches
  1. 9.1.x src/lib/Cleantalk/Common/Firewall/FirewallUpdater.php \Cleantalk\Common\Firewall\FirewallUpdater::writeDbExclusions()

Writing to the DB self IPs

Return value

array|int

1 call to FirewallUpdater::writeDbExclusions()
FirewallUpdater::update in src/lib/Cleantalk/Common/Firewall/FirewallUpdater.php

File

src/lib/Cleantalk/Common/Firewall/FirewallUpdater.php, line 335

Class

FirewallUpdater

Namespace

Cleantalk\Common\Firewall

Code

private function writeDbExclusions() {
  $query = "INSERT INTO " . $this->fw_data_table_name . "_temp (network, mask, status) VALUES ";
  $exclusions = array();

  //Exclusion for servers IP (SERVER_ADDR)
  if (Server::get('HTTP_HOST')) {

    // Exceptions for local hosts
    if (!in_array(Server::get_domain(), array(
      'lc',
      'loc',
      'lh',
    ))) {
      $exclusions[] = Helper::dns__resolve(Server::get('HTTP_HOST'));
      $exclusions[] = '127.0.0.1';
    }
  }
  foreach ($exclusions as $exclusion) {
    if (Helper::ip__validate($exclusion) && sprintf('%u', ip2long($exclusion))) {
      $query .= '(' . sprintf('%u', ip2long($exclusion)) . ', ' . sprintf('%u', bindec(str_repeat('1', 32))) . ', 1),';
    }
  }
  if ($exclusions) {
    $sql_result = $this->db
      ->execute(substr($query, 0, -1) . ';');
    return $sql_result === false ? array(
      'error' => 'COULD_NOT_WRITE_TO_DB 4: ' . $this->db
        ->get_last_error(),
    ) : count($exclusions);
  }
  return 0;
}