widget_ips.php
4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
//$d is defined here as a wfDashboard instance
$initial = false;
if (!isset($limit)) { $limit = 10; $initial = true; }
?>
<div class="wf-row">
<div class="wf-col-xs-12">
<div class="wf-dashboard-item active">
<div class="wf-dashboard-item-inner">
<div class="wf-dashboard-item-content">
<div class="wf-dashboard-item-title">
<strong>Top IPs Blocked</strong>
</div>
<div class="wf-dashboard-item-action"><div class="wf-dashboard-item-action-disclosure"></div></div>
</div>
</div>
<div class="wf-dashboard-item-extra">
<ul class="wf-dashboard-item-list">
<li>
<div>
<div class="wf-dashboard-toggle-btns">
<ul class="wf-pagination wf-pagination-sm">
<li class="wf-active"><a href="#" class="wf-dashboard-ips" data-grouping="24h">24 Hours</a></li>
<li><a href="#" class="wf-dashboard-ips" data-grouping="7d">7 Days</a></li>
<li><a href="#" class="wf-dashboard-ips" data-grouping="30d">30 Days</a></li>
</ul>
</div>
<div class="wf-ips wf-ips-24h">
<?php if (count($d->ips24h) == 0): ?>
<div class="wf-dashboard-item-list-text"><p><em>No blocks have been recorded.</em></p></div>
<?php else: ?>
<?php $data = array_slice($d->ips24h, 0, min($limit, count($d->ips24h)), true); include(dirname(__FILE__) . '/widget_content_ips.php'); ?>
<?php if (count($d->ips24h) > $limit && $initial): ?>
<div class="wf-dashboard-item-list-text"><div class="wf-dashboard-show-more" data-grouping="ips" data-period="24h"><a href="#">Show more</a></div></div>
<?php endif; ?>
<?php endif; ?>
</div>
<div class="wf-ips wf-ips-7d wf-hidden">
<?php if (count($d->ips7d) == 0): ?>
<div class="wf-dashboard-item-list-text"><p><em>No blocks have been recorded.</em></p></div>
<?php else: ?>
<?php $data = array_slice($d->ips7d, 0, min($limit, count($d->ips7d)), true); include(dirname(__FILE__) . '/widget_content_ips.php'); ?>
<?php if (count($d->ips7d) > $limit && $initial): ?>
<div class="wf-dashboard-item-list-text"><div class="wf-dashboard-show-more" data-grouping="ips" data-period="7d"><a href="#">Show more</a></div></div>
<?php endif; ?>
<?php endif; ?>
</div>
<div class="wf-ips wf-ips-30d wf-hidden">
<?php if (count($d->ips30d) == 0): ?>
<div class="wf-dashboard-item-list-text"><p><em>No blocks have been recorded.</em></p></div>
<?php else: ?>
<?php $data = array_slice($d->ips30d, 0, min($limit, count($d->ips30d)), true); include(dirname(__FILE__) . '/widget_content_ips.php'); ?>
<?php if (count($d->ips30d) > $limit && $initial): ?>
<div class="wf-dashboard-item-list-text"><div class="wf-dashboard-show-more" data-grouping="ips" data-period="30d"><a href="#">Show more</a></div></div>
<?php endif; ?>
<?php endif; ?>
</div>
<script type="application/javascript">
(function($) {
$('.wf-dashboard-ips').on('click', function(e) {
e.preventDefault();
e.stopPropagation();
$(this).closest('ul').find('li').removeClass('wf-active');
$(this).closest('li').addClass('wf-active');
$('.wf-ips').addClass('wf-hidden');
$('.wf-ips-' + $(this).data('grouping')).removeClass('wf-hidden');
});
$('.wf-ips .wf-dashboard-show-more a').on('click', function(e) {
e.preventDefault();
e.stopPropagation();
var grouping = $(this).parent().data('grouping');
var period = $(this).parent().data('period');
$(this).closest('.wf-dashboard-item-list-text').fadeOut();
var self = this;
WFAD.ajax('wordfence_dashboardShowMore', {
grouping: grouping,
period: period
}, function(res) {
if (res.ok) {
var table = $('#ips-data-template').tmpl(res);
$(self).closest('.wf-ips').css('overflow-y', 'auto');
$(self).closest('.wf-ips').find('table').replaceWith(table);
}
else {
WFAD.colorbox('400px', 'An error occurred', 'We encountered an error trying load more data.');
$(this).closest('.wf-dashboard-item-list-text').fadeIn();
}
});
});
})(jQuery);
</script>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
<script type="text/x-jquery-template" id="ips-data-template">
<table class="wf-table wf-table-hover">
<thead>
<tr>
<th>IP</th>
<th colspan="2">Country</th>
<th>Block Count</th>
</tr>
</thead>
<tbody>
{{each(idx, d) data}}
<tr>
<td>${d.IP}</td>
<td>${d.countryName}</td>
<td><img src="${d.countryFlag}" class="wfFlag" height="11" width="16" alt="${d.countryName}" title="${d.countryName}"></td>
<td>${d.blockCount}</td>
</tr>
{{/each}}
</tbody>
</table>
</script>