Project

General

Profile

Download (9.89 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 "Alternatively the (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 "Timeout before auto boot continues (seconds): {$timeout}";
46
	$key = null;
47
	exec("/bin/stty erase " . chr(8));
48
	while(!in_array($key, array("r","R", "i", "I", "~", "!"))) {
49
	        echo chr(8) . "{$timeout}";
50
	        `/bin/stty -icanon min 0 time 25`;
51
	        $key = trim(`KEY=\`dd count=1 2>/dev/null\`; echo \$KEY`);
52
	        `/bin/stty icanon`;
53
	        // Decrement our timeout value
54
	        $timeout--;
55
	        // If we have reached 0 exit and continue on
56
	        if ($timeout == 0) 
57
				break;
58
	}
59
	// If R or I was pressed do our logic here
60
	if (in_array($key, array("r", "R"))) {
61
	  putenv("TERM=cons25");
62
	  echo "\n\nRecovery mode selected...\n";
63
	  passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer_rescue");
64
	} elseif (in_array($key, array("i", "I"))) {
65
	  putenv("TERM=cons25");  
66
	  echo "\n\nInstaller mode selected...\n";
67
	  passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer");
68
	  if(file_exists("/tmp/install_complete")) {
69
		passthru("/etc/rc.reboot");
70
		exit;
71
	  }
72
	} elseif (in_array($key, array("!", "~"))) {
73
 		putenv("TERM=cons25");
74
		echo "\n\nRecovery shell selected...\n";
75
		echo "\n";
76
		touch("/tmp/donotbootup");
77
		exit;
78
	} else {
79
		echo "\n\n";
80
	}
81
}
82

    
83
echo " done.\n";
84

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

    
96
/* let the other functions know we're booting */
97
$pkg_interface = 'console';
98
$g['booting'] = true;
99
touch("{$g['varrun_path']}/booting");
100
if($g['platform'] == "cdrom") {
101
	$motd = trim(file_get_contents("/etc/motd"));
102
	if (strlen($motd) > 2) 
103
		echo "\n{$motd}\n\n";
104
}
105

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

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

    
131
conf_mount_rw();
132

    
133
/* remove previous firmware upgrade if present */
134
if (file_exists("/root/firmware.tgz")) 
135
	unlink("/root/firmware.tgz");
136

    
137
/* start devd (dhclient now uses it */
138
echo "Starting device manager (devd)...";
139
mute_kernel_msgs();
140
start_devd();
141
set_device_perms();
142
unmute_kernel_msgs();
143
echo "done.\n";
144

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

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

    
153
$lan_if = $config['interfaces']['lan']['if'];
154
$wan_if = get_real_interface();
155

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

    
167
/* convert config and clean backups */
168
echo "Updating configuration...";
169
convert_config();
170
echo "done.\n";
171

    
172
echo "Cleaning backup cache...";
173
cleanup_backupcache(true);
174
echo "done.\n";
175

    
176
/* read in /etc/sysctl.conf and set values if needed */
177
echo "Setting up extended sysctls...";
178
system_setup_sysctl();
179
echo "done.\n";
180

    
181
/* enable glxsb if wanted */
182
load_glxsb();
183

    
184
/* run any early shell commands specified in config.xml */
185
system_do_shell_commands(1);
186

    
187
/* save dmesg output to file */
188
system_dmesg_save();
189

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

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

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

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

    
202
/* start syslogd */
203
system_syslogd_start();
204

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

    
212
/* generate resolv.conf */
213
system_resolvconf_generate();
214

    
215
/* setup altq + pf */
216
filter_configure_sync();
217

    
218
/* start pflog */
219
echo "Starting PFLOG...";
220
filter_pflog_start();
221
echo "done.\n";
222

    
223
/* start load balancer daemon */
224
relayd_configure();
225

    
226
	/* reconfigure our gateway monitor */
227
echo "Setting up gateway monitors...";
228
	setup_gateways_monitor();
229
echo "done.\n";
230

    
231
/* start OpenVPN server & clients */
232
echo "Syncing OpenVPN settings...";
233
openvpn_resync_all();
234
echo "done.\n";
235

    
236
if($avail > 0 and $avail < 65) {
237
	echo "System has less than 65 megabytes of ram {$avail}.  Delaying webConfigurator startup.\n";
238
	/* start webConfigurator up on final pass */
239
	touch("/tmp/restart_webgui");
240
} else {
241
	/* start web server */
242
	system_webgui_start();
243
}
244

    
245
/* configure cron service */
246
echo "Configuring CRON...";
247
configure_cron();
248
echo "done.\n";
249

    
250
/* set up static routes */
251
system_routing_configure();
252

    
253
/* enable routing */
254
system_routing_enable();
255

    
256
echo "Starting Secure Shell Services...";
257
mwexec_bg("/etc/sshd");
258
echo "done.\n";
259

    
260
/* configure console menu */
261
system_console_configure();
262

    
263
/* start the NTP client */
264
echo "Starting OpenNTP time client...";
265
system_ntp_configure();
266
echo "done.\n";
267

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

    
271
/* start dyndns service */
272
services_dyndns_configure();
273

    
274
/* static IP address? -> attempt DNS update */
275
if (is_ipaddr($config['interfaces']['wan']['ipaddr']))
276
	services_dnsupdate_process();
277

    
278
/* start dnsmasq service */
279
services_dnsmasq_configure();
280

    
281
/* start DHCP relay */
282
services_dhcrelay_configure();
283

    
284
/* setup pppoe and pptp */
285
vpn_setup();
286

    
287
/* start the captive portal */
288
captiveportal_configure();
289

    
290
/* start Voucher support */
291
require_once("voucher.inc");
292
voucher_configure();
293

    
294
/* run any shell commands specified in config.xml */
295
system_do_shell_commands();
296

    
297
/* setup polling */
298
setup_polling();
299

    
300
/* setup interface microcode which improves tcp/ip speed */
301
echo "Setting up microcode and tx/rx offloading...";
302
setup_microcode();
303
echo "done.\n";
304

    
305
/* start IPsec tunnels */
306
vpn_ipsec_configure();
307

    
308
/* start SNMP service */
309
services_snmpd_configure();
310

    
311
/* power down hard drive if needed/set */
312
system_set_harddisk_standby();
313

    
314
/* lock down console if necessary */
315
if(isset($config['system']['disableconsolemenu']))
316
	touch("/var/etc/console_lockdown");
317

    
318
/* Run a filter configure now that most all services have started */
319
filter_configure_sync();
320

    
321
/* load graphing functions */
322
enable_rrd_graphing();
323

    
324
/* start DHCP service */
325
services_dhcpd_configure();
326

    
327
/* startup OLSR if needed */
328
setup_wireless_olsr();
329

    
330
/* startup routed if needed */
331
include_once("/usr/local/pkg/routed/routed.inc");
332
setup_routed();
333

    
334
/* enable watchdog if supported */
335
enable_watchdog();
336

    
337
/* if <system><afterbootupshellcmd> exists, execute the command */
338
if($config['system']['afterbootupshellcmd'] <> "") {
339
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
340
	mwexec($config['system']['afterbootupshellcmd']);
341
}
342

    
343
if($avail < 126) {
344
	require_once("/etc/inc/notices.inc");
345
	file_notice("{$g['product_name']}MemoryRequirements", "{$g['product_name']} requires atleast 128 megabytes of RAM.  Expect unusual performance.  This platform is not supported.", "Memory", "", 1);
346
	mwexec("sysctl net.inet.tcp.recvspace=4096");
347
	mwexec("sysctl net.inet.tcp.sendspace=4096");
348
}
349

    
350
/* if we are operating at 1000 then increase timeouts.
351
   this was never accounted for after moving to 1000 hz */
352
$kern_hz = `sysctl kern.clockrate | awk '{ print $5 }' | cut -d"," -f1`;
353
$kern_hz = trim($kern_hz, "\r\n");
354
if($kern_hz == "1000") 
355
	mwexec("sysctl net.inet.tcp.rexmit_min=30");
356

    
357
/* start the igmpproxy daemon */
358
services_igmpproxy_configure();
359

    
360
/* start the upnp daemon if it is enabled */
361
upnp_start();
362

    
363
/* If powerd is enabled, lets launch it */
364
activate_powerd();
365

    
366
mwexec_bg("/usr/sbin/update_dns_cache.sh");
367

    
368
/* done */
369
unlink("{$g['varrun_path']}/booting");
370
unset($g['booting']);
371

    
372
led_normalize();
373

    
374
?>
(32-32/89)