Project

General

Profile

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

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

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

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

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

    
206
global $config_parsed;
207
$config_parsed = false;
208

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

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

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

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

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

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

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

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

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

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

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

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

    
363
global $vpn_and_ppp_ifs;
364
$vpn_and_ppp_ifs = ['l2tp', 'pppoe', 'enc0', 'openvpn'];
365

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

    
372
global $sshConfigDir;
373
$sshConfigDir = '/etc/ssh';
374

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

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

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

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

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

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

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

    
468
	if (PHP_SAPI === 'cli') {
469
		return (true);
470
	}
471

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

    
476
	return (false);
477
}
478

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

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

    
506
// source pfSense Plus specific globals last
507
if (can_include('globals.plus.inc')) {
508
	include_once('globals.plus.inc');
509
}
(20-20/62)