You are here

public function AntiCrawler::_die in Anti Spam by CleanTalk 9.1.x

Same name and namespace in other branches
  1. 8.4 src/lib/Cleantalk/Common/Firewall/Modules/AntiCrawler.php \Cleantalk\Common\Firewall\Modules\AntiCrawler::_die()

@inheritdoc

Overrides FirewallModule::_die

File

src/lib/Cleantalk/Common/Firewall/Modules/AntiCrawler.php, line 261

Class

AntiCrawler

Namespace

Cleantalk\Common\Firewall\Modules

Code

public function _die($result) {
  parent::_die($result);

  // File exists?
  if (file_exists(__DIR__ . "/die_page_anticrawler.html")) {
    $die_page = file_get_contents(__DIR__ . "/die_page_anticrawler.html");
    $net_count = $this->db
      ->fetch('SELECT COUNT(*) as net_count FROM ' . $this->db__table__sfw)['net_count'];

    // Translation
    $replaces = array(
      '{SFW_DIE_NOTICE_IP}' => 'Anti-Crawler Protection is activated for your IP ',
      '{SFW_DIE_MAKE_SURE_JS_ENABLED}' => 'To continue working with the web site, please make sure that you have enabled JavaScript.',
      '{SFW_DIE_YOU_WILL_BE_REDIRECTED}' => 'You will be automatically redirected to the requested page after 3 seconds.<br>' . 'Don\'t close this page. Please, wait for 3 seconds to pass to the page.',
      '{CLEANTALK_TITLE}' => $this
        ->__('Antispam by CleanTalk', 'cleantalk-spam-protect'),
      '{REMOTE_ADDRESS}' => $result['ip'],
      '{SERVICE_ID}' => $net_count,
      '{HOST}' => '',
      '{COOKIE_ANTICRAWLER}' => $this->antibot_cookie_value,
      '{COOKIE_ANTICRAWLER_PASSED}' => '1',
      '{GENERATED}' => '<p>The page was generated at&nbsp;' . date('D, d M Y H:i:s') . "</p>",
      '{USE_ALT_COOKIES}' => \Drupal::config('cleantalk.settings')
        ->get('cleantalk_alternative_cookies_session') ? 1 : 0,
    );
    foreach ($replaces as $place_holder => $replace) {
      $die_page = str_replace($place_holder, $replace, $die_page);
    }
    if (isset($_GET['debug'])) {
      $debug = '<h1>Headers</h1>' . str_replace("\n", "<br>", print_r(\apache_request_headers(), true)) . '<h1>$_SERVER</h1>' . str_replace("\n", "<br>", print_r($_SERVER, true)) . '<h1>IPS</h1>' . str_replace("\n", "<br>", print_r($this->ip_array, true));
    }
    else {
      $debug = '';
    }
    $die_page = str_replace("{DEBUG}", $debug, $die_page);
    die($die_page);
  }
  die("IP BLACKLISTED. Blocked by AntiCrawler " . $result['ip']);
}