Project

General

Profile

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