Add hit counter and latest hit timer to IP spamfilter

This commit is contained in:
Kijin Sung 2019-07-27 23:35:42 +09:00
parent 853d6753eb
commit 1bf488e367
6 changed files with 52 additions and 13 deletions

View file

@ -0,0 +1,14 @@
<query id="updateDeniedIPHit" action="update">
<tables>
<table name="spamfilter_denied_ip" />
</tables>
<columns>
<column name="hit" default="plus(1)" />
<column name="latest_hit" default="curdate()" />
</columns>
<conditions>
<condition operation="equal" column="ipaddress" var="ipaddress" notnull="notnull" />
</conditions>
</query>

View file

@ -1,5 +1,7 @@
<table name="spamfilter_denied_ip">
<column name="ipaddress" type="varchar" size="60" utf8mb4="false" notnull="notnull" primary_key="primary_key" />
<column name="hit" type="number" notnull="notnull" default="0" index="idx_hit" />
<column name="latest_hit" type="date" index="idx_latest_hit" />
<column name="description" type="varchar" size="255" />
<column name="regdate" type="date" index="idx_regdate" />
</table>

View file

@ -21,9 +21,16 @@ class spamfilterAdminView extends spamfilter
*/
function dispSpamfilterAdminDeniedIPList()
{
// Get sort index
$sort_index = Context::get('sort_index');
if (!in_array($sort_index, array('regdate', 'latest_hit', 'hit')))
{
$sort_index = 'regdate';
}
// Get the list of denied IP addresses and words
$oSpamFilterModel = getModel('spamfilter');
$ip_list = $oSpamFilterModel->getDeniedIPList();
$ip_list = $oSpamFilterModel->getDeniedIPList($sort_index);
Context::set('ip_list', $ip_list);
$security = new Security();

View file

@ -47,7 +47,8 @@ class spamfilter extends ModuleObject
*/
if(!$oDB->isColumnExists('spamfilter_denied_word', 'hit')) return true;
if(!$oDB->isColumnExists('spamfilter_denied_word', 'latest_hit')) return true;
if(!$oDB->isColumnExists('spamfilter_denied_ip', 'hit')) return true;
if(!$oDB->isColumnExists('spamfilter_denied_ip', 'latest_hit')) return true;
if(!$oDB->isColumnExists('spamfilter_denied_ip', 'description')) return true;
if(!$oModuleModel->getTrigger('document.manage', 'spamfilter', 'controller', 'triggerManageDocument', 'before'))
@ -102,7 +103,16 @@ class spamfilter extends ModuleObject
$oDB->addColumn('spamfilter_denied_word','latest_hit','date');
$oDB->addIndex('spamfilter_denied_word','idx_latest_hit', 'latest_hit');
}
if(!$oDB->isColumnExists('spamfilter_denied_ip', 'hit'))
{
$oDB->addColumn('spamfilter_denied_ip','hit','number',12,0,true);
$oDB->addIndex('spamfilter_denied_ip','idx_hit', 'hit');
}
if(!$oDB->isColumnExists('spamfilter_denied_ip', 'latest_hit'))
{
$oDB->addColumn('spamfilter_denied_ip','latest_hit','date');
$oDB->addIndex('spamfilter_denied_ip','idx_latest_hit', 'latest_hit');
}
if(!$oDB->isColumnExists('spamfilter_denied_ip', 'description'))
{
$oDB->addColumn('spamfilter_denied_ip','description','varchar', 250);

View file

@ -27,10 +27,10 @@ class spamfilterModel extends spamfilter
/**
* @brief Return the list of registered IP addresses which were banned
*/
function getDeniedIPList()
function getDeniedIPList($sort_index = 'regdate')
{
$args = new stdClass();
$args->sort_index = "regdate";
$args->sort_index = $sort_index;
$args->page = Context::get('page')?Context::get('page'):1;
$output = executeQueryArray('spamfilter.getDeniedIPList', $args);
if(!$output->data) return array();
@ -48,12 +48,14 @@ class spamfilterModel extends spamfilter
$ip_ranges = array();
foreach ($ip_list as $ip_range)
{
$ip_ranges[] = $ip_range->ipaddress;
}
if (Rhymix\Framework\Filters\IpFilter::inRanges(\RX_CLIENT_IP, $ip_ranges))
{
return new BaseObject(-1, 'msg_alert_registered_denied_ip');
if (Rhymix\Framework\Filters\IpFilter::inRange(\RX_CLIENT_IP, $ip_range->ipaddress))
{
$args = new stdClass();
$args->ipaddress = $ip_range->ipaddress;
executeQuery('spamfilter.updateDeniedIPHit', $args);
return new BaseObject(-1, 'msg_alert_registered_denied_ip');
}
}
return new BaseObject();

View file

@ -18,7 +18,9 @@
<tr>
<th scope="col">IP</th>
<th scope="col">{$lang->description}</th>
<th scope="col">{$lang->regdate}</th>
<th scope="col"><a href="{getUrl('sort_index', 'latest_hit')}">{$lang->latest_hit} <!--@if($sort_index === 'latest_hit')--><!--@endif--></a></th>
<th scope="col"><a href="{getUrl('sort_index', 'hit')}">{$lang->hit} <!--@if($sort_index === 'hit')--><!--@endif--></a></th>
<th scope="col"><a href="{getUrl('sort_index', 'regdate')}">{$lang->regdate} <!--@if($sort_index === 'regdate' || !$sort_index)--><!--@endif--></a></th>
<th scope="col"><input type="checkbox" name="ipaddress" title="Check All" /></th>
</tr>
</thead>
@ -26,11 +28,13 @@
<tr loop="$ip_list => $ip_info">
<td>{$ip_info->ipaddress}</td>
<td>{$ip_info->description}</td>
<td><!--@if($ip_info->latest_hit)-->{zdate($ip_info->latest_hit,'Y-m-d H:i')}<!--@else-->-<!--@end--></td>
<td>{$ip_info->hit}</td>
<td>{zdate($ip_info->regdate,'Y-m-d')}</td>
<td><input type="checkbox" name="ipaddress[]" value="{$ip_info->ipaddress}" /></td>
</tr>
<tr cond="!$ip_list">
<td colspan="4" style="text-align:center">{$lang->no_data}</td>
<td colspan="6" style="text-align:center">{$lang->no_data}</td>
</tr>
</tbody>
</table>