You are here

public function Firewall::run in Anti Spam by CleanTalk 8.4

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

Do main logic of the module.

Return value

void returns die page or set cookies

File

src/lib/Cleantalk/Common/Firewall/Firewall.php, line 164

Class

Firewall

Namespace

Cleantalk\Common\Firewall

Code

public function run() {
  $this->module_names = array_keys($this->fw_modules);
  $results = array();

  // Checking
  foreach ($this->fw_modules as $module) {
    if (isset($module->isExcluded) && $module->isExcluded) {
      continue;
    }
    $module_results = $module
      ->check();
    if (!empty($module_results)) {
      $results[$module->module_name] = $module_results;
    }
    if ($this
      ->isWhitelisted($results)) {

      // Break protection logic if it whitelisted or trusted network.
      break;
    }
  }

  // Write Logs
  foreach ($this->fw_modules as $module) {
    if (array_key_exists($module->module_name, $results)) {
      foreach ($results[$module->module_name] as $result) {
        if (in_array($result['status'], array(
          'PASS_SFW__BY_WHITELIST',
          'PASS_SFW',
          'PASS_ANTIFLOOD',
          'PASS_ANTICRAWLER',
          'PASS_ANTICRAWLER_UA',
          'PASS_ANTIFLOOD_UA',
        ))) {
          continue;
        }
        $module
          ->update_log($result['ip'], $result['status'], !empty($result['network']) ? $result['network'] : null, !empty($result['is_personal']) ? $result['is_personal'] : null);
      }
    }
  }

  // Get the primary result
  $result = $this
    ->prioritize($results);

  // Do finish action - die or set cookies
  foreach ($this->module_names as $module_name) {
    if (strpos($result['status'], $module_name)) {

      // Blocked
      if (strpos($result['status'], 'DENY') !== false) {
        $this->fw_modules[$module_name]
          ->actionsForDenied($result);
        $this->fw_modules[$module_name]
          ->_die($result);

        // Allowed
      }
      else {
        $this->fw_modules[$module_name]
          ->actionsForPassed($result);
      }
    }
  }
}