Project

General

Profile

Download (8.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) 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
	/* setup php.ini */
77
	opcode_cache_configuration();
78

    
79
	$lan_if = $config['interfaces']['lan']['if'];
80
	$wan_if = get_real_wan_interface();
81

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

    
103
	echo "Cleaning backup cache...";
104
	cleanup_backupcache(true);
105
	echo "done.\n";
106

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

    
112
	/* sync user passwords */
113
	echo "Syncing user passwords...";
114
	sync_webgui_passwords();
115
	echo "done.\n";
116

    
117
	echo "Starting Secure Shell Services...";
118
	mwexec_bg("/etc/sshd");
119
	echo "done.\n";
120

    
121
	/* run any early shell commands specified in config.xml */
122
	system_do_shell_commands(1);
123

    
124
	/* save dmesg output to file */
125
	system_dmesg_save();
126

    
127
	/* set up our timezone */
128
	system_timezone_configure();
129

    
130
	/* set up our hostname */
131
	system_hostname_configure();
132

    
133
	/* make hosts file */
134
	system_hosts_generate();
135

    
136
	/* generate resolv.conf */
137
	system_resolvconf_generate();
138

    
139
	/* configure loopback interface */
140
	interfaces_loopback_configure();
141

    
142
	/* start syslogd */
143
	system_syslogd_start();
144

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

    
157
	/* set up WAN interface */
158
	echo "Configuring WAN interface...";
159
	mute_kernel_msgs();
160
	interfaces_wan_configure();
161
	unmute_kernel_msgs();
162
	echo "done.\n";
163

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

    
173
	/* bring up carp interfaces */
174
	interfaces_carp_configure();
175

    
176
	/* generate resolv.conf */
177
	system_resolvconf_generate();
178

    
179
	/* check if the wan interface is up, this might delay upto 10 seconds */
180
	is_wan_interface_up("wan");
181

    
182
	/* Sync the system time at boot before service startup */
183
	sync_system_time();
184

    
185
	/* start pflog */
186
	filter_pflog_start();
187

    
188
	setup_filter_bridge();
189

    
190
	/* start load balancer daemon */
191
	load_balancer_use_sticky();
192
	slbd_configure();
193

    
194
	/* start OpenVPN server & clients */
195
    openvpn_resync_all();
196

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

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

    
213
	/* configure cron service */
214
	configure_cron();
215

    
216
	/* set up static routes */
217
	system_routing_configure();
218

    
219
	/* enable routing */
220
	system_routing_enable();
221

    
222
	/* ensure passwords are sync'd */
223
	system_password_configure();
224

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

    
228
	/* start dyndns service */
229
	services_dyndns_configure();
230

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

    
235
	/* start DHCP service */
236
	services_dhcpd_configure();
237

    
238
	/* start dnsmasq service */
239
	services_dnsmasq_configure();
240

    
241
	/* start DHCP relay */
242
	services_dhcrelay_configure();
243

    
244
	/* start proxy ARP service */
245
	services_proxyarp_configure();
246

    
247
	/* setup pppoe and pptp */
248
	vpn_setup();
249

    
250
	/* start the captive portal */
251
	captiveportal_configure();
252

    
253
	/* run any shell commands specified in config.xml */
254
	system_do_shell_commands();
255

    
256
	/* setup polling */
257
	setup_polling();
258

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

    
264
	mwexec("/sbin/pfctl -f /tmp/rules.debug");
265

    
266
	/* start IPsec tunnels */
267
	vpn_ipsec_configure();
268

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

    
274
	interfaces_carp_bring_up_final();
275

    
276
	/* start SNMP service */
277
	services_snmpd_configure();
278

    
279
	/* power down hard drive if needed/set */
280
	system_set_harddisk_standby();
281

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

    
286
	filter_configure();
287

    
288
	/* load graphing functions */
289
	enable_rrd_graphing();
290

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

    
296
	/* startup OLSR if needed */
297
	setup_wireless_olsr();
298

    
299
	/* startup routed if needed */
300
	include_once("/usr/local/pkg/routed/routed.inc");
301
	setup_routed();
302

    
303
	/* enable watchdog if supported */
304
	enable_watchdog();
305

    
306
	/* start the NTP client */
307
	echo "Starting OpenNTP time client...";
308
	system_ntp_configure();
309
	echo "done.\n";
310

    
311
	/* if <system><afterbootupshellcmd> exists, execute the command */
312
	if($config['system']['afterbootupshellcmd'] <> "")
313
		mwexec($config['system']['afterbootupshellcmd']);
314

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

    
329
	upnp_start();
330

    
331
	if (isset($config['ipsec']['enable']) || isset($config['mobileclients']['enable'])) 
332
		mwexec_bg("/usr/local/sbin/racoon_watch.sh");
333

    
334
	mwexec_bg("/usr/sbin/update_dns_cache.sh");
335

    
336
	/* done */
337
	unlink("{$g['varrun_path']}/booting");
338
	$g['booting'] = FALSE;
339

    
340
?>
(27-27/79)