Project

General

Profile

Download (5.77 KB) Statistics
| Branch: | Tag: | Revision:
1 7afae53f Scott Ullrich
<?php
2
/*
3 c07b05e0 Scott Ullrich
	diag_tables.php
4 ce77a9c4 Phil Davis
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
5 7afae53f Scott Ullrich
	Copyright (C) 2010 Jim Pingle
6
7
	Portions borrowed from diag_dump_states.php:
8
	Copyright (C) 2010 Scott Ullrich
9
	All rights reserved.
10
11
	Redistribution and use in source and binary forms, with or without
12
	modification, 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 the
19
	   documentation and/or other materials provided with the distribution.
20
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32
33
/*
34
	pfSense_BUILDER_BINARIES:	/sbin/pfctl
35
	pfSense_MODULE:	filter
36
*/
37
38
##|+PRIV
39 c07b05e0 Scott Ullrich
##|*IDENT=page-diagnostics-tables
40
##|*NAME=Diagnostics: PF Table IP addresses
41
##|*DESCR=Allow access to the 'Diagnostics: Tables' page.
42
##|*MATCH=diag_tables.php*
43 7afae53f Scott Ullrich
##|-PRIV
44
45 c07b05e0 Scott Ullrich
$pgtitle = array(gettext("Diagnostics"), gettext("Tables"));
46 d71fc5d3 jim-p
$shortcut_section = "aliases";
47 7afae53f Scott Ullrich
48
require_once("guiconfig.inc");
49
50
// Set default table
51
$tablename = "sshlockout";
52 e166769c Renato Botelho
53 5f601060 Phil Davis
if ($_REQUEST['type']) {
54 34525fef Ermal
	$tablename = $_REQUEST['type'];
55 5f601060 Phil Davis
}
56 e166769c Renato Botelho
57 5f601060 Phil Davis
if ($_REQUEST['delete']) {
58
	if (is_ipaddr($_REQUEST['delete']) || is_subnet($_REQUEST['delete'])) {
59 7afae53f Scott Ullrich
		exec("/sbin/pfctl -t " . escapeshellarg($_REQUEST['type']) . " -T delete " . escapeshellarg($_REQUEST['delete']), $delete);
60
		echo htmlentities($_REQUEST['delete']);
61
	}
62 e166769c Renato Botelho
	exit;
63 7afae53f Scott Ullrich
}
64
65 5f601060 Phil Davis
if ($_REQUEST['deleteall']) {
66 e26e0eac jim-p
	exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
67 5f601060 Phil Davis
	if (is_array($entries)) {
68
		foreach ($entries as $entryA) {
69 7afae53f Scott Ullrich
			$entry = trim($entryA);
70
			exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T delete " . escapeshellarg($entry), $delete);
71
		}
72
	}
73
}
74
75 5f601060 Phil Davis
if ((($tablename == "bogons") || ($tablename == "bogonsv6")) && ($_POST['Download'])) {
76 6c474eb8 Warren Baker
	mwexec_bg("/etc/rc.update_bogons.sh now");
77
	$maxtimetowait = 0;
78
	$loading = true;
79 5f601060 Phil Davis
	while ($loading == true) {
80 6c474eb8 Warren Baker
		$isrunning = `/bin/ps awwwux | /usr/bin/grep -v grep | /usr/bin/grep bogons`;
81 5f601060 Phil Davis
		if ($isrunning == "") {
82 6c474eb8 Warren Baker
			$loading = false;
83 5f601060 Phil Davis
		}
84 6c474eb8 Warren Baker
		$maxtimetowait++;
85 5f601060 Phil Davis
		if ($maxtimetowait > 89) {
86 6c474eb8 Warren Baker
			$loading = false;
87 5f601060 Phil Davis
		}
88 6c474eb8 Warren Baker
		sleep(1);
89
	}
90 5f601060 Phil Davis
	if ($maxtimetowait < 90) {
91 6c474eb8 Warren Baker
		$savemsg = gettext("The bogons database has been updated.");
92 5f601060 Phil Davis
	}
93 6c474eb8 Warren Baker
}
94
95 e26e0eac jim-p
exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
96 34525fef Ermal
exec("/sbin/pfctl -sT", $tables);
97 7afae53f Scott Ullrich
98
include("head.inc");
99
?>
100 7786daaa Colin Fleming
<body>
101
<?php include("fbegin.inc"); ?>
102 7afae53f Scott Ullrich
103 1c9ed80d Warren Baker
<?php if ($savemsg) print_info_box($savemsg); ?>
104 7786daaa Colin Fleming
<form method="post" action="diag_tables.php">
105 7afae53f Scott Ullrich
106 91f026b0 ayvis
<script type="text/javascript">
107 7786daaa Colin Fleming
//<![CDATA[
108 7afae53f Scott Ullrich
	function method_change(entrytype) {
109 c07b05e0 Scott Ullrich
		window.location='diag_tables.php?type=' + entrytype;
110 7afae53f Scott Ullrich
	}
111
	function del_entry(entry) {
112 e26e0eac jim-p
		jQuery.ajax("diag_tables.php?type=<?php echo htmlspecialchars($tablename);?>&delete=" + entry, {
113 ebfc87d6 Vinicius Coque
		complete: function(response) {
114
			if (200 == response.status) {
115
				// Escape all dots to not confuse jQuery selectors
116
				name = response.responseText.replace(/\./g,'\\.');
117 f7ff77fa jim-p
				name = name.replace(/\//g,'\\/');
118 ebfc87d6 Vinicius Coque
				jQuery('#' + name).fadeOut(1000);
119
			}
120 7afae53f Scott Ullrich
		}
121
		});
122
	}
123 7786daaa Colin Fleming
//]]>
124 7afae53f Scott Ullrich
</script>
125 e166769c Renato Botelho
126
<?=gettext("Table:");?>
127 7786daaa Colin Fleming
<select id="type" onchange="method_change(jQuery('#type').val());" name="type">
128 5f601060 Phil Davis
	<?php
129
	foreach ($tables as $table) {
130 7786daaa Colin Fleming
		echo "<option value=\"{$table}\"";
131 5f601060 Phil Davis
		if ($tablename == $table) {
132 7786daaa Colin Fleming
			echo " selected=\"selected\"";
133 34525fef Ermal
		}
134 5f601060 Phil Davis
		echo ">{$table}</option>\n";
135
	}
136 34525fef Ermal
	?>
137 7afae53f Scott Ullrich
</select>
138
139 7786daaa Colin Fleming
<br/><br/>
140 7afae53f Scott Ullrich
141 7786daaa Colin Fleming
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0" summary="tables">
142 7afae53f Scott Ullrich
	<tr>
143 441e7f01 Renato Botelho
		<td class="listhdrr"><?=gettext("IP Address");?></td>
144 7afae53f Scott Ullrich
	</tr>
145 5f601060 Phil Davis
<?php
146
	$count = 0;
147
	foreach ($entries as $entryA):
148
		$entry = trim($entryA);
149
?>
150 7786daaa Colin Fleming
	<tr id="<?=$entry?>">
151 7afae53f Scott Ullrich
		<td>
152
			<?php echo $entry; ?>
153
		</td>
154
		<td>
155 5f601060 Phil Davis
			<?php if (($tablename != "bogons") && ($tablename != "bogonsv6")) { ?>
156 7786daaa Colin Fleming
			<a onclick="del_entry('<?=htmlspecialchars($entry)?>');">
157
				<img src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" alt="delete" />
158 7afae53f Scott Ullrich
			</a>
159 7786daaa Colin Fleming
			<?php } ?>
160 7afae53f Scott Ullrich
		</td>
161
	</tr>
162
<?php
163 5f601060 Phil Davis
		$count++;
164
	endforeach;
165
	if ($count == 0) {
166
		if (($tablename == "bogons") || ($tablename == "bogonsv6")) {
167 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.");
168 5f601060 Phil Davis
		} else {
169 7786daaa Colin Fleming
			echo "<tr><td>" . gettext("No entries exist in this table.");
170 5f601060 Phil Davis
		}
171
	}
172 7afae53f Scott Ullrich
?>
173
174
<?php
175 5f601060 Phil Davis
	if ($count > 0) {
176
		if (($tablename == "bogons") || ($tablename == "bogonsv6")) {
177 83b9c4d2 N0YB
			$last_updated = exec('/usr/bin/grep -i -m 1 -E "^# last updated" /etc/' . escapeshellarg($tablename));
178 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";
179 5f601060 Phil Davis
		} else {
180 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.");
181 5f601060 Phil Davis
		}
182
	}
183 7afae53f Scott Ullrich
?>
184 7786daaa Colin Fleming
</td></tr>
185 909e7d0d N0YB
</table>
186 7786daaa Colin Fleming
</form>
187 909e7d0d N0YB
188 7afae53f Scott Ullrich
<?php include("fend.inc"); ?>
189 7786daaa Colin Fleming
</body>
190
</html>