Project

General

Profile

Download (5.67 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 d71fc5d3 jim-p
$shortcut_section = "aliases";
46 7afae53f Scott Ullrich
47
require_once("guiconfig.inc");
48
49
// Set default table
50
$tablename = "sshlockout";
51 e166769c Renato Botelho
52
if($_REQUEST['type'])
53 34525fef Ermal
	$tablename = $_REQUEST['type'];
54 e166769c Renato Botelho
55 7afae53f Scott Ullrich
if($_REQUEST['delete']) {
56 e26e0eac jim-p
	if(is_ipaddr($_REQUEST['delete']) || is_subnet($_REQUEST['delete'])) {
57 7afae53f Scott Ullrich
		exec("/sbin/pfctl -t " . escapeshellarg($_REQUEST['type']) . " -T delete " . escapeshellarg($_REQUEST['delete']), $delete);
58
		echo htmlentities($_REQUEST['delete']);
59
	}
60 e166769c Renato Botelho
	exit;
61 7afae53f Scott Ullrich
}
62
63
if($_REQUEST['deleteall']) {
64 e26e0eac jim-p
	exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
65 7afae53f Scott Ullrich
	if(is_array($entries)) {
66
		foreach($entries as $entryA) {
67
			$entry = trim($entryA);
68
			exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T delete " . escapeshellarg($entry), $delete);
69
		}
70
	}
71
}
72
73 909e7d0d N0YB
if((($tablename == "bogons") || ($tablename == "bogonsv6")) && ($_POST['Download'])) {
74 6c474eb8 Warren Baker
	mwexec_bg("/etc/rc.update_bogons.sh now");
75
	$maxtimetowait = 0;
76
	$loading = true;
77
	while($loading == true) {
78
		$isrunning = `/bin/ps awwwux | /usr/bin/grep -v grep | /usr/bin/grep bogons`;
79
		if($isrunning == "")
80
			$loading = false;
81
		$maxtimetowait++;
82
		if($maxtimetowait > 89)
83
			$loading = false;
84
		sleep(1);
85
	}
86
	if($maxtimetowait < 90)
87
		$savemsg = gettext("The bogons database has been updated.");
88
}
89
90 e26e0eac jim-p
exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
91 34525fef Ermal
exec("/sbin/pfctl -sT", $tables);
92 7afae53f Scott Ullrich
93
include("head.inc");
94
?>
95 7786daaa Colin Fleming
<body>
96
<?php include("fbegin.inc"); ?>
97 7afae53f Scott Ullrich
98 1c9ed80d Warren Baker
<?php if ($savemsg) print_info_box($savemsg); ?>
99 7786daaa Colin Fleming
<form method="post" action="diag_tables.php">
100 7afae53f Scott Ullrich
101 91f026b0 ayvis
<script type="text/javascript">
102 7786daaa Colin Fleming
//<![CDATA[
103 7afae53f Scott Ullrich
	function method_change(entrytype) {
104 c07b05e0 Scott Ullrich
		window.location='diag_tables.php?type=' + entrytype;
105 7afae53f Scott Ullrich
	}
106
	function del_entry(entry) {
107 e26e0eac jim-p
		jQuery.ajax("diag_tables.php?type=<?php echo htmlspecialchars($tablename);?>&delete=" + entry, {
108 ebfc87d6 Vinicius Coque
		complete: function(response) {
109
			if (200 == response.status) {
110
				// Escape all dots to not confuse jQuery selectors
111
				name = response.responseText.replace(/\./g,'\\.');
112 f7ff77fa jim-p
				name = name.replace(/\//g,'\\/');
113 ebfc87d6 Vinicius Coque
				jQuery('#' + name).fadeOut(1000);
114
			}
115 7afae53f Scott Ullrich
		}
116
		});
117
	}
118 7786daaa Colin Fleming
//]]>
119 7afae53f Scott Ullrich
</script>
120 e166769c Renato Botelho
121
<?=gettext("Table:");?>
122 7786daaa Colin Fleming
<select id="type" onchange="method_change(jQuery('#type').val());" name="type">
123 34525fef Ermal
	<?php foreach ($tables as $table) {
124 7786daaa Colin Fleming
		echo "<option value=\"{$table}\"";
125 34525fef Ermal
		if ($tablename == $table)
126 7786daaa Colin Fleming
			echo " selected=\"selected\"";
127 34525fef Ermal
		echo ">{$table}</option>\n";
128
		}
129
	?>
130 7afae53f Scott Ullrich
</select>
131
132 7786daaa Colin Fleming
<br/><br/>
133 7afae53f Scott Ullrich
134 7786daaa Colin Fleming
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0" summary="tables">
135 7afae53f Scott Ullrich
	<tr>
136 441e7f01 Renato Botelho
		<td class="listhdrr"><?=gettext("IP Address");?></td>
137 7afae53f Scott Ullrich
	</tr>
138
<?php $count = 0; foreach($entries as $entryA): ?>
139
	<?php $entry = trim($entryA); ?>
140 7786daaa Colin Fleming
	<tr id="<?=$entry?>">
141 7afae53f Scott Ullrich
		<td>
142
			<?php echo $entry; ?>
143
		</td>
144
		<td>
145 909e7d0d N0YB
			<?php if ( ($tablename != "bogons") && ($tablename != "bogonsv6") ) { ?>
146 7786daaa Colin Fleming
			<a onclick="del_entry('<?=htmlspecialchars($entry)?>');">
147
				<img src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" alt="delete" />
148 7afae53f Scott Ullrich
			</a>
149 7786daaa Colin Fleming
			<?php } ?>
150 7afae53f Scott Ullrich
		</td>
151
	</tr>
152
<?php $count++; endforeach; ?>
153
<?php
154
	if($count == 0)
155 e166769c Renato Botelho
		if( ($tablename == "bogons") || ($tablename == "bogonsv6") )
156 7786daaa Colin Fleming
			echo "<tr><td>" . gettext("No entries exist in this table.") . "&nbsp;&nbsp;" . "<input name=\"Download\" type=\"submit\" class=\"formbtn\" value=\"" . gettext("Download") . "\" /> " . gettext(" the latest bogon data.");
157 909e7d0d N0YB
		else
158 7786daaa Colin Fleming
			echo "<tr><td>" . gettext("No entries exist in this table.");
159 7afae53f Scott Ullrich
?>
160
161
<?php
162
	if($count > 0)
163 e166769c Renato Botelho
		if( ($tablename == "bogons") || ($tablename == "bogonsv6") ) {
164 83b9c4d2 N0YB
			$last_updated = exec('/usr/bin/grep -i -m 1 -E "^# last updated" /etc/' . escapeshellarg($tablename));
165 7786daaa Colin Fleming
			echo "<tr><td>&nbsp;<b>$count</b> " . gettext("entries in this table.") . "&nbsp;&nbsp;" . "<input name=\"Download\" type=\"submit\" class=\"formbtn\" value=\"" . gettext("Download") . "\" /> " . gettext(" the latest bogon data.") . "<br />" . "$last_updated";
166 15fc311f jim-p
		}
167 6c474eb8 Warren Baker
		else
168 7786daaa Colin Fleming
			echo "<tr><td>" . gettext("Delete") . " <a href=\"diag_tables.php?deleteall=true&amp;type=" . htmlspecialchars($tablename) . "\">" . gettext("all") . "</a> " . "<b>$count</b> " . gettext("entries in this table.");
169 7afae53f Scott Ullrich
?>
170 7786daaa Colin Fleming
</td></tr>
171 909e7d0d N0YB
</table>
172 7786daaa Colin Fleming
</form>
173 909e7d0d N0YB
174 7afae53f Scott Ullrich
<?php include("fend.inc"); ?>
175 7786daaa Colin Fleming
</body>
176
</html>