Project

General

Profile

Download (12.7 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php -f
2
<?php
3
ini_set('apc.enabled', '0');
4

    
5
/* $Id$ */
6
/*
7
	rc.bootup
8
	part of pfSense by Scott Ullrich
9
	originally based on m0n0wall (http://m0n0.ch/wall)
10
	Copyright (C) 2004-2009 Scott Ullrich <sullrich@pfsense.org>.
11
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
12
	Copyright (C) 2009 Erik Kristensen
13
	All rights reserved.
14

    
15
	Redistribution and use in source and binary forms, with or without
16
	modification, are permitted provided that the following conditions are met:
17

    
18
	1. Redistributions of source code must retain the above copyright notice,
19
	   this list of conditions and the following disclaimer.
20

    
21
	2. Redistributions in binary form must reproduce the above copyright
22
	   notice, this list of conditions and the following disclaimer in the
23
	   documentation and/or other materials provided with the distribution.
24

    
25
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
26
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
29
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
	POSSIBILITY OF SUCH DAMAGE.
35
*/
36

    
37
function rescue_detect_keypress() {
38
	// How long do you want the script to wait before moving on (in seconds)
39
	$timeout=9;
40
	echo "\n";
41
	echo "[ Press R to enter recovery mode or ]\n";
42
	echo "[  press I to launch the installer  ]\n\n";
43
	echo "(R)ecovery mode can assist by rescuing config.xml\n";
44
	echo "from a broken hard disk installation, etc.\n\n";
45
	echo "(I)nstaller may be invoked now if you do \n";
46
	echo "not wish to boot into the liveCD environment at this time.\n\n";
47
	echo "(C) continues the LiveCD bootup without further pause.\n\n";
48
	echo "Timeout before auto boot continues (seconds): {$timeout}";
49
	$key = null;
50
	exec("/bin/stty erase " . chr(8));
51
	while (!in_array($key, array("c", "C", "r","R", "i", "I", "~", "!"))) {
52
		echo chr(8) . "{$timeout}";
53
		`/bin/stty -icanon min 0 time 25`;
54
		$key = trim(`KEY=\`dd count=1 2>/dev/null\`; echo \$KEY`);
55
		`/bin/stty icanon`;
56
		// Decrement our timeout value
57
		$timeout--;
58
		// If we have reached 0 exit and continue on
59
		if ($timeout == 0) {
60
			break;
61
		}
62
	}
63
	// If R or I was pressed do our logic here
64
	if (in_array($key, array("r", "R"))) {
65
		putenv("TERM=cons25");
66
		echo "\n\nRecovery mode selected...\n";
67
		passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer_rescue");
68
	} elseif (in_array($key, array("i", "I"))) {
69
		putenv("TERM=cons25");
70
		echo "\n\nInstaller mode selected...\n";
71
		passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer");
72
		if (file_exists("/tmp/install_complete")) {
73
			passthru("/etc/rc.reboot");
74
			exit;
75
		}
76
	} elseif (in_array($key, array("!", "~"))) {
77
		putenv("TERM=cons25");
78
		echo "\n\nRecovery shell selected...\n";
79
		echo "\n";
80
		touch("/tmp/donotbootup");
81
		exit;
82
	} else {
83
		echo "\n\n";
84
	}
85
}
86

    
87
echo " done.\n";
88

    
89
echo "Initializing...";
90
echo ".";
91
require_once("/etc/inc/globals.inc");
92
echo ".";
93
require_once("/etc/inc/led.inc");
94
led_normalize();
95
echo ".";
96
if (led_count() >= 3) {
97
	led_kitt();
98
}
99

    
100
/* let the other functions know we're booting */
101
$pkg_interface = 'console';
102
$g['booting'] = true;
103

    
104
/* parse the configuration and include all functions used below */
105
require_once("/etc/inc/config.inc");
106
echo ".";
107
require_once("/etc/inc/config.console.inc");
108
echo ".";
109
require_once("/etc/inc/auth.inc");
110
echo ".";
111
require_once("/etc/inc/functions.inc");
112
echo ".";
113
require_once("/etc/inc/filter.inc");
114
echo ".";
115
require_once("/etc/inc/shaper.inc");
116
echo ".";
117
require_once("/etc/inc/ipsec.inc");
118
echo ".";
119
require_once("/etc/inc/vpn.inc");
120
echo ".";
121
require_once("/etc/inc/openvpn.inc");
122
echo ".";
123
require_once("/etc/inc/captiveportal.inc");
124
echo ".";
125
require_once("/etc/inc/rrd.inc");
126
echo ".";
127
require_once("/etc/inc/pfsense-utils.inc");
128
echo ".";
129

    
130
/* get system memory amount */
131
$memory = get_memory();
132
$physmem = $memory[0];
133
$realmem = $memory[1];
134
echo " done.\n";
135

    
136
conf_mount_rw();
137

    
138
/* save dmesg output to file */
139
system_dmesg_save();
140

    
141
/* check whether config reset is desired (via hardware button on WRAP/ALIX) */
142
system_check_reset_button();
143

    
144
/* remove previous firmware upgrade if present */
145
if (file_exists("/root/firmware.tgz")) {
146
	unlink("/root/firmware.tgz");
147
}
148

    
149
/* start devd (dhclient now uses it) */
150
echo "Starting device manager (devd)...";
151
mute_kernel_msgs();
152
start_devd();
153
set_device_perms();
154
unmute_kernel_msgs();
155
echo "done.\n";
156

    
157
// Display rescue configuration option
158
if ($g['platform'] == "cdrom") {
159
	rescue_detect_keypress();
160
}
161

    
162
echo "Loading configuration...";
163
parse_config_bootup();
164
echo "done.\n";
165

    
166
if ($g['platform'] == "jail") {
167
	/* We must determine what network settings have been configured for us */
168
	$wanif = "lo0";	/* defaults, if the jail admin hasn't set us up */
169
	$ipaddr = "127.0.0.1";
170
	$iflist = get_interface_list();
171
	foreach ($iflist as $iface => $ifa) {
172
		if (isset($ifa['ipaddr'])) {
173
			$wanif = $iface;
174
			$ipaddr = $ifa['ipaddr'];
175
			break;
176
		}
177
	}
178
	$config['interfaces'] = array();
179
	$config['interfaces']['lan'] = array();
180
	$config['interfaces']['lan']['enable'] = false;
181
	$config['interfaces']['wan'] = array();
182
	/* XXX, todo */
183
	$config['interfaces']['wan']['if'] = $wanif;
184
	$config['interfaces']['wan']['ipaddr'] = $ipaddr;
185
	$config['interfaces']['wan']['subnet'] = "32";	/* XXX right? */
186
	$config['interfaces']['wan']['enable'] = true;
187
	if ($config['dhcpd']['lan']) {
188
		unset($config['dhcpd']['lan']['enable']);
189
	}
190
	unlink_if_exists('/conf/trigger_initial_wizard');
191
	write_config();
192
} else {
193
	/*
194
	 *	Determine if we need to throw a interface exception
195
	 *	and ask the user to reassign interfaces.  This will
196
	 *	avoid a reboot and that is a good thing.
197
	 */
198
	while (is_interface_mismatch() == true) {
199
		led_assigninterfaces();
200
		if (isset($config['revision'])) {
201
			if (file_exists("{$g['tmp_path']}/missing_interfaces")) {
202
				echo "Warning: Configuration references interfaces that do not exist: " . file_get_contents("{$g['tmp_path']}/missing_interfaces") . "\n";
203
			}
204
			echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
205
		} else {
206
			echo "\nDefault interfaces not found -- Running interface assignment option.\n";
207
		}
208
		$ifaces = get_interface_list();
209
		if (is_array($ifaces)) {
210
			foreach ($ifaces as $iface => $ifdata) {
211
				interfaces_bring_up($iface);
212
			}
213
		}
214
		set_networking_interfaces_ports();
215
		led_kitt();
216
	}
217
}
218

    
219
/* convert config and clean backups */
220
echo "Updating configuration...";
221
convert_config();
222
echo "done.\n";
223

    
224
echo "Cleaning backup cache...";
225
cleanup_backupcache(true);
226
echo "done.\n";
227

    
228
/* read in /etc/sysctl.conf and set values if needed */
229
echo "Setting up extended sysctls...";
230
system_setup_sysctl();
231
echo "done.\n";
232

    
233
/* enable optional crypto modules */
234
load_crypto();
235

    
236
/* enable optional thermal sensor modules */
237
load_thermal_hardware();
238

    
239
/* run any early shell commands specified in config.xml */
240
system_do_shell_commands(1);
241

    
242
/* set up our timezone */
243
system_timezone_configure();
244

    
245
/* set up our hostname */
246
system_hostname_configure();
247

    
248
/* make hosts file */
249
system_hosts_generate();
250

    
251
/* configure loopback interface */
252
interfaces_loopback_configure();
253

    
254
/* start syslogd */
255
system_syslogd_start();
256

    
257
echo "Starting Secure Shell Services...";
258
send_event("service reload sshd");
259
echo "done.\n";
260

    
261
/* setup polling */
262
echo "Setting up polling defaults...";
263
setup_polling();
264
echo "done.\n";
265

    
266
/* setup interface microcode which improves tcp/ip speed */
267
echo "Setting up interfaces microcode...";
268
setup_microcode();
269
echo "done.\n";
270

    
271
/* set up interfaces */
272
if (!$debugging) {
273
	mute_kernel_msgs();
274
}
275
interfaces_configure();
276
interfaces_sync_setup();
277
if (!$debugging) {
278
	unmute_kernel_msgs();
279
}
280

    
281
/* re-make hosts file after configuring interfaces */
282
system_hosts_generate();
283

    
284
/* start OpenVPN server & clients */
285
echo "Syncing OpenVPN settings...";
286
openvpn_resync_all();
287
echo "done.\n";
288

    
289
/* generate resolv.conf */
290
system_resolvconf_generate();
291

    
292
/* setup altq + pf */
293
filter_configure_sync();
294

    
295
/* start pflog */
296
echo "Starting PFLOG...";
297
filter_pflog_start();
298
echo "done.\n";
299

    
300
/* reconfigure our gateway monitor */
301
echo "Setting up gateway monitors...";
302
setup_gateways_monitor();
303
echo "done.\n";
304

    
305
echo "Synchronizing user settings...";
306
local_sync_accounts();
307
echo "done.\n";
308

    
309
if ($realmem > 0 and $realmem < 65) {
310
	echo "System has less than 65 megabytes of ram {$realmem}.  Delaying webConfigurator startup.\n";
311
	/* start webConfigurator up on final pass */
312
	mwexec("/usr/local/sbin/pfSctl -c 'service restart webgui'");
313
} else {
314
	/* start web server */
315
	system_webgui_start();
316
}
317

    
318
/* configure cron service */
319
echo "Configuring CRON...";
320
configure_cron();
321
echo "done.\n";
322

    
323
/* set up static routes */
324
system_routing_configure();
325

    
326
/* enable routing */
327
system_routing_enable();
328

    
329
/* start dnsmasq service */
330
services_dnsmasq_configure();
331

    
332
/* start unbound service */
333
services_unbound_configure();
334

    
335
/* Do an initial time sync */
336
echo "Starting NTP time client...";
337
/* At bootup this will just write the config, ntpd will launch from ntpdate_sync_once.sh */
338
system_ntp_configure(false);
339
mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh", true);
340
echo "done.\n";
341

    
342
/* start load balancer daemon */
343
relayd_configure();
344

    
345
/* configure console menu */
346
system_console_configure();
347

    
348
/* start DHCP service */
349
services_dhcpd_configure();
350

    
351
/* start dhcpleases dhcp hosts leases program */
352
system_dhcpleases_configure();
353

    
354
/* start DHCP relay */
355
services_dhcrelay_configure();
356

    
357
/* start DHCP6 relay */
358
services_dhcrelay6_configure();
359

    
360
/* dyndns service updates */
361
send_event("service reload dyndnsall");
362

    
363
/* Run a filter configure now that most all services have started */
364
filter_configure_sync();
365

    
366
/* setup pppoe and pptp */
367
vpn_setup();
368

    
369
/* start the captive portal */
370
captiveportal_configure();
371

    
372
/* start Voucher support */
373
voucher_configure();
374

    
375
/* run any shell commands specified in config.xml */
376
system_do_shell_commands();
377

    
378
/* start IPsec tunnels */
379
$ipsec_dynamic_hosts = vpn_ipsec_configure();
380

    
381
/* start SNMP service */
382
services_snmpd_configure();
383

    
384
/* power down hard drive if needed/set */
385
system_set_harddisk_standby();
386

    
387
/* lock down console if necessary */
388
reload_ttys();
389

    
390
/* load graphing functions */
391
enable_rrd_graphing();
392

    
393
/* enable watchdog if supported */
394
enable_watchdog();
395

    
396
/* if <system><afterbootupshellcmd> exists, execute the command */
397
if ($config['system']['afterbootupshellcmd'] <> "") {
398
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
399
	mwexec($config['system']['afterbootupshellcmd']);
400
}
401

    
402
if ($physmem < $g['minimum_ram_warning']) {
403
	require_once("/etc/inc/notices.inc");
404
	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);
405
	set_sysctl(array(
406
		"net.inet.tcp.recvspace" => "4096",
407
		"net.inet.tcp.sendspace" => "4096"
408
	));
409
}
410

    
411
/* if we are operating at 1000 then increase timeouts.
412
   this was never accounted for after moving to 1000 hz */
413
$kern_hz = get_single_sysctl('kern.clockrate');
414
$kern_hz = substr($kern_hz, strpos($kern_hz, "hz = ") + 5);
415
$kern_hz = substr($kern_hz, 0, strpos($kern_hz, ","));
416
if ($kern_hz == "1000") {
417
	set_single_sysctl("net.inet.tcp.rexmit_min" , "30");
418
}
419

    
420
/* start the igmpproxy daemon */
421
services_igmpproxy_configure();
422

    
423
/* start the upnp daemon if it is enabled */
424
upnp_start();
425

    
426
/* If powerd is enabled, lets launch it */
427
activate_powerd();
428

    
429
/* Set preferred protocol */
430
prefer_ipv4_or_ipv6();
431

    
432
/* Remove the old shutdown binary if we kept it. */
433
if (file_exists("/sbin/shutdown.old")) {
434
	@unlink("/sbin/shutdown.old");
435
}
436

    
437
/* Resync / Reinstall packages if need be */
438
if (file_exists('/conf/needs_package_sync')) {
439
	if ($config['installedpackages'] <> '' && is_array($config['installedpackages']['package'])) {
440
		require_once("pkg-utils.inc");
441
		if ($g['platform'] == "pfSense" || $g['platform'] == "nanobsd") {
442
			mark_subsystem_dirty('packagelock');
443
			pkg_reinstall_all();
444
			clear_subsystem_dirty('packagelock');
445
		}
446
	}
447
	@unlink('/conf/needs_package_sync');
448
}
449

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

    
454
/* done */
455
unset($g['booting']);
456
@unlink("{$g['varrun_path']}/booting");
457

    
458
/* If there are ipsec dynamic hosts try again to reload the tunnels as rc.newipsecdns does */
459
if ($ipsec_dynamic_hosts) {
460
	vpn_ipsec_configure();
461
}
462
if ($ipsec_dynamic_hosts || !empty($filterdns)) {
463
	filter_configure();
464
}
465

    
466
led_normalize();
467

    
468
conf_mount_ro();
469

    
470
?>
(33-33/104)