Project

General

Profile

Download (5.06 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	diag_tables.php
4
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
5
	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
	pfSense_MODULE: filter
36
*/
37

    
38
##|+PRIV
39
##|*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
##|-PRIV
44

    
45
$pgtitle = array(gettext("Diagnostics"), gettext("Tables"));
46
$shortcut_section = "aliases";
47

    
48
require_once("guiconfig.inc");
49

    
50
// Set default table
51
$tablename = "sshlockout";
52
$bogons = false;
53

    
54
if($_REQUEST['type'])
55
	$tablename = $_REQUEST['type'];
56

    
57
if($_REQUEST['delete']) {
58
	if(is_ipaddr($_REQUEST['delete']) || is_subnet($_REQUEST['delete'])) {
59
		exec("/sbin/pfctl -t " . escapeshellarg($_REQUEST['type']) . " -T delete " . escapeshellarg($_REQUEST['delete']), $delete);
60
		echo htmlentities($_REQUEST['delete']);
61
	}
62
	exit;
63
}
64

    
65
if($_POST['deleteall']) {
66
	exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
67
	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
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
	}
94
}
95

    
96
exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
97
exec("/sbin/pfctl -sT", $tables);
98

    
99
include("head.inc");
100

    
101
if ($savemsg)
102
	print_info_box($savemsg);
103

    
104
require('classes/Form.class.php');
105
$form = new Form('Show'));
106

    
107
$section = new Form_Section('Table to display');
108

    
109
$section->addInput(new Form_Select(
110
	'type',
111
	'Table',
112
	$tablename,
113
	array_combine($tables, $tables)
114
));
115

    
116
$form->add($section);
117
print $form;
118
?>
119

    
120
<script>
121
events.push(function(){
122
	$('a[data-entry]').on('click', function(){
123
		var el = $(this);
124

    
125
		$.ajax(
126
			'/diag_tables.php',
127
			{
128
				type: 'post',
129
				data: {
130
					type: '<?=htmlspecialchars($tablename)?>',
131
					delete: $(this).data('entry')
132
				},
133
				success: function(){
134
					el.parents('tr').remove();
135
				},
136
		});
137
	});
138
});
139
</script>
140

    
141
<div class="table-responsive">
142
	<table class="table table-striped table-hover table-condensed">
143
		<thead>
144
			<tr>
145
				<th><?=gettext("IP Address")?></th>
146
			</tr>
147
		</thead>
148
		<tbody>
149
<?php
150
		foreach ($entries as $entry):
151
			$entry = trim($entry);
152
?>
153
			<tr>
154
				<td>
155
					<?=$entry?>
156
				</td>
157
				<td>
158
					<?php if (!$bogons): ?>
159
						<a class="btn btn-xs btn-default" data-entry="<?=htmlspecialchars($entry)?>">Remove</a>
160
					<?php endif ?>
161
				</td>
162
			</tr>
163
<?php endforeach ?>
164
		</tbody>
165
	</table>
166
</div>
167
<?php if (empty($entries)): ?>
168
	<div class="alert alert-warning" role="alert">No entries exist in this table</div>
169
<?php endif ?>
170

    
171
<?php
172

    
173
if ($bogons || !empty($entries)) {
174
	$form = new Form;
175

    
176
	$section = new Form_Section('Table Data');
177

    
178
	if ($bogons) {
179
		$last_updated = exec('/usr/bin/grep -i -m 1 -E "^# last updated" /etc/' . escapeshellarg($tablename) . '|cut -d"(" -f2|tr -d ")" ');
180

    
181
		$section->addInput(new Form_StaticText(
182
			'Last update',
183
			$last_updated
184
		));
185

    
186
		$section->addInput(new Form_Button(
187
			'Download',
188
			'Download'
189
		))->setHelp('Download the latest bogon data')->addClass('btn-warning');
190
	} elseif (!empty($entries)) {
191
		$section->addInput(new Form_Button(
192
			'deleteall',
193
			'Clear Table'
194
		))->setHelp('Clear all of the entries in this table')->addClass('btn-danger');
195
	}
196

    
197
	$form->add($section);
198
	print $form;
199
}
200

    
201
include("foot.inc");
(40-40/241)