summaryrefslogtreecommitdiffstats
path: root/usr/local/www/widgets/widgets/log.widget.php
blob: 61c2acf5eaa8e8622d6120ada82b8e245ee43e64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
/*
        $Id$
        Copyright 2007 Scott Dale
        Part of pfSense widgets (www.pfsense.com)
        originally based on m0n0wall (http://m0n0.ch/wall)

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

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

        1. Redistributions of source code must retain the above copyright notice,
           this list of conditions and the following disclaimer.

        2. Redistributions in binary form must reproduce the above copyright
           notice, this list of conditions and the following disclaimer in the
           documentation and/or other materials provided with the distribution.

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

$nocsrf = true;

require_once("guiconfig.inc");
require_once("pfsense-utils.inc");
require_once("functions.inc");

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

if($_POST['filterlogentries']) {
	unset($config['widgets']['filterlogentries']);
	if( ($_POST['filterlogentries']) and ($_POST['filterlogentries'] != ' ') ) $config['widgets']['filterlogentries'] = $_POST['filterlogentries'];

	unset($config['widgets']['filterlogentriesacts']);
	if($_POST['actpass'])   $config['widgets']['filterlogentriesacts'] .= $_POST['actpass']   . " ";
	if($_POST['actblock'])  $config['widgets']['filterlogentriesacts'] .= $_POST['actblock']  . " ";
	if($_POST['actreject']) $config['widgets']['filterlogentriesacts'] .= $_POST['actreject'] . " ";
	if (isset($config['widgets']['filterlogentriesacts'])) $config['widgets']['filterlogentriesacts'] = trim($config['widgets']['filterlogentriesacts']);

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

	write_config("Saved Filter Log Entries via Dashboard");
  $filename = $_SERVER['HTTP_REFERER'];
  if(headers_sent($file, $line)){
    echo '<script type="text/javascript">';
    echo 'window.location.href="'.$filename.'";';
    echo '</script>';
    echo '<noscript>';
    echo '<meta http-equiv="refresh" content="0;url='.$filename.'" />';
    echo '</noscript>';  
  } 
	Header("Location: /");
}

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

//set variables for log

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

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

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

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

?>

<script language="javascript">
lastsawtime = '<?php echo time(); ?>';
var lines = Array();
var timer;
var updateDelay = 30000;
var isBusy = false;
var isPaused = false;
var nentries = <?php echo $nentries; ?>;

<?php
if(isset($config['syslog']['reverse']))
	echo "var isReverse = true;\n";
else
	echo "var isReverse = false;\n";
?>

/* Called by the AJAX updater */
function format_log_line(row) {
	var line = '<td class="listMRlr" align="center">' + row[0] + '</td>' +
		'<td class="listMRr ellipsis" title="' + row[2] + '">' + row[2] + '</td>' +
		'<td class="listMRr ellipsis" title="' + row[3] + '">' + row[3] + '</td>' +
		'<td class="listMRr ellipsis" title="' + row[4] + '">' + row[4] + '</td>' +
		'<td class="listMRr ellipsis" title="' + row[5] + '">' + row[5] + '</td>';

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

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

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

	return line;
}
</script>
<script src="/javascript/filter_log.js" type="text/javascript"></script>
<input type="hidden" id="log-config" name="log-config" value="">

<div id="log-settings" name="log-settings" class="widgetconfigdiv" style="display:none;">
	<form action="/widgets/widgets/log.widget.php" method="post" name="iforma">
		Number of lines to display: 
		<select name="filterlogentries" class="formfld unknown" id="filterlogentries">
		<?php for ($i = 0; $i <= 20; $i++) { ?>
			<option value="<?php if ($i > 0) echo $i; else echo ' ';?>" <?php if ($nentries == $i) echo "SELECTED";?>><?php if ($i > 0) echo ' ' . $i; else echo ' ';?></option>
		<?php } ?>
		</select>

<?php 
		$Include_Act = explode(",", str_replace(" ", ",", $nentriesacts));
		if ($nentriesinterfaces == "All") $nentriesinterfaces = "";
?>
		<input id="actpass"   name="actpass"   type="checkbox" value="Pass"   <?php if (in_arrayi('Pass',   $Include_Act)) echo "checked"; ?> /> Pass
		<input id="actblock"  name="actblock"  type="checkbox" value="Block"  <?php if (in_arrayi('Block',  $Include_Act)) echo "checked"; ?> /> Block
		<input id="actreject" name="actreject" type="checkbox" value="Reject" <?php if (in_arrayi('Reject', $Include_Act)) echo "checked"; ?> /> Reject
		<br/>
		Interfaces: 
		<input id="filterlogentriesinterfaces" name="filterlogentriesinterfaces" class="formfld unknown" type="text" size="20" class="formfld unknown" value="<?= $nentriesinterfaces ?>" />
        &nbsp &nbsp &nbsp 

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

<table width="100%" border="0" cellpadding="0" cellspacing="0" style="table-layout: fixed;">
	<colgroup>
		<col style='width: 8%;' />
		<col style='width: 10%;' />
		<col style='width: 35%;' />
		<col style='width: 35%;' />
		<col style='width: 12%;' />
	</colgroup>
	<thead>
		<tr>
			<td class="listhdrr"><?=gettext("Act");?></td>
			<td class="listhdrr"><?=gettext("IF");?></td>
			<td class="listhdrr"><?=gettext("Source");?></td>
			<td class="listhdrr"><?=gettext("Destination");?></td>
			<td class="listhdrr"><?=gettext("Prot");?></td>
		</tr>
	</thead>
	<tbody id='filter-log-entries'>
	<?php
	$rowIndex = 0;
	foreach ($filterlog as $filterent):
	$evenRowClass = $rowIndex % 2 ? " listMReven" : " listMRodd";
	$rowIndex++;
	?>
		<tr class="<?=$evenRowClass?>">
			<td class="listMRlr" nowrap="nowrap" align="center">
			<a href="#" onclick="javascript:getURL('diag_logs_filter.php?getrulenum=<?php echo "{$filterent['rulenum']},{$filterent['act']}"; ?>', outputrule);">
			<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'];?>" />
			</a>
			</td>
			<td class="listMRr ellipsis" nowrap="nowrap" title="<?php echo htmlspecialchars($filterent['interface']);?>"><?php echo htmlspecialchars($filterent['interface']);?></td>
			<td class="listMRr ellipsis" nowrap="nowrap" title="<?php echo htmlspecialchars($filterent['src']);?>"><?php echo htmlspecialchars($filterent['src']);?></td>
			<td class="listMRr ellipsis" nowrap="nowrap" title="<?php echo htmlspecialchars($filterent['dst']);?>"><?php echo htmlspecialchars($filterent['dst']);?></td>
			<?php
				if ($filterent['proto'] == "TCP")
					$filterent['proto'] .= ":{$filterent['tcpflags']}";
			?>
			<td class="listMRr ellipsis" nowrap="nowrap" title="<?php echo htmlspecialchars($filterent['proto']);?>"><?php echo htmlspecialchars($filterent['proto']);?></td>
		</tr>
	<?php endforeach; ?>
	</tbody>
</table>

<!-- needed to display the widget settings menu -->
<script language="javascript" type="text/javascript">
	selectIntLink = "log-configure";
	textlink = document.getElementById(selectIntLink);
	textlink.style.display = "inline";
</script>
OpenPOWER on IntegriCloud