Project

General

Profile

Download (8.72 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) echo "\n{$motd}\n\n";
47
	}
48

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

    
58
	conf_mount_rw();
59

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

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

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

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

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

    
100
	echo "Cleaning backup cache...";
101
	cleanup_backupcache(true);
102
	echo "done.\n";
103

    
104
	/* read in /etc/sysctl.conf and set values if needed */
105
	echo "Setting up extended sysctls...";
106
	system_setup_sysctl();
107
	echo "done.\n";
108

    
109
	/* sync user passwords */
110
	echo "Syncing user passwords...";
111
	sync_webgui_passwords();
112
	echo "done.\n";
113

    
114
	echo "Starting Secure Shell Services...";
115
	mwexec_bg("/etc/sshd");
116
	echo "done.\n";
117

    
118
	/* run any early shell commands specified in config.xml */
119
	system_do_shell_commands(1);
120

    
121
	/* save dmesg output to file */
122
	system_dmesg_save();
123

    
124
	/* set up our timezone */
125
	system_timezone_configure();
126

    
127
	/* set up our hostname */
128
	system_hostname_configure();
129

    
130
	/* make hosts file */
131
	system_hosts_generate();
132

    
133
	/* generate resolv.conf */
134
	system_resolvconf_generate();
135

    
136
	/* configure loopback interface */
137
	interfaces_loopback_configure();
138

    
139
	/* start syslogd */
140
	system_syslogd_start();
141

    
142
	/* set up VLAN virtual interfaces */
143
	interfaces_vlan_configure();
144
	
145
	if($config['interfaces']['lan']) {
146
		/* set up LAN interface */
147
		echo "Configuring LAN interface...";
148
		mute_kernel_msgs();
149
		interfaces_lan_configure();
150
		unmute_kernel_msgs();
151
		echo "done.\n";
152
	}
153

    
154
	/* set up WAN interface */
155
	echo "Configuring WAN interface...";
156
	mute_kernel_msgs();
157
	interfaces_wan_configure();
158
	unmute_kernel_msgs();
159
	echo "done.\n";
160

    
161
	/* set up Optional interfaces */
162
	echo "Configuring OPT interfaces...";
163
	if(!$debugging)
164
		mute_kernel_msgs();
165
	interfaces_optional_configure();
166
	if(!$debugging)
167
		unmute_kernel_msgs();
168
	echo "done.\n";
169

    
170
	/* bring up carp interfaces */
171
	interfaces_carp_configure();
172

    
173
	/* generate resolv.conf */
174
	system_resolvconf_generate();
175

    
176
	/* check if the wan interface is up, this might delay upto 10 seconds */
177
	is_wan_interface_up("wan");
178

    
179
	/* Sync the system time at boot before service startup */
180
	sync_system_time();
181

    
182
	/* start pflog */
183
	filter_pflog_start();
184

    
185
	setup_filter_bridge();
186

    
187
	/* start load balancer daemon */
188
	load_balancer_use_sticky();
189
	slbd_configure();
190

    
191
	/* start OpenVPN server & clients */
192
    openvpn_resync_all();
193

    
194
	/* setup altq + pf */
195
	echo "Configuring firewall...";
196
	//mute_kernel_msgs();
197
	filter_configure_sync();
198
	//unmute_kernel_msgs();
199
	echo "done.\n";
200

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

    
210
	/* configure cron service */
211
	configure_cron();
212

    
213
	/* set up static routes */
214
	system_routing_configure();
215

    
216
	/* enable routing */
217
	system_routing_enable();
218

    
219
	/* ensure passwords are sync'd */
220
	system_password_configure();
221

    
222
	/* configure console menu */
223
	system_console_configure();
224

    
225
	/* start dyndns service */
226
	services_dyndns_configure();
227

    
228
	/* static IP address? -> attempt DNS update */
229
	if (is_ipaddr($config['interfaces']['wan']['ipaddr']))
230
		services_dnsupdate_process();
231

    
232
	/* start DHCP service */
233
	services_dhcpd_configure();
234

    
235
	/* start dnsmasq service */
236
	services_dnsmasq_configure();
237

    
238
	/* start DHCP relay */
239
	services_dhcrelay_configure();
240

    
241
	/* start proxy ARP service */
242
	services_proxyarp_configure();
243

    
244
	/* setup pppoe and pptp */
245
	vpn_setup();
246

    
247
	/* start the captive portal */
248
	captiveportal_configure();
249

    
250
	/* run any shell commands specified in config.xml */
251
	system_do_shell_commands();
252

    
253
	/* setup polling */
254
	setup_polling();
255

    
256
	/* setup interface microcode which improves tcp/ip speed */
257
	echo "Setting up microcode and tx/rx offloading...";
258
	setup_microcode();
259
	echo "done.\n";
260

    
261
	mwexec("/sbin/pfctl -f /tmp/rules.debug");
262

    
263
	/* start IPsec tunnels */
264
	vpn_ipsec_configure();
265

    
266
	/* start ftp proxy helpers if they are enabled */
267
	echo "Starting FTP helpers...";
268
	system_start_ftp_helpers();
269
	echo "done.\n";
270

    
271
	interfaces_carp_bring_up_final();
272

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

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

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

    
283
	filter_configure();
284

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

    
288
	/*   start DHCP service again now that CARP has settled
289
	 *   incase user is using primary/backup failover dhcp mode
290
         */
291
	services_dhcpd_configure();
292

    
293
	/* startup OLSR if needed */
294
	setup_wireless_olsr();
295

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

    
300
	/* enable watchdog if supported */
301
	enable_watchdog();
302

    
303
	/* start the NTP client */
304
	echo "Starting OpenNTP time client...";
305
	system_ntp_configure();
306
	echo "done.\n";
307

    
308
	/* if <system><afterbootupshellcmd> exists, execute the command */
309
	if($config['system']['afterbootupshellcmd'] <> "")
310
		mwexec($config['system']['afterbootupshellcmd']);
311

    
312
	if($avail < 126) {
313
		require_once("/etc/inc/notices.inc");
314
		file_notice("pfSenseMemoryRequirements", "pfSense requires atleast 128 megabytes of RAM.  Expect unusual performance.  This platform is not supported.", "Memory", "", 1);
315
		mwexec("sysctl net.inet.tcp.recvspace=4096");
316
		mwexec("sysctl net.inet.tcp.sendspace=4096");
317
	}
318
	
319
	/* if we are operating at 1000 then increase timeouts.
320
	   this was never accounted for after moving to 1000 hz */
321
	$kern_hz = `sysctl kern.clockrate | awk '{ print $5 }' | cut -d"," -f1`;
322
	$kern_hz = trim($kern_hz, "\r\n");
323
	if($kern_hz == "1000") 
324
		mwexec("sysctl net.inet.tcp.rexmit_min=30");
325

    
326
	upnp_start();
327

    
328
	if (isset($config['ipsec']['enable']) || isset($config['mobileclients']['enable'])) 
329
		mwexec_bg("/usr/local/sbin/racoon_watch.sh");
330

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

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

    
337
?>
(27-27/79)