Project

General

Profile

Download (6.34 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	diag_tables.php
4
*/
5
/* ====================================================================
6
 *  Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved. 
7
 *  Copyright (c)  2010 Jim Pingle
8
 *	Portions borrowed from diag_dump_states.php
9
 *	Copyright (c) 2010 Scott Ullrich
10
 *
11
 *  Redistribution and use in source and binary forms, with or without modification, 
12
 *  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
19
 *      the documentation and/or other materials provided with the
20
 *      distribution. 
21
 *
22
 *  3. All advertising materials mentioning features or use of this software 
23
 *      must display the following acknowledgment:
24
 *      "This product includes software developed by the pfSense Project
25
 *       for use in the pfSense software distribution. (http://www.pfsense.org/). 
26
 *
27
 *  4. The names "pfSense" and "pfSense Project" must not be used to
28
 *       endorse or promote products derived from this software without
29
 *       prior written permission. For written permission, please contact
30
 *       coreteam@pfsense.org.
31
 *
32
 *  5. Products derived from this software may not be called "pfSense"
33
 *      nor may "pfSense" appear in their names without prior written
34
 *      permission of the Electric Sheep Fencing, LLC.
35
 *
36
 *  6. Redistributions of any form whatsoever must retain the following
37
 *      acknowledgment:
38
 *
39
 *  "This product includes software developed by the pfSense Project
40
 *  for use in the pfSense software distribution (http://www.pfsense.org/).
41
  *
42
 *  THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
43
 *  EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45
 *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
46
 *  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
 *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50
 *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
 *  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53
 *  OF THE POSSIBILITY OF SUCH DAMAGE.
54
 *
55
 *  ====================================================================
56
 *
57
 */
58
/*
59
	pfSense_BUILDER_BINARIES:	/sbin/pfctl
60
	pfSense_MODULE: filter
61
*/
62

    
63
##|+PRIV
64
##|*IDENT=page-diagnostics-tables
65
##|*NAME=Diagnostics: PF Table IP addresses
66
##|*DESCR=Allow access to the 'Diagnostics: Tables' page.
67
##|*MATCH=diag_tables.php*
68
##|-PRIV
69

    
70
$pgtitle = array(gettext("Diagnostics"), gettext("Tables"));
71
$shortcut_section = "aliases";
72

    
73
require_once("guiconfig.inc");
74

    
75
// Set default table
76
$tablename = "sshlockout";
77
$bogons = false;
78

    
79
if ($_REQUEST['type']) {
80
	$tablename = $_REQUEST['type'];
81
}
82

    
83
if ($_REQUEST['delete']) {
84
	if (is_ipaddr($_REQUEST['delete']) || is_subnet($_REQUEST['delete'])) {
85
		exec("/sbin/pfctl -t " . escapeshellarg($_REQUEST['type']) . " -T delete " . escapeshellarg($_REQUEST['delete']), $delete);
86
		echo htmlentities($_REQUEST['delete']);
87
	}
88
	exit;
89
}
90

    
91
if ($_POST['deleteall']) {
92
	exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
93
	if (is_array($entries)) {
94
		foreach ($entries as $entryA) {
95
			$entry = trim($entryA);
96
			exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T delete " . escapeshellarg($entry), $delete);
97
		}
98
	}
99
}
100

    
101
if (($tablename == "bogons") || ($tablename == "bogonsv6")) {
102
	$bogons = true;
103

    
104
	if ($_POST['Download']) {
105
		mwexec_bg("/etc/rc.update_bogons.sh now");
106
		$maxtimetowait = 0;
107
		$loading = true;
108
		while ($loading == true) {
109
			$isrunning = `/bin/ps awwwux | /usr/bin/grep -v grep | /usr/bin/grep bogons`;
110
			if ($isrunning == "")
111
				$loading = false;
112
			$maxtimetowait++;
113
			if ($maxtimetowait > 89)
114
				$loading = false;
115
			sleep(1);
116
		}
117
		if ($maxtimetowait < 90)
118
			$savemsg = gettext("The bogons database has been updated.");
119
	}
120
}
121

    
122
exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
123
exec("/sbin/pfctl -sT", $tables);
124

    
125
include("head.inc");
126

    
127
if ($savemsg)
128
	print_info_box($savemsg);
129

    
130
require_once('classes/Form.class.php');
131
$form = new Form('Show');
132

    
133
$section = new Form_Section('Table to display');
134

    
135
$section->addInput(new Form_Select(
136
	'type',
137
	'Table',
138
	$tablename,
139
	array_combine($tables, $tables)
140
));
141

    
142
$form->add($section);
143
print $form;
144
?>
145

    
146
<script>
147
events.push(function(){
148
	$('a[data-entry]').on('click', function(){
149
		var el = $(this);
150

    
151
		$.ajax(
152
			'/diag_tables.php',
153
			{
154
				type: 'post',
155
				data: {
156
					type: '<?=htmlspecialchars($tablename)?>',
157
					delete: $(this).data('entry')
158
				},
159
				success: function(){
160
					el.parents('tr').remove();
161
				},
162
		});
163
	});
164
});
165
</script>
166

    
167
<div class="table-responsive">
168
	<table class="table table-striped table-hover table-condensed">
169
		<thead>
170
			<tr>
171
				<th><?=gettext("IP Address")?></th>
172
			</tr>
173
		</thead>
174
		<tbody>
175
<?php
176
		foreach ($entries as $entry):
177
			$entry = trim($entry);
178
?>
179
			<tr>
180
				<td>
181
					<?=$entry?>
182
				</td>
183
				<td>
184
					<?php if (!$bogons): ?>
185
						<a class="btn btn-xs btn-default" data-entry="<?=htmlspecialchars($entry)?>">Remove</a>
186
					<?php endif ?>
187
				</td>
188
			</tr>
189
<?php endforeach ?>
190
		</tbody>
191
	</table>
192
</div>
193
<?php if (empty($entries)): ?>
194
	<div class="alert alert-warning" role="alert">No entries exist in this table</div>
195
<?php endif ?>
196

    
197
<?php
198

    
199
if ($bogons || !empty($entries)) {
200
	$form = new Form;
201

    
202
	$section = new Form_Section('Table Data');
203

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

    
207
		$section->addInput(new Form_StaticText(
208
			'Last update',
209
			$last_updated
210
		));
211

    
212
		$section->addInput(new Form_Button(
213
			'Download',
214
			'Download'
215
		))->setHelp('Download the latest bogon data')->addClass('btn-warning');
216
	} elseif (!empty($entries)) {
217
		$section->addInput(new Form_Button(
218
			'deleteall',
219
			'Clear Table'
220
		))->setHelp('Clear all of the entries in this table')->addClass('btn-danger');
221
	}
222

    
223
	$form->add($section);
224
	print $form;
225
}
226

    
227
include("foot.inc");
(41-41/235)