Project

General

Profile

Download (11.2 KB) Statistics
| Branch: | Tag: | Revision:
1 cb7d18d5 Renato Botelho
#!/usr/local/bin/php-cgi -f
2 5b237745 Scott Ullrich
<?php
3
/*
4 ac24dc24 Renato Botelho
 * rc.bootup
5
 *
6
 * originally based on m0n0wall (http://m0n0.ch/wall)
7 c5d81585 Renato Botelho
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
 * Copyright (c) 2009 Erik Kristensen
9 38809d47 Renato Botelho do Couto
 * Copyright (c) 2005-2013 BSD Perimeter
10
 * Copyright (c) 2013-2016 Electric Sheep Fencing
11 8f585441 Luiz Souza
 * Copyright (c) 2014-2021 Rubicon Communications, LLC (Netgate)
12 ac24dc24 Renato Botelho
 * All rights reserved.
13
 *
14 b12ea3fb Renato Botelho
 * 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 ac24dc24 Renato Botelho
 *
18 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
19 ac24dc24 Renato Botelho
 *
20 b12ea3fb Renato Botelho
 * 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 ac24dc24 Renato Botelho
 */
26 5b237745 Scott Ullrich
27 bed6c19b Renato Botelho
require_once("pkg-utils.inc");
28
29 6cc9e241 Scott Ullrich
echo " done.\n";
30
31
echo "Initializing...";
32
echo ".";
33
require_once("/etc/inc/globals.inc");
34 483e6de8 Scott Ullrich
echo ".";
35 00a4146e jim-p
require_once("/etc/inc/led.inc");
36
led_normalize();
37 483e6de8 Scott Ullrich
echo ".";
38 00a4146e jim-p
if (led_count() >= 3) {
39
	led_kitt();
40
}
41 483e6de8 Scott Ullrich
42 6cc9e241 Scott Ullrich
/* let the other functions know we're booting */
43
$pkg_interface = 'console';
44 410cdac4 Scott Ullrich
$g['booting'] = true;
45 6cc9e241 Scott Ullrich
46
/* parse the configuration and include all functions used below */
47
require_once("/etc/inc/config.inc");
48
echo ".";
49 032c40c7 Scott Ullrich
require_once("/etc/inc/config.console.inc");
50
echo ".";
51 3066a36f Ermal Lu?i
require_once("/etc/inc/auth.inc");
52
echo ".";
53 6cc9e241 Scott Ullrich
require_once("/etc/inc/functions.inc");
54 62d93213 Scott Ullrich
echo ".";
55 1b1c179d jim-p
require_once("/etc/inc/filter.inc");
56 5f2d078e Scott Ullrich
echo ".";
57 1b1c179d jim-p
require_once("/etc/inc/shaper.inc");
58 5f2d078e Scott Ullrich
echo ".";
59 483e6de8 Scott Ullrich
require_once("/etc/inc/ipsec.inc");
60
echo ".";
61
require_once("/etc/inc/vpn.inc");
62
echo ".";
63 4103ddd6 Luiz Souza
require_once("/etc/inc/web/wg.inc");
64
echo ".";
65 5f2d078e Scott Ullrich
require_once("/etc/inc/openvpn.inc");
66 62d93213 Scott Ullrich
echo ".";
67 483e6de8 Scott Ullrich
require_once("/etc/inc/captiveportal.inc");
68
echo ".";
69
require_once("/etc/inc/rrd.inc");
70
echo ".";
71 3ffa8318 Renato Botelho
require_once("/etc/inc/pfsense-utils.inc");
72
echo ".";
73 62d93213 Scott Ullrich
74 6cc9e241 Scott Ullrich
/* get system memory amount */
75
$memory = get_memory();
76 5517f604 Phil Davis
$physmem = $memory[0];
77
$realmem = $memory[1];
78 6cc9e241 Scott Ullrich
echo " done.\n";
79
80
81 7f039071 jim-p
/* save dmesg output to file */
82
system_dmesg_save();
83
84 7188fc6d Scott Ullrich
/* check whether config reset is desired (via hardware button on WRAP/ALIX) */
85
system_check_reset_button();
86
87 6cc9e241 Scott Ullrich
/* remove previous firmware upgrade if present */
88 e173dd74 Phil Davis
if (file_exists("/root/firmware.tgz")) {
89 6cc9e241 Scott Ullrich
	unlink("/root/firmware.tgz");
90 e173dd74 Phil Davis
}
91 6cc9e241 Scott Ullrich
92 7d7da5e5 Phil Davis
/* Triggering of the initial setup wizard after reboot has been requested */
93 58a2ba62 jim-p
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 7d7da5e5 Phil Davis
}
97
98 de00c381 Phil Davis
/* start devd (dhclient now uses it) */
99 6cc9e241 Scott Ullrich
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 d5116ed5 Scott Ullrich
echo "Loading configuration...";
107
parse_config_bootup();
108
echo "done.\n";
109
110 8ce97259 Renato Botelho
mwexec("/usr/sbin/gnid > {$g['vardb_path']}/uniqueid 2>/dev/null");
111 6ca93df3 Renato Botelho
112 59e04186 nagyrobi
/* run any early shell commands specified in config.xml */
113
system_do_shell_commands(1);
114
115 75a1149e Phil Davis
// 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 20f8233d Luiz Souza
if (file_exists("{$g['conf_path']}/trigger_initial_wizard") && !file_exists("{$g['conf_path']}/assign_complete")) {
119 b49e6c01 Phil Davis
	check_for_alternate_interfaces();
120
}
121
122 79ccd1f2 jim-p
/* 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 6fa9f38c Renato Botelho
/*
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 7734aea6 Andrew Thompson
		}
140 6fa9f38c Renato Botelho
		echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
141
	} else {
142
		echo "\nDefault interfaces not found -- Running interface assignment option.\n";
143 7734aea6 Andrew Thompson
	}
144 6fa9f38c Renato Botelho
	$ifaces = get_interface_list();
145
	if (is_array($ifaces)) {
146
		foreach ($ifaces as $iface => $ifdata) {
147
			interfaces_bring_up($iface);
148 7734aea6 Andrew Thompson
		}
149 7f8d463f Ermal
	}
150 87d2f8cd Luiz Souza
	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 3614c7da Luiz Souza
	reload_interfaces_sync();
157 6fa9f38c Renato Botelho
	led_kitt();
158 6cc9e241 Scott Ullrich
}
159
160 c2530487 PiBa-NL
echo "Checking config backups consistency...";
161 6cc9e241 Scott Ullrich
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 7530177c jim-p
/* enable optional crypto modules */
170
load_crypto();
171 09f18f59 jim-p
172 f60156f6 jim-p
/* enable optional thermal sensor modules */
173
load_thermal_hardware();
174
175 6cc9e241 Scott Ullrich
/* 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 7daab3d8 jim-p
/* Setup Local CA Trust Store */
188
ca_setup_trust_store();
189
190 2b6f7508 smos
/* start syslogd */
191
system_syslogd_start();
192
193 4594c689 Viktor G
/* set pam shell authentication backend */
194
set_pam_auth();
195
196 029d6129 NOYB
/* 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 03afdafa NOYB
201 b29d9c8e Ermal
echo "Starting Secure Shell Services...";
202 08b64f79 Ermal
send_event("service reload sshd");
203 b29d9c8e Ermal
echo "done.\n";
204
205 9a4c3eed Ermal
/* setup interface microcode which improves tcp/ip speed */
206 7d6128e0 Ermal
echo "Setting up interfaces microcode...";
207 9a4c3eed Ermal
setup_microcode();
208
echo "done.\n";
209
210 3edfe694 Viktor Gurov
/* pcscd daemon must be started before IPsec */
211 403add46 Viktor Gurov
echo "Starting PC/SC Smart Card Services...";
212 3edfe694 Viktor Gurov
mwexec_bg("/usr/local/sbin/pcscd");
213
echo "done.\n";
214
215 42c48efe jim-p
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 19f3d39a JTL
/* 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 6cc9e241 Scott Ullrich
/* set up interfaces */
231 e173dd74 Phil Davis
if (!$debugging) {
232 70b89814 Scott Ullrich
	mute_kernel_msgs();
233 e173dd74 Phil Davis
}
234 6cc9e241 Scott Ullrich
interfaces_configure();
235 8ff85c39 Ermal
interfaces_sync_setup();
236 e173dd74 Phil Davis
if (!$debugging) {
237 70b89814 Scott Ullrich
	unmute_kernel_msgs();
238 e173dd74 Phil Davis
}
239 86ddbb71 Scott Ullrich
240 4994b350 smos
/* re-make hosts file after configuring interfaces */
241
system_hosts_generate();
242
243 d09d53ac Ermal
/* start OpenVPN server & clients */
244
echo "Syncing OpenVPN settings...";
245
openvpn_resync_all();
246
echo "done.\n";
247
248 6cc9e241 Scott Ullrich
/* generate resolv.conf */
249
system_resolvconf_generate();
250 aa01f2f2 Scott Ullrich
251 2fd9d050 Scott Ullrich
/* setup altq + pf */
252
filter_configure_sync();
253
254 6cc9e241 Scott Ullrich
/* start pflog */
255
echo "Starting PFLOG...";
256
filter_pflog_start();
257
echo "done.\n";
258 d0e94aaf Scott Ullrich
259 17fdcb8d Ermal Lu?i
/* reconfigure our gateway monitor */
260 6cc9e241 Scott Ullrich
echo "Setting up gateway monitors...";
261 17fdcb8d Ermal Lu?i
setup_gateways_monitor();
262
echo "done.\n";
263
264 4c6135c2 Renato Botelho
/* set up static routes */
265 1da0c794 PiBa-NL
echo "Setting up static routes...";
266 4c6135c2 Renato Botelho
system_routing_configure();
267 1da0c794 PiBa-NL
echo "done.\n";
268 4c6135c2 Renato Botelho
269 26dc7555 Renato Botelho
echo "Setting up DNSs...\n";
270 4c6135c2 Renato Botelho
/* start dnsmasq service */
271
services_dnsmasq_configure();
272
273
/* start unbound service */
274
services_unbound_configure();
275
276 17fdcb8d Ermal Lu?i
echo "Synchronizing user settings...";
277 79f7bc7f Renato Botelho
local_reset_accounts();
278 6cc9e241 Scott Ullrich
echo "done.\n";
279 d0e94aaf Scott Ullrich
280 e173dd74 Phil Davis
if ($realmem > 0 and $realmem < 65) {
281 5517f604 Phil Davis
	echo "System has less than 65 megabytes of ram {$realmem}.  Delaying webConfigurator startup.\n";
282 6cc9e241 Scott Ullrich
	/* start webConfigurator up on final pass */
283 f3239b2d Chris Buechler
	mwexec("/usr/local/sbin/pfSctl -c 'service restart webgui'");
284 6cc9e241 Scott Ullrich
} else {
285
	/* start web server */
286
	system_webgui_start();
287
}
288 ef9366bd Scott Ullrich
289 6cc9e241 Scott Ullrich
/* configure cron service */
290
echo "Configuring CRON...";
291
configure_cron();
292
echo "done.\n";
293 68cd47b3 Scott Ullrich
294 6cc9e241 Scott Ullrich
/* enable routing */
295
system_routing_enable();
296 e5cd29a0 Scott Ullrich
297 2dced82f Renato Botelho
/* Enable ntpd */
298
system_ntp_configure();
299 0b8e9d38 jim-p
300 749dfdb7 Luiz Souza
/* Configure console (and serial port - if necessary). */
301
console_configure();
302 a005424e Scott Ullrich
303 24d619f5 Ermal
/* start DHCP service */
304
services_dhcpd_configure();
305
306 e173dd74 Phil Davis
/* start dhcpleases dhcp hosts leases program */
307 92150bd8 Ermal
system_dhcpleases_configure();
308
309 6cc9e241 Scott Ullrich
/* start DHCP relay */
310
services_dhcrelay_configure();
311 562fca6d Scott Ullrich
312 06433d75 Phil Davis
/* start DHCP6 relay */
313
services_dhcrelay6_configure();
314
315 422bc2a7 Ermal
/* dyndns service updates */
316
send_event("service reload dyndnsall");
317
318 8c41a3e4 Ermal
/* Run a filter configure now that most all services have started */
319
filter_configure_sync();
320
321 6cc9e241 Scott Ullrich
/* setup pppoe and pptp */
322
vpn_setup();
323 c6e604d8 Scott Ullrich
324 1566a360 Renato Botelho do Couto
/* Setup WireGuard tunnels. */
325 4103ddd6 Luiz Souza
wg_configure();
326
327 6cc9e241 Scott Ullrich
/* start the captive portal */
328
captiveportal_configure();
329 f4959a69 Scott Ullrich
330 336e3c1c Charlie
/* start Voucher support */
331
voucher_configure();
332
333 6cc9e241 Scott Ullrich
/* run any shell commands specified in config.xml */
334
system_do_shell_commands();
335 9f966bc9 Scott Ullrich
336 6cc9e241 Scott Ullrich
/* start IPsec tunnels */
337 c6220dcf jim-p
$ipsec_dynamic_hosts = ipsec_configure();
338 a199b93e Scott Ullrich
339 6cc9e241 Scott Ullrich
/* start SNMP service */
340
services_snmpd_configure();
341 11cbd478 Scott Ullrich
342 6cc9e241 Scott Ullrich
/* power down hard drive if needed/set */
343
system_set_harddisk_standby();
344 011bff69 Bill Marquette
345 6cc9e241 Scott Ullrich
/* lock down console if necessary */
346 edb4b657 Renato Botelho
reload_ttys();
347 d0e94aaf Scott Ullrich
348 6cc9e241 Scott Ullrich
/* 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 e173dd74 Phil Davis
if ($config['system']['afterbootupshellcmd'] <> "") {
356 6cc9e241 Scott Ullrich
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
357
	mwexec($config['system']['afterbootupshellcmd']);
358
}
359
360 e173dd74 Phil Davis
if ($physmem < $g['minimum_ram_warning']) {
361 6cc9e241 Scott Ullrich
	require_once("/etc/inc/notices.inc");
362 573ec19d Renato Botelho do Couto
	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 971de1f9 Renato Botelho
	set_sysctl(array(
364
		"net.inet.tcp.recvspace" => "4096",
365
		"net.inet.tcp.sendspace" => "4096"
366
	));
367 6cc9e241 Scott Ullrich
}
368
369 82bf21fc jim-p
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 6cc9e241 Scott Ullrich
/* if we are operating at 1000 then increase timeouts.
375
   this was never accounted for after moving to 1000 hz */
376 971de1f9 Renato Botelho
$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 e173dd74 Phil Davis
if ($kern_hz == "1000") {
380 971de1f9 Renato Botelho
	set_single_sysctl("net.inet.tcp.rexmit_min" , "30");
381 e173dd74 Phil Davis
}
382 c108ec01 Scott Ullrich
383 34c7f02e Scott Ullrich
/* start the igmpproxy daemon */
384 6cc9e241 Scott Ullrich
services_igmpproxy_configure();
385 41997fbb Ermal Luci
386 6cc9e241 Scott Ullrich
/* start the upnp daemon if it is enabled */
387
upnp_start();
388 6f20377b Scott Ullrich
389 6cc9e241 Scott Ullrich
/* If powerd is enabled, lets launch it */
390
activate_powerd();
391 8e9fa41d Scott Ullrich
392 77a341a4 Renato Botelho
/* Set preferred protocol */
393
prefer_ipv4_or_ipv6();
394
395 9b193619 Scott Ullrich
/* Resync / Reinstall packages if need be */
396 58a2ba62 jim-p
if (file_exists("{$g['conf_path']}/needs_package_sync")) {
397 10511c3b Renato Botelho
	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 8552be10 Renato Botelho
}
403
404 eac52376 jim-p
/* 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 25ed9cf8 jim-p
408 6cc9e241 Scott Ullrich
/* done */
409 27556fa9 Scott Ullrich
unset($g['booting']);
410 f658bac7 Ermal LUÇI
@unlink("{$g['varrun_path']}/booting");
411 5c60c947 Scott Ullrich
412 e5b89d37 Ermal
/* If there are ipsec dynamic hosts try again to reload the tunnels as rc.newipsecdns does */
413
if ($ipsec_dynamic_hosts) {
414 c6220dcf jim-p
	ipsec_configure();
415 f087d453 Renato Botelho
}
416 bab606ee Chris Buechler
if ($ipsec_dynamic_hosts || !empty($filterdns)) {
417
	filter_configure();
418
}
419 e5b89d37 Ermal
420 00a4146e jim-p
led_normalize();
421 410cdac4 Scott Ullrich
422 1c2ef5f2 PiBa-NL
notify_all_remote("Bootup complete");
423 3a4b0147 Ermal
?>