Project

General

Profile

Download (4.72 KB) Statistics
| Branch: | Tag: | Revision:
1 7afae53f Scott Ullrich
<?php
2
/*
3 c07b05e0 Scott Ullrich
	diag_tables.php
4 7afae53f Scott Ullrich
	Copyright (C) 2010 Jim Pingle
5
6
	Portions borrowed from diag_dump_states.php:
7
	Copyright (C) 2010 Scott Ullrich
8
	All rights reserved.
9
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31
32
/*
33
	pfSense_BUILDER_BINARIES:	/sbin/pfctl
34
	pfSense_MODULE:	filter
35
*/
36
37
##|+PRIV
38 c07b05e0 Scott Ullrich
##|*IDENT=page-diagnostics-tables
39
##|*NAME=Diagnostics: PF Table IP addresses
40
##|*DESCR=Allow access to the 'Diagnostics: Tables' page.
41
##|*MATCH=diag_tables.php*
42 7afae53f Scott Ullrich
##|-PRIV
43
44 c07b05e0 Scott Ullrich
$pgtitle = array(gettext("Diagnostics"), gettext("Tables"));
45 7afae53f Scott Ullrich
46
require_once("guiconfig.inc");
47
48
// Set default table
49
$tablename = "sshlockout";
50
	
51 34525fef Ermal
if($_REQUEST['type']) 
52
	$tablename = $_REQUEST['type'];
53 7afae53f Scott Ullrich
	
54
if($_REQUEST['delete']) {
55
	if(is_ipaddr($_REQUEST['delete'])) {
56
		exec("/sbin/pfctl -t " . escapeshellarg($_REQUEST['type']) . " -T delete " . escapeshellarg($_REQUEST['delete']), $delete);
57
		echo htmlentities($_REQUEST['delete']);
58
	}
59
	exit;	
60
}
61
62
if($_REQUEST['deleteall']) {
63
	exec("/sbin/pfctl -t $tablename -T show", $entries);
64
	if(is_array($entries)) {
65
		foreach($entries as $entryA) {
66
			$entry = trim($entryA);
67
			exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T delete " . escapeshellarg($entry), $delete);
68
		}
69
	}
70
}
71
72 6c474eb8 Warren Baker
if(($tablename == "bogons") && ($_POST['Download'])) {
73
	mwexec_bg("/etc/rc.update_bogons.sh now");
74
	$maxtimetowait = 0;
75
	$loading = true;
76
	while($loading == true) {
77
		$isrunning = `/bin/ps awwwux | /usr/bin/grep -v grep | /usr/bin/grep bogons`;
78
		if($isrunning == "")
79
			$loading = false;
80
		$maxtimetowait++;
81
		if($maxtimetowait > 89)
82
			$loading = false;
83
		sleep(1);
84
	}
85
	if($maxtimetowait < 90)
86
		$savemsg = gettext("The bogons database has been updated.");
87
}
88
89 7afae53f Scott Ullrich
exec("/sbin/pfctl -t $tablename -T show", $entries);
90 34525fef Ermal
exec("/sbin/pfctl -sT", $tables);
91 7afae53f Scott Ullrich
92
include("head.inc");
93
include("fbegin.inc");
94
95
?>
96
97 1c9ed80d Warren Baker
<?php if ($savemsg) print_info_box($savemsg); ?>
98 7afae53f Scott Ullrich
<form method='post'>
99
100
<script language="javascript">
101
	function method_change(entrytype) {
102 c07b05e0 Scott Ullrich
		window.location='diag_tables.php?type=' + entrytype;
103 7afae53f Scott Ullrich
	}
104
	function del_entry(entry) {
105 ebfc87d6 Vinicius Coque
		jQuery.ajax("diag_tables.php?type=<?php echo $tablename;?>&delete=" + entry, {
106
		complete: function(response) {
107
			if (200 == response.status) {
108
				// Escape all dots to not confuse jQuery selectors
109
				name = response.responseText.replace(/\./g,'\\.');
110
				jQuery('#' + name).fadeOut(1000);
111
			}
112 7afae53f Scott Ullrich
		}
113
		});
114
	}
115
</script>
116
	
117 9f6bd43e Carlos Eduardo Ramos
<?=gettext("Table:");?> 
118 51e9533f Vinicius Coque
<select id='type' onChange='method_change(jQuery("#type").val());' name='type'>
119 34525fef Ermal
	<?php foreach ($tables as $table) {
120
		echo "<option name='{$table}' value='{$table}'";
121
		if ($tablename == $table)
122
			echo " selected ";
123
		echo ">{$table}</option>\n";
124
		}
125
	?>
126 7afae53f Scott Ullrich
</select>
127
128
<p/>
129
130
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
131
	<tr>
132 441e7f01 Renato Botelho
		<td class="listhdrr"><?=gettext("IP Address");?></td>
133 7afae53f Scott Ullrich
	</tr>
134
<?php $count = 0; foreach($entries as $entryA): ?>
135
	<?php $entry = trim($entryA); ?>
136
	<tr id='<?=$entry?>'>
137
		<td>
138
			<?php echo $entry; ?>
139
		</td>
140
		<td>
141 6c474eb8 Warren Baker
			<?php if ($tablename != "bogons") { ?>
142 7afae53f Scott Ullrich
			<a onClick='del_entry("<?=$entry?>");'>
143
				<img img src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif">
144 6c474eb8 Warren Baker
			<?php } ?>
145 7afae53f Scott Ullrich
			</a>
146
		</td>
147
	</tr>
148
<?php $count++; endforeach; ?>
149
<?php
150
	if($count == 0)
151 441e7f01 Renato Botelho
		echo "<tr><td>" . gettext("No entries exist in this table.") . "</td></tr>";
152 7afae53f Scott Ullrich
?>
153
154
</table>
155
156
<?php
157
	if($count > 0)
158 6c474eb8 Warren Baker
  		if($tablename == "bogons")
159
			echo "<input name='Download' type='submit' class='formbtn' value='" . gettext("Download") . "'> " . gettext(" the latest bogon data.");
160
		else
161
			echo "<p/>" . gettext("Delete") . " <a href='diag_tables.php?deleteall=true&type={$tablename}'>" . gettext("all") . "</a> " . gettext("entries in this table.");
162 7afae53f Scott Ullrich
?>
163
164
<?php include("fend.inc"); ?>