Projet

Général

Profil

Télécharger (10 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / widgets / widgets / log.widget.php @ 6f3d2063

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
                        <option value="<?=$iface;?>" <?php if ($nentriesinterfaces == $iface) echo "selected=\"selected\"";?>>
156
                      <?=htmlspecialchars($ifacename);?>
157
                      </option>
158
                      <?php endforeach; ?>
159
                    </select>
160

    
161
		<input id="submita" name="submita" type="submit" class="formbtn" value="Save" />
162
	</form>
163
</div>
164

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

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