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-2025 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
|
/* Import the Installer network settings. */
|
126
|
if (file_exists("{$g['conf_path']}/trigger_initial_wizard") &&
|
127
|
file_exists("{$g['conf_path']}/installer-settings.json")) {
|
128
|
echo "Importing the network settings from the Netgate Installer...";
|
129
|
installer_settings_import();
|
130
|
echo "done.\n";
|
131
|
}
|
132
|
|
133
|
// Only do the alternate interface checks if:
|
134
|
// 1) The user has not yet run the initial wizard; and
|
135
|
// 2) The user has not used the console menu to setup interface assignments
|
136
|
if (file_exists("{$g['conf_path']}/trigger_initial_wizard") && !file_exists("{$g['conf_path']}/assign_complete")) {
|
137
|
check_for_alternate_interfaces();
|
138
|
}
|
139
|
|
140
|
/* Convert configuration
|
141
|
* This must happen before the interface mismatch test, see
|
142
|
* https://redmine.pfsense.org/issues/7809 */
|
143
|
echo "Updating configuration...";
|
144
|
convert_config();
|
145
|
echo "done.\n";
|
146
|
|
147
|
/*
|
148
|
* Determine if we need to throw a interface exception
|
149
|
* and ask the user to reassign interfaces. This will
|
150
|
* avoid a reboot and that is a good thing.
|
151
|
*/
|
152
|
while (is_interface_mismatch() == true) {
|
153
|
led_assigninterfaces();
|
154
|
if (config_get_path('revision') !== null) {
|
155
|
if (file_exists("{$g['tmp_path']}/missing_interfaces")) {
|
156
|
echo "Warning: Configuration references interfaces that do not exist: " . file_get_contents("{$g['tmp_path']}/missing_interfaces") . "\n";
|
157
|
}
|
158
|
echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
|
159
|
} else {
|
160
|
echo "\nDefault interfaces not found -- Running interface assignment option.\n";
|
161
|
}
|
162
|
$ifaces = get_interface_list();
|
163
|
if (is_array($ifaces)) {
|
164
|
foreach ($ifaces as $iface => $ifdata) {
|
165
|
interfaces_bring_up($iface);
|
166
|
}
|
167
|
}
|
168
|
if (set_networking_interfaces_ports() == -1) {
|
169
|
echo "\npfSense cannot continue without at least one Network Interface Card.\n";
|
170
|
echo "\nHalting the system.\n";
|
171
|
system("/sbin/shutdown -h now");
|
172
|
exit(0);
|
173
|
}
|
174
|
reload_interfaces_sync();
|
175
|
led_kitt();
|
176
|
}
|
177
|
|
178
|
/* enable optional crypto modules */
|
179
|
echo "Loading cryptographic accelerator drivers...";
|
180
|
load_crypto();
|
181
|
echo "done.\n";
|
182
|
|
183
|
echo "Checking config backups consistency...";
|
184
|
cleanup_backupcache(true);
|
185
|
echo "done.\n";
|
186
|
|
187
|
/* set additional sysctls not defined in loader.conf */
|
188
|
echo "Setting up extended sysctls...";
|
189
|
system_setup_sysctl();
|
190
|
echo "done.\n";
|
191
|
|
192
|
$file = '/deferred_pkg_install';
|
193
|
if (file_exists($file)) {
|
194
|
echo "Executing deferred package installation scripts...";
|
195
|
register_all_installed_packages(true);
|
196
|
unlink($file);
|
197
|
echo "done.\n";
|
198
|
}
|
199
|
|
200
|
/* run any early shell commands specified in config.xml */
|
201
|
echo "Executing early shell commands...";
|
202
|
system_do_shell_commands(1);
|
203
|
echo "done.\n";
|
204
|
|
205
|
/* enable optional thermal sensor modules */
|
206
|
load_thermal_hardware();
|
207
|
|
208
|
/* set up our timezone */
|
209
|
system_timezone_configure();
|
210
|
|
211
|
/* set up our hostname */
|
212
|
system_hostname_configure();
|
213
|
|
214
|
/* make hosts file */
|
215
|
system_hosts_generate();
|
216
|
|
217
|
/* disable CARP prior to configuring interfaces */
|
218
|
enable_carp(false);
|
219
|
|
220
|
/* configure loopback interface */
|
221
|
interfaces_loopback_configure();
|
222
|
|
223
|
/* Setup Local CA Trust Store */
|
224
|
ca_setup_trust_store();
|
225
|
|
226
|
/* If the system uses ZFS and has compression enabled for /var/log, disable log
|
227
|
* compression by default. See https://redmine.pfsense.org/issues/12011
|
228
|
*/
|
229
|
$varlog_compression_state = 'off';
|
230
|
if (is_module_loaded('zfs.ko')) {
|
231
|
exec("/sbin/zfs get -H compression /var/log | /usr/bin/awk '{print $3;}'", $varlog_compression_state);
|
232
|
$varlog_compression_state = $varlog_compression_state[0];
|
233
|
}
|
234
|
if (file_exists("{$g['conf_path']}/trigger_initial_wizard") &&
|
235
|
(trim($varlog_compression_state) != 'off')) {
|
236
|
touch("{$g['conf_path']}/syslog_default_uncompressed");
|
237
|
}
|
238
|
/* start syslogd */
|
239
|
system_syslogd_start();
|
240
|
|
241
|
/* set pam shell authentication backend */
|
242
|
set_pam_auth();
|
243
|
|
244
|
/* Log the RAM disk restore messages. */
|
245
|
if (file_exists("/var/log/restore_ramdisk_store.boot")) {
|
246
|
exec("/usr/bin/logger -f /var/log/restore_ramdisk_store.boot");
|
247
|
}
|
248
|
|
249
|
/* setup interface microcode which improves tcp/ip speed */
|
250
|
echo "Setting up interfaces microcode...";
|
251
|
setup_microcode();
|
252
|
echo "done.\n";
|
253
|
|
254
|
if (strlen(config_get_path('system/mds_disable', '')) > 0) {
|
255
|
set_single_sysctl("hw.mds_disable" , (int)config_get_path('system/mds_disable'));
|
256
|
}
|
257
|
|
258
|
/* remove leftover dhcp6c lock file if it exist */
|
259
|
if (file_exists("/tmp/dhcp6c_lock")) {
|
260
|
@unlink("/tmp/dhcp6c_lock");
|
261
|
echo("Removed leftover dhcp6c lock file: /tmp/dhcp6c_lock\n");
|
262
|
}
|
263
|
if (file_exists("/tmp/dhcp6c_ifs")) {
|
264
|
@unlink("/tmp/dhcp6c_ifs");
|
265
|
}
|
266
|
|
267
|
/* set up interfaces */
|
268
|
if (!$debugging) {
|
269
|
mute_kernel_msgs();
|
270
|
}
|
271
|
interfaces_configure();
|
272
|
interfaces_sync_setup();
|
273
|
if (!$debugging) {
|
274
|
unmute_kernel_msgs();
|
275
|
}
|
276
|
|
277
|
/* re-make hosts file after configuring interfaces */
|
278
|
system_hosts_generate();
|
279
|
|
280
|
/* start sshd */
|
281
|
if (config_path_enabled('system/ssh')) {
|
282
|
echo "Starting Secure Shell Services...";
|
283
|
send_event("service reload sshd");
|
284
|
echo "done.\n";
|
285
|
}
|
286
|
|
287
|
/* start OpenVPN server & clients */
|
288
|
echo "Syncing OpenVPN settings...";
|
289
|
openvpn_resync_all();
|
290
|
echo "done.\n";
|
291
|
|
292
|
/* generate resolv.conf */
|
293
|
system_resolvconf_generate();
|
294
|
|
295
|
/* setup altq + pf */
|
296
|
filter_configure_sync();
|
297
|
|
298
|
/* start pflog */
|
299
|
echo "Starting PFLOG...";
|
300
|
filter_pflog_start();
|
301
|
echo "done.\n";
|
302
|
|
303
|
/* reconfigure our gateway monitor */
|
304
|
setup_gateways_monitor();
|
305
|
|
306
|
/* set up static routes */
|
307
|
echo "Setting up static routes...";
|
308
|
system_routing_configure();
|
309
|
echo "done.\n";
|
310
|
|
311
|
if (config_path_enabled('unbound') ||
|
312
|
config_path_enabled('dnsmasq')) {
|
313
|
echo "Setting up DNSs...\n";
|
314
|
/* start dnsmasq service */
|
315
|
services_dnsmasq_configure();
|
316
|
|
317
|
/* start unbound service */
|
318
|
services_unbound_configure();
|
319
|
}
|
320
|
|
321
|
echo "Synchronizing user settings...";
|
322
|
local_reset_accounts();
|
323
|
echo "done.\n";
|
324
|
|
325
|
/* configure cron service */
|
326
|
echo "Configuring CRON...";
|
327
|
configure_cron();
|
328
|
echo "done.\n";
|
329
|
|
330
|
/* enable routing */
|
331
|
system_routing_enable();
|
332
|
|
333
|
/* Set initial time by using IP addresses in case DNS is not available
|
334
|
* This works around issues with DNSSEC and gives the firewall a better chance
|
335
|
* of having a highly accurate clock at boot.
|
336
|
* NG 7352, NG 7447
|
337
|
*/
|
338
|
|
339
|
/* Default to Google Public NTP servers */
|
340
|
$ntp_boot_time_servers = '216.239.35.0 216.239.35.4 216.239.35.8 216.239.35.12';
|
341
|
/* File to allow users to override default behavior.
|
342
|
* Servers must be a single line with space-separated IP address entries ONLY as
|
343
|
* DNS may not be functional. */
|
344
|
$ntp_boot_time_servers_override = '/conf/ntp-boot-time-servers';
|
345
|
|
346
|
/* Handle user override of NTP bootstrap behavior */
|
347
|
if (file_exists($ntp_boot_time_servers_override)) {
|
348
|
if (filesize($ntp_boot_time_servers_override) > 0) {
|
349
|
/* Read servers from file if the file is not empty. */
|
350
|
$servers = file_get_contents($ntp_boot_time_servers_override);
|
351
|
$checkservers = explode(' ', trim($servers));
|
352
|
$goodservers = array();
|
353
|
/* Only add entries which are valid IP addresses. */
|
354
|
foreach ($checkservers as $ntpserver) {
|
355
|
if (is_ipaddr($ntpserver)) {
|
356
|
$goodservers[] = escapeshellarg($ntpserver);
|
357
|
}
|
358
|
}
|
359
|
$ntp_boot_time_servers = implode(' ', $goodservers);
|
360
|
} else {
|
361
|
/* Disable check if the file exists but is empty. */
|
362
|
$ntp_boot_time_servers = '';
|
363
|
}
|
364
|
}
|
365
|
|
366
|
if (!empty($ntp_boot_time_servers)) {
|
367
|
echo gettext("Bootstrapping clock...");
|
368
|
mwexec("/usr/bin/timeout -k 45 30 /usr/local/sbin/ntpd -g -q -c /dev/null {$ntp_boot_time_servers}");
|
369
|
echo gettext("done.") . "\n";
|
370
|
}
|
371
|
|
372
|
/* Enable ntpd */
|
373
|
system_ntp_configure();
|
374
|
|
375
|
if ($realmem > 0 and $realmem < 65) {
|
376
|
echo "System has less than 65 megabytes of ram {$realmem}. Delaying webConfigurator startup.\n";
|
377
|
/* start webConfigurator up on final pass */
|
378
|
mwexec("/usr/local/sbin/pfSctl -c 'service restart webgui'");
|
379
|
} else {
|
380
|
/* start web server */
|
381
|
system_webgui_start();
|
382
|
}
|
383
|
|
384
|
/* Configure console (and serial port - if necessary). */
|
385
|
console_configure();
|
386
|
|
387
|
/* start DHCP service */
|
388
|
services_dhcpd_configure();
|
389
|
|
390
|
/* start dhcpleases dhcp hosts leases program */
|
391
|
system_dhcpleases_configure();
|
392
|
|
393
|
/* start DHCP relay */
|
394
|
services_dhcrelay_configure();
|
395
|
|
396
|
/* start DHCP6 relay */
|
397
|
services_dhcrelay6_configure();
|
398
|
|
399
|
/* dyndns service updates */
|
400
|
send_event("service reload dyndnsall");
|
401
|
|
402
|
/* Run a filter configure now that most all services have started */
|
403
|
filter_configure_sync();
|
404
|
|
405
|
/* setup pppoe and pptp */
|
406
|
vpn_setup();
|
407
|
|
408
|
/* start the captive portal */
|
409
|
captiveportal_configure();
|
410
|
|
411
|
/* start Voucher support */
|
412
|
voucher_configure();
|
413
|
|
414
|
/* run any shell commands specified in config.xml */
|
415
|
system_do_shell_commands();
|
416
|
|
417
|
/* start IPsec tunnels */
|
418
|
$ipsec_dynamic_hosts = ipsec_configure();
|
419
|
|
420
|
/* start SNMP service */
|
421
|
services_snmpd_configure();
|
422
|
|
423
|
/* power down hard drive if needed/set */
|
424
|
system_set_harddisk_standby();
|
425
|
|
426
|
/* lock down console if necessary */
|
427
|
reload_ttys();
|
428
|
|
429
|
/* load graphing functions */
|
430
|
enable_rrd_graphing();
|
431
|
|
432
|
/* enable watchdog if supported */
|
433
|
enable_watchdog();
|
434
|
|
435
|
/* if <system><afterbootupshellcmd> exists, execute the command */
|
436
|
$afterbootupshellcmd = config_get_path('system/afterbootupshellcmd', '');
|
437
|
if (!empty($afterbootupshellcmd)) {
|
438
|
echo "Running afterbootupshellcmd {$afterbootupshellcmd}\n";
|
439
|
mwexec($afterbootupshellcmd);
|
440
|
}
|
441
|
|
442
|
if ($physmem < $g['minimum_ram_warning']) {
|
443
|
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);
|
444
|
set_sysctl(array(
|
445
|
"net.inet.tcp.recvspace" => "4096",
|
446
|
"net.inet.tcp.sendspace" => "4096"
|
447
|
));
|
448
|
}
|
449
|
|
450
|
if (file_exists("/conf/ram_disks_failed")) {
|
451
|
file_notice("RAM Disks", "RAM disk creation failed. Reverted to traditional storage. Check RAM disk sizes.", "RAM Disks");
|
452
|
}
|
453
|
|
454
|
/* if we are operating at 1000 then increase timeouts.
|
455
|
this was never accounted for after moving to 1000 hz */
|
456
|
$kern_hz = get_single_sysctl('kern.clockrate');
|
457
|
$kern_hz = substr($kern_hz, strpos($kern_hz, "hz = ") + 5);
|
458
|
$kern_hz = substr($kern_hz, 0, strpos($kern_hz, ","));
|
459
|
if ($kern_hz == "1000") {
|
460
|
set_single_sysctl("net.inet.tcp.rexmit_min" , "30");
|
461
|
}
|
462
|
|
463
|
/* start the igmpproxy daemon */
|
464
|
services_igmpproxy_configure();
|
465
|
|
466
|
/* start the upnp daemon if it is enabled */
|
467
|
upnp_start();
|
468
|
|
469
|
/* If powerd is enabled, lets launch it */
|
470
|
activate_powerd();
|
471
|
|
472
|
/* Set preferred protocol */
|
473
|
prefer_ipv4_or_ipv6();
|
474
|
|
475
|
/* Resync / Reinstall packages if need be */
|
476
|
if (file_exists("{$g['conf_path']}/needs_package_sync")) {
|
477
|
echo "Triggering packages reinstallation in background\n";
|
478
|
mwexec_bg("{$g['etc_path']}/rc.package_reinstall_all");
|
479
|
} else {
|
480
|
/* Detect installed binary pkgs that are not registered in the system */
|
481
|
register_all_installed_packages();
|
482
|
}
|
483
|
|
484
|
/* Give syslogd a kick after everything else has been initialized, otherwise it can occasionally
|
485
|
fail to route syslog messages properly on both IPv4 and IPv6 */
|
486
|
system_sshguard_stop();
|
487
|
system_syslogd_start();
|
488
|
|
489
|
/* done */
|
490
|
$g['booting'] = false;
|
491
|
@unlink("{$g['varrun_path']}/booting");
|
492
|
|
493
|
/* re-enable CARP */
|
494
|
enable_carp();
|
495
|
|
496
|
/* If there are ipsec dynamic hosts try again to reload the tunnels as rc.newipsecdns does */
|
497
|
if ($ipsec_dynamic_hosts) {
|
498
|
echo gettext("Configuring IPsec VPN for dynamic hosts... ");
|
499
|
ipsec_configure();
|
500
|
|
501
|
/* restart dpinger if PH1 remote gateway == fqdn and PH2 mode == VTI
|
502
|
* see https://redmine.pfsense.org/issues/12763 */
|
503
|
foreach (config_get_path('ipsec/phase1', []) as $p1) {
|
504
|
if (!isset($p1['mobile']) && !isset($p1['disabled']) && is_fqdn($p1['remote-gateway'])) {
|
505
|
foreach (config_get_path('ipsec/phase2', []) as $p2) {
|
506
|
if (!isset($p2['disabled']) && ($p2['mode'] == 'vti')) {
|
507
|
setup_gateways_monitor();
|
508
|
break 2;
|
509
|
}
|
510
|
}
|
511
|
}
|
512
|
}
|
513
|
|
514
|
echo gettext("done") . "\n";
|
515
|
}
|
516
|
if ($ipsec_dynamic_hosts || !empty($filterdns)) {
|
517
|
echo gettext("Configuring filter for dynamic IPsec VPN hosts... ");
|
518
|
filter_configure();
|
519
|
echo gettext("done") . "\n";
|
520
|
}
|
521
|
|
522
|
/* Dynamically-configured system aliases may only be ready after the
|
523
|
* earlier filter reload calls. Hence alias issues with ruleset
|
524
|
* generation will only trigger alerts once the system has finished
|
525
|
* booting. Now that bootup is complete, reload the filter to alert of
|
526
|
* any alias issues. */
|
527
|
filter_configure_sync();
|
528
|
|
529
|
led_normalize();
|
530
|
|
531
|
notify_all_remote("Bootup complete");
|
532
|
?>
|