Project

General

Profile

Download (12.9 KB) Statistics
| Branch: | Tag: | Revision:
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-2022 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

    
72
/* get system memory amount */
73
$memory = get_memory();
74
$physmem = $memory[0];
75
$realmem = $memory[1];
76
echo " done.\n";
77

    
78

    
79
/* save dmesg output to file */
80
system_dmesg_save();
81

    
82
/* check whether config reset is desired (via hardware button on WRAP/ALIX) */
83
system_check_reset_button();
84

    
85
/* remove previous firmware upgrade if present */
86
if (file_exists("/root/firmware.tgz")) {
87
	unlink("/root/firmware.tgz");
88
}
89

    
90
/* restore RRD, SSH keys and extra data on bsdinstall config restore
91
 * see https://redmine.pfsense.org/issues/12518 */
92
if (file_exists("{$g['conf_path']}/installer_copied_config") &&
93
    file_exists("{$g['conf_path']}/restore_config_data")) {
94
	copy("/cf/conf/config.xml", "{$g['tmp_path']}/config_to_restore.xml");
95
	restore_backup("{$g['tmp_path']}/config_to_restore.xml");
96
	@unlink("{$g['tmp_path']}/config_to_restore.xml");
97
	@unlink("{$g['conf_path']}/installer_copied_config");
98
	@unlink("{$g['conf_path']}/restore_config_data");
99
}
100

    
101
/* Triggering of the initial setup wizard after reboot has been requested */
102
if (file_exists("{$g['conf_path']}/trigger_initial_wizard_after_reboot")) {
103
	touch("{$g['conf_path']}/trigger_initial_wizard");
104
	@unlink("{$g['conf_path']}/trigger_initial_wizard_after_reboot");
105
}
106

    
107
/* start devd (dhclient now uses it) */
108
echo "Starting device manager (devd)...";
109
mute_kernel_msgs();
110
start_devd();
111
set_device_perms();
112
unmute_kernel_msgs();
113
echo "done.\n";
114

    
115
echo "Loading configuration...";
116
parse_config_bootup();
117
echo "done.\n";
118

    
119
mwexec("/usr/sbin/gnid > {$g['vardb_path']}/uniqueid 2>/dev/null");
120

    
121
/* run any early shell commands specified in config.xml */
122
system_do_shell_commands(1);
123

    
124
// Only do the alternate interface checks if:
125
// 1) The user has not yet run the initial wizard; and
126
// 2) The user has not used the console menu to setup interface assignments
127
if (file_exists("{$g['conf_path']}/trigger_initial_wizard") && !file_exists("{$g['conf_path']}/assign_complete")) {
128
	check_for_alternate_interfaces();
129
}
130

    
131
/* Convert configuration
132
 * This must happen before the interface mismatch test, see
133
 * https://redmine.pfsense.org/issues/7809 */
134
echo "Updating configuration...";
135
convert_config();
136
echo "done.\n";
137

    
138
/*
139
 *	Determine if we need to throw a interface exception
140
 *	and ask the user to reassign interfaces.  This will
141
 *	avoid a reboot and that is a good thing.
142
 */
143
while (is_interface_mismatch() == true) {
144
	led_assigninterfaces();
145
	if (isset($config['revision'])) {
146
		if (file_exists("{$g['tmp_path']}/missing_interfaces")) {
147
			echo "Warning: Configuration references interfaces that do not exist: " . file_get_contents("{$g['tmp_path']}/missing_interfaces") . "\n";
148
		}
149
		echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
150
	} else {
151
		echo "\nDefault interfaces not found -- Running interface assignment option.\n";
152
	}
153
	$ifaces = get_interface_list();
154
	if (is_array($ifaces)) {
155
		foreach ($ifaces as $iface => $ifdata) {
156
			interfaces_bring_up($iface);
157
		}
158
	}
159
	if (set_networking_interfaces_ports() == -1) {
160
		echo "\npfSense cannot continue without at least one Network Interface Card.\n";
161
		echo "\nHalting the system.\n";
162
		system("/sbin/shutdown -h now");
163
		exit(0);
164
	}
165
	reload_interfaces_sync();
166
	led_kitt();
167
}
168

    
169
echo "Checking config backups consistency...";
170
cleanup_backupcache(true);
171
echo "done.\n";
172

    
173
/* read in /etc/sysctl.conf and set values if needed */
174
echo "Setting up extended sysctls...";
175
system_setup_sysctl();
176
echo "done.\n";
177

    
178
/* enable optional crypto modules */
179
load_crypto();
180

    
181
/* enable optional thermal sensor modules */
182
load_thermal_hardware();
183

    
184
/* set up our timezone */
185
system_timezone_configure();
186

    
187
/* set up our hostname */
188
system_hostname_configure();
189

    
190
/* make hosts file */
191
system_hosts_generate();
192

    
193
/* configure loopback interface */
194
interfaces_loopback_configure();
195

    
196
/* Setup Local CA Trust Store */
197
ca_setup_trust_store();
198

    
199
/* If the system uses ZFS and has compression enabled for /var/log, disable log
200
 * compression by default. See https://redmine.pfsense.org/issues/12011
201
 */
202
$varlog_compression_state = 'off';
203
if (is_module_loaded('zfs.ko')) {
204
	exec("/sbin/zfs get -H compression /var/log | /usr/bin/awk '{print $3;}'", $varlog_compression_state);
205
	$varlog_compression_state = $varlog_compression_state[0];
206
}
207
if (file_exists("{$g['conf_path']}/trigger_initial_wizard") &&
208
    (trim($varlog_compression_state) != 'off')) {
209
	touch("{$g['conf_path']}/syslog_default_uncompressed");
210
}
211
/* start syslogd */
212
system_syslogd_start();
213

    
214
/* set pam shell authentication backend */
215
set_pam_auth();
216

    
217
/* Log the RAM disk restore messages. */
218
if (file_exists("/var/log/restore_ramdisk_store.boot")) {
219
	exec("logger -f /var/log/restore_ramdisk_store.boot");
220
}
221

    
222
init_config_arr(array('system', 'ssh'));
223
if (isset($config['system']['ssh']['enable'])) {
224
	echo "Starting Secure Shell Services...";
225
	send_event("service reload sshd");
226
	echo "done.\n";
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 files if they exist */
240
foreach ($config['interfaces'] as $interface) {
241
        if ($interface['ipaddrv6'] == "dhcp6") {
242
            if (file_exists("/tmp/dhcp6c_" . $interface['if'] . "_lock")) {
243
                @unlink("/tmp/dhcp6c_" . $interface['if'] . "_lock");
244
                echo("Removed leftover dhcp6c lock file: " . "/tmp/dhcp6c_" . $interface['if'] . "_lock\n");
245
            }
246
         }
247
     }
248

    
249
/* set up interfaces */
250
if (!$debugging) {
251
	mute_kernel_msgs();
252
}
253
interfaces_configure();
254
interfaces_sync_setup();
255
if (!$debugging) {
256
	unmute_kernel_msgs();
257
}
258

    
259
/* re-make hosts file after configuring interfaces */
260
system_hosts_generate();
261

    
262
/* start OpenVPN server & clients */
263
echo "Syncing OpenVPN settings...";
264
openvpn_resync_all();
265
echo "done.\n";
266

    
267
/* generate resolv.conf */
268
system_resolvconf_generate();
269

    
270
/* setup altq + pf */
271
filter_configure_sync();
272

    
273
/* start pflog */
274
echo "Starting PFLOG...";
275
filter_pflog_start();
276
echo "done.\n";
277

    
278
/* reconfigure our gateway monitor */
279
setup_gateways_monitor();
280

    
281
/* set up static routes */
282
echo "Setting up static routes...";
283
system_routing_configure();
284
echo "done.\n";
285

    
286
init_config_arr(array('unbound'));
287
init_config_arr(array('dnsmasq'));
288
if (isset($config['unbound']['enable']) ||
289
    isset($config['dnsmasq']['enable'])) {
290
	echo "Setting up DNSs...\n";
291
	/* start dnsmasq service */
292
	services_dnsmasq_configure();
293

    
294
	/* start unbound service */
295
	services_unbound_configure();
296
}
297

    
298
echo "Synchronizing user settings...";
299
local_reset_accounts();
300
echo "done.\n";
301

    
302
if ($realmem > 0 and $realmem < 65) {
303
	echo "System has less than 65 megabytes of ram {$realmem}.  Delaying webConfigurator startup.\n";
304
	/* start webConfigurator up on final pass */
305
	mwexec("/usr/local/sbin/pfSctl -c 'service restart webgui'");
306
} else {
307
	/* start web server */
308
	system_webgui_start();
309
}
310

    
311
/* configure cron service */
312
echo "Configuring CRON...";
313
configure_cron();
314
echo "done.\n";
315

    
316
/* enable routing */
317
system_routing_enable();
318

    
319
/* Enable ntpd */
320
system_ntp_configure();
321

    
322
/* Configure console (and serial port - if necessary). */
323
console_configure();
324

    
325
/* start DHCP service */
326
services_dhcpd_configure();
327

    
328
/* start dhcpleases dhcp hosts leases program */
329
system_dhcpleases_configure();
330

    
331
/* start DHCP relay */
332
services_dhcrelay_configure();
333

    
334
/* start DHCP6 relay */
335
services_dhcrelay6_configure();
336

    
337
/* dyndns service updates */
338
send_event("service reload dyndnsall");
339

    
340
/* Run a filter configure now that most all services have started */
341
filter_configure_sync();
342

    
343
/* setup pppoe and pptp */
344
vpn_setup();
345

    
346
/* start the captive portal */
347
captiveportal_configure();
348

    
349
/* start Voucher support */
350
voucher_configure();
351

    
352
/* run any shell commands specified in config.xml */
353
system_do_shell_commands();
354

    
355
/* start IPsec tunnels */
356
$ipsec_dynamic_hosts = ipsec_configure();
357

    
358
/* start SNMP service */
359
services_snmpd_configure();
360

    
361
/* power down hard drive if needed/set */
362
system_set_harddisk_standby();
363

    
364
/* lock down console if necessary */
365
reload_ttys();
366

    
367
/* load graphing functions */
368
enable_rrd_graphing();
369

    
370
/* enable watchdog if supported */
371
enable_watchdog();
372

    
373
/* if <system><afterbootupshellcmd> exists, execute the command */
374
if ($config['system']['afterbootupshellcmd'] <> "") {
375
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
376
	mwexec($config['system']['afterbootupshellcmd']);
377
}
378

    
379
if ($physmem < $g['minimum_ram_warning']) {
380
	require_once("/etc/inc/notices.inc");
381
	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);
382
	set_sysctl(array(
383
		"net.inet.tcp.recvspace" => "4096",
384
		"net.inet.tcp.sendspace" => "4096"
385
	));
386
}
387

    
388
if (file_exists("/conf/ram_disks_failed")) {
389
	require_once("/etc/inc/notices.inc");
390
	file_notice("RAM Disks", "RAM disk creation failed. Reverted to traditional storage. Check RAM disk sizes.", "RAM Disks");
391
}
392

    
393
/* if we are operating at 1000 then increase timeouts.
394
   this was never accounted for after moving to 1000 hz */
395
$kern_hz = get_single_sysctl('kern.clockrate');
396
$kern_hz = substr($kern_hz, strpos($kern_hz, "hz = ") + 5);
397
$kern_hz = substr($kern_hz, 0, strpos($kern_hz, ","));
398
if ($kern_hz == "1000") {
399
	set_single_sysctl("net.inet.tcp.rexmit_min" , "30");
400
}
401

    
402
/* start the igmpproxy daemon */
403
services_igmpproxy_configure();
404

    
405
/* start the upnp daemon if it is enabled */
406
upnp_start();
407

    
408
/* If powerd is enabled, lets launch it */
409
activate_powerd();
410

    
411
/* Set preferred protocol */
412
prefer_ipv4_or_ipv6();
413

    
414
/* Resync / Reinstall packages if need be */
415
if (file_exists("{$g['conf_path']}/needs_package_sync")) {
416
	echo "Triggering packages reinstallation in background\n";
417
	mwexec_bg("{$g['etc_path']}/rc.package_reinstall_all");
418
} else {
419
	/* Detect installed binary pkgs that are not registered in the system */
420
	register_all_installed_packages();
421
}
422

    
423
/* Give syslogd a kick after everything else has been initialized, otherwise it can occasionally
424
   fail to route syslog messages properly on both IPv4 and IPv6 */
425
system_syslogd_start();
426

    
427
/* done */
428
unset($g['booting']);
429
@unlink("{$g['varrun_path']}/booting");
430

    
431
/* If there are ipsec dynamic hosts try again to reload the tunnels as rc.newipsecdns does */
432
if ($ipsec_dynamic_hosts) {
433
	echo gettext("Configuring IPsec VPN for dynamic hosts... ");
434
	ipsec_configure();
435
	echo gettext("done") . "\n";
436
}
437
if ($ipsec_dynamic_hosts || !empty($filterdns)) {
438
	echo gettext("Configuring filter for dynamic IPsec VPN hosts... ");
439
	filter_configure();
440
	echo gettext("done") . "\n";
441
}
442

    
443
led_normalize();
444

    
445
// Ensure that any custom repository specifications that were downloaded are now clearred. 
446
// This ensure that no "left over" repos or messages remain
447
// If the custom repo is still required, it will be downloaded once the user visists system/update
448
// Basically this circumvents the 24 hour cache when custom repositories are in use
449
$basename = "/usr/local/share/{$g['product_name']}/pkg/repos/pfSense-repo-custom.*";
450
foreach (glob($basename) as $f) {
451
    unlink($f);
452
}
453

    
454
notify_all_remote("Bootup complete");
455
?>
(22-22/84)