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 |
|
|
##|+PRIV
|
58 |
c07b05e0
|
Scott Ullrich
|
##|*IDENT=page-diagnostics-tables
|
59 |
9599211d
|
jim-p
|
##|*NAME=Diagnostics: pf Table IP addresses
|
60 |
c07b05e0
|
Scott Ullrich
|
##|*DESCR=Allow access to the 'Diagnostics: Tables' page.
|
61 |
|
|
##|*MATCH=diag_tables.php*
|
62 |
7afae53f
|
Scott Ullrich
|
##|-PRIV
|
63 |
|
|
|
64 |
c07b05e0
|
Scott Ullrich
|
$pgtitle = array(gettext("Diagnostics"), gettext("Tables"));
|
65 |
d71fc5d3
|
jim-p
|
$shortcut_section = "aliases";
|
66 |
7afae53f
|
Scott Ullrich
|
|
67 |
|
|
require_once("guiconfig.inc");
|
68 |
|
|
|
69 |
|
|
// Set default table
|
70 |
|
|
$tablename = "sshlockout";
|
71 |
e166769c
|
Renato Botelho
|
|
72 |
5f601060
|
Phil Davis
|
if ($_REQUEST['type']) {
|
73 |
34525fef
|
Ermal
|
$tablename = $_REQUEST['type'];
|
74 |
5f601060
|
Phil Davis
|
}
|
75 |
e166769c
|
Renato Botelho
|
|
76 |
f6622167
|
NOYB
|
// Gather selected alias metadata.
|
77 |
|
|
if (isset($config['aliases']['alias'])) {
|
78 |
|
|
foreach ($config['aliases']['alias'] as $alias) {
|
79 |
|
|
if ( $alias['name'] == $tablename ) {
|
80 |
|
|
$tmp = array();
|
81 |
|
|
$tmp['type'] = $alias['type'];
|
82 |
|
|
$tmp['name'] = $alias['name'];
|
83 |
|
|
$tmp['url'] = $alias['url'];
|
84 |
|
|
$tmp['freq'] = $alias['updatefreq'];
|
85 |
|
|
break;
|
86 |
|
|
}
|
87 |
|
|
}
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
# Determine if selected alias is either a bogons or URL table.
|
91 |
|
|
if (($tablename == "bogons") || ($tablename == "bogonsv6")) {
|
92 |
|
|
$bogons = true;
|
93 |
|
|
} else if (preg_match('/urltable/i', $tmp['type'])) {
|
94 |
|
|
$urltable = true;
|
95 |
|
|
} else {
|
96 |
|
|
$bogons = $urltable = false;
|
97 |
|
|
}
|
98 |
|
|
|
99 |
5f601060
|
Phil Davis
|
if ($_REQUEST['delete']) {
|
100 |
|
|
if (is_ipaddr($_REQUEST['delete']) || is_subnet($_REQUEST['delete'])) {
|
101 |
7afae53f
|
Scott Ullrich
|
exec("/sbin/pfctl -t " . escapeshellarg($_REQUEST['type']) . " -T delete " . escapeshellarg($_REQUEST['delete']), $delete);
|
102 |
|
|
echo htmlentities($_REQUEST['delete']);
|
103 |
|
|
}
|
104 |
e166769c
|
Renato Botelho
|
exit;
|
105 |
7afae53f
|
Scott Ullrich
|
}
|
106 |
|
|
|
107 |
6f80b61e
|
Phil Davis
|
if ($_POST['clearall']) {
|
108 |
e26e0eac
|
jim-p
|
exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
|
109 |
5f601060
|
Phil Davis
|
if (is_array($entries)) {
|
110 |
|
|
foreach ($entries as $entryA) {
|
111 |
7afae53f
|
Scott Ullrich
|
$entry = trim($entryA);
|
112 |
|
|
exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T delete " . escapeshellarg($entry), $delete);
|
113 |
|
|
}
|
114 |
|
|
}
|
115 |
16424666
|
Phil Davis
|
unset($entries);
|
116 |
7afae53f
|
Scott Ullrich
|
}
|
117 |
|
|
|
118 |
f6622167
|
NOYB
|
if ($_POST['Download'] && ($bogons || $urltable)) {
|
119 |
3a652703
|
sbeaver
|
|
120 |
f6622167
|
NOYB
|
if ($bogons) { // If selected table is either bogons or bogonsv6.
|
121 |
|
|
$mwexec_bg_cmd = '/etc/rc.update_bogons.sh now';
|
122 |
|
|
$table_type = 'bogons';
|
123 |
|
|
$db_name = 'bogons';
|
124 |
|
|
} else if ($urltable) { // If selected table is a URL table alias.
|
125 |
|
|
$mwexec_bg_cmd = '/etc/rc.update_urltables now forceupdate ' . $tablename;
|
126 |
|
|
$table_type = 'urltables';
|
127 |
|
|
$db_name = $tablename;
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
mwexec_bg($mwexec_bg_cmd);
|
131 |
|
|
$maxtimetowait = 0;
|
132 |
|
|
$loading = true;
|
133 |
|
|
while ($loading == true) {
|
134 |
|
|
$isrunning = `/bin/ps awwwux | /usr/bin/grep -v grep | /usr/bin/grep $table_type`;
|
135 |
|
|
if ($isrunning == "") {
|
136 |
|
|
$loading = false;
|
137 |
3a652703
|
sbeaver
|
}
|
138 |
f6622167
|
NOYB
|
$maxtimetowait++;
|
139 |
|
|
if ($maxtimetowait > 89) {
|
140 |
|
|
$loading = false;
|
141 |
947141fd
|
Phil Davis
|
}
|
142 |
f6622167
|
NOYB
|
sleep(1);
|
143 |
|
|
}
|
144 |
|
|
if ($maxtimetowait < 90) {
|
145 |
|
|
$savemsg = sprintf(gettext("The %s database has been updated."), $db_name);
|
146 |
6c474eb8
|
Warren Baker
|
}
|
147 |
|
|
}
|
148 |
|
|
|
149 |
e26e0eac
|
jim-p
|
exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
|
150 |
34525fef
|
Ermal
|
exec("/sbin/pfctl -sT", $tables);
|
151 |
7afae53f
|
Scott Ullrich
|
|
152 |
|
|
include("head.inc");
|
153 |
c054d8bc
|
sbeaver
|
|
154 |
947141fd
|
Phil Davis
|
if ($savemsg) {
|
155 |
e6f5c464
|
Stephen Beaver
|
print_info_box($savemsg, 'success');
|
156 |
947141fd
|
Phil Davis
|
}
|
157 |
ad9e2a90
|
sbeaver
|
|
158 |
060ed238
|
Stephen Beaver
|
if ($tablename == "webConfiguratorlockout") {
|
159 |
1176360c
|
k-paulius
|
$displayname = gettext("webConfigurator Lockout Table");
|
160 |
060ed238
|
Stephen Beaver
|
} else {
|
161 |
3d7a8696
|
k-paulius
|
$displayname = sprintf(gettext("%s Table"), ucfirst($tablename));
|
162 |
060ed238
|
Stephen Beaver
|
}
|
163 |
|
|
|
164 |
e6f5c464
|
Stephen Beaver
|
$form = new Form(false);
|
165 |
3a652703
|
sbeaver
|
|
166 |
5f88f964
|
k-paulius
|
$section = new Form_Section('Table to Display');
|
167 |
e6f5c464
|
Stephen Beaver
|
$group = new Form_Group("Table");
|
168 |
ad9e2a90
|
sbeaver
|
|
169 |
e6f5c464
|
Stephen Beaver
|
$group->add(new Form_Select(
|
170 |
ad9e2a90
|
sbeaver
|
'type',
|
171 |
e6f5c464
|
Stephen Beaver
|
null,
|
172 |
ad9e2a90
|
sbeaver
|
$tablename,
|
173 |
|
|
array_combine($tables, $tables)
|
174 |
|
|
));
|
175 |
|
|
|
176 |
f6622167
|
NOYB
|
if ($bogons || $urltable || !empty($entries)) {
|
177 |
|
|
if ($bogons || $urltable) {
|
178 |
e6f5c464
|
Stephen Beaver
|
$group->add(new Form_Button(
|
179 |
|
|
'Download',
|
180 |
faab522f
|
Renato Botelho
|
'Update',
|
181 |
37676f4e
|
jim-p
|
null,
|
182 |
|
|
'fa-refresh'
|
183 |
|
|
))->addClass('btn-success btn-sm');
|
184 |
e6f5c464
|
Stephen Beaver
|
} elseif (!empty($entries)) {
|
185 |
|
|
$group->add(new Form_Button(
|
186 |
|
|
'clearall',
|
187 |
faab522f
|
Renato Botelho
|
'Empty Table',
|
188 |
37676f4e
|
jim-p
|
null,
|
189 |
8a3c6f0c
|
jim-p
|
'fa-trash'
|
190 |
37676f4e
|
jim-p
|
))->addClass('btn-danger btn-sm');
|
191 |
e6f5c464
|
Stephen Beaver
|
}
|
192 |
|
|
}
|
193 |
|
|
|
194 |
|
|
$section->add($group);
|
195 |
ad9e2a90
|
sbeaver
|
$form->add($section);
|
196 |
|
|
print $form;
|
197 |
e6f5c464
|
Stephen Beaver
|
|
198 |
f6622167
|
NOYB
|
if ($bogons || $urltable || !empty($entries)) {
|
199 |
c57b2aad
|
Phil Davis
|
?>
|
200 |
|
|
<div>
|
201 |
c95dabdd
|
Stephen Beaver
|
<div class="infoblock blockopen">
|
202 |
c57b2aad
|
Phil Davis
|
<?php
|
203 |
f6622167
|
NOYB
|
if ($bogons) {
|
204 |
|
|
$table_file = '/etc/' . escapeshellarg($tablename);
|
205 |
|
|
} else if ($urltable) {
|
206 |
|
|
$table_file = '/var/db/aliastables/' . escapeshellarg($tablename) . '.txt';
|
207 |
|
|
} else {
|
208 |
|
|
$table_file = '';
|
209 |
|
|
}
|
210 |
|
|
|
211 |
|
|
$datestrregex = '(Mon|Tue|Wed|Thr|Fri|Sat|Sun).* GMT';
|
212 |
|
|
$datelineregex = 'last.*' . $datestrregex;
|
213 |
|
|
|
214 |
|
|
$last_updated = exec('/usr/bin/grep -i -m 1 -E "^# ' . $datelineregex . '" ' . $table_file . '|/usr/bin/grep -i -m 1 -E -o "' . $datestrregex . '"');
|
215 |
|
|
|
216 |
c57b2aad
|
Phil Davis
|
if ($last_updated != "") {
|
217 |
8031655d
|
NOYB
|
$last_update_msg = sprintf(gettext("Table last updated on %s."), $last_updated);
|
218 |
c57b2aad
|
Phil Davis
|
} else {
|
219 |
8031655d
|
NOYB
|
$last_update_msg = gettext("Date of last update of table is unknown.");
|
220 |
c57b2aad
|
Phil Davis
|
}
|
221 |
8031655d
|
NOYB
|
|
222 |
|
|
$records_count_msg = sprintf(gettext("%s records."), number_format(count($entries), 0, gettext("."), gettext(",")));
|
223 |
|
|
|
224 |
f6622167
|
NOYB
|
# Display up to 10 comment lines (lines that begin with '#').
|
225 |
|
|
unset($comment_lines);
|
226 |
|
|
$res = exec('/usr/bin/grep -i -m 10 -E "^#" ' . $table_file, $comment_lines);
|
227 |
|
|
|
228 |
|
|
foreach ($comment_lines as $comment_line) {
|
229 |
|
|
$table_comments .= "$comment_line" . "<br />";
|
230 |
|
|
}
|
231 |
|
|
|
232 |
|
|
if ($table_comments) {
|
233 |
f72e804a
|
NOYB
|
print_info_box($last_update_msg . " " . $records_count_msg . "<br />" .
|
234 |
f6622167
|
NOYB
|
'<span style="display:none" class="infoblock">' . ' ' . gettext("Hide table comments.") . '<br />' . $table_comments . '</span>' .
|
235 |
|
|
'<span style="display:none" id="showtblcom">' . ' ' . gettext("Show table comments.") . '</span>' .
|
236 |
|
|
'' , 'info', false);
|
237 |
|
|
} else {
|
238 |
|
|
print_info_box($last_update_msg . " " . $records_count_msg, 'info', false);
|
239 |
|
|
}
|
240 |
c57b2aad
|
Phil Davis
|
?>
|
241 |
|
|
</div>
|
242 |
|
|
</div>
|
243 |
|
|
<?php
|
244 |
e6f5c464
|
Stephen Beaver
|
}
|
245 |
7afae53f
|
Scott Ullrich
|
?>
|
246 |
|
|
|
247 |
8fd9052f
|
Colin Fleming
|
<script type="text/javascript">
|
248 |
|
|
//<![CDATA[
|
249 |
947141fd
|
Phil Davis
|
events.push(function() {
|
250 |
f6622167
|
NOYB
|
|
251 |
|
|
$('#showtblcom').show();
|
252 |
|
|
|
253 |
|
|
$('[id^="showinfo1"]').click(function() {
|
254 |
|
|
$('#showtblcom').toggle();
|
255 |
|
|
});
|
256 |
|
|
|
257 |
947141fd
|
Phil Davis
|
$('a[data-entry]').on('click', function() {
|
258 |
eb500b85
|
Sjon Hortensius
|
var el = $(this);
|
259 |
|
|
|
260 |
|
|
$.ajax(
|
261 |
|
|
'/diag_tables.php',
|
262 |
|
|
{
|
263 |
|
|
type: 'post',
|
264 |
|
|
data: {
|
265 |
|
|
type: '<?=htmlspecialchars($tablename)?>',
|
266 |
|
|
delete: $(this).data('entry')
|
267 |
|
|
},
|
268 |
947141fd
|
Phil Davis
|
success: function() {
|
269 |
eb500b85
|
Sjon Hortensius
|
el.parents('tr').remove();
|
270 |
|
|
},
|
271 |
7afae53f
|
Scott Ullrich
|
});
|
272 |
eb500b85
|
Sjon Hortensius
|
});
|
273 |
e6f5c464
|
Stephen Beaver
|
|
274 |
|
|
// Auto-submit the form on table selector change
|
275 |
|
|
$('#type').on('change', function() {
|
276 |
|
|
$('form').submit();
|
277 |
|
|
});
|
278 |
eb500b85
|
Sjon Hortensius
|
});
|
279 |
8fd9052f
|
Colin Fleming
|
//]]>
|
280 |
7afae53f
|
Scott Ullrich
|
</script>
|
281 |
e166769c
|
Renato Botelho
|
|
282 |
4027d64e
|
k-paulius
|
<?php
|
283 |
|
|
if (empty($entries)) {
|
284 |
|
|
print_info_box(gettext("No entries exist in this table."), 'warning', false);
|
285 |
|
|
} else {
|
286 |
|
|
?>
|
287 |
060ed238
|
Stephen Beaver
|
<div class="panel panel-default">
|
288 |
|
|
<div class="panel-heading"><h2 class="panel-title"><?=$displayname?></h2></div>
|
289 |
|
|
<div class="panel-body">
|
290 |
|
|
<div class="table-responsive">
|
291 |
|
|
<table class="table table-striped table-hover table-condensed">
|
292 |
|
|
<thead>
|
293 |
|
|
<tr>
|
294 |
|
|
<th><?=gettext("IP Address")?></th>
|
295 |
|
|
<th></th>
|
296 |
|
|
</tr>
|
297 |
|
|
</thead>
|
298 |
|
|
<tbody>
|
299 |
37f73a7c
|
NOYB
|
<?php
|
300 |
|
|
// This is a band-aid for a yet to be root caused performance issue with large tables. Suspected is css and/or sorting.
|
301 |
|
|
if (count($entries) > 3000) {
|
302 |
|
|
print "<tr><td colspan='2'><pre>";
|
303 |
|
|
foreach ($entries as $entry) {
|
304 |
|
|
$entry = trim($entry);
|
305 |
|
|
print $entry . "\n";
|
306 |
|
|
}
|
307 |
|
|
print "</pre></td></tr>";
|
308 |
|
|
} else {
|
309 |
|
|
?>
|
310 |
7afae53f
|
Scott Ullrich
|
<?php
|
311 |
eb500b85
|
Sjon Hortensius
|
foreach ($entries as $entry):
|
312 |
|
|
$entry = trim($entry);
|
313 |
7afae53f
|
Scott Ullrich
|
?>
|
314 |
060ed238
|
Stephen Beaver
|
<tr>
|
315 |
|
|
<td>
|
316 |
|
|
<?=$entry?>
|
317 |
|
|
</td>
|
318 |
|
|
<td>
|
319 |
f6622167
|
NOYB
|
<?php if (!$bogons && !$urltable): ?>
|
320 |
37676f4e
|
jim-p
|
<a style="cursor: pointer;" data-entry="<?=htmlspecialchars($entry)?>">
|
321 |
|
|
<i class="fa fa-trash" title="<?= gettext("Remove this entry") ?>"></i>
|
322 |
|
|
</a>
|
323 |
060ed238
|
Stephen Beaver
|
<?php endif ?>
|
324 |
|
|
</td>
|
325 |
|
|
</tr>
|
326 |
eb500b85
|
Sjon Hortensius
|
<?php endforeach ?>
|
327 |
37f73a7c
|
NOYB
|
<?php } ?>
|
328 |
060ed238
|
Stephen Beaver
|
</tbody>
|
329 |
|
|
</table>
|
330 |
|
|
</div>
|
331 |
|
|
</div>
|
332 |
c054d8bc
|
sbeaver
|
</div>
|
333 |
060ed238
|
Stephen Beaver
|
|
334 |
3a652703
|
sbeaver
|
<?php
|
335 |
7c945f74
|
k-paulius
|
}
|
336 |
4027d64e
|
k-paulius
|
|
337 |
7ac86a5f
|
Colin Fleming
|
include("foot.inc");
|