Project

General

Profile

« Previous | Next » 

Revision 76af8cdb

Added by NOYB NOYB over 9 years ago

Status - System Logs - Manage Log

Build up th manage log section with options to override the "General Logging Options" settings on an individual log basis.
Remove over exuberant gettext's.
Set/adjust filter form field widths to be better fitting for the field types.
Open/Close filter form based on filtering state.

View differences:

src/usr/local/www/diag_logs.php
112 112
	}
113 113
}
114 114

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

  
117

  
115 118
function getGETPOSTsettingvalue($settingname, $default) {
116 119
	$settingvalue = $default;
117 120
	if ($_GET[$settingname]) {
......
123 126
	return $settingvalue;
124 127
}
125 128

  
129

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

  
128 132
if ($filtersubmit) {
133
	$filter_active = true;
129 134
	$filtertext = getGETPOSTsettingvalue('filtertext', "");
130 135
	$filterlogentries_qty = getGETPOSTsettingvalue('filterlogentries_qty', null);
131 136
}
......
133 138
$filterlogentries_submit = getGETPOSTsettingvalue('filterlogentries_submit', null);
134 139

  
135 140
if ($filterlogentries_submit) {
141
	$filter_active = true;
136 142
	$filterfieldsarray = array();
137 143

  
138 144
	$filterfieldsarray['time'] = getGETPOSTsettingvalue('filterlogentries_time', null);
......
142 148
	$filterlogentries_qty = getGETPOSTsettingvalue('filterlogentries_qty', null);
143 149
}
144 150

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

  
147
$nentries = $config['syslog']['nentries'];
152
# Manage Log - Code
153

  
154
$specific_log = basename($logfile) . '_settings';
155

  
156
$pconfig['cronorder'] = $config['syslog'][$specific_log]['cronorder'];
157
$pconfig['nentries'] = $config['syslog'][$specific_log]['nentries'];
158
$pconfig['logfilesize'] = $config['syslog'][$specific_log]['logfilesize'];
159
$pconfig['format'] = $config['syslog'][$specific_log]['format'];
160
$pconfig['loglighttpd'] = !isset($config['syslog']['nologlighttpd']);
161

  
162
$save_settings = getGETPOSTsettingvalue('save_settings', null);
163

  
164
if ($save_settings) {
165
	$cronorder = getGETPOSTsettingvalue('cronorder',  null);
166
	$nentries = getGETPOSTsettingvalue('nentries', null);
167
	$logfilesize = getGETPOSTsettingvalue('logfilesize', null);
168
	$format  = getGETPOSTsettingvalue('format',  null);
169
	$loglighttpd  = getGETPOSTsettingvalue('loglighttpd',  null);
170

  
171
	unset($input_errors);
172
	$pconfig = $_POST;
173

  
174
	/* input validation */
175
	if (isset($nentries) && (strlen($nentries) > 0)) {
176
		if (!is_numeric($nentries) || ($nentries < 5) || ($nentries > 2000)) {
177
			$input_errors[] = gettext("Number of log entries to show must be between 5 and 2000.");
178
		}
179
	}
180

  
181
	if (isset($logfilesize) && (strlen($logfilesize) > 0)) {
182
		if (!is_numeric($logfilesize) || ($logfilesize < 100000)) {
183
			$input_errors[] = gettext("Log file size must be numeric and greater than or equal to 100000.");
184
		}
185
	}
186

  
187
	if (!$input_errors) {
188

  
189
		# Clear out the specific log settings and leave only the applied settings to override the general logging options (global) settings.
190
		unset($config['syslog'][$specific_log]);
191

  
192
		if ($cronorder != '') { # if not using the general logging options setting (global)
193
			$config['syslog'][$specific_log]['cronorder'] = $cronorder;
194
		}
195

  
196
		if (isset($nentries) && (strlen($nentries) > 0)) {
197
			$config['syslog'][$specific_log]['nentries'] = (int)$nentries;
198
		}
199

  
200
		if (isset($logfilesize) && (strlen($logfilesize) > 0)) {
201
			$config['syslog'][$specific_log]['logfilesize'] = (int)$logfilesize;
202
		}
203

  
204
		if ($format != '') { # if not using the general logging options setting (global)
205
			$config['syslog'][$specific_log]['format'] = $format;
206
		}
207

  
208
		$oldnologlighttpd = isset($config['syslog']['nologlighttpd']);
209
		if ($logfile == 'system') {
210
			$config['syslog']['nologlighttpd'] = $loglighttpd ? false : true;
211
		}
212

  
213
		write_config();
214

  
215
		$retval = 0;
216
		$savemsg = get_std_save_message($retval);
217

  
218
		if ($oldnologlighttpd !== isset($config['syslog']['nologlighttpd'])) {
219
			ob_flush();
220
			flush();
221
			log_error(gettext("webConfigurator configuration has changed. Restarting webConfigurator."));
222
			send_event("service restart webgui");
223
			$savemsg .= "<br />" . gettext("WebGUI process is restarting.");
224
		}
225
	}
226
}
227

  
228

  
229
# Formatted/Raw Display
230
if ($config['syslog'][$specific_log]['format'] == 'formatted') {
231
	$rawfilter = false;
232
}
233
else if ($config['syslog'][$specific_log]['format'] == 'raw') {
234
	$rawfilter = true;
235
}	
236
else {	# Use the general logging options setting (global).
237
	$rawfilter = isset($config['syslog']['rawfilter']);
238
}
239

  
240

  
241
isset($config['syslog'][$specific_log]['nentries']) ? $nentries = $config['syslog'][$specific_log]['nentries'] : $nentries = $config['syslog']['nentries'];
148 242

  
149 243
# Override Display Quantity
150 244
if ($filterlogentries_qty) {
......
172 266
$pgtitle = array(gettext("Status"), gettext("System logs"), gettext($allowed_logs[$logfile]["name"]));
173 267
include("head.inc");
174 268

  
269
if (!$input_errors && $savemsg) {
270
	print_info_box($savemsg);
271
	$manage_log_active = false;
272
}
273

  
175 274
$tab_array = array();
176 275
$tab_array[] = array(gettext("System"), ($logfile == 'system'), "diag_logs.php");
177 276
$tab_array[] = array(gettext("Firewall"), false, "diag_logs_filter.php");
......
196 295
	display_top_tabs($tab_array, false, 'nav nav-tabs');
197 296
}
198 297

  
199
if (!isset($config['syslog']['rawfilter'])) { // Advanced log filter form
298
define(SEC_OPEN, 0x00);
299
define(SEC_CLOSED, 0x04);
300

  
301
if ($filter_active)
302
	$filter_state = SEC_OPEN;
303
else
304
	$filter_state = SEC_CLOSED;
305

  
306
if (!$rawfilter) { // Advanced log filter form
200 307
	$form = new Form(false);
201 308

  
202
	$section = new Form_Section(gettext('Advanced Log Filter'), 'adv-filter-panel', true);
309
	$section = new Form_Section('Advanced Log Filter', 'adv-filter-panel', COLLAPSIBLE|$filter_state);
203 310

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

  
......
208 315
		null,
209 316
		'text',
210 317
		$filterfieldsarray['time']
211
	))->setHelp(gettext('Time'));
318
	))->setWidth(3)->setHelp('Time');
212 319

  
213 320
	$group->add(new Form_Input(
214 321
		'filterlogentries_process',
215 322
		null,
216 323
		'text',
217 324
		$filterfieldsarray['process']
218
	))->setHelp(gettext('Process'));
325
	))->setWidth(2)->setHelp('Process');
219 326

  
220 327
	$group->add(new Form_Input(
221 328
		'filterlogentries_pid',
222 329
		null,
223 330
		'text',
224 331
		$filterfieldsarray['pid']
225
	))->setHelp(gettext('PID'));
332
	))->setWidth(2)->setHelp('PID');
226 333

  
227 334
	$group->add(new Form_Input(
228 335
		'filterlogentries_qty',
......
230 337
		'number',
231 338
		$filterlogentries_qty,
232 339
		['placeholder' => $nentries]
233
	))->setHelp(gettext('Quantity'));
340
	))->setWidth(2)->setHelp('Quantity');
234 341

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

  
......
241 348
		null,
242 349
		'text',
243 350
		$filterfieldsarray['message']
244
	))->setHelp(gettext('Log Message'));
351
	))->setWidth(7)->setHelp('Message');
245 352

  
246 353
	$btnsubmit = new Form_Button(
247 354
		'filterlogentries_submit',
......
253 360
else { // Simple log filter form
254 361
	$form = new Form(false);
255 362

  
256
	$section = new Form_Section(gettext('Log Filter'), 'basic-filter-panel', true);
363
	$section = new Form_Section('Log Filter', 'basic-filter-panel', COLLAPSIBLE|$filter_state);
257 364

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

  
......
262 369
		null,
263 370
		'text',
264 371
		$filtertext
265
	))->setHelp(gettext('Filter Expression'));
372
	))->setWidth(6)->setHelp('Filter Expression');
266 373

  
267 374
	$group->add(new Form_Input(
268 375
		'filterlogentries_qty',
......
270 377
		'number',
271 378
		$filterlogentries_qty,
272 379
		['placeholder' => $nentries]
273
	))->setHelp(gettext('Quantity'));
380
	))->setWidth(2)->setHelp('Quantity');
274 381

  
275 382
	$btnsubmit = new Form_Button(
276 383
		'filtersubmit',
......
293 400
print $form;
294 401

  
295 402
// Now the forms are complete we can draw the log table and its controls
296
if (!isset($config['syslog']['rawfilter'])) {
403
if (!$rawfilter) {
297 404
	if ($filterlogentries_submit)
298 405
		$filterlog = conv_log_filter($system_logfile, $nentries, $nentries + 100, $filterfieldsarray);
299 406
	else
......
305 412
		<h2 class="panel-title">
306 413
<?php
307 414
	if ((!$filtertext) && (!$filterfieldsarray))
308
		printf(gettext("Last %d %s log entries."), count($filterlog), $logfile);
415
		printf(gettext("Last %d %s log entries."), count($filterlog), gettext($allowed_logs[$logfile]["name"]));
309 416
	else
310
		printf(gettext("%d matched %s log entries."), count($filterlog), $logfile);
417
		printf(gettext("%d matched %s log entries."), count($filterlog), gettext($allowed_logs[$logfile]["name"]));
311 418

  
312
	printf(gettext(" (Maximum %d)"), $nentries);
419
	printf(" (" . gettext("Maximum %d") . ")", $nentries);
313 420
?>
314 421
		</h2>
315 422
	</div>
......
343 450
	} // e-o-foreach
344 451
?>
345 452
		</table>
453
<?php
454
	if (count($filterlog) == 0)
455
		print_info_box(gettext('No logs to display'));
456
?>
346 457
		</div>
347 458
	</div>
348 459
</div>
349 460
<?php
350
	if (count($filterlog) == 0)
351
		print_info_box(gettext('No logs to display'));
352 461
}
353 462
else
354 463
{
355 464
?>
356 465
<div class="panel panel-default">
357
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Last ")?><?=$nentries?> <?=$logfile?><?=gettext(" log entries")?></h2></div>
466
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Last ")?><?=$nentries?> <?=gettext($allowed_logs[$logfile]["name"])?><?=gettext(" log entries")?></h2></div>
358 467
	<div class="table table-responsive">
359 468
		<table class="table table-striped table-hover">
360 469
			<thead>
......
377 486
?>
378 487
			</tbody>
379 488
		</table>
380
	</div>
381
</div>
382 489
<?php
383 490
	if ($rows == 0)
384 491
		print_info_box(gettext('No logs to display'));
492
?>
493
	</div>
494
</div>
495
<?php
385 496
}
386 497
?>
387 498

  
388 499
<?php
500
# Manage Log - Section/Form
501

  
502
if ($input_errors) {
503
	print_input_errors($input_errors);
504
	$manage_log_active = true;
505
}
506

  
507
if ($manage_log_active)
508
	$manage_log_state = SEC_OPEN;
509
else
510
	$manage_log_state = SEC_CLOSED;
511

  
389 512
$form = new Form(false);
390 513

  
391
$section = new Form_Section(gettext('Manage Log'), 'log-manager-panel', true);
514
$section = new Form_Section(gettext('Manage') . ' ' . gettext($allowed_logs[$logfile]["name"]) . ' ' . gettext('Log'), 'log-manager-panel', COLLAPSIBLE|$manage_log_state);
515

  
516
$section->addInput(new Form_StaticText(
517
	'',
518
	'These settings override the "General Logging Options" settings.'
519
));
520

  
521
$group = new Form_Group('Forward/Reverse Display');
522

  
523
$group->add(new Form_Checkbox(
524
	'cronorder',
525
	null,
526
	'Forward',
527
	($pconfig['cronorder'] == 'forward') ? true : false,
528
	'forward'
529
))->displayAsRadio();
530

  
531
$group->add(new Form_Checkbox(
532
	'cronorder',
533
	null,
534
	'Reverse',
535
	($pconfig['cronorder'] == 'reverse') ? true : false,
536
	'reverse'
537
))->displayAsRadio();
538

  
539
$group->add(new Form_Checkbox(
540
	'cronorder',
541
	null,
542
	'General Logging Options Setting',
543
	($pconfig['cronorder'] == '') ? true : false,
544
	''
545
))->displayAsRadio();
546

  
547
$group->setHelp('Show log entries in forward (newest at bottom) or reverse (newest at top) order.');
548
$section->add($group);
549

  
550
$group = new Form_Group('GUI Log Entries');
392 551

  
393
$group = new Form_Group('');
552
# Use the general logging options setting (global) as placeholder.
553
$group->add(new Form_Input(
554
	'nentries',
555
	'GUI Log Entries',
556
	'number',
557
	$pconfig['nentries'],
558
	['placeholder' => $config['syslog']['nentries']]
559
))->setWidth(2);
560

  
561
$group->setHelp('This is the number of log entries displayed in the GUI. It does not affect how many entries are contained in the log.');
562
$section->add($group);
563

  
564
$group = new Form_Group('Log file size (Bytes)');
565

  
566
# Use the general logging options setting (global) as placeholder.
567
$group->add(new Form_Input(
568
	'logfilesize',
569
	'Log file size (Bytes)',
570
	'number',
571
	$pconfig['logfilesize'],
572
	['placeholder' => $config['syslog']['logfilesize'] ? $config['syslog']['logfilesize'] : "511488"]
573
))->setWidth(2);
574
$group->setHelp("The log is held in a constant-size circular log file. This field controls how large the log file is, and thus how many entries may exist inside the log. The default is approximately 500KB." .
575
					'<br /><br />' .
576
			"NOTE: The log size is changed the next time it is cleared. To immediately change the log size, first save the options to set the size, then clear the log using the \"Clear Log\" action below. ");
577
$section->add($group);
578

  
579
$group = new Form_Group('Formatted/Raw Display');
580

  
581
$group->add(new Form_Checkbox(
582
	'format',
583
	null,
584
	'Formatted',
585
	($pconfig['format'] == 'formatted') ? true : false,
586
	'formatted'
587
))->displayAsRadio();
588

  
589
$group->add(new Form_Checkbox(
590
	'format',
591
	null,
592
	'Raw',
593
	($pconfig['format'] == 'raw') ? true : false,
594
	'raw'
595
))->displayAsRadio();
596

  
597
$group->add(new Form_Checkbox(
598
	'format',
599
	null,
600
	'General Logging Options Setting',
601
	($pconfig['format'] == '') ? true : false,
602
	''
603
))->displayAsRadio();
604

  
605
$group->setHelp('Show the log entries as formated or raw output as generated by the service. The raw output will reveal more detailed information, but it is more difficult to read.');
606
$section->add($group);
607

  
608
if ($logfile == 'system') {
609
	$section->addInput(new Form_Checkbox(
610
		'loglighttpd',
611
		'Web Server Log',
612
		'Log errors from the web server process',
613
		$pconfig['loglighttpd']
614
	))->setHelp('If this is checked, errors from the lighttpd web server process for the GUI or Captive Portal will appear in the system log.');
615
}
616

  
617
$btnsavesettings = new Form_Button(
618
	'save_settings',
619
	gettext('Save'),
620
	null
621
);
622

  
623
$btnsavesettings->addClass('btn-sm');
394 624

  
395 625
$btnclear = new Form_Button(
396 626
	'clear',
......
401 631

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

  
404
if ($logfile == 'dhcpd')
405
	print_info_box(gettext('Warning: Clearing the log file will restart the DHCP daemon.'));
634
$group = new Form_Group('Action');
635

  
636
$group->add(new Form_StaticText(
637
	'',
638
	$btnsavesettings
639
))->setHelp('Saves changed settings.');
406 640

  
407 641
$group->add(new Form_StaticText(
408 642
	'',
409 643
	$btnclear
410
));
644
))->setHelp('Clears local log file and reinitializes it as an empty log. Save any settings changes first.');
411 645

  
412 646
$section->add($group);
413 647
$form->add($section);

Also available in: Unified diff