1 |
5b237745
|
Scott Ullrich
|
<?php
|
2 |
ac24dc24
|
Renato Botelho
|
/*
|
3 |
|
|
* globals.inc
|
4 |
2af1b0c7
|
Stephen Beaver
|
*
|
5 |
ac24dc24
|
Renato Botelho
|
* part of pfSense (https://www.pfsense.org)
|
6 |
38809d47
|
Renato Botelho do Couto
|
* Copyright (c) 2004-2013 BSD Perimeter
|
7 |
|
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
8 |
402c98a2
|
Reid Linnemann
|
* Copyright (c) 2014-2023 Rubicon Communications, LLC (Netgate)
|
9 |
ac24dc24
|
Renato Botelho
|
* All rights reserved.
|
10 |
2af1b0c7
|
Stephen Beaver
|
*
|
11 |
b12ea3fb
|
Renato Botelho
|
* 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 |
2af1b0c7
|
Stephen Beaver
|
*
|
15 |
b12ea3fb
|
Renato Botelho
|
* http://www.apache.org/licenses/LICENSE-2.0
|
16 |
2af1b0c7
|
Stephen Beaver
|
*
|
17 |
b12ea3fb
|
Renato Botelho
|
* 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 |
2af1b0c7
|
Stephen Beaver
|
*/
|
23 |
9ba87997
|
Phil Davis
|
|
24 |
43c83997
|
Phil Davis
|
// Global defines
|
25 |
523855b0
|
Scott Ullrich
|
|
26 |
43c83997
|
Phil Davis
|
// Automatic panel collapse
|
27 |
820562e8
|
NewEraCracker
|
define('COLLAPSIBLE', 0x08);
|
28 |
|
|
define('SEC_CLOSED', 0x04);
|
29 |
|
|
define('SEC_OPEN', 0x00);
|
30 |
5b237745
|
Scott Ullrich
|
|
31 |
77a8a7d6
|
Steve Beaver
|
// IP address types
|
32 |
8e26b84f
|
Christian McDonald
|
define('IPV4', 4);
|
33 |
|
|
define('IPV6', 6);
|
34 |
|
|
define('IPV4V6', 2);
|
35 |
|
|
define('ALIAS', 1);
|
36 |
77a8a7d6
|
Steve Beaver
|
|
37 |
0793de1a
|
Luiz Souza
|
// Interface Name Size
|
38 |
8e26b84f
|
Christian McDonald
|
define('IF_NAMESIZE', 15); /* 16 minus the terminating NULL */
|
39 |
0793de1a
|
Luiz Souza
|
|
40 |
5ea90990
|
Stephen Beaver
|
// AddPassword method defines
|
41 |
8e26b84f
|
Christian McDonald
|
define('DMYPWD', '********');
|
42 |
5ea90990
|
Stephen Beaver
|
|
43 |
7c2468c5
|
Viktor G
|
// Captive Portal aliases prefix
|
44 |
8e26b84f
|
Christian McDonald
|
define('CPPREFIX', 'cpzoneid_');
|
45 |
7c2468c5
|
Viktor G
|
|
46 |
dce1eece
|
Christian McDonald
|
$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 |
8346b5c4
|
jim-p
|
global $g;
|
53 |
095b2481
|
Steve Wheeler
|
$g = [
|
54 |
8e26b84f
|
Christian McDonald
|
'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>®</sup>',
|
79 |
dce1eece
|
Christian McDonald
|
'product_version' => $product_version,
|
80 |
|
|
'product_copyright_years' => '2004 - ' . $present_year,
|
81 |
8e26b84f
|
Christian McDonald
|
'disablehelpmenu' => false,
|
82 |
|
|
'disablehelpicon' => false,
|
83 |
|
|
'disablecrashreporter' => false,
|
84 |
|
|
'debug' => false,
|
85 |
6ce83e74
|
jim-p
|
'latest_config' => '23.3',
|
86 |
8e26b84f
|
Christian McDonald
|
'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 |
095b2481
|
Steve Wheeler
|
'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 |
8e26b84f
|
Christian McDonald
|
'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 |
5b237745
|
Scott Ullrich
|
|
115 |
a03e3c1f
|
Bill Marquette
|
/* IP TOS flags */
|
116 |
8e26b84f
|
Christian McDonald
|
global $iptos;
|
117 |
|
|
$iptos = ['lowdelay', 'throughput', 'reliability'];
|
118 |
a03e3c1f
|
Bill Marquette
|
|
119 |
|
|
/* TCP flags */
|
120 |
8e26b84f
|
Christian McDonald
|
global $tcpflags;
|
121 |
|
|
$tcpflags = ['syn', 'ack', 'fin', 'rst', 'psh', 'urg', 'ece', 'cwr'];
|
122 |
a03e3c1f
|
Bill Marquette
|
|
123 |
dce1eece
|
Christian McDonald
|
if (file_exists($version_patch_file)) {
|
124 |
|
|
$g['product_version_patch'] = rtrim(file_get_contents($version_patch_file));
|
125 |
5a0235ca
|
Renato Botelho
|
} else {
|
126 |
8e26b84f
|
Christian McDonald
|
$g['product_version_patch'] = '0';
|
127 |
5a0235ca
|
Renato Botelho
|
}
|
128 |
|
|
|
129 |
2568e151
|
Christian McDonald
|
$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 |
5a0235ca
|
Renato Botelho
|
}
|
133 |
|
|
|
134 |
2568e151
|
Christian McDonald
|
$flavor_file = g_get('etc_path') . '/default-config-flavor';
|
135 |
8e26b84f
|
Christian McDonald
|
if (file_exists($flavor_file)) {
|
136 |
|
|
$flavor_array = file($flavor_file);
|
137 |
630326d4
|
Renato Botelho
|
$g['default-config-flavor'] = chop($flavor_array[0]);
|
138 |
|
|
} else {
|
139 |
|
|
$g['default-config-flavor'] = '';
|
140 |
|
|
}
|
141 |
|
|
|
142 |
2568e151
|
Christian McDonald
|
$g['openvpn_base'] = g_get('varetc_path') . '/openvpn';
|
143 |
348c2af1
|
jim-p
|
|
144 |
3c2cb48c
|
Luiz Otavio O Souza
|
$g['pkg_repos_path'] = '/usr/local/etc/' . $g['product_name'] . '/pkg/repos';
|
145 |
9de48f4b
|
Luiz Otavio O Souza
|
|
146 |
3a35f55f
|
Scott Ullrich
|
/* Default sysctls */
|
147 |
8e26b84f
|
Christian McDonald
|
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 |
3a35f55f
|
Scott Ullrich
|
|
192 |
545d0b46
|
Dave Cornejo
|
$machine_type = php_uname('m');
|
193 |
|
|
if (($machine_type == 'arm') || ($machine_type == 'arm64')) {
|
194 |
|
|
$sysctls['kern.shutdown.secure_halt'] = 1;
|
195 |
|
|
}
|
196 |
|
|
|
197 |
ae04affe
|
Renato Botelho
|
/* Read all XML files in following dir and load menu entries */
|
198 |
2568e151
|
Christian McDonald
|
$g['ext_menu_path'] = '/usr/local/share/'. g_get('product_name') . '/menu';
|
199 |
ae04affe
|
Renato Botelho
|
|
200 |
e8f8aeb6
|
Renato Botelho
|
/* Cache file used to store pfSense version */
|
201 |
2568e151
|
Christian McDonald
|
$g['version_cache_file'] = g_get('varrun_path') . '/' . g_get('product_name') . '_version';
|
202 |
8e26b84f
|
Christian McDonald
|
$g['version_cache_refresh'] = 7200; /* 2h */
|
203 |
b8d09280
|
Ermal LUÇI
|
|
204 |
2568e151
|
Christian McDonald
|
if (file_exists(g_get('cf_conf_path') . '/enableserial_force')) {
|
205 |
719db60e
|
Ermal LUÇI
|
$g['enableserial_force'] = true;
|
206 |
9ba87997
|
Phil Davis
|
}
|
207 |
719db60e
|
Ermal LUÇI
|
|
208 |
8e26b84f
|
Christian McDonald
|
global $config_parsed;
|
209 |
1883455a
|
Ermal
|
$config_parsed = false;
|
210 |
9734b054
|
Scott Ullrich
|
|
211 |
39d2f39d
|
NOYB
|
/* Factory default check IP service. */
|
212 |
8e26b84f
|
Christian McDonald
|
global $factory_default_checkipservice;
|
213 |
095b2481
|
Steve Wheeler
|
$factory_default_checkipservice = [
|
214 |
8e26b84f
|
Christian McDonald
|
'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 |
ddb57f79
|
jim-p
|
$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 |
b20cfb55
|
jim-p
|
|
237 |
286e685d
|
Marcos Mendoza
|
// pf tokens from FreeBSD source /sbin/pfctl/parse.y
|
238 |
b20cfb55
|
jim-p
|
global $pf_reserved_keywords;
|
239 |
095b2481
|
Steve Wheeler
|
$pf_reserved_keywords = [
|
240 |
286e685d
|
Marcos Mendoza
|
// 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 |
a637e8ec
|
Marcos Mendoza
|
'stickyaddress', 'urpffailed', 'dropovl', 'failpolicy', 'mapeportset',
|
261 |
286e685d
|
Marcos Mendoza
|
// Custom tokens
|
262 |
|
|
'arrow', 'codel', 'error', 'filename', 'fragcrop', 'fragdrop', 'IPsec', 'L2TP', 'maximummin', 'OpenVPN',
|
263 |
|
|
'pppoe', 'pptp'
|
264 |
8e26b84f
|
Christian McDonald
|
];
|
265 |
62ed56dc
|
Luiz Souza
|
|
266 |
7997506f
|
vktg
|
/* Reserved table names to avoid collision */
|
267 |
783e9a2a
|
vktg
|
global $reserved_table_names;
|
268 |
095b2481
|
Steve Wheeler
|
$reserved_table_names = [
|
269 |
8e26b84f
|
Christian McDonald
|
'bogons',
|
270 |
|
|
'bogonsv6',
|
271 |
|
|
'negate_networks',
|
272 |
|
|
'snort2c',
|
273 |
|
|
'sshguard',
|
274 |
|
|
'tonatsubnets',
|
275 |
|
|
'virusprot',
|
276 |
|
|
'vpn_networks',
|
277 |
|
|
];
|
278 |
783e9a2a
|
vktg
|
|
279 |
62ed56dc
|
Luiz Souza
|
/* VLAN Prio values. */
|
280 |
8e26b84f
|
Christian McDonald
|
global $vlanprio_values;
|
281 |
095b2481
|
Steve Wheeler
|
$vlanprio_values = [
|
282 |
8e26b84f
|
Christian McDonald
|
'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 |
095b2481
|
Steve Wheeler
|
$vlanprio = [
|
294 |
8e26b84f
|
Christian McDonald
|
'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 |
62ed56dc
|
Luiz Souza
|
|
304 |
f9e8c833
|
jim-p
|
global $system_log_files;
|
305 |
095b2481
|
Steve Wheeler
|
$system_log_files = [
|
306 |
8e26b84f
|
Christian McDonald
|
'system', 'filter', 'dhcpd', 'vpn', 'poes', 'l2tps', 'openvpn',
|
307 |
|
|
'portalauth', 'ipsec', 'ppp', 'wireless', 'nginx', 'ntpd', 'gateways',
|
308 |
|
|
'resolver', 'routing', 'auth'
|
309 |
|
|
];
|
310 |
f9e8c833
|
jim-p
|
|
311 |
eacc805e
|
jim-p
|
global $system_log_non_syslog_files;
|
312 |
8e26b84f
|
Christian McDonald
|
$system_log_non_syslog_files = ['dmesg.boot', 'utx.log', 'userlog'];
|
313 |
eacc805e
|
jim-p
|
|
314 |
03cdd6ad
|
jim-p
|
global $system_log_compression_types;
|
315 |
095b2481
|
Steve Wheeler
|
$system_log_compression_types = [
|
316 |
8e26b84f
|
Christian McDonald
|
'bzip2' => [
|
317 |
03cdd6ad
|
jim-p
|
'flag' => 'J',
|
318 |
87fb98b9
|
jim-p
|
'cat' => '/usr/bin/bzcat -qf',
|
319 |
03cdd6ad
|
jim-p
|
'ext' => 'bz2',
|
320 |
8e26b84f
|
Christian McDonald
|
],
|
321 |
|
|
'gzip' => [
|
322 |
03cdd6ad
|
jim-p
|
'flag' => 'Z',
|
323 |
87fb98b9
|
jim-p
|
'cat' => '/usr/bin/zcat -qf',
|
324 |
03cdd6ad
|
jim-p
|
'ext' => 'gz',
|
325 |
8e26b84f
|
Christian McDonald
|
],
|
326 |
|
|
'xz' => [
|
327 |
03cdd6ad
|
jim-p
|
'flag' => 'X',
|
328 |
87fb98b9
|
jim-p
|
'cat' => '/usr/bin/xzcat -qf',
|
329 |
03cdd6ad
|
jim-p
|
'ext' => 'xz',
|
330 |
8e26b84f
|
Christian McDonald
|
],
|
331 |
|
|
'zstd' => [
|
332 |
03cdd6ad
|
jim-p
|
'flag' => 'Y',
|
333 |
87fb98b9
|
jim-p
|
'cat' => '/usr/bin/zstdcat -qqf',
|
334 |
03cdd6ad
|
jim-p
|
'ext' => 'zst',
|
335 |
8e26b84f
|
Christian McDonald
|
],
|
336 |
|
|
'none' => [
|
337 |
03cdd6ad
|
jim-p
|
'flag' => '',
|
338 |
a62b14a7
|
Viktor G
|
'cat' => '/bin/cat',
|
339 |
03cdd6ad
|
jim-p
|
'ext' => '',
|
340 |
8e26b84f
|
Christian McDonald
|
],
|
341 |
|
|
];
|
342 |
03cdd6ad
|
jim-p
|
|
343 |
e5eba380
|
Viktor G
|
global $ddnsdomainkeyalgorithms;
|
344 |
8e26b84f
|
Christian McDonald
|
$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 |
e5eba380
|
Viktor G
|
|
353 |
cb0a23f2
|
jim-p
|
global $ipsec_filtermodes;
|
354 |
8e26b84f
|
Christian McDonald
|
$ipsec_filtermodes = [
|
355 |
f873a4ef
|
jim-p
|
'enc' => 'Filter IPsec Tunnel, Transport, and VTI on IPsec tab (enc0)',
|
356 |
8e26b84f
|
Christian McDonald
|
'if_ipsec' => 'Filter IPsec VTI and Transport on assigned interfaces, block all tunnel mode traffic',
|
357 |
|
|
];
|
358 |
cb0a23f2
|
jim-p
|
|
359 |
|
|
global $ipsec_filter_sysctl;
|
360 |
095b2481
|
Steve Wheeler
|
$ipsec_filter_sysctl = [
|
361 |
8e26b84f
|
Christian McDonald
|
'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 |
cb0a23f2
|
jim-p
|
|
379 |
6d98e931
|
Viktor G
|
global $vpn_and_ppp_ifs;
|
380 |
8e26b84f
|
Christian McDonald
|
$vpn_and_ppp_ifs = ['l2tp', 'pppoe', 'enc0', 'openvpn'];
|
381 |
dc22e511
|
Viktor G
|
|
382 |
|
|
global $ssh_keys;
|
383 |
8e26b84f
|
Christian McDonald
|
$ssh_keys = [
|
384 |
|
|
['type' => 'rsa', 'suffix' => 'rsa_'],
|
385 |
|
|
['type' => 'ed25519', 'suffix' => 'ed25519_'],
|
386 |
|
|
];
|
387 |
dc22e511
|
Viktor G
|
|
388 |
|
|
global $sshConfigDir;
|
389 |
8e26b84f
|
Christian McDonald
|
$sshConfigDir = '/etc/ssh';
|
390 |
dc22e511
|
Viktor G
|
|
391 |
47eecb16
|
Viktor G
|
global $lagg_hash_list;
|
392 |
8e26b84f
|
Christian McDonald
|
$lagg_hash_list = [
|
393 |
47eecb16
|
Viktor G
|
'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 |
8e26b84f
|
Christian McDonald
|
'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 |
095b2481
|
Steve Wheeler
|
return (g_has($key, true) ? $g[$key] : $default);
|
428 |
8e26b84f
|
Christian McDonald
|
}
|
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 |
47eecb16
|
Viktor G
|
|
509 |
def2ce00
|
Christian McDonald
|
/**
|
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 |
8e26b84f
|
Christian McDonald
|
// short-circuit on absolute paths before checking relative include paths
|
519 |
def2ce00
|
Christian McDonald
|
return (file_exists($filename) || (bool) stream_resolve_include_path($filename));
|
520 |
|
|
}
|
521 |
|
|
|
522 |
7a654802
|
Marcos Mendoza
|
/**
|
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 |
def2ce00
|
Christian McDonald
|
// source pfSense Plus specific globals last
|
573 |
|
|
if (can_include('globals.plus.inc')) {
|
574 |
|
|
include_once('globals.plus.inc');
|
575 |
|
|
}
|