mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 17:21:39 +09:00
Update spamfilter to use Rhymix IP filter
This commit is contained in:
parent
3d571142a4
commit
e2df99d440
2 changed files with 43 additions and 23 deletions
|
|
@ -164,25 +164,44 @@ class spamfilterController extends spamfilter
|
|||
*/
|
||||
function insertIP($ipaddress_list, $description = null)
|
||||
{
|
||||
$regExr = "/^((\d{1,3}(?:.(\d{1,3}|\*)){3})\s*(\/\/(.*)\s*)?)*\s*$/";
|
||||
if(!preg_match($regExr,$ipaddress_list)) return new Object(-1, 'msg_invalid');
|
||||
$ipaddress_list = str_replace("\r","",$ipaddress_list);
|
||||
$ipaddress_list = explode("\n",$ipaddress_list);
|
||||
foreach($ipaddress_list as $ipaddressValue)
|
||||
if (!is_array($ipaddress_list))
|
||||
{
|
||||
$args = new stdClass();
|
||||
preg_match("/(\d{1,3}(?:.(\d{1,3}|\*)){3})\s*(\/\/(.*)\s*)?/",$ipaddressValue,$matches);
|
||||
if($ipaddress=trim($matches[1]))
|
||||
$ipaddress_list = array_map('trim', explode("\n", $ipaddress_list));
|
||||
}
|
||||
$fail_list = '';
|
||||
$output = null;
|
||||
|
||||
foreach ($ipaddress_list as $ipaddress)
|
||||
{
|
||||
$args = new stdClass;
|
||||
if (preg_match('@^(.+?)(?://|#)(.*)$@', $ipaddress, $matches))
|
||||
{
|
||||
$args->ipaddress = trim($matches[1]);
|
||||
$args->description = trim($matches[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$args->ipaddress = $ipaddress;
|
||||
if(!$description && $matches[4]) $args->description = $matches[4];
|
||||
else $args->description = $description;
|
||||
$args->description = $description;
|
||||
}
|
||||
|
||||
if (!Rhymix\Framework\Filters\IpFilter::validateRange($args->ipaddress))
|
||||
{
|
||||
return new Object(-1, 'msg_invalid');
|
||||
}
|
||||
|
||||
$output = executeQuery('spamfilter.insertDeniedIP', $args);
|
||||
if(!$output->toBool()) $fail_list .= $ipaddress.'<br/>';
|
||||
if (!$output->toBool())
|
||||
{
|
||||
$fail_list .= $args->ipaddress . '<br />';
|
||||
}
|
||||
}
|
||||
|
||||
$output->add('fail_list',$fail_list);
|
||||
|
||||
if ($output)
|
||||
{
|
||||
$output->add('fail_list', $fail_list);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,9 +32,8 @@ class spamfilterModel extends spamfilter
|
|||
$args = new stdClass();
|
||||
$args->sort_index = "regdate";
|
||||
$args->page = Context::get('page')?Context::get('page'):1;
|
||||
$output = executeQuery('spamfilter.getDeniedIPList', $args);
|
||||
$output = executeQueryArray('spamfilter.getDeniedIPList', $args);
|
||||
if(!$output->data) return;
|
||||
if(!is_array($output->data)) return array($output->data);
|
||||
return $output->data;
|
||||
}
|
||||
|
||||
|
|
@ -43,18 +42,20 @@ class spamfilterModel extends spamfilter
|
|||
*/
|
||||
function isDeniedIP()
|
||||
{
|
||||
$ipaddress = $_SERVER['REMOTE_ADDR'];
|
||||
|
||||
$ip_list = $this->getDeniedIPList();
|
||||
if(!count($ip_list)) return new Object();
|
||||
|
||||
$count = count($ip_list);
|
||||
for($i=0;$i<$count;$i++)
|
||||
|
||||
$ip_ranges = array();
|
||||
foreach ($ip_list as $ip_range)
|
||||
{
|
||||
$ip = str_replace('.', '\.', str_replace('*','(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)',$ip_list[$i]->ipaddress));
|
||||
if(preg_match('/^'.$ip.'$/', $ipaddress, $matches)) return new Object(-1,'msg_alert_registered_denied_ip');
|
||||
$ip_ranges[] = $ip_range->ipaddress;
|
||||
}
|
||||
|
||||
|
||||
if (Rhymix\Framework\Filters\IpFilter::inRanges(\RX_CLIENT_IP, $ip_ranges))
|
||||
{
|
||||
return new Object(-1, 'msg_alert_registered_denied_ip');
|
||||
}
|
||||
|
||||
return new Object();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue