Project

General

Profile

Download (10.5 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
/* remove leftover dhcp6c lock files if they exist */
201
foreach ($config['interfaces'] as $interface) {
202
        if ($interface['ipaddrv6'] == "dhcp6") {
203
            if (file_exists("/tmp/dhcp6c_" . $interface['if'] . "_lock")) {
204
                @unlink("/tmp/dhcp6c_" . $interface['if'] . "_lock");
205
                echo("Removed leftover dhcp6c lock file: " . "/tmp/dhcp6c_" . $interface['if'] . "_lock\n");
206
            }
207
         }
208
     }
209

    
210
/* set up interfaces */
211
if (!$debugging) {
212
	mute_kernel_msgs();
213
}
214
interfaces_configure();
215
interfaces_sync_setup();
216
if (!$debugging) {
217
	unmute_kernel_msgs();
218
}
219

    
220
/* re-make hosts file after configuring interfaces */
221
system_hosts_generate();
222

    
223
/* start OpenVPN server & clients */
224
echo "Syncing OpenVPN settings...";
225
openvpn_resync_all();
226
echo "done.\n";
227

    
228
/* generate resolv.conf */
229
system_resolvconf_generate();
230

    
231
/* setup altq + pf */
232
filter_configure_sync();
233

    
234
/* start pflog */
235
echo "Starting PFLOG...";
236
filter_pflog_start();
237
echo "done.\n";
238

    
239
/* reconfigure our gateway monitor */
240
echo "Setting up gateway monitors...";
241
setup_gateways_monitor();
242
echo "done.\n";
243

    
244
/* set up static routes */
245
echo "Setting up static routes...";
246
system_routing_configure();
247
echo "done.\n";
248

    
249
echo "Setting up DNSs...\n";
250
/* start dnsmasq service */
251
services_dnsmasq_configure();
252

    
253
/* start unbound service */
254
services_unbound_configure();
255

    
256
echo "Synchronizing user settings...";
257
local_reset_accounts();
258
echo "done.\n";
259

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

    
269
/* configure cron service */
270
echo "Configuring CRON...";
271
configure_cron();
272
echo "done.\n";
273

    
274
/* enable routing */
275
system_routing_enable();
276

    
277
/* Enable ntpd */
278
echo "Starting NTP time client...";
279
system_ntp_configure();
280
echo "done.\n";
281

    
282
/* start load balancer daemon */
283
relayd_configure();
284

    
285
/* configure console menu and serial port*/
286
setup_serial_port();
287

    
288
/* start DHCP service */
289
services_dhcpd_configure();
290

    
291
/* start dhcpleases dhcp hosts leases program */
292
system_dhcpleases_configure();
293

    
294
/* start DHCP relay */
295
services_dhcrelay_configure();
296

    
297
/* start DHCP6 relay */
298
services_dhcrelay6_configure();
299

    
300
/* dyndns service updates */
301
send_event("service reload dyndnsall");
302

    
303
/* Run a filter configure now that most all services have started */
304
filter_configure_sync();
305

    
306
/* setup pppoe and pptp */
307
vpn_setup();
308

    
309
/* start the captive portal */
310
captiveportal_configure();
311

    
312
/* start Voucher support */
313
voucher_configure();
314

    
315
/* run any shell commands specified in config.xml */
316
system_do_shell_commands();
317

    
318
/* start IPsec tunnels */
319
$ipsec_dynamic_hosts = vpn_ipsec_configure();
320

    
321
/* start SNMP service */
322
services_snmpd_configure();
323

    
324
/* power down hard drive if needed/set */
325
system_set_harddisk_standby();
326

    
327
/* lock down console if necessary */
328
reload_ttys();
329

    
330
/* load graphing functions */
331
enable_rrd_graphing();
332

    
333
/* enable watchdog if supported */
334
enable_watchdog();
335

    
336
/* if <system><afterbootupshellcmd> exists, execute the command */
337
if ($config['system']['afterbootupshellcmd'] <> "") {
338
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
339
	mwexec($config['system']['afterbootupshellcmd']);
340
}
341

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

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

    
360
/* start the igmpproxy daemon */
361
services_igmpproxy_configure();
362

    
363
/* start the upnp daemon if it is enabled */
364
upnp_start();
365

    
366
/* If powerd is enabled, lets launch it */
367
activate_powerd();
368

    
369
/* Set preferred protocol */
370
prefer_ipv4_or_ipv6();
371

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

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

    
385
/* done */
386
unset($g['booting']);
387
@unlink("{$g['varrun_path']}/booting");
388

    
389
/* If there are ipsec dynamic hosts try again to reload the tunnels as rc.newipsecdns does */
390
if ($ipsec_dynamic_hosts) {
391
	vpn_ipsec_configure();
392
}
393
if ($ipsec_dynamic_hosts || !empty($filterdns)) {
394
	filter_configure();
395
}
396

    
397
led_normalize();
398

    
399
notify_all_remote("Bootup complete");
400
?>
(22-22/83)