You are here

abstract class FirewallModule in Anti Spam by CleanTalk 8.4

Same name and namespace in other branches
  1. 9.1.x src/lib/Cleantalk/Common/Firewall/FirewallModule.php \Cleantalk\Common\Firewall\FirewallModule

Hierarchy

Expanded class hierarchy of FirewallModule

3 files declare their use of FirewallModule
AntiCrawler.php in src/lib/Cleantalk/Common/Firewall/Modules/AntiCrawler.php
AntiFlood.php in src/lib/Cleantalk/Common/Firewall/Modules/AntiFlood.php
SFW.php in src/lib/Cleantalk/Common/Firewall/Modules/SFW.php

File

src/lib/Cleantalk/Common/Firewall/FirewallModule.php, line 20

Namespace

Cleantalk\Common\Firewall
View source
abstract class FirewallModule {

  /**
   * @var string
   */
  protected $api_key;

  /**
   * @var string
   */
  public $module_name = 'FireWall Module';

  /**
   * @var array
   */
  protected $ip_array = array();

  /**
   * @var DB
   */
  protected $db;

  /**
   * @var string
   */
  protected $db_log_table_name;

  /**
   * @var string
   */
  protected $db_data_table_name;

  /**
   * @var Helper
   */
  protected $helper;

  /**
   * @var string
   */
  protected $real_ip;

  /**
   * @var string
   */
  protected $test_ip;

  /**
   * @var bool
   */
  protected $test;

  /**
   * @var bool
   */
  protected $debug;

  /**
   * @var array
   */
  protected $debug_data = array();

  /**
   * FirewallModule constructor.
   * Use this method to prepare any data for the module working.
   *
   * @param string $data_table
   * @param array $params
   */
  public abstract function __construct($data_table, $params = array());

  /**
   * Use this method to execute main logic of the module.
   *
   * @return array  Array of the check results
   */
  public abstract function check();

  /**
   * Do logic for denied request.
   *
   * @param string $result
   * @return void
   */
  public abstract function actionsForDenied($result);

  /**
   * Do logic for allowed request.
   *
   * @param string $result
   * @return void
   */
  public abstract function actionsForPassed($result);

  /**
   * Configure and set additional properties: real_ip, test_ip, test
   *
   * @param array $ips
   * @return void
   */
  public function ipAppendAdditional($ips) {
    $this->real_ip = isset($ips['real']) ? $ips['real'] : null;
    if (Get::get('sfw_test_ip') && Helper::ip__validate(Get::get('sfw_test_ip')) !== false) {
      $this->ip_array['sfw_test'] = Get::get('sfw_test_ip');
      $this->test_ip = Get::get('sfw_test_ip');
      $this->test = true;
    }
  }

  /**
   * Set specify CMS based DB instance
   *
   * @param DB $db
   */
  public function setDb(DB $db) {
    $this->db = $db;
  }

  /**
   * Set Log Table name
   *
   * @param string $log_table_name
   */
  public function setLogTableName($log_table_name) {
    $this->db_data_table_name = $this->db->prefix . $this->db_data_table_name;
    $this->db_log_table_name = $log_table_name;
  }

  /**
   * Set specify CMS based Helper instance
   *
   * @param Helper $helper
   */
  public function setHelper(Helper $helper) {
    $this->helper = $helper;
  }

  /**
   * Set API KEY
   *
   * @param string $api_key
   */
  public function setApiKey($api_key) {
    $this->api_key = $api_key;
  }

  /**
   * Set is debug property.
   *
   * @param bool $debug
   */
  public function setIsDebug($debug) {
    $this->debug = $debug;
  }

  /**
   * Set visitor's IP
   *
   * @param array $ip_array    $ip_array = array( 'real' => '1.2.3.4' )
   */
  public function setIpArray($ip_array) {
    $this->ip_array = $ip_array;
  }

  /**
   * Default die page for blocked requests.
   *
   * @param array $result
   */
  public function _die($result) {

    // Headers
    if (headers_sent() === false) {
      header('Expires: ' . date(DATE_RFC822, mktime(0, 0, 0, 1, 1, 1971)));
      header('Cache-Control: no-store, no-cache, must-revalidate');
      header('Cache-Control: post-check=0, pre-check=0', FALSE);
      header('Pragma: no-cache');
      header("HTTP/1.0 403 Forbidden");
    }
  }

  /**
   * This is a placeholder for WP translation function.
   * For compatibility with any CMS.
   *
   * @param $string
   * @param $text_domain
   * @return mixed
   */
  public function __($string, $text_domain) {
    if (function_exists('__')) {
      return __($string, $text_domain);
    }
    return $string;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FirewallModule::$api_key protected property
FirewallModule::$db protected property
FirewallModule::$db_data_table_name protected property
FirewallModule::$db_log_table_name protected property
FirewallModule::$debug protected property
FirewallModule::$debug_data protected property
FirewallModule::$helper protected property
FirewallModule::$ip_array protected property
FirewallModule::$module_name public property 3
FirewallModule::$real_ip protected property *
FirewallModule::$test protected property *
FirewallModule::$test_ip protected property *
FirewallModule::actionsForDenied abstract public function Do logic for denied request. 3
FirewallModule::actionsForPassed abstract public function Do logic for allowed request. 3
FirewallModule::check abstract public function Use this method to execute main logic of the module. 3
FirewallModule::ipAppendAdditional public function Configure and set additional properties: real_ip, test_ip, test
FirewallModule::setApiKey public function Set API KEY
FirewallModule::setDb public function Set specify CMS based DB instance
FirewallModule::setHelper public function Set specify CMS based Helper instance
FirewallModule::setIpArray public function Set visitor's IP
FirewallModule::setIsDebug public function Set is debug property.
FirewallModule::setLogTableName public function Set Log Table name
FirewallModule::_die public function Default die page for blocked requests. 3
FirewallModule::__ public function This is a placeholder for WP translation function. For compatibility with any CMS.
FirewallModule::__construct abstract public function * FirewallModule constructor. * Use this method to prepare any data for the module working. * * 3