Project

General

Profile

Download (12.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	diag_logs.php
4
*/
5
/* ====================================================================
6
 *  Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *
8
 *  Some or all of this file is based on the m0n0wall project which is
9
 *  Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
10
 *
11
 *  Redistribution and use in source and binary forms, with or without modification,
12
 *  are permitted provided that the following conditions are met:
13
 *
14
 *  1. Redistributions of source code must retain the above copyright notice,
15
 *      this list of conditions and the following disclaimer.
16
 *
17
 *  2. Redistributions in binary form must reproduce the above copyright
18
 *      notice, this list of conditions and the following disclaimer in
19
 *      the documentation and/or other materials provided with the
20
 *      distribution.
21
 *
22
 *  3. All advertising materials mentioning features or use of this software
23
 *      must display the following acknowledgment:
24
 *      "This product includes software developed by the pfSense Project
25
 *       for use in the pfSense software distribution. (http://www.pfsense.org/).
26
 *
27
 *  4. The names "pfSense" and "pfSense Project" must not be used to
28
 *       endorse or promote products derived from this software without
29
 *       prior written permission. For written permission, please contact
30
 *       coreteam@pfsense.org.
31
 *
32
 *  5. Products derived from this software may not be called "pfSense"
33
 *      nor may "pfSense" appear in their names without prior written
34
 *      permission of the Electric Sheep Fencing, LLC.
35
 *
36
 *  6. Redistributions of any form whatsoever must retain the following
37
 *      acknowledgment:
38
 *
39
 *  "This product includes software developed by the pfSense Project
40
 *  for use in the pfSense software distribution (http://www.pfsense.org/).
41
 *
42
 *  THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
43
 *  EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45
 *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
46
 *  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
 *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50
 *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
 *  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53
 *  OF THE POSSIBILITY OF SUCH DAMAGE.
54
 *
55
 *  ====================================================================
56
 *
57
 */
58

    
59
/*
60
	pfSense_MODULE:	system
61
*/
62

    
63
##|+PRIV
64
##|*IDENT=page-diagnostics-logs-system
65
##|*NAME=Status: Logs: System
66
##|*DESCR=Allow access to the 'Status: System Logs: General' page.
67
##|*MATCH=diag_logs.php
68
##|-PRIV
69

    
70
require("guiconfig.inc");
71
require_once("filter_log.inc");
72

    
73
/*
74
Build a list of allowed log files so we can reject others to prevent the page
75
from acting on unauthorized files.
76
*/
77
$allowed_logs = array(
78
	"system" => array("name" => "General",
79
		    "shortcut" => ""),
80
	"dhcpd" => array("name" => "DHCP",
81
		    "shortcut" => "dhcp"),
82
	"portalauth" => array("name" => "Captive Portal Authentication",
83
		    "shortcut" => "captiveportal"),
84
	"ipsec" => array("name" => "IPsec",
85
		    "shortcut" => "ipsec"),
86
	"ppp" => array("name" => "PPP",
87
		    "shortcut" => ""),
88
	"relayd" => array("name" => "Load Balancer",
89
		    "shortcut" => "relayd"),
90
	"openvpn" => array("name" => "OpenVPN",
91
		    "shortcut" => "openvpn"),
92
	"ntpd" => array("name" => "NTPd",
93
		    "shortcut" => "ntp"),
94
	"gateways" => array("name" => "Gateways",
95
		    "shortcut" => "gateways"),
96
	"routing" => array("name" => "Routing",
97
		    "shortcut" => "routing"),
98
	"resolver" => array("name" => "DNS Resolver",
99
		    "shortcut" => "resolver"),
100
	"wireless" => array("name" => "Wireless",
101
		    "shortcut" => "wireless"),
102
);
103

    
104
// The logs to display are specified in a GET argument. Default to 'system' logs
105
if (!$_GET['logfile']) {
106
	$logfile = 'system';
107
} else {
108
	$logfile = $_GET['logfile'];
109
	if (!array_key_exists($logfile, $allowed_logs)) {
110
		/* Do not let someone attempt to load an unauthorized log. */
111
		$logfile = 'system';
112
	}
113
}
114

    
115
function getGETPOSTsettingvalue($settingname, $default) {
116
	$settingvalue = $default;
117
	if ($_GET[$settingname]) {
118
		$settingvalue = $_GET[$settingname];
119
	}
120
	if ($_POST[$settingname]) {
121
		$settingvalue = $_POST[$settingname];
122
	}
123
	return $settingvalue;
124
}
125

    
126
$filtersubmit = getGETPOSTsettingvalue('filtersubmit', null);
127

    
128
if ($filtersubmit) {
129
	$filtertext = getGETPOSTsettingvalue('filtertext', "");
130
	$filterlogentries_qty = getGETPOSTsettingvalue('filterlogentries_qty', null);
131
}
132

    
133
$filterlogentries_submit = getGETPOSTsettingvalue('filterlogentries_submit', null);
134

    
135
if ($filterlogentries_submit) {
136
	$filterfieldsarray = array();
137

    
138
	$filterfieldsarray['time'] = getGETPOSTsettingvalue('filterlogentries_time', null);
139
	$filterfieldsarray['process'] = getGETPOSTsettingvalue('filterlogentries_process', null);
140
	$filterfieldsarray['pid'] = getGETPOSTsettingvalue('filterlogentries_pid', null);
141
	$filterfieldsarray['message'] = getGETPOSTsettingvalue('filterlogentries_message', null);
142
	$filterlogentries_qty = getGETPOSTsettingvalue('filterlogentries_qty', null);
143
}
144

    
145
$system_logfile = "{$g['varlog_path']}/" . basename($logfile) . ".log";
146

    
147
$nentries = $config['syslog']['nentries'];
148

    
149
# Override Display Quantity
150
if ($filterlogentries_qty) {
151
	$nentries = $filterlogentries_qty;
152
}
153

    
154
if (!$nentries || !is_numeric($nentries)) {
155
	$nentries = 50;
156
}
157

    
158
if ($_POST['clear']) {
159
	clear_log_file($system_logfile);
160
}
161

    
162
if ($filtertext) {
163
	$filtertextmeta="?filtertext=$filtertext";
164
}
165

    
166
/* Setup shortcuts if they exist */
167

    
168
if (!empty($allowed_logs[$logfile]["shortcut"])) {
169
	$shortcut_section = $allowed_logs[$logfile]["shortcut"];
170
}
171

    
172
$pgtitle = array(gettext("Status"), gettext("System logs"), gettext($allowed_logs[$logfile]["name"]));
173
include("head.inc");
174

    
175
$tab_array = array();
176
$tab_array[] = array(gettext("System"), ($logfile == 'system'), "diag_logs.php");
177
$tab_array[] = array(gettext("Firewall"), false, "diag_logs_filter.php");
178
$tab_array[] = array(gettext("DHCP"), ($logfile == 'dhcpd'), "diag_logs.php?logfile=dhcpd");
179
$tab_array[] = array(gettext("Portal Auth"), ($logfile == 'portalauth'), "diag_logs.php?logfile=portalauth");
180
$tab_array[] = array(gettext("IPsec"), ($logfile == 'ipsec'), "diag_logs.php?logfile=ipsec");
181
$tab_array[] = array(gettext("PPP"), ($logfile == 'ppp'), "diag_logs.php?logfile=ppp");
182
$tab_array[] = array(gettext("VPN"), false, "diag_logs_vpn.php");
183
$tab_array[] = array(gettext("Load Balancer"), ($logfile == 'relayd'), "diag_logs.php?logfile=relayd");
184
$tab_array[] = array(gettext("OpenVPN"), ($logfile == 'openvpn'), "diag_logs.php?logfile=openvpn");
185
$tab_array[] = array(gettext("NTP"), ($logfile == 'ntpd'), "diag_logs.php?logfile=ntpd");
186
$tab_array[] = array(gettext("Settings"), false, "diag_logs_settings.php");
187
display_top_tabs($tab_array);
188

    
189
$tab_array = array();
190
if (in_array($logfile, array('system', 'gateways', 'routing', 'resolver', 'wireless')))	 {
191
	$tab_array[] = array(gettext("General"), ($logfile == 'system'), "/diag_logs.php");
192
	$tab_array[] = array(gettext("Gateways"), ($logfile == 'gateways'), "/diag_logs.php?logfile=gateways");
193
	$tab_array[] = array(gettext("Routing"), ($logfile == 'routing'), "/diag_logs.php?logfile=routing");
194
	$tab_array[] = array(gettext("Resolver"), ($logfile == 'resolver'), "/diag_logs.php?logfile=resolver");
195
	$tab_array[] = array(gettext("Wireless"), ($logfile == 'wireless'), "/diag_logs.php?logfile=wireless");
196
	display_top_tabs($tab_array, false, 'nav nav-tabs');
197
}
198

    
199
if (!isset($config['syslog']['rawfilter'])) { // Advanced log filter form
200
	$form = new Form(false);
201

    
202
	$section = new Form_Section('Advanced Log Filter', 'adv-filter-panel', true);
203

    
204
	$group = new Form_Group('');
205

    
206
	$group->add(new Form_Input(
207
		'filterlogentries_time',
208
		null,
209
		'text',
210
		$filterfieldsarray['time']
211
	))->setHelp('Time');
212

    
213
	$group->add(new Form_Input(
214
		'filterlogentries_process',
215
		null,
216
		'text',
217
		$filterfieldsarray['process']
218
	))->setHelp('Process');
219

    
220
	$group->add(new Form_Input(
221
		'filterlogentries_pid',
222
		null,
223
		'number',
224
		$filterfieldsarray['pid']
225
	))->setHelp('PID');
226

    
227
	$group->add(new Form_Input(
228
		'filterlogentries_qty',
229
		null,
230
		'number',
231
		$filterlogentries_qty,
232
		['placeholder' => $nentries]
233
	))->setHelp('Quantity');
234

    
235
	$section->add($group);
236

    
237
	$group = new Form_Group('');
238

    
239
	$group->add(new Form_Input(
240
		'filterlogentries_message',
241
		null,
242
		'text',
243
		$filterfieldsarray['message']
244
	))->setHelp('Log Message');
245

    
246
	$btnsubmit = new Form_Button(
247
		'filterlogentries_submit',
248
		' ' . 'Apply Filter',
249
		null,
250
		'fa-filter'
251
	);
252
}
253
else { // Simple log filter form
254
	$form = new Form(false);
255

    
256
	$section = new Form_Section('Log Filter', 'basic-filter-panel', true);
257

    
258
	$group = new Form_Group('');
259

    
260
	$group->add(new Form_Input(
261
		'filtertext',
262
		null,
263
		'text',
264
		$filtertext
265
	))->setHelp('Filter Expression');
266

    
267
	$group->add(new Form_Input(
268
		'filterlogentries_qty',
269
		null,
270
		'number',
271
		$filterlogentries_qty,
272
		['placeholder' => $nentries]
273
	))->setHelp('Quantity');
274

    
275
	$btnsubmit = new Form_Button(
276
		'filtersubmit',
277
		' ' . 'Apply Filter',
278
		null,
279
		'fa-filter'
280
	);
281
}
282

    
283
$btnsubmit->removeClass('btn-primary')->addClass('btn-success')->addClass('btn-sm');
284

    
285
$group->add(new Form_StaticText(
286
	'',
287
	$btnsubmit
288
));
289

    
290
$group->setHelp('<a target="_blank" href="http://www.php.net/manual/en/book.pcre.php">' . 'Regular expression reference</a> Precede with exclamation (!) to exclude match.');
291
$section->add($group);
292
$form->add($section);
293
print $form;
294

    
295
// Now the forms are complete we can draw the log table and its controls
296
if (!isset($config['syslog']['rawfilter'])) {
297
	if ($filterlogentries_submit)
298
		$filterlog = conv_log_filter($system_logfile, $nentries, $nentries + 100, $filterfieldsarray);
299
	else
300
		$filterlog = conv_log_filter($system_logfile, $nentries, $nentries + 100, $filtertext);
301
?>
302

    
303
<div class="panel panel-default">
304
	<div class="panel-heading">
305
		<h2 class="panel-title">
306
<?php
307
	if ((!$filtertext) && (!$filterfieldsarray))
308
		printf(gettext("Last %d %s log entries."), count($filterlog), $logfile);
309
	else
310
		printf(gettext("%d matched %s log entries."), count($filterlog), $logfile);
311

    
312
	printf(gettext(" (Maximum %d)"), $nentries);
313
?>
314
		</h2>
315
	</div>
316
	<div class="panel-body">
317
	   <div class="table-responsive">
318
		<table class="table table-striped table-hover table-compact">
319
			<tr>
320
				<th><?=gettext("Time")?></th>
321
				<th><?=gettext("Process")?></th>
322
				<th><?=gettext("PID")?></th>
323
				<th style="width:100%"><?=gettext("Log Message")?></th>
324
			</tr>
325
<?php
326
	foreach ($filterlog as $filterent) {
327
?>
328
			<tr>
329
				<td style="white-space:nowrap;">
330
					<?=htmlspecialchars($filterent['time'])?>
331
				</td>
332
				<td style="white-space:nowrap;">
333
					<?=htmlspecialchars($filterent['process'])?>
334
				</td>
335
				<td style="white-space:nowrap;">
336
					<?=htmlspecialchars($filterent['pid'])?>
337
				</td>
338
				<td style="word-wrap:break-word; word-break:break-all; white-space:normal">
339
					<?=htmlspecialchars($filterent['message'])?>
340
				</td>
341
			</tr>
342
<?php
343
	} // e-o-foreach
344
?>
345
		</table>
346
		</div>
347
	</div>
348
</div>
349
<?php
350
	if (count($filterlog) == 0)
351
		print_info_box('No logs to display');
352
}
353
else
354
{
355
?>
356
<div class="panel panel-default">
357
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Last ")?><?=$nentries?> <?=$logfile?><?=gettext(" log entries")?></h2></div>
358
	<div class="table table-responsive">
359
		<table class="table table-striped table-hover">
360
			<thead>
361
				<tr>
362
					<th class="col-sm-2"></th>
363
					<th></th>
364
				</tr>
365
			</thead>
366
			<tbody>
367
<?php
368
	if (($logfile == 'resolver') || ($logfile == 'system'))
369
		$inverse = array("ppp");
370
	else
371
		$inverse = null;
372

    
373
	if ($filtertext)
374
		$rows = dump_clog($system_logfile, $nentries, true, array("$filtertext"), $inverse);
375
	else
376
		$rows = dump_clog($system_logfile, $nentries, true, array(), $inverse);
377
?>
378
			</tbody>
379
		</table>
380
	</div>
381
</div>
382
<?php
383
	if ($rows == 0)
384
		print_info_box('No logs to display');
385
}
386
?>
387

    
388
<?php
389
$form = new Form(false);
390

    
391
$section = new Form_Section('Manage Log', 'log-manager-panel', true);
392

    
393
$group = new Form_Group('');
394

    
395
$btnclear = new Form_Button(
396
	'clear',
397
	' ' . 'Clear log',
398
	null,
399
	'fa-trash'
400
);
401

    
402
$btnclear->removeClass('btn-primary')->addClass('btn-danger')->addClass('btn-sm');
403

    
404
if ($logfile == 'dhcpd')
405
	print_info_box('Warning: Clearing the log file will restart the DHCP daemon.');
406

    
407
$group->add(new Form_StaticText(
408
	'',
409
	$btnclear
410
));
411

    
412
$section->add($group);
413
$form->add($section);
414
print $form;
415
?>
416

    
417
<?php include("foot.inc"); ?>
(20-20/228)