Project

General

Profile

Download (8.51 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
	unmute_kernel_msgs();
83
	/*
84
	 *   Determine if we need to throw a interface exception
85
	 *   and ask the user to reassign interfaces.  This will
86
	 *   avoid a reboot and thats a good thing.
87
	 */
88
	while(is_interface_mismatch() == true) {
89
		echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
90
		set_networking_interfaces_ports();
91
	}
92

    
93
	/* convert config and clean backups */
94
	echo "Updating configuration...";
95
	convert_config();
96
	echo "done.\n";
97

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

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

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

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

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

    
119
	/* save dmesg output to file */
120
	system_dmesg_save();
121

    
122
	/* set up our timezone */
123
	system_timezone_configure();
124

    
125
	/* set up our hostname */
126
	system_hostname_configure();
127

    
128
	/* make hosts file */
129
	system_hosts_generate();
130

    
131
	/* generate resolv.conf */
132
	system_resolvconf_generate();
133

    
134
	/* configure loopback interface */
135
	interfaces_loopback_configure();
136

    
137
	/* start syslogd */
138
	system_syslogd_start();
139

    
140
	/* set up VLAN virtual interfaces */
141
	interfaces_vlan_configure();
142

    
143
	/* set up LAN interface */
144
	echo "Configuring LAN interface...";
145
	mute_kernel_msgs();
146
	interfaces_lan_configure();
147
	unmute_kernel_msgs();
148
	echo "done.\n";
149

    
150
	/* set up WAN interface */
151
	echo "Configuring WAN interface...";
152
	mute_kernel_msgs();
153
	interfaces_wan_configure();
154
	unmute_kernel_msgs();
155
	echo "done.\n";
156

    
157
	/* set up Optional interfaces */
158
	echo "Configuring OPT interfaces...";
159
	if(!$debugging)
160
		mute_kernel_msgs();
161
	interfaces_optional_configure();
162
	if(!$debugging)
163
		unmute_kernel_msgs();
164
	echo "done.\n";
165

    
166
	/* bring up carp interfaces */
167
	interfaces_carp_configure();
168

    
169
	/* generate resolv.conf */
170
	system_resolvconf_generate();
171

    
172
	/* check if the wan interface is up, this might delay upto 10 seconds */
173
	is_wan_interface_up("wan");
174

    
175
	/* Sync the system time at boot before service startup */
176
	sync_system_time();
177

    
178
	/* start pflog */
179
	filter_pflog_start();
180

    
181
	setup_filter_bridge();
182

    
183
	/* start load balancer daemon */
184
	load_balancer_use_sticky();
185
	slbd_configure();
186

    
187
	/* start OpenVPN server & clients */
188
    openvpn_resync_all();
189

    
190
	/* setup altq + pf */
191
	echo "Configuring firewall...";
192
	//mute_kernel_msgs();
193
	filter_configure_sync();
194
	//unmute_kernel_msgs();
195
	echo "done.\n";
196

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

    
206
	/* configure cron service */
207
	configure_cron();
208

    
209
	/* set up static routes */
210
	system_routing_configure();
211

    
212
	/* enable routing */
213
	system_routing_enable();
214

    
215
	/* ensure passwords are sync'd */
216
	system_password_configure();
217

    
218
	/* configure console menu */
219
	system_console_configure();
220

    
221
	/* start DHCP service */
222
	services_dhcpd_configure();
223

    
224
	/* start dnsmasq service */
225
	services_dnsmasq_configure();
226

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

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

    
234
	/* start DHCP relay */
235
	services_dhcrelay_configure();
236

    
237
	/* start proxy ARP service */
238
	services_proxyarp_configure();
239

    
240
	/* setup pppoe and pptp */
241
	vpn_setup();
242

    
243
	/* start the captive portal */
244
	captiveportal_configure();
245

    
246
	/* run any shell commands specified in config.xml */
247
	system_do_shell_commands();
248

    
249
	/* setup polling */
250
	setup_polling();
251

    
252
	/* setup interface microcode which improves tcp/ip speed */
253
	echo "Setting up microcode and tx/rx offloading...";
254
	setup_microcode();
255
	echo "done.\n";
256

    
257
	mwexec("/sbin/pfctl -f /tmp/rules.debug");
258

    
259
	/* start IPsec tunnels */
260
	vpn_ipsec_configure();
261

    
262
	/* start ftp proxy helpers if they are enabled */
263
	echo "Starting FTP helpers...";
264
	system_start_ftp_helpers();
265
	echo "done.\n";
266

    
267
	interfaces_carp_bring_up_final();
268

    
269
	/* start SNMP service */
270
	services_snmpd_configure();
271

    
272
	/* power down hard drive if needed/set */
273
	system_set_harddisk_standby();
274

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

    
279
	filter_configure();
280

    
281
	/* load graphing functions */
282
	enable_rrd_graphing();
283

    
284
	/*   start DHCP service again now that CARP has settled
285
	 *   incase user is using primary/backup failover dhcp mode
286
         */
287
	services_dhcpd_configure();
288

    
289
	/* startup OLSR if needed */
290
	setup_wireless_olsr();
291

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

    
296
	/* enable watchdog if supported */
297
	enable_watchdog();
298

    
299
	/* start the NTP client */
300
	echo "Starting OpenNTP time client...";
301
	system_ntp_configure();
302
	echo "done.\n";
303

    
304
	/* if <system><afterbootupshellcmd> exists, execute the command */
305
	if($config['system']['afterbootupshellcmd'] <> "")
306
		mwexec($config['system']['afterbootupshellcmd']);
307

    
308
	if($avail < 126) {
309
		require_once("/etc/inc/notices.inc");
310
		file_notice("pfSenseMemoryRequirements", "pfSense requires atleast 128 megabytes of RAM.  Expect unusual performance.  This platform is not supported.", "Memory", "", 1);
311
		mwexec("sysctl net.inet.tcp.recvspace=4096");
312
		mwexec("sysctl net.inet.tcp.sendspace=4096");
313
	}
314

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

    
322
	upnp_start();
323

    
324
	if (isset($config['ipsec']['enable']) || isset($config['mobileclients']['enable'])) 
325
		mwexec_bg("/usr/local/sbin/racoon_watch.sh");
326

    
327
	/* done */
328
	unlink("{$g['varrun_path']}/booting");
329
	$g['booting'] = FALSE;
330

    
331
?>
(27-27/78)