Project

General

Profile

Download (35.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * guiconfig.inc
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2019 Rubicon Communications, LLC (Netgate)
7
 * All rights reserved.
8
 *
9
 * originally based on m0n0wall (http://m0n0.ch/wall)
10
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
 * All rights reserved.
12
 *
13
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16
 *
17
 * http://www.apache.org/licenses/LICENSE-2.0
18
 *
19
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24
 */
25

    
26
/* Include authentication routines */
27
/* THIS MUST BE ABOVE ALL OTHER CODE */
28
header("X-Frame-Options: SAMEORIGIN");
29
include_once('phpsessionmanager.inc');
30
if (!$nocsrf) {
31
	function csrf_startup() {
32
		global $config;
33
		csrf_conf('rewrite-js', '/csrf/csrf-magic.js');
34
		$timeout_minutes = isset($config['system']['webgui']['session_timeout']) ? $config['system']['webgui']['session_timeout'] : 240;
35
		csrf_conf('expires', $timeout_minutes * 60);
36
	}
37
	require_once("csrf/csrf-magic.php");
38
	if ($_SERVER['REQUEST_METHOD'] == 'POST') {
39
		phpsession_end(true);
40
	}
41
}
42

    
43
/* make sure nothing is cached */
44
if (!$omit_nocacheheaders) {
45
	header("Expires: 0");
46
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
47
	header("Cache-Control: no-cache, no-store, must-revalidate");
48
	header("Pragma: no-cache");
49
}
50

    
51
require_once("authgui.inc");
52

    
53
/* parse the configuration and include all configuration functions */
54
require_once("functions.inc");
55

    
56
/* Include the autoloader for all the GUI display classes */
57
require_once("classes/autoload.inc.php");
58

    
59
/* used by progress bar */
60
$lastseen = "-1";
61

    
62
$navlevelsep = ": ";	/* navigation level separator string */
63
$mandfldhtml = "";		/* display this before mandatory input fields */
64
$mandfldhtmlspc = "";	/* same as above, but with spacing */
65

    
66
if (!function_exists('set_language')) {
67
	require_once("pfsense-utils.inc");
68
}
69

    
70
set_language();
71

    
72
/* Some ajax scripts still need access to GUI */
73
if (!$ignorefirmwarelock) {
74
	if (is_subsystem_dirty('firmwarelock')) {
75
		if (!$d_isfwfile) {
76
			header("Location: system_update.php");
77
			exit;
78
		} else {
79
			return;
80
		}
81
	}
82
}
83

    
84
/* Reserved table names to avoid collision */
85
$reserved_table_names = array(
86
	"bogons",
87
	"bogonsv6",
88
	"negate_networks",
89
	"snort2c",
90
	"sshguard",
91
	"tonatsubnets",
92
	"virusprot",
93
	"vpn_networks",
94
);
95

    
96
$firewall_rules_dscp_types = array(
97
	"af11",
98
	"af12",
99
	"af13",
100
	"af21",
101
	"af22",
102
	"af23",
103
	"af31",
104
	"af32",
105
	"af33",
106
	"af41",
107
	"af42",
108
	"af43",
109
	"VA",
110
	"EF",
111
	"cs1",
112
	"cs2",
113
	"cs3",
114
	"cs4",
115
	"cs5",
116
	"cs6",
117
	"cs7",
118
	"0x01",
119
	"0x02",
120
	"0x04");
121

    
122
$auth_server_types = array(
123
	'ldap' => "LDAP",
124
	'radius' => "RADIUS");
125

    
126
$ldap_urltypes = array(
127
	'TCP - Standard' => 389,
128
	'TCP - STARTTLS' => 389,
129
	'SSL - Encrypted' => 636);
130

    
131
$ldap_scopes = array(
132
	'one' => gettext("One Level"),
133
	'subtree' => gettext("Entire Subtree"));
134

    
135
$ldap_protvers = array(
136
	2,
137
	3);
138

    
139
$ldap_templates = array(
140

    
141
	'open' => array(
142
		'desc' => "OpenLDAP",
143
		'attr_user' => "cn",
144
		'attr_group' => "cn",
145
		'attr_member' => "member"),
146

    
147
	'msad' => array(
148
		'desc' => "Microsoft AD",
149
		'attr_user' => "samAccountName",
150
		'attr_group' => "cn",
151
		'attr_member' => "memberOf"),
152

    
153
	'edir' => array(
154
		'desc' => "Novell eDirectory",
155
		'attr_user' => "cn",
156
		'attr_group' => "cn",
157
		'attr_member' => "uniqueMember"));
158

    
159
$radius_srvcs = array(
160
	'both' => gettext("Authentication and Accounting"),
161
	'auth' => gettext("Authentication"),
162
	'acct' => gettext("Accounting"));
163

    
164
$radius_protocol = array(
165
	'PAP' => "PAP",
166
	'CHAP_MD5' => "MD5-CHAP",
167
	'MSCHAPv1' => "MS-CHAPv1",
168
	'MSCHAPv2' => "MS-CHAPv2");
169

    
170
$netbios_nodetypes = array(
171
	'0' => "none",
172
	'1' => "b-node",
173
	'2' => "p-node",
174
	'4' => "m-node",
175
	'8' => "h-node");
176

    
177
/* some well known ports */
178
$wkports = array(
179
	5999 => "CVSup",
180
	53 => "DNS",
181
	21 => "FTP",
182
	3000 => "HBCI",
183
	80 => "HTTP",
184
	443 => "HTTPS",
185
	5190 => "ICQ",
186
	113 => "IDENT/AUTH",
187
	143 => "IMAP",
188
	993 => "IMAP/S",
189
	4500 => "IPsec NAT-T",
190
	500 => "ISAKMP",
191
	1701 => "L2TP",
192
	389 => "LDAP",
193
	1755 => "MMS/TCP",
194
	7000 => "MMS/UDP",
195
	445 => "MS DS",
196
	3389 => "MS RDP",
197
	1512 => "MS WINS",
198
	1863 => "MSN",
199
	119 => "NNTP",
200
	123 => "NTP",
201
	138 => "NetBIOS-DGM",
202
	137 => "NetBIOS-NS",
203
	139 => "NetBIOS-SSN",
204
	1194 => "OpenVPN",
205
	110 => "POP3",
206
	995 => "POP3/S",
207
	1723 => "PPTP",
208
	1812 => "RADIUS",
209
	1813 => "RADIUS accounting",
210
	5004 => "RTP",
211
	5060 => "SIP",
212
	25 => "SMTP",
213
	465 => "SMTP/S",
214
	161 => "SNMP",
215
	162 => "SNMP-Trap",
216
	22 => "SSH",
217
	3478 => "STUN",
218
	587 => "SUBMISSION",
219
	3544 => "Teredo",
220
	23 => "Telnet",
221
	69 => "TFTP",
222
	5900 => "VNC");
223

    
224
/* TCP flags */
225
$tcpflags = array("fin", "syn", "rst", "psh", "ack", "urg", "ece", "cwr");
226

    
227
$specialnets = array(
228
	"(self)" => gettext("This Firewall"),
229
	"pppoe" => gettext("PPPoE clients"),
230
	"l2tp" => gettext("L2TP clients"));
231

    
232
$spiflist = get_configured_interface_with_descr(true);
233
foreach ($spiflist as $ifgui => $ifdesc) {
234
	$specialnets[$ifgui] = $ifdesc . " net";
235
	$specialnets[$ifgui . 'ip'] = $ifdesc . " address";
236
}
237

    
238
$medias = array(
239
	"auto" => gettext("autoselect"),
240
	"100full" => gettext("100BASE-TX full-duplex"),
241
	"100half" => gettext("100BASE-TX half-duplex"),
242
	"10full" => gettext("10BASE-T full-duplex"),
243
	"10half" => gettext("10BASE-T half-duplex"));
244

    
245
$wlan_modes = array(
246
	"bss" => gettext("Infrastructure (BSS)"),
247
	"adhoc" => gettext("Ad-hoc (IBSS)"),
248
	"hostap" => gettext("Access Point"));
249

    
250
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, &$input_errors) {
251

    
252
	/* check for bad control characters */
253
	foreach ($postdata as $pn => $pd) {
254
		if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
255
			$input_errors[] = sprintf(gettext("The field %s contains invalid characters."), $pn);
256
		}
257
	}
258

    
259
	if (is_array($reqdfields)) {
260
		for ($i = 0; $i < count($reqdfields); $i++) {
261
			if ($postdata[$reqdfields[$i]] == "") {
262
				$input_errors[] = sprintf(gettext("The field %s is required."), $reqdfieldsn[$i]);
263
			}
264
		}
265
	}
266
}
267

    
268
function print_input_errors($input_errors) {
269
	echo '<div class="alert alert-danger input-errors">';
270
	echo '<p>' . gettext('The following input errors were detected:') . '</p>';
271
	echo '<ul>';
272

    
273
	foreach ($input_errors as $ierr) {
274
		echo '<li>' . htmlspecialchars($ierr) . '</li>';
275
	}
276

    
277
	echo '</ul>';
278
	echo '</div>';
279
}
280

    
281
function verify_gzip_file($fname) {
282
	$returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
283
	if ($returnvar != 0) {
284
		return 0;
285
	} else {
286
		return 1;
287
	}
288
}
289

    
290
// sprint_info_box() returns a string with a formatted informational box, it does not print the box.
291
// To format and print in one step, call print_info_box() as usual.
292
// Any required button is explicitly created, rather than relying on the detection of certain
293
// strings in the message (such as "apply"). print_info_box_np() has been exterminated.
294
// $class = the bootstrap style class (default, info, warning, success, danger)
295
// $btnname and btntext describe the optional button and its display text, the default is an 'x' Close button.
296
// Note that there is also a shortcut function print_apply_box here that creates a standard "apply" box for you.
297
// In many cases just substitute that for print_info_box_np() to easily get a warning style "Apply changes" box.
298
function sprint_info_box($msg, $class="alert-warning", $btnname = "close", $btntext = "", $btnicon = "", $btnclass = "default") {
299

    
300
	if (strpos($class, "alert-") !== 0) {
301
		$class = 'alert-' . $class;
302
	}
303

    
304
	$msg = '<div class="pull-left">' . $msg . '</div>';
305

    
306
	if ($btnname === "close") {
307
		$msg = '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' . $msg;
308
	} else if ($btnname != "") {
309
		if (empty($btntext)) {
310
			$btntext = $btnname;
311
		}
312
		if (!empty($btnicon)) {
313
			$btnicon = '<i class="fa ' . $btnicon . ' icon-embed-btn"></i>';
314
		}
315

    
316
		$msg .= '<form method="post" class="pull-right"><button type="submit" class="btn btn-' . $btnclass . '" name="'. $btnname . '" value="' . $btntext . '">' . $btnicon . $btntext . '</button>';
317

    
318
		if ( isset($_POST['if']) && !empty($_POST['if'])) {
319
			$msg .= "<input type=\"hidden\" name=\"if\" value=\"" . htmlspecialchars($_POST['if']) . "\" />";
320
		}
321

    
322
		$msg .= '</form>';
323
	}
324

    
325
	return '<div class="alert ' . $class . ' clearfix" role="alert">' . $msg . '</div>';
326
}
327

    
328
// Format and print an info box. See sprint_info_box() for details.
329
function print_info_box($msg, $class="alert-warning", $btnname = "close", $btntext = "", $btnicon = "", $btnclass = "default") {
330
	echo sprint_info_box($msg, $class, $btnname, $btntext, $btnicon, $btnclass);
331
}
332

    
333
function print_apply_box($msg) {
334
	print_info_box($msg, "warning", "apply", gettext("Apply Changes"), 'fa-check', 'success');
335
}
336

    
337
// Format and print a box reporting that changes have been applied
338
// $retval = status value from the functions called to apply the changes
339
// 0 is good
340
// non-zero is a problem
341
// $extra_text = optional extra text to display after the standard message
342
function print_apply_result_box($retval, $extra_text="") {
343
	$result_msg = get_std_save_message($retval);
344
	if ($retval === 0) {
345
		// 0 is success
346
		$severity = "success";
347
	} else {
348
		// non-zero means there was some problem
349
		$severity = "warning";
350
	}
351

    
352
	if (strlen($extra_text) > 0) {
353
		$result_msg .= " " . $extra_text;
354
	}
355
	print_info_box($result_msg, $severity);
356
}
357

    
358
/*
359
 * Print Bootstrap callout
360
 *
361
 * @param string $msg     message to display
362
 * @param string $class   contextual class, defaults to info (default | danger | warning | info)
363
 * @param string $heading optional callout heading
364
 */
365
function print_callout($msg, $class = 'info', $heading = '') {
366

    
367
	if ('' == $msg) {
368
		return;
369
	}
370
	$class = strtolower($class);
371
	$callout = '';
372

    
373
	if ($class != 'default' && $class != 'danger' && $class != 'warning' && $class != 'info') {
374
		$class = 'info';
375
	}
376
	$callout .= '<div class="bs-callout bs-callout-' . $class . '">';
377

    
378
	if ('' != $heading) {
379
		$callout .= '<h4>' . $heading . '</h4>';
380
	}
381
	$callout .= $msg . '</div>';
382
	echo $callout;
383
}
384

    
385
function get_std_save_message($retval) {
386
	$filter_related = false;
387
	$filter_pages = array("firewall_aliases", "firewall_nat", "firewall_rules", "status_logs_filter");
388
	if ($retval === 0) {
389
		// 0 is success
390
		$to_return = gettext("The changes have been applied successfully.");
391
	} else {
392
		// non-zero means there was some problem
393
		$to_return = sprintf(gettext('There was a problem applying the changes. See the %1$sSystem Logs%2$s.'), '<a href="status_logs.php">', '</a>');
394
	}
395
	foreach ($filter_pages as $fp) {
396
		if (stristr($_SERVER['SCRIPT_FILENAME'], $fp)) {
397
			$filter_related = true;
398
		}
399
	}
400
	if ($filter_related) {
401
		$to_return .= " " . gettext("The firewall rules are now reloading in the background.") . "<br />" .
402
		    sprintf(gettext('%1$sMonitor%2$s the filter reload progress.'), "<a href='status_filter_reload.php'>", "</a>");
403
	}
404
	return $to_return;
405
}
406

    
407
function pprint_address($adr) {
408
	global $specialnets;
409

    
410
	if (isset($adr['any'])) {
411
		$padr = "*";
412
	} else if ($adr['network']) {
413
		$padr = $specialnets[$adr['network']];
414
	} else {
415
		$padr = $adr['address'];
416
	}
417

    
418
	if (isset($adr['not'])) {
419
		$padr = "! " . $padr;
420
	}
421

    
422
	return $padr;
423
}
424

    
425
function pprint_port($port) {
426
	global $wkports;
427

    
428
	$pport = "";
429

    
430
	if (!$port) {
431
		return "*";
432
	} else {
433
		$srcport = explode("-", $port);
434
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
435
			$pport = $srcport[0];
436
			if ($wkports[$srcport[0]]) {
437
				$pport .= " (" . $wkports[$srcport[0]] . ")";
438
			}
439
		} else {
440
			$pport .= $srcport[0] . " - " . $srcport[1];
441
		}
442
	}
443

    
444
	return $pport;
445
}
446

    
447
function insert_word_breaks_in_domain_name($domain_name) {
448
	return str_replace('.', '<wbr>.', $domain_name);
449
}
450

    
451
function firewall_check_for_advanced_options(&$item) {
452
	$item_set = "";
453
	if ($item['os']) {
454
			$item_set .= "os " . htmlspecialchars($item['os']) . " ";
455
	}
456
	if ($item['dscp']) {
457
		$item_set .= "dscp " . htmlspecialchars($item['dscp']) . " ";
458
	}
459
	if ($item['max']) {
460
		$item_set .= "max " . htmlspecialchars($item['max']) . " ";
461
	}
462
	if ($item['max-src-nodes']) {
463
		$item_set .= "max-src-nodes " . htmlspecialchars($item['max-src-nodes']) . " ";
464
	}
465
	if ($item['max-src-conn']) {
466
		$item_set .= "max-src-conn " . htmlspecialchars($item['max-src-conn']) . " ";
467
	}
468
	if ($item['max-src-states']) {
469
		$item_set .= "max-src-states " . htmlspecialchars($item['max-src-states']) . " ";
470
	}
471
	if (isset($item['nopfsync'])) {
472
		$item_set .= "nopfsync ";
473
	}
474
	if ($item['statetype'] != "keep state" && $item['statetype'] != "") {
475
		$item_set .= "statetype " . htmlspecialchars($item['statetype']) . " ";
476
	}
477
	if ($item['statetimeout']) {
478
		$item_set .= "statetimeout " . htmlspecialchars($item['statetimeout']) . " ";
479
	}
480
	if (isset($item['nosync'])) {
481
		$item_set .= "no XMLRPC Sync ";
482
	}
483
	if ($item['max-src-conn-rate']) {
484
		$item_set .= "max-src-conn-rate " . htmlspecialchars($item['max-src-conn-rate']) . " ";
485
	}
486
	if ($item['max-src-conn-rates']) {
487
		$item_set .= "max-src-conn-rates " . htmlspecialchars($item['max-src-conn-rates']) . " ";
488
	}
489
	if ($item['vlanprio']) {
490
		$item_set .= "vlanprio " . htmlspecialchars($item['vlanprio']) . " ";
491
	}
492
	if ($item['vlanprioset']) {
493
		$item_set .= "vlanprioset " . htmlspecialchars($item['vlanprioset']) . " ";
494
	}
495
	if ($item['gateway']) {
496
		$item_set .= "gateway " . htmlspecialchars($item['gateway']) . " ";
497
	}
498
	if ($item['dnpipe']) {
499
		$item_set .= "limiter " . htmlspecialchars($item['dnpipe']) . " ";
500
	}
501
	if ($item['pdnpipe']) {
502
		$item_set .= "limiter " . htmlspecialchars($item['pdnpipe']) . " ";
503
	}
504
	if ($item['ackqueue']) {
505
		$item_set .= "ackqueue " . htmlspecialchars($item['ackqueue']) . " ";
506
	}
507
	if ($item['defaultqueue']) {
508
		$item_set .= "defaultqueue " . htmlspecialchars($item['defaultqueue']) . " ";
509
	}
510
	if ($item['tag']) {
511
		$item_set .= "tag " . htmlspecialchars($item['tag']) . " ";
512
	}
513
	if ($item['tagged']) {
514
		$item_set .= "tagged " . htmlspecialchars($item['tagged']) . " ";
515
	}
516
	if (isset($item['allowopts'])) {
517
		$item_set .= "allowopts ";
518
	}
519
	if (isset($item['disablereplyto'])) {
520
		$item_set .= "disable reply-to ";
521
	}
522
	if ($item['tcpflags_any'] || $item['tcpflags1'] || $item['tcpflags2']) {
523
		$item_set .= "tcpflags set";
524
	}
525

    
526
	return $item_set;
527
}
528

    
529
function gentitle($title) {
530
	global $navlevelsep;
531
	if (!is_array($title)) {
532
		return $title;
533
	} else {
534
		return join($navlevelsep, $title);
535
	}
536
}
537

    
538
function genhtmltitle($title, $links=true) {
539
	if (is_array($title)) {
540
		$num_crumbs = count($title);
541
	} else if ($title != NULL) {
542
		$num_crumbs = 1;
543
	} else {
544
		$num_crumbs = 0;
545
	}
546

    
547
	// If the array contains only one element, there are no breadcrumbs, so don't
548
	// add anything else
549
	if ($num_crumbs > 1) {
550
		$bc = '<ol class="breadcrumb">';
551

    
552
		if (!is_array($links)) {
553
			$gen_default = ($links === true);
554
			$links = array_fill(0, $num_crumbs, '');
555
			// If no links passed, then default to a link to self on the last entry.
556
			if ($gen_default) {
557
				$links[$num_crumbs-1] = '@self';
558
			}
559
		}
560

    
561
		foreach ($title as $idx => $el) {
562
			$href = $links[$idx];
563
			if (strlen($href) > 0) {
564
				// For convenience, if the caller specifies '@self' then make a link
565
				// to the current page, including any query string.
566
				if ($href == '@self') {
567
					$href = $_SERVER['REQUEST_URI'];
568
				}
569
				if (substr($href, 0, 1) != '/') {
570
					$href = '/' . $href;
571
				}
572
				$bc .= '<li><a href="' . htmlentities($href) . '">' . $el . '</a></li>';
573
			} else {
574
				$bc .= '<li>' . $el . '</li>';
575
			}
576
		}
577

    
578
		$bc .= '</ol>';
579
	} else {
580
		$bc = "";
581
	}
582

    
583
	return $bc;
584
}
585

    
586
function gen_customwidgettitle_div($widgettitle) {
587
	$divstr = '<div class="form-group">';
588
	$divstr .= '  <label for="descr" class="col-sm-4 control-label">' . gettext('Widget title'). '</label>';
589
	$divstr .= '  <div class="col-sm-4">';
590
	$divstr .= '    <input type="text" name="descr" id="descr" value="'. $widgettitle . '" class="form-control" />';
591
	$divstr .= '  </div>';
592
	$divstr .= '</div>';
593

    
594
	return $divstr;
595
}
596

    
597
function set_customwidgettitle(& $user_settings) {
598
	if ($_POST['descr']) {
599
		$user_settings['widgets'][$_POST['widgetkey']]['descr'] = trim($_POST['descr']);
600
	} else {
601
		unset($user_settings['widgets'][$_POST['widgetkey']]['descr']);
602
	}
603
}
604

    
605
/* update the changedesc and changecount(er) variables */
606
function update_changedesc($update) {
607
	global $changedesc;
608
	global $changecount;
609

    
610
	$changedesc .= " {$update}";
611
	$changecount++;
612
}
613

    
614
// This version of dump_clog() does not output <td></td> or any other table elements.
615
function dump_clog_no_table($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
616
	global $g, $config;
617
	$sor = isset($config['syslog']['reverse']) ? "-r" : "";
618
	$specific_log = basename($logfile, '.log') . '_settings';
619
	if ($config['syslog'][$specific_log]['cronorder'] == 'forward') $sor = "";
620
	if ($config['syslog'][$specific_log]['cronorder'] == 'reverse') $sor = "-r";
621
	$logarr = array();
622
	$grepline = "  ";
623
	if (is_array($grepfor)) {
624
		$invert = '';
625
		if ((strpos($grepfor[0], '!') === 0)) {
626
			$grepfor[0] = substr($grepfor[0], 1);
627
			$invert = '-v';
628
		}
629
		$grepline .= " | /usr/bin/egrep {$invert} " . escapeshellarg(implode("|", $grepfor));
630
	}
631
	if (is_array($grepinvert)) {
632
		$grepline .= " | /usr/bin/egrep -v " . escapeshellarg(implode("|", $grepinvert));
633
	}
634
	if (is_dir($logfile)) {
635
		$logarr = array(sprintf(gettext("File %s is a directory."), $logfile));
636
	} elseif (file_exists($logfile) && filesize($logfile) == 0) {
637
		$logarr = array(gettext("Log file started."));
638
	} else {
639
		if ($config['system']['disablesyslogclog']) {
640
			exec("cat " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
641
		} else {
642
			exec("/usr/local/sbin/clog " . escapeshellarg($logfile) . "{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
643
		}
644
	}
645
	echo "\n";
646

    
647
	$rows = 0;
648
	foreach ($logarr as $logent) {
649
		$rows++;
650
		$logent = preg_split("/\s+/", $logent, 6);
651

    
652
		if ($withorig) {
653
				$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
654
				$entry_text = ($logent[3] ==  $config['system']['hostname']) ? "" : $logent[3] . " ";
655
				$entry_text .= htmlspecialchars($logent[4] . " " . $logent[5]);
656
				echo "{$entry_date_time}";
657
				echo " " . "{$entry_text}"	. "\n";
658
		} else {
659
				echo htmlspecialchars($logent[5]) . "\n";
660
		}
661

    
662
	}
663
	return($rows);
664
}
665

    
666
function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
667
	global $g, $config;
668
	$sor = isset($config['syslog']['reverse']) ? "-r" : "";
669
	$specific_log = basename($logfile, '.log') . '_settings';
670
	if ($config['syslog'][$specific_log]['cronorder'] == 'forward') $sor = "";
671
	if ($config['syslog'][$specific_log]['cronorder'] == 'reverse') $sor = "-r";
672
	$logarr = array();
673
	$grepline = "  ";
674
	if (is_array($grepfor)) {
675
		$invert = '';
676
		if ((strpos($grepfor[0], '!') === 0)) {
677
			$grepfor[0] = substr($grepfor[0], 1);
678
			$invert = '-v';
679
		}
680
		$grepline .= " | /usr/bin/egrep {$invert} " . escapeshellarg(implode("|", $grepfor));
681
	}
682
	if (is_array($grepinvert)) {
683
		$grepline .= " | /usr/bin/egrep -v " . escapeshellarg(implode("|", $grepinvert));
684
	}
685
	if (is_dir($logfile)) {
686
		$logarr = array(sprintf(gettext("File %s is a directory."), $logfile));
687
	} elseif (file_exists($logfile) && filesize($logfile) == 0) {
688
		$logarr = array(gettext("Log file started."));
689
	} else {
690
		if ($config['system']['disablesyslogclog']) {
691
			exec("cat " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
692
		} else {
693
			exec("/usr/local/sbin/clog " . escapeshellarg($logfile) . "{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
694
		}
695
	}
696

    
697
	$rows = 0;
698
	foreach ($logarr as $logent) {
699
		$rows++;
700
		$logent = preg_split("/\s+/", $logent, 6);
701
		echo "<tr>\n";
702
		if ($withorig) {
703
			$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
704
			$entry_text = ($logent[3] == $config['system']['hostname']) ? "" : $logent[3] . " ";
705
			$entry_text .= htmlspecialchars($logent[4] . " " . $logent[5]);
706
			echo "<td class=\"text-nowrap\">{$entry_date_time}</td>\n";
707
			echo "<td style=\"word-wrap:break-word; word-break:break-all; white-space:normal\">{$entry_text}</td>\n";
708
		} else {
709
				echo "<td>" . htmlspecialchars($logent[5]) . "</td>\n";
710
		}
711
		echo "</tr>\n";
712
	}
713
	return($rows);
714
}
715

    
716
function return_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "", $grepreverse = false) {
717
	global $g, $config;
718
	$sor = (isset($config['syslog']['reverse']) || $grepreverse) ? "-r" : "";
719
	$specific_log = basename($logfile, '.log') . '_settings';
720
	if (($config['syslog'][$specific_log]['cronorder'] == 'forward') && !$grepreverse) $sor = "";
721
	if (($config['syslog'][$specific_log]['cronorder'] == 'reverse') ||  $grepreverse) $sor = "-r";
722
	$logarr = array();
723
	$grepline = "  ";
724
	if (is_array($grepfor)) {
725
		$grepline .= " | /usr/bin/egrep " . escapeshellarg(implode("|", $grepfor));
726
	}
727
	if (is_array($grepinvert)) {
728
		$grepline .= " | /usr/bin/egrep -v " . escapeshellarg(implode("|", $grepinvert));
729
	}
730
	if ($config['system']['disablesyslogclog']) {
731
		exec("cat " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
732
	} else {
733
		exec("/usr/local/sbin/clog " . escapeshellarg($logfile) . "{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
734
	}
735
	return($logarr);
736
}
737

    
738
/* Check if variable has changed, update and log if it has
739
 * returns true if var changed
740
 * varname = variable name in plain text
741
 * orig = original value
742
 * new = new value
743
 */
744
function update_if_changed($varname, & $orig, $new) {
745
	if (is_array($orig) && is_array($new)) {
746
		$a_diff = array_diff($orig, $new);
747
		foreach ($a_diff as $diff) {
748
			update_changedesc("removed {$varname}: \"{$diff}\"");
749
		}
750
		$a_diff = array_diff($new, $orig);
751
		foreach ($a_diff as $diff) {
752
			update_changedesc("added {$varname}: \"{$diff}\"");
753
		}
754
		$orig = $new;
755
		return true;
756

    
757
	} else {
758
		if ($orig != $new) {
759
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
760
			$orig = $new;
761
			return true;
762
		}
763
	}
764
	return false;
765
}
766

    
767
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
768
	if (isset($adr['any'])) {
769
		$padr = "any";
770
	} else if ($adr['network']) {
771
		$padr = $adr['network'];
772
	} else if ($adr['address']) {
773
		list($padr, $pmask) = explode("/", $adr['address']);
774
		if (!$pmask) {
775
			if (is_ipaddrv6($padr)) {
776
				$pmask = 128;
777
			} else {
778
				$pmask = 32;
779
			}
780
		}
781
	}
782

    
783
	if (isset($adr['not'])) {
784
		$pnot = 1;
785
	} else {
786
		$pnot = 0;
787
	}
788

    
789
	if ($adr['port']) {
790
		list($pbeginport, $pendport) = explode("-", $adr['port']);
791
		if (!$pendport) {
792
			$pendport = $pbeginport;
793
		}
794
	} else if (!is_alias($pbeginport) && !is_alias($pendport)) {
795
		$pbeginport = "any";
796
		$pendport = "any";
797
	}
798
}
799

    
800
function pconfig_to_address(&$adr, $padr, $pmask, $pnot = false, $pbeginport = 0, $pendport = 0) {
801
	$adr = array();
802

    
803
	if ($padr == "any") {
804
		$adr['any'] = true;
805
	} else if (is_specialnet($padr)) {
806
		$adr['network'] = $padr;
807
	} else {
808
		$adr['address'] = $padr;
809
		if (is_ipaddrv6($padr)) {
810
			if ($pmask != 128) {
811
				$adr['address'] .= "/" . $pmask;
812
			}
813
		} else {
814
			if ($pmask != 32) {
815
				$adr['address'] .= "/" . $pmask;
816
			}
817
		}
818
	}
819

    
820
	if ($pnot) {
821
		$adr['not'] = true;
822
	} else {
823
		unset($adr['not']);
824
	}
825

    
826
	if (($pbeginport != 0) && ($pbeginport != "any")) {
827
		if ($pbeginport != $pendport) {
828
			$adr['port'] = $pbeginport . "-" . $pendport;
829
		} else {
830
			$adr['port'] = $pbeginport;
831
		}
832
	}
833

    
834
	/*
835
	 * If the port is still unset, then it must not be numeric, but could
836
	 * be an alias or a well-known/registered service.
837
	 * See https://redmine.pfsense.org/issues/8410
838
	 */
839
	if (!isset($adr['port']) && is_port_or_alias($pbeginport)) {
840
		$adr['port'] = $pbeginport;
841
	}
842
}
843

    
844
function is_specialnet($net) {
845
	global $specialsrcdst;
846

    
847
	if (!$net) {
848
		return false;
849
	}
850
	if (in_array($net, $specialsrcdst)) {
851
		return true;
852
	} else {
853
		return false;
854
	}
855
}
856

    
857
//function to create widget tabs when called
858
function display_widget_tabs(& $tab_array) {
859
	echo "<div id=\"tabs\">";
860
	$tabscounter = 0;
861
	foreach ($tab_array as $ta) {
862
		$dashpos = strpos($ta[2], '-');
863
		$tabname = $ta[2] . "-tab";
864
		$tabclass = substr($ta[2], 0, $dashpos);
865
		$tabclass = $tabclass . "-class";
866
		if ($ta[1] == true) {
867
			$tabActive = "table-cell";
868
			$tabNonActive = "none";
869
		} else {
870
			$tabActive = "none";
871
			$tabNonActive = "table-cell";
872
		}
873
		echo "<div id=\"{$ta[2]}-active\" class=\"{$tabclass}-tabactive\" style=\"display:{$tabActive}; background-color:#EEEEEE; color:black;\">";
874
		echo "<b>&nbsp;&nbsp;&nbsp;{$ta[0]}";
875
		echo "&nbsp;&nbsp;&nbsp;</b>";
876
		echo "</div>";
877

    
878
		echo "<div id=\"{$ta[2]}-deactive\" class=\"{$tabclass}-tabdeactive\" style=\"display:{$tabNonActive}; background-color:#777777; color:white; cursor: pointer;\" onclick=\"return changeTabDIV('{$ta[2]}')\">";
879
		echo "<b>&nbsp;&nbsp;&nbsp;{$ta[0]}";
880
		echo "&nbsp;&nbsp;&nbsp;</b>";
881
		echo "</div>";
882
	}
883
	echo "</div>";
884
}
885

    
886

    
887
// Return inline javascript file or CSS to minimize
888
// request count going back to server.
889
function outputJavaScriptFileInline($javascript) {
890
	if (file_exists($javascript)) {
891
		echo "\n<script type=\"text/javascript\">\n";
892
		include_once($javascript);
893
		echo "\n</script>\n";
894
	} else {
895
		echo "\n\n<!-- Could not locate file:  {$javascript} -->\n\n";
896
	}
897
}
898

    
899

    
900

    
901
function outputCSSPrintFileInline($css) {
902
	if (file_exists($css)) {
903
		echo "\n<style media=\"print\" type=\"text/css\">\n";
904
		include_once($css);
905
		echo "\n</style>\n";
906
	} else {
907
		echo "\n\n<!-- Could not locate file:  {$css} -->\n\n";
908
	}
909
}
910

    
911

    
912
function outputCSSFileInline($css) {
913
	if (file_exists($css)) {
914
		echo "\n<style type=\"text/css\">\n";
915
		include_once($css);
916
		echo "\n</style>\n";
917
	} else {
918
		echo "\n\n<!-- Could not locate file:  {$css} -->\n\n";
919
	}
920
}
921

    
922
$rfc2616 = array(
923
	100 => "100 Continue",
924
	101 => "101 Switching Protocols",
925
	200 => "200 OK",
926
	201 => "201 Created",
927
	202 => "202 Accepted",
928
	203 => "203 Non-Authoritative Information",
929
	204 => "204 No Content",
930
	205 => "205 Reset Content",
931
	206 => "206 Partial Content",
932
	300 => "300 Multiple Choices",
933
	301 => "301 Moved Permanently",
934
	302 => "302 Found",
935
	303 => "303 See Other",
936
	304 => "304 Not Modified",
937
	305 => "305 Use Proxy",
938
	306 => "306 (Unused)",
939
	307 => "307 Temporary Redirect",
940
	400 => "400 Bad Request",
941
	401 => "401 Unauthorized",
942
	402 => "402 Payment Required",
943
	403 => "403 Forbidden",
944
	404 => "404 Not Found",
945
	405 => "405 Method Not Allowed",
946
	406 => "406 Not Acceptable",
947
	407 => "407 Proxy Authentication Required",
948
	408 => "408 Request Timeout",
949
	409 => "409 Conflict",
950
	410 => "410 Gone",
951
	411 => "411 Length Required",
952
	412 => "412 Precondition Failed",
953
	413 => "413 Request Entity Too Large",
954
	414 => "414 Request-URI Too Long",
955
	415 => "415 Unsupported Media Type",
956
	416 => "416 Requested Range Not Satisfiable",
957
	417 => "417 Expectation Failed",
958
	500 => "500 Internal Server Error",
959
	501 => "501 Not Implemented",
960
	502 => "502 Bad Gateway",
961
	503 => "503 Service Unavailable",
962
	504 => "504 Gateway Timeout",
963
	505 => "505 HTTP Version Not Supported"
964
);
965

    
966
function is_rfc2616_code($code) {
967
	global $rfc2616;
968
	if (isset($rfc2616[$code])) {
969
		return true;
970
	} else {
971
		return false;
972
	}
973
}
974

    
975
function print_rfc2616_select($tag, $current) {
976
	global $rfc2616;
977

    
978
	/* Default to 200 OK if not set */
979
	if ($current == "") {
980
		$current = 200;
981
	}
982

    
983
	echo "<select id=\"{$tag}\" name=\"{$tag}\">\n";
984
	foreach ($rfc2616 as $code => $message) {
985
		if ($code == $current) {
986
			$sel = " selected";
987
		} else {
988
			$sel = "";
989
		}
990
		echo "<option value=\"{$code}\"{$sel}>{$message}</option>\n";
991
	}
992
	echo "</select>\n";
993
}
994

    
995
// Useful debugging function, much cleaner than print_r
996
function echo_array($array, $return_me = false) {
997
	if (is_array($array) == false) {
998
		$return = "The provided variable is not an array.";
999
	} else {
1000
		foreach ($array as $name=>$value) {
1001
			if (is_array($value)) {
1002
				$return .= "";
1003
				$return .= "['<b>$name</b>'] {<div style=\"margin-left:10px;\">\n";
1004
				$return .= echo_array($value, true);
1005
				$return .= "</div>}";
1006
				$return .= "\n\n";
1007
			} else {
1008
				if (is_string($value)) {
1009
					$value = "\"$value\"";
1010
				}
1011
				$return .= "['<b>$name</b>'] = $value\n\n";
1012
			}
1013
		}
1014
	}
1015
	if ($return_me == true) {
1016
		return $return;
1017
	} else {
1018
		echo "<pre>".$return."</pre>";
1019
	}
1020
}
1021

    
1022
/****f* pfsense-utils/display_top_tabs
1023
 * NAME
1024
 *	 display_top_tabs - display tabs with rounded edges
1025
 * INPUTS
1026
 *	 $text	  - array of tabs
1027
 * RESULT
1028
 *	 null
1029
 ******/
1030
function display_top_tabs(& $tab_array, $no_drop_down = false, $type = 'pills', $usepost = "") {
1031
	global $config;
1032
	global $g;
1033
	global $tab_array_indent;
1034
	global $tab_array_space;
1035
	global $tab_array_char_limit;
1036

    
1037
	/*	does the user have access to this tab?
1038
	 *	master user has access to everything.
1039
	 *	if the user does not have access, simply
1040
	 *	unset the tab item.
1041
	 */
1042

    
1043
	/* empty string code */
1044
	if ($tab_array_indent == '') {
1045
		$tab_array_indent = 0;
1046
	}
1047

    
1048
	if ($tab_array_space == '') {
1049
		$tab_array_space = 1;
1050
	}
1051

    
1052
	if ($tab_array_char_limit == '') {
1053
		$tab_array_char_limit = 256;
1054
	}
1055

    
1056
	foreach ($tab_array as $tab_id => $ta) {
1057
		if (!isAllowedPage($ta[2])) {
1058
			unset ($tab_array[$tab_id]);
1059
		}
1060
	}
1061

    
1062
	$tab_active_bg	 = "#EEEEEE";
1063
	$tab_inactive_bg = "#777777";
1064
	$nifty_tabs_corners = "#FFF";
1065
	$font_color = "white";
1066

    
1067
	$tabcharcount = 0;
1068
	foreach ($tab_array as $ta) {
1069
		$tabcharcount = $tabcharcount + strlen($ta[0]);
1070
	}
1071

    
1072
	if ($no_drop_down == true) {
1073
		$tabcharcount = 0;
1074
		unset($tab_array_char_limit);
1075
	}
1076

    
1077
	// If the character count of the tab names is > 670
1078
	// then show a select item dropdown menubox.
1079
	if ($tabcharcount > $tab_array_char_limit) {
1080
		echo gettext("Currently viewing: ");
1081
		echo "<select name=\"TabSelect\" onchange=\"tabs_will_go(this)\">\n";
1082

    
1083
		foreach ($tab_array as $ta) {
1084
			if ($ta[1] == "true") {
1085
				$selected = " selected";
1086
			} else {
1087
				$selected = "";
1088
			}
1089
			// Onclick in option will not work in some browser
1090
			// echo "<option onclick=\"document.location='{$ta[2]}';\"{$selected}>{$ta['0']}</option>\n";
1091
			echo "<option value=\"{$ta[2]}\"{$selected}>{$ta['0']}</option>\n";
1092
		}
1093

    
1094
		echo "</select>\n<p>&nbsp;</p>";
1095
		echo "<script type=\"text/javascript\">";
1096
		echo "\n//<![CDATA[\n";
1097
		if ($usepost == 'usepost') {
1098
			echo " function tabs_will_go(obj){ var target = obj.value.split(\"?\"); postSubmit(get2post(target[1]),target[0]); }\n";
1099
		} else {
1100
			echo " function tabs_will_go(obj){ document.location = obj.value; }\n";
1101
		}
1102
		echo "//]]>\n";
1103
		echo "</script>";
1104
	} else {
1105
		echo '<ul class="nav nav-' . $type . '">';
1106

    
1107
		foreach ($tab_array as $ta) {
1108
			echo '<li role="presentation"';
1109
			if ($ta[1]) {
1110
				echo ' class="active"';
1111
			}
1112

    
1113
			echo '><a href="' . $ta[2] . '" ' . $usepost . '>' . $ta[0] . '</a></li>';
1114
		}
1115

    
1116
		echo '</ul>';
1117
	}
1118
}
1119

    
1120
function add_package_tabs($tabgroup, &$tab_array) {
1121
	global $config, $g;
1122

    
1123
	if (!isset($config['installedpackages']['package'])) {
1124
		return;
1125
	}
1126

    
1127
	foreach ($config['installedpackages']['package'] as $pkg) {
1128
		if (!is_array($pkg['tabs']['tab'])) {
1129
			continue;
1130
		}
1131

    
1132
		foreach ($pkg['tabs']['tab'] as $tab) {
1133
			if ($tab['tabgroup'] != $tabgroup) {
1134
				continue;
1135
			}
1136
			$tab_entry = array();
1137
			if ($tab['name']) {
1138
				$tab_entry[] = $tab['name'];
1139
				$tab_entry[] = false;
1140
				$tab_entry[] = $tab['url'];
1141
				$tab_array[] = $tab_entry;
1142
			}
1143
		}
1144
	}
1145
}
1146

    
1147
function alias_info_popup($alias_id) {
1148
	global $config, $user_settings;
1149

    
1150
	if (!is_array($config['aliases']['alias'][$alias_id])) {
1151
		return;
1152
	}
1153

    
1154
	$maxlength = 60;
1155
	$alias = $config['aliases']['alias'][$alias_id];
1156
	$content = "";
1157

    
1158
	if ($user_settings['webgui']['disablealiaspopupdetail']) {
1159
		if (strlen($alias['descr']) >= $maxlength) {
1160
			$alias['descr'] = substr($alias['descr'], 0, $maxlength) . '&hellip;';
1161
		}
1162

    
1163
		$content .= $alias['descr'];
1164
	} else if ($alias['url']) {
1165
		// TODO: Change it when pf supports tables with ports
1166
		if ($alias['type'] == "urltable") {
1167
			exec("/sbin/pfctl -t {$alias['name']} -T show | wc -l", $total_entries);
1168
			$counter=preg_replace("/\D/", "", $total_entries[0]);
1169
			exec("/sbin/pfctl -t {$alias['name']} -T show | head -10002", $alias_addresses);
1170
		} else {
1171
			$urlfn = alias_expand_urltable($alias['name']);
1172
			$alias_addresses = explode("\n", file_get_contents($urlfn));
1173
			$counter = count($alias_addresses);
1174
		}
1175

    
1176
		$content .= '<h5>'. $alias['url'] .'</h5><ul><li>'. implode('</li><li>', $alias_addresses) .'</li></ul>';
1177
		if ($counter > 10002) {
1178
			$content .= '<i>'. gettext("listing only first 10k items") .'</i>';
1179
		}
1180
	} else {
1181
		$alias_addresses = explode (" ", $alias['address']);
1182
		$alias_details = explode ("||", $alias['detail']);
1183
		$idx = 0;
1184

    
1185
		$content .= "<table>\n";
1186
		$content .= "<thead>\n";
1187
		$content .= "<tr>\n";
1188
		$content .= "<th>" . gettext("Value") . "</th><th  style='padding-left: 10px;'>" . gettext("Description") . "</th></tr>\n";
1189
		$content .= "</thead>\n";
1190
		$content .= "<tbody>\n";
1191

    
1192
		foreach ($alias_addresses as $ap) {
1193
			$content .= "	<tr>\n";
1194
			$content .= "		<td>\n";
1195
			$content .= 			$ap;
1196
			$content .=	"		</td>\n";
1197
			$content .= "		<td style='padding-left: 10px;'>\n";
1198
			$content .= 			htmlspecialchars($alias_details[$idx]);
1199
			$content .=	"		</td>\n";
1200
			$content .= "	</tr>\n";
1201
			$idx++;
1202
		}
1203

    
1204
		$content .= "</tbody>\n";
1205
		$content .= "<table>\n";
1206
	}
1207

    
1208
	return $content;
1209
}
1210

    
1211
function rule_columns_with_alias($src, $srcport, $dst, $dstport, $target="", $targetport="") {
1212
	global $config;
1213

    
1214
	if ($config['aliases']['alias'] == "" || !is_array($config['aliases']['alias'])) {
1215
		return;
1216
	}
1217

    
1218
	$columns = array();
1219
	foreach ($config['aliases']['alias'] as $alias_id => $alias_name) {
1220
		if ($alias_name['name'] == $src) {
1221
			$columns['src'] = $alias_id;
1222
		}
1223
		if ($alias_name['name'] == $srcport) {
1224
			$columns['srcport'] = $alias_id;
1225
		}
1226
		if ($alias_name['name'] == $dst) {
1227
			$columns['dst'] = $alias_id;
1228
		}
1229
		if ($alias_name['name'] == $dstport) {
1230
			$columns['dstport'] = $alias_id;
1231
		}
1232
		if ($alias_name['name'] == $target) {
1233
			$columns['target'] = $alias_id;
1234
		}
1235
		if ($alias_name['name'] == $targetport) {
1236
			$columns['targetport'] = $alias_id;
1237
		}
1238
	}
1239

    
1240
	return $columns;
1241
}
1242

    
1243
function form_output_row($name, $label, $content) {
1244
var_dump($content);die;
1245
?>
1246
<div class="form-group">
1247
	<label for="<?=$name?>" class="col-sm-2 control-label"><?=gettext($label); ?></label>
1248
	<div class="col-sm-10">
1249
		<?=$content?>
1250
	</div>
1251
</div>
1252
<?php
1253
}
1254

    
1255
function set_flash_message($class, $msg) {
1256
	@phpsession_begin();
1257
	$_SESSION['flash_messages'][$class][] = $msg;
1258
	@phpsession_end(true);
1259
}
1260

    
1261
function get_flash_message() {
1262
	@phpsession_begin();
1263
	if (isset($_SESSION['flash_messages']) && !empty($_SESSION['flash_messages'])) {
1264
		foreach ($_SESSION['flash_messages'] as $class => $flash_message) {
1265
			print_info_box(implode("<br />", $flash_message), $class);
1266
		}
1267
		unset($_SESSION['flash_messages']);
1268
	}
1269
	@phpsession_end(true);
1270
}
1271

    
1272
/* Retrieve GET or POST Value/State
1273
 * Eample Usage:
1274
 * $value = getGETPOSTsettingvalue('get/post parameter name', "");
1275
 * $value = getGETPOSTsettingvalue('get/post parameter name', null);
1276
 * $state = getGETPOSTsettingvalue('get/post parameter name', null);
1277
 * $state = getGETPOSTsettingvalue('get/post parameter name', false);
1278
 */
1279
function getGETPOSTsettingvalue($settingname, $default) {
1280
	$settingvalue = $default;
1281
	if ($_GET[$settingname]) {
1282
		$settingvalue = $_GET[$settingname];
1283
	}
1284
	if ($_POST[$settingname]) {
1285
		$settingvalue = $_POST[$settingname];
1286
	}
1287
	return $settingvalue;
1288
}
1289

    
1290
/* set timezone */
1291
if (isset($config['system']['timezone']) &&
1292
    !empty($config['system']['timezone'])) {
1293
	$timezone = $config['system']['timezone'];
1294
} elseif (isset($g['default_timezone']) && !empty($g['default_timezone'])) {
1295
	$timezone = $g['default_timezone'];
1296
} else {
1297
	$timezone = "Etc/UTC";
1298
}
1299

    
1300
/* Remove files we do not want to see in a crash report */
1301
function cleanup_crash_file_list() {
1302
	$files = glob("/var/crash/*");
1303
	if (!is_array($files) || empty($files)) {
1304
		return array();
1305
	}
1306

    
1307
	$exclude_patterns = array(
1308
		'.*.last',
1309
		'bounds',
1310
		'minfree'
1311
	);
1312

    
1313
	foreach ($files as $idx => $fb) {
1314
		if (preg_match('/' . implode('|', $exclude_patterns) . '/', basename($fb)) == 1) {
1315
			unset($files[$idx]);
1316
		}
1317
	}
1318

    
1319
	return $files;
1320
}
1321

    
1322
function system_has_crash_data() {
1323
	/* Test if there are any crash data files present */
1324
	return count(cleanup_crash_file_list()) > 0;
1325
}
1326

    
1327
function system_has_php_errors() {
1328
	/* Check if the PHP error log is empty. Cast to int in case the file
1329
	 * does not exist and filesize() returns false. */
1330
	return (int) @filesize("/tmp/PHP_errors.log") > 0;
1331
}
1332

    
1333
date_default_timezone_set($timezone);
1334

    
1335
?>
(66-66/234)