Project

General

Profile

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

    
9
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	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

    
22
	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
	echo " done.\n";
35

    
36
	echo "Initializing...";
37
	echo ".";
38
	require_once("/etc/inc/globals.inc");
39
	echo ".";
40
	/* let the other functions know we're booting */
41
	$pkg_interface = 'console';
42
	$g['booting'] = TRUE;
43
	touch("{$g['varrun_path']}/booting");
44
	if($g['platform'] == "cdrom") {
45
		$motd = trim(file_get_contents("/etc/motd"));
46
		if (strlen($motd) > 2) 
47
			echo "\n{$motd}\n\n";
48
	}
49

    
50
	/* parse the configuration and include all functions used below */
51
	require_once("/etc/inc/config.inc");
52
	echo ".";
53
	require_once("/etc/inc/functions.inc");
54
	/* get system memory amount */
55
	$memory = get_memory();
56
	$avail = $memory[0];
57
	echo " done.\n";
58

    
59
	conf_mount_rw();
60

    
61
	/* remove previous firmware upgrade if present */
62
	if (file_exists("/root/firmware.tgz")) 
63
		unlink("/root/firmware.tgz");
64

    
65
	/* start devd (dhclient now uses it */
66
	echo "Starting device manager (devd)...";
67
	mute_kernel_msgs();
68
	start_devd();
69
	set_device_perms();
70
	unmute_kernel_msgs();
71
	echo "done.\n";
72

    
73
	echo "Loading configuration...";
74
	parse_config_bootup();
75
	echo "done.\n";
76

    
77
	$lan_if = $config['interfaces']['lan']['if'];
78
	$wan_if = get_real_interface();
79

    
80
	/*
81
	 *  Determine if we need to throw a interface exception
82
	 *  and ask the user to reassign interfaces.  This will
83
	 *  avoid a reboot and thats a good thing.
84
	 */
85
	unmute_kernel_msgs();
86
	while(is_interface_mismatch() == true) {
87
		echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
88
		set_networking_interfaces_ports();
89
	}
90
	
91
	/* convert config and clean backups */
92
	echo "Updating configuration...";
93
	convert_config();
94
	echo "done.\n";
95

    
96
	echo "Cleaning backup cache...";
97
	cleanup_backupcache(true);
98
	echo "done.\n";
99

    
100
	/* read in /etc/sysctl.conf and set values if needed */
101
	echo "Setting up extended sysctls...";
102
	system_setup_sysctl();
103
	echo "done.\n";
104

    
105
	echo "Starting Secure Shell Services...";
106
	mwexec_bg("/etc/sshd");
107
	echo "done.\n";
108

    
109
	/* run any early shell commands specified in config.xml */
110
	system_do_shell_commands(1);
111

    
112
	/* save dmesg output to file */
113
	system_dmesg_save();
114

    
115
	/* set up our timezone */
116
	system_timezone_configure();
117

    
118
	/* set up our hostname */
119
	system_hostname_configure();
120

    
121
	/* make hosts file */
122
	system_hosts_generate();
123

    
124
	/* configure loopback interface */
125
	interfaces_loopback_configure();
126

    
127
	/* start syslogd */
128
	system_syslogd_start();
129

    
130
	/* set up interfaces */
131
	if(!$debugging)
132
		mute_kernel_msgs();
133
	interfaces_configure();
134
	if(!$debugging)
135
		unmute_kernel_msgs();
136

    
137
	/* setup altq + pf */
138
	filter_configure_sync();
139

    
140
	/* generate resolv.conf */
141
	system_resolvconf_generate();
142

    
143
	/* start pflog */
144
	echo "Starting PFLOG...";
145
	filter_pflog_start();
146
	echo "done.\n";
147

    
148
	/* start load balancer daemon */
149
	relayd_configure();
150

    
151
 	/* reconfigure our gateway monitor */
152
	echo "Setting up gateway monitors...";
153
 	setup_gateways_monitor();
154
	echo "done.\n";
155

    
156
	/* start OpenVPN server & clients */
157
	echo "Syncing OpenVPN settings...";
158
	openvpn_resync_all();
159
	echo "done.\n";
160

    
161
	if($avail > 0 and $avail < 65) {
162
		echo "System has less than 65 megabytes of ram {$avail}.  Delaying webConfigurator startup.\n";
163
		/* start webConfigurator up on final pass */
164
		touch("/tmp/restart_webgui");
165
	} else {
166
		/* start web server */
167
		system_webgui_start();
168
	}
169

    
170
	/* configure cron service */
171
	echo "Configuring CRON...";
172
	configure_cron();
173
	echo "done.\n";
174
	
175
	/* set up static routes */
176
	system_routing_configure();
177

    
178
	/* enable routing */
179
	system_routing_enable();
180

    
181
	/* configure console menu */
182
	system_console_configure();
183

    
184
	/* start the NTP client */
185
	echo "Starting OpenNTP time client...";
186
	system_ntp_configure();
187
	echo "done.\n";
188

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

    
192
	/* start dyndns service */
193
	services_dyndns_configure();
194

    
195
	/* static IP address? -> attempt DNS update */
196
	if (is_ipaddr($config['interfaces']['wan']['ipaddr']))
197
		services_dnsupdate_process();
198

    
199
	/* start dnsmasq service */
200
	services_dnsmasq_configure();
201

    
202
	/* start DHCP relay */
203
	services_dhcrelay_configure();
204

    
205
	/* start proxy ARP service */
206
	services_proxyarp_configure();
207

    
208
	/* setup pppoe and pptp */
209
	vpn_setup();
210

    
211
	/* start the captive portal */
212
	captiveportal_configure();
213

    
214
	/* run any shell commands specified in config.xml */
215
	system_do_shell_commands();
216

    
217
	/* setup polling */
218
	setup_polling();
219

    
220
	/* setup interface microcode which improves tcp/ip speed */
221
	echo "Setting up microcode and tx/rx offloading...";
222
	setup_microcode();
223
	echo "done.\n";
224

    
225
	/* start IPsec tunnels */
226
	vpn_ipsec_configure();
227

    
228
	/* start ftp proxy helpers if they are enabled */
229
	echo "Starting FTP helpers...";
230
	system_start_ftp_helpers();
231
	echo "done.\n";
232

    
233
	/* start SNMP service */
234
	services_snmpd_configure();
235

    
236
	/* power down hard drive if needed/set */
237
	system_set_harddisk_standby();
238

    
239
	/* lock down console if necessary */
240
	if(isset($config['system']['disableconsolemenu']))
241
		touch("/var/etc/console_lockdown");
242

    
243
	/* Run a filter configure now that most all services have started */
244
	filter_configure_sync();
245

    
246
	/* load graphing functions */
247
	enable_rrd_graphing();
248
	
249
	/* start DHCP service */
250
	services_dhcpd_configure();
251

    
252
	/* startup OLSR if needed */
253
	setup_wireless_olsr();
254

    
255
	/* startup routed if needed */
256
	include_once("/usr/local/pkg/routed/routed.inc");
257
	setup_routed();
258

    
259
	/* enable watchdog if supported */
260
	enable_watchdog();
261

    
262
	/* if <system><afterbootupshellcmd> exists, execute the command */
263
	if($config['system']['afterbootupshellcmd'] <> "") {
264
		echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
265
		mwexec($config['system']['afterbootupshellcmd']);
266
	}
267

    
268
	if($avail < 126) {
269
		require_once("/etc/inc/notices.inc");
270
		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);
271
		mwexec("sysctl net.inet.tcp.recvspace=4096");
272
		mwexec("sysctl net.inet.tcp.sendspace=4096");
273
	}
274
	
275
	/* if we are operating at 1000 then increase timeouts.
276
	   this was never accounted for after moving to 1000 hz */
277
	$kern_hz = `sysctl kern.clockrate | awk '{ print $5 }' | cut -d"," -f1`;
278
	$kern_hz = trim($kern_hz, "\r\n");
279
	if($kern_hz == "1000") 
280
		mwexec("sysctl net.inet.tcp.rexmit_min=30");
281

    
282
	/* start the igmpproxy daemon
283
	services_igmpproxy_configure();
284

    
285
	/* start the upnp daemon if it is enabled */
286
	upnp_start();
287

    
288
	mwexec_bg("/usr/sbin/update_dns_cache.sh");
289

    
290
	/* done */
291
	unlink("{$g['varrun_path']}/booting");
292
	$g['booting'] = FALSE;
293

    
294
?>
(32-32/84)