<?php
/**
* block_ip.plugin.php
*
* Blocks one or more IP addresses. Also a network can be blocked starting with a common IP e.g. 1.2.x.x
*
* @author Svetoslav Marinov <hide@address.com>
* @version 1.0
* @package block_ip
*/
class seofilter_plugin_block_ip extends seofilter_plugin {
var $version = 1.0;
/**
* $event can be executed
* PRE, POST, INPUT, OUTPUT Filter
*
* @param constant
* @access public
* @return bool
*/
function execute($event)
{
if ($event == SEOFILTER_EVENT_INPUT) {
if ($this->_forbid_ip()) {
$this->content('Access denied.');
$this->status(SEOFILTER_STATUS_CONTENT_CHANGED | SEOFILTER_STATUS_EXIT);
return false;
}
}
return true;
}
/**
* Performs a check if IP address whether the user should be stoped or not for viewing the forum.
*
* @param array $matches
* @return string
* @access private
*/
function _forbid_ip($matches = array())
{
$stat = 0;
$params = $this->params();
if (!empty($params['block'])) {
$ips = (array) $params['block'];
foreach ($ips as $ip) {
$ipq = preg_quote($ip);
// If the IP matches from the begining. Block it.
if (preg_match('#^' . $ipq . '#', $_SERVER['REMOTE_ADDR'])) {
$stat = 1;
break;
}
}
}
return $stat;
}
}
?>