1
|
#!/usr/local/bin/php-cgi -f
|
2
|
<?php
|
3
|
/*
|
4
|
rc.bootup
|
5
|
part of pfSense by Scott Ullrich
|
6
|
originally based on m0n0wall (http://m0n0.ch/wall)
|
7
|
Copyright (C) 2004-2009 Scott Ullrich <sullrich@pfsense.org>.
|
8
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
9
|
Copyright (C) 2009 Erik Kristensen
|
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("pkg-utils.inc");
|
35
|
|
36
|
function rescue_detect_keypress() {
|
37
|
// How long do you want the script to wait before moving on (in seconds)
|
38
|
$timeout=9;
|
39
|
echo "\n";
|
40
|
echo "[ Press R to enter recovery mode or ]\n";
|
41
|
echo "[ press I to launch the installer ]\n\n";
|
42
|
echo "(R)ecovery mode can assist by rescuing config.xml\n";
|
43
|
echo "from a broken hard disk installation, etc.\n\n";
|
44
|
echo "(I)nstaller will be invoked\n\n";
|
45
|
echo "Timeout before auto boot continues (seconds): {$timeout}";
|
46
|
$key = null;
|
47
|
exec("/bin/stty erase " . chr(8));
|
48
|
while (!in_array($key, array("r", "R", "i", "I"))) {
|
49
|
echo chr(8) . "{$timeout}";
|
50
|
`/bin/stty -icanon min 0 time 25`;
|
51
|
$key = trim(`KEY=\`dd count=1 2>/dev/null\`; echo \$KEY`);
|
52
|
`/bin/stty icanon`;
|
53
|
// Decrement our timeout value
|
54
|
$timeout--;
|
55
|
// If we have reached 0 exit and continue on
|
56
|
if ($timeout == 0) {
|
57
|
break;
|
58
|
}
|
59
|
}
|
60
|
// If R or I was pressed do our logic here
|
61
|
if (in_array($key, array("r", "R"))) {
|
62
|
putenv("TERM=xterm");
|
63
|
echo "\n\nRecovery mode selected...\n";
|
64
|
passthru("/usr/bin/env TERM=xterm /bin/tcsh");
|
65
|
} else {
|
66
|
putenv("TERM=xterm");
|
67
|
echo "\n\nInstaller mode selected...\n";
|
68
|
passthru("/usr/bin/env TERM=xterm /bin/tcsh -c /scripts/lua_installer");
|
69
|
}
|
70
|
|
71
|
passthru("/etc/rc.reboot");
|
72
|
exit;
|
73
|
}
|
74
|
|
75
|
echo " done.\n";
|
76
|
|
77
|
echo "Initializing...";
|
78
|
echo ".";
|
79
|
require_once("/etc/inc/globals.inc");
|
80
|
echo ".";
|
81
|
require_once("/etc/inc/led.inc");
|
82
|
led_normalize();
|
83
|
echo ".";
|
84
|
if (led_count() >= 3) {
|
85
|
led_kitt();
|
86
|
}
|
87
|
|
88
|
/* let the other functions know we're booting */
|
89
|
$pkg_interface = 'console';
|
90
|
$g['booting'] = true;
|
91
|
|
92
|
/* parse the configuration and include all functions used below */
|
93
|
require_once("/etc/inc/config.inc");
|
94
|
echo ".";
|
95
|
require_once("/etc/inc/config.console.inc");
|
96
|
echo ".";
|
97
|
require_once("/etc/inc/auth.inc");
|
98
|
echo ".";
|
99
|
require_once("/etc/inc/functions.inc");
|
100
|
echo ".";
|
101
|
require_once("/etc/inc/filter.inc");
|
102
|
echo ".";
|
103
|
require_once("/etc/inc/shaper.inc");
|
104
|
echo ".";
|
105
|
require_once("/etc/inc/ipsec.inc");
|
106
|
echo ".";
|
107
|
require_once("/etc/inc/vpn.inc");
|
108
|
echo ".";
|
109
|
require_once("/etc/inc/openvpn.inc");
|
110
|
echo ".";
|
111
|
require_once("/etc/inc/captiveportal.inc");
|
112
|
echo ".";
|
113
|
require_once("/etc/inc/rrd.inc");
|
114
|
echo ".";
|
115
|
require_once("/etc/inc/pfsense-utils.inc");
|
116
|
echo ".";
|
117
|
|
118
|
/* get system memory amount */
|
119
|
$memory = get_memory();
|
120
|
$physmem = $memory[0];
|
121
|
$realmem = $memory[1];
|
122
|
echo " done.\n";
|
123
|
|
124
|
conf_mount_rw();
|
125
|
|
126
|
/* save dmesg output to file */
|
127
|
system_dmesg_save();
|
128
|
|
129
|
/* check whether config reset is desired (via hardware button on WRAP/ALIX) */
|
130
|
system_check_reset_button();
|
131
|
|
132
|
/* remove previous firmware upgrade if present */
|
133
|
if (file_exists("/root/firmware.tgz")) {
|
134
|
unlink("/root/firmware.tgz");
|
135
|
}
|
136
|
|
137
|
/* Reinstall of packages after reboot has been requested */
|
138
|
if (file_exists('/conf/needs_package_sync_after_reboot')) {
|
139
|
touch('/conf/needs_package_sync');
|
140
|
@unlink('/conf/needs_package_sync_after_reboot');
|
141
|
}
|
142
|
|
143
|
/* Triggering of the initial setup wizard after reboot has been requested */
|
144
|
if (file_exists('/conf/trigger_initial_wizard_after_reboot')) {
|
145
|
touch('/conf/trigger_initial_wizard');
|
146
|
@unlink('/conf/trigger_initial_wizard_after_reboot');
|
147
|
}
|
148
|
|
149
|
/* start devd (dhclient now uses it) */
|
150
|
echo "Starting device manager (devd)...";
|
151
|
mute_kernel_msgs();
|
152
|
start_devd();
|
153
|
set_device_perms();
|
154
|
unmute_kernel_msgs();
|
155
|
echo "done.\n";
|
156
|
|
157
|
// Display rescue configuration option
|
158
|
if ($g['platform'] == "cdrom") {
|
159
|
rescue_detect_keypress();
|
160
|
}
|
161
|
|
162
|
echo "Loading configuration...";
|
163
|
parse_config_bootup();
|
164
|
echo "done.\n";
|
165
|
|
166
|
/* run any early shell commands specified in config.xml */
|
167
|
system_do_shell_commands(1);
|
168
|
|
169
|
if (file_exists("/conf/trigger_initial_wizard")) {
|
170
|
check_for_alternate_interfaces();
|
171
|
}
|
172
|
|
173
|
/*
|
174
|
* Determine if we need to throw a interface exception
|
175
|
* and ask the user to reassign interfaces. This will
|
176
|
* avoid a reboot and that is a good thing.
|
177
|
*/
|
178
|
while (is_interface_mismatch() == true) {
|
179
|
led_assigninterfaces();
|
180
|
if (isset($config['revision'])) {
|
181
|
if (file_exists("{$g['tmp_path']}/missing_interfaces")) {
|
182
|
echo "Warning: Configuration references interfaces that do not exist: " . file_get_contents("{$g['tmp_path']}/missing_interfaces") . "\n";
|
183
|
}
|
184
|
echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
|
185
|
} else {
|
186
|
echo "\nDefault interfaces not found -- Running interface assignment option.\n";
|
187
|
}
|
188
|
$ifaces = get_interface_list();
|
189
|
if (is_array($ifaces)) {
|
190
|
foreach ($ifaces as $iface => $ifdata) {
|
191
|
interfaces_bring_up($iface);
|
192
|
}
|
193
|
}
|
194
|
set_networking_interfaces_ports();
|
195
|
led_kitt();
|
196
|
}
|
197
|
|
198
|
/* convert config and clean backups */
|
199
|
echo "Updating configuration...";
|
200
|
convert_config();
|
201
|
echo "done.\n";
|
202
|
|
203
|
echo "Cleaning backup cache...";
|
204
|
cleanup_backupcache(true);
|
205
|
echo "done.\n";
|
206
|
|
207
|
/* read in /etc/sysctl.conf and set values if needed */
|
208
|
echo "Setting up extended sysctls...";
|
209
|
system_setup_sysctl();
|
210
|
echo "done.\n";
|
211
|
|
212
|
/* enable optional crypto modules */
|
213
|
load_crypto();
|
214
|
|
215
|
/* enable optional thermal sensor modules */
|
216
|
load_thermal_hardware();
|
217
|
|
218
|
/* set up our timezone */
|
219
|
system_timezone_configure();
|
220
|
|
221
|
/* set up our hostname */
|
222
|
system_hostname_configure();
|
223
|
|
224
|
/* make hosts file */
|
225
|
system_hosts_generate();
|
226
|
|
227
|
/* configure loopback interface */
|
228
|
interfaces_loopback_configure();
|
229
|
|
230
|
/* start syslogd */
|
231
|
system_syslogd_start();
|
232
|
|
233
|
/* restore alias tables */
|
234
|
restore_aliastables();
|
235
|
|
236
|
echo "Starting Secure Shell Services...";
|
237
|
send_event("service reload sshd");
|
238
|
echo "done.\n";
|
239
|
|
240
|
/* setup polling */
|
241
|
echo "Setting up polling defaults...";
|
242
|
setup_polling();
|
243
|
echo "done.\n";
|
244
|
|
245
|
/* setup interface microcode which improves tcp/ip speed */
|
246
|
echo "Setting up interfaces microcode...";
|
247
|
setup_microcode();
|
248
|
echo "done.\n";
|
249
|
|
250
|
/* set up interfaces */
|
251
|
if (!$debugging) {
|
252
|
mute_kernel_msgs();
|
253
|
}
|
254
|
interfaces_configure();
|
255
|
interfaces_sync_setup();
|
256
|
if (!$debugging) {
|
257
|
unmute_kernel_msgs();
|
258
|
}
|
259
|
|
260
|
/* re-make hosts file after configuring interfaces */
|
261
|
system_hosts_generate();
|
262
|
|
263
|
/* start OpenVPN server & clients */
|
264
|
echo "Syncing OpenVPN settings...";
|
265
|
openvpn_resync_all();
|
266
|
echo "done.\n";
|
267
|
|
268
|
/* generate resolv.conf */
|
269
|
system_resolvconf_generate();
|
270
|
|
271
|
/* setup altq + pf */
|
272
|
filter_configure_sync();
|
273
|
|
274
|
/* start pflog */
|
275
|
echo "Starting PFLOG...";
|
276
|
filter_pflog_start();
|
277
|
echo "done.\n";
|
278
|
|
279
|
/* reconfigure our gateway monitor */
|
280
|
echo "Setting up gateway monitors...";
|
281
|
setup_gateways_monitor();
|
282
|
echo "done.\n";
|
283
|
|
284
|
echo "Synchronizing user settings...";
|
285
|
local_sync_accounts();
|
286
|
echo "done.\n";
|
287
|
|
288
|
if ($realmem > 0 and $realmem < 65) {
|
289
|
echo "System has less than 65 megabytes of ram {$realmem}. Delaying webConfigurator startup.\n";
|
290
|
/* start webConfigurator up on final pass */
|
291
|
mwexec("/usr/local/sbin/pfSctl -c 'service restart webgui'");
|
292
|
} else {
|
293
|
/* start web server */
|
294
|
system_webgui_start();
|
295
|
}
|
296
|
|
297
|
/* configure cron service */
|
298
|
echo "Configuring CRON...";
|
299
|
configure_cron();
|
300
|
echo "done.\n";
|
301
|
|
302
|
/* set up static routes */
|
303
|
system_routing_configure();
|
304
|
|
305
|
/* enable routing */
|
306
|
system_routing_enable();
|
307
|
|
308
|
/* start dnsmasq service */
|
309
|
services_dnsmasq_configure();
|
310
|
|
311
|
/* start unbound service */
|
312
|
services_unbound_configure();
|
313
|
|
314
|
/* Enable ntpd */
|
315
|
echo "Starting NTP time client...";
|
316
|
system_ntp_configure();
|
317
|
echo "done.\n";
|
318
|
|
319
|
/* start load balancer daemon */
|
320
|
relayd_configure();
|
321
|
|
322
|
/* configure console menu and serial port*/
|
323
|
setup_serial_port();
|
324
|
|
325
|
/* start DHCP service */
|
326
|
services_dhcpd_configure();
|
327
|
|
328
|
/* start dhcpleases dhcp hosts leases program */
|
329
|
system_dhcpleases_configure();
|
330
|
|
331
|
/* start DHCP relay */
|
332
|
services_dhcrelay_configure();
|
333
|
|
334
|
/* start DHCP6 relay */
|
335
|
services_dhcrelay6_configure();
|
336
|
|
337
|
/* dyndns service updates */
|
338
|
send_event("service reload dyndnsall");
|
339
|
|
340
|
/* Run a filter configure now that most all services have started */
|
341
|
filter_configure_sync();
|
342
|
|
343
|
/* setup pppoe and pptp */
|
344
|
vpn_setup();
|
345
|
|
346
|
/* start the captive portal */
|
347
|
captiveportal_configure();
|
348
|
|
349
|
/* start Voucher support */
|
350
|
voucher_configure();
|
351
|
|
352
|
/* run any shell commands specified in config.xml */
|
353
|
system_do_shell_commands();
|
354
|
|
355
|
/* start IPsec tunnels */
|
356
|
$ipsec_dynamic_hosts = vpn_ipsec_configure();
|
357
|
|
358
|
/* start SNMP service */
|
359
|
services_snmpd_configure();
|
360
|
|
361
|
/* power down hard drive if needed/set */
|
362
|
system_set_harddisk_standby();
|
363
|
|
364
|
/* lock down console if necessary */
|
365
|
reload_ttys();
|
366
|
|
367
|
/* load graphing functions */
|
368
|
enable_rrd_graphing();
|
369
|
|
370
|
/* enable watchdog if supported */
|
371
|
enable_watchdog();
|
372
|
|
373
|
/* if <system><afterbootupshellcmd> exists, execute the command */
|
374
|
if ($config['system']['afterbootupshellcmd'] <> "") {
|
375
|
echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
|
376
|
mwexec($config['system']['afterbootupshellcmd']);
|
377
|
}
|
378
|
|
379
|
if ($physmem < $g['minimum_ram_warning']) {
|
380
|
require_once("/etc/inc/notices.inc");
|
381
|
file_notice("{$g['product_name']}MemoryRequirements", "{$g['product_name']} requires at least {$g['minimum_ram_warning_text']} of RAM. Expect unusual performance. This platform is not supported.", "Memory", "", 1);
|
382
|
set_sysctl(array(
|
383
|
"net.inet.tcp.recvspace" => "4096",
|
384
|
"net.inet.tcp.sendspace" => "4096"
|
385
|
));
|
386
|
}
|
387
|
|
388
|
/* if we are operating at 1000 then increase timeouts.
|
389
|
this was never accounted for after moving to 1000 hz */
|
390
|
$kern_hz = get_single_sysctl('kern.clockrate');
|
391
|
$kern_hz = substr($kern_hz, strpos($kern_hz, "hz = ") + 5);
|
392
|
$kern_hz = substr($kern_hz, 0, strpos($kern_hz, ","));
|
393
|
if ($kern_hz == "1000") {
|
394
|
set_single_sysctl("net.inet.tcp.rexmit_min" , "30");
|
395
|
}
|
396
|
|
397
|
/* start the igmpproxy daemon */
|
398
|
services_igmpproxy_configure();
|
399
|
|
400
|
/* start the upnp daemon if it is enabled */
|
401
|
upnp_start();
|
402
|
|
403
|
/* If powerd is enabled, lets launch it */
|
404
|
activate_powerd();
|
405
|
|
406
|
/* Set preferred protocol */
|
407
|
prefer_ipv4_or_ipv6();
|
408
|
|
409
|
/* Remove the old shutdown binary if we kept it. */
|
410
|
if (file_exists("/sbin/shutdown.old")) {
|
411
|
@unlink("/sbin/shutdown.old");
|
412
|
}
|
413
|
|
414
|
/* Resync / Reinstall packages if need be */
|
415
|
if (file_exists('/conf/needs_package_sync') &&
|
416
|
($g['platform'] == $g['product_name'] || $g['platform'] == "nanobsd")) {
|
417
|
mark_subsystem_dirty('packagelock');
|
418
|
if (package_reinstall_all()) {
|
419
|
@unlink('/conf/needs_package_sync');
|
420
|
}
|
421
|
clear_subsystem_dirty('packagelock');
|
422
|
}
|
423
|
|
424
|
/* Detect installed binary pkgs that are not registered in the system */
|
425
|
if ($g['platform'] != "cdrom") {
|
426
|
register_all_installed_packages();
|
427
|
}
|
428
|
|
429
|
/* Give syslogd a kick after everything else has been initialized, otherwise it can occasionally
|
430
|
fail to route syslog messages properly on both IPv4 and IPv6 */
|
431
|
system_syslogd_start();
|
432
|
|
433
|
/* done */
|
434
|
unset($g['booting']);
|
435
|
@unlink("{$g['varrun_path']}/booting");
|
436
|
|
437
|
/* If there are ipsec dynamic hosts try again to reload the tunnels as rc.newipsecdns does */
|
438
|
if ($ipsec_dynamic_hosts) {
|
439
|
vpn_ipsec_configure();
|
440
|
}
|
441
|
if ($ipsec_dynamic_hosts || !empty($filterdns)) {
|
442
|
filter_configure();
|
443
|
}
|
444
|
|
445
|
led_normalize();
|
446
|
|
447
|
conf_mount_ro();
|
448
|
|
449
|
?>
|