Project

General

Profile

Download (6.88 KB) Statistics
| Branch: | Tag: | Revision:
1 7afae53f Scott Ullrich
<?php
2
/*
3 c07b05e0 Scott Ullrich
	diag_tables.php
4 7afae53f Scott Ullrich
*/
5 fd9ebcd5 Stephen Beaver
/* ====================================================================
6 0da0d43e Phil Davis
 *  Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7 fd9ebcd5 Stephen Beaver
 *	Portions borrowed from diag_dump_states.php
8
 *
9 0da0d43e Phil Davis
 *  Redistribution and use in source and binary forms, with or without modification,
10
 *  are permitted provided that the following conditions are met:
11 fd9ebcd5 Stephen Beaver
 *
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 0da0d43e Phil Davis
 *      distribution.
19 fd9ebcd5 Stephen Beaver
 *
20 0da0d43e Phil Davis
 *  3. All advertising materials mentioning features or use of this software
21 fd9ebcd5 Stephen Beaver
 *      must display the following acknowledgment:
22
 *      "This product includes software developed by the pfSense Project
23 0da0d43e Phil Davis
 *       for use in the pfSense software distribution. (http://www.pfsense.org/).
24 fd9ebcd5 Stephen Beaver
 *
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 0da0d43e Phil Davis
 *
40 fd9ebcd5 Stephen Beaver
 *  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 7afae53f Scott Ullrich
57
##|+PRIV
58 c07b05e0 Scott Ullrich
##|*IDENT=page-diagnostics-tables
59 9599211d jim-p
##|*NAME=Diagnostics: pf Table IP addresses
60 c07b05e0 Scott Ullrich
##|*DESCR=Allow access to the 'Diagnostics: Tables' page.
61
##|*MATCH=diag_tables.php*
62 7afae53f Scott Ullrich
##|-PRIV
63
64 c07b05e0 Scott Ullrich
$pgtitle = array(gettext("Diagnostics"), gettext("Tables"));
65 d71fc5d3 jim-p
$shortcut_section = "aliases";
66 7afae53f Scott Ullrich
67
require_once("guiconfig.inc");
68
69
// Set default table
70
$tablename = "sshlockout";
71 3a652703 sbeaver
$bogons = false;
72 e166769c Renato Botelho
73 5f601060 Phil Davis
if ($_REQUEST['type']) {
74 34525fef Ermal
	$tablename = $_REQUEST['type'];
75 5f601060 Phil Davis
}
76 e166769c Renato Botelho
77 5f601060 Phil Davis
if ($_REQUEST['delete']) {
78
	if (is_ipaddr($_REQUEST['delete']) || is_subnet($_REQUEST['delete'])) {
79 7afae53f Scott Ullrich
		exec("/sbin/pfctl -t " . escapeshellarg($_REQUEST['type']) . " -T delete " . escapeshellarg($_REQUEST['delete']), $delete);
80
		echo htmlentities($_REQUEST['delete']);
81
	}
82 e166769c Renato Botelho
	exit;
83 7afae53f Scott Ullrich
}
84
85 6f80b61e Phil Davis
if ($_POST['clearall']) {
86 e26e0eac jim-p
	exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
87 5f601060 Phil Davis
	if (is_array($entries)) {
88
		foreach ($entries as $entryA) {
89 7afae53f Scott Ullrich
			$entry = trim($entryA);
90
			exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T delete " . escapeshellarg($entry), $delete);
91
		}
92
	}
93 16424666 Phil Davis
	unset($entries);
94 7afae53f Scott Ullrich
}
95
96 288a2a0f Phil Davis
if (($tablename == "bogons") || ($tablename == "bogonsv6")) {
97 3a652703 sbeaver
	$bogons = true;
98
99 288a2a0f Phil Davis
	if ($_POST['Download']) {
100 3a652703 sbeaver
		mwexec_bg("/etc/rc.update_bogons.sh now");
101
		$maxtimetowait = 0;
102
		$loading = true;
103 288a2a0f Phil Davis
		while ($loading == true) {
104 3a652703 sbeaver
			$isrunning = `/bin/ps awwwux | /usr/bin/grep -v grep | /usr/bin/grep bogons`;
105 947141fd Phil Davis
			if ($isrunning == "") {
106 3a652703 sbeaver
				$loading = false;
107 947141fd Phil Davis
			}
108 3a652703 sbeaver
			$maxtimetowait++;
109 947141fd Phil Davis
			if ($maxtimetowait > 89) {
110 3a652703 sbeaver
				$loading = false;
111 947141fd Phil Davis
			}
112 3a652703 sbeaver
			sleep(1);
113
		}
114 947141fd Phil Davis
		if ($maxtimetowait < 90) {
115 3a652703 sbeaver
			$savemsg = gettext("The bogons database has been updated.");
116 947141fd Phil Davis
		}
117 6c474eb8 Warren Baker
	}
118
}
119
120 e26e0eac jim-p
exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
121 34525fef Ermal
exec("/sbin/pfctl -sT", $tables);
122 7afae53f Scott Ullrich
123
include("head.inc");
124 c054d8bc sbeaver
125 947141fd Phil Davis
if ($savemsg) {
126 e6f5c464 Stephen Beaver
	print_info_box($savemsg, 'success');
127 947141fd Phil Davis
}
128 ad9e2a90 sbeaver
129 060ed238 Stephen Beaver
if ($tablename == "webConfiguratorlockout") {
130 1176360c k-paulius
	$displayname = gettext("webConfigurator Lockout Table");
131 060ed238 Stephen Beaver
} else {
132 3d7a8696 k-paulius
	$displayname = sprintf(gettext("%s Table"), ucfirst($tablename));
133 060ed238 Stephen Beaver
}
134
135 e6f5c464 Stephen Beaver
$form = new Form(false);
136 3a652703 sbeaver
137 5f88f964 k-paulius
$section = new Form_Section('Table to Display');
138 e6f5c464 Stephen Beaver
$group = new Form_Group("Table");
139 ad9e2a90 sbeaver
140 e6f5c464 Stephen Beaver
$group->add(new Form_Select(
141 ad9e2a90 sbeaver
	'type',
142 e6f5c464 Stephen Beaver
	null,
143 ad9e2a90 sbeaver
	$tablename,
144
	array_combine($tables, $tables)
145
));
146
147 e6f5c464 Stephen Beaver
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 ad9e2a90 sbeaver
$form->add($section);
163
print $form;
164 e6f5c464 Stephen Beaver
165
if ($bogons || !empty($entries)) {
166 c57b2aad Phil Davis
?>
167
<div>
168 c95dabdd Stephen Beaver
	<div class="infoblock blockopen">
169 c57b2aad Phil Davis
<?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 85d29bf5 Stephen Beaver
		print_info_box(gettext("Table last updated on ") . $last_updated, 'info', false);
173 c57b2aad Phil Davis
	} else {
174 85d29bf5 Stephen Beaver
		print_info_box(gettext("Date of last update of table is unknown"), 'info', false);
175 c57b2aad Phil Davis
	}
176
?>
177
	</div>
178
</div>
179
<?php
180 e6f5c464 Stephen Beaver
}
181 7afae53f Scott Ullrich
?>
182
183 8fd9052f Colin Fleming
<script type="text/javascript">
184
//<![CDATA[
185 947141fd Phil Davis
events.push(function() {
186
	$('a[data-entry]').on('click', function() {
187 eb500b85 Sjon Hortensius
		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 947141fd Phil Davis
				success: function() {
198 eb500b85 Sjon Hortensius
					el.parents('tr').remove();
199
				},
200 7afae53f Scott Ullrich
		});
201 eb500b85 Sjon Hortensius
	});
202 e6f5c464 Stephen Beaver
203
	// Auto-submit the form on table selector change
204
	$('#type').on('change', function() {
205
        $('form').submit();
206
    });
207 eb500b85 Sjon Hortensius
});
208 8fd9052f Colin Fleming
//]]>
209 7afae53f Scott Ullrich
</script>
210 e166769c Renato Botelho
211 060ed238 Stephen Beaver
<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 7afae53f Scott Ullrich
<?php
224 eb500b85 Sjon Hortensius
		foreach ($entries as $entry):
225
			$entry = trim($entry);
226 7afae53f Scott Ullrich
?>
227 060ed238 Stephen Beaver
					<tr>
228
						<td>
229
							<?=$entry?>
230
						</td>
231
						<td>
232
							<?php if (!$bogons): ?>
233 185b4365 Phil Davis
								<a class="btn btn-xs btn-default" data-entry="<?=htmlspecialchars($entry)?>"><?=gettext("Remove")?></a>
234 060ed238 Stephen Beaver
							<?php endif ?>
235
						</td>
236
					</tr>
237 eb500b85 Sjon Hortensius
<?php endforeach ?>
238 060ed238 Stephen Beaver
				</tbody>
239
			</table>
240
		</div>
241
	</div>
242 c054d8bc sbeaver
</div>
243 060ed238 Stephen Beaver
244 3a652703 sbeaver
<?php
245 7c945f74 k-paulius
if (empty($entries)) {
246
	print_info_box(gettext("No entries exist in this table"), 'warning', false);
247
}
248 7ac86a5f Colin Fleming
include("foot.inc");