Project

General

Profile

Download (10.1 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/auth.inc");
105
echo ".";
106
require_once("/etc/inc/functions.inc");
107
echo ".";
108
require("/etc/inc/filter.inc");
109
echo ".";
110
require("/etc/inc/shaper.inc");
111
echo ".";
112
require_once("/etc/inc/ipsec.inc");
113
echo ".";
114
require_once("/etc/inc/vpn.inc");
115
echo ".";
116
require_once("/etc/inc/openvpn.inc");
117
echo ".";
118
require_once("/etc/inc/captiveportal.inc");
119
echo ".";
120
require_once("/etc/inc/rrd.inc");
121
echo ".";
122
require_once("/etc/inc/pfsense-utils.inc");
123
echo ".";
124

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

    
130
conf_mount_rw();
131

    
132
/* save dmesg output to file */
133
system_dmesg_save();
134

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

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

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

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

    
154
echo "Loading configuration...";
155
parse_config_bootup();
156
echo "done.\n";
157

    
158
$lan_if = $config['interfaces']['lan']['if'];
159
$wan_if = get_real_interface();
160

    
161
/*
162
 *  Determine if we need to throw a interface exception
163
 *  and ask the user to reassign interfaces.  This will
164
 *  avoid a reboot and thats a good thing.
165
 */
166
while(is_interface_mismatch() == true) {
167
	echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
168
	set_networking_interfaces_ports();
169
}
170

    
171
/* convert config and clean backups */
172
echo "Updating configuration...";
173
convert_config();
174
echo "done.\n";
175

    
176
echo "Cleaning backup cache...";
177
cleanup_backupcache(true);
178
echo "done.\n";
179

    
180
/* read in /etc/sysctl.conf and set values if needed */
181
echo "Setting up extended sysctls...";
182
system_setup_sysctl();
183
echo "done.\n";
184

    
185
/* enable glxsb if wanted */
186
load_glxsb();
187

    
188
/* run any early shell commands specified in config.xml */
189
system_do_shell_commands(1);
190

    
191
/* set up our timezone */
192
system_timezone_configure();
193

    
194
/* set up our hostname */
195
system_hostname_configure();
196

    
197
/* make hosts file */
198
system_hosts_generate();
199

    
200
/* configure loopback interface */
201
interfaces_loopback_configure();
202

    
203
echo "Starting Secure Shell Services...";
204
mwexec_bg("/etc/sshd");
205
echo "done.\n";
206

    
207
/* set up interfaces */
208
if(!$debugging)
209
	mute_kernel_msgs();
210
interfaces_configure();
211
if(!$debugging)
212
	unmute_kernel_msgs();
213

    
214
/* re-make hosts file after configuring interfaces */
215
system_hosts_generate();
216

    
217
/* generate resolv.conf */
218
system_resolvconf_generate();
219

    
220
/* start syslogd */
221
system_syslogd_start();
222

    
223
/* setup altq + pf */
224
filter_configure_sync();
225

    
226
/* start pflog */
227
echo "Starting PFLOG...";
228
filter_pflog_start();
229
echo "done.\n";
230

    
231
/* start load balancer daemon */
232
relayd_configure();
233

    
234
/* reconfigure our gateway monitor */
235
echo "Setting up gateway monitors...";
236
setup_gateways_monitor();
237
echo "done.\n";
238

    
239
echo "Synchronizing user settings...";
240
if (empty($config['system']['webgui']['backend']))
241
	local_sync_accounts();
242
echo "done.\n";
243

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

    
249
if($avail > 0 and $avail < 65) {
250
	echo "System has less than 65 megabytes of ram {$avail}.  Delaying webConfigurator startup.\n";
251
	/* start webConfigurator up on final pass */
252
	touch("/tmp/restart_webgui");
253
} else {
254
	/* start web server */
255
	system_webgui_start();
256
}
257

    
258
/* configure cron service */
259
echo "Configuring CRON...";
260
configure_cron();
261
echo "done.\n";
262

    
263
/* set up static routes */
264
system_routing_configure();
265

    
266
/* enable routing */
267
system_routing_enable();
268

    
269
/* configure console menu */
270
system_console_configure();
271

    
272
/* start the NTP client */
273
echo "Starting OpenNTP time client...";
274
system_ntp_configure();
275
echo "done.\n";
276

    
277
/* Launch on bootup and keep trying to sync.  Exit once time/date has been sync'd. */
278
mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh");
279

    
280
/* static IP address? -> attempt DNS update */
281
if (is_ipaddr($config['interfaces']['wan']['ipaddr']))
282
	services_dnsupdate_process();
283

    
284
/* start dnsmasq service */
285
services_dnsmasq_configure();
286

    
287
/* start dyndns service */
288
@touch("{$g['tmp_path']}/update_dyndns");
289

    
290
/* start DHCP relay */
291
services_dhcrelay_configure();
292

    
293
/* setup pppoe and pptp */
294
vpn_setup();
295

    
296
/* start the captive portal */
297
captiveportal_configure();
298

    
299
/* start Voucher support */
300
voucher_configure();
301

    
302
/* run any shell commands specified in config.xml */
303
system_do_shell_commands();
304

    
305
/* setup polling */
306
setup_polling();
307

    
308
/* setup interface microcode which improves tcp/ip speed */
309
echo "Setting up microcode and tx/rx offloading...";
310
setup_microcode();
311
echo "done.\n";
312

    
313
/* start IPsec tunnels */
314
vpn_ipsec_configure();
315

    
316
/* start SNMP service */
317
services_snmpd_configure();
318

    
319
/* power down hard drive if needed/set */
320
system_set_harddisk_standby();
321

    
322
/* lock down console if necessary */
323
auto_login();
324

    
325
/* Run a filter configure now that most all services have started */
326
filter_configure_sync();
327

    
328
/* load graphing functions */
329
enable_rrd_graphing();
330

    
331
/* start DHCP service */
332
services_dhcpd_configure();
333

    
334
/* startup OLSR if needed */
335
setup_wireless_olsr();
336

    
337
/* startup routed if needed */
338
include_once("/usr/local/pkg/routed/routed.inc");
339
setup_routed();
340

    
341
/* enable watchdog if supported */
342
enable_watchdog();
343

    
344
/* if <system><afterbootupshellcmd> exists, execute the command */
345
if($config['system']['afterbootupshellcmd'] <> "") {
346
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
347
	mwexec($config['system']['afterbootupshellcmd']);
348
}
349

    
350
if($avail < $g['minimum_ram_warning']) {
351
	require_once("/etc/inc/notices.inc");
352
	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);
353
	mwexec("sysctl net.inet.tcp.recvspace=4096");
354
	mwexec("sysctl net.inet.tcp.sendspace=4096");
355
}
356

    
357
/* if we are operating at 1000 then increase timeouts.
358
   this was never accounted for after moving to 1000 hz */
359
$kern_hz = `sysctl kern.clockrate | awk '{ print $5 }' | cut -d"," -f1`;
360
$kern_hz = trim($kern_hz, "\r\n");
361
if($kern_hz == "1000") 
362
	mwexec("sysctl net.inet.tcp.rexmit_min=30");
363

    
364
/* start the igmpproxy daemon */
365
services_igmpproxy_configure();
366

    
367
/* start the upnp daemon if it is enabled */
368
upnp_start();
369

    
370
/* If powerd is enabled, lets launch it */
371
activate_powerd();
372

    
373
/* done */
374
unset($g['booting']);
375

    
376
led_normalize();
377

    
378
conf_mount_ro();
379

    
380
?>
(32-32/93)