1
|
#!/usr/local/bin/php-cgi -f
|
2
|
<?php
|
3
|
/*
|
4
|
* rc.bootup
|
5
|
*
|
6
|
* originally based on m0n0wall (http://m0n0.ch/wall)
|
7
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
8
|
* Copyright (c) 2009 Erik Kristensen
|
9
|
* Copyright (c) 2005-2013 BSD Perimeter
|
10
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
11
|
* Copyright (c) 2014-2024 Rubicon Communications, LLC (Netgate)
|
12
|
* All rights reserved.
|
13
|
*
|
14
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
15
|
* you may not use this file except in compliance with the License.
|
16
|
* You may obtain a copy of the License at
|
17
|
*
|
18
|
* http://www.apache.org/licenses/LICENSE-2.0
|
19
|
*
|
20
|
* Unless required by applicable law or agreed to in writing, software
|
21
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
22
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
23
|
* See the License for the specific language governing permissions and
|
24
|
* limitations under the License.
|
25
|
*/
|
26
|
|
27
|
require_once("pkg-utils.inc");
|
28
|
|
29
|
echo " done.\n";
|
30
|
|
31
|
echo "Initializing...";
|
32
|
echo ".";
|
33
|
require_once("/etc/inc/globals.inc");
|
34
|
echo ".";
|
35
|
require_once("/etc/inc/led.inc");
|
36
|
led_normalize();
|
37
|
echo ".";
|
38
|
if (led_count() >= 3) {
|
39
|
led_kitt();
|
40
|
}
|
41
|
|
42
|
/* let the other functions know we're booting */
|
43
|
$pkg_interface = 'console';
|
44
|
$g['booting'] = true;
|
45
|
|
46
|
/* parse the configuration and include all functions used below */
|
47
|
require_once("/etc/inc/config.inc");
|
48
|
echo ".";
|
49
|
require_once("/etc/inc/config.console.inc");
|
50
|
echo ".";
|
51
|
require_once("/etc/inc/auth.inc");
|
52
|
echo ".";
|
53
|
require_once("/etc/inc/functions.inc");
|
54
|
echo ".";
|
55
|
require_once("/etc/inc/filter.inc");
|
56
|
echo ".";
|
57
|
require_once("/etc/inc/shaper.inc");
|
58
|
echo ".";
|
59
|
require_once("/etc/inc/ipsec.inc");
|
60
|
echo ".";
|
61
|
require_once("/etc/inc/vpn.inc");
|
62
|
echo ".";
|
63
|
require_once("/etc/inc/openvpn.inc");
|
64
|
echo ".";
|
65
|
require_once("/etc/inc/captiveportal.inc");
|
66
|
echo ".";
|
67
|
require_once("/etc/inc/rrd.inc");
|
68
|
echo ".";
|
69
|
require_once("/etc/inc/pfsense-utils.inc");
|
70
|
echo ".";
|
71
|
require_once("/etc/inc/notices.inc");
|
72
|
echo ".";
|
73
|
/* Setup notice queues */
|
74
|
notices_setup();
|
75
|
|
76
|
/* get system memory amount */
|
77
|
$memory = get_memory();
|
78
|
$physmem = $memory[0];
|
79
|
$realmem = $memory[1];
|
80
|
echo " done.\n";
|
81
|
|
82
|
|
83
|
/* save dmesg output to file */
|
84
|
system_dmesg_save();
|
85
|
|
86
|
/* check whether config reset is desired (via hardware button on WRAP/ALIX) */
|
87
|
system_check_reset_button();
|
88
|
|
89
|
/* remove previous firmware upgrade if present */
|
90
|
if (file_exists("/root/firmware.tgz")) {
|
91
|
unlink("/root/firmware.tgz");
|
92
|
}
|
93
|
|
94
|
/* restore RRD, SSH keys and extra data on bsdinstall config restore
|
95
|
* see https://redmine.pfsense.org/issues/12518 */
|
96
|
if (file_exists("{$g['conf_path']}/installer_copied_config") &&
|
97
|
file_exists("{$g['conf_path']}/restore_config_data")) {
|
98
|
copy("/cf/conf/config.xml", "{$g['tmp_path']}/config_to_restore.xml");
|
99
|
restore_backup("{$g['tmp_path']}/config_to_restore.xml");
|
100
|
@unlink("{$g['tmp_path']}/config_to_restore.xml");
|
101
|
@unlink("{$g['conf_path']}/installer_copied_config");
|
102
|
@unlink("{$g['conf_path']}/restore_config_data");
|
103
|
}
|
104
|
|
105
|
/* Triggering of the initial setup wizard after reboot has been requested */
|
106
|
if (file_exists("{$g['conf_path']}/trigger_initial_wizard_after_reboot")) {
|
107
|
touch("{$g['conf_path']}/trigger_initial_wizard");
|
108
|
@unlink("{$g['conf_path']}/trigger_initial_wizard_after_reboot");
|
109
|
}
|
110
|
|
111
|
/* start devd (dhclient now uses it) */
|
112
|
echo "Starting device manager (devd)...";
|
113
|
mute_kernel_msgs();
|
114
|
start_devd();
|
115
|
set_device_perms();
|
116
|
unmute_kernel_msgs();
|
117
|
echo "done.\n";
|
118
|
|
119
|
echo "Loading configuration...";
|
120
|
parse_config_bootup();
|
121
|
echo "done.\n";
|
122
|
|
123
|
mwexec("/usr/sbin/gnid > {$g['vardb_path']}/uniqueid 2>/dev/null");
|
124
|
|
125
|
/* run any early shell commands specified in config.xml */
|
126
|
system_do_shell_commands(1);
|
127
|
|
128
|
// Only do the alternate interface checks if:
|
129
|
// 1) The user has not yet run the initial wizard; and
|
130
|
// 2) The user has not used the console menu to setup interface assignments
|
131
|
if (file_exists("{$g['conf_path']}/trigger_initial_wizard") && !file_exists("{$g['conf_path']}/assign_complete")) {
|
132
|
check_for_alternate_interfaces();
|
133
|
}
|
134
|
|
135
|
/* Convert configuration
|
136
|
* This must happen before the interface mismatch test, see
|
137
|
* https://redmine.pfsense.org/issues/7809 */
|
138
|
echo "Updating configuration...";
|
139
|
convert_config();
|
140
|
echo "done.\n";
|
141
|
|
142
|
/*
|
143
|
* Determine if we need to throw a interface exception
|
144
|
* and ask the user to reassign interfaces. This will
|
145
|
* avoid a reboot and that is a good thing.
|
146
|
*/
|
147
|
while (is_interface_mismatch() == true) {
|
148
|
led_assigninterfaces();
|
149
|
if (isset($config['revision'])) {
|
150
|
if (file_exists("{$g['tmp_path']}/missing_interfaces")) {
|
151
|
echo "Warning: Configuration references interfaces that do not exist: " . file_get_contents("{$g['tmp_path']}/missing_interfaces") . "\n";
|
152
|
}
|
153
|
echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
|
154
|
} else {
|
155
|
echo "\nDefault interfaces not found -- Running interface assignment option.\n";
|
156
|
}
|
157
|
$ifaces = get_interface_list();
|
158
|
if (is_array($ifaces)) {
|
159
|
foreach ($ifaces as $iface => $ifdata) {
|
160
|
interfaces_bring_up($iface);
|
161
|
}
|
162
|
}
|
163
|
if (set_networking_interfaces_ports() == -1) {
|
164
|
echo "\npfSense cannot continue without at least one Network Interface Card.\n";
|
165
|
echo "\nHalting the system.\n";
|
166
|
system("/sbin/shutdown -h now");
|
167
|
exit(0);
|
168
|
}
|
169
|
reload_interfaces_sync();
|
170
|
led_kitt();
|
171
|
}
|
172
|
|
173
|
echo "Checking config backups consistency...";
|
174
|
cleanup_backupcache(true);
|
175
|
echo "done.\n";
|
176
|
|
177
|
/* read in /etc/sysctl.conf and set values if needed */
|
178
|
echo "Setting up extended sysctls...";
|
179
|
system_setup_sysctl();
|
180
|
echo "done.\n";
|
181
|
|
182
|
/* enable optional crypto modules */
|
183
|
load_crypto();
|
184
|
|
185
|
/* enable optional thermal sensor modules */
|
186
|
load_thermal_hardware();
|
187
|
|
188
|
/* set up our timezone */
|
189
|
system_timezone_configure();
|
190
|
|
191
|
/* set up our hostname */
|
192
|
system_hostname_configure();
|
193
|
|
194
|
/* make hosts file */
|
195
|
system_hosts_generate();
|
196
|
|
197
|
/* disable CARP prior to configuring interfaces */
|
198
|
enable_carp(false);
|
199
|
|
200
|
/* configure loopback interface */
|
201
|
interfaces_loopback_configure();
|
202
|
|
203
|
/* Setup Local CA Trust Store */
|
204
|
ca_setup_trust_store();
|
205
|
|
206
|
/* If the system uses ZFS and has compression enabled for /var/log, disable log
|
207
|
* compression by default. See https://redmine.pfsense.org/issues/12011
|
208
|
*/
|
209
|
$varlog_compression_state = 'off';
|
210
|
if (is_module_loaded('zfs.ko')) {
|
211
|
exec("/sbin/zfs get -H compression /var/log | /usr/bin/awk '{print $3;}'", $varlog_compression_state);
|
212
|
$varlog_compression_state = $varlog_compression_state[0];
|
213
|
}
|
214
|
if (file_exists("{$g['conf_path']}/trigger_initial_wizard") &&
|
215
|
(trim($varlog_compression_state) != 'off')) {
|
216
|
touch("{$g['conf_path']}/syslog_default_uncompressed");
|
217
|
}
|
218
|
/* start syslogd */
|
219
|
system_syslogd_start();
|
220
|
|
221
|
/* set pam shell authentication backend */
|
222
|
set_pam_auth();
|
223
|
|
224
|
/* Log the RAM disk restore messages. */
|
225
|
if (file_exists("/var/log/restore_ramdisk_store.boot")) {
|
226
|
exec("/usr/bin/logger -f /var/log/restore_ramdisk_store.boot");
|
227
|
}
|
228
|
|
229
|
/* setup interface microcode which improves tcp/ip speed */
|
230
|
echo "Setting up interfaces microcode...";
|
231
|
setup_microcode();
|
232
|
echo "done.\n";
|
233
|
|
234
|
if (isset($config['system']['mds_disable']) &&
|
235
|
(strlen($config['system']['mds_disable']) > 0)) {
|
236
|
set_single_sysctl("hw.mds_disable" , (int)$config['system']['mds_disable']);
|
237
|
}
|
238
|
|
239
|
/* remove leftover dhcp6c lock file if it exist */
|
240
|
if (file_exists("/tmp/dhcp6c_lock")) {
|
241
|
@unlink("/tmp/dhcp6c_lock");
|
242
|
echo("Removed leftover dhcp6c lock file: /tmp/dhcp6c_lock\n");
|
243
|
}
|
244
|
if (file_exists("/tmp/dhcp6c_ifs")) {
|
245
|
@unlink("/tmp/dhcp6c_ifs");
|
246
|
}
|
247
|
|
248
|
/* set up interfaces */
|
249
|
if (!$debugging) {
|
250
|
mute_kernel_msgs();
|
251
|
}
|
252
|
interfaces_configure();
|
253
|
interfaces_sync_setup();
|
254
|
if (!$debugging) {
|
255
|
unmute_kernel_msgs();
|
256
|
}
|
257
|
|
258
|
/* re-make hosts file after configuring interfaces */
|
259
|
system_hosts_generate();
|
260
|
|
261
|
/* start sshd */
|
262
|
init_config_arr(array('system', 'ssh'));
|
263
|
if (isset($config['system']['ssh']['enable'])) {
|
264
|
echo "Starting Secure Shell Services...";
|
265
|
send_event("service reload sshd");
|
266
|
echo "done.\n";
|
267
|
}
|
268
|
|
269
|
/* start OpenVPN server & clients */
|
270
|
echo "Syncing OpenVPN settings...";
|
271
|
openvpn_resync_all();
|
272
|
echo "done.\n";
|
273
|
|
274
|
/* generate resolv.conf */
|
275
|
system_resolvconf_generate();
|
276
|
|
277
|
/* setup altq + pf */
|
278
|
filter_configure_sync();
|
279
|
|
280
|
/* start pflog */
|
281
|
echo "Starting PFLOG...";
|
282
|
filter_pflog_start();
|
283
|
echo "done.\n";
|
284
|
|
285
|
/* reconfigure our gateway monitor */
|
286
|
setup_gateways_monitor();
|
287
|
|
288
|
/* set up static routes */
|
289
|
echo "Setting up static routes...";
|
290
|
system_routing_configure();
|
291
|
echo "done.\n";
|
292
|
|
293
|
init_config_arr(array('unbound'));
|
294
|
init_config_arr(array('dnsmasq'));
|
295
|
if (isset($config['unbound']['enable']) ||
|
296
|
isset($config['dnsmasq']['enable'])) {
|
297
|
echo "Setting up DNSs...\n";
|
298
|
/* start dnsmasq service */
|
299
|
services_dnsmasq_configure();
|
300
|
|
301
|
/* start unbound service */
|
302
|
services_unbound_configure();
|
303
|
}
|
304
|
|
305
|
echo "Synchronizing user settings...";
|
306
|
local_reset_accounts();
|
307
|
echo "done.\n";
|
308
|
|
309
|
/* configure cron service */
|
310
|
echo "Configuring CRON...";
|
311
|
configure_cron();
|
312
|
echo "done.\n";
|
313
|
|
314
|
/* enable routing */
|
315
|
system_routing_enable();
|
316
|
|
317
|
/* Set initial time by using IP addresses in case DNS is not available
|
318
|
* This works around issues with DNSSEC and gives the firewall a better chance
|
319
|
* of having a highly accurate clock at boot.
|
320
|
* NG 7352, NG 7447
|
321
|
*/
|
322
|
|
323
|
/* Default to Google Public NTP servers */
|
324
|
$ntp_boot_time_servers = '216.239.35.0 216.239.35.4 216.239.35.8 216.239.35.12';
|
325
|
/* File to allow users to override default behavior.
|
326
|
* Servers must be a single line with space-separated IP address entries ONLY as
|
327
|
* DNS may not be functional. */
|
328
|
$ntp_boot_time_servers_override = '/conf/ntp-boot-time-servers';
|
329
|
|
330
|
/* Handle user override of NTP bootstrap behavior */
|
331
|
if (file_exists($ntp_boot_time_servers_override)) {
|
332
|
if (filesize($ntp_boot_time_servers_override) > 0) {
|
333
|
/* Read servers from file if the file is not empty. */
|
334
|
$servers = file_get_contents($ntp_boot_time_servers_override);
|
335
|
$checkservers = explode(' ', trim($servers));
|
336
|
$goodservers = array();
|
337
|
/* Only add entries which are valid IP addresses. */
|
338
|
foreach ($checkservers as $ntpserver) {
|
339
|
if (is_ipaddr($ntpserver)) {
|
340
|
$goodservers[] = escapeshellarg($ntpserver);
|
341
|
}
|
342
|
}
|
343
|
$ntp_boot_time_servers = implode(' ', $goodservers);
|
344
|
} else {
|
345
|
/* Disable check if the file exists but is empty. */
|
346
|
$ntp_boot_time_servers = '';
|
347
|
}
|
348
|
}
|
349
|
|
350
|
if (!empty($ntp_boot_time_servers)) {
|
351
|
echo gettext("Bootstrapping clock...");
|
352
|
mwexec("/usr/bin/timeout -k 45 30 /usr/local/sbin/ntpd -g -q -c /dev/null {$ntp_boot_time_servers}");
|
353
|
echo gettext("done.") . "\n";
|
354
|
}
|
355
|
|
356
|
/* Enable ntpd */
|
357
|
system_ntp_configure();
|
358
|
|
359
|
if ($realmem > 0 and $realmem < 65) {
|
360
|
echo "System has less than 65 megabytes of ram {$realmem}. Delaying webConfigurator startup.\n";
|
361
|
/* start webConfigurator up on final pass */
|
362
|
mwexec("/usr/local/sbin/pfSctl -c 'service restart webgui'");
|
363
|
} else {
|
364
|
/* start web server */
|
365
|
system_webgui_start();
|
366
|
}
|
367
|
|
368
|
/* Configure console (and serial port - if necessary). */
|
369
|
console_configure();
|
370
|
|
371
|
/* start DHCP service */
|
372
|
services_dhcpd_configure();
|
373
|
|
374
|
/* start dhcpleases dhcp hosts leases program */
|
375
|
system_dhcpleases_configure();
|
376
|
|
377
|
/* start DHCP relay */
|
378
|
services_dhcrelay_configure();
|
379
|
|
380
|
/* start DHCP6 relay */
|
381
|
services_dhcrelay6_configure();
|
382
|
|
383
|
/* dyndns service updates */
|
384
|
send_event("service reload dyndnsall");
|
385
|
|
386
|
/* Run a filter configure now that most all services have started */
|
387
|
filter_configure_sync();
|
388
|
|
389
|
/* setup pppoe and pptp */
|
390
|
vpn_setup();
|
391
|
|
392
|
/* start the captive portal */
|
393
|
captiveportal_configure();
|
394
|
|
395
|
/* start Voucher support */
|
396
|
voucher_configure();
|
397
|
|
398
|
/* run any shell commands specified in config.xml */
|
399
|
system_do_shell_commands();
|
400
|
|
401
|
/* start IPsec tunnels */
|
402
|
$ipsec_dynamic_hosts = ipsec_configure();
|
403
|
|
404
|
/* start SNMP service */
|
405
|
services_snmpd_configure();
|
406
|
|
407
|
/* power down hard drive if needed/set */
|
408
|
system_set_harddisk_standby();
|
409
|
|
410
|
/* lock down console if necessary */
|
411
|
reload_ttys();
|
412
|
|
413
|
/* load graphing functions */
|
414
|
enable_rrd_graphing();
|
415
|
|
416
|
/* enable watchdog if supported */
|
417
|
enable_watchdog();
|
418
|
|
419
|
/* if <system><afterbootupshellcmd> exists, execute the command */
|
420
|
if ($config['system']['afterbootupshellcmd'] <> "") {
|
421
|
echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
|
422
|
mwexec($config['system']['afterbootupshellcmd']);
|
423
|
}
|
424
|
|
425
|
if ($physmem < $g['minimum_ram_warning']) {
|
426
|
file_notice("{$g['product_label']}MemoryRequirements", "{$g['product_label']} requires at least {$g['minimum_ram_warning_text']} of RAM. Expect unusual performance. This platform is not supported.", "Memory", "", 1);
|
427
|
set_sysctl(array(
|
428
|
"net.inet.tcp.recvspace" => "4096",
|
429
|
"net.inet.tcp.sendspace" => "4096"
|
430
|
));
|
431
|
}
|
432
|
|
433
|
if (file_exists("/conf/ram_disks_failed")) {
|
434
|
file_notice("RAM Disks", "RAM disk creation failed. Reverted to traditional storage. Check RAM disk sizes.", "RAM Disks");
|
435
|
}
|
436
|
|
437
|
/* if we are operating at 1000 then increase timeouts.
|
438
|
this was never accounted for after moving to 1000 hz */
|
439
|
$kern_hz = get_single_sysctl('kern.clockrate');
|
440
|
$kern_hz = substr($kern_hz, strpos($kern_hz, "hz = ") + 5);
|
441
|
$kern_hz = substr($kern_hz, 0, strpos($kern_hz, ","));
|
442
|
if ($kern_hz == "1000") {
|
443
|
set_single_sysctl("net.inet.tcp.rexmit_min" , "30");
|
444
|
}
|
445
|
|
446
|
/* start the igmpproxy daemon */
|
447
|
services_igmpproxy_configure();
|
448
|
|
449
|
/* start the upnp daemon if it is enabled */
|
450
|
upnp_start();
|
451
|
|
452
|
/* If powerd is enabled, lets launch it */
|
453
|
activate_powerd();
|
454
|
|
455
|
/* Set preferred protocol */
|
456
|
prefer_ipv4_or_ipv6();
|
457
|
|
458
|
/* Resync / Reinstall packages if need be */
|
459
|
if (file_exists("{$g['conf_path']}/needs_package_sync")) {
|
460
|
echo "Triggering packages reinstallation in background\n";
|
461
|
mwexec_bg("{$g['etc_path']}/rc.package_reinstall_all");
|
462
|
} else {
|
463
|
/* Detect installed binary pkgs that are not registered in the system */
|
464
|
register_all_installed_packages();
|
465
|
}
|
466
|
|
467
|
/* Give syslogd a kick after everything else has been initialized, otherwise it can occasionally
|
468
|
fail to route syslog messages properly on both IPv4 and IPv6 */
|
469
|
system_syslogd_start();
|
470
|
|
471
|
/* done */
|
472
|
$g['booting'] = false;
|
473
|
@unlink("{$g['varrun_path']}/booting");
|
474
|
|
475
|
/* re-enable CARP */
|
476
|
enable_carp();
|
477
|
|
478
|
/* If there are ipsec dynamic hosts try again to reload the tunnels as rc.newipsecdns does */
|
479
|
if ($ipsec_dynamic_hosts) {
|
480
|
echo gettext("Configuring IPsec VPN for dynamic hosts... ");
|
481
|
ipsec_configure();
|
482
|
|
483
|
/* restart dpinger if PH1 remote gateway == fqdn and PH2 mode == VTI
|
484
|
* see https://redmine.pfsense.org/issues/12763 */
|
485
|
foreach ($config['ipsec']['phase1'] as $p1) {
|
486
|
if (!isset($p1['mobile']) && !isset($p1['disabled']) && is_fqdn($p1['remote-gateway'])) {
|
487
|
foreach ($config['ipsec']['phase2'] as $p2) {
|
488
|
if (!isset($p2['disabled']) && ($p2['mode'] == 'vti')) {
|
489
|
setup_gateways_monitor();
|
490
|
break 2;
|
491
|
}
|
492
|
}
|
493
|
}
|
494
|
}
|
495
|
|
496
|
echo gettext("done") . "\n";
|
497
|
}
|
498
|
if ($ipsec_dynamic_hosts || !empty($filterdns)) {
|
499
|
echo gettext("Configuring filter for dynamic IPsec VPN hosts... ");
|
500
|
filter_configure();
|
501
|
echo gettext("done") . "\n";
|
502
|
}
|
503
|
|
504
|
led_normalize();
|
505
|
|
506
|
notify_all_remote("Bootup complete");
|
507
|
?>
|