Project

General

Profile

Download (11.8 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php-cgi -f
2
<?php
3
/*
4
	rc.bootup
5
	part of pfSense by Scott Ullrich
6
	originally based on m0n0wall (http://m0n0.ch/wall)
7
	Copyright (C) 2004-2009 Scott Ullrich <sullrich@pfsense.org>.
8
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9
	Copyright (C) 2009 Erik Kristensen
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

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

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

    
34
function rescue_detect_keypress() {
35
	// How long do you want the script to wait before moving on (in seconds)
36
	$timeout=9;
37
	echo "\n";
38
	echo "[ Press R to enter recovery mode or ]\n";
39
	echo "[  press I to launch the installer  ]\n\n";
40
	echo "(R)ecovery mode can assist by rescuing config.xml\n";
41
	echo "from a broken hard disk installation, etc.\n\n";
42
	echo "(I)nstaller will be invoked\n\n";
43
	echo "Timeout before auto boot continues (seconds): {$timeout}";
44
	$key = null;
45
	exec("/bin/stty erase " . chr(8));
46
	while (!in_array($key, array("r", "R", "i", "I"))) {
47
		echo chr(8) . "{$timeout}";
48
		`/bin/stty -icanon min 0 time 25`;
49
		$key = trim(`KEY=\`dd count=1 2>/dev/null\`; echo \$KEY`);
50
		`/bin/stty icanon`;
51
		// Decrement our timeout value
52
		$timeout--;
53
		// If we have reached 0 exit and continue on
54
		if ($timeout == 0) {
55
			break;
56
		}
57
	}
58
	// If R or I was pressed do our logic here
59
	if (in_array($key, array("r", "R"))) {
60
		putenv("TERM=cons25");
61
		echo "\n\nRecovery mode selected...\n";
62
		passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer rescue");
63
	} else {
64
		putenv("TERM=cons25");
65
		echo "\n\nInstaller mode selected...\n";
66
		passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer");
67
	}
68

    
69
	passthru("/etc/rc.reboot");
70
	exit;
71
}
72

    
73
echo " done.\n";
74

    
75
echo "Initializing...";
76
echo ".";
77
require_once("/etc/inc/globals.inc");
78
echo ".";
79
require_once("/etc/inc/led.inc");
80
led_normalize();
81
echo ".";
82
if (led_count() >= 3) {
83
	led_kitt();
84
}
85

    
86
/* let the other functions know we're booting */
87
$pkg_interface = 'console';
88
$g['booting'] = true;
89

    
90
/* parse the configuration and include all functions used below */
91
require_once("/etc/inc/config.inc");
92
echo ".";
93
require_once("/etc/inc/config.console.inc");
94
echo ".";
95
require_once("/etc/inc/auth.inc");
96
echo ".";
97
require_once("/etc/inc/functions.inc");
98
echo ".";
99
require_once("/etc/inc/filter.inc");
100
echo ".";
101
require_once("/etc/inc/shaper.inc");
102
echo ".";
103
require_once("/etc/inc/ipsec.inc");
104
echo ".";
105
require_once("/etc/inc/vpn.inc");
106
echo ".";
107
require_once("/etc/inc/openvpn.inc");
108
echo ".";
109
require_once("/etc/inc/captiveportal.inc");
110
echo ".";
111
require_once("/etc/inc/rrd.inc");
112
echo ".";
113
require_once("/etc/inc/pfsense-utils.inc");
114
echo ".";
115

    
116
/* get system memory amount */
117
$memory = get_memory();
118
$physmem = $memory[0];
119
$realmem = $memory[1];
120
echo " done.\n";
121

    
122
conf_mount_rw();
123

    
124
/* save dmesg output to file */
125
system_dmesg_save();
126

    
127
/* check whether config reset is desired (via hardware button on WRAP/ALIX) */
128
system_check_reset_button();
129

    
130
/* remove previous firmware upgrade if present */
131
if (file_exists("/root/firmware.tgz")) {
132
	unlink("/root/firmware.tgz");
133
}
134

    
135
/* Reinstall of packages after reboot has been requested */
136
if (file_exists('/conf/needs_package_sync_after_reboot')) {
137
	touch('/conf/needs_package_sync');
138
	@unlink('/conf/needs_package_sync_after_reboot');
139
}
140

    
141
/* Triggering of the initial setup wizard after reboot has been requested */
142
if (file_exists('/conf/trigger_initial_wizard_after_reboot')) {
143
	touch('/conf/trigger_initial_wizard');
144
	@unlink('/conf/trigger_initial_wizard_after_reboot');
145
}
146

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

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

    
160
echo "Loading configuration...";
161
parse_config_bootup();
162
echo "done.\n";
163

    
164
/* run any early shell commands specified in config.xml */
165
system_do_shell_commands(1);
166

    
167
if (file_exists("/conf/trigger_initial_wizard")) {
168
	check_for_alternate_interfaces();
169
}
170

    
171
/*
172
 *	Determine if we need to throw a interface exception
173
 *	and ask the user to reassign interfaces.  This will
174
 *	avoid a reboot and that is a good thing.
175
 */
176
while (is_interface_mismatch() == true) {
177
	led_assigninterfaces();
178
	if (isset($config['revision'])) {
179
		if (file_exists("{$g['tmp_path']}/missing_interfaces")) {
180
			echo "Warning: Configuration references interfaces that do not exist: " . file_get_contents("{$g['tmp_path']}/missing_interfaces") . "\n";
181
		}
182
		echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
183
	} else {
184
		echo "\nDefault interfaces not found -- Running interface assignment option.\n";
185
	}
186
	$ifaces = get_interface_list();
187
	if (is_array($ifaces)) {
188
		foreach ($ifaces as $iface => $ifdata) {
189
			interfaces_bring_up($iface);
190
		}
191
	}
192
	set_networking_interfaces_ports();
193
	led_kitt();
194
}
195

    
196
/* convert config and clean backups */
197
echo "Updating configuration...";
198
convert_config();
199
echo "done.\n";
200

    
201
echo "Cleaning backup cache...";
202
cleanup_backupcache(true);
203
echo "done.\n";
204

    
205
/* read in /etc/sysctl.conf and set values if needed */
206
echo "Setting up extended sysctls...";
207
system_setup_sysctl();
208
echo "done.\n";
209

    
210
/* enable optional crypto modules */
211
load_crypto();
212

    
213
/* enable optional thermal sensor modules */
214
load_thermal_hardware();
215

    
216
/* set up our timezone */
217
system_timezone_configure();
218

    
219
/* set up our hostname */
220
system_hostname_configure();
221

    
222
/* make hosts file */
223
system_hosts_generate();
224

    
225
/* configure loopback interface */
226
interfaces_loopback_configure();
227

    
228
/* start syslogd */
229
system_syslogd_start();
230

    
231
echo "Starting Secure Shell Services...";
232
send_event("service reload sshd");
233
echo "done.\n";
234

    
235
/* setup polling */
236
echo "Setting up polling defaults...";
237
setup_polling();
238
echo "done.\n";
239

    
240
/* setup interface microcode which improves tcp/ip speed */
241
echo "Setting up interfaces microcode...";
242
setup_microcode();
243
echo "done.\n";
244

    
245
/* set up interfaces */
246
if (!$debugging) {
247
	mute_kernel_msgs();
248
}
249
interfaces_configure();
250
interfaces_sync_setup();
251
if (!$debugging) {
252
	unmute_kernel_msgs();
253
}
254

    
255
/* re-make hosts file after configuring interfaces */
256
system_hosts_generate();
257

    
258
/* start OpenVPN server & clients */
259
echo "Syncing OpenVPN settings...";
260
openvpn_resync_all();
261
echo "done.\n";
262

    
263
/* generate resolv.conf */
264
system_resolvconf_generate();
265

    
266
/* setup altq + pf */
267
filter_configure_sync();
268

    
269
/* start pflog */
270
echo "Starting PFLOG...";
271
filter_pflog_start();
272
echo "done.\n";
273

    
274
/* reconfigure our gateway monitor */
275
echo "Setting up gateway monitors...";
276
setup_gateways_monitor();
277
echo "done.\n";
278

    
279
echo "Synchronizing user settings...";
280
local_sync_accounts();
281
echo "done.\n";
282

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

    
292
/* configure cron service */
293
echo "Configuring CRON...";
294
configure_cron();
295
echo "done.\n";
296

    
297
/* set up static routes */
298
system_routing_configure();
299

    
300
/* enable routing */
301
system_routing_enable();
302

    
303
/* start dnsmasq service */
304
services_dnsmasq_configure();
305

    
306
/* start unbound service */
307
services_unbound_configure();
308

    
309
/* Do an initial time sync */
310
echo "Starting NTP time client...";
311
/* At bootup this will just write the config, ntpd will launch from ntpdate_sync_once.sh */
312
system_ntp_configure(false);
313
mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh", true);
314
echo "done.\n";
315

    
316
/* start load balancer daemon */
317
relayd_configure();
318

    
319
/* configure console menu */
320
system_console_configure();
321

    
322
/* start DHCP service */
323
services_dhcpd_configure();
324

    
325
/* start dhcpleases dhcp hosts leases program */
326
system_dhcpleases_configure();
327

    
328
/* start DHCP relay */
329
services_dhcrelay_configure();
330

    
331
/* start DHCP6 relay */
332
services_dhcrelay6_configure();
333

    
334
/* dyndns service updates */
335
send_event("service reload dyndnsall");
336

    
337
/* Run a filter configure now that most all services have started */
338
filter_configure_sync();
339

    
340
/* setup pppoe and pptp */
341
vpn_setup();
342

    
343
/* start the captive portal */
344
captiveportal_configure();
345

    
346
/* start Voucher support */
347
voucher_configure();
348

    
349
/* run any shell commands specified in config.xml */
350
system_do_shell_commands();
351

    
352
/* start IPsec tunnels */
353
$ipsec_dynamic_hosts = vpn_ipsec_configure();
354

    
355
/* start SNMP service */
356
services_snmpd_configure();
357

    
358
/* power down hard drive if needed/set */
359
system_set_harddisk_standby();
360

    
361
/* lock down console if necessary */
362
reload_ttys();
363

    
364
/* load graphing functions */
365
enable_rrd_graphing();
366

    
367
/* enable watchdog if supported */
368
enable_watchdog();
369

    
370
/* if <system><afterbootupshellcmd> exists, execute the command */
371
if ($config['system']['afterbootupshellcmd'] <> "") {
372
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
373
	mwexec($config['system']['afterbootupshellcmd']);
374
}
375

    
376
if ($physmem < $g['minimum_ram_warning']) {
377
	require_once("/etc/inc/notices.inc");
378
	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);
379
	set_sysctl(array(
380
		"net.inet.tcp.recvspace" => "4096",
381
		"net.inet.tcp.sendspace" => "4096"
382
	));
383
}
384

    
385
/* if we are operating at 1000 then increase timeouts.
386
   this was never accounted for after moving to 1000 hz */
387
$kern_hz = get_single_sysctl('kern.clockrate');
388
$kern_hz = substr($kern_hz, strpos($kern_hz, "hz = ") + 5);
389
$kern_hz = substr($kern_hz, 0, strpos($kern_hz, ","));
390
if ($kern_hz == "1000") {
391
	set_single_sysctl("net.inet.tcp.rexmit_min" , "30");
392
}
393

    
394
/* start the igmpproxy daemon */
395
services_igmpproxy_configure();
396

    
397
/* start the upnp daemon if it is enabled */
398
upnp_start();
399

    
400
/* If powerd is enabled, lets launch it */
401
activate_powerd();
402

    
403
/* Set preferred protocol */
404
prefer_ipv4_or_ipv6();
405

    
406
/* Remove the old shutdown binary if we kept it. */
407
if (file_exists("/sbin/shutdown.old")) {
408
	@unlink("/sbin/shutdown.old");
409
}
410

    
411
/* Resync / Reinstall packages if need be */
412
if (file_exists('/conf/needs_package_sync') &&
413
    ($g['platform'] == $g['product_name'] || $g['platform'] == "nanobsd")) {
414
	require_once("pkg-utils.inc");
415
	mark_subsystem_dirty('packagelock');
416
	if (package_reinstall_all()) {
417
		@unlink('/conf/needs_package_sync');
418
	}
419
	clear_subsystem_dirty('packagelock');
420
}
421

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

    
426
/* done */
427
unset($g['booting']);
428
@unlink("{$g['varrun_path']}/booting");
429

    
430
/* If there are ipsec dynamic hosts try again to reload the tunnels as rc.newipsecdns does */
431
if ($ipsec_dynamic_hosts) {
432
	vpn_ipsec_configure();
433
}
434
if ($ipsec_dynamic_hosts || !empty($filterdns)) {
435
	filter_configure();
436
}
437

    
438
led_normalize();
439

    
440
conf_mount_ro();
441

    
442
?>
(27-27/94)