Project

General

Profile

Download (10.7 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-2018 Rubicon Communications, LLC (Netgate). All rights reserved.
10
 * All rights reserved.
11
 *
12
 * 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
 *
16
 * http://www.apache.org/licenses/LICENSE-2.0
17
 *
18
 * 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
 */
24

    
25
require_once("pkg-utils.inc");
26

    
27
echo " done.\n";
28

    
29
echo "Initializing...";
30
echo ".";
31
require_once("/etc/inc/globals.inc");
32
echo ".";
33
require_once("/etc/inc/led.inc");
34
led_normalize();
35
echo ".";
36
if (led_count() >= 3) {
37
	led_kitt();
38
}
39

    
40
/* let the other functions know we're booting */
41
$pkg_interface = 'console';
42
$g['booting'] = true;
43

    
44
/* parse the configuration and include all functions used below */
45
require_once("/etc/inc/config.inc");
46
echo ".";
47
require_once("/etc/inc/config.console.inc");
48
echo ".";
49
require_once("/etc/inc/auth.inc");
50
echo ".";
51
require_once("/etc/inc/functions.inc");
52
echo ".";
53
require_once("/etc/inc/filter.inc");
54
echo ".";
55
require_once("/etc/inc/shaper.inc");
56
echo ".";
57
require_once("/etc/inc/ipsec.inc");
58
echo ".";
59
require_once("/etc/inc/vpn.inc");
60
echo ".";
61
require_once("/etc/inc/openvpn.inc");
62
echo ".";
63
require_once("/etc/inc/captiveportal.inc");
64
echo ".";
65
require_once("/etc/inc/rrd.inc");
66
echo ".";
67
require_once("/etc/inc/pfsense-utils.inc");
68
echo ".";
69

    
70
/* get system memory amount */
71
$memory = get_memory();
72
$physmem = $memory[0];
73
$realmem = $memory[1];
74
echo " done.\n";
75

    
76

    
77
/* save dmesg output to file */
78
system_dmesg_save();
79

    
80
/* check whether config reset is desired (via hardware button on WRAP/ALIX) */
81
system_check_reset_button();
82

    
83
/* remove previous firmware upgrade if present */
84
if (file_exists("/root/firmware.tgz")) {
85
	unlink("/root/firmware.tgz");
86
}
87

    
88
/* Triggering of the initial setup wizard after reboot has been requested */
89
if (file_exists("{$g['conf_path']}/trigger_initial_wizard_after_reboot")) {
90
	touch("{$g['conf_path']}/trigger_initial_wizard");
91
	@unlink("{$g['conf_path']}/trigger_initial_wizard_after_reboot");
92
}
93

    
94
/* start devd (dhclient now uses it) */
95
echo "Starting device manager (devd)...";
96
mute_kernel_msgs();
97
start_devd();
98
set_device_perms();
99
unmute_kernel_msgs();
100
echo "done.\n";
101

    
102
echo "Loading configuration...";
103
parse_config_bootup();
104
echo "done.\n";
105

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

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

    
111
// Only do the alternate interface checks if:
112
// 1) The user has not yet run the initial wizard; and
113
// 2) The user has not used the console menu to setup interface assignments
114
if (file_exists("{$g['conf_path']}/trigger_initial_wizard") && !file_exists("{$g['conf_path']}/assign_complete")) {
115
	check_for_alternate_interfaces();
116
}
117

    
118
/* Convert configuration
119
 * This must happen before the interface mismatch test, see
120
 * https://redmine.pfsense.org/issues/7809 */
121
echo "Updating configuration...";
122
convert_config();
123
echo "done.\n";
124

    
125
/*
126
 *	Determine if we need to throw a interface exception
127
 *	and ask the user to reassign interfaces.  This will
128
 *	avoid a reboot and that is a good thing.
129
 */
130
while (is_interface_mismatch() == true) {
131
	led_assigninterfaces();
132
	if (isset($config['revision'])) {
133
		if (file_exists("{$g['tmp_path']}/missing_interfaces")) {
134
			echo "Warning: Configuration references interfaces that do not exist: " . file_get_contents("{$g['tmp_path']}/missing_interfaces") . "\n";
135
		}
136
		echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
137
	} else {
138
		echo "\nDefault interfaces not found -- Running interface assignment option.\n";
139
	}
140
	$ifaces = get_interface_list();
141
	if (is_array($ifaces)) {
142
		foreach ($ifaces as $iface => $ifdata) {
143
			interfaces_bring_up($iface);
144
		}
145
	}
146
	if (set_networking_interfaces_ports() == -1) {
147
		echo "\npfSense cannot continue without at least one Network Interface Card.\n";
148
		echo "\nHalting the system.\n";
149
		system("/sbin/shutdown -h now");
150
		exit(0);
151
	}
152
	reload_interfaces_sync();
153
	led_kitt();
154
}
155

    
156
echo "Checking config backups consistency...";
157
cleanup_backupcache(true);
158
echo "done.\n";
159

    
160
/* read in /etc/sysctl.conf and set values if needed */
161
echo "Setting up extended sysctls...";
162
system_setup_sysctl();
163
echo "done.\n";
164

    
165
/* enable optional crypto modules */
166
load_crypto();
167

    
168
/* enable optional thermal sensor modules */
169
load_thermal_hardware();
170

    
171
/* set up our timezone */
172
system_timezone_configure();
173

    
174
/* set up our hostname */
175
system_hostname_configure();
176

    
177
/* make hosts file */
178
system_hosts_generate();
179

    
180
/* configure loopback interface */
181
interfaces_loopback_configure();
182

    
183
/* start syslogd */
184
system_syslogd_start();
185

    
186
/* Log the RAM disk restore messages. */
187
if (file_exists("/var/log/restore_ramdisk_store.boot")) {
188
	exec("logger -f /var/log/restore_ramdisk_store.boot");
189
}
190

    
191
echo "Starting Secure Shell Services...";
192
send_event("service reload sshd");
193
echo "done.\n";
194

    
195
/* setup interface microcode which improves tcp/ip speed */
196
echo "Setting up interfaces microcode...";
197
setup_microcode();
198
echo "done.\n";
199

    
200
if (isset($config['system']['mds_disable']) &&
201
    (strlen($config['system']['mds_disable']) > 0)) {
202
	set_single_sysctl("hw.mds_disable" , (int)$config['system']['mds_disable']);
203
}
204

    
205
/* 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
/* set up interfaces */
216
if (!$debugging) {
217
	mute_kernel_msgs();
218
}
219
interfaces_configure();
220
interfaces_sync_setup();
221
if (!$debugging) {
222
	unmute_kernel_msgs();
223
}
224

    
225
/* re-make hosts file after configuring interfaces */
226
system_hosts_generate();
227

    
228
/* start OpenVPN server & clients */
229
echo "Syncing OpenVPN settings...";
230
openvpn_resync_all();
231
echo "done.\n";
232

    
233
/* generate resolv.conf */
234
system_resolvconf_generate();
235

    
236
/* setup altq + pf */
237
filter_configure_sync();
238

    
239
/* start pflog */
240
echo "Starting PFLOG...";
241
filter_pflog_start();
242
echo "done.\n";
243

    
244
/* reconfigure our gateway monitor */
245
echo "Setting up gateway monitors...";
246
setup_gateways_monitor();
247
echo "done.\n";
248

    
249
/* set up static routes */
250
echo "Setting up static routes...";
251
system_routing_configure();
252
echo "done.\n";
253

    
254
echo "Setting up DNSs...\n";
255
/* start dnsmasq service */
256
services_dnsmasq_configure();
257

    
258
/* start unbound service */
259
services_unbound_configure();
260

    
261
echo "Synchronizing user settings...";
262
local_reset_accounts();
263
echo "done.\n";
264

    
265
if ($realmem > 0 and $realmem < 65) {
266
	echo "System has less than 65 megabytes of ram {$realmem}.  Delaying webConfigurator startup.\n";
267
	/* start webConfigurator up on final pass */
268
	mwexec("/usr/local/sbin/pfSctl -c 'service restart webgui'");
269
} else {
270
	/* start web server */
271
	system_webgui_start();
272
}
273

    
274
/* configure cron service */
275
echo "Configuring CRON...";
276
configure_cron();
277
echo "done.\n";
278

    
279
/* enable routing */
280
system_routing_enable();
281

    
282
/* Enable ntpd */
283
echo "Starting NTP time client...";
284
system_ntp_configure();
285
echo "done.\n";
286

    
287
/* start load balancer daemon */
288
relayd_configure();
289

    
290
/* configure console menu and serial port*/
291
setup_serial_port();
292

    
293
/* start DHCP service */
294
services_dhcpd_configure();
295

    
296
/* start dhcpleases dhcp hosts leases program */
297
system_dhcpleases_configure();
298

    
299
/* start DHCP relay */
300
services_dhcrelay_configure();
301

    
302
/* start DHCP6 relay */
303
services_dhcrelay6_configure();
304

    
305
/* dyndns service updates */
306
send_event("service reload dyndnsall");
307

    
308
/* Run a filter configure now that most all services have started */
309
filter_configure_sync();
310

    
311
/* setup pppoe and pptp */
312
vpn_setup();
313

    
314
/* start the captive portal */
315
captiveportal_configure();
316

    
317
/* start Voucher support */
318
voucher_configure();
319

    
320
/* run any shell commands specified in config.xml */
321
system_do_shell_commands();
322

    
323
/* start IPsec tunnels */
324
$ipsec_dynamic_hosts = vpn_ipsec_configure();
325

    
326
/* start SNMP service */
327
services_snmpd_configure();
328

    
329
/* power down hard drive if needed/set */
330
system_set_harddisk_standby();
331

    
332
/* lock down console if necessary */
333
reload_ttys();
334

    
335
/* load graphing functions */
336
enable_rrd_graphing();
337

    
338
/* enable watchdog if supported */
339
enable_watchdog();
340

    
341
/* if <system><afterbootupshellcmd> exists, execute the command */
342
if ($config['system']['afterbootupshellcmd'] <> "") {
343
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
344
	mwexec($config['system']['afterbootupshellcmd']);
345
}
346

    
347
if ($physmem < $g['minimum_ram_warning']) {
348
	require_once("/etc/inc/notices.inc");
349
	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);
350
	set_sysctl(array(
351
		"net.inet.tcp.recvspace" => "4096",
352
		"net.inet.tcp.sendspace" => "4096"
353
	));
354
}
355

    
356
/* if we are operating at 1000 then increase timeouts.
357
   this was never accounted for after moving to 1000 hz */
358
$kern_hz = get_single_sysctl('kern.clockrate');
359
$kern_hz = substr($kern_hz, strpos($kern_hz, "hz = ") + 5);
360
$kern_hz = substr($kern_hz, 0, strpos($kern_hz, ","));
361
if ($kern_hz == "1000") {
362
	set_single_sysctl("net.inet.tcp.rexmit_min" , "30");
363
}
364

    
365
/* start the igmpproxy daemon */
366
services_igmpproxy_configure();
367

    
368
/* start the upnp daemon if it is enabled */
369
upnp_start();
370

    
371
/* If powerd is enabled, lets launch it */
372
activate_powerd();
373

    
374
/* Set preferred protocol */
375
prefer_ipv4_or_ipv6();
376

    
377
/* Resync / Reinstall packages if need be */
378
if (file_exists("{$g['conf_path']}/needs_package_sync")) {
379
	echo "Triggering packages reinstallation in background\n";
380
	mwexec_bg("{$g['etc_path']}/rc.package_reinstall_all");
381
} else {
382
	/* Detect installed binary pkgs that are not registered in the system */
383
	register_all_installed_packages();
384
}
385

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

    
390
/* done */
391
unset($g['booting']);
392
@unlink("{$g['varrun_path']}/booting");
393

    
394
/* If there are ipsec dynamic hosts try again to reload the tunnels as rc.newipsecdns does */
395
if ($ipsec_dynamic_hosts) {
396
	vpn_ipsec_configure();
397
}
398
if ($ipsec_dynamic_hosts || !empty($filterdns)) {
399
	filter_configure();
400
}
401

    
402
led_normalize();
403

    
404
notify_all_remote("Bootup complete");
405
?>
(21-21/82)