Project

General

Profile

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

    
24
// Global defines
25

    
26
// Automatic panel collapse
27
define('COLLAPSIBLE', 0x08);
28
define('SEC_CLOSED', 0x04);
29
define('SEC_OPEN', 0x00);
30

    
31
// IP address types
32
define('IPV4', 4);
33
define('IPV6', 6);
34
define('IPV4V6', 2);
35
define('ALIAS', 1);
36

    
37
// Interface Name Size
38
define('IF_NAMESIZE', 15);	/* 16 minus the terminating NULL */
39

    
40
// AddPassword method defines
41
define('DMYPWD', '********');
42

    
43
// Captive Portal aliases prefix
44
define('CPPREFIX', 'cpzoneid_');
45

    
46
$version_file = '/etc/version';
47
$version_patch_file = $version_file . 'patch';
48

    
49
$product_version = rtrim(file_get_contents($version_file));
50
$present_year = date('Y');
51

    
52
global $g;
53
$g = [
54
	'acbbackuppath' => '/cf/conf/acb/',
55
	'event_address' => 'unix:///var/run/check_reload_status',
56
	'factory_shipped_username' => 'admin',
57
	'factory_shipped_password' => 'pfsense',
58
	'upload_path' => '/root',
59
	'dhcpd_chroot_path' => '/var/dhcpd',
60
	'unbound_chroot_path' => '/var/unbound',
61
	'var_path' => '/var',
62
	'varrun_path' => '/var/run',
63
	'varetc_path' => '/var/etc',
64
	'vardb_path' => '/var/db',
65
	'varlog_path' => '/var/log',
66
	'etc_path' => '/etc',
67
	'tmp_path' => '/tmp',
68
	'tmp_path_user_code' => '/tmp/user_code',
69
	'conf_path' => '/conf',
70
	'conf_default_path' => '/conf.default',
71
	'cf_path' => '/cf',
72
	'cf_conf_path' => '/cf/conf',
73
	'www_path' => '/usr/local/www',
74
	'xml_rootobj' => 'pfsense',
75
	'admin_group' => 'admins',
76
	'product_name' => 'pfSense',
77
	'product_label' => 'pfSense',
78
	'product_label_html' => 'Netgate pfSense<sup>&#174;</sup>',
79
	'product_version' => $product_version,
80
	'product_copyright_years' => '2004 - ' . $present_year,
81
	'disablehelpmenu' => false,
82
	'disablehelpicon' => false,
83
	'disablecrashreporter' => false,
84
	'debug' => false,
85
	'latest_config' => '22.9',
86
	'minimum_ram_warning' => '101',
87
	'minimum_ram_warning_text' => '128 MB',
88
	'wan_interface_name' => 'wan',
89
	'captiveportal_path' => '/usr/local/captiveportal',
90
	'captiveportal_element_path' => '/var/db/cpelements',
91
	'captiveportal_element_sizelimit' => 1048576,
92
	'captiveportal_rules_interval' => 50,
93
	'services_dhcp_server_enable' => true,
94
	'wireless_regex' => '/^(ath|athp|bwi|bwn|ipw|iwi|iwlwifi|iwm|iwn|malo|mwl|ral|rsu|rtwn|rum|run|uath|upgt|ural|urtw|urtwn|wi|wpi|wtap|zyd)[0-9]+/',
95
	'help_base_url' => '/help.php',
96
	'pkg_prefix' => 'pfSense-pkg-',
97
	'default_timezone' => 'Etc/UTC',
98
	'language' => 'en_US',
99
	'default_config_backup_count' => 30,
100
	'default_cert_expiredays' => 27,
101
	'default_log_entries' => 500,
102
	'default_log_size' => 512000,
103
	'minimumtableentries_bogonsv6' => 400000,
104
	'alternativemetaports' => ['vmware', 'php72', 'php73', 'php74'],
105
	'backuppath' => [
106
		'captiveportal' => '/var/db/captiveportal*.db',
107
		'dhcpd' => '/var/dhcpd/var/db/dhcpd.leases',
108
		'dhcpdv6' => '/var/dhcpd/var/db/dhcpd6.leases',
109
		'voucher' => '/var/db/voucher_*.db'
110
	],
111
	'cp_prefix' => 'cpzoneid',
112
	'booting' => false
113
];
114

    
115
/* IP TOS flags */
116
global $iptos;
117
$iptos = ['lowdelay', 'throughput', 'reliability'];
118

    
119
/* TCP flags */
120
global $tcpflags;
121
$tcpflags = ['syn', 'ack', 'fin', 'rst', 'psh', 'urg', 'ece', 'cwr'];
122

    
123
if (file_exists($version_patch_file)) {
124
	$g['product_version_patch'] = rtrim(file_get_contents($version_patch_file));
125
} else {
126
	$g['product_version_patch'] = '0';
127
}
128

    
129
$g['product_version_string'] = g_get('product_version');
130
if (is_numeric(g_get('product_version_patch')) && g_get('product_version_patch') != '0') {
131
	$g['product_version_string'] .= '-p'. g_get('product_version_patch');
132
}
133

    
134
$flavor_file = g_get('etc_path') . '/default-config-flavor';
135
if (file_exists($flavor_file)) {
136
	$flavor_array = file($flavor_file);
137
	$g['default-config-flavor'] = chop($flavor_array[0]);
138
} else {
139
	$g['default-config-flavor'] = '';
140
}
141

    
142
$g['openvpn_base'] = g_get('varetc_path') . '/openvpn';
143

    
144
$g['pkg_repos_path'] = '/usr/local/etc/' . $g['product_name'] . '/pkg/repos';
145

    
146
/* Default sysctls */
147
global $sysctls;
148
$sysctls = [
149
	'net.inet.ip.portrange.first' => '1024',
150
	'net.inet.tcp.blackhole' => '2',
151
	'net.inet.udp.blackhole' => '1',
152
	'net.inet.ip.random_id' => '1',
153
	'net.inet.tcp.drop_synfin' => '1',
154
	'net.inet.ip.redirect' => '1',
155
	'net.inet6.ip6.redirect' => '1',
156
	'net.inet6.ip6.use_tempaddr' => '0',
157
	'net.inet6.ip6.prefer_tempaddr' => '0',
158
	'net.inet.tcp.syncookies' => '1',
159
	'net.inet.tcp.recvspace' => '65228',
160
	'net.inet.tcp.sendspace' => '65228',
161
	'net.inet.tcp.delayed_ack' => '0',
162
	'net.inet.udp.maxdgram' => '57344',
163
	'net.link.bridge.pfil_onlyip' => '0',
164
	'net.link.bridge.pfil_member' => '1',
165
	'net.link.bridge.pfil_bridge' => '0',
166
	'net.link.tap.user_open' => '1',
167
	'net.link.vlan.mtag_pcp' => '1',
168
	'kern.randompid' => '347',
169
	'net.inet.ip.intr_queue_maxlen' => '1000',
170
	'hw.syscons.kbd_reboot' => '0',
171
	'net.inet.tcp.log_debug' => '0',
172
	'net.inet.tcp.tso' => '1',
173
	'net.inet.icmp.icmplim' => '0',
174
	'vfs.read_max' => '32',
175
	'kern.ipc.maxsockbuf' => '4262144',
176
	'net.inet.ip.process_options' => 0,
177
	'kern.random.harvest.mask' => '351',
178
	'net.route.netisr_maxqlen' => 1024,
179
	'net.inet.udp.checksum' => 1,
180
	'net.inet.icmp.reply_from_interface' => 1,
181
	'net.inet6.ip6.rfc6204w3' => 1,
182
	'net.key.preferred_oldsa' => '0',
183
	'net.inet.carp.senderr_demotion_factor' => 0, /* Do not demote CARP for interface send errors */
184
	'net.pfsync.carp_demotion_factor' => 0, /* Do not demote CARP for pfsync errors */
185
	'net.raw.recvspace' => 65536,
186
	'net.raw.sendspace' => 65536,
187
	'net.inet.raw.recvspace' => 131072,
188
	'net.inet.raw.maxdgram' => 131072,
189
	'kern.corefile' => '/root/%N.core' /* Write all core files to /root/ so they do not consume space on other slices */
190
];
191

    
192
$machine_type = php_uname('m');
193
if (($machine_type == 'arm') || ($machine_type == 'arm64')) {
194
	$sysctls['kern.shutdown.secure_halt'] = 1;
195
}
196

    
197
/* Read all XML files in following dir and load menu entries */
198
$g['ext_menu_path'] = '/usr/local/share/'. g_get('product_name') . '/menu';
199

    
200
/* Cache file used to store pfSense version */
201
$g['version_cache_file'] = g_get('varrun_path') . '/' . g_get('product_name') . '_version';
202
$g['version_cache_refresh'] = 7200; /* 2h */
203

    
204
if (file_exists(g_get('cf_conf_path') . '/enableserial_force')) {
205
	$g['enableserial_force'] = true;
206
}
207

    
208
global $config_parsed;
209
$config_parsed = false;
210

    
211
/* Factory default check IP service. */
212
global $factory_default_checkipservice;
213
$factory_default_checkipservice = [
214
	'enable' => true,
215
	'name' => 'Default',
216
	'url' => 'http://checkip.dyndns.org',
217
	'descr' => 'Default Check IP Service',
218
];
219

    
220
global $dyndns_split_domain_types;
221
$dyndns_split_domain_types = ['namecheap', 'cloudflare', 'cloudflare-v6', 'gratisdns', 'cloudns', 'godaddy', 'godaddy-v6', 'linode', 'linode-v6'];
222

    
223
// pf tokens from FreeBSD source /sbin/pfctl/parse.y
224
global $pf_reserved_keywords;
225
$pf_reserved_keywords = [
226
	// Original tokens
227
	'all', 'allow-opts', 'altq', 'anchor', 'antispoof', 'any', 'bandwidth', 'binat', 'binat-anchor', 'bitmask',
228
	'block', 'block-policy', 'buckets', 'cbq', 'code', 'codelq', 'crop', 'debug', 'divert-reply', 'divert-to',
229
	'dnpipe', 'dnqueue', 'drop', 'drop-ovl', 'dup-to', 'ether', 'fail-policy', 'fairq', 'fastroute', 'file',
230
	'fingerprints', 'flags', 'floating', 'flush', 'for', 'fragment', 'from', 'global', 'group', 'hfsc', 'hogs',
231
	'hostid', 'icmp-type', 'icmp6-type', 'if-bound', 'in', 'include', 'inet', 'inet6', 'interval', 'keep',
232
	'keepcounters', 'l3', 'label', 'limit', 'linkshare', 'load', 'log', 'loginterface', 'map-e-portset', 'match',
233
	'max', 'max-mss', 'max-src-conn', 'max-src-conn-rate', 'max-src-nodes', 'max-src-states', 'min-ttl', 'modulate',
234
	'nat', 'nat-anchor', 'no', 'no-df', 'no-route', 'no-sync', 'on', 'optimization', 'os', 'out', 'overload',
235
	'pass', 'port', 'prio', 'priority', 'priq', 'probability', 'proto', 'qlimit', 'queue', 'quick', 'random',
236
	'random-id', 'rdr', 'rdr-anchor', 'realtime', 'reassemble', 'reply-to', 'require-order', 'return', 'return-icmp',
237
	'return-icmp6', 'return-rst', 'ridentifier', 'round-robin', 'route', 'route-to', 'rtable', 'rule',
238
	'ruleset-optimization', 'scrub', 'set', 'set-tos', 'skip', 'sloppy', 'source-hash', 'source-track', 'state',
239
	'state-defaults', 'state-policy', 'static-port', 'sticky-address', 'syncookies', 'synproxy', 'table', 'tag',
240
	'tagged', 'target', 'tbrsize', 'timeout', 'to', 'tos', 'ttl', 'upperlimit', 'urpf-failed', 'user',
241
	// Original tokens in fuzzy format
242
	'allowopts', 'binatanchor', 'blockpolicy', 'divertreply', 'divertto', 'duptoicmptype', 'icmp6type', 'ifboundmaxmss',
243
	'maxsrcconn', 'maxsrcconnrate', 'maxsrcnodes', 'maxsrcstates', 'minttl', 'natanchornodf', 'noroute', 'nosync',
244
	'randomidrdranchor', 'replyto', 'requireorderreturnicmp', 'returnicmp6', 'returnrstroundrobinrouteto',
245
	'ruleset_optimization', 'settos', 'sourcehash', 'sourcetrackstatedefaults', 'statepolicy', 'staticport',
246
	'stickyaddress', 'urpffailed', 'dropovl', 'failpolicy', 'mapeportset',
247
	// Custom tokens
248
	'arrow', 'codel', 'error', 'filename', 'fragcrop', 'fragdrop', 'IPsec', 'L2TP', 'maximummin', 'OpenVPN',
249
	'pppoe', 'pptp'
250
];
251

    
252
/* Reserved table names to avoid collision */
253
global $reserved_table_names;
254
$reserved_table_names = [
255
	'bogons',
256
	'bogonsv6',
257
	'negate_networks',
258
	'snort2c',
259
	'sshguard',
260
	'tonatsubnets',
261
	'virusprot',
262
	'vpn_networks',
263
];
264

    
265
/* VLAN Prio values. */
266
global $vlanprio_values;
267
$vlanprio_values = [
268
	'bk' => 0,
269
	'be' => 1,
270
	'ee' => 2,
271
	'ca' => 3,
272
	'vi' => 4,
273
	'vo' => 5,
274
	'ic' => 6,
275
	'nc' => 7,
276
];
277

    
278
global $vlanprio;
279
$vlanprio = [
280
	'bk' => 'Background (BK, 0)',
281
	'be' => 'Best Effort (BE, 1)',
282
	'ee' => 'Excellent Effort (EE, 2)',
283
	'ca' => 'Critical Applications (CA, 3)',
284
	'vi' => 'Video (VI, 4)',
285
	'vo' => 'Voice (VO, 5)',
286
	'ic' => 'Internetwork Control (IC, 6)',
287
	'nc' => 'Network Control (NC, 7)',
288
];
289

    
290
global $system_log_files;
291
$system_log_files = [
292
	'system', 'filter', 'dhcpd', 'vpn', 'poes', 'l2tps', 'openvpn',
293
	'portalauth', 'ipsec', 'ppp', 'wireless', 'nginx', 'ntpd', 'gateways',
294
	'resolver', 'routing', 'auth'
295
];
296

    
297
global $system_log_non_syslog_files;
298
$system_log_non_syslog_files = ['dmesg.boot', 'utx.log', 'userlog'];
299

    
300
global $system_log_compression_types;
301
$system_log_compression_types = [
302
	'bzip2' => [
303
			'flag' => 'J',
304
			'cat' => '/usr/bin/bzcat -qf',
305
			'ext' => 'bz2',
306
	],
307
	'gzip' => [
308
			'flag' => 'Z',
309
			'cat' => '/usr/bin/zcat -qf',
310
			'ext' => 'gz',
311
	],
312
	'xz' => [
313
			'flag' => 'X',
314
			'cat' => '/usr/bin/xzcat -qf',
315
			'ext' => 'xz',
316
	],
317
	'zstd' => [
318
			'flag' => 'Y',
319
			'cat' => '/usr/bin/zstdcat -qqf',
320
			'ext' => 'zst',
321
	],
322
	'none' => [
323
			'flag' => '',
324
			'cat' => '/bin/cat',
325
			'ext' => '',
326
	],
327
];
328

    
329
global $ddnsdomainkeyalgorithms;
330
$ddnsdomainkeyalgorithms = [
331
	'hmac-md5' => 'HMAC-MD5 (legacy default)',
332
	'hmac-sha1' => 'HMAC-SHA1',
333
	'hmac-sha224' => 'HMAC-SHA224',
334
	'hmac-sha256' => 'HMAC-SHA256 (current bind9 default)',
335
	'hmac-sha384' => 'HMAC-SHA384',
336
	'hmac-sha512' => 'HMAC-SHA512 (most secure)',
337
];
338

    
339
global $ipsec_filtermodes;
340
$ipsec_filtermodes = [
341
	'enc' => 'Filter IPsec Tunnel, Transport, and VTI on IPsec tab (enc0)',
342
	'if_ipsec' => 'Filter IPsec VTI and Transport on assigned interfaces, block all tunnel mode traffic',
343
];
344

    
345
global $ipsec_filter_sysctl;
346
$ipsec_filter_sysctl = [
347
	'enc' => [
348
		'net.inet.ipsec.filtertunnel'   => '0x0000',
349
		'net.inet6.ipsec6.filtertunnel' => '0x0000',
350
		'net.enc.out.ipsec_bpf_mask'    => '0x0001',
351
		'net.enc.out.ipsec_filter_mask' => '0x0001',
352
		'net.enc.in.ipsec_bpf_mask'     => '0x0002',
353
		'net.enc.in.ipsec_filter_mask'  => '0x0002',
354
	],
355
	'if_ipsec' => [
356
		'net.inet.ipsec.filtertunnel'   => '0x0001',
357
		'net.inet6.ipsec6.filtertunnel' => '0x0001',
358
		'net.enc.out.ipsec_bpf_mask'    => '0x0000',
359
		'net.enc.out.ipsec_filter_mask' => '0x0000',
360
		'net.enc.in.ipsec_bpf_mask'     => '0x0000',
361
		'net.enc.in.ipsec_filter_mask'  => '0x0000',
362
	],
363
];
364

    
365
global $vpn_and_ppp_ifs;
366
$vpn_and_ppp_ifs = ['l2tp', 'pppoe', 'enc0', 'openvpn'];
367

    
368
global $ssh_keys;
369
$ssh_keys = [
370
	['type' => 'rsa', 'suffix' => 'rsa_'],
371
	['type' => 'ed25519', 'suffix' => 'ed25519_'],
372
];
373

    
374
global $sshConfigDir;
375
$sshConfigDir = '/etc/ssh';
376

    
377
global $lagg_hash_list;
378
$lagg_hash_list = [
379
	'l2,l3,l4' => 'Layer 2/3/4 (default)',
380
	'l2' => 'Layer 2 (MAC Address)',
381
	'l3' => 'Layer 3 (IP Address)',
382
	'l4' => 'Layer 4 (Port Number)',
383
	'l2,l3' => 'Layer 2/3 (MAC + IP)',
384
	'l3,l4' => 'Layer 3/4 (IP + Port)',
385
	'l2,l4' => 'Layer 2/4 (MAC + Port)',
386
];
387

    
388
/**
389
 * Check if the global $g variable contains a $key
390
 *
391
 * @param string $key The key
392
 * @param bool $isset Also perform isset check
393
 *
394
 * @return bool
395
 */
396
function g_has(string $key, bool $isset = false) : bool
397
{
398
	global $g;
399
	return (array_key_exists($key, $g) && (!$isset || isset($g[$key])));
400
}
401

    
402
/**
403
 * Get the global $g variable value by $key
404
 *
405
 * @param string $key The key
406
 * @param mixed $default The value to return on a key miss
407
 *
408
 * @return mixed
409
 */
410
function g_get(string $key, mixed $default = null) : mixed
411
{
412
	global $g;
413
	return (g_has($key, true) ? $g[$key] : $default);
414
}
415

    
416
/**
417
 * Set the global $g variable value by $key
418
 *
419
 * @param string $key The key
420
 * @param mixed $value The value
421
 * @param bool $force Force set (can replace) the value
422
 *
423
 * @return mixed
424
 */
425
function g_set(string $key, mixed $value, bool $force = false) : mixed
426
{
427
	global $g;
428
	if ($force || !g_has($key, true)) {
429
		$g[$key] = $value;
430
	}
431
	return (g_get($key));
432
}
433

    
434
/**
435
 * Unset the global $g variable value by $key
436
 *
437
 * @param string $key The key
438
 *
439
 * @return void
440
 */
441
function g_unset(string $key) : void
442
{
443
	global $g;
444
	if (g_has($key)) {
445
		unset($g[$key]);
446
	}
447
}
448

    
449
/**
450
 * Determine if the system is currently booting
451
 *
452
 * @return bool
453
 */
454
function is_platform_booting() : bool
455
{
456
	return (g_get('booting', false) || file_exists(g_get('varrun_path') . '/booting'));
457
}
458

    
459
/**
460
 * Determine if PHP is executing in cli context
461
 *
462
 * @return bool
463
 */
464
function is_cli_sapi() : bool
465
{
466
	if (defined('STDIN')) {
467
		return (true);
468
	}
469

    
470
	if (PHP_SAPI === 'cli') {
471
		return (true);
472
	}
473

    
474
	if (array_key_exists('SHELL', $_ENV)) {
475
		return (true);
476
	}
477

    
478
	return (false);
479
}
480

    
481
/**
482
 * Determine if the system is booting
483
 *
484
 * @deprecated Prefer the use of is_platform_booting
485
 *
486
 * @param bool $only_on_console Require cli execution context
487
 *
488
 * @return bool
489
 */
490
function platform_booting(bool $only_on_console = false) : bool
491
{
492
	return (is_platform_booting() && (!$only_on_console || is_cli_sapi()));
493
}
494

    
495
/**
496
 * Check if a file can be included
497
 *
498
 * @param string $filename
499
 *
500
 * @return bool
501
 */
502
function can_include(string $filename) : bool
503
{
504
	// short-circuit on absolute paths before checking relative include paths
505
	return (file_exists($filename) || (bool) stream_resolve_include_path($filename));
506
}
507

    
508
// source pfSense Plus specific globals last
509
if (can_include('globals.plus.inc')) {
510
	include_once('globals.plus.inc');
511
}
(19-19/61)