Project

General

Profile

Download (7.11 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
 *	Portions borrowed from diag_dump_states.php
8
 *
9
 *  Redistribution and use in source and binary forms, with or without modification,
10
 *  are permitted provided that the following conditions are met:
11
 *
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
 *      distribution.
19
 *
20
 *  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
 *
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
 *
40
 *  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

    
57
##|+PRIV
58
##|*IDENT=page-diagnostics-tables
59
##|*NAME=Diagnostics: pf Table IP addresses
60
##|*DESCR=Allow access to the 'Diagnostics: Tables' page.
61
##|*MATCH=diag_tables.php*
62
##|-PRIV
63

    
64
$pgtitle = array(gettext("Diagnostics"), gettext("Tables"));
65
$shortcut_section = "aliases";
66

    
67
require_once("guiconfig.inc");
68

    
69
// Set default table
70
$tablename = "sshlockout";
71
$bogons = false;
72

    
73
if ($_REQUEST['type']) {
74
	$tablename = $_REQUEST['type'];
75
}
76

    
77
if ($_REQUEST['delete']) {
78
	if (is_ipaddr($_REQUEST['delete']) || is_subnet($_REQUEST['delete'])) {
79
		exec("/sbin/pfctl -t " . escapeshellarg($_REQUEST['type']) . " -T delete " . escapeshellarg($_REQUEST['delete']), $delete);
80
		echo htmlentities($_REQUEST['delete']);
81
	}
82
	exit;
83
}
84

    
85
if ($_POST['clearall']) {
86
	exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
87
	if (is_array($entries)) {
88
		foreach ($entries as $entryA) {
89
			$entry = trim($entryA);
90
			exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T delete " . escapeshellarg($entry), $delete);
91
		}
92
	}
93
	unset($entries);
94
}
95

    
96
if (($tablename == "bogons") || ($tablename == "bogonsv6")) {
97
	$bogons = true;
98

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

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

    
123
include("head.inc");
124

    
125
if ($savemsg) {
126
	print_info_box($savemsg, 'success');
127
}
128

    
129
if ($tablename == "webConfiguratorlockout") {
130
	$displayname = gettext("webConfigurator Lockout Table");
131
} else {
132
	$displayname = sprintf(gettext("%s Table"), ucfirst($tablename));
133
}
134

    
135
$form = new Form(false);
136

    
137
$section = new Form_Section('Table to Display');
138
$group = new Form_Group("Table");
139

    
140
$group->add(new Form_Select(
141
	'type',
142
	null,
143
	$tablename,
144
	array_combine($tables, $tables)
145
));
146

    
147
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
$form->add($section);
163
print $form;
164

    
165
if ($bogons || !empty($entries)) {
166
?>
167
<div>
168
	<div class="infoblock blockopen">
169
<?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
		$last_update_msg = sprintf(gettext("Table last updated on %s."), $last_updated);
173
	} else {
174
		$last_update_msg = gettext("Date of last update of table is unknown.");
175
	}
176

    
177
	$records_count_msg = sprintf(gettext("%s records."), number_format(count($entries), 0, gettext("."), gettext(",")));
178

    
179
	print_info_box($last_update_msg . "&nbsp; &nbsp; " . $records_count_msg, 'info', false);
180
?>
181
	</div>
182
</div>
183
<?php
184
}
185
?>
186

    
187
<script type="text/javascript">
188
//<![CDATA[
189
events.push(function() {
190
	$('a[data-entry]').on('click', function() {
191
		var el = $(this);
192

    
193
		$.ajax(
194
			'/diag_tables.php',
195
			{
196
				type: 'post',
197
				data: {
198
					type: '<?=htmlspecialchars($tablename)?>',
199
					delete: $(this).data('entry')
200
				},
201
				success: function() {
202
					el.parents('tr').remove();
203
				},
204
		});
205
	});
206

    
207
	// Auto-submit the form on table selector change
208
	$('#type').on('change', function() {
209
        $('form').submit();
210
    });
211
});
212
//]]>
213
</script>
214

    
215
<?php
216
if (empty($entries)) {
217
	print_info_box(gettext("No entries exist in this table."), 'warning', false);
218
} else {
219
?>
220
<div class="panel panel-default">
221
	<div class="panel-heading"><h2 class="panel-title"><?=$displayname?></h2></div>
222
	<div class="panel-body">
223
		<div class="table-responsive">
224
			<table class="table table-striped table-hover table-condensed">
225
				<thead>
226
					<tr>
227
						<th><?=gettext("IP Address")?></th>
228
						<th></th>
229
					</tr>
230
				</thead>
231
				<tbody>
232
<?php
233
		foreach ($entries as $entry):
234
			$entry = trim($entry);
235
?>
236
					<tr>
237
						<td>
238
							<?=$entry?>
239
						</td>
240
						<td>
241
							<?php if (!$bogons): ?>
242
								<a class="btn btn-xs btn-default" data-entry="<?=htmlspecialchars($entry)?>"><?=gettext("Remove")?></a>
243
							<?php endif ?>
244
						</td>
245
					</tr>
246
<?php endforeach ?>
247
				</tbody>
248
			</table>
249
		</div>
250
	</div>
251
</div>
252

    
253
<?php
254
}
255

    
256
$nosorting = TRUE;
257

    
258
include("foot.inc");
(29-29/229)