Project

General

Profile

Download (9.78 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

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

    
121
/* get system memory amount */
122
$memory = get_memory();
123
$avail = $memory[0];
124
echo " done.\n";
125

    
126
conf_mount_rw();
127

    
128
/* remove previous firmware upgrade if present */
129
if (file_exists("/root/firmware.tgz")) 
130
	unlink("/root/firmware.tgz");
131

    
132
/* start devd (dhclient now uses it */
133
echo "Starting device manager (devd)...";
134
mute_kernel_msgs();
135
start_devd();
136
set_device_perms();
137
unmute_kernel_msgs();
138
echo "done.\n";
139

    
140
// Display rescue configuration option
141
if($g['platform'] == "cdrom") 
142
		rescue_detect_keypress();
143

    
144
echo "Loading configuration...";
145
parse_config_bootup();
146
echo "done.\n";
147

    
148
$lan_if = $config['interfaces']['lan']['if'];
149
$wan_if = get_real_interface();
150

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

    
162
/* convert config and clean backups */
163
echo "Updating configuration...";
164
convert_config();
165
echo "done.\n";
166

    
167
echo "Cleaning backup cache...";
168
cleanup_backupcache(true);
169
echo "done.\n";
170

    
171
/* read in /etc/sysctl.conf and set values if needed */
172
echo "Setting up extended sysctls...";
173
system_setup_sysctl();
174
echo "done.\n";
175

    
176
/* enable glxsb if wanted */
177
load_glxsb();
178

    
179
/* run any early shell commands specified in config.xml */
180
system_do_shell_commands(1);
181

    
182
/* save dmesg output to file */
183
system_dmesg_save();
184

    
185
/* set up our timezone */
186
system_timezone_configure();
187

    
188
/* set up our hostname */
189
system_hostname_configure();
190

    
191
/* make hosts file */
192
system_hosts_generate();
193

    
194
/* configure loopback interface */
195
interfaces_loopback_configure();
196

    
197
/* start syslogd */
198
system_syslogd_start();
199

    
200
/* set up interfaces */
201
if(!$debugging)
202
	mute_kernel_msgs();
203
interfaces_configure();
204
if(!$debugging)
205
	unmute_kernel_msgs();
206

    
207
/* generate resolv.conf */
208
system_resolvconf_generate();
209

    
210
/* setup altq + pf */
211
filter_configure_sync();
212

    
213
/* start pflog */
214
echo "Starting PFLOG...";
215
filter_pflog_start();
216
echo "done.\n";
217

    
218
/* start load balancer daemon */
219
relayd_configure();
220

    
221
	/* reconfigure our gateway monitor */
222
echo "Setting up gateway monitors...";
223
	setup_gateways_monitor();
224
echo "done.\n";
225

    
226
/* start OpenVPN server & clients */
227
echo "Syncing OpenVPN settings...";
228
openvpn_resync_all();
229
echo "done.\n";
230

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

    
240
/* configure cron service */
241
echo "Configuring CRON...";
242
configure_cron();
243
echo "done.\n";
244

    
245
/* set up static routes */
246
system_routing_configure();
247

    
248
/* enable routing */
249
system_routing_enable();
250

    
251
echo "Starting Secure Shell Services...";
252
mwexec_bg("/etc/sshd");
253
echo "done.\n";
254

    
255
/* configure console menu */
256
system_console_configure();
257

    
258
/* start the NTP client */
259
echo "Starting OpenNTP time client...";
260
system_ntp_configure();
261
echo "done.\n";
262

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

    
266
/* start dyndns service */
267
services_dyndns_configure();
268

    
269
/* static IP address? -> attempt DNS update */
270
if (is_ipaddr($config['interfaces']['wan']['ipaddr']))
271
	services_dnsupdate_process();
272

    
273
/* start dnsmasq service */
274
services_dnsmasq_configure();
275

    
276
/* start DHCP relay */
277
services_dhcrelay_configure();
278

    
279
/* setup pppoe and pptp */
280
vpn_setup();
281

    
282
/* start the captive portal */
283
captiveportal_configure();
284

    
285
/* start Voucher support */
286
require_once("voucher.inc");
287
voucher_configure();
288

    
289
/* run any shell commands specified in config.xml */
290
system_do_shell_commands();
291

    
292
/* setup polling */
293
setup_polling();
294

    
295
/* setup interface microcode which improves tcp/ip speed */
296
echo "Setting up microcode and tx/rx offloading...";
297
setup_microcode();
298
echo "done.\n";
299

    
300
/* start IPsec tunnels */
301
vpn_ipsec_configure();
302

    
303
/* start SNMP service */
304
services_snmpd_configure();
305

    
306
/* power down hard drive if needed/set */
307
system_set_harddisk_standby();
308

    
309
/* lock down console if necessary */
310
if(isset($config['system']['disableconsolemenu'])) {
311
	auto_login(false);
312
} else {
313
	auto_login(true);
314
}
315

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

    
319
/* load graphing functions */
320
enable_rrd_graphing();
321

    
322
/* start DHCP service */
323
services_dhcpd_configure();
324

    
325
/* startup OLSR if needed */
326
setup_wireless_olsr();
327

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

    
332
/* enable watchdog if supported */
333
enable_watchdog();
334

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

    
341
if($avail < 126) {
342
	require_once("/etc/inc/notices.inc");
343
	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);
344
	mwexec("sysctl net.inet.tcp.recvspace=4096");
345
	mwexec("sysctl net.inet.tcp.sendspace=4096");
346
}
347

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

    
355
/* start the igmpproxy daemon */
356
services_igmpproxy_configure();
357

    
358
/* start the upnp daemon if it is enabled */
359
upnp_start();
360

    
361
/* If powerd is enabled, lets launch it */
362
activate_powerd();
363

    
364
mwexec_bg("/usr/sbin/update_dns_cache.sh");
365

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

    
370
led_normalize();
371

    
372
?>
(32-32/89)