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