Project

General

Profile

Download (34.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * guiconfig.inc
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2018 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
	"webConfiguratorlockout"
95
);
96

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

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

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

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

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

    
140
$ldap_templates = array(
141

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
423
	return $padr;
424
}
425

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

    
429
	$pport = "";
430

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

    
445
	return $pport;
446
}
447

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

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

    
527
	return $item_set;
528
}
529

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

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

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

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

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

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

    
584
	return $bc;
585
}
586

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

    
595
	return $divstr;
596
}
597

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
887

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

    
900

    
901

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

    
912

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1209
	return $content;
1210
}
1211

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

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

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

    
1241
	return $columns;
1242
}
1243

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

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

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

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

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

    
1301
date_default_timezone_set($timezone);
1302

    
1303
?>
(66-66/234)