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
|
function rescue_detect_keypress() {
|
35
|
// How long do you want the script to wait before moving on (in seconds)
|
36
|
$timeout=9;
|
37
|
echo "\n";
|
38
|
echo "[ Press R to enter recovery mode or ]\n";
|
39
|
echo "[ press I to launch the installer ]\n\n";
|
40
|
echo "(R)ecovery mode can assist by rescuing config.xml\n";
|
41
|
echo "from a broken hard disk installation, etc.\n\n";
|
42
|
echo "Alternatively the (I)nstaller may be invoked now if you do \n";
|
43
|
echo "not wish to boot into the liveCD environment at this time.\n\n";
|
44
|
echo "Timeout before auto boot continues (seconds): {$timeout}";
|
45
|
$key = null;
|
46
|
exec("/bin/stty erase " . chr(8));
|
47
|
while(!in_array($key, array("r","R", "i", "I", "~", "!"))) {
|
48
|
echo chr(8) . "{$timeout}";
|
49
|
`/bin/stty -icanon min 0 time 25`;
|
50
|
$key = trim(`KEY=\`dd count=1 2>/dev/null\`; echo \$KEY`);
|
51
|
`/bin/stty icanon`;
|
52
|
// Decrement our timeout value
|
53
|
$timeout--;
|
54
|
// If we have reached 0 exit and continue on
|
55
|
if ($timeout == 0)
|
56
|
break;
|
57
|
}
|
58
|
// If R or I was pressed do our logic here
|
59
|
if (in_array($key, array("r", "R"))) {
|
60
|
putenv("TERM=cons25");
|
61
|
echo "\n\nRecovery mode selected...\n";
|
62
|
passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer_rescue");
|
63
|
} elseif (in_array($key, array("i", "I"))) {
|
64
|
putenv("TERM=cons25");
|
65
|
echo "\n\nInstaller mode selected...\n";
|
66
|
passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer");
|
67
|
if(file_exists("/tmp/install_complete")) {
|
68
|
passthru("/etc/rc.reboot");
|
69
|
exit;
|
70
|
}
|
71
|
} elseif (in_array($key, array("!", "~"))) {
|
72
|
putenv("TERM=cons25");
|
73
|
echo "\n\nRecovery shell selected...\n";
|
74
|
echo "\n";
|
75
|
touch("/tmp/donotbootup");
|
76
|
exit;
|
77
|
} else {
|
78
|
echo "\n\n";
|
79
|
}
|
80
|
}
|
81
|
|
82
|
echo " done.\n";
|
83
|
echo "Initializing...";
|
84
|
echo ".";
|
85
|
require_once("/etc/inc/globals.inc");
|
86
|
echo ".";
|
87
|
/* let the other functions know we're booting */
|
88
|
$pkg_interface = 'console';
|
89
|
$g['booting'] = TRUE;
|
90
|
touch("{$g['varrun_path']}/booting");
|
91
|
if($g['platform'] == "cdrom") {
|
92
|
$motd = trim(file_get_contents("/etc/motd"));
|
93
|
if(strlen($motd) > 2) echo "\n{$motd}\n\n";
|
94
|
}
|
95
|
|
96
|
/* parse the configuration and include all functions used below */
|
97
|
require_once("/etc/inc/config.inc");
|
98
|
echo ".";
|
99
|
require_once("/etc/inc/functions.inc");
|
100
|
/* get system memory amount */
|
101
|
$memory = get_memory();
|
102
|
$avail = $memory[0];
|
103
|
echo " done.\n";
|
104
|
|
105
|
conf_mount_rw();
|
106
|
|
107
|
/* remove previous firmware upgrade if present */
|
108
|
if(file_exists("/root/firmware.tgz"))
|
109
|
unlink("/root/firmware.tgz");
|
110
|
|
111
|
/* start devd (dhclient now uses it */
|
112
|
echo "Starting device manager (devd)...";
|
113
|
mute_kernel_msgs();
|
114
|
start_devd();
|
115
|
set_device_perms();
|
116
|
unmute_kernel_msgs();
|
117
|
echo "done.\n";
|
118
|
|
119
|
// Display rescue configuration option
|
120
|
if($g['platform'] == "cdrom")
|
121
|
rescue_detect_keypress();
|
122
|
|
123
|
echo "Loading configuration...";
|
124
|
parse_config_bootup();
|
125
|
echo "done.\n";
|
126
|
|
127
|
/* setup php.ini */
|
128
|
opcode_cache_configuration();
|
129
|
|
130
|
$lan_if = $config['interfaces']['lan']['if'];
|
131
|
$wan_if = get_real_wan_interface();
|
132
|
|
133
|
unmute_kernel_msgs();
|
134
|
/*
|
135
|
* Determine if we need to throw a interface exception
|
136
|
* and ask the user to reassign interfaces. This will
|
137
|
* avoid a reboot and thats a good thing.
|
138
|
*/
|
139
|
while(is_interface_mismatch() == true) {
|
140
|
echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
|
141
|
set_networking_interfaces_ports();
|
142
|
}
|
143
|
|
144
|
/* convert config and clean backups */
|
145
|
echo "Updating configuration...";
|
146
|
convert_config();
|
147
|
echo "done.\n";
|
148
|
|
149
|
echo "Cleaning backup cache...";
|
150
|
cleanup_backupcache(true);
|
151
|
echo "done.\n";
|
152
|
|
153
|
/* load glxsb unless it's disabled */
|
154
|
setup_glxsb();
|
155
|
|
156
|
/* read in /etc/sysctl.conf and set values if needed */
|
157
|
echo "Setting up extended sysctls...";
|
158
|
system_setup_sysctl();
|
159
|
echo "done.\n";
|
160
|
|
161
|
/* sync user passwords */
|
162
|
echo "Syncing user passwords...";
|
163
|
sync_webgui_passwords();
|
164
|
echo "done.\n";
|
165
|
|
166
|
echo "Starting Secure Shell Services...";
|
167
|
mwexec_bg("/etc/sshd");
|
168
|
echo "done.\n";
|
169
|
|
170
|
/* run any early shell commands specified in config.xml */
|
171
|
system_do_shell_commands(1);
|
172
|
|
173
|
/* save dmesg output to file */
|
174
|
system_dmesg_save();
|
175
|
|
176
|
/* generate resolv.conf */
|
177
|
system_resolvconf_generate();
|
178
|
|
179
|
/* set up our timezone */
|
180
|
system_timezone_configure();
|
181
|
|
182
|
/* set up our hostname */
|
183
|
system_hostname_configure();
|
184
|
|
185
|
/* make hosts file */
|
186
|
system_hosts_generate();
|
187
|
|
188
|
/* configure loopback interface */
|
189
|
interfaces_loopback_configure();
|
190
|
|
191
|
/* set up VLAN virtual interfaces */
|
192
|
interfaces_vlan_configure();
|
193
|
|
194
|
/* setup interface microcode which improves tcp/ip speed */
|
195
|
echo "Setting up microcode and tx/rx offloading...";
|
196
|
setup_microcode();
|
197
|
echo "done.\n";
|
198
|
|
199
|
/* set up LAN interface */
|
200
|
echo "Configuring LAN interface...";
|
201
|
mute_kernel_msgs();
|
202
|
interfaces_lan_configure();
|
203
|
unmute_kernel_msgs();
|
204
|
echo "done.\n";
|
205
|
|
206
|
/* set up WAN interface */
|
207
|
echo "Configuring WAN interface...";
|
208
|
mute_kernel_msgs();
|
209
|
interfaces_wan_configure();
|
210
|
unmute_kernel_msgs();
|
211
|
echo "done.\n";
|
212
|
|
213
|
/* set up Optional interfaces */
|
214
|
echo "Configuring OPT interfaces...";
|
215
|
if(!$debugging)
|
216
|
mute_kernel_msgs();
|
217
|
interfaces_optional_configure();
|
218
|
if(!$debugging)
|
219
|
unmute_kernel_msgs();
|
220
|
echo "done.\n";
|
221
|
|
222
|
/* bring up carp interfaces */
|
223
|
interfaces_carp_configure();
|
224
|
|
225
|
/* start syslogd - needs to be after LAN bringup. */
|
226
|
system_syslogd_start();
|
227
|
|
228
|
/* generate resolv.conf */
|
229
|
system_resolvconf_generate();
|
230
|
|
231
|
/* start the NTP client */
|
232
|
echo "Starting OpenNTP time client...";
|
233
|
system_ntp_configure();
|
234
|
echo "done.\n";
|
235
|
|
236
|
/* Launch on bootup and keep trying to sync. Exit once time/date has been sync'd. */
|
237
|
mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh");
|
238
|
|
239
|
/* start pflog */
|
240
|
filter_pflog_start();
|
241
|
|
242
|
/* start load balancer daemon */
|
243
|
load_balancer_use_sticky();
|
244
|
slbd_configure();
|
245
|
|
246
|
/* start OpenVPN server & clients */
|
247
|
openvpn_resync_all();
|
248
|
|
249
|
/* setup altq + pf */
|
250
|
echo "Configuring firewall...";
|
251
|
//mute_kernel_msgs();
|
252
|
filter_configure_sync();
|
253
|
//unmute_kernel_msgs();
|
254
|
echo "done.\n";
|
255
|
|
256
|
if($avail > 0 and $avail < 65) {
|
257
|
echo "System has less than 65 megabytes of ram {$avail}. Delaying webConfigurator startup.\n";
|
258
|
/* start webConfigurator up on final pass */
|
259
|
touch("/tmp/restart_webgui");
|
260
|
} else {
|
261
|
/* start web server */
|
262
|
system_webgui_start();
|
263
|
}
|
264
|
|
265
|
/* configure cron service */
|
266
|
configure_cron();
|
267
|
|
268
|
/* set up static routes */
|
269
|
system_routing_configure();
|
270
|
|
271
|
/* enable routing */
|
272
|
system_routing_enable();
|
273
|
|
274
|
/* ensure passwords are sync'd */
|
275
|
system_password_configure();
|
276
|
|
277
|
/* configure console menu */
|
278
|
system_console_configure();
|
279
|
|
280
|
/* start DHCP service */
|
281
|
services_dhcpd_configure();
|
282
|
|
283
|
/* start dnsmasq service */
|
284
|
services_dnsmasq_configure();
|
285
|
|
286
|
/* start dyndns service */
|
287
|
services_dyndns_configure();
|
288
|
|
289
|
/* static IP address? -> attempt DNS update */
|
290
|
if (is_ipaddr($config['interfaces']['wan']['ipaddr']))
|
291
|
services_dnsupdate_process();
|
292
|
|
293
|
/* start DHCP relay */
|
294
|
services_dhcrelay_configure();
|
295
|
|
296
|
/* start proxy ARP service */
|
297
|
services_proxyarp_configure();
|
298
|
|
299
|
/* setup pppoe and pptp */
|
300
|
vpn_setup();
|
301
|
|
302
|
/* start the captive portal */
|
303
|
captiveportal_configure();
|
304
|
|
305
|
/* run any shell commands specified in config.xml */
|
306
|
system_do_shell_commands();
|
307
|
|
308
|
/* setup polling */
|
309
|
setup_polling();
|
310
|
|
311
|
mwexec("/sbin/pfctl -f /tmp/rules.debug");
|
312
|
|
313
|
interfaces_carp_bring_up_final();
|
314
|
|
315
|
/* start IPsec tunnels */
|
316
|
vpn_ipsec_configure();
|
317
|
|
318
|
/* start ftp proxy helpers if they are enabled */
|
319
|
echo "Starting FTP helpers...";
|
320
|
system_start_ftp_helpers();
|
321
|
echo "done.\n";
|
322
|
|
323
|
/* start SNMP service */
|
324
|
services_snmpd_configure();
|
325
|
|
326
|
/* power down hard drive if needed/set */
|
327
|
system_set_harddisk_standby();
|
328
|
|
329
|
/* lock down console if necessary */
|
330
|
if(isset($config['system']['disableconsolemenu']))
|
331
|
touch("/var/etc/console_lockdown");
|
332
|
|
333
|
echo "Final filter pass...";
|
334
|
filter_configure_sync();
|
335
|
echo "done.\n";
|
336
|
|
337
|
/* load graphing functions */
|
338
|
enable_rrd_graphing();
|
339
|
|
340
|
/* start DHCP service again now that CARP has settled
|
341
|
* incase user is using primary/backup failover dhcp mode
|
342
|
*/
|
343
|
services_dhcpd_configure();
|
344
|
|
345
|
/* startup OLSR if needed */
|
346
|
setup_wireless_olsr();
|
347
|
|
348
|
/* startup routed if needed */
|
349
|
include_once("/usr/local/pkg/routed/routed.inc");
|
350
|
setup_routed();
|
351
|
|
352
|
/* if <system><afterbootupshellcmd> exists, execute the command */
|
353
|
if($config['system']['afterbootupshellcmd'] <> "")
|
354
|
mwexec($config['system']['afterbootupshellcmd']);
|
355
|
|
356
|
if($avail < 121) {
|
357
|
require_once("/etc/inc/notices.inc");
|
358
|
file_notice("{$g['product_name']}MemoryRequirements", "{$g['product_name']} requires atleast 128 megabytes of RAM. Expect unusual performance. This platform is not supported.", "Memory", "", 1);
|
359
|
mwexec("sysctl net.inet.tcp.recvspace=4096");
|
360
|
mwexec("sysctl net.inet.tcp.sendspace=4096");
|
361
|
}
|
362
|
|
363
|
/* if we are operating at 1000 then increase timeouts.
|
364
|
this was never accounted for after moving to 1000 hz */
|
365
|
$kern_hz = `sysctl kern.clockrate | awk '{ print $5 }' | cut -d"," -f1`;
|
366
|
$kern_hz = trim($kern_hz, "\r\n");
|
367
|
if($kern_hz == "1000")
|
368
|
mwexec("sysctl net.inet.tcp.rexmit_min=30");
|
369
|
|
370
|
upnp_start();
|
371
|
|
372
|
/* done */
|
373
|
unlink("{$g['varrun_path']}/booting");
|
374
|
unset($g['booting']);
|
375
|
|
376
|
?>
|