1
|
<?php
|
2
|
/*
|
3
|
diag_tables.php
|
4
|
*/
|
5
|
/* ====================================================================
|
6
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
7
|
* Portions borrowed from diag_dump_states.php
|
8
|
*
|
9
|
* Redistribution and use in source and binary forms, with or without modification,
|
10
|
* are permitted provided that the following conditions are met:
|
11
|
*
|
12
|
* 1. Redistributions of source code must retain the above copyright notice,
|
13
|
* this list of conditions and the following disclaimer.
|
14
|
*
|
15
|
* 2. Redistributions in binary form must reproduce the above copyright
|
16
|
* notice, this list of conditions and the following disclaimer in
|
17
|
* the documentation and/or other materials provided with the
|
18
|
* distribution.
|
19
|
*
|
20
|
* 3. All advertising materials mentioning features or use of this software
|
21
|
* must display the following acknowledgment:
|
22
|
* "This product includes software developed by the pfSense Project
|
23
|
* for use in the pfSense software distribution. (http://www.pfsense.org/).
|
24
|
*
|
25
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
26
|
* endorse or promote products derived from this software without
|
27
|
* prior written permission. For written permission, please contact
|
28
|
* coreteam@pfsense.org.
|
29
|
*
|
30
|
* 5. Products derived from this software may not be called "pfSense"
|
31
|
* nor may "pfSense" appear in their names without prior written
|
32
|
* permission of the Electric Sheep Fencing, LLC.
|
33
|
*
|
34
|
* 6. Redistributions of any form whatsoever must retain the following
|
35
|
* acknowledgment:
|
36
|
*
|
37
|
* "This product includes software developed by the pfSense Project
|
38
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
39
|
*
|
40
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
41
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
42
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
43
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
44
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
45
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
46
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
47
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
48
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
49
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
50
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
51
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
52
|
*
|
53
|
* ====================================================================
|
54
|
*
|
55
|
*/
|
56
|
/*
|
57
|
pfSense_BUILDER_BINARIES: /sbin/pfctl
|
58
|
pfSense_MODULE: filter
|
59
|
*/
|
60
|
|
61
|
##|+PRIV
|
62
|
##|*IDENT=page-diagnostics-tables
|
63
|
##|*NAME=Diagnostics: pf Table IP addresses
|
64
|
##|*DESCR=Allow access to the 'Diagnostics: Tables' page.
|
65
|
##|*MATCH=diag_tables.php*
|
66
|
##|-PRIV
|
67
|
|
68
|
$pgtitle = array(gettext("Diagnostics"), gettext("Tables"));
|
69
|
$shortcut_section = "aliases";
|
70
|
|
71
|
require_once("guiconfig.inc");
|
72
|
|
73
|
// Set default table
|
74
|
$tablename = "sshlockout";
|
75
|
$bogons = false;
|
76
|
|
77
|
if ($_REQUEST['type']) {
|
78
|
$tablename = $_REQUEST['type'];
|
79
|
}
|
80
|
|
81
|
if ($_REQUEST['delete']) {
|
82
|
if (is_ipaddr($_REQUEST['delete']) || is_subnet($_REQUEST['delete'])) {
|
83
|
exec("/sbin/pfctl -t " . escapeshellarg($_REQUEST['type']) . " -T delete " . escapeshellarg($_REQUEST['delete']), $delete);
|
84
|
echo htmlentities($_REQUEST['delete']);
|
85
|
}
|
86
|
exit;
|
87
|
}
|
88
|
|
89
|
if ($_POST['deleteall']) {
|
90
|
exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
|
91
|
if (is_array($entries)) {
|
92
|
foreach ($entries as $entryA) {
|
93
|
$entry = trim($entryA);
|
94
|
exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T delete " . escapeshellarg($entry), $delete);
|
95
|
}
|
96
|
}
|
97
|
}
|
98
|
|
99
|
if (($tablename == "bogons") || ($tablename == "bogonsv6")) {
|
100
|
$bogons = true;
|
101
|
|
102
|
if ($_POST['Download']) {
|
103
|
mwexec_bg("/etc/rc.update_bogons.sh now");
|
104
|
$maxtimetowait = 0;
|
105
|
$loading = true;
|
106
|
while ($loading == true) {
|
107
|
$isrunning = `/bin/ps awwwux | /usr/bin/grep -v grep | /usr/bin/grep bogons`;
|
108
|
if ($isrunning == "")
|
109
|
$loading = false;
|
110
|
$maxtimetowait++;
|
111
|
if ($maxtimetowait > 89)
|
112
|
$loading = false;
|
113
|
sleep(1);
|
114
|
}
|
115
|
if ($maxtimetowait < 90)
|
116
|
$savemsg = gettext("The bogons database has been updated.");
|
117
|
}
|
118
|
}
|
119
|
|
120
|
exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
|
121
|
exec("/sbin/pfctl -sT", $tables);
|
122
|
|
123
|
include("head.inc");
|
124
|
|
125
|
if ($savemsg)
|
126
|
print_info_box($savemsg);
|
127
|
|
128
|
$form = new Form('Show');
|
129
|
|
130
|
$section = new Form_Section('Table to display');
|
131
|
|
132
|
$section->addInput(new Form_Select(
|
133
|
'type',
|
134
|
'Table',
|
135
|
$tablename,
|
136
|
array_combine($tables, $tables)
|
137
|
));
|
138
|
|
139
|
$form->add($section);
|
140
|
print $form;
|
141
|
?>
|
142
|
|
143
|
<script type="text/javascript">
|
144
|
//<![CDATA[
|
145
|
events.push(function(){
|
146
|
$('a[data-entry]').on('click', function(){
|
147
|
var el = $(this);
|
148
|
|
149
|
$.ajax(
|
150
|
'/diag_tables.php',
|
151
|
{
|
152
|
type: 'post',
|
153
|
data: {
|
154
|
type: '<?=htmlspecialchars($tablename)?>',
|
155
|
delete: $(this).data('entry')
|
156
|
},
|
157
|
success: function(){
|
158
|
el.parents('tr').remove();
|
159
|
},
|
160
|
});
|
161
|
});
|
162
|
});
|
163
|
//]]>
|
164
|
</script>
|
165
|
|
166
|
<div class="table-responsive">
|
167
|
<table class="table table-striped table-hover table-condensed">
|
168
|
<thead>
|
169
|
<tr>
|
170
|
<th><?=gettext("IP Address")?></th>
|
171
|
<th></th>
|
172
|
</tr>
|
173
|
</thead>
|
174
|
<tbody>
|
175
|
<?php
|
176
|
foreach ($entries as $entry):
|
177
|
$entry = trim($entry);
|
178
|
?>
|
179
|
<tr>
|
180
|
<td>
|
181
|
<?=$entry?>
|
182
|
</td>
|
183
|
<td>
|
184
|
<?php if (!$bogons): ?>
|
185
|
<a class="btn btn-xs btn-default" data-entry="<?=htmlspecialchars($entry)?>">Remove</a>
|
186
|
<?php endif ?>
|
187
|
</td>
|
188
|
</tr>
|
189
|
<?php endforeach ?>
|
190
|
</tbody>
|
191
|
</table>
|
192
|
</div>
|
193
|
<?php if (empty($entries)): ?>
|
194
|
<div class="alert alert-warning" role="alert">No entries exist in this table</div>
|
195
|
<?php endif ?>
|
196
|
|
197
|
<?php
|
198
|
|
199
|
if ($bogons || !empty($entries)) {
|
200
|
$form = new Form;
|
201
|
|
202
|
$section = new Form_Section('Table Data');
|
203
|
|
204
|
if ($bogons) {
|
205
|
$last_updated = exec('/usr/bin/grep -i -m 1 -E "^# last updated" /etc/' . escapeshellarg($tablename) . '|cut -d"(" -f2|tr -d ")" ');
|
206
|
|
207
|
$section->addInput(new Form_StaticText(
|
208
|
'Last update',
|
209
|
$last_updated
|
210
|
));
|
211
|
|
212
|
$section->addInput(new Form_Button(
|
213
|
'Download',
|
214
|
'Download'
|
215
|
))->setHelp('Download the latest bogon data')->addClass('btn-warning');
|
216
|
} elseif (!empty($entries)) {
|
217
|
$section->addInput(new Form_Button(
|
218
|
'deleteall',
|
219
|
'Clear Table'
|
220
|
))->setHelp('Clear all of the entries in this table')->addClass('btn-danger');
|
221
|
}
|
222
|
|
223
|
$form->add($section);
|
224
|
print $form;
|
225
|
}
|
226
|
|
227
|
include("foot.inc");
|