Project

General

Profile

Download (12.4 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-2021 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 and extra data on bsdinstall config restore
91
 * see https://redmine.pfsense.org/issues/12518 */
92
if (file_exists("{$g['conf_path']}/trigger_restore_config_after_bsdinstall")) {
93
	copy("/cf/conf/config.xml", "{$g['tmp_path']}/config_to_restore.xml");
94
	restore_backup("{$g['tmp_path']}/config_to_restore.xml");
95
	@unlink("{$g['tmp_path']}/config_to_restore.xml");
96
	@unlink("{$g['conf_path']}/trigger_restore_config_after_bsdinstall");
97
}
98

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

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

    
113
echo "Loading configuration...";
114
parse_config_bootup();
115
echo "done.\n";
116

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

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

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

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

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

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

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

    
176
/* enable optional crypto modules */
177
load_crypto();
178

    
179
/* enable optional thermal sensor modules */
180
load_thermal_hardware();
181

    
182
/* set up our timezone */
183
system_timezone_configure();
184

    
185
/* set up our hostname */
186
system_hostname_configure();
187

    
188
/* make hosts file */
189
system_hosts_generate();
190

    
191
/* configure loopback interface */
192
interfaces_loopback_configure();
193

    
194
/* Setup Local CA Trust Store */
195
ca_setup_trust_store();
196

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

    
212
/* set pam shell authentication backend */
213
set_pam_auth();
214

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

    
220
init_config_arr(array('system', 'ssh'));
221
if (isset($config['system']['ssh']['enable'])) {
222
	echo "Starting Secure Shell Services...";
223
	send_event("service reload sshd");
224
	echo "done.\n";
225
}
226

    
227
/* setup interface microcode which improves tcp/ip speed */
228
echo "Setting up interfaces microcode...";
229
setup_microcode();
230
echo "done.\n";
231

    
232
if (isset($config['system']['mds_disable']) &&
233
    (strlen($config['system']['mds_disable']) > 0)) {
234
	set_single_sysctl("hw.mds_disable" , (int)$config['system']['mds_disable']);
235
}
236

    
237
/* remove leftover dhcp6c lock files if they exist */
238
foreach ($config['interfaces'] as $interface) {
239
        if ($interface['ipaddrv6'] == "dhcp6") {
240
            if (file_exists("/tmp/dhcp6c_" . $interface['if'] . "_lock")) {
241
                @unlink("/tmp/dhcp6c_" . $interface['if'] . "_lock");
242
                echo("Removed leftover dhcp6c lock file: " . "/tmp/dhcp6c_" . $interface['if'] . "_lock\n");
243
            }
244
         }
245
     }
246

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

    
257
/* re-make hosts file after configuring interfaces */
258
system_hosts_generate();
259

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

    
265
/* generate resolv.conf */
266
system_resolvconf_generate();
267

    
268
/* setup altq + pf */
269
filter_configure_sync();
270

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

    
276
/* reconfigure our gateway monitor */
277
setup_gateways_monitor();
278

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

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

    
292
	/* start unbound service */
293
	services_unbound_configure();
294
}
295

    
296
echo "Synchronizing user settings...";
297
local_reset_accounts();
298
echo "done.\n";
299

    
300
if ($realmem > 0 and $realmem < 65) {
301
	echo "System has less than 65 megabytes of ram {$realmem}.  Delaying webConfigurator startup.\n";
302
	/* start webConfigurator up on final pass */
303
	mwexec("/usr/local/sbin/pfSctl -c 'service restart webgui'");
304
} else {
305
	/* start web server */
306
	system_webgui_start();
307
}
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
/* Enable ntpd */
318
system_ntp_configure();
319

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

    
323
/* start DHCP service */
324
services_dhcpd_configure();
325

    
326
/* start dhcpleases dhcp hosts leases program */
327
system_dhcpleases_configure();
328

    
329
/* start DHCP relay */
330
services_dhcrelay_configure();
331

    
332
/* start DHCP6 relay */
333
services_dhcrelay6_configure();
334

    
335
/* dyndns service updates */
336
send_event("service reload dyndnsall");
337

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

    
341
/* setup pppoe and pptp */
342
vpn_setup();
343

    
344
/* start the captive portal */
345
captiveportal_configure();
346

    
347
/* start Voucher support */
348
voucher_configure();
349

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

    
353
/* start IPsec tunnels */
354
$ipsec_dynamic_hosts = ipsec_configure();
355

    
356
/* start SNMP service */
357
services_snmpd_configure();
358

    
359
/* power down hard drive if needed/set */
360
system_set_harddisk_standby();
361

    
362
/* lock down console if necessary */
363
reload_ttys();
364

    
365
/* load graphing functions */
366
enable_rrd_graphing();
367

    
368
/* enable watchdog if supported */
369
enable_watchdog();
370

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

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

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

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

    
400
/* start the igmpproxy daemon */
401
services_igmpproxy_configure();
402

    
403
/* start the upnp daemon if it is enabled */
404
upnp_start();
405

    
406
/* If powerd is enabled, lets launch it */
407
activate_powerd();
408

    
409
/* Set preferred protocol */
410
prefer_ipv4_or_ipv6();
411

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

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

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

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

    
441
led_normalize();
442

    
443
notify_all_remote("Bootup complete");
444
?>
(22-22/84)