Project

General

Profile

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