Project

General

Profile

Download (16.2 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-2024 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' => '23.3',
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,/var/lib/kea/dhcp4.leases}',
108
		'dhcpdv6' => '{/var/dhcpd/var/db/dhcpd6.leases,/var/lib/kea/dhcp6.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 = [
222
	'cloudflare', 'cloudflare-v6',
223
	'cloudns',
224
	"digitalocean", "digitalocean-v6",
225
	"gandi-livedns", "gandi-livedns-v6",
226
	'godaddy', 'godaddy-v6',
227
	'gratisdns',
228
	'linode', 'linode-v6',
229
	"mythicbeasts", "mythicbeasts-v6",
230
	'namecheap',
231
	"name.com", "name.com-v6",
232
	"onecom", "onecom-v6",
233
	'porkbun', 'porkbun-v6',
234
	"yandex", "yandex-v6",
235
];
236

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

    
266
/* Reserved table names to avoid collision */
267
global $reserved_table_names;
268
$reserved_table_names = [
269
	'bogons',
270
	'bogonsv6',
271
	'negate_networks',
272
	'snort2c',
273
	'sshguard',
274
	'tonatsubnets',
275
	'virusprot',
276
	'vpn_networks',
277
];
278

    
279
/* VLAN Prio values. */
280
global $vlanprio_values;
281
$vlanprio_values = [
282
	'bk' => 0,
283
	'be' => 1,
284
	'ee' => 2,
285
	'ca' => 3,
286
	'vi' => 4,
287
	'vo' => 5,
288
	'ic' => 6,
289
	'nc' => 7,
290
];
291

    
292
global $vlanprio;
293
$vlanprio = [
294
	'bk' => 'Background (BK, 0)',
295
	'be' => 'Best Effort (BE, 1)',
296
	'ee' => 'Excellent Effort (EE, 2)',
297
	'ca' => 'Critical Applications (CA, 3)',
298
	'vi' => 'Video (VI, 4)',
299
	'vo' => 'Voice (VO, 5)',
300
	'ic' => 'Internetwork Control (IC, 6)',
301
	'nc' => 'Network Control (NC, 7)',
302
];
303

    
304
global $system_log_files;
305
$system_log_files = [
306
	'system', 'filter', 'dhcpd', 'vpn', 'poes', 'l2tps', 'openvpn',
307
	'portalauth', 'ipsec', 'ppp', 'wireless', 'nginx', 'ntpd', 'gateways',
308
	'resolver', 'routing', 'auth'
309
];
310

    
311
global $system_log_non_syslog_files;
312
$system_log_non_syslog_files = ['dmesg.boot', 'utx.log', 'userlog'];
313

    
314
global $system_log_compression_types;
315
$system_log_compression_types = [
316
	'bzip2' => [
317
			'flag' => 'J',
318
			'cat' => '/usr/bin/bzcat -qf',
319
			'ext' => 'bz2',
320
	],
321
	'gzip' => [
322
			'flag' => 'Z',
323
			'cat' => '/usr/bin/zcat -qf',
324
			'ext' => 'gz',
325
	],
326
	'xz' => [
327
			'flag' => 'X',
328
			'cat' => '/usr/bin/xzcat -qf',
329
			'ext' => 'xz',
330
	],
331
	'zstd' => [
332
			'flag' => 'Y',
333
			'cat' => '/usr/bin/zstdcat -qqf',
334
			'ext' => 'zst',
335
	],
336
	'none' => [
337
			'flag' => '',
338
			'cat' => '/bin/cat',
339
			'ext' => '',
340
	],
341
];
342

    
343
global $ddnsdomainkeyalgorithms;
344
$ddnsdomainkeyalgorithms = [
345
	'hmac-md5' => 'HMAC-MD5 (legacy default)',
346
	'hmac-sha1' => 'HMAC-SHA1',
347
	'hmac-sha224' => 'HMAC-SHA224',
348
	'hmac-sha256' => 'HMAC-SHA256 (current bind9 default)',
349
	'hmac-sha384' => 'HMAC-SHA384',
350
	'hmac-sha512' => 'HMAC-SHA512 (most secure)',
351
];
352

    
353
global $ipsec_filtermodes;
354
$ipsec_filtermodes = [
355
	'enc' => 'Filter IPsec Tunnel, Transport, and VTI on IPsec tab (enc0)',
356
	'if_ipsec' => 'Filter IPsec VTI and Transport on assigned interfaces, block all tunnel mode traffic',
357
];
358

    
359
global $ipsec_filter_sysctl;
360
$ipsec_filter_sysctl = [
361
	'enc' => [
362
		'net.inet.ipsec.filtertunnel'   => '0x0000',
363
		'net.inet6.ipsec6.filtertunnel' => '0x0000',
364
		'net.enc.out.ipsec_bpf_mask'    => '0x0001',
365
		'net.enc.out.ipsec_filter_mask' => '0x0001',
366
		'net.enc.in.ipsec_bpf_mask'     => '0x0002',
367
		'net.enc.in.ipsec_filter_mask'  => '0x0002',
368
	],
369
	'if_ipsec' => [
370
		'net.inet.ipsec.filtertunnel'   => '0x0001',
371
		'net.inet6.ipsec6.filtertunnel' => '0x0001',
372
		'net.enc.out.ipsec_bpf_mask'    => '0x0000',
373
		'net.enc.out.ipsec_filter_mask' => '0x0000',
374
		'net.enc.in.ipsec_bpf_mask'     => '0x0000',
375
		'net.enc.in.ipsec_filter_mask'  => '0x0000',
376
	],
377
];
378

    
379
global $vpn_and_ppp_ifs;
380
$vpn_and_ppp_ifs = ['l2tp', 'pppoe', 'enc0', 'openvpn'];
381

    
382
global $ssh_keys;
383
$ssh_keys = [
384
	['type' => 'rsa', 'suffix' => 'rsa_'],
385
	['type' => 'ed25519', 'suffix' => 'ed25519_'],
386
];
387

    
388
global $sshConfigDir;
389
$sshConfigDir = '/etc/ssh';
390

    
391
global $lagg_hash_list;
392
$lagg_hash_list = [
393
	'l2,l3,l4' => 'Layer 2/3/4 (default)',
394
	'l2' => 'Layer 2 (MAC Address)',
395
	'l3' => 'Layer 3 (IP Address)',
396
	'l4' => 'Layer 4 (Port Number)',
397
	'l2,l3' => 'Layer 2/3 (MAC + IP)',
398
	'l3,l4' => 'Layer 3/4 (IP + Port)',
399
	'l2,l4' => 'Layer 2/4 (MAC + Port)',
400
];
401

    
402
/**
403
 * Check if the global $g variable contains a $key
404
 *
405
 * @param string $key The key
406
 * @param bool $isset Also perform isset check
407
 *
408
 * @return bool
409
 */
410
function g_has(string $key, bool $isset = false) : bool
411
{
412
	global $g;
413
	return (array_key_exists($key, $g) && (!$isset || isset($g[$key])));
414
}
415

    
416
/**
417
 * Get the global $g variable value by $key
418
 *
419
 * @param string $key The key
420
 * @param mixed $default The value to return on a key miss
421
 *
422
 * @return mixed
423
 */
424
function g_get(string $key, mixed $default = null) : mixed
425
{
426
	global $g;
427
	return (g_has($key, true) ? $g[$key] : $default);
428
}
429

    
430
/**
431
 * Set the global $g variable value by $key
432
 *
433
 * @param string $key The key
434
 * @param mixed $value The value
435
 * @param bool $force Force set (can replace) the value
436
 *
437
 * @return mixed
438
 */
439
function g_set(string $key, mixed $value, bool $force = false) : mixed
440
{
441
	global $g;
442
	if ($force || !g_has($key, true)) {
443
		$g[$key] = $value;
444
	}
445
	return (g_get($key));
446
}
447

    
448
/**
449
 * Unset the global $g variable value by $key
450
 *
451
 * @param string $key The key
452
 *
453
 * @return void
454
 */
455
function g_unset(string $key) : void
456
{
457
	global $g;
458
	if (g_has($key)) {
459
		unset($g[$key]);
460
	}
461
}
462

    
463
/**
464
 * Determine if the system is currently booting
465
 *
466
 * @return bool
467
 */
468
function is_platform_booting() : bool
469
{
470
	return (g_get('booting', false) || file_exists(g_get('varrun_path') . '/booting'));
471
}
472

    
473
/**
474
 * Determine if PHP is executing in cli context
475
 *
476
 * @return bool
477
 */
478
function is_cli_sapi() : bool
479
{
480
	if (defined('STDIN')) {
481
		return (true);
482
	}
483

    
484
	if (PHP_SAPI === 'cli') {
485
		return (true);
486
	}
487

    
488
	if (array_key_exists('SHELL', $_ENV)) {
489
		return (true);
490
	}
491

    
492
	return (false);
493
}
494

    
495
/**
496
 * Determine if the system is booting
497
 *
498
 * @deprecated Prefer the use of is_platform_booting
499
 *
500
 * @param bool $only_on_console Require cli execution context
501
 *
502
 * @return bool
503
 */
504
function platform_booting(bool $only_on_console = false) : bool
505
{
506
	return (is_platform_booting() && (!$only_on_console || is_cli_sapi()));
507
}
508

    
509
/**
510
 * Check if a file can be included
511
 *
512
 * @param string $filename
513
 *
514
 * @return bool
515
 */
516
function can_include(string $filename) : bool
517
{
518
	// short-circuit on absolute paths before checking relative include paths
519
	return (file_exists($filename) || (bool) stream_resolve_include_path($filename));
520
}
521

    
522
/**
523
 * Get a list of known protocols
524
 *
525
 * @param string $type Filter the returned list based on the type
526
 *
527
 * @return array
528
 */
529
function get_ipprotocols(?string $type = ''):array {
530
	$exclude = [];
531
	$ipprotocols = [
532
		'any' => gettext('Any'),
533
		'tcp' => 'TCP',
534
		'udp' => 'UDP',
535
		'tcp/udp' => 'TCP/UDP',
536
		'icmp' => 'ICMP',
537
		'esp' => 'ESP',
538
		'ah' => 'AH',
539
		'gre' => 'GRE',
540
		'etherip' => 'EoIP',
541
		'ipv6' => 'IPV6',
542
		'igmp' => 'IGMP',
543
		'pim' => 'PIM',
544
		'ospf' => 'OSPF',
545
		'sctp' => 'SCTP',
546
		'carp' => 'CARP',
547
		'pfsync' => 'PFSYNC'
548
	];
549

    
550
	switch ($type) {
551
		case 'portsonly':
552
			$ipprotocols = [
553
				'tcp' => 'TCP',
554
				'udp' => 'UDP',
555
				'tcp/udp' => 'TCP/UDP',
556
				'sctp' => 'SCTP'
557
			];
558
			break;
559
		case 'outboundnat':
560
			$exclude = ['EoIP', 'PIM', 'OSPF'];
561
			break;
562
		case 'portforward':
563
			$exclude = ['EoIP', 'CARP', 'PFSYNC'];
564
			break;
565
		default:
566
			break;
567
	}
568

    
569
	return array_diff($ipprotocols, $exclude);
570
}
571

    
572
// source pfSense Plus specific globals last
573
if (can_include('globals.plus.inc')) {
574
	include_once('globals.plus.inc');
575
}
(19-19/61)