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
|
require_once("globals.inc");
|
35
|
require_once("pfsense-utils.inc");
|
36
|
|
37
|
/* let the other functions know we're booting */
|
38
|
$pkg_interface = 'console';
|
39
|
$g['booting'] = TRUE;
|
40
|
touch("{$g['varrun_path']}/booting");
|
41
|
|
42
|
if($g['platform'] == "cdrom") {
|
43
|
$motd = trim(file_get_contents("/etc/motd"));
|
44
|
if(strlen($motd) > 2) echo "\n{$motd}\n\n";
|
45
|
}
|
46
|
|
47
|
/* parse the configuration and include all functions used below */
|
48
|
require_once("config.inc");
|
49
|
|
50
|
require_once("functions.inc");
|
51
|
|
52
|
/* get system memory amount */
|
53
|
$memory = get_memory();
|
54
|
$avail = $memory[0];
|
55
|
|
56
|
/* start devd (dhclient now uses it */
|
57
|
echo "Starting device manager (devd)... ";
|
58
|
mute_kernel_msgs();
|
59
|
start_devd();
|
60
|
set_device_perms();
|
61
|
unmute_kernel_msgs();
|
62
|
echo "done.\n";
|
63
|
|
64
|
echo "Loading configuration... ";
|
65
|
parse_config_bootup();
|
66
|
echo "done.\n";
|
67
|
|
68
|
$lan_if = $config['interfaces']['lan']['if'];
|
69
|
$wan_if = get_real_wan_interface();
|
70
|
|
71
|
/*
|
72
|
* Determine if we need to throw a interface exception
|
73
|
* and ask the user to reassign interfaces. This will
|
74
|
* avoid a reboot and thats a good thing.
|
75
|
*/
|
76
|
$do_assign = 0;
|
77
|
/* we need to ignore the vlan interface checks) */
|
78
|
if(stristr($lan_if,"vlan") == false and stristr($wan_if,"vlan") == false) {
|
79
|
if(does_interface_exist($lan_if) == false) {
|
80
|
echo "\n\n\nLAN {$lan_if} interface mismatch.";
|
81
|
$do_assign = 1;
|
82
|
}
|
83
|
if($config['interfaces']['wan']['ipaddr'] <> "pppoe" && $config['interfaces']['wan']['ipaddr'] <> "pptp" && $do_assign == 0) {
|
84
|
if(does_interface_exist($wan_if) == false) {
|
85
|
echo "\n\n\nWAN {$wan_if} interface mismatch.";
|
86
|
$do_assign = 1;
|
87
|
}
|
88
|
}
|
89
|
if($do_assign == 1 and !file_exists("{$g['tmp_path']}/assign_complete")) {
|
90
|
$noreboot = true;
|
91
|
echo " -- Running interface assignment option.\n";
|
92
|
set_networking_interfaces_ports();
|
93
|
}
|
94
|
}
|
95
|
unmute_kernel_msgs();
|
96
|
|
97
|
/* convert config and clean backups */
|
98
|
echo "Updating configuration... ";
|
99
|
convert_config();
|
100
|
echo "done.\n";
|
101
|
|
102
|
echo "Cleaning backup cache... ";
|
103
|
cleanup_backupcache(true);
|
104
|
echo "done.\n";
|
105
|
|
106
|
/* read in /etc/sysctl.conf and set values if needed */
|
107
|
echo "Setting up extended sysctls... ";
|
108
|
system_setup_sysctl();
|
109
|
echo "done.\n";
|
110
|
|
111
|
/* sync user passwords */
|
112
|
echo "Syncing user passwords... ";
|
113
|
sync_webgui_passwords();
|
114
|
echo "done.\n";
|
115
|
|
116
|
echo "Starting Secure Shell Services... ";
|
117
|
mwexec_bg("/etc/sshd");
|
118
|
echo "done.\n";
|
119
|
|
120
|
/* run any early shell commands specified in config.xml */
|
121
|
system_do_shell_commands(1);
|
122
|
|
123
|
/* save dmesg output to file */
|
124
|
system_dmesg_save();
|
125
|
|
126
|
/* set up our timezone */
|
127
|
system_timezone_configure();
|
128
|
|
129
|
/* set up our hostname */
|
130
|
system_hostname_configure();
|
131
|
|
132
|
/* make hosts file */
|
133
|
system_hosts_generate();
|
134
|
|
135
|
/* generate resolv.conf */
|
136
|
system_resolvconf_generate();
|
137
|
|
138
|
/* configure loopback interface */
|
139
|
interfaces_loopback_configure();
|
140
|
|
141
|
/* start syslogd */
|
142
|
system_syslogd_start();
|
143
|
|
144
|
/* set up VLAN virtual interfaces */
|
145
|
interfaces_vlan_configure();
|
146
|
|
147
|
/* set up LAN interface */
|
148
|
echo "Configuring LAN interface... ";
|
149
|
mute_kernel_msgs();
|
150
|
interfaces_lan_configure();
|
151
|
unmute_kernel_msgs();
|
152
|
echo "done.\n";
|
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
|
/* start pflog */
|
177
|
filter_pflog_start();
|
178
|
|
179
|
setup_filter_bridge();
|
180
|
|
181
|
/* start load balancer daemon */
|
182
|
slbd_configure();
|
183
|
|
184
|
/* start OpenVPN server & clients */
|
185
|
openvpn_resync_all();
|
186
|
|
187
|
/* setup altq + pf */
|
188
|
echo "Configuring firewall... ";
|
189
|
//mute_kernel_msgs();
|
190
|
filter_configure_sync();
|
191
|
//unmute_kernel_msgs();
|
192
|
echo "done.\n";
|
193
|
|
194
|
if($avail > 0 and $avail < 65) {
|
195
|
echo "System has less than 65 megabytes of ram {$avail}. Delaying webConfigurator startup.\n";
|
196
|
/* start webConfigurator up on final pass */
|
197
|
touch("/tmp/restart_webgui");
|
198
|
} else {
|
199
|
/* start web server */
|
200
|
system_webgui_start();
|
201
|
}
|
202
|
|
203
|
/* set up static routes */
|
204
|
system_routing_configure();
|
205
|
|
206
|
/* enable routing */
|
207
|
system_routing_enable();
|
208
|
|
209
|
/* ensure passwords are sync'd */
|
210
|
system_password_configure();
|
211
|
|
212
|
/* configure console menu */
|
213
|
system_console_configure();
|
214
|
|
215
|
/* start dnsmasq service */
|
216
|
services_dnsmasq_configure();
|
217
|
|
218
|
/* start dyndns service */
|
219
|
services_dyndns_configure();
|
220
|
|
221
|
/* static IP address? -> attempt DNS update */
|
222
|
if (is_ipaddr($config['interfaces']['wan']['ipaddr']))
|
223
|
services_dnsupdate_process();
|
224
|
|
225
|
/* start DHCP service */
|
226
|
services_dhcpd_configure();
|
227
|
|
228
|
/* start DHCP relay */
|
229
|
services_dhcrelay_configure();
|
230
|
|
231
|
/* start proxy ARP service */
|
232
|
services_proxyarp_configure();
|
233
|
|
234
|
/* start the NTP client */
|
235
|
system_ntp_configure();
|
236
|
|
237
|
/* setup pppoe and pptp */
|
238
|
vpn_setup();
|
239
|
|
240
|
/* start the captive portal */
|
241
|
captiveportal_configure();
|
242
|
|
243
|
/* run any shell commands specified in config.xml */
|
244
|
system_do_shell_commands();
|
245
|
|
246
|
/* setup polling */
|
247
|
setup_polling();
|
248
|
|
249
|
/* setup interface microcode which improves tcp/ip speed */
|
250
|
echo "Setting up microcode and tx/rx offloading... ";
|
251
|
setup_microcode();
|
252
|
echo "done.\n";
|
253
|
|
254
|
mwexec("/sbin/pfctl -f /tmp/rules.debug");
|
255
|
|
256
|
/* start IPsec tunnels */
|
257
|
vpn_ipsec_configure();
|
258
|
|
259
|
/* start ftp proxy helpers if they are enabled */
|
260
|
echo "Starting FTP helpers... ";
|
261
|
system_start_ftp_helpers();
|
262
|
echo "done.\n";
|
263
|
|
264
|
interfaces_carp_bring_up_final();
|
265
|
|
266
|
/* start SNMP service */
|
267
|
services_snmpd_configure();
|
268
|
|
269
|
/* power down hard drive if needed/set */
|
270
|
system_set_harddisk_standby();
|
271
|
|
272
|
/* lock down console if necessary */
|
273
|
if(isset($config['system']['disableconsolemenu']))
|
274
|
touch("/var/etc/console_lockdown");
|
275
|
|
276
|
filter_configure();
|
277
|
|
278
|
/* load graphing functions */
|
279
|
enable_rrd_graphing();
|
280
|
|
281
|
/* start DHCP service again now that CARP has settled
|
282
|
* incase user is using primary/backup failover dhcp mode
|
283
|
*/
|
284
|
services_dhcpd_configure();
|
285
|
|
286
|
/* startup OLSR if needed */
|
287
|
setup_wireless_olsr();
|
288
|
|
289
|
/* enable watchdog if supported */
|
290
|
enable_watchdog();
|
291
|
|
292
|
/* done */
|
293
|
unlink("{$g['varrun_path']}/booting");
|
294
|
$g['booting'] = FALSE;
|
295
|
|
296
|
?>
|