Project

General

Profile

Download (10.9 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-2019 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
/* 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

    
196
echo "Starting Secure Shell Services...";
197
send_event("service reload sshd");
198
echo "done.\n";
199

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

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

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

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

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

    
235
/* re-make hosts file after configuring interfaces */
236
system_hosts_generate();
237

    
238
/* start OpenVPN server & clients */
239
echo "Syncing OpenVPN settings...";
240
openvpn_resync_all();
241
echo "done.\n";
242

    
243
/* generate resolv.conf */
244
system_resolvconf_generate();
245

    
246
/* setup altq + pf */
247
filter_configure_sync();
248

    
249
/* start pflog */
250
echo "Starting PFLOG...";
251
filter_pflog_start();
252
echo "done.\n";
253

    
254
/* reconfigure our gateway monitor */
255
echo "Setting up gateway monitors...";
256
setup_gateways_monitor();
257
echo "done.\n";
258

    
259
/* set up static routes */
260
echo "Setting up static routes...";
261
system_routing_configure();
262
echo "done.\n";
263

    
264
echo "Setting up DNSs...\n";
265
/* start dnsmasq service */
266
services_dnsmasq_configure();
267

    
268
/* start unbound service */
269
services_unbound_configure();
270

    
271
echo "Synchronizing user settings...";
272
local_reset_accounts();
273
echo "done.\n";
274

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

    
284
/* configure cron service */
285
echo "Configuring CRON...";
286
configure_cron();
287
echo "done.\n";
288

    
289
/* enable routing */
290
system_routing_enable();
291

    
292
/* Enable ntpd */
293
echo "Starting NTP time client...";
294
system_ntp_configure();
295
echo "done.\n";
296

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
372
/* start the igmpproxy daemon */
373
services_igmpproxy_configure();
374

    
375
/* start the upnp daemon if it is enabled */
376
upnp_start();
377

    
378
/* If powerd is enabled, lets launch it */
379
activate_powerd();
380

    
381
/* Set preferred protocol */
382
prefer_ipv4_or_ipv6();
383

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

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

    
397
/* done */
398
unset($g['booting']);
399
@unlink("{$g['varrun_path']}/booting");
400

    
401
/* If there are ipsec dynamic hosts try again to reload the tunnels as rc.newipsecdns does */
402
if ($ipsec_dynamic_hosts) {
403
	ipsec_configure();
404
}
405
if ($ipsec_dynamic_hosts || !empty($filterdns)) {
406
	filter_configure();
407
}
408

    
409
led_normalize();
410

    
411
notify_all_remote("Bootup complete");
412
?>
(21-21/81)