Projet

Général

Profil

Télécharger (9,73 ko) Statistiques
| Branche: | Tag: | Révision:

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

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($_POST['filterlogentries']) {
44
	unset($config['widgets']['filterlogentries']);
45
	if( ($_POST['filterlogentries']) and ($_POST['filterlogentries'] != ' ') ) $config['widgets']['filterlogentries'] = $_POST['filterlogentries'];
46

    
47
	unset($config['widgets']['filterlogentriesacts']);
48
	if($_POST['actpass'])   $config['widgets']['filterlogentriesacts'] .= $_POST['actpass']   . " ";
49
	if($_POST['actblock'])  $config['widgets']['filterlogentriesacts'] .= $_POST['actblock']  . " ";
50
	if($_POST['actreject']) $config['widgets']['filterlogentriesacts'] .= $_POST['actreject'] . " ";
51
	if (isset($config['widgets']['filterlogentriesacts'])) $config['widgets']['filterlogentriesacts'] = trim($config['widgets']['filterlogentriesacts']);
52

    
53
	unset($config['widgets']['filterlogentriesinterfaces']);
54
	if( ($_POST['filterlogentriesinterfaces']) and ($_POST['filterlogentriesinterfaces'] != "All") ) $config['widgets']['filterlogentriesinterfaces'] = $_POST['filterlogentriesinterfaces'];
55
	if (isset($config['widgets']['filterlogentriesinterfaces'])) $config['widgets']['filterlogentriesinterfaces'] = trim($config['widgets']['filterlogentriesinterfaces']);
56

    
57
	write_config("Saved Filter Log Entries via Dashboard");
58
	$filename = $_SERVER['HTTP_REFERER'];
59
	if(headers_sent($file, $line)){
60
		echo "<script type=\"text/javascript\">\n";
61
		echo "//<![CDATA[\n";
62
		echo "window.location.href=\"" . $filename . "\";\n";
63
		echo "//]]>\n";
64
		echo "</script>\n";
65
		echo "<noscript>\n";
66
		echo "<meta http-equiv=\"refresh\" content=\"0;url=" . $filename . "\" />\n";
67
		echo "</noscript>\n";
68
	}
69
	header("Location: /");
70
}
71

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

    
74
//set variables for log
75

    
76
$nentriesacts       = isset($config['widgets']['filterlogentriesacts'])       ? $config['widgets']['filterlogentriesacts']       : 'All';
77
$nentriesinterfaces = isset($config['widgets']['filterlogentriesinterfaces']) ? $config['widgets']['filterlogentriesinterfaces'] : 'All';
78

    
79
$filterfieldsarray = array("act", "interface");
80
$filterfieldsarray['act'] = $nentriesacts;
81
$filterfieldsarray['interface'] = $nentriesinterfaces;
82

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

    
86
/* AJAX related routines */
87
handle_ajax($nentries, $nentries + 20);
88

    
89
?>
90

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

    
101
<?php
102
if(isset($config['syslog']['reverse']))
103
	echo "var isReverse = true;\n";
104
else
105
	echo "var isReverse = false;\n";
106
?>
107

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

    
116
	var nentriesacts = "<?php echo $nentriesacts; ?>";
117
	var nentriesinterfaces = "<?php echo $nentriesinterfaces; ?>";
118

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

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

    
125
	return line;
126
}
127
//]]>
128
</script>
129
<script src="/javascript/filter_log.js" type="text/javascript"></script>
130
<input type="hidden" id="log-config" name="log-config" value="" />
131

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

    
141
<?php
142
		$Include_Act = explode(",", str_replace(" ", ",", $nentriesacts));
143
		if ($nentriesinterfaces == "All") $nentriesinterfaces = "";
144
?>
145
		<input id="actpass"   name="actpass"   type="checkbox" value="Pass"   <?php if (in_arrayi('Pass',   $Include_Act)) echo "checked=\"checked\""; ?> /> Pass
146
		<input id="actblock"  name="actblock"  type="checkbox" value="Block"  <?php if (in_arrayi('Block',  $Include_Act)) echo "checked=\"checked\""; ?> /> Block
147
		<input id="actreject" name="actreject" type="checkbox" value="Reject" <?php if (in_arrayi('Reject', $Include_Act)) echo "checked=\"checked\""; ?> /> Reject
148
		<br />
149
		Interfaces:
150
		<select id="filterlogentriesinterfaces" name="filterlogentriesinterfaces" class="formselect">
151
			<option value="All">ALL</option>
152
<?php
153
		$interfaces = get_configured_interface_with_descr();
154
		foreach ($interfaces as $iface => $ifacename):
155
?>
156
			<option value="<?=$iface;?>" <?php if ($nentriesinterfaces == $iface) echo "selected=\"selected\"";?>>
157
				<?=htmlspecialchars($ifacename);?>
158
			</option>
159
<?php
160
		endforeach;
161
?>
162
		</select>
163

    
164
		<input id="submita" name="submita" type="submit" class="formbtn" value="Save" />
165
	</form>
166
</div>
167

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

    
216
<!-- needed to display the widget settings menu -->
217
<script type="text/javascript">
218
//<![CDATA[
219
	selectIntLink = "log-configure";
220
	textlink = document.getElementById(selectIntLink);
221
	textlink.style.display = "inline";
222
//]]>
223
</script>
(11-11/21)