Project

General

Profile

Download (11.1 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-2020 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
/* Triggering of the initial setup wizard after reboot has been requested */
91
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
}
95

    
96
/* start devd (dhclient now uses it) */
97
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
echo "Loading configuration...";
105
parse_config_bootup();
106
echo "done.\n";
107

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

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

    
113
// 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
if (file_exists("{$g['conf_path']}/trigger_initial_wizard") && !file_exists("{$g['conf_path']}/assign_complete")) {
117
	check_for_alternate_interfaces();
118
}
119

    
120
/* 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
/*
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
		}
138
		echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
139
	} else {
140
		echo "\nDefault interfaces not found -- Running interface assignment option.\n";
141
	}
142
	$ifaces = get_interface_list();
143
	if (is_array($ifaces)) {
144
		foreach ($ifaces as $iface => $ifdata) {
145
			interfaces_bring_up($iface);
146
		}
147
	}
148
	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
	reload_interfaces_sync();
155
	led_kitt();
156
}
157

    
158
echo "Checking config backups consistency...";
159
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
/* enable optional crypto modules */
168
load_crypto();
169

    
170
/* enable optional thermal sensor modules */
171
load_thermal_hardware();
172

    
173
/* 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
/* Setup Local CA Trust Store */
186
ca_setup_trust_store();
187

    
188
/* start syslogd */
189
system_syslogd_start();
190

    
191
/* set pam shell authentication backend */
192
set_pam_auth();
193

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

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

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

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

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

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

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

    
238
/* re-make hosts file after configuring interfaces */
239
system_hosts_generate();
240

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

    
246
/* generate resolv.conf */
247
system_resolvconf_generate();
248

    
249
/* setup altq + pf */
250
filter_configure_sync();
251

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

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

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

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

    
271
/* start unbound service */
272
services_unbound_configure();
273

    
274
echo "Synchronizing user settings...";
275
local_reset_accounts();
276
echo "done.\n";
277

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

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

    
292
/* enable routing */
293
system_routing_enable();
294

    
295
/* Enable ntpd */
296
system_ntp_configure();
297

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

    
301
/* start DHCP service */
302
services_dhcpd_configure();
303

    
304
/* start dhcpleases dhcp hosts leases program */
305
system_dhcpleases_configure();
306

    
307
/* start DHCP relay */
308
services_dhcrelay_configure();
309

    
310
/* start DHCP6 relay */
311
services_dhcrelay6_configure();
312

    
313
/* dyndns service updates */
314
send_event("service reload dyndnsall");
315

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

    
319
/* setup pppoe and pptp */
320
vpn_setup();
321

    
322
/* start the captive portal */
323
captiveportal_configure();
324

    
325
/* start Voucher support */
326
voucher_configure();
327

    
328
/* run any shell commands specified in config.xml */
329
system_do_shell_commands();
330

    
331
/* start IPsec tunnels */
332
$ipsec_dynamic_hosts = ipsec_configure();
333

    
334
/* start SNMP service */
335
services_snmpd_configure();
336

    
337
/* power down hard drive if needed/set */
338
system_set_harddisk_standby();
339

    
340
/* lock down console if necessary */
341
reload_ttys();
342

    
343
/* load graphing functions */
344
enable_rrd_graphing();
345

    
346
/* enable watchdog if supported */
347
enable_watchdog();
348

    
349
/* if <system><afterbootupshellcmd> exists, execute the command */
350
if ($config['system']['afterbootupshellcmd'] <> "") {
351
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
352
	mwexec($config['system']['afterbootupshellcmd']);
353
}
354

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

    
364
if (file_exists("/conf/ram_disks_failed")) {
365
	require_once("/etc/inc/notices.inc");
366
	file_notice("RAM Disks", "RAM disk creation failed. Reverted to traditional storage. Check RAM disk sizes.", "RAM Disks");
367
}
368

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

    
378
/* start the igmpproxy daemon */
379
services_igmpproxy_configure();
380

    
381
/* start the upnp daemon if it is enabled */
382
upnp_start();
383

    
384
/* If powerd is enabled, lets launch it */
385
activate_powerd();
386

    
387
/* Set preferred protocol */
388
prefer_ipv4_or_ipv6();
389

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

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

    
403
/* done */
404
unset($g['booting']);
405
@unlink("{$g['varrun_path']}/booting");
406

    
407
/* If there are ipsec dynamic hosts try again to reload the tunnels as rc.newipsecdns does */
408
if ($ipsec_dynamic_hosts) {
409
	ipsec_configure();
410
}
411
if ($ipsec_dynamic_hosts || !empty($filterdns)) {
412
	filter_configure();
413
}
414

    
415
led_normalize();
416

    
417
notify_all_remote("Bootup complete");
418
?>
(21-21/82)