Project

General

Profile

Download (11.2 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/web/wg.inc");
64
echo ".";
65
require_once("/etc/inc/openvpn.inc");
66
echo ".";
67
require_once("/etc/inc/captiveportal.inc");
68
echo ".";
69
require_once("/etc/inc/rrd.inc");
70
echo ".";
71
require_once("/etc/inc/pfsense-utils.inc");
72
echo ".";
73

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

    
80

    
81
/* save dmesg output to file */
82
system_dmesg_save();
83

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

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

    
92
/* Triggering of the initial setup wizard after reboot has been requested */
93
if (file_exists("{$g['conf_path']}/trigger_initial_wizard_after_reboot")) {
94
	touch("{$g['conf_path']}/trigger_initial_wizard");
95
	@unlink("{$g['conf_path']}/trigger_initial_wizard_after_reboot");
96
}
97

    
98
/* start devd (dhclient now uses it) */
99
echo "Starting device manager (devd)...";
100
mute_kernel_msgs();
101
start_devd();
102
set_device_perms();
103
unmute_kernel_msgs();
104
echo "done.\n";
105

    
106
echo "Loading configuration...";
107
parse_config_bootup();
108
echo "done.\n";
109

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

    
112
/* run any early shell commands specified in config.xml */
113
system_do_shell_commands(1);
114

    
115
// Only do the alternate interface checks if:
116
// 1) The user has not yet run the initial wizard; and
117
// 2) The user has not used the console menu to setup interface assignments
118
if (file_exists("{$g['conf_path']}/trigger_initial_wizard") && !file_exists("{$g['conf_path']}/assign_complete")) {
119
	check_for_alternate_interfaces();
120
}
121

    
122
/* Convert configuration
123
 * This must happen before the interface mismatch test, see
124
 * https://redmine.pfsense.org/issues/7809 */
125
echo "Updating configuration...";
126
convert_config();
127
echo "done.\n";
128

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

    
160
echo "Checking config backups consistency...";
161
cleanup_backupcache(true);
162
echo "done.\n";
163

    
164
/* read in /etc/sysctl.conf and set values if needed */
165
echo "Setting up extended sysctls...";
166
system_setup_sysctl();
167
echo "done.\n";
168

    
169
/* enable optional crypto modules */
170
load_crypto();
171

    
172
/* enable optional thermal sensor modules */
173
load_thermal_hardware();
174

    
175
/* set up our timezone */
176
system_timezone_configure();
177

    
178
/* set up our hostname */
179
system_hostname_configure();
180

    
181
/* make hosts file */
182
system_hosts_generate();
183

    
184
/* configure loopback interface */
185
interfaces_loopback_configure();
186

    
187
/* Setup Local CA Trust Store */
188
ca_setup_trust_store();
189

    
190
/* start syslogd */
191
system_syslogd_start();
192

    
193
/* set pam shell authentication backend */
194
set_pam_auth();
195

    
196
/* Log the RAM disk restore messages. */
197
if (file_exists("/var/log/restore_ramdisk_store.boot")) {
198
	exec("logger -f /var/log/restore_ramdisk_store.boot");
199
}
200

    
201
echo "Starting Secure Shell Services...";
202
send_event("service reload sshd");
203
echo "done.\n";
204

    
205
/* setup interface microcode which improves tcp/ip speed */
206
echo "Setting up interfaces microcode...";
207
setup_microcode();
208
echo "done.\n";
209

    
210
/* pcscd daemon must be started before IPsec */
211
echo "Starting PC/SC Smart Card Services...";
212
mwexec_bg("/usr/local/sbin/pcscd");
213
echo "done.\n";
214

    
215
if (isset($config['system']['mds_disable']) &&
216
    (strlen($config['system']['mds_disable']) > 0)) {
217
	set_single_sysctl("hw.mds_disable" , (int)$config['system']['mds_disable']);
218
}
219

    
220
/* remove leftover dhcp6c lock files if they exist */
221
foreach ($config['interfaces'] as $interface) {
222
        if ($interface['ipaddrv6'] == "dhcp6") {
223
            if (file_exists("/tmp/dhcp6c_" . $interface['if'] . "_lock")) {
224
                @unlink("/tmp/dhcp6c_" . $interface['if'] . "_lock");
225
                echo("Removed leftover dhcp6c lock file: " . "/tmp/dhcp6c_" . $interface['if'] . "_lock\n");
226
            }
227
         }
228
     }
229

    
230
/* set up interfaces */
231
if (!$debugging) {
232
	mute_kernel_msgs();
233
}
234
interfaces_configure();
235
interfaces_sync_setup();
236
if (!$debugging) {
237
	unmute_kernel_msgs();
238
}
239

    
240
/* re-make hosts file after configuring interfaces */
241
system_hosts_generate();
242

    
243
/* start OpenVPN server & clients */
244
echo "Syncing OpenVPN settings...";
245
openvpn_resync_all();
246
echo "done.\n";
247

    
248
/* generate resolv.conf */
249
system_resolvconf_generate();
250

    
251
/* setup altq + pf */
252
filter_configure_sync();
253

    
254
/* start pflog */
255
echo "Starting PFLOG...";
256
filter_pflog_start();
257
echo "done.\n";
258

    
259
/* reconfigure our gateway monitor */
260
echo "Setting up gateway monitors...";
261
setup_gateways_monitor();
262
echo "done.\n";
263

    
264
/* set up static routes */
265
echo "Setting up static routes...";
266
system_routing_configure();
267
echo "done.\n";
268

    
269
echo "Setting up DNSs...\n";
270
/* start dnsmasq service */
271
services_dnsmasq_configure();
272

    
273
/* start unbound service */
274
services_unbound_configure();
275

    
276
echo "Synchronizing user settings...";
277
local_reset_accounts();
278
echo "done.\n";
279

    
280
if ($realmem > 0 and $realmem < 65) {
281
	echo "System has less than 65 megabytes of ram {$realmem}.  Delaying webConfigurator startup.\n";
282
	/* start webConfigurator up on final pass */
283
	mwexec("/usr/local/sbin/pfSctl -c 'service restart webgui'");
284
} else {
285
	/* start web server */
286
	system_webgui_start();
287
}
288

    
289
/* configure cron service */
290
echo "Configuring CRON...";
291
configure_cron();
292
echo "done.\n";
293

    
294
/* enable routing */
295
system_routing_enable();
296

    
297
/* Enable ntpd */
298
system_ntp_configure();
299

    
300
/* Configure console (and serial port - if necessary). */
301
console_configure();
302

    
303
/* start DHCP service */
304
services_dhcpd_configure();
305

    
306
/* start dhcpleases dhcp hosts leases program */
307
system_dhcpleases_configure();
308

    
309
/* start DHCP relay */
310
services_dhcrelay_configure();
311

    
312
/* start DHCP6 relay */
313
services_dhcrelay6_configure();
314

    
315
/* dyndns service updates */
316
send_event("service reload dyndnsall");
317

    
318
/* Run a filter configure now that most all services have started */
319
filter_configure_sync();
320

    
321
/* setup pppoe and pptp */
322
vpn_setup();
323

    
324
/* Setup WireGuard tunnels. */
325
wg_configure();
326

    
327
/* start the captive portal */
328
captiveportal_configure();
329

    
330
/* start Voucher support */
331
voucher_configure();
332

    
333
/* run any shell commands specified in config.xml */
334
system_do_shell_commands();
335

    
336
/* start IPsec tunnels */
337
$ipsec_dynamic_hosts = ipsec_configure();
338

    
339
/* start SNMP service */
340
services_snmpd_configure();
341

    
342
/* power down hard drive if needed/set */
343
system_set_harddisk_standby();
344

    
345
/* lock down console if necessary */
346
reload_ttys();
347

    
348
/* load graphing functions */
349
enable_rrd_graphing();
350

    
351
/* enable watchdog if supported */
352
enable_watchdog();
353

    
354
/* if <system><afterbootupshellcmd> exists, execute the command */
355
if ($config['system']['afterbootupshellcmd'] <> "") {
356
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
357
	mwexec($config['system']['afterbootupshellcmd']);
358
}
359

    
360
if ($physmem < $g['minimum_ram_warning']) {
361
	require_once("/etc/inc/notices.inc");
362
	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);
363
	set_sysctl(array(
364
		"net.inet.tcp.recvspace" => "4096",
365
		"net.inet.tcp.sendspace" => "4096"
366
	));
367
}
368

    
369
if (file_exists("/conf/ram_disks_failed")) {
370
	require_once("/etc/inc/notices.inc");
371
	file_notice("RAM Disks", "RAM disk creation failed. Reverted to traditional storage. Check RAM disk sizes.", "RAM Disks");
372
}
373

    
374
/* if we are operating at 1000 then increase timeouts.
375
   this was never accounted for after moving to 1000 hz */
376
$kern_hz = get_single_sysctl('kern.clockrate');
377
$kern_hz = substr($kern_hz, strpos($kern_hz, "hz = ") + 5);
378
$kern_hz = substr($kern_hz, 0, strpos($kern_hz, ","));
379
if ($kern_hz == "1000") {
380
	set_single_sysctl("net.inet.tcp.rexmit_min" , "30");
381
}
382

    
383
/* start the igmpproxy daemon */
384
services_igmpproxy_configure();
385

    
386
/* start the upnp daemon if it is enabled */
387
upnp_start();
388

    
389
/* If powerd is enabled, lets launch it */
390
activate_powerd();
391

    
392
/* Set preferred protocol */
393
prefer_ipv4_or_ipv6();
394

    
395
/* Resync / Reinstall packages if need be */
396
if (file_exists("{$g['conf_path']}/needs_package_sync")) {
397
	echo "Triggering packages reinstallation in background\n";
398
	mwexec_bg("{$g['etc_path']}/rc.package_reinstall_all");
399
} else {
400
	/* Detect installed binary pkgs that are not registered in the system */
401
	register_all_installed_packages();
402
}
403

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

    
408
/* done */
409
unset($g['booting']);
410
@unlink("{$g['varrun_path']}/booting");
411

    
412
/* If there are ipsec dynamic hosts try again to reload the tunnels as rc.newipsecdns does */
413
if ($ipsec_dynamic_hosts) {
414
	ipsec_configure();
415
}
416
if ($ipsec_dynamic_hosts || !empty($filterdns)) {
417
	filter_configure();
418
}
419

    
420
led_normalize();
421

    
422
notify_all_remote("Bootup complete");
423
?>
(21-21/82)