Project

General

Profile

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

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

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

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

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

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

    
84
echo " done.\n";
85

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

    
97
/* let the other functions know we're booting */
98
$pkg_interface = 'console';
99
$g['booting'] = true;
100

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

    
127
/* get system memory amount */
128
$memory = get_memory();
129
$avail = $memory[0];
130
echo " done.\n";
131

    
132
conf_mount_rw();
133

    
134
/* save dmesg output to file */
135
system_dmesg_save();
136

    
137
/* check whether config reset is desired (via hardware button on WRAP/ALIX) */
138
system_check_reset_button();
139

    
140
/* remove previous firmware upgrade if present */
141
if (file_exists("/root/firmware.tgz")) 
142
	unlink("/root/firmware.tgz");
143

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

    
152
// Display rescue configuration option
153
if($g['platform'] == "cdrom") 
154
		rescue_detect_keypress();
155

    
156
echo "Loading configuration...";
157
parse_config_bootup();
158
echo "done.\n";
159

    
160
if($g['platform'] == "jail") {
161
	/* We must determine what network settings have been configured for us */
162
	$wanif = "lo0";	/* defaults, if the jail admin hasn't set us up */
163
	$ipaddr = "127.0.0.1";
164
	$iflist = get_interface_list();
165
	foreach ($iflist as $iface => $ifa) {
166
		if (isset($ifa['ipaddr'])) {
167
			$wanif = $iface;
168
			$ipaddr = $ifa['ipaddr'];
169
			break;
170
		}
171
	}
172
	$config['interfaces'] = array();
173
	$config['interfaces']['lan'] = array();
174
	$config['interfaces']['lan']['enable'] = false;
175
	$config['interfaces']['wan'] = array();
176
	/* XXX, todo */
177
	$config['interfaces']['wan']['if'] = $wanif;
178
	$config['interfaces']['wan']['ipaddr'] = $ipaddr;
179
	$config['interfaces']['wan']['subnet'] = "32";	/* XXX right? */
180
	$config['interfaces']['wan']['enable'] = true;
181
	if($config['dhcpd']['lan']) 
182
		unset($config['dhcpd']['lan']['enable']);
183
	unlink_if_exists('/conf/trigger_initial_wizard');
184
	write_config();
185
} else {
186
	/*
187
	 *  Determine if we need to throw a interface exception
188
	 *  and ask the user to reassign interfaces.  This will
189
	 *  avoid a reboot and thats a good thing.
190
	 */
191
	while(is_interface_mismatch() == true) {
192
		led_assigninterfaces();
193
		echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
194
		$ifaces = get_interface_list();
195
		if (is_array($ifaces)) {
196
			foreach($ifaces as $iface => $ifdata)
197
				interfaces_bring_up($iface);
198
		}
199
		set_networking_interfaces_ports();
200
		led_kitt();
201
	}
202
}
203

    
204
/* convert config and clean backups */
205
echo "Updating configuration...";
206
convert_config();
207
echo "done.\n";
208

    
209
echo "Cleaning backup cache...";
210
cleanup_backupcache(true);
211
echo "done.\n";
212

    
213
/* read in /etc/sysctl.conf and set values if needed */
214
echo "Setting up extended sysctls...";
215
system_setup_sysctl();
216
echo "done.\n";
217

    
218
/* enable glxsb if wanted */
219
load_glxsb();
220

    
221
/* run any early shell commands specified in config.xml */
222
system_do_shell_commands(1);
223

    
224
/* set up our timezone */
225
system_timezone_configure();
226

    
227
/* set up our hostname */
228
system_hostname_configure();
229

    
230
/* make hosts file */
231
system_hosts_generate();
232

    
233
/* configure loopback interface */
234
interfaces_loopback_configure();
235

    
236
echo "Starting Secure Shell Services...";
237
mwexec_bg("/etc/sshd");
238
echo "done.\n";
239

    
240
/* setup polling */
241
echo "Setting up polling defaults...";
242
setup_polling();
243
echo "done.\n";
244

    
245
/* setup interface microcode which improves tcp/ip speed */
246
echo "Setting up interfaces microcode...";
247
setup_microcode();
248
echo "done.\n";
249

    
250
/* set up interfaces */
251
if(!$debugging)
252
	mute_kernel_msgs();
253
interfaces_configure();
254
if(!$debugging)
255
	unmute_kernel_msgs();
256

    
257
/* re-make hosts file after configuring interfaces */
258
system_hosts_generate();
259

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

    
265
/* generate resolv.conf */
266
system_resolvconf_generate();
267

    
268
/* start syslogd */
269
system_syslogd_start();
270

    
271
/* setup altq + pf */
272
filter_configure_sync();
273

    
274
/* start pflog */
275
echo "Starting PFLOG...";
276
filter_pflog_start();
277
echo "done.\n";
278

    
279
/* reconfigure our gateway monitor */
280
echo "Setting up gateway monitors...";
281
setup_gateways_monitor();
282
echo "done.\n";
283

    
284
echo "Synchronizing user settings...";
285
local_sync_accounts();
286
echo "done.\n";
287

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

    
297
/* configure cron service */
298
echo "Configuring CRON...";
299
configure_cron();
300
echo "done.\n";
301

    
302
/* set up static routes */
303
system_routing_configure();
304

    
305
/* enable routing */
306
system_routing_enable();
307

    
308
/* start load balancer daemon */
309
relayd_configure();
310

    
311
/* configure console menu */
312
system_console_configure();
313

    
314
/* start DHCP service */
315
services_dhcpd_configure();
316

    
317
/* start dnsmasq service */
318
services_dnsmasq_configure();
319

    
320
/* start dhcpleases dhpcp hosts leases program */
321
system_dhcpleases_configure();
322

    
323
/* start DHCP relay */
324
services_dhcrelay_configure();
325

    
326
/* dyndns service updates */
327
send_event("service reload dyndnsall");
328

    
329
/* Run a filter configure now that most all services have started */
330
filter_configure_sync();
331

    
332
/* start the NTP client */
333
echo "Starting OpenNTP time client...";
334
system_ntp_configure();
335
echo "done.\n";
336

    
337
/* setup pppoe and pptp */
338
vpn_setup();
339

    
340
/* start the captive portal */
341
captiveportal_configure();
342

    
343
/* start Voucher support */
344
voucher_configure();
345

    
346
/* run any shell commands specified in config.xml */
347
system_do_shell_commands();
348

    
349
/* start IPsec tunnels */
350
vpn_ipsec_configure();
351
/* Reload dynamic hostname tunnels after bootup finishes */
352
send_event("service reload ipsecdns");
353

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

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

    
360
/* lock down console if necessary */
361
auto_login();
362

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

    
366
/* startup OLSR if needed */
367
setup_wireless_olsr();
368

    
369
/* startup routed if needed */
370
include_once("/usr/local/pkg/routed.inc");
371
setup_routed();
372

    
373
/* enable watchdog if supported */
374
enable_watchdog();
375

    
376
/* if <system><afterbootupshellcmd> exists, execute the command */
377
if($config['system']['afterbootupshellcmd'] <> "") {
378
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
379
	mwexec($config['system']['afterbootupshellcmd']);
380
}
381

    
382
if($avail < $g['minimum_ram_warning']) {
383
	require_once("/etc/inc/notices.inc");
384
	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);
385
	mwexec("/sbin/sysctl net.inet.tcp.recvspace=4096");
386
	mwexec("/sbin/sysctl net.inet.tcp.sendspace=4096");
387
}
388

    
389
/* if we are operating at 1000 then increase timeouts.
390
   this was never accounted for after moving to 1000 hz */
391
$kern_hz = `/sbin/sysctl kern.clockrate | /usr/bin/awk '{ print $5 }' | /usr/bin/cut -d"," -f1`;
392
$kern_hz = trim($kern_hz, "\r\n");
393
if($kern_hz == "1000") 
394
	mwexec("/sbin/sysctl net.inet.tcp.rexmit_min=30");
395

    
396
/* start the igmpproxy daemon */
397
services_igmpproxy_configure();
398

    
399
/* start the upnp daemon if it is enabled */
400
upnp_start();
401

    
402
/* If powerd is enabled, lets launch it */
403
activate_powerd();
404

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

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

    
422
/* done */
423
unset($g['booting']);
424

    
425
led_normalize();
426

    
427
conf_mount_ro();
428

    
429
?>
(38-38/107)