-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin-list.php
203 lines (173 loc) · 6.12 KB
/
admin-list.php
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
if (!defined('ABSPATH')) {
exit;
}
class WPDMARC_Admin_List extends WP_List_Table
{
public function __construct()
{
parent::__construct(array(
'singular' => 'report',
'plural' => 'reports',
'ajax' => false
));
}
public function column_default($item, $column_name)
{
echo $item[$column_name];
}
public function column_date($item)
{
echo $item['begin'] . '</br>' . $item['end'];
}
public function column_disposition($item)
{
echo $item['disposition'] . "</br> Count: {$item['count']}";
}
public function column_status($item)
{
echo "SPF: <span class='status-{$item['spf']}'>{$item['spf']}</span></br>DKIM: <span class='status-{$item['dkim']}'>{$item['dkim']}</span>";
}
public function column_source_ip($item)
{
echo "<a target=\"_blank\" href=\"http://www.ip-tracker.org/locator/ip-lookup.php?ip={$item['source_ip']}\">" . $item['source_ip'] . '</a></br>' . $item['header_from'];
}
public function column_filename($item)
{
echo "<span title='{$item['report_slug']} '>{$item['filename']}</span><br>{$item['org_name']}";
}
public function prepare_items()
{
global $wpdb;
$this->_column_headers = array(
$this->get_columns(),
array(),
$this->get_sortable_columns()
);
$per_page = 50;
// search
$search = null;
if (isset($_REQUEST['s'])) {
$search = trim($_REQUEST['s']);
}
if ($search) {
$total_items = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->prefix}wpdmarc_record WHERE `source_ip` LIKE %s", '%' . $search . '%'));
} else {
$total_items = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}wpdmarc_record");
}
$this->paged = filter_input(INPUT_GET, 'paged', FILTER_SANITIZE_NUMBER_INT);
if (isset($_REQUEST['orderby']) && in_array($_REQUEST['orderby'], array('id', 'created', 'status'))) {
$orderby = $_REQUEST['orderby'];
} else {
$orderby = 'p.begin';
}
$order = (isset($_REQUEST['order']) && in_array($_REQUEST['order'], array('asc', 'desc'))) ? $_REQUEST['order'] : 'desc';
if ($search) {
$items = $wpdb->get_results(
$wpdb->prepare("
SELECT *
FROM {$wpdb->prefix}wpdmarc_record r
INNER JOIN {$wpdb->prefix}wpdmarc_report p ON r.report_slug = p.slug WHERE `source_ip` LIKE %s
ORDER BY $orderby $order LIMIT %d OFFSET %d", '%' . $search . '%', $per_page, $this->paged * $per_page),
ARRAY_A
);
} else {
$items = $wpdb->get_results(
$wpdb->prepare("
SELECT *
FROM {$wpdb->prefix}wpdmarc_record r
INNER JOIN {$wpdb->prefix}wpdmarc_report p ON r.report_slug = p.slug
ORDER BY $orderby $order LIMIT %d OFFSET %d", $per_page, $this->paged * $per_page),
ARRAY_A
);
}
$this->items = $items;
$this->set_pagination_args(array(
'total_items' => $total_items,
'per_page' => $per_page,
'total_pages' => ceil($total_items / $per_page)
));
}
public function get_columns()
{
return array(
'id' => __('ID'),
'date' => 'Date range',
'source_ip' => 'Source IP',
'disposition' => 'Disposition',
'status' => 'Status',
'filename' => 'Source'
);
}
public function get_sortable_columns()
{
$items = array(
'id' => array('id', true),
'source_ip' => array('source_ip', true),
'disposition' => array('disposition', true),
'filename' => array('filename', true),
'domain' => array('domain', true),
'date' => array('begin', true),
);
return $items;
}
protected function column_cb($item)
{
return sprintf('<input type="checkbox" name="bulk-action[]" value="%s" />', $item['id']);
}
}
?>
<style>
.column-id {
width: 40px;
}
.column-date {
width: 160px !important;
}
.status-fail {
color: red;
}
</style>
<div class="wrap">
<div class="icon32 icon32-posts-post" id="icon-edit"><br></div>
<h1>DMARC Reports</h1>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages': ['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Source IP', 'Count'],
<?php
global $wpdb;
foreach ($wpdb->get_results(
"SELECT `source_ip`, SUM(`count`) as sum FROM {$wpdb->prefix}wpdmarc_report report INNER JOIN {$wpdb->prefix}wpdmarc_record record ON `record`.`report_slug` = `report`.`slug` WHERE `begin` > DATE_ADD(NOW(), INTERVAL -3 MONTH) AND `disposition` != 'none' GROUP BY `source_ip` HAVING SUM(`count`) > 1",
ARRAY_A
) as $result) {
echo "['{$result['source_ip']}', {$result['sum']} ], \n";
}
?>
]);
var options = {
title: 'Quarantined IPs > 1 in the last 3 months'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>
<div id="piechart" style="width: 100%; height: 300px;"></div>
<?
$table = new WPDMARC_Admin_List();
$table->prepare_items();
foreach ($messages as $message) { ?>
<div class="notice is-dismissible notice-<?php echo $message[0] ?> "><p><?php echo $message[1]; ?></p></div><?php
}
?>
<form method="POST">
<?php $table->search_box('Search IP..', 'obrazci'); ?>
<?php $table->display() ?>
<?php
printf('<input type="hidden" name="paged" value="%d" />', $table->paged);
?>
</form>
</div>