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
|
##|+PRIV
|
58
|
##|*IDENT=page-diagnostics-tables
|
59
|
##|*NAME=Diagnostics: pf Table IP addresses
|
60
|
##|*DESCR=Allow access to the 'Diagnostics: Tables' page.
|
61
|
##|*MATCH=diag_tables.php*
|
62
|
##|-PRIV
|
63
|
|
64
|
$pgtitle = array(gettext("Diagnostics"), gettext("Tables"));
|
65
|
$shortcut_section = "aliases";
|
66
|
|
67
|
require_once("guiconfig.inc");
|
68
|
|
69
|
// Set default table
|
70
|
$tablename = "sshlockout";
|
71
|
$bogons = false;
|
72
|
|
73
|
if ($_REQUEST['type']) {
|
74
|
$tablename = $_REQUEST['type'];
|
75
|
}
|
76
|
|
77
|
if ($_REQUEST['delete']) {
|
78
|
if (is_ipaddr($_REQUEST['delete']) || is_subnet($_REQUEST['delete'])) {
|
79
|
exec("/sbin/pfctl -t " . escapeshellarg($_REQUEST['type']) . " -T delete " . escapeshellarg($_REQUEST['delete']), $delete);
|
80
|
echo htmlentities($_REQUEST['delete']);
|
81
|
}
|
82
|
exit;
|
83
|
}
|
84
|
|
85
|
if ($_POST['clearall']) {
|
86
|
exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
|
87
|
if (is_array($entries)) {
|
88
|
foreach ($entries as $entryA) {
|
89
|
$entry = trim($entryA);
|
90
|
exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T delete " . escapeshellarg($entry), $delete);
|
91
|
}
|
92
|
}
|
93
|
unset($entries);
|
94
|
}
|
95
|
|
96
|
if (($tablename == "bogons") || ($tablename == "bogonsv6")) {
|
97
|
$bogons = true;
|
98
|
|
99
|
if ($_POST['Download']) {
|
100
|
mwexec_bg("/etc/rc.update_bogons.sh now");
|
101
|
$maxtimetowait = 0;
|
102
|
$loading = true;
|
103
|
while ($loading == true) {
|
104
|
$isrunning = `/bin/ps awwwux | /usr/bin/grep -v grep | /usr/bin/grep bogons`;
|
105
|
if ($isrunning == "") {
|
106
|
$loading = false;
|
107
|
}
|
108
|
$maxtimetowait++;
|
109
|
if ($maxtimetowait > 89) {
|
110
|
$loading = false;
|
111
|
}
|
112
|
sleep(1);
|
113
|
}
|
114
|
if ($maxtimetowait < 90) {
|
115
|
$savemsg = gettext("The bogons database has been updated.");
|
116
|
}
|
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, 'success');
|
127
|
}
|
128
|
|
129
|
if ($tablename == "webConfiguratorlockout") {
|
130
|
$displayname = gettext("Web configurator lockout table");
|
131
|
} else {
|
132
|
$displayname = sprintf(gettext("%s table"), ucfirst($tablename));
|
133
|
}
|
134
|
|
135
|
$form = new Form(false);
|
136
|
|
137
|
$section = new Form_Section('Table to display');
|
138
|
$group = new Form_Group("Table");
|
139
|
|
140
|
$group->add(new Form_Select(
|
141
|
'type',
|
142
|
null,
|
143
|
$tablename,
|
144
|
array_combine($tables, $tables)
|
145
|
));
|
146
|
|
147
|
if ($bogons || !empty($entries)) {
|
148
|
if ($bogons) {
|
149
|
$group->add(new Form_Button(
|
150
|
'Download',
|
151
|
'Update'
|
152
|
))->removeClass('btn-primary')->addClass('btn-success btn-sm');
|
153
|
} elseif (!empty($entries)) {
|
154
|
$group->add(new Form_Button(
|
155
|
'clearall',
|
156
|
'Clear Table'
|
157
|
))->removeClass('btn-primary')->addClass('btn-danger btn-sm');
|
158
|
}
|
159
|
}
|
160
|
|
161
|
$section->add($group);
|
162
|
$form->add($section);
|
163
|
print $form;
|
164
|
|
165
|
if ($bogons || !empty($entries)) {
|
166
|
?>
|
167
|
<div>
|
168
|
<div class="infoblock blockopen">
|
169
|
<?php
|
170
|
$last_updated = exec('/usr/bin/grep -i -m 1 -E "^# last updated" /etc/' . escapeshellarg($tablename) . '|cut -d"(" -f2|tr -d ")" ');
|
171
|
if ($last_updated != "") {
|
172
|
print_info_box(gettext("Table last updated on ") . $last_updated, 'info', false);
|
173
|
} else {
|
174
|
print_info_box(gettext("Date of last update of table is unknown"), 'info', false);
|
175
|
}
|
176
|
?>
|
177
|
</div>
|
178
|
</div>
|
179
|
<?php
|
180
|
}
|
181
|
?>
|
182
|
|
183
|
<script type="text/javascript">
|
184
|
//<![CDATA[
|
185
|
events.push(function() {
|
186
|
$('a[data-entry]').on('click', function() {
|
187
|
var el = $(this);
|
188
|
|
189
|
$.ajax(
|
190
|
'/diag_tables.php',
|
191
|
{
|
192
|
type: 'post',
|
193
|
data: {
|
194
|
type: '<?=htmlspecialchars($tablename)?>',
|
195
|
delete: $(this).data('entry')
|
196
|
},
|
197
|
success: function() {
|
198
|
el.parents('tr').remove();
|
199
|
},
|
200
|
});
|
201
|
});
|
202
|
|
203
|
// Auto-submit the form on table selector change
|
204
|
$('#type').on('change', function() {
|
205
|
$('form').submit();
|
206
|
});
|
207
|
});
|
208
|
//]]>
|
209
|
</script>
|
210
|
|
211
|
<div class="panel panel-default">
|
212
|
<div class="panel-heading"><h2 class="panel-title"><?=$displayname?></h2></div>
|
213
|
<div class="panel-body">
|
214
|
<div class="table-responsive">
|
215
|
<table class="table table-striped table-hover table-condensed">
|
216
|
<thead>
|
217
|
<tr>
|
218
|
<th><?=gettext("IP Address")?></th>
|
219
|
<th></th>
|
220
|
</tr>
|
221
|
</thead>
|
222
|
<tbody>
|
223
|
<?php
|
224
|
foreach ($entries as $entry):
|
225
|
$entry = trim($entry);
|
226
|
?>
|
227
|
<tr>
|
228
|
<td>
|
229
|
<?=$entry?>
|
230
|
</td>
|
231
|
<td>
|
232
|
<?php if (!$bogons): ?>
|
233
|
<a class="btn btn-xs btn-default" data-entry="<?=htmlspecialchars($entry)?>"><?=gettext("Remove")?></a>
|
234
|
<?php endif ?>
|
235
|
</td>
|
236
|
</tr>
|
237
|
<?php endforeach ?>
|
238
|
</tbody>
|
239
|
</table>
|
240
|
</div>
|
241
|
</div>
|
242
|
</div>
|
243
|
|
244
|
<?php if (empty($entries)): ?>
|
245
|
<div class="alert alert-warning" role="alert"><?=gettext("No entries exist in this table")?></div>
|
246
|
<?php endif ?>
|
247
|
|
248
|
<?php
|
249
|
|
250
|
include("foot.inc");
|