Project

General

Profile

Download (9.07 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=4;
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 "Recovery mode can assist by rescuing config.xml\n";
42
	echo "from a broken hard disk installation, etc.\n\n";
43
	echo "Alternatively the installer 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
	while(!in_array($key, array("r","R"))) {
48
	        echo " {$timeout}";
49
	        `/bin/stty -icanon min 0 time 25`;
50
	        $key = trim(`KEY=\`dd count=1 2>/dev/null\`; echo \$KEY`);
51
	        `/bin/stty icanon`;
52
	        // Decrement our timeout value
53
	        $timeout--;
54
	        // If we have reached 0 exit and continue on
55
	        if ($timeout == 0) 
56
				break;
57
	}
58
	// If R or I was pressed do our logic here
59
	if (in_array($key, array("r", "R"))) {
60
	  system("env TERM=cons25 /bin/tcsh -c /scripts/lua_installer_rescue");
61
	} elseif (in_array($key, array("i", "I"))) {
62
	  system("env TERM=cons25 /bin/tcsh -c /scripts/lua_installer");
63
	  if(file_exists("/tmp/install_complete")) {
64
		system("/etc/rc.reboot");
65
		exit;
66
	  }
67
	} elseif (in_array($key, array("!", "~"))) {
68
		echo "\n";
69
		touch("/tmp/donotbootup");
70
		exit;
71
	}
72
}
73

    
74
echo " done.\n";
75

    
76
echo "Initializing...";
77
echo ".";
78
require_once("/etc/inc/globals.inc");
79
echo ".";
80
/* let the other functions know we're booting */
81
$pkg_interface = 'console';
82
$g['booting'] = TRUE;
83
touch("{$g['varrun_path']}/booting");
84
if($g['platform'] == "cdrom") {
85
	$motd = trim(file_get_contents("/etc/motd"));
86
	if (strlen($motd) > 2) 
87
		echo "\n{$motd}\n\n";
88
}
89

    
90
/* parse the configuration and include all functions used below */
91
require_once("/etc/inc/config.inc");
92
echo ".";
93
require_once("/etc/inc/functions.inc");
94
/* get system memory amount */
95
$memory = get_memory();
96
$avail = $memory[0];
97
echo " done.\n";
98

    
99
conf_mount_rw();
100

    
101
/* remove previous firmware upgrade if present */
102
if (file_exists("/root/firmware.tgz")) 
103
	unlink("/root/firmware.tgz");
104

    
105
/* start devd (dhclient now uses it */
106
echo "Starting device manager (devd)...";
107
mute_kernel_msgs();
108
start_devd();
109
set_device_perms();
110
unmute_kernel_msgs();
111
echo "done.\n";
112

    
113
// Display rescue configuration option
114
if($g['platform'] == "cdrom") 
115
		rescue_detect_keypress();
116

    
117
echo "Loading configuration...";
118
parse_config_bootup();
119
echo "done.\n";
120

    
121
$lan_if = $config['interfaces']['lan']['if'];
122
$wan_if = get_real_interface();
123

    
124
/*
125
 *  Determine if we need to throw a interface exception
126
 *  and ask the user to reassign interfaces.  This will
127
 *  avoid a reboot and thats a good thing.
128
 */
129
unmute_kernel_msgs();
130
while(is_interface_mismatch() == true) {
131
	echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
132
	set_networking_interfaces_ports();
133
}
134

    
135
/* convert config and clean backups */
136
echo "Updating configuration...";
137
convert_config();
138
echo "done.\n";
139

    
140
echo "Cleaning backup cache...";
141
cleanup_backupcache(true);
142
echo "done.\n";
143

    
144
/* read in /etc/sysctl.conf and set values if needed */
145
echo "Setting up extended sysctls...";
146
system_setup_sysctl();
147
echo "done.\n";
148

    
149
echo "Starting Secure Shell Services...";
150
mwexec_bg("/etc/sshd");
151
echo "done.\n";
152

    
153
/* run any early shell commands specified in config.xml */
154
system_do_shell_commands(1);
155

    
156
/* save dmesg output to file */
157
system_dmesg_save();
158

    
159
/* set up our timezone */
160
system_timezone_configure();
161

    
162
/* set up our hostname */
163
system_hostname_configure();
164

    
165
/* make hosts file */
166
system_hosts_generate();
167

    
168
/* configure loopback interface */
169
interfaces_loopback_configure();
170

    
171
/* start syslogd */
172
system_syslogd_start();
173

    
174
/* set up interfaces */
175
if(!$debugging)
176
	mute_kernel_msgs();
177
interfaces_configure();
178
if(!$debugging)
179
	unmute_kernel_msgs();
180

    
181
/* setup altq + pf */
182
filter_configure_sync();
183

    
184
/* generate resolv.conf */
185
system_resolvconf_generate();
186

    
187
/* start pflog */
188
echo "Starting PFLOG...";
189
filter_pflog_start();
190
echo "done.\n";
191

    
192
/* start load balancer daemon */
193
relayd_configure();
194

    
195
	/* reconfigure our gateway monitor */
196
echo "Setting up gateway monitors...";
197
	setup_gateways_monitor();
198
echo "done.\n";
199

    
200
/* start OpenVPN server & clients */
201
echo "Syncing OpenVPN settings...";
202
openvpn_resync_all();
203
echo "done.\n";
204

    
205
if($avail > 0 and $avail < 65) {
206
	echo "System has less than 65 megabytes of ram {$avail}.  Delaying webConfigurator startup.\n";
207
	/* start webConfigurator up on final pass */
208
	touch("/tmp/restart_webgui");
209
} else {
210
	/* start web server */
211
	system_webgui_start();
212
}
213

    
214
/* configure cron service */
215
echo "Configuring CRON...";
216
configure_cron();
217
echo "done.\n";
218

    
219
/* set up static routes */
220
system_routing_configure();
221

    
222
/* enable routing */
223
system_routing_enable();
224

    
225
/* configure console menu */
226
system_console_configure();
227

    
228
/* start the NTP client */
229
echo "Starting OpenNTP time client...";
230
system_ntp_configure();
231
echo "done.\n";
232

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

    
236
/* start dyndns service */
237
services_dyndns_configure();
238

    
239
/* static IP address? -> attempt DNS update */
240
if (is_ipaddr($config['interfaces']['wan']['ipaddr']))
241
	services_dnsupdate_process();
242

    
243
/* start dnsmasq service */
244
services_dnsmasq_configure();
245

    
246
/* start DHCP relay */
247
services_dhcrelay_configure();
248

    
249
/* start proxy ARP service */
250
services_proxyarp_configure();
251

    
252
/* setup pppoe and pptp */
253
vpn_setup();
254

    
255
/* start the captive portal */
256
captiveportal_configure();
257

    
258
/* run any shell commands specified in config.xml */
259
system_do_shell_commands();
260

    
261
/* setup polling */
262
setup_polling();
263

    
264
/* setup interface microcode which improves tcp/ip speed */
265
echo "Setting up microcode and tx/rx offloading...";
266
setup_microcode();
267
echo "done.\n";
268

    
269
/* start IPsec tunnels */
270
vpn_ipsec_configure();
271

    
272
/* start SNMP service */
273
services_snmpd_configure();
274

    
275
/* power down hard drive if needed/set */
276
system_set_harddisk_standby();
277

    
278
/* lock down console if necessary */
279
if(isset($config['system']['disableconsolemenu']))
280
	touch("/var/etc/console_lockdown");
281

    
282
/* Run a filter configure now that most all services have started */
283
filter_configure_sync();
284

    
285
/* load graphing functions */
286
enable_rrd_graphing();
287

    
288
/* start DHCP service */
289
services_dhcpd_configure();
290

    
291
/* startup OLSR if needed */
292
setup_wireless_olsr();
293

    
294
/* startup routed if needed */
295
include_once("/usr/local/pkg/routed/routed.inc");
296
setup_routed();
297

    
298
/* enable watchdog if supported */
299
enable_watchdog();
300

    
301
/* if <system><afterbootupshellcmd> exists, execute the command */
302
if($config['system']['afterbootupshellcmd'] <> "") {
303
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
304
	mwexec($config['system']['afterbootupshellcmd']);
305
}
306

    
307
if($avail < 126) {
308
	require_once("/etc/inc/notices.inc");
309
	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);
310
	mwexec("sysctl net.inet.tcp.recvspace=4096");
311
	mwexec("sysctl net.inet.tcp.sendspace=4096");
312
}
313

    
314
/* if we are operating at 1000 then increase timeouts.
315
   this was never accounted for after moving to 1000 hz */
316
$kern_hz = `sysctl kern.clockrate | awk '{ print $5 }' | cut -d"," -f1`;
317
$kern_hz = trim($kern_hz, "\r\n");
318
if($kern_hz == "1000") 
319
	mwexec("sysctl net.inet.tcp.rexmit_min=30");
320

    
321
/* start the igmpproxy daemon
322
services_igmpproxy_configure();
323

    
324
/* start the upnp daemon if it is enabled */
325
upnp_start();
326

    
327
/* If powerd is enabled, lets launch it */
328
activate_powerd();
329

    
330
mwexec_bg("/usr/sbin/update_dns_cache.sh");
331

    
332
/* done */
333
unlink("{$g['varrun_path']}/booting");
334
$g['booting'] = FALSE;
335

    
336
?>
(32-32/85)