summaryrefslogtreecommitdiffstats
path: root/etc/rc.bootup
blob: 64362bf14d7b716be74ec49536dd9ae489d23f18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#!/usr/local/bin/php -f
<?php
/* $Id$ */
/*
	rc.bootup
	part of pfSense by Scott Ullrich
	originally based on m0n0wall (http://m0n0.ch/wall)

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

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

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

	2. Redistributions in binary form must reproduce the above copyright
	   notice, this list of conditions and the following disclaimer in the
	   documentation and/or other materials provided with the distribution.

	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
	POSSIBILITY OF SUCH DAMAGE.
*/

	echo " done.\n";

	echo "Initializing...";
	echo ".";
	require_once("/etc/inc/globals.inc");
	echo ".";
	/* let the other functions know we're booting */
	$pkg_interface = 'console';
	$g['booting'] = TRUE;
	touch("{$g['varrun_path']}/booting");
	if($g['platform'] == "cdrom") {
		$motd = trim(file_get_contents("/etc/motd"));
		if(strlen($motd) > 2) echo "\n{$motd}\n\n";
	}

	/* parse the configuration and include all functions used below */
	require_once("/etc/inc/config.inc");
	echo ".";
	require_once("/etc/inc/functions.inc");
	/* get system memory amount */
	$memory = get_memory();
	$avail = $memory[0];
	echo " done.\n";

	/* start devd (dhclient now uses it */
	echo "Starting device manager (devd)...";
	mute_kernel_msgs();
	start_devd();
	set_device_perms();
	unmute_kernel_msgs();
	echo "done.\n";

	echo "Loading configuration...";
	parse_config_bootup();
	echo "done.\n";

	/* setup php.ini */
	opcode_cache_configuration();

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

	/*
	 *  Determine if we need to throw a interface exception
     *  and ask the user to reassign interfaces.  This will
     *  avoid a reboot and thats a good thing.
	 */
	unmute_kernel_msgs();
	/*
	 *   Determine if we need to throw a interface exception
	 *   and ask the user to reassign interfaces.  This will
	 *   avoid a reboot and thats a good thing.
	 */
	while(is_interface_mismatch() == true) {
		echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
		set_networking_interfaces_ports();
	}
	
	/* convert config and clean backups */
	echo "Updating configuration...";
	convert_config();
	echo "done.\n";

	echo "Cleaning backup cache...";
	cleanup_backupcache(true);
	echo "done.\n";

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

	/* sync user passwords */
	echo "Syncing user passwords...";
	sync_webgui_passwords();
	echo "done.\n";

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

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

	/* save dmesg output to file */
	system_dmesg_save();

	/* set up our timezone */
	system_timezone_configure();

	/* set up our hostname */
	system_hostname_configure();

	/* make hosts file */
	system_hosts_generate();

	/* generate resolv.conf */
	system_resolvconf_generate();

	/* configure loopback interface */
	interfaces_loopback_configure();

	/* start syslogd */
	system_syslogd_start();

	/* set up VLAN virtual interfaces */
	interfaces_vlan_configure();

	/* set up LAN interface */
	echo "Configuring LAN interface...";
	mute_kernel_msgs();
	interfaces_lan_configure();
	unmute_kernel_msgs();
	echo "done.\n";

	/* set up WAN interface */
	echo "Configuring WAN interface...";
	mute_kernel_msgs();
	interfaces_wan_configure();
	unmute_kernel_msgs();
	echo "done.\n";

	/* set up Optional interfaces */
	echo "Configuring OPT interfaces...";
	if(!$debugging)
		mute_kernel_msgs();
	interfaces_optional_configure();
	if(!$debugging)
		unmute_kernel_msgs();
	echo "done.\n";

	/* bring up carp interfaces */
	interfaces_carp_configure();

	/* generate resolv.conf */
	system_resolvconf_generate();

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

	/* start pflog */
	filter_pflog_start();

	setup_filter_bridge();

	/* start load balancer daemon */
	slbd_configure();

	/* start OpenVPN server & clients */
    openvpn_resync_all();

	/* setup altq + pf */
	echo "Configuring firewall...";
	//mute_kernel_msgs();
	filter_configure_sync();
	//unmute_kernel_msgs();
	echo "done.\n";

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

	/* configure cron service */
	configure_cron();

	/* set up static routes */
	system_routing_configure();

	/* enable routing */
	system_routing_enable();

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

	/* configure console menu */
	system_console_configure();

	/* start dnsmasq service */
	services_dnsmasq_configure();

	/* start dyndns service */
	services_dyndns_configure();

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

	/* start DHCP service */
	services_dhcpd_configure();

	/* start DHCP relay */
	services_dhcrelay_configure();

	/* start proxy ARP service */
	services_proxyarp_configure();

	/* setup pppoe and pptp */
	vpn_setup();

	/* start the captive portal */
	captiveportal_configure();

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

	/* setup polling */
	setup_polling();

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

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

	/* start IPsec tunnels */
	vpn_ipsec_configure();

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

	interfaces_carp_bring_up_final();

	/* start SNMP service */
	services_snmpd_configure();

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

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

	filter_configure();

	/* load graphing functions */
	enable_rrd_graphing();

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

	/* startup OLSR if needed */
	setup_wireless_olsr();

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

	/* enable watchdog if supported */
	enable_watchdog();

	/* start the NTP client */
	echo "Starting OpenNTP time client...";
	system_ntp_configure();
	echo "done.\n";

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

	if($avail < 126) {
		require_once("/etc/inc/notices.inc");
		file_notice("pfSenseMemoryRequirements", "pfSense requires atleast 128 megabytes of RAM.  Expect unusual performance.  This platform is not supported.", "Memory", "", 1);
	}

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

?>
OpenPOWER on IntegriCloud