<commit_before><?php

/**
 * Block
 *
 * @package silverstripe-blacklist
 * @license BSD License http://www.silverstripe.org/bsd-license
 * @author <<EMAIL>>
 **/
class Block {

	/**
	 * @var string $ip the current user IP address
	 **/
	private $userIP;

	/**
	 * @var string $referer the current user referer
	 **/
	private $userReferer;

	/**
	 * @var string $host the current user host
	 **/
	private $userHost;

	/**
	 * Our constructor is paased the user information and assigns it to class properties
	 *
	 * @param  string $ip       the current user IP
	 * @param  string $host     the current user host
	 * @param  string $referer  the current user referer
	 * 
	 * @return void
	 **/
	function __construct($ip, $host, $referer)
	{
		$this->userIP = $ip;
		$this->userHost = $host;
		$this->userReferer = $referer;

		$this->getBlockedData();
	}

	/**
	 * @return void
	 **/
	private function getBlockedData()
	{
		$blocked = BlockModel::get();

		$this->checkIP()
		$this->checkHost()
		$this->checkReferer();
	}

	private function checkIP()
	{
		if(is_array($blocked)) :
		
			$ip  = ip2long($this->userIP);
			$min = ip2long($blocked[0]);
			$max = ip2long($blocked[1]);
			
			if($ip >= $min && $ip <= $max) :
				$this->forbidden();
			endif;
		else :
			if($this->userIP == $blocked) :
				$this->forbidden();
			endif;
		endif;
	}
	
	private function checkHost()
	{
		if(strpos($this->userHost, $blocked) !== false) :
			$this->forbidden();
		endif;
	}
	
	private function checkReferer()
	{
		if(strpos($this->userReferer, $blocked) !== false) :
			$this->forbidden();
		endif;
	}
	
	private function forbidden()
	{
		header('HTTP/1.0 403 Forbidden');
		die;
	}
}<commit_msg>add blocking functionality<commit_after><?php

/**
 * Block
 *
 * @package silverstripe-blacklist
 * @license BSD License http://www.silverstripe.org/bsd-license
 * @author <<EMAIL>>
 **/
class Block {

	/**
	 * @var string $ip the current user IP address
	 **/
	private $userIP;

	/**
	 * @var string $referer the current user referer
	 **/
	private $userReferer;

	/**
	 * @var string $host the current user host
	 **/
	private $userHost;

	/**
	 * Our constructor is paased the user information and assigns it to class properties
	 *
	 * @param  string $ip       the current user IP
	 * @param  string $host     the current user host
	 * @param  string $referer  the current user referer
	 * 
	 * @return void
	 **/
	function __construct($ip, $host, $referer)
	{
		$this->userIP = $ip;
		$this->userHost = $host;
		$this->userReferer = $referer;

		$this->getBlockedData();
	}

	/**
	 * @return void
	 **/
	private function getBlockedData()
	{
		$blocked = BlockModel::get();

		foreach($blocked as $data) :
			$this->checkIP(
				$data->ip,
				$data->ipMin,
				$data->ipMax
				);

			$this->checkHost($data->host);

			$this->checkReferer($data->referer);
		endforeach;
	}

	private function checkIP($ip, $ipMin, $ipMax)
	{
		if($ipMin != '' && $ipMax != '') :
		
			$ip  = ip2long($this->userIP);
			$min = ip2long($ipMin);
			$max = ip2long($ipMax);
			
			if($ip >= $min && $ip <= $max) :
				$this->forbidden();
			endif;
		else :
			if($this->userIP == $ip) :
				$this->forbidden();
			endif;
		endif;
	}
	
	private function checkHost($host)
	{
		if(strpos($this->userHost, $host) !== false) :
			$this->forbidden();
		endif;
	}
	
	private function checkReferer($referer)
	{
		if(strpos($this->userReferer, $referer) !== false) :
			$this->forbidden();
		endif;
	}
	
	private function forbidden()
	{
		header('HTTP/1.0 403 Forbidden');
		die;
	}
}
{'fraction_non_alphanumeric': 0.1715009856378485, 'fraction_numerical': 0.005068994649394537, 'mean_word_length': 3.0921658986175116, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '308204', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1282, 'n_words': 296}