Project

General

Profile

Download (5.09 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(
106
	new Form_Button(
107
		null,
108
		'Show'
109
));
110

    
111
$section = new Form_Section('Table to display');
112

    
113
$section->addInput(new Form_Select(
114
	'type',
115
	'Table',
116
	$tablename,
117
	array_combine($tables, $tables)
118
));
119

    
120
$form->add($section);
121
print $form;
122
?>
123

    
124
<script>
125
events.push(function(){
126
	$('a[data-entry]').on('click', function(){
127
		var el = $(this);
128

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

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

    
175
<?php
176

    
177
if ($bogons || !empty($entries)) {
178
	$form = new Form;
179

    
180
	$section = new Form_Section('Table Data');
181

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

    
185
		$section->addInput(new Form_StaticText(
186
			'Last update',
187
			$last_updated
188
		));
189

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

    
201
	$form->add($section);
202
	print $form;
203
}
204

    
205
include("foot.inc");
(51-51/252)