1 |
7afae53f
|
Scott Ullrich
|
<?php
|
2 |
|
|
/*
|
3 |
c07b05e0
|
Scott Ullrich
|
diag_tables.php
|
4 |
7afae53f
|
Scott Ullrich
|
*/
|
5 |
fd9ebcd5
|
Stephen Beaver
|
/* ====================================================================
|
6 |
0da0d43e
|
Phil Davis
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
7 |
fd9ebcd5
|
Stephen Beaver
|
* Portions borrowed from diag_dump_states.php
|
8 |
|
|
*
|
9 |
0da0d43e
|
Phil Davis
|
* Redistribution and use in source and binary forms, with or without modification,
|
10 |
|
|
* are permitted provided that the following conditions are met:
|
11 |
fd9ebcd5
|
Stephen Beaver
|
*
|
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 |
0da0d43e
|
Phil Davis
|
* distribution.
|
19 |
fd9ebcd5
|
Stephen Beaver
|
*
|
20 |
0da0d43e
|
Phil Davis
|
* 3. All advertising materials mentioning features or use of this software
|
21 |
fd9ebcd5
|
Stephen Beaver
|
* must display the following acknowledgment:
|
22 |
|
|
* "This product includes software developed by the pfSense Project
|
23 |
0da0d43e
|
Phil Davis
|
* for use in the pfSense software distribution. (http://www.pfsense.org/).
|
24 |
fd9ebcd5
|
Stephen Beaver
|
*
|
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 |
0da0d43e
|
Phil Davis
|
*
|
40 |
fd9ebcd5
|
Stephen Beaver
|
* 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 |
7afae53f
|
Scott Ullrich
|
/*
|
57 |
|
|
pfSense_BUILDER_BINARIES: /sbin/pfctl
|
58 |
c054d8bc
|
sbeaver
|
pfSense_MODULE: filter
|
59 |
7afae53f
|
Scott Ullrich
|
*/
|
60 |
|
|
|
61 |
|
|
##|+PRIV
|
62 |
c07b05e0
|
Scott Ullrich
|
##|*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 |
7afae53f
|
Scott Ullrich
|
##|-PRIV
|
67 |
|
|
|
68 |
c07b05e0
|
Scott Ullrich
|
$pgtitle = array(gettext("Diagnostics"), gettext("Tables"));
|
69 |
d71fc5d3
|
jim-p
|
$shortcut_section = "aliases";
|
70 |
7afae53f
|
Scott Ullrich
|
|
71 |
|
|
require_once("guiconfig.inc");
|
72 |
|
|
|
73 |
|
|
// Set default table
|
74 |
|
|
$tablename = "sshlockout";
|
75 |
3a652703
|
sbeaver
|
$bogons = false;
|
76 |
e166769c
|
Renato Botelho
|
|
77 |
5f601060
|
Phil Davis
|
if ($_REQUEST['type']) {
|
78 |
34525fef
|
Ermal
|
$tablename = $_REQUEST['type'];
|
79 |
5f601060
|
Phil Davis
|
}
|
80 |
e166769c
|
Renato Botelho
|
|
81 |
5f601060
|
Phil Davis
|
if ($_REQUEST['delete']) {
|
82 |
|
|
if (is_ipaddr($_REQUEST['delete']) || is_subnet($_REQUEST['delete'])) {
|
83 |
7afae53f
|
Scott Ullrich
|
exec("/sbin/pfctl -t " . escapeshellarg($_REQUEST['type']) . " -T delete " . escapeshellarg($_REQUEST['delete']), $delete);
|
84 |
|
|
echo htmlentities($_REQUEST['delete']);
|
85 |
|
|
}
|
86 |
e166769c
|
Renato Botelho
|
exit;
|
87 |
7afae53f
|
Scott Ullrich
|
}
|
88 |
|
|
|
89 |
288a2a0f
|
Phil Davis
|
if ($_POST['deleteall']) {
|
90 |
e26e0eac
|
jim-p
|
exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
|
91 |
5f601060
|
Phil Davis
|
if (is_array($entries)) {
|
92 |
|
|
foreach ($entries as $entryA) {
|
93 |
7afae53f
|
Scott Ullrich
|
$entry = trim($entryA);
|
94 |
|
|
exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T delete " . escapeshellarg($entry), $delete);
|
95 |
|
|
}
|
96 |
|
|
}
|
97 |
|
|
}
|
98 |
|
|
|
99 |
288a2a0f
|
Phil Davis
|
if (($tablename == "bogons") || ($tablename == "bogonsv6")) {
|
100 |
3a652703
|
sbeaver
|
$bogons = true;
|
101 |
|
|
|
102 |
288a2a0f
|
Phil Davis
|
if ($_POST['Download']) {
|
103 |
3a652703
|
sbeaver
|
mwexec_bg("/etc/rc.update_bogons.sh now");
|
104 |
|
|
$maxtimetowait = 0;
|
105 |
|
|
$loading = true;
|
106 |
288a2a0f
|
Phil Davis
|
while ($loading == true) {
|
107 |
3a652703
|
sbeaver
|
$isrunning = `/bin/ps awwwux | /usr/bin/grep -v grep | /usr/bin/grep bogons`;
|
108 |
288a2a0f
|
Phil Davis
|
if ($isrunning == "")
|
109 |
3a652703
|
sbeaver
|
$loading = false;
|
110 |
|
|
$maxtimetowait++;
|
111 |
288a2a0f
|
Phil Davis
|
if ($maxtimetowait > 89)
|
112 |
3a652703
|
sbeaver
|
$loading = false;
|
113 |
|
|
sleep(1);
|
114 |
|
|
}
|
115 |
288a2a0f
|
Phil Davis
|
if ($maxtimetowait < 90)
|
116 |
3a652703
|
sbeaver
|
$savemsg = gettext("The bogons database has been updated.");
|
117 |
6c474eb8
|
Warren Baker
|
}
|
118 |
|
|
}
|
119 |
|
|
|
120 |
e26e0eac
|
jim-p
|
exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
|
121 |
34525fef
|
Ermal
|
exec("/sbin/pfctl -sT", $tables);
|
122 |
7afae53f
|
Scott Ullrich
|
|
123 |
|
|
include("head.inc");
|
124 |
c054d8bc
|
sbeaver
|
|
125 |
|
|
if ($savemsg)
|
126 |
|
|
print_info_box($savemsg);
|
127 |
ad9e2a90
|
sbeaver
|
|
128 |
ad2879b8
|
PiBa-NL
|
require_once('classes/Form.class.php');
|
129 |
7ac86a5f
|
Colin Fleming
|
$form = new Form('Show');
|
130 |
3a652703
|
sbeaver
|
|
131 |
ad9e2a90
|
sbeaver
|
$section = new Form_Section('Table to display');
|
132 |
|
|
|
133 |
|
|
$section->addInput(new Form_Select(
|
134 |
|
|
'type',
|
135 |
|
|
'Table',
|
136 |
|
|
$tablename,
|
137 |
|
|
array_combine($tables, $tables)
|
138 |
|
|
));
|
139 |
|
|
|
140 |
|
|
$form->add($section);
|
141 |
|
|
print $form;
|
142 |
7afae53f
|
Scott Ullrich
|
?>
|
143 |
|
|
|
144 |
eb500b85
|
Sjon Hortensius
|
<script>
|
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 |
7afae53f
|
Scott Ullrich
|
});
|
161 |
eb500b85
|
Sjon Hortensius
|
});
|
162 |
|
|
});
|
163 |
7afae53f
|
Scott Ullrich
|
</script>
|
164 |
e166769c
|
Renato Botelho
|
|
165 |
ad9e2a90
|
sbeaver
|
<div class="table-responsive">
|
166 |
3a652703
|
sbeaver
|
<table class="table table-striped table-hover table-condensed">
|
167 |
ad9e2a90
|
sbeaver
|
<thead>
|
168 |
eb500b85
|
Sjon Hortensius
|
<tr>
|
169 |
|
|
<th><?=gettext("IP Address")?></th>
|
170 |
|
|
</tr>
|
171 |
ad9e2a90
|
sbeaver
|
</thead>
|
172 |
3a652703
|
sbeaver
|
<tbody>
|
173 |
7afae53f
|
Scott Ullrich
|
<?php
|
174 |
eb500b85
|
Sjon Hortensius
|
foreach ($entries as $entry):
|
175 |
|
|
$entry = trim($entry);
|
176 |
7afae53f
|
Scott Ullrich
|
?>
|
177 |
eb500b85
|
Sjon Hortensius
|
<tr>
|
178 |
ad9e2a90
|
sbeaver
|
<td>
|
179 |
eb500b85
|
Sjon Hortensius
|
<?=$entry?>
|
180 |
ad9e2a90
|
sbeaver
|
</td>
|
181 |
|
|
<td>
|
182 |
eb500b85
|
Sjon Hortensius
|
<?php if (!$bogons): ?>
|
183 |
|
|
<a class="btn btn-xs btn-default" data-entry="<?=htmlspecialchars($entry)?>">Remove</a>
|
184 |
|
|
<?php endif ?>
|
185 |
ad9e2a90
|
sbeaver
|
</td>
|
186 |
|
|
</tr>
|
187 |
eb500b85
|
Sjon Hortensius
|
<?php endforeach ?>
|
188 |
ad9e2a90
|
sbeaver
|
</tbody>
|
189 |
|
|
</table>
|
190 |
c054d8bc
|
sbeaver
|
</div>
|
191 |
eb500b85
|
Sjon Hortensius
|
<?php if (empty($entries)): ?>
|
192 |
|
|
<div class="alert alert-warning" role="alert">No entries exist in this table</div>
|
193 |
|
|
<?php endif ?>
|
194 |
|
|
|
195 |
3a652703
|
sbeaver
|
<?php
|
196 |
|
|
|
197 |
eb500b85
|
Sjon Hortensius
|
if ($bogons || !empty($entries)) {
|
198 |
|
|
$form = new Form;
|
199 |
3a652703
|
sbeaver
|
|
200 |
eb500b85
|
Sjon Hortensius
|
$section = new Form_Section('Table Data');
|
201 |
3a652703
|
sbeaver
|
|
202 |
eb500b85
|
Sjon Hortensius
|
if ($bogons) {
|
203 |
3a652703
|
sbeaver
|
$last_updated = exec('/usr/bin/grep -i -m 1 -E "^# last updated" /etc/' . escapeshellarg($tablename) . '|cut -d"(" -f2|tr -d ")" ');
|
204 |
|
|
|
205 |
eb500b85
|
Sjon Hortensius
|
$section->addInput(new Form_StaticText(
|
206 |
3a652703
|
sbeaver
|
'Last update',
|
207 |
|
|
$last_updated
|
208 |
|
|
));
|
209 |
|
|
|
210 |
eb500b85
|
Sjon Hortensius
|
$section->addInput(new Form_Button(
|
211 |
3a652703
|
sbeaver
|
'Download',
|
212 |
|
|
'Download'
|
213 |
eb500b85
|
Sjon Hortensius
|
))->setHelp('Download the latest bogon data')->addClass('btn-warning');
|
214 |
|
|
} elseif (!empty($entries)) {
|
215 |
|
|
$section->addInput(new Form_Button(
|
216 |
3a652703
|
sbeaver
|
'deleteall',
|
217 |
|
|
'Clear Table'
|
218 |
eb500b85
|
Sjon Hortensius
|
))->setHelp('Clear all of the entries in this table')->addClass('btn-danger');
|
219 |
3a652703
|
sbeaver
|
}
|
220 |
|
|
|
221 |
eb500b85
|
Sjon Hortensius
|
$form->add($section);
|
222 |
|
|
print $form;
|
223 |
3a652703
|
sbeaver
|
}
|
224 |
909e7d0d
|
N0YB
|
|
225 |
7ac86a5f
|
Colin Fleming
|
include("foot.inc");
|