Project

General

Profile

Download (12.4 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php -f
2
<?php
3 abb87c26 Ermal
ini_set('apc.enabled', '0');
4
5 1b8df11b Bill Marquette
/* $Id$ */
6 5b237745 Scott Ullrich
/*
7
	rc.bootup
8 e5cd29a0 Scott Ullrich
	part of pfSense by Scott Ullrich
9
	originally based on m0n0wall (http://m0n0.ch/wall)
10 70045f5f Scott Ullrich
	Copyright (C) 2004-2009 Scott Ullrich <sullrich@pfsense.org>.
11 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
12 745188c8 Scott Ullrich
	Copyright (C) 2009 Erik Kristensen
13 5b237745 Scott Ullrich
	All rights reserved.
14 e5cd29a0 Scott Ullrich
15 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
16
	modification, are permitted provided that the following conditions are met:
17 e5cd29a0 Scott Ullrich
18 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
19
	   this list of conditions and the following disclaimer.
20 e5cd29a0 Scott Ullrich
21 5b237745 Scott Ullrich
	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 e5cd29a0 Scott Ullrich
25 5b237745 Scott Ullrich
	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 6cc9e241 Scott Ullrich
function rescue_detect_keypress() {
38
	// How long do you want the script to wait before moving on (in seconds)
39 1e4e8458 Scott Ullrich
	$timeout=9;
40 41d07e42 Scott Ullrich
	echo "\n";
41 6c616b93 Scott Ullrich
    echo "[ Press R to enter recovery mode or ]\n";
42
	echo "[  press I to launch the installer  ]\n\n";
43 1e4e8458 Scott Ullrich
	echo "(R)ecovery mode can assist by rescuing config.xml\n";
44 e5a06994 Scott Ullrich
	echo "from a broken hard disk installation, etc.\n\n";
45 055abc57 Scott Ullrich
	echo "(I)nstaller may be invoked now if you do \n";
46 efce1588 Scott Ullrich
	echo "not wish to boot into the liveCD environment at this time.\n\n";
47 22af75a3 Scott Ullrich
	echo "(C) continues the LiveCD bootup without further pause.\n\n";
48 1e4e8458 Scott Ullrich
	echo "Timeout before auto boot continues (seconds): {$timeout}";
49 6cc9e241 Scott Ullrich
	$key = null;
50 1e4e8458 Scott Ullrich
	exec("/bin/stty erase " . chr(8));
51 055abc57 Scott Ullrich
	while(!in_array($key, array("c", "C", "r","R", "i", "I", "~", "!"))) {
52 1e4e8458 Scott Ullrich
	        echo chr(8) . "{$timeout}";
53 e5a06994 Scott Ullrich
	        `/bin/stty -icanon min 0 time 25`;
54 6cc9e241 Scott Ullrich
	        $key = trim(`KEY=\`dd count=1 2>/dev/null\`; echo \$KEY`);
55 2eeb1781 Scott Ullrich
	        `/bin/stty icanon`;
56 6cc9e241 Scott Ullrich
	        // Decrement our timeout value
57
	        $timeout--;
58
	        // If we have reached 0 exit and continue on
59 70045f5f Scott Ullrich
	        if ($timeout == 0) 
60
				break;
61 6cc9e241 Scott Ullrich
	}
62 540bd313 Scott Ullrich
	// If R or I was pressed do our logic here
63 70045f5f Scott Ullrich
	if (in_array($key, array("r", "R"))) {
64 68235416 Scott Ullrich
	  putenv("TERM=cons25");
65
	  echo "\n\nRecovery mode selected...\n";
66 f98d3d65 Scott Ullrich
	  passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer_rescue");
67 d5116ed5 Scott Ullrich
	} elseif (in_array($key, array("i", "I"))) {
68 68235416 Scott Ullrich
	  putenv("TERM=cons25");  
69
	  echo "\n\nInstaller mode selected...\n";
70 f98d3d65 Scott Ullrich
	  passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer");
71 c1da5030 Scott Ullrich
	  if(file_exists("/tmp/install_complete")) {
72 f98d3d65 Scott Ullrich
		passthru("/etc/rc.reboot");
73 c1da5030 Scott Ullrich
		exit;
74
	  }
75
	} elseif (in_array($key, array("!", "~"))) {
76 68235416 Scott Ullrich
 		putenv("TERM=cons25");
77
		echo "\n\nRecovery shell selected...\n";
78 6c616b93 Scott Ullrich
		echo "\n";
79 c1da5030 Scott Ullrich
		touch("/tmp/donotbootup");
80
		exit;
81 01ef30e9 Scott Ullrich
	} else {
82
		echo "\n\n";
83 745188c8 Scott Ullrich
	}
84 6cc9e241 Scott Ullrich
}
85
86
echo " done.\n";
87
88
echo "Initializing...";
89
echo ".";
90
require_once("/etc/inc/globals.inc");
91 483e6de8 Scott Ullrich
echo ".";
92 00a4146e jim-p
require_once("/etc/inc/led.inc");
93
led_normalize();
94 483e6de8 Scott Ullrich
echo ".";
95 00a4146e jim-p
if (led_count() >= 3) {
96
	led_kitt();
97
}
98 483e6de8 Scott Ullrich
99 6cc9e241 Scott Ullrich
/* let the other functions know we're booting */
100
$pkg_interface = 'console';
101 410cdac4 Scott Ullrich
$g['booting'] = true;
102 6cc9e241 Scott Ullrich
103
/* parse the configuration and include all functions used below */
104
require_once("/etc/inc/config.inc");
105
echo ".";
106 032c40c7 Scott Ullrich
require_once("/etc/inc/config.console.inc");
107
echo ".";
108 3066a36f Ermal Lu?i
require_once("/etc/inc/auth.inc");
109
echo ".";
110 6cc9e241 Scott Ullrich
require_once("/etc/inc/functions.inc");
111 62d93213 Scott Ullrich
echo ".";
112 1b1c179d jim-p
require_once("/etc/inc/filter.inc");
113 5f2d078e Scott Ullrich
echo ".";
114 1b1c179d jim-p
require_once("/etc/inc/shaper.inc");
115 5f2d078e Scott Ullrich
echo ".";
116 483e6de8 Scott Ullrich
require_once("/etc/inc/ipsec.inc");
117
echo ".";
118
require_once("/etc/inc/vpn.inc");
119
echo ".";
120 5f2d078e Scott Ullrich
require_once("/etc/inc/openvpn.inc");
121 62d93213 Scott Ullrich
echo ".";
122 483e6de8 Scott Ullrich
require_once("/etc/inc/captiveportal.inc");
123
echo ".";
124
require_once("/etc/inc/rrd.inc");
125
echo ".";
126 3ffa8318 Renato Botelho
require_once("/etc/inc/pfsense-utils.inc");
127
echo ".";
128 62d93213 Scott Ullrich
129 6cc9e241 Scott Ullrich
/* get system memory amount */
130
$memory = get_memory();
131 76a7d8e4 Ermal
$avail = $memory[1];
132 6cc9e241 Scott Ullrich
echo " done.\n";
133
134 63e18082 jim-p
conf_mount_rw();
135 6cc9e241 Scott Ullrich
136 7f039071 jim-p
/* save dmesg output to file */
137
system_dmesg_save();
138
139 7188fc6d Scott Ullrich
/* check whether config reset is desired (via hardware button on WRAP/ALIX) */
140
system_check_reset_button();
141
142 6cc9e241 Scott Ullrich
/* remove previous firmware upgrade if present */
143
if (file_exists("/root/firmware.tgz")) 
144
	unlink("/root/firmware.tgz");
145
146 de00c381 Phil Davis
/* start devd (dhclient now uses it) */
147 6cc9e241 Scott Ullrich
echo "Starting device manager (devd)...";
148
mute_kernel_msgs();
149
start_devd();
150
set_device_perms();
151
unmute_kernel_msgs();
152
echo "done.\n";
153
154
// Display rescue configuration option
155
if($g['platform'] == "cdrom") 
156
		rescue_detect_keypress();
157
158 d5116ed5 Scott Ullrich
echo "Loading configuration...";
159
parse_config_bootup();
160
echo "done.\n";
161
162 7734aea6 Andrew Thompson
if($g['platform'] == "jail") {
163
	/* We must determine what network settings have been configured for us */
164
	$wanif = "lo0";	/* defaults, if the jail admin hasn't set us up */
165
	$ipaddr = "127.0.0.1";
166
	$iflist = get_interface_list();
167
	foreach ($iflist as $iface => $ifa) {
168
		if (isset($ifa['ipaddr'])) {
169
			$wanif = $iface;
170
			$ipaddr = $ifa['ipaddr'];
171
			break;
172
		}
173
	}
174
	$config['interfaces'] = array();
175
	$config['interfaces']['lan'] = array();
176
	$config['interfaces']['lan']['enable'] = false;
177
	$config['interfaces']['wan'] = array();
178
	/* XXX, todo */
179
	$config['interfaces']['wan']['if'] = $wanif;
180
	$config['interfaces']['wan']['ipaddr'] = $ipaddr;
181
	$config['interfaces']['wan']['subnet'] = "32";	/* XXX right? */
182
	$config['interfaces']['wan']['enable'] = true;
183
	if($config['dhcpd']['lan']) 
184
		unset($config['dhcpd']['lan']['enable']);
185
	unlink_if_exists('/conf/trigger_initial_wizard');
186
	write_config();
187
} else {
188
	/*
189
	 *  Determine if we need to throw a interface exception
190
	 *  and ask the user to reassign interfaces.  This will
191
	 *  avoid a reboot and thats a good thing.
192
	 */
193
	while(is_interface_mismatch() == true) {
194
		led_assigninterfaces();
195 7852ce9b Erik Fonnesbeck
		if (isset($config['revision'])) {
196
			if (file_exists("{$g['tmp_path']}/missing_interfaces"))
197
				echo "Warning: Configuration references interfaces that do not exist: " . file_get_contents("{$g['tmp_path']}/missing_interfaces") . "\n";
198
			echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
199
		} else
200
			echo "\nDefault interfaces not found -- Running interface assignment option.\n";
201 7734aea6 Andrew Thompson
		$ifaces = get_interface_list();
202
		if (is_array($ifaces)) {
203
			foreach($ifaces as $iface => $ifdata)
204
				interfaces_bring_up($iface);
205
		}
206
		set_networking_interfaces_ports();
207
		led_kitt();
208 7f8d463f Ermal
	}
209 6cc9e241 Scott Ullrich
}
210
211
/* convert config and clean backups */
212
echo "Updating configuration...";
213
convert_config();
214
echo "done.\n";
215
216
echo "Cleaning backup cache...";
217
cleanup_backupcache(true);
218
echo "done.\n";
219
220
/* read in /etc/sysctl.conf and set values if needed */
221
echo "Setting up extended sysctls...";
222
system_setup_sysctl();
223
echo "done.\n";
224
225 7530177c jim-p
/* enable optional crypto modules */
226
load_crypto();
227 09f18f59 jim-p
228 f60156f6 jim-p
/* enable optional thermal sensor modules */
229
load_thermal_hardware();
230
231 6cc9e241 Scott Ullrich
/* run any early shell commands specified in config.xml */
232
system_do_shell_commands(1);
233 ef0090a3 Scott Ullrich
234 6cc9e241 Scott Ullrich
/* set up our timezone */
235
system_timezone_configure();
236
237
/* set up our hostname */
238
system_hostname_configure();
239
240
/* make hosts file */
241
system_hosts_generate();
242
243
/* configure loopback interface */
244
interfaces_loopback_configure();
245
246 2b6f7508 smos
/* start syslogd */
247
system_syslogd_start();
248
249 b29d9c8e Ermal
echo "Starting Secure Shell Services...";
250
mwexec_bg("/etc/sshd");
251
echo "done.\n";
252
253 9a4c3eed Ermal
/* setup polling */
254
echo "Setting up polling defaults...";
255
setup_polling();
256
echo "done.\n";
257
258
/* setup interface microcode which improves tcp/ip speed */
259 7d6128e0 Ermal
echo "Setting up interfaces microcode...";
260 9a4c3eed Ermal
setup_microcode();
261
echo "done.\n";
262
263 6cc9e241 Scott Ullrich
/* set up interfaces */
264
if(!$debugging)
265 70b89814 Scott Ullrich
	mute_kernel_msgs();
266 6cc9e241 Scott Ullrich
interfaces_configure();
267
if(!$debugging)
268 70b89814 Scott Ullrich
	unmute_kernel_msgs();
269 86ddbb71 Scott Ullrich
270 4994b350 smos
/* re-make hosts file after configuring interfaces */
271
system_hosts_generate();
272
273 d09d53ac Ermal
/* start OpenVPN server & clients */
274
echo "Syncing OpenVPN settings...";
275
openvpn_resync_all();
276
echo "done.\n";
277
278 6cc9e241 Scott Ullrich
/* generate resolv.conf */
279
system_resolvconf_generate();
280 aa01f2f2 Scott Ullrich
281 2fd9d050 Scott Ullrich
/* setup altq + pf */
282
filter_configure_sync();
283
284 6cc9e241 Scott Ullrich
/* start pflog */
285
echo "Starting PFLOG...";
286
filter_pflog_start();
287
echo "done.\n";
288 d0e94aaf Scott Ullrich
289 17fdcb8d Ermal Lu?i
/* reconfigure our gateway monitor */
290 6cc9e241 Scott Ullrich
echo "Setting up gateway monitors...";
291 17fdcb8d Ermal Lu?i
setup_gateways_monitor();
292
echo "done.\n";
293
294
echo "Synchronizing user settings...";
295 24e61cce Ermal
local_sync_accounts();
296 6cc9e241 Scott Ullrich
echo "done.\n";
297 d0e94aaf Scott Ullrich
298 6cc9e241 Scott Ullrich
if($avail > 0 and $avail < 65) {
299
	echo "System has less than 65 megabytes of ram {$avail}.  Delaying webConfigurator startup.\n";
300
	/* start webConfigurator up on final pass */
301 f3239b2d Chris Buechler
	mwexec("/usr/local/sbin/pfSctl -c 'service restart webgui'");
302 6cc9e241 Scott Ullrich
} else {
303
	/* start web server */
304
	system_webgui_start();
305
}
306 ef9366bd Scott Ullrich
307 6cc9e241 Scott Ullrich
/* configure cron service */
308
echo "Configuring CRON...";
309
configure_cron();
310
echo "done.\n";
311 68cd47b3 Scott Ullrich
312 6cc9e241 Scott Ullrich
/* set up static routes */
313
system_routing_configure();
314 d0e94aaf Scott Ullrich
315 6cc9e241 Scott Ullrich
/* enable routing */
316
system_routing_enable();
317 e5cd29a0 Scott Ullrich
318 26ee0570 jim-p
/* start dnsmasq service */
319
services_dnsmasq_configure();
320
321 0b8e9d38 jim-p
/* Do an initial time sync */
322
echo "Starting NTP time client...";
323
/* At bootup this will just write the config, ntpd will launch from ntpdate_sync_once.sh */
324
system_ntp_configure(false);
325 b61e8960 jim-p
mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh", true);
326 de00c381 Phil Davis
echo "done.\n";
327 0b8e9d38 jim-p
328 d1265444 Ermal
/* start load balancer daemon */
329
relayd_configure();
330
331 6cc9e241 Scott Ullrich
/* configure console menu */
332
system_console_configure();
333 a005424e Scott Ullrich
334 24d619f5 Ermal
/* start DHCP service */
335
services_dhcpd_configure();
336
337 92150bd8 Ermal
/* start dhcpleases dhpcp hosts leases program */
338
system_dhcpleases_configure();
339
340 6cc9e241 Scott Ullrich
/* start DHCP relay */
341
services_dhcrelay_configure();
342 562fca6d Scott Ullrich
343 64ad3cc8 Phil Davis
/* start DHCP6 relay */
344
services_dhcrelay6_configure();
345
346 422bc2a7 Ermal
/* dyndns service updates */
347
send_event("service reload dyndnsall");
348
349 8c41a3e4 Ermal
/* Run a filter configure now that most all services have started */
350
filter_configure_sync();
351
352 6cc9e241 Scott Ullrich
/* setup pppoe and pptp */
353
vpn_setup();
354 c6e604d8 Scott Ullrich
355 6cc9e241 Scott Ullrich
/* start the captive portal */
356
captiveportal_configure();
357 f4959a69 Scott Ullrich
358 336e3c1c Charlie
/* start Voucher support */
359
voucher_configure();
360
361 6cc9e241 Scott Ullrich
/* run any shell commands specified in config.xml */
362
system_do_shell_commands();
363 9f966bc9 Scott Ullrich
364 6cc9e241 Scott Ullrich
/* start IPsec tunnels */
365 e5b89d37 Ermal
$ipsec_dynamic_hosts = vpn_ipsec_configure();
366 a199b93e Scott Ullrich
367 6cc9e241 Scott Ullrich
/* start SNMP service */
368
services_snmpd_configure();
369 11cbd478 Scott Ullrich
370 6cc9e241 Scott Ullrich
/* power down hard drive if needed/set */
371
system_set_harddisk_standby();
372 011bff69 Bill Marquette
373 6cc9e241 Scott Ullrich
/* lock down console if necessary */
374 a46e450c Ermal Lu?i
auto_login();
375 d0e94aaf Scott Ullrich
376 6cc9e241 Scott Ullrich
/* load graphing functions */
377
enable_rrd_graphing();
378
379
/* enable watchdog if supported */
380
enable_watchdog();
381
382
/* if <system><afterbootupshellcmd> exists, execute the command */
383
if($config['system']['afterbootupshellcmd'] <> "") {
384
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
385
	mwexec($config['system']['afterbootupshellcmd']);
386
}
387
388 9f274393 Chris Buechler
if($avail < $g['minimum_ram_warning']) {
389 6cc9e241 Scott Ullrich
	require_once("/etc/inc/notices.inc");
390 9f274393 Chris Buechler
	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);
391 c5901d28 Ermal
	mwexec("/sbin/sysctl net.inet.tcp.recvspace=4096");
392
	mwexec("/sbin/sysctl net.inet.tcp.sendspace=4096");
393 6cc9e241 Scott Ullrich
}
394
395
/* if we are operating at 1000 then increase timeouts.
396
   this was never accounted for after moving to 1000 hz */
397 c5901d28 Ermal
$kern_hz = `/sbin/sysctl kern.clockrate | /usr/bin/awk '{ print $5 }' | /usr/bin/cut -d"," -f1`;
398 6cc9e241 Scott Ullrich
$kern_hz = trim($kern_hz, "\r\n");
399
if($kern_hz == "1000") 
400 c5901d28 Ermal
	mwexec("/sbin/sysctl net.inet.tcp.rexmit_min=30");
401 c108ec01 Scott Ullrich
402 34c7f02e Scott Ullrich
/* start the igmpproxy daemon */
403 6cc9e241 Scott Ullrich
services_igmpproxy_configure();
404 41997fbb Ermal Luci
405 6cc9e241 Scott Ullrich
/* start the upnp daemon if it is enabled */
406
upnp_start();
407 6f20377b Scott Ullrich
408 6cc9e241 Scott Ullrich
/* If powerd is enabled, lets launch it */
409
activate_powerd();
410 8e9fa41d Scott Ullrich
411 bf072179 jim-p
/* Remove the old shutdown binary if we kept it. */
412
if (file_exists("/sbin/shutdown.old"))
413 c5901d28 Ermal
	@unlink("/sbin/shutdown.old");
414 bf072179 jim-p
415 9b193619 Scott Ullrich
/* Resync / Reinstall packages if need be */
416
if(file_exists('/conf/needs_package_sync')) {
417
	if($config['installedpackages'] <> '' && is_array($config['installedpackages']['package'])) {
418 7aa9ab00 Scott Ullrich
		require_once("pkg-utils.inc");
419 9b193619 Scott Ullrich
		if($g['platform'] == "pfSense" || $g['platform'] == "nanobsd") {
420 261c7de8 jim-p
			mark_subsystem_dirty('packagelock');
421 9b193619 Scott Ullrich
			pkg_reinstall_all();
422 261c7de8 jim-p
			clear_subsystem_dirty('packagelock');
423 9b193619 Scott Ullrich
		}
424
	}
425 393cd3fc Ermal
	@unlink('/conf/needs_package_sync');
426 9b193619 Scott Ullrich
}
427
428 eac52376 jim-p
/* Give syslogd a kick after everything else has been initialized, otherwise it can occasionally
429
   fail to route syslog messages properly on both IPv4 and IPv6 */
430
system_syslogd_start();
431 25ed9cf8 jim-p
432 6cc9e241 Scott Ullrich
/* done */
433 27556fa9 Scott Ullrich
unset($g['booting']);
434 5c60c947 Scott Ullrich
435 e5b89d37 Ermal
/* If there are ipsec dynamic hosts try again to reload the tunnels as rc.newipsecdns does */
436
if ($ipsec_dynamic_hosts) {
437
	vpn_ipsec_refresh_policies();
438
	vpn_ipsec_configure();
439
}
440
441 00a4146e jim-p
led_normalize();
442 410cdac4 Scott Ullrich
443 63e18082 jim-p
conf_mount_ro();
444 6346595c Ermal Lu?i
445 3a4b0147 Ermal
?>