Projet

Général

Profil

Télécharger (8,63 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / widgets / widgets / log.widget.php @ d1dda498

1
<?php
2
/*
3
	$Id$
4
	Copyright 2007 Scott Dale
5
	Part of pfSense widgets (https://www.pfsense.org)
6
	originally based on m0n0wall (http://m0n0.ch/wall)
7

    
8
	Copyright (C) 2004-2005 T. Lechat <dev@lechat.org>, Manuel Kasper <mk@neon1.net>
9
	and Jonathan Watt <jwatt@jwatt.org>.
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17
	
18
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21

    
22
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33

    
34
$nocsrf = true;
35

    
36
require_once("guiconfig.inc");
37
require_once("pfsense-utils.inc");
38
require_once("functions.inc");
39

    
40
/* In an effort to reduce duplicate code, many shared functions have been moved here. */
41
require_once("filter_log.inc");
42

    
43
if(is_numeric($_POST['filterlogentries'])) {
44
	$config['widgets']['filterlogentries'] = $_POST['filterlogentries'];
45

    
46
	$acts = array();
47
	if ($_POST['actpass'])   $acts[] = "Pass";
48
	if ($_POST['actblock'])  $acts[] = "Block";
49
	if ($_POST['actreject']) $acts[] = "Reject";
50

    
51
	if (!empty($acts))
52
		$config['widgets']['filterlogentriesacts'] = implode(" ", $acts);
53
	else
54
		unset($config['widgets']['filterlogentriesacts']);
55
	unset($acts);
56

    
57
	if( ($_POST['filterlogentriesinterfaces']) and ($_POST['filterlogentriesinterfaces'] != "All") )
58
		$config['widgets']['filterlogentriesinterfaces'] = trim($_POST['filterlogentriesinterfaces']);
59
	else
60
		unset($config['widgets']['filterlogentriesinterfaces']);
61

    
62
	write_config("Saved Filter Log Entries via Dashboard");
63
	Header("Location: /");
64
	exit(0);
65
}
66

    
67
$nentries = isset($config['widgets']['filterlogentries']) ? $config['widgets']['filterlogentries'] : 5;
68

    
69
//set variables for log
70

    
71
$nentriesacts       = isset($config['widgets']['filterlogentriesacts'])       ? $config['widgets']['filterlogentriesacts']       : 'All';
72
$nentriesinterfaces = isset($config['widgets']['filterlogentriesinterfaces']) ? $config['widgets']['filterlogentriesinterfaces'] : 'All';
73

    
74
$filterfieldsarray = array(
75
	"act" => $nentriesacts,
76
	"interface" => $nentriesinterfaces
77
);
78

    
79
$filter_logfile = "{$g['varlog_path']}/filter.log";
80
$filterlog = conv_log_filter($filter_logfile, $nentries, 50, $filterfieldsarray);        //Get log entries
81

    
82
/* AJAX related routines */
83
handle_ajax($nentries, $nentries + 20);
84

    
85
?>
86

    
87
<script type="text/javascript">
88
//<![CDATA[
89
lastsawtime = '<?php echo time(); ?>';
90
var lines = Array();
91
var timer;
92
var updateDelay = 30000;
93
var isBusy = false;
94
var isPaused = false;
95
var nentries = <?php echo $nentries; ?>;
96

    
97
<?php
98
if(isset($config['syslog']['reverse']))
99
	echo "var isReverse = true;\n";
100
else
101
	echo "var isReverse = false;\n";
102
?>
103

    
104
/* Called by the AJAX updater */
105
function format_log_line(row) {
106
	var line = '<td class="listMRlr" align="center">' + row[0] + '<\/td>' +
107
		'<td class="listMRr ellipsis" title="' + row[1] + '">' + row[1].slice(0,-3) + '<\/td>' +
108
		'<td class="listMRr ellipsis" title="' + row[2] + '">' + row[2] + '<\/td>' +
109
		'<td class="listMRr ellipsis" title="' + row[3] + '">' + row[3] + '<\/td>' +
110
		'<td class="listMRr ellipsis" title="' + row[4] + '">' + row[4] + '<\/td>';
111

    
112
	var nentriesacts = "<?php echo $nentriesacts; ?>";
113
	var nentriesinterfaces = "<?php echo $nentriesinterfaces; ?>";
114

    
115
	var Action = row[0].match(/alt=.*?(pass|block|reject)/i).join("").match(/pass|block|reject/i).join("");
116
	var Interface = row[2];
117

    
118
	if ( !(in_arrayi(Action,	nentriesacts.replace      (/\s+/g, ',').split(',') ) ) && (nentriesacts != 'All') )			return false;
119
	if ( !(in_arrayi(Interface,	nentriesinterfaces.replace(/\s+/g, ',').split(',') ) ) && (nentriesinterfaces != 'All') )	return false;
120

    
121
	return line;
122
}
123
//]]>
124
</script>
125
<script src="/javascript/filter_log.js" type="text/javascript"></script>
126
<input type="hidden" id="log-config" name="log-config" value="" />
127

    
128
<div id="log-settings" class="widgetconfigdiv" style="display:none;">
129
	<form action="/widgets/widgets/log.widget.php" method="post" name="iforma">
130
		Number of lines to display:
131
		<select name="filterlogentries" class="formfld unknown" id="filterlogentries">
132
		<?php for ($i = 1; $i <= 20; $i++) { ?>
133
			<option value="<?php echo $i;?>" <?php if ($nentries == $i) echo "selected=\"selected\"";?>><?php echo $i;?></option>
134
		<?php } ?>
135
		</select>
136

    
137
<?php
138
		$Include_Act = explode(" ", $nentriesacts);
139
		if ($nentriesinterfaces == "All") $nentriesinterfaces = "";
140
?>
141
		<input id="actpass"   name="actpass"   type="checkbox" value="Pass"   <?php if (in_arrayi('Pass',   $Include_Act)) echo "checked=\"checked\""; ?> /> Pass
142
		<input id="actblock"  name="actblock"  type="checkbox" value="Block"  <?php if (in_arrayi('Block',  $Include_Act)) echo "checked=\"checked\""; ?> /> Block
143
		<input id="actreject" name="actreject" type="checkbox" value="Reject" <?php if (in_arrayi('Reject', $Include_Act)) echo "checked=\"checked\""; ?> /> Reject
144
		<br/>
145
		Interfaces:
146
		<input id="filterlogentriesinterfaces" name="filterlogentriesinterfaces" class="formfld unknown" type="text" size="20" value="<?= htmlspecialchars($nentriesinterfaces) ?>" />
147
		&nbsp; &nbsp; &nbsp;
148
		<input id="submita" name="submita" type="submit" class="formbtn" value="Save" />
149
	</form>
150
</div>
151

    
152
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="table-layout: fixed;" summary="logs">
153
	<colgroup>
154
		<col style='width:  7%;' />
155
		<col style='width: 23%;' />
156
		<col style='width: 11%;' />
157
		<col style='width: 28%;' />
158
		<col style='width: 31%;' />
159
	</colgroup>
160
	<thead>
161
		<tr>
162
			<td class="listhdrr"><?=gettext("Act");?></td>
163
			<td class="listhdrr"><?=gettext("Time");?></td>
164
			<td class="listhdrr"><?=gettext("IF");?></td>
165
			<td class="listhdrr"><?=gettext("Source");?></td>
166
			<td class="listhdrr"><?=gettext("Destination");?></td>
167
		</tr>
168
	</thead>
169
	<tbody id='filter-log-entries'>
170
	<?php
171
	$rowIndex = 0;
172
	foreach ($filterlog as $filterent):
173
	$evenRowClass = $rowIndex % 2 ? " listMReven" : " listMRodd";
174
	$rowIndex++;
175
	?>
176
		<tr class="<?=$evenRowClass?>">
177
			<td class="listMRlr" nowrap="nowrap" align="center">
178
			<a href="#" onclick="javascript:getURL('diag_logs_filter.php?getrulenum=<?php echo "{$filterent['rulenum']},{$filterent['act']}"; ?>', outputrule);">
179
			<img border="0" src="<?php echo find_action_image($filterent['act']);?>" width="11" height="11" alt="<?php echo $filterent['act'];?>" title="<?php echo $filterent['act'];?>" />
180
			</a>
181
			</td>
182
			<td class="listMRr ellipsis nowrap" title="<?php echo htmlspecialchars($filterent['time']);?>"><?php echo substr(htmlspecialchars($filterent['time']),0,-3);?></td>
183
			<td class="listMRr ellipsis nowrap" title="<?php echo htmlspecialchars($filterent['interface']);?>"><?php echo htmlspecialchars($filterent['interface']);?></td>
184
			<td class="listMRr ellipsis nowrap" title="<?php echo htmlspecialchars($filterent['src']);?>">
185
				<a href="#" onclick="javascript:getURL('diag_dns.php?host=<?php echo "{$filterent['srcip']}"; ?>&amp;dialog_output=true', outputrule);" title="<?=gettext("Reverse Resolve with DNS");?>">
186
				<?php echo htmlspecialchars($filterent['srcip']);?></a></td>
187
			<td class="listMRr ellipsis nowrap" title="<?php echo htmlspecialchars($filterent['dst']);?>">
188
				<a href="#" onclick="javascript:getURL('diag_dns.php?host=<?php echo "{$filterent['dstip']}"; ?>&amp;dialog_output=true', outputrule);" title="<?=gettext("Reverse Resolve with DNS");?>">
189
				<?php echo htmlspecialchars($filterent['dstip']);?></a><?php echo ":" . htmlspecialchars($filterent['dstport']);?></td>
190
			<?php
191
				if ($filterent['proto'] == "TCP")
192
					$filterent['proto'] .= ":{$filterent['tcpflags']}";
193
			?>
194
		</tr>
195
	<?php
196
	endforeach;
197
	if ($rowIndex == 0) {
198
	?>
199
		<tr><td></td></tr>
200
	<?php
201
	}
202
	?>
203
	</tbody>
204
</table>
205

    
206
<!-- needed to display the widget settings menu -->
207
<script type="text/javascript">
208
//<![CDATA[
209
	selectIntLink = "log-configure";
210
	textlink = document.getElementById(selectIntLink);
211
	textlink.style.display = "inline";
212
//]]>
213
</script>
(11-11/20)