Project

General

Profile

Download (10.2 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php -f
2
<?php
3 1b8df11b Bill Marquette
/* $Id$ */
4 5b237745 Scott Ullrich
/*
5
	rc.bootup
6 e5cd29a0 Scott Ullrich
	part of pfSense by Scott Ullrich
7
	originally based on m0n0wall (http://m0n0.ch/wall)
8
9 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11 e5cd29a0 Scott Ullrich
12 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14 e5cd29a0 Scott Ullrich
15 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17 e5cd29a0 Scott Ullrich
18 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21 e5cd29a0 Scott Ullrich
22 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33
34 c224dd9d Scott Ullrich
function rescue_detect_keypress() {
35
	// How long do you want the script to wait before moving on (in seconds)
36
	$timeout=9;
37
	echo "\n";
38
    echo "[ Press R to enter recovery mode or ]\n";
39
	echo "[  press I to launch the installer  ]\n\n";
40
	echo "(R)ecovery mode can assist by rescuing config.xml\n";
41
	echo "from a broken hard disk installation, etc.\n\n";
42
	echo "Alternatively the (I)nstaller may be invoked now if you do \n";
43
	echo "not wish to boot into the liveCD environment at this time.\n\n";
44
	echo "Timeout before auto boot continues (seconds): {$timeout}";
45
	$key = null;
46
	exec("/bin/stty erase " . chr(8));
47
	while(!in_array($key, array("r","R", "i", "I", "~", "!"))) {
48
	        echo chr(8) . "{$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
	  putenv("TERM=cons25");
61
	  echo "\n\nRecovery mode selected...\n";
62
	  passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer_rescue");
63
	} elseif (in_array($key, array("i", "I"))) {
64
	  putenv("TERM=cons25");  
65
	  echo "\n\nInstaller mode selected...\n";
66
	  passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer");
67
	  if(file_exists("/tmp/install_complete")) {
68
		passthru("/etc/rc.reboot");
69
		exit;
70
	  }
71
	} elseif (in_array($key, array("!", "~"))) {
72
 		putenv("TERM=cons25");
73
		echo "\n\nRecovery shell selected...\n";
74
		echo "\n";
75
		touch("/tmp/donotbootup");
76
		exit;
77
	} else {
78
		echo "\n\n";
79
	}
80
}
81
82 d0e94aaf Scott Ullrich
	echo " done.\n";
83
	echo "Initializing...";
84
	echo ".";
85 4bee8672 Scott Ullrich
	require_once("/etc/inc/globals.inc");
86 d0e94aaf Scott Ullrich
	echo ".";
87 a164b0ca Scott Ullrich
	/* let the other functions know we're booting */
88
	$pkg_interface = 'console';
89
	$g['booting'] = TRUE;
90
	touch("{$g['varrun_path']}/booting");
91 2c35ed91 Scott Ullrich
	if($g['platform'] == "cdrom") {
92 7822d966 Colin Smith
		$motd = trim(file_get_contents("/etc/motd"));
93 2c35ed91 Scott Ullrich
		if(strlen($motd) > 2) echo "\n{$motd}\n\n";
94
	}
95 5f89728d Scott Ullrich
96 5b237745 Scott Ullrich
	/* parse the configuration and include all functions used below */
97 4bee8672 Scott Ullrich
	require_once("/etc/inc/config.inc");
98 d0e94aaf Scott Ullrich
	echo ".";
99 4bee8672 Scott Ullrich
	require_once("/etc/inc/functions.inc");
100 a6abbd66 Scott Ullrich
	/* get system memory amount */
101
	$memory = get_memory();
102
	$avail = $memory[0];
103 d0e94aaf Scott Ullrich
	echo " done.\n";
104 e5cd29a0 Scott Ullrich
105 7c26341a Scott Ullrich
	conf_mount_rw();
106
107
	/* remove previous firmware upgrade if present */
108
	if(file_exists("/root/firmware.tgz")) 
109 d5d5feec Scott Ullrich
		unlink("/root/firmware.tgz");
110 7c26341a Scott Ullrich
111 86ddbb71 Scott Ullrich
	/* start devd (dhclient now uses it */
112 f05740c1 Scott Ullrich
	echo "Starting device manager (devd)...";
113 70b89814 Scott Ullrich
	mute_kernel_msgs();
114 86ddbb71 Scott Ullrich
	start_devd();
115 09b949e1 Scott Ullrich
	set_device_perms();
116 70b89814 Scott Ullrich
	unmute_kernel_msgs();
117 86ddbb71 Scott Ullrich
	echo "done.\n";
118
119 c224dd9d Scott Ullrich
	// Display rescue configuration option
120
	if($g['platform'] == "cdrom") 
121
			rescue_detect_keypress();
122
123 f05740c1 Scott Ullrich
	echo "Loading configuration...";
124 b6f3f5c6 Colin Smith
	parse_config_bootup();
125 74dbce1f Scott Ullrich
	echo "done.\n";
126 b6f3f5c6 Colin Smith
127 a164b0ca Scott Ullrich
	/* setup php.ini */
128
	opcode_cache_configuration();
129
130 afde8c22 Scott Ullrich
	$lan_if = $config['interfaces']['lan']['if'];
131 aa01f2f2 Scott Ullrich
	$wan_if = get_real_wan_interface();
132
133 914a762d Scott Ullrich
	unmute_kernel_msgs();
134 28d38aa4 Scott Ullrich
	/*
135 914a762d Scott Ullrich
	 *   Determine if we need to throw a interface exception
136
	 *   and ask the user to reassign interfaces.  This will
137
	 *   avoid a reboot and thats a good thing.
138 28d38aa4 Scott Ullrich
	 */
139 914a762d Scott Ullrich
	while(is_interface_mismatch() == true) {
140
		echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
141
		set_networking_interfaces_ports();
142 6ee4c02f Scott Ullrich
	}
143 aa01f2f2 Scott Ullrich
144 d6f1dbe3 Colin Smith
	/* convert config and clean backups */
145 f05740c1 Scott Ullrich
	echo "Updating configuration...";
146 5b237745 Scott Ullrich
	convert_config();
147 74dbce1f Scott Ullrich
	echo "done.\n";
148 bad59dd6 Colin Smith
149 f05740c1 Scott Ullrich
	echo "Cleaning backup cache...";
150 d6f1dbe3 Colin Smith
	cleanup_backupcache(true);
151 74dbce1f Scott Ullrich
	echo "done.\n";
152 f6bed300 Chris Buechler
	
153
	/* load glxsb unless it's disabled */
154
	setup_glxsb();
155 d0e94aaf Scott Ullrich
156 3ff9d424 Scott Ullrich
	/* read in /etc/sysctl.conf and set values if needed */
157 f05740c1 Scott Ullrich
	echo "Setting up extended sysctls...";
158 3ff9d424 Scott Ullrich
	system_setup_sysctl();
159 92e2deb7 Scott Ullrich
	echo "done.\n";
160 3ff9d424 Scott Ullrich
161 88b63d7c Scott Ullrich
	/* sync user passwords */
162 f05740c1 Scott Ullrich
	echo "Syncing user passwords...";
163 88b63d7c Scott Ullrich
	sync_webgui_passwords();
164 92e2deb7 Scott Ullrich
	echo "done.\n";
165 88b63d7c Scott Ullrich
166 f05740c1 Scott Ullrich
	echo "Starting Secure Shell Services...";
167 beaff8b0 Scott Ullrich
	mwexec_bg("/etc/sshd");
168
	echo "done.\n";
169
170 5b237745 Scott Ullrich
	/* run any early shell commands specified in config.xml */
171
	system_do_shell_commands(1);
172 e5cd29a0 Scott Ullrich
173 5b237745 Scott Ullrich
	/* save dmesg output to file */
174
	system_dmesg_save();
175 e5cd29a0 Scott Ullrich
176 b8e0d152 Scott Ullrich
	/* generate resolv.conf */
177
	system_resolvconf_generate();
178
179 5b237745 Scott Ullrich
	/* set up our timezone */
180
	system_timezone_configure();
181 e5cd29a0 Scott Ullrich
182 5b237745 Scott Ullrich
	/* set up our hostname */
183
	system_hostname_configure();
184 e5cd29a0 Scott Ullrich
185 5b237745 Scott Ullrich
	/* make hosts file */
186
	system_hosts_generate();
187 e5cd29a0 Scott Ullrich
188 5b237745 Scott Ullrich
	/* configure loopback interface */
189
	interfaces_loopback_configure();
190 e5cd29a0 Scott Ullrich
191 9490c282 Chris Buechler
	/* set up VLAN virtual interfaces */
192
	interfaces_vlan_configure();
193
194 19ee38b4 Chris Buechler
	/* setup interface microcode which improves tcp/ip speed */
195
	echo "Setting up microcode and tx/rx offloading...";
196
	setup_microcode();
197
	echo "done.\n";
198
199 5b237745 Scott Ullrich
	/* set up LAN interface */
200 f05740c1 Scott Ullrich
	echo "Configuring LAN interface...";
201 dd2ab8f8 Scott Ullrich
	mute_kernel_msgs();
202 5b237745 Scott Ullrich
	interfaces_lan_configure();
203 dd2ab8f8 Scott Ullrich
	unmute_kernel_msgs();
204 74dbce1f Scott Ullrich
	echo "done.\n";
205 e5cd29a0 Scott Ullrich
206 5b237745 Scott Ullrich
	/* set up WAN interface */
207 f05740c1 Scott Ullrich
	echo "Configuring WAN interface...";
208 dd2ab8f8 Scott Ullrich
	mute_kernel_msgs();
209 5b237745 Scott Ullrich
	interfaces_wan_configure();
210 dd2ab8f8 Scott Ullrich
	unmute_kernel_msgs();
211 74dbce1f Scott Ullrich
	echo "done.\n";
212 e5cd29a0 Scott Ullrich
213 5b237745 Scott Ullrich
	/* set up Optional interfaces */
214 f05740c1 Scott Ullrich
	echo "Configuring OPT interfaces...";
215 e556dea7 Scott Ullrich
	if(!$debugging)
216
		mute_kernel_msgs();
217 5b237745 Scott Ullrich
	interfaces_optional_configure();
218 d0e94aaf Scott Ullrich
	if(!$debugging)
219 e556dea7 Scott Ullrich
		unmute_kernel_msgs();
220 74dbce1f Scott Ullrich
	echo "done.\n";
221 dd2ab8f8 Scott Ullrich
222 ae723ece Scott Ullrich
	/* bring up carp interfaces */
223
	interfaces_carp_configure();
224
225 f99cd0a7 sullrich
	/* start syslogd - needs to be after LAN bringup. */
226
	system_syslogd_start();
227
228 3a89b8d9 Scott Ullrich
	/* generate resolv.conf */
229
	system_resolvconf_generate();
230
231 4f46cd86 Scott Ullrich
	/* start the NTP client */
232
	echo "Starting OpenNTP time client...";
233
	system_ntp_configure();
234
	echo "done.\n";
235
236 fbc6ad95 Scott Ullrich
	/* Launch on bootup and keep trying to sync.  Exit once time/date has been sync'd. */
237
	mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh");
238 baf9fab2 Seth Mos
239 24d15c0c Scott Ullrich
	/* start pflog */
240
	filter_pflog_start();
241 3962b070 Scott Ullrich
242 ab34f4ec Scott Ullrich
	/* start load balancer daemon */
243 ab0d0394 Scott Ullrich
	load_balancer_use_sticky();
244 ab34f4ec Scott Ullrich
	slbd_configure();
245 12c09555 Scott Ullrich
246
	/* start OpenVPN server & clients */
247 19ee38b4 Chris Buechler
	openvpn_resync_all();
248 d0e94aaf Scott Ullrich
249 24d15c0c Scott Ullrich
	/* setup altq + pf */
250 cb74ffd5 Scott Ullrich
	echo "Configuring firewall...";
251 1c872736 Scott Ullrich
	//mute_kernel_msgs();
252 4e6f9d37 Scott Ullrich
	filter_configure_sync();
253 1c872736 Scott Ullrich
	//unmute_kernel_msgs();
254 74dbce1f Scott Ullrich
	echo "done.\n";
255 e5cd29a0 Scott Ullrich
256 a6abbd66 Scott Ullrich
	if($avail > 0 and $avail < 65) {
257 bd042586 Scott Ullrich
		echo "System has less than 65 megabytes of ram {$avail}.  Delaying webConfigurator startup.\n";
258 a6abbd66 Scott Ullrich
		/* start webConfigurator up on final pass */
259
		touch("/tmp/restart_webgui");
260
	} else {
261
		/* start web server */
262
		system_webgui_start();
263
	}
264 d0e94aaf Scott Ullrich
265 1071e028 Scott Ullrich
	/* configure cron service */
266
	configure_cron();
267
268 5b237745 Scott Ullrich
	/* set up static routes */
269
	system_routing_configure();
270 e5cd29a0 Scott Ullrich
271 5b237745 Scott Ullrich
	/* enable routing */
272
	system_routing_enable();
273 d0e94aaf Scott Ullrich
274 fb453a4a Scott Ullrich
	/* ensure passwords are sync'd */
275
	system_password_configure();
276 e5cd29a0 Scott Ullrich
277 5b237745 Scott Ullrich
	/* configure console menu */
278
	system_console_configure();
279 e5cd29a0 Scott Ullrich
280 c71e7398 Scott Ullrich
	/* start DHCP service */
281
	services_dhcpd_configure();
282
283 5b237745 Scott Ullrich
	/* start dnsmasq service */
284
	services_dnsmasq_configure();
285 e5cd29a0 Scott Ullrich
286 5b237745 Scott Ullrich
	/* start dyndns service */
287
	services_dyndns_configure();
288 d0e94aaf Scott Ullrich
289 5ffb18e0 Scott Ullrich
	/* static IP address? -> attempt DNS update */
290
	if (is_ipaddr($config['interfaces']['wan']['ipaddr']))
291
		services_dnsupdate_process();
292 e5cd29a0 Scott Ullrich
293 5ffb18e0 Scott Ullrich
	/* start DHCP relay */
294
	services_dhcrelay_configure();
295
296 5b237745 Scott Ullrich
	/* start proxy ARP service */
297
	services_proxyarp_configure();
298
299 88964924 Scott Ullrich
	/* setup pppoe and pptp */
300
	vpn_setup();
301 3d941d72 Scott Ullrich
302 5b237745 Scott Ullrich
	/* start the captive portal */
303
	captiveportal_configure();
304 e5cd29a0 Scott Ullrich
305 5b237745 Scott Ullrich
	/* run any shell commands specified in config.xml */
306
	system_do_shell_commands();
307 e5cd29a0 Scott Ullrich
308 562fca6d Scott Ullrich
	/* setup polling */
309
	setup_polling();
310
311 11e2c67c Scott Ullrich
	mwexec("/sbin/pfctl -f /tmp/rules.debug");
312 d0e94aaf Scott Ullrich
313 31eb6cb7 Chris Buechler
	interfaces_carp_bring_up_final();
314
315 11c32d4a Scott Ullrich
	/* start IPsec tunnels */
316 11e2c67c Scott Ullrich
	vpn_ipsec_configure();
317 c6e604d8 Scott Ullrich
318 154349f9 Scott Ullrich
	/* start ftp proxy helpers if they are enabled */
319 f05740c1 Scott Ullrich
	echo "Starting FTP helpers...";
320 154349f9 Scott Ullrich
	system_start_ftp_helpers();
321
	echo "done.\n";
322
323 f4959a69 Scott Ullrich
	/* start SNMP service */
324
	services_snmpd_configure();
325
326 9f966bc9 Scott Ullrich
	/* power down hard drive if needed/set */
327 11e2c67c Scott Ullrich
	system_set_harddisk_standby();
328 9f966bc9 Scott Ullrich
329 ce9e67ce Scott Ullrich
	/* lock down console if necessary */
330
	if(isset($config['system']['disableconsolemenu']))
331
		touch("/var/etc/console_lockdown");
332 f4959a69 Scott Ullrich
333 9d6ce77f Scott Ullrich
	echo "Final filter pass...";
334 31eb6cb7 Chris Buechler
	filter_configure_sync();
335 9d6ce77f Scott Ullrich
	echo "done.\n";
336 d0e94aaf Scott Ullrich
337 f0842feb Scott Ullrich
	/* load graphing functions */
338 d0e94aaf Scott Ullrich
	enable_rrd_graphing();
339 1e19b3b4 Scott Ullrich
340
	/*   start DHCP service again now that CARP has settled
341
	 *   incase user is using primary/backup failover dhcp mode
342 bcc84d48 sullrich
	 */
343 1e19b3b4 Scott Ullrich
	services_dhcpd_configure();
344 a199b93e Scott Ullrich
345 11cbd478 Scott Ullrich
	/* startup OLSR if needed */
346
	setup_wireless_olsr();
347
348 011bff69 Bill Marquette
	/* startup routed if needed */
349
	include_once("/usr/local/pkg/routed/routed.inc");
350
	setup_routed();
351
352 6d80ad3a Scott Ullrich
	/* if <system><afterbootupshellcmd> exists, execute the command */
353
	if($config['system']['afterbootupshellcmd'] <> "")
354
		mwexec($config['system']['afterbootupshellcmd']);
355
356 bcc84d48 sullrich
	if($avail < 121) {
357 4bee8672 Scott Ullrich
		require_once("/etc/inc/notices.inc");
358 d5fc8ff4 Scott Ullrich
		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);
359 3b3978e8 Scott Ullrich
		mwexec("sysctl net.inet.tcp.recvspace=4096");
360
		mwexec("sysctl net.inet.tcp.sendspace=4096");
361 c108ec01 Scott Ullrich
	}
362
363 c126316b Scott Ullrich
	/* if we are operating at 1000 then increase timeouts.
364
	   this was never accounted for after moving to 1000 hz */
365
	$kern_hz = `sysctl kern.clockrate | awk '{ print $5 }' | cut -d"," -f1`;
366
	$kern_hz = trim($kern_hz, "\r\n");
367 a074233d Scott Ullrich
	if($kern_hz == "1000") 
368 c126316b Scott Ullrich
		mwexec("sysctl net.inet.tcp.rexmit_min=30");
369
370 f7c2ef28 Scott Ullrich
	upnp_start();
371
372 5b237745 Scott Ullrich
	/* done */
373
	unlink("{$g['varrun_path']}/booting");
374 b66cf573 Scott Ullrich
	unset($g['booting']);
375 5c60c947 Scott Ullrich
376 fbc6ad95 Scott Ullrich
?>