Project

General

Profile

Download (10.7 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
 * Copyright (c) 2014-2019 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 5f2d078e Scott Ullrich
require_once("/etc/inc/openvpn.inc");
64 62d93213 Scott Ullrich
echo ".";
65 483e6de8 Scott Ullrich
require_once("/etc/inc/captiveportal.inc");
66
echo ".";
67
require_once("/etc/inc/rrd.inc");
68
echo ".";
69 3ffa8318 Renato Botelho
require_once("/etc/inc/pfsense-utils.inc");
70
echo ".";
71 62d93213 Scott Ullrich
72 6cc9e241 Scott Ullrich
/* get system memory amount */
73
$memory = get_memory();
74 5517f604 Phil Davis
$physmem = $memory[0];
75
$realmem = $memory[1];
76 6cc9e241 Scott Ullrich
echo " done.\n";
77
78
79 7f039071 jim-p
/* save dmesg output to file */
80
system_dmesg_save();
81
82 7188fc6d Scott Ullrich
/* check whether config reset is desired (via hardware button on WRAP/ALIX) */
83
system_check_reset_button();
84
85 6cc9e241 Scott Ullrich
/* remove previous firmware upgrade if present */
86 e173dd74 Phil Davis
if (file_exists("/root/firmware.tgz")) {
87 6cc9e241 Scott Ullrich
	unlink("/root/firmware.tgz");
88 e173dd74 Phil Davis
}
89 6cc9e241 Scott Ullrich
90 7d7da5e5 Phil Davis
/* Triggering of the initial setup wizard after reboot has been requested */
91 58a2ba62 jim-p
if (file_exists("{$g['conf_path']}/trigger_initial_wizard_after_reboot")) {
92
	touch("{$g['conf_path']}/trigger_initial_wizard");
93
	@unlink("{$g['conf_path']}/trigger_initial_wizard_after_reboot");
94 7d7da5e5 Phil Davis
}
95
96 de00c381 Phil Davis
/* start devd (dhclient now uses it) */
97 6cc9e241 Scott Ullrich
echo "Starting device manager (devd)...";
98
mute_kernel_msgs();
99
start_devd();
100
set_device_perms();
101
unmute_kernel_msgs();
102
echo "done.\n";
103
104 d5116ed5 Scott Ullrich
echo "Loading configuration...";
105
parse_config_bootup();
106
echo "done.\n";
107
108 8ce97259 Renato Botelho
mwexec("/usr/sbin/gnid > {$g['vardb_path']}/uniqueid 2>/dev/null");
109 6ca93df3 Renato Botelho
110 59e04186 nagyrobi
/* run any early shell commands specified in config.xml */
111
system_do_shell_commands(1);
112
113 75a1149e Phil Davis
// Only do the alternate interface checks if:
114
// 1) The user has not yet run the initial wizard; and
115
// 2) The user has not used the console menu to setup interface assignments
116 20f8233d Luiz Souza
if (file_exists("{$g['conf_path']}/trigger_initial_wizard") && !file_exists("{$g['conf_path']}/assign_complete")) {
117 b49e6c01 Phil Davis
	check_for_alternate_interfaces();
118
}
119
120 79ccd1f2 jim-p
/* Convert configuration
121
 * This must happen before the interface mismatch test, see
122
 * https://redmine.pfsense.org/issues/7809 */
123
echo "Updating configuration...";
124
convert_config();
125
echo "done.\n";
126
127 6fa9f38c Renato Botelho
/*
128
 *	Determine if we need to throw a interface exception
129
 *	and ask the user to reassign interfaces.  This will
130
 *	avoid a reboot and that is a good thing.
131
 */
132
while (is_interface_mismatch() == true) {
133
	led_assigninterfaces();
134
	if (isset($config['revision'])) {
135
		if (file_exists("{$g['tmp_path']}/missing_interfaces")) {
136
			echo "Warning: Configuration references interfaces that do not exist: " . file_get_contents("{$g['tmp_path']}/missing_interfaces") . "\n";
137 7734aea6 Andrew Thompson
		}
138 6fa9f38c Renato Botelho
		echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
139
	} else {
140
		echo "\nDefault interfaces not found -- Running interface assignment option.\n";
141 7734aea6 Andrew Thompson
	}
142 6fa9f38c Renato Botelho
	$ifaces = get_interface_list();
143
	if (is_array($ifaces)) {
144
		foreach ($ifaces as $iface => $ifdata) {
145
			interfaces_bring_up($iface);
146 7734aea6 Andrew Thompson
		}
147 7f8d463f Ermal
	}
148 87d2f8cd Luiz Souza
	if (set_networking_interfaces_ports() == -1) {
149
		echo "\npfSense cannot continue without at least one Network Interface Card.\n";
150
		echo "\nHalting the system.\n";
151
		system("/sbin/shutdown -h now");
152
		exit(0);
153
	}
154 3614c7da Luiz Souza
	reload_interfaces_sync();
155 6fa9f38c Renato Botelho
	led_kitt();
156 6cc9e241 Scott Ullrich
}
157
158 c2530487 PiBa-NL
echo "Checking config backups consistency...";
159 6cc9e241 Scott Ullrich
cleanup_backupcache(true);
160
echo "done.\n";
161
162
/* read in /etc/sysctl.conf and set values if needed */
163
echo "Setting up extended sysctls...";
164
system_setup_sysctl();
165
echo "done.\n";
166
167 7530177c jim-p
/* enable optional crypto modules */
168
load_crypto();
169 09f18f59 jim-p
170 f60156f6 jim-p
/* enable optional thermal sensor modules */
171
load_thermal_hardware();
172
173 6cc9e241 Scott Ullrich
/* set up our timezone */
174
system_timezone_configure();
175
176
/* set up our hostname */
177
system_hostname_configure();
178
179
/* make hosts file */
180
system_hosts_generate();
181
182
/* configure loopback interface */
183
interfaces_loopback_configure();
184
185 2b6f7508 smos
/* start syslogd */
186
system_syslogd_start();
187
188 029d6129 NOYB
/* Log the RAM disk restore messages. */
189
if (file_exists("/var/log/restore_ramdisk_store.boot")) {
190
	exec("logger -f /var/log/restore_ramdisk_store.boot");
191
}
192 03afdafa NOYB
193 b29d9c8e Ermal
echo "Starting Secure Shell Services...";
194 08b64f79 Ermal
send_event("service reload sshd");
195 b29d9c8e Ermal
echo "done.\n";
196
197 9a4c3eed Ermal
/* setup interface microcode which improves tcp/ip speed */
198 7d6128e0 Ermal
echo "Setting up interfaces microcode...";
199 9a4c3eed Ermal
setup_microcode();
200
echo "done.\n";
201
202 42c48efe jim-p
if (isset($config['system']['mds_disable']) &&
203
    (strlen($config['system']['mds_disable']) > 0)) {
204
	set_single_sysctl("hw.mds_disable" , (int)$config['system']['mds_disable']);
205
}
206
207 19f3d39a JTL
/* remove leftover dhcp6c lock files if they exist */
208
foreach ($config['interfaces'] as $interface) {
209
        if ($interface['ipaddrv6'] == "dhcp6") {
210
            if (file_exists("/tmp/dhcp6c_" . $interface['if'] . "_lock")) {
211
                @unlink("/tmp/dhcp6c_" . $interface['if'] . "_lock");
212
                echo("Removed leftover dhcp6c lock file: " . "/tmp/dhcp6c_" . $interface['if'] . "_lock\n");
213
            }
214
         }
215
     }
216
217 6cc9e241 Scott Ullrich
/* set up interfaces */
218 e173dd74 Phil Davis
if (!$debugging) {
219 70b89814 Scott Ullrich
	mute_kernel_msgs();
220 e173dd74 Phil Davis
}
221 6cc9e241 Scott Ullrich
interfaces_configure();
222 8ff85c39 Ermal
interfaces_sync_setup();
223 e173dd74 Phil Davis
if (!$debugging) {
224 70b89814 Scott Ullrich
	unmute_kernel_msgs();
225 e173dd74 Phil Davis
}
226 86ddbb71 Scott Ullrich
227 4994b350 smos
/* re-make hosts file after configuring interfaces */
228
system_hosts_generate();
229
230 d09d53ac Ermal
/* start OpenVPN server & clients */
231
echo "Syncing OpenVPN settings...";
232
openvpn_resync_all();
233
echo "done.\n";
234
235 6cc9e241 Scott Ullrich
/* generate resolv.conf */
236
system_resolvconf_generate();
237 aa01f2f2 Scott Ullrich
238 2fd9d050 Scott Ullrich
/* setup altq + pf */
239
filter_configure_sync();
240
241 6cc9e241 Scott Ullrich
/* start pflog */
242
echo "Starting PFLOG...";
243
filter_pflog_start();
244
echo "done.\n";
245 d0e94aaf Scott Ullrich
246 17fdcb8d Ermal Lu?i
/* reconfigure our gateway monitor */
247 6cc9e241 Scott Ullrich
echo "Setting up gateway monitors...";
248 17fdcb8d Ermal Lu?i
setup_gateways_monitor();
249
echo "done.\n";
250
251 4c6135c2 Renato Botelho
/* set up static routes */
252 1da0c794 PiBa-NL
echo "Setting up static routes...";
253 4c6135c2 Renato Botelho
system_routing_configure();
254 1da0c794 PiBa-NL
echo "done.\n";
255 4c6135c2 Renato Botelho
256 26dc7555 Renato Botelho
echo "Setting up DNSs...\n";
257 4c6135c2 Renato Botelho
/* start dnsmasq service */
258
services_dnsmasq_configure();
259
260
/* start unbound service */
261
services_unbound_configure();
262
263 17fdcb8d Ermal Lu?i
echo "Synchronizing user settings...";
264 79f7bc7f Renato Botelho
local_reset_accounts();
265 6cc9e241 Scott Ullrich
echo "done.\n";
266 d0e94aaf Scott Ullrich
267 e173dd74 Phil Davis
if ($realmem > 0 and $realmem < 65) {
268 5517f604 Phil Davis
	echo "System has less than 65 megabytes of ram {$realmem}.  Delaying webConfigurator startup.\n";
269 6cc9e241 Scott Ullrich
	/* start webConfigurator up on final pass */
270 f3239b2d Chris Buechler
	mwexec("/usr/local/sbin/pfSctl -c 'service restart webgui'");
271 6cc9e241 Scott Ullrich
} else {
272
	/* start web server */
273
	system_webgui_start();
274
}
275 ef9366bd Scott Ullrich
276 6cc9e241 Scott Ullrich
/* configure cron service */
277
echo "Configuring CRON...";
278
configure_cron();
279
echo "done.\n";
280 68cd47b3 Scott Ullrich
281 6cc9e241 Scott Ullrich
/* enable routing */
282
system_routing_enable();
283 e5cd29a0 Scott Ullrich
284 2dced82f Renato Botelho
/* Enable ntpd */
285 0b8e9d38 jim-p
echo "Starting NTP time client...";
286 2dced82f Renato Botelho
system_ntp_configure();
287 de00c381 Phil Davis
echo "done.\n";
288 0b8e9d38 jim-p
289 749dfdb7 Luiz Souza
/* Configure console (and serial port - if necessary). */
290
console_configure();
291 a005424e Scott Ullrich
292 24d619f5 Ermal
/* start DHCP service */
293
services_dhcpd_configure();
294
295 e173dd74 Phil Davis
/* start dhcpleases dhcp hosts leases program */
296 92150bd8 Ermal
system_dhcpleases_configure();
297
298 6cc9e241 Scott Ullrich
/* start DHCP relay */
299
services_dhcrelay_configure();
300 562fca6d Scott Ullrich
301 06433d75 Phil Davis
/* start DHCP6 relay */
302
services_dhcrelay6_configure();
303
304 422bc2a7 Ermal
/* dyndns service updates */
305
send_event("service reload dyndnsall");
306
307 8c41a3e4 Ermal
/* Run a filter configure now that most all services have started */
308
filter_configure_sync();
309
310 6cc9e241 Scott Ullrich
/* setup pppoe and pptp */
311
vpn_setup();
312 c6e604d8 Scott Ullrich
313 6cc9e241 Scott Ullrich
/* start the captive portal */
314
captiveportal_configure();
315 f4959a69 Scott Ullrich
316 336e3c1c Charlie
/* start Voucher support */
317
voucher_configure();
318
319 6cc9e241 Scott Ullrich
/* run any shell commands specified in config.xml */
320
system_do_shell_commands();
321 9f966bc9 Scott Ullrich
322 6cc9e241 Scott Ullrich
/* start IPsec tunnels */
323 e5b89d37 Ermal
$ipsec_dynamic_hosts = vpn_ipsec_configure();
324 a199b93e Scott Ullrich
325 6cc9e241 Scott Ullrich
/* start SNMP service */
326
services_snmpd_configure();
327 11cbd478 Scott Ullrich
328 6cc9e241 Scott Ullrich
/* power down hard drive if needed/set */
329
system_set_harddisk_standby();
330 011bff69 Bill Marquette
331 6cc9e241 Scott Ullrich
/* lock down console if necessary */
332 edb4b657 Renato Botelho
reload_ttys();
333 d0e94aaf Scott Ullrich
334 6cc9e241 Scott Ullrich
/* load graphing functions */
335
enable_rrd_graphing();
336
337
/* enable watchdog if supported */
338
enable_watchdog();
339
340
/* if <system><afterbootupshellcmd> exists, execute the command */
341 e173dd74 Phil Davis
if ($config['system']['afterbootupshellcmd'] <> "") {
342 6cc9e241 Scott Ullrich
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
343
	mwexec($config['system']['afterbootupshellcmd']);
344
}
345
346 e173dd74 Phil Davis
if ($physmem < $g['minimum_ram_warning']) {
347 6cc9e241 Scott Ullrich
	require_once("/etc/inc/notices.inc");
348 9f274393 Chris Buechler
	file_notice("{$g['product_name']}MemoryRequirements", "{$g['product_name']} requires at least {$g['minimum_ram_warning_text']} of RAM.  Expect unusual performance.  This platform is not supported.", "Memory", "", 1);
349 971de1f9 Renato Botelho
	set_sysctl(array(
350
		"net.inet.tcp.recvspace" => "4096",
351
		"net.inet.tcp.sendspace" => "4096"
352
	));
353 6cc9e241 Scott Ullrich
}
354
355
/* if we are operating at 1000 then increase timeouts.
356
   this was never accounted for after moving to 1000 hz */
357 971de1f9 Renato Botelho
$kern_hz = get_single_sysctl('kern.clockrate');
358
$kern_hz = substr($kern_hz, strpos($kern_hz, "hz = ") + 5);
359
$kern_hz = substr($kern_hz, 0, strpos($kern_hz, ","));
360 e173dd74 Phil Davis
if ($kern_hz == "1000") {
361 971de1f9 Renato Botelho
	set_single_sysctl("net.inet.tcp.rexmit_min" , "30");
362 e173dd74 Phil Davis
}
363 c108ec01 Scott Ullrich
364 34c7f02e Scott Ullrich
/* start the igmpproxy daemon */
365 6cc9e241 Scott Ullrich
services_igmpproxy_configure();
366 41997fbb Ermal Luci
367 6cc9e241 Scott Ullrich
/* start the upnp daemon if it is enabled */
368
upnp_start();
369 6f20377b Scott Ullrich
370 6cc9e241 Scott Ullrich
/* If powerd is enabled, lets launch it */
371
activate_powerd();
372 8e9fa41d Scott Ullrich
373 77a341a4 Renato Botelho
/* Set preferred protocol */
374
prefer_ipv4_or_ipv6();
375
376 9b193619 Scott Ullrich
/* Resync / Reinstall packages if need be */
377 58a2ba62 jim-p
if (file_exists("{$g['conf_path']}/needs_package_sync")) {
378 10511c3b Renato Botelho
	echo "Triggering packages reinstallation in background\n";
379
	mwexec_bg("{$g['etc_path']}/rc.package_reinstall_all");
380
} else {
381
	/* Detect installed binary pkgs that are not registered in the system */
382
	register_all_installed_packages();
383 8552be10 Renato Botelho
}
384
385 eac52376 jim-p
/* Give syslogd a kick after everything else has been initialized, otherwise it can occasionally
386
   fail to route syslog messages properly on both IPv4 and IPv6 */
387
system_syslogd_start();
388 25ed9cf8 jim-p
389 6cc9e241 Scott Ullrich
/* done */
390 27556fa9 Scott Ullrich
unset($g['booting']);
391 f658bac7 Ermal LUÇI
@unlink("{$g['varrun_path']}/booting");
392 5c60c947 Scott Ullrich
393 e5b89d37 Ermal
/* If there are ipsec dynamic hosts try again to reload the tunnels as rc.newipsecdns does */
394
if ($ipsec_dynamic_hosts) {
395
	vpn_ipsec_configure();
396 f087d453 Renato Botelho
}
397 bab606ee Chris Buechler
if ($ipsec_dynamic_hosts || !empty($filterdns)) {
398
	filter_configure();
399
}
400 e5b89d37 Ermal
401 00a4146e jim-p
led_normalize();
402 410cdac4 Scott Ullrich
403 1c2ef5f2 PiBa-NL
notify_all_remote("Bootup complete");
404 3a4b0147 Ermal
?>