Projet

Général

Profil

Télécharger (5,51 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / diag_tables.php @ 0fab7eb1

1
<?php
2
/*
3
	diag_tables.php
4
	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
##|*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
##|-PRIV
43

    
44
$pgtitle = array(gettext("Diagnostics"), gettext("Tables"));
45
$shortcut_section = "aliases";
46

    
47
require_once("guiconfig.inc");
48

    
49
// Set default table
50
$tablename = "sshlockout";
51

    
52
if($_REQUEST['type'])
53
	$tablename = $_REQUEST['type'];
54

    
55
if($_REQUEST['delete']) {
56
	if(is_ipaddr($_REQUEST['delete']) || is_subnet($_REQUEST['delete'])) {
57
		exec("/sbin/pfctl -t " . escapeshellarg($_REQUEST['type']) . " -T delete " . escapeshellarg($_REQUEST['delete']), $delete);
58
		echo htmlentities($_REQUEST['delete']);
59
	}
60
	exit;
61
}
62

    
63
if($_REQUEST['deleteall']) {
64
	exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
65
	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
if((($tablename == "bogons") || ($tablename == "bogonsv6")) && ($_POST['Download'])) {
74
	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
exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
91
exec("/sbin/pfctl -sT", $tables);
92

    
93
include("head.inc");
94
include("fbegin.inc");
95

    
96
?>
97

    
98
<?php if ($savemsg) print_info_box($savemsg); ?>
99
<form method='post'>
100

    
101
<script type="text/javascript">
102
	function method_change(entrytype) {
103
		window.location='diag_tables.php?type=' + entrytype;
104
	}
105
	function del_entry(entry) {
106
		jQuery.ajax("diag_tables.php?type=<?php echo htmlspecialchars($tablename);?>&delete=" + entry, {
107
		complete: function(response) {
108
			if (200 == response.status) {
109
				// Escape all dots to not confuse jQuery selectors
110
				name = response.responseText.replace(/\./g,'\\.');
111
				name = name.replace(/\//g,'\\/');
112
				jQuery('#' + name).fadeOut(1000);
113
			}
114
		}
115
		});
116
	}
117
</script>
118

    
119
<?=gettext("Table:");?>
120
<select id='type' onChange='method_change(jQuery("#type").val());' name='type'>
121
	<?php foreach ($tables as $table) {
122
		echo "<option name='{$table}' value='{$table}'";
123
		if ($tablename == $table)
124
			echo " selected ";
125
		echo ">{$table}</option>\n";
126
		}
127
	?>
128
</select>
129

    
130
<p/>
131

    
132
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
133
	<tr>
134
		<td class="listhdrr"><?=gettext("IP Address");?></td>
135
	</tr>
136
<?php $count = 0; foreach($entries as $entryA): ?>
137
	<?php $entry = trim($entryA); ?>
138
	<tr id='<?=$entry?>'>
139
		<td>
140
			<?php echo $entry; ?>
141
		</td>
142
		<td>
143
			<?php if ( ($tablename != "bogons") && ($tablename != "bogonsv6") ) { ?>
144
			<a onClick='del_entry("<?=htmlspecialchars($entry)?>");'>
145
				<img img src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif">
146
			<?php } ?>
147
			</a>
148
		</td>
149
	</tr>
150
<?php $count++; endforeach; ?>
151
<?php
152
	if($count == 0)
153
		if( ($tablename == "bogons") || ($tablename == "bogonsv6") )
154
			echo "<p/>" . gettext("No entries exist in this table.") . "&nbsp&nbsp" . "<input name='Download' type='submit' class='formbtn' value='" . gettext("Download") . "'> " . gettext(" the latest bogon data.");
155
		else
156
			echo "<p/>" . gettext("No entries exist in this table.");
157
?>
158

    
159
<?php
160
	if($count > 0)
161
		if( ($tablename == "bogons") || ($tablename == "bogonsv6") ) {
162
			$last_updated = exec('/usr/bin/grep -i -m 1 -E "^# last updated" /etc/' . escapeshellarg($tablename));
163
			echo "<p/>&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";
164
		}
165
		else
166
			echo "<p/>" . gettext("Delete") . " <a href='diag_tables.php?deleteall=true&type=" . htmlspecialchars($tablename) . "'>" . gettext("all") . "</a> " . "<b>$count</b> " . gettext("entries in this table.");
167
?>
168

    
169
</table>
170

    
171
<?php include("fend.inc"); ?>
(49-49/254)