Project

General

Profile

Download (11.2 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
/* start devd (dhclient now uses it) */
136
echo "Starting device manager (devd)...";
137
mute_kernel_msgs();
138
start_devd();
139
set_device_perms();
140
unmute_kernel_msgs();
141
echo "done.\n";
142

    
143
// Display rescue configuration option
144
if ($g['platform'] == "cdrom") {
145
	rescue_detect_keypress();
146
}
147

    
148
echo "Loading configuration...";
149
parse_config_bootup();
150
echo "done.\n";
151

    
152
/* run any early shell commands specified in config.xml */
153
system_do_shell_commands(1);
154

    
155
/*
156
 *	Determine if we need to throw a interface exception
157
 *	and ask the user to reassign interfaces.  This will
158
 *	avoid a reboot and that is a good thing.
159
 */
160
while (is_interface_mismatch() == true) {
161
	led_assigninterfaces();
162
	if (isset($config['revision'])) {
163
		if (file_exists("{$g['tmp_path']}/missing_interfaces")) {
164
			echo "Warning: Configuration references interfaces that do not exist: " . file_get_contents("{$g['tmp_path']}/missing_interfaces") . "\n";
165
		}
166
		echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
167
	} else {
168
		echo "\nDefault interfaces not found -- Running interface assignment option.\n";
169
	}
170
	$ifaces = get_interface_list();
171
	if (is_array($ifaces)) {
172
		foreach ($ifaces as $iface => $ifdata) {
173
			interfaces_bring_up($iface);
174
		}
175
	}
176
	set_networking_interfaces_ports();
177
	led_kitt();
178
}
179

    
180
/* convert config and clean backups */
181
echo "Updating configuration...";
182
convert_config();
183
echo "done.\n";
184

    
185
echo "Cleaning backup cache...";
186
cleanup_backupcache(true);
187
echo "done.\n";
188

    
189
/* read in /etc/sysctl.conf and set values if needed */
190
echo "Setting up extended sysctls...";
191
system_setup_sysctl();
192
echo "done.\n";
193

    
194
/* enable optional crypto modules */
195
load_crypto();
196

    
197
/* enable optional thermal sensor modules */
198
load_thermal_hardware();
199

    
200
/* set up our timezone */
201
system_timezone_configure();
202

    
203
/* set up our hostname */
204
system_hostname_configure();
205

    
206
/* make hosts file */
207
system_hosts_generate();
208

    
209
/* configure loopback interface */
210
interfaces_loopback_configure();
211

    
212
/* start syslogd */
213
system_syslogd_start();
214

    
215
echo "Starting Secure Shell Services...";
216
send_event("service reload sshd");
217
echo "done.\n";
218

    
219
/* setup polling */
220
echo "Setting up polling defaults...";
221
setup_polling();
222
echo "done.\n";
223

    
224
/* setup interface microcode which improves tcp/ip speed */
225
echo "Setting up interfaces microcode...";
226
setup_microcode();
227
echo "done.\n";
228

    
229
/* set up interfaces */
230
if (!$debugging) {
231
	mute_kernel_msgs();
232
}
233
interfaces_configure();
234
interfaces_sync_setup();
235
if (!$debugging) {
236
	unmute_kernel_msgs();
237
}
238

    
239
/* re-make hosts file after configuring interfaces */
240
system_hosts_generate();
241

    
242
/* start OpenVPN server & clients */
243
echo "Syncing OpenVPN settings...";
244
openvpn_resync_all();
245
echo "done.\n";
246

    
247
/* generate resolv.conf */
248
system_resolvconf_generate();
249

    
250
/* setup altq + pf */
251
filter_configure_sync();
252

    
253
/* start pflog */
254
echo "Starting PFLOG...";
255
filter_pflog_start();
256
echo "done.\n";
257

    
258
/* reconfigure our gateway monitor */
259
echo "Setting up gateway monitors...";
260
setup_gateways_monitor();
261
echo "done.\n";
262

    
263
echo "Synchronizing user settings...";
264
local_sync_accounts();
265
echo "done.\n";
266

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

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

    
281
/* set up static routes */
282
system_routing_configure();
283

    
284
/* enable routing */
285
system_routing_enable();
286

    
287
/* start dnsmasq service */
288
services_dnsmasq_configure();
289

    
290
/* start unbound service */
291
services_unbound_configure();
292

    
293
/* Do an initial time sync */
294
echo "Starting NTP time client...";
295
/* At bootup this will just write the config, ntpd will launch from ntpdate_sync_once.sh */
296
system_ntp_configure(false);
297
mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh", true);
298
echo "done.\n";
299

    
300
/* start load balancer daemon */
301
relayd_configure();
302

    
303
/* configure console menu */
304
system_console_configure();
305

    
306
/* start DHCP service */
307
services_dhcpd_configure();
308

    
309
/* start dhcpleases dhcp hosts leases program */
310
system_dhcpleases_configure();
311

    
312
/* start DHCP relay */
313
services_dhcrelay_configure();
314

    
315
/* start DHCP6 relay */
316
services_dhcrelay6_configure();
317

    
318
/* dyndns service updates */
319
send_event("service reload dyndnsall");
320

    
321
/* Run a filter configure now that most all services have started */
322
filter_configure_sync();
323

    
324
/* setup pppoe and pptp */
325
vpn_setup();
326

    
327
/* start the captive portal */
328
captiveportal_configure();
329

    
330
/* start Voucher support */
331
voucher_configure();
332

    
333
/* run any shell commands specified in config.xml */
334
system_do_shell_commands();
335

    
336
/* start IPsec tunnels */
337
$ipsec_dynamic_hosts = vpn_ipsec_configure();
338

    
339
/* start SNMP service */
340
services_snmpd_configure();
341

    
342
/* power down hard drive if needed/set */
343
system_set_harddisk_standby();
344

    
345
/* lock down console if necessary */
346
reload_ttys();
347

    
348
/* load graphing functions */
349
enable_rrd_graphing();
350

    
351
/* enable watchdog if supported */
352
enable_watchdog();
353

    
354
/* if <system><afterbootupshellcmd> exists, execute the command */
355
if ($config['system']['afterbootupshellcmd'] <> "") {
356
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
357
	mwexec($config['system']['afterbootupshellcmd']);
358
}
359

    
360
if ($physmem < $g['minimum_ram_warning']) {
361
	require_once("/etc/inc/notices.inc");
362
	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);
363
	set_sysctl(array(
364
		"net.inet.tcp.recvspace" => "4096",
365
		"net.inet.tcp.sendspace" => "4096"
366
	));
367
}
368

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

    
378
/* start the igmpproxy daemon */
379
services_igmpproxy_configure();
380

    
381
/* start the upnp daemon if it is enabled */
382
upnp_start();
383

    
384
/* If powerd is enabled, lets launch it */
385
activate_powerd();
386

    
387
/* Set preferred protocol */
388
prefer_ipv4_or_ipv6();
389

    
390
/* Remove the old shutdown binary if we kept it. */
391
if (file_exists("/sbin/shutdown.old")) {
392
	@unlink("/sbin/shutdown.old");
393
}
394

    
395
/* Resync / Reinstall packages if need be */
396
if (file_exists('/conf/needs_package_sync') &&
397
    ($g['platform'] == $g['product_name'] || $g['platform'] == "nanobsd")) {
398
	require_once("pkg-utils.inc");
399
	mark_subsystem_dirty('packagelock');
400
	if (package_reinstall_all()) {
401
		@unlink('/conf/needs_package_sync');
402
	}
403
	clear_subsystem_dirty('packagelock');
404
}
405

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

    
410
/* done */
411
unset($g['booting']);
412
@unlink("{$g['varrun_path']}/booting");
413

    
414
/* If there are ipsec dynamic hosts try again to reload the tunnels as rc.newipsecdns does */
415
if ($ipsec_dynamic_hosts) {
416
	vpn_ipsec_configure();
417
}
418
if ($ipsec_dynamic_hosts || !empty($filterdns)) {
419
	filter_configure();
420
}
421

    
422
led_normalize();
423

    
424
conf_mount_ro();
425

    
426
?>
(33-33/101)