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-2022 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
|
global $g;
|
47
|
$g = array(
|
48
|
"acbbackuppath" => "/cf/conf/acb/",
|
49
|
"event_address" => "unix:///var/run/check_reload_status",
|
50
|
"factory_shipped_username" => "admin",
|
51
|
"factory_shipped_password" => "pfsense",
|
52
|
"upload_path" => "/root",
|
53
|
"dhcpd_chroot_path" => "/var/dhcpd",
|
54
|
"unbound_chroot_path" => "/var/unbound",
|
55
|
"var_path" => "/var",
|
56
|
"varrun_path" => "/var/run",
|
57
|
"varetc_path" => "/var/etc",
|
58
|
"vardb_path" => "/var/db",
|
59
|
"varlog_path" => "/var/log",
|
60
|
"etc_path" => "/etc",
|
61
|
"tmp_path" => "/tmp",
|
62
|
"tmp_path_user_code" => "/tmp/user_code",
|
63
|
"conf_path" => "/conf",
|
64
|
"conf_default_path" => "/conf.default",
|
65
|
"cf_path" => "/cf",
|
66
|
"cf_conf_path" => "/cf/conf",
|
67
|
"www_path" => "/usr/local/www",
|
68
|
"xml_rootobj" => "pfsense",
|
69
|
"admin_group" => "admins",
|
70
|
"product_name" => "pfSense",
|
71
|
"product_label" => "pfSense",
|
72
|
"product_label_html" => "Netgate pfSense<sup>®</sup>",
|
73
|
"product_version" => trim(file_get_contents("/etc/version"), " \n"),
|
74
|
"product_copyright_years" => "2004 - ".date("Y"),
|
75
|
"disablehelpmenu" => false,
|
76
|
"disablehelpicon" => false,
|
77
|
"disablecrashreporter" => false,
|
78
|
"debug" => false,
|
79
|
"latest_config" => "22.7",
|
80
|
"minimum_ram_warning" => "101",
|
81
|
"minimum_ram_warning_text" => "128 MB",
|
82
|
"wan_interface_name" => "wan",
|
83
|
"captiveportal_path" => "/usr/local/captiveportal",
|
84
|
"captiveportal_element_path" => "/var/db/cpelements",
|
85
|
"captiveportal_element_sizelimit" => 1048576,
|
86
|
"captiveportal_rules_interval" => 50,
|
87
|
"services_dhcp_server_enable" => true,
|
88
|
"wireless_regex" => "/^(ath|athp|bwi|bwn|ipw|iwi|iwm|iwn|malo|mwl|ral|rsu|rtwn|rum|run|uath|upgt|ural|urtw|urtwn|wi|wpi|wtap|zyd)[0-9]+/",
|
89
|
"help_base_url" => "/help.php",
|
90
|
"pkg_prefix" => "pfSense-pkg-",
|
91
|
"default_timezone" => "Etc/UTC",
|
92
|
"language" => "en_US",
|
93
|
"default_config_backup_count" => 30,
|
94
|
"default_cert_expiredays" => 27,
|
95
|
"default_log_entries" => 500,
|
96
|
"default_log_size" => 512000,
|
97
|
"minimumtableentries_bogonsv6" => 400000,
|
98
|
"alternativemetaports" => array("vmware", "php72", "php73", "php74"),
|
99
|
"backuppath" => array(
|
100
|
'captiveportal' => "/var/db/captiveportal*.db",
|
101
|
'dhcpd' => "/var/dhcpd/var/db/dhcpd.leases",
|
102
|
'dhcpdv6' => "/var/dhcpd/var/db/dhcpd6.leases",
|
103
|
'voucher' => "/var/db/voucher_*.db"
|
104
|
),
|
105
|
"cp_prefix" => 'cpzoneid',
|
106
|
"booting" => false
|
107
|
);
|
108
|
|
109
|
/* IP TOS flags */
|
110
|
$iptos = array("lowdelay", "throughput", "reliability");
|
111
|
|
112
|
/* TCP flags */
|
113
|
$tcpflags = array("syn", "ack", "fin", "rst", "psh", "urg", "ece", "cwr");
|
114
|
|
115
|
if (file_exists("/etc/version.patch")) {
|
116
|
$g["product_version_patch"] = trim(file_get_contents("/etc/version.patch"), " \n");
|
117
|
} else {
|
118
|
$g["product_version_patch"] = "0";
|
119
|
}
|
120
|
|
121
|
$g['product_version_string'] = $g['product_version'];
|
122
|
if (is_numeric($g["product_version_patch"]) && $g["product_version_patch"] != "0") {
|
123
|
$g['product_version_string'] .= "-p{$g['product_version_patch']}";
|
124
|
}
|
125
|
|
126
|
if (file_exists("{$g['etc_path']}/default-config-flavor")) {
|
127
|
$flavor_array = file("{$g['etc_path']}/default-config-flavor");
|
128
|
$g['default-config-flavor'] = chop($flavor_array[0]);
|
129
|
} else {
|
130
|
$g['default-config-flavor'] = '';
|
131
|
}
|
132
|
|
133
|
$g['openvpn_base'] = "{$g['varetc_path']}/openvpn";
|
134
|
|
135
|
/* Default sysctls */
|
136
|
$sysctls = array("net.inet.ip.portrange.first" => "1024",
|
137
|
"net.inet.tcp.blackhole" => "2",
|
138
|
"net.inet.udp.blackhole" => "1",
|
139
|
"net.inet.ip.random_id" => "1",
|
140
|
"net.inet.tcp.drop_synfin" => "1",
|
141
|
"net.inet.ip.redirect" => "1",
|
142
|
"net.inet6.ip6.redirect" => "1",
|
143
|
"net.inet6.ip6.use_tempaddr" => "0",
|
144
|
"net.inet6.ip6.prefer_tempaddr" => "0",
|
145
|
"net.inet.tcp.syncookies" => "1",
|
146
|
"net.inet.tcp.recvspace" => "65228",
|
147
|
"net.inet.tcp.sendspace" => "65228",
|
148
|
"net.inet.tcp.delayed_ack" => "0",
|
149
|
"net.inet.udp.maxdgram" => "57344",
|
150
|
"net.link.bridge.pfil_onlyip" => "0",
|
151
|
"net.link.bridge.pfil_member" => "1",
|
152
|
"net.link.bridge.pfil_bridge" => "0",
|
153
|
"net.link.tap.user_open" => "1",
|
154
|
"net.link.vlan.mtag_pcp" => "1",
|
155
|
"kern.randompid" => "347",
|
156
|
"net.inet.ip.intr_queue_maxlen" => "1000",
|
157
|
"hw.syscons.kbd_reboot" => "0",
|
158
|
"net.inet.tcp.log_debug" => "0",
|
159
|
"net.inet.tcp.tso" => "1",
|
160
|
"net.inet.icmp.icmplim" => "0",
|
161
|
"vfs.read_max" => "32",
|
162
|
"kern.ipc.maxsockbuf" => "4262144",
|
163
|
"net.inet.ip.process_options" => 0,
|
164
|
"kern.random.harvest.mask" => "351",
|
165
|
"net.route.netisr_maxqlen" => 1024,
|
166
|
"net.inet.udp.checksum" => 1,
|
167
|
"net.inet.icmp.reply_from_interface" => 1,
|
168
|
"net.inet6.ip6.rfc6204w3" => 1,
|
169
|
"net.key.preferred_oldsa" => "0",
|
170
|
"net.inet.carp.senderr_demotion_factor" => 0, /* Do not demote CARP for interface send errors */
|
171
|
"net.pfsync.carp_demotion_factor" => 0, /* Do not demote CARP for pfsync errors */
|
172
|
"net.raw.recvspace" => 65536,
|
173
|
"net.raw.sendspace" => 65536,
|
174
|
"net.inet.raw.recvspace" => 131072,
|
175
|
"net.inet.raw.maxdgram" => 131072,
|
176
|
"kern.corefile" => "/root/%N.core" /* Write all core files to /root/ so they do not consume space on other slices */
|
177
|
);
|
178
|
|
179
|
$machine_type = php_uname('m');
|
180
|
if (($machine_type == 'arm') || ($machine_type == 'arm64')) {
|
181
|
$sysctls['kern.shutdown.secure_halt'] = 1;
|
182
|
}
|
183
|
|
184
|
/* Include override values for the above if needed. If the file doesn't exist, don't try to load it. */
|
185
|
if (file_exists("/etc/inc/globals_override.inc")) {
|
186
|
@include_once("globals_override.inc");
|
187
|
}
|
188
|
|
189
|
/* Read all XML files in following dir and load menu entries */
|
190
|
$g["ext_menu_path"] = "/usr/local/share/{$g['product_name']}/menu";
|
191
|
|
192
|
/* Cache file used to store pfSense version */
|
193
|
$g["version_cache_file"] = "{$g['varrun_path']}/{$g['product_name']}_version";
|
194
|
$g['version_cache_refresh'] = 2 * 60 * 60; /* 2h */
|
195
|
|
196
|
function platform_booting($on_console = false) {
|
197
|
global $g;
|
198
|
|
199
|
if ($g['booting'] || file_exists("{$g['varrun_path']}/booting")) {
|
200
|
if ($on_console == false || php_sapi_name() != 'fpm-fcgi') {
|
201
|
return true;
|
202
|
}
|
203
|
}
|
204
|
|
205
|
return false;
|
206
|
}
|
207
|
|
208
|
if (file_exists("{$g['cf_conf_path']}/enableserial_force")) {
|
209
|
$g['enableserial_force'] = true;
|
210
|
}
|
211
|
|
212
|
$config_parsed = false;
|
213
|
|
214
|
/* Factory default check IP service. */
|
215
|
$factory_default_checkipservice = array(
|
216
|
"enable" => true,
|
217
|
"name" => 'Default',
|
218
|
"url" => 'http://checkip.dyndns.org',
|
219
|
// "username" => '',
|
220
|
// "password" => '',
|
221
|
// "verifysslpeer" => true,
|
222
|
"descr" => 'Default Check IP Service'
|
223
|
);
|
224
|
|
225
|
$dyndns_split_domain_types = array("namecheap", "cloudflare", "cloudflare-v6", "gratisdns", "cloudns", "godaddy", "godaddy-v6", "linode", "linode-v6");
|
226
|
|
227
|
// pf tokens from FreeBSD source /sbin/pfctl/parse.y
|
228
|
global $pf_reserved_keywords;
|
229
|
$pf_reserved_keywords = array(
|
230
|
// Original tokens
|
231
|
'all', 'allow-opts', 'altq', 'anchor', 'antispoof', 'any', 'bandwidth', 'binat', 'binat-anchor', 'bitmask',
|
232
|
'block', 'block-policy', 'buckets', 'cbq', 'code', 'codelq', 'crop', 'debug', 'divert-reply', 'divert-to',
|
233
|
'dnpipe', 'dnqueue', 'drop', 'drop-ovl', 'dup-to', 'ether', 'fail-policy', 'fairq', 'fastroute', 'file',
|
234
|
'fingerprints', 'flags', 'floating', 'flush', 'for', 'fragment', 'from', 'global', 'group', 'hfsc', 'hogs',
|
235
|
'hostid', 'icmp-type', 'icmp6-type', 'if-bound', 'in', 'include', 'inet', 'inet6', 'interval', 'keep',
|
236
|
'keepcounters', 'l3', 'label', 'limit', 'linkshare', 'load', 'log', 'loginterface', 'map-e-portset', 'match',
|
237
|
'max', 'max-mss', 'max-src-conn', 'max-src-conn-rate', 'max-src-nodes', 'max-src-states', 'min-ttl', 'modulate',
|
238
|
'nat', 'nat-anchor', 'no', 'no-df', 'no-route', 'no-sync', 'on', 'optimization', 'os', 'out', 'overload',
|
239
|
'pass', 'port', 'prio', 'priority', 'priq', 'probability', 'proto', 'qlimit', 'queue', 'quick', 'random',
|
240
|
'random-id', 'rdr', 'rdr-anchor', 'realtime', 'reassemble', 'reply-to', 'require-order', 'return', 'return-icmp',
|
241
|
'return-icmp6', 'return-rst', 'ridentifier', 'round-robin', 'route', 'route-to', 'rtable', 'rule',
|
242
|
'ruleset-optimization', 'scrub', 'set', 'set-tos', 'skip', 'sloppy', 'source-hash', 'source-track', 'state',
|
243
|
'state-defaults', 'state-policy', 'static-port', 'sticky-address', 'syncookies', 'synproxy', 'table', 'tag',
|
244
|
'tagged', 'target', 'tbrsize', 'timeout', 'to', 'tos', 'ttl', 'upperlimit', 'urpf-failed', 'user',
|
245
|
// Original tokens in fuzzy format
|
246
|
'allowopts', 'binatanchor', 'blockpolicy', 'divertreply', 'divertto', 'duptoicmptype', 'icmp6type', 'ifboundmaxmss',
|
247
|
'maxsrcconn', 'maxsrcconnrate', 'maxsrcnodes', 'maxsrcstates', 'minttl', 'natanchornodf', 'noroute', 'nosync',
|
248
|
'randomidrdranchor', 'replyto', 'requireorderreturnicmp', 'returnicmp6', 'returnrstroundrobinrouteto',
|
249
|
'ruleset_optimization', 'settos', 'sourcehash', 'sourcetrackstatedefaults', 'statepolicy', 'staticport',
|
250
|
'stickyaddress', 'urpffailed', 'crop', 'dnpipe', 'dnqueue', 'dropovl', 'ether', 'failpolicy', 'file', 'keepcounters',
|
251
|
'l3', 'mapeportset', 'match', 'ridentifier', 'syncookies',
|
252
|
// Custom tokens
|
253
|
'arrow', 'codel', 'error', 'filename', 'fragcrop', 'fragdrop', 'IPsec', 'L2TP', 'maximummin', 'OpenVPN',
|
254
|
'pppoe', 'pptp'
|
255
|
);
|
256
|
|
257
|
/* Reserved table names to avoid collision */
|
258
|
global $reserved_table_names;
|
259
|
$reserved_table_names = array(
|
260
|
"bogons",
|
261
|
"bogonsv6",
|
262
|
"negate_networks",
|
263
|
"snort2c",
|
264
|
"sshguard",
|
265
|
"tonatsubnets",
|
266
|
"virusprot",
|
267
|
"vpn_networks",
|
268
|
);
|
269
|
|
270
|
/* VLAN Prio values. */
|
271
|
$vlanprio_values = array(
|
272
|
"bk" => 0,
|
273
|
"be" => 1,
|
274
|
"ee" => 2,
|
275
|
"ca" => 3,
|
276
|
"vi" => 4,
|
277
|
"vo" => 5,
|
278
|
"ic" => 6,
|
279
|
"nc" => 7
|
280
|
);
|
281
|
|
282
|
$vlanprio = array(
|
283
|
"bk" => "Background (BK, 0)",
|
284
|
"be" => "Best Effort (BE, 1)",
|
285
|
"ee" => "Excellent Effort (EE, 2)",
|
286
|
"ca" => "Critical Applications (CA, 3)",
|
287
|
"vi" => "Video (VI, 4)",
|
288
|
"vo" => "Voice (VO, 5)",
|
289
|
"ic" => "Internetwork Control (IC, 6)",
|
290
|
"nc" => "Network Control (NC, 7)"
|
291
|
);
|
292
|
|
293
|
global $system_log_files;
|
294
|
$system_log_files = array(
|
295
|
"system", "filter", "dhcpd", "vpn", "poes", "l2tps", "openvpn",
|
296
|
"portalauth", "ipsec", "ppp", "wireless", "nginx", "ntpd", "gateways",
|
297
|
"resolver", "routing", "auth");
|
298
|
|
299
|
global $system_log_non_syslog_files;
|
300
|
$system_log_non_syslog_files = array('dmesg.boot', 'utx.log', 'userlog');
|
301
|
|
302
|
global $system_log_compression_types;
|
303
|
$system_log_compression_types = array(
|
304
|
'bzip2' => array(
|
305
|
'flag' => 'J',
|
306
|
'cat' => '/usr/bin/bzcat -qf',
|
307
|
'ext' => 'bz2',
|
308
|
),
|
309
|
'gzip' => array(
|
310
|
'flag' => 'Z',
|
311
|
'cat' => '/usr/bin/zcat -qf',
|
312
|
'ext' => 'gz',
|
313
|
),
|
314
|
'xz' => array(
|
315
|
'flag' => 'X',
|
316
|
'cat' => '/usr/bin/xzcat -qf',
|
317
|
'ext' => 'xz',
|
318
|
),
|
319
|
'zstd' => array(
|
320
|
'flag' => 'Y',
|
321
|
'cat' => '/usr/bin/zstdcat -qqf',
|
322
|
'ext' => 'zst',
|
323
|
),
|
324
|
'none' => array(
|
325
|
'flag' => '',
|
326
|
'cat' => '/bin/cat',
|
327
|
'ext' => '',
|
328
|
),
|
329
|
);
|
330
|
|
331
|
global $ddnsdomainkeyalgorithms;
|
332
|
$ddnsdomainkeyalgorithms = array(
|
333
|
'hmac-md5' => 'HMAC-MD5 (legacy default)',
|
334
|
'hmac-sha1' => 'HMAC-SHA1',
|
335
|
'hmac-sha224' => 'HMAC-SHA224',
|
336
|
'hmac-sha256' => 'HMAC-SHA256 (current bind9 default)',
|
337
|
'hmac-sha384' => 'HMAC-SHA384',
|
338
|
'hmac-sha512' => 'HMAC-SHA512 (most secure)');
|
339
|
|
340
|
global $ipsec_filtermodes;
|
341
|
$ipsec_filtermodes = array(
|
342
|
'enc' => 'Filter IPsec Tunnel, Transport, and VTI on IPsec tab (enc0)',
|
343
|
'if_ipsec' => 'Filter IPsec VTI and Transport on assigned interfaces, block all tunnel mode traffic'
|
344
|
);
|
345
|
|
346
|
global $ipsec_filter_sysctl;
|
347
|
$ipsec_filter_sysctl = array(
|
348
|
'enc' => array(
|
349
|
"net.inet.ipsec.filtertunnel" => "0x0000",
|
350
|
"net.inet6.ipsec6.filtertunnel" => "0x0000",
|
351
|
"net.enc.out.ipsec_bpf_mask" => "0x0001",
|
352
|
"net.enc.out.ipsec_filter_mask" => "0x0001",
|
353
|
"net.enc.in.ipsec_bpf_mask" => "0x0002",
|
354
|
"net.enc.in.ipsec_filter_mask" => "0x0002"
|
355
|
),
|
356
|
'if_ipsec' => array(
|
357
|
"net.inet.ipsec.filtertunnel" => "0x0001",
|
358
|
"net.inet6.ipsec6.filtertunnel" => "0x0001",
|
359
|
"net.enc.out.ipsec_bpf_mask" => "0x0000",
|
360
|
"net.enc.out.ipsec_filter_mask" => "0x0000",
|
361
|
"net.enc.in.ipsec_bpf_mask" => "0x0000",
|
362
|
"net.enc.in.ipsec_filter_mask" => "0x0000"
|
363
|
),
|
364
|
);
|
365
|
|
366
|
global $vpn_and_ppp_ifs;
|
367
|
$vpn_and_ppp_ifs = array("l2tp", "pppoe", "enc0", "openvpn");
|
368
|
|
369
|
global $ssh_keys;
|
370
|
$ssh_keys = array(
|
371
|
array('type' => 'rsa', 'suffix' => 'rsa_'),
|
372
|
array('type' => 'ed25519', 'suffix' => 'ed25519_')
|
373
|
);
|
374
|
|
375
|
global $sshConfigDir;
|
376
|
$sshConfigDir = "/etc/ssh";
|
377
|
|
378
|
global $lagg_hash_list;
|
379
|
$lagg_hash_list = array(
|
380
|
'l2,l3,l4' => 'Layer 2/3/4 (default)',
|
381
|
'l2' => 'Layer 2 (MAC Address)',
|
382
|
'l3' => 'Layer 3 (IP Address)',
|
383
|
'l4' => 'Layer 4 (Port Number)',
|
384
|
'l2,l3' => 'Layer 2/3 (MAC + IP)',
|
385
|
'l3,l4' => 'Layer 3/4 (IP + Port)',
|
386
|
'l2,l4' => 'Layer 2/4 (MAC + Port)'
|
387
|
);
|
388
|
|
389
|
?>
|