Project

General

Profile

Download (11.1 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php-cgi -f
2
<?php
3
/*
4
 * rc.bootup
5
 *
6
 * originally based on m0n0wall (http://m0n0.ch/wall)
7
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
 * Copyright (c) 2009 Erik Kristensen
9
 * Copyright (c) 2005-2016 Electric Sheep Fencing, LLC. All rights reserved.
10
 * All rights reserved.
11
 *
12
 * Licensed under the Apache License, Version 2.0 (the "License");
13
 * you may not use this file except in compliance with the License.
14
 * You may obtain a copy of the License at
15
 *
16
 * http://www.apache.org/licenses/LICENSE-2.0
17
 *
18
 * Unless required by applicable law or agreed to in writing, software
19
 * distributed under the License is distributed on an "AS IS" BASIS,
20
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
 * See the License for the specific language governing permissions and
22
 * limitations under the License.
23
 */
24

    
25
require_once("pkg-utils.inc");
26

    
27
function rescue_detect_keypress() {
28
	// How long do you want the script to wait before moving on (in seconds)
29
	$timeout=9;
30
	echo "\n";
31
	echo "[ Press R to enter recovery mode or ]\n";
32
	echo "[  press I to launch the installer  ]\n\n";
33
	echo "(R)ecovery mode can assist by rescuing config.xml\n";
34
	echo "from a broken hard disk installation, etc.\n\n";
35
	echo "(I)nstaller will be invoked\n\n";
36
	echo "Timeout before auto boot continues (seconds): {$timeout}";
37
	$key = null;
38
	exec("/bin/stty erase " . chr(8));
39
	while (!in_array($key, array("r", "R", "i", "I"))) {
40
		echo chr(8) . "{$timeout}";
41
		`/bin/stty -icanon min 0 time 25`;
42
		$key = trim(`KEY=\`dd count=1 2>/dev/null\`; echo \$KEY`);
43
		`/bin/stty icanon`;
44
		// Decrement our timeout value
45
		$timeout--;
46
		// If we have reached 0 exit and continue on
47
		if ($timeout == 0) {
48
			break;
49
		}
50
	}
51
	// If R or I was pressed do our logic here
52
	if (in_array($key, array("r", "R"))) {
53
		putenv("TERM=xterm");
54
		echo "\n\nRecovery mode selected...\n";
55
		passthru("/usr/bin/env TERM=xterm /bin/tcsh");
56
	} else {
57
		putenv("TERM=xterm");
58
		echo "\n\nInstaller mode selected...\n";
59
		passthru("/usr/bin/env TERM=xterm /bin/tcsh -c /scripts/lua_installer");
60
	}
61

    
62
	passthru("/etc/rc.reboot");
63
	exit;
64
}
65

    
66
echo " done.\n";
67

    
68
echo "Initializing...";
69
echo ".";
70
require_once("/etc/inc/globals.inc");
71
echo ".";
72
require_once("/etc/inc/led.inc");
73
led_normalize();
74
echo ".";
75
if (led_count() >= 3) {
76
	led_kitt();
77
}
78

    
79
/* let the other functions know we're booting */
80
$pkg_interface = 'console';
81
$g['booting'] = true;
82

    
83
/* parse the configuration and include all functions used below */
84
require_once("/etc/inc/config.inc");
85
echo ".";
86
require_once("/etc/inc/config.console.inc");
87
echo ".";
88
require_once("/etc/inc/auth.inc");
89
echo ".";
90
require_once("/etc/inc/functions.inc");
91
echo ".";
92
require_once("/etc/inc/filter.inc");
93
echo ".";
94
require_once("/etc/inc/shaper.inc");
95
echo ".";
96
require_once("/etc/inc/ipsec.inc");
97
echo ".";
98
require_once("/etc/inc/vpn.inc");
99
echo ".";
100
require_once("/etc/inc/openvpn.inc");
101
echo ".";
102
require_once("/etc/inc/captiveportal.inc");
103
echo ".";
104
require_once("/etc/inc/rrd.inc");
105
echo ".";
106
require_once("/etc/inc/pfsense-utils.inc");
107
echo ".";
108

    
109
/* get system memory amount */
110
$memory = get_memory();
111
$physmem = $memory[0];
112
$realmem = $memory[1];
113
echo " done.\n";
114

    
115
conf_mount_rw();
116

    
117
/* save dmesg output to file */
118
system_dmesg_save();
119

    
120
/* check whether config reset is desired (via hardware button on WRAP/ALIX) */
121
system_check_reset_button();
122

    
123
/* remove previous firmware upgrade if present */
124
if (file_exists("/root/firmware.tgz")) {
125
	unlink("/root/firmware.tgz");
126
}
127

    
128
/* Reinstall of packages after reboot has been requested */
129
if (file_exists('/conf/needs_package_sync_after_reboot')) {
130
	touch('/conf/needs_package_sync');
131
	@unlink('/conf/needs_package_sync_after_reboot');
132
}
133

    
134
/* Triggering of the initial setup wizard after reboot has been requested */
135
if (file_exists('/conf/trigger_initial_wizard_after_reboot')) {
136
	touch('/conf/trigger_initial_wizard');
137
	@unlink('/conf/trigger_initial_wizard_after_reboot');
138
}
139

    
140
/* start devd (dhclient now uses it) */
141
echo "Starting device manager (devd)...";
142
mute_kernel_msgs();
143
start_devd();
144
set_device_perms();
145
unmute_kernel_msgs();
146
echo "done.\n";
147

    
148
// Display rescue configuration option
149
if ($g['platform'] == "cdrom") {
150
	rescue_detect_keypress();
151
}
152

    
153
echo "Loading configuration...";
154
parse_config_bootup();
155
echo "done.\n";
156

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

    
160
if (file_exists("/conf/trigger_initial_wizard")) {
161
	check_for_alternate_interfaces();
162
}
163

    
164
/*
165
 *	Determine if we need to throw a interface exception
166
 *	and ask the user to reassign interfaces.  This will
167
 *	avoid a reboot and that is a good thing.
168
 */
169
while (is_interface_mismatch() == true) {
170
	led_assigninterfaces();
171
	if (isset($config['revision'])) {
172
		if (file_exists("{$g['tmp_path']}/missing_interfaces")) {
173
			echo "Warning: Configuration references interfaces that do not exist: " . file_get_contents("{$g['tmp_path']}/missing_interfaces") . "\n";
174
		}
175
		echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
176
	} else {
177
		echo "\nDefault interfaces not found -- Running interface assignment option.\n";
178
	}
179
	$ifaces = get_interface_list();
180
	if (is_array($ifaces)) {
181
		foreach ($ifaces as $iface => $ifdata) {
182
			interfaces_bring_up($iface);
183
		}
184
	}
185
	set_networking_interfaces_ports();
186
	led_kitt();
187
}
188

    
189
/* convert config and clean backups */
190
echo "Updating configuration...";
191
convert_config();
192
echo "done.\n";
193

    
194
echo "Cleaning backup cache...";
195
cleanup_backupcache(true);
196
echo "done.\n";
197

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

    
203
/* enable optional crypto modules */
204
load_crypto();
205

    
206
/* enable optional thermal sensor modules */
207
load_thermal_hardware();
208

    
209
/* set up our timezone */
210
system_timezone_configure();
211

    
212
/* set up our hostname */
213
system_hostname_configure();
214

    
215
/* make hosts file */
216
system_hosts_generate();
217

    
218
/* configure loopback interface */
219
interfaces_loopback_configure();
220

    
221
/* start syslogd */
222
system_syslogd_start();
223

    
224
/* restore alias tables */
225
restore_aliastables();
226

    
227
echo "Starting Secure Shell Services...";
228
send_event("service reload sshd");
229
echo "done.\n";
230

    
231
/* setup polling */
232
echo "Setting up polling defaults...";
233
setup_polling();
234
echo "done.\n";
235

    
236
/* setup interface microcode which improves tcp/ip speed */
237
echo "Setting up interfaces microcode...";
238
setup_microcode();
239
echo "done.\n";
240

    
241
/* set up interfaces */
242
if (!$debugging) {
243
	mute_kernel_msgs();
244
}
245
interfaces_configure();
246
interfaces_sync_setup();
247
if (!$debugging) {
248
	unmute_kernel_msgs();
249
}
250

    
251
/* re-make hosts file after configuring interfaces */
252
system_hosts_generate();
253

    
254
/* start OpenVPN server & clients */
255
echo "Syncing OpenVPN settings...";
256
openvpn_resync_all();
257
echo "done.\n";
258

    
259
/* generate resolv.conf */
260
system_resolvconf_generate();
261

    
262
/* setup altq + pf */
263
filter_configure_sync();
264

    
265
/* start pflog */
266
echo "Starting PFLOG...";
267
filter_pflog_start();
268
echo "done.\n";
269

    
270
/* reconfigure our gateway monitor */
271
echo "Setting up gateway monitors...";
272
setup_gateways_monitor();
273
echo "done.\n";
274

    
275
echo "Synchronizing user settings...";
276
local_sync_accounts();
277
echo "done.\n";
278

    
279
if ($realmem > 0 and $realmem < 65) {
280
	echo "System has less than 65 megabytes of ram {$realmem}.  Delaying webConfigurator startup.\n";
281
	/* start webConfigurator up on final pass */
282
	mwexec("/usr/local/sbin/pfSctl -c 'service restart webgui'");
283
} else {
284
	/* start web server */
285
	system_webgui_start();
286
}
287

    
288
/* configure cron service */
289
echo "Configuring CRON...";
290
configure_cron();
291
echo "done.\n";
292

    
293
/* set up static routes */
294
system_routing_configure();
295

    
296
/* enable routing */
297
system_routing_enable();
298

    
299
/* start dnsmasq service */
300
services_dnsmasq_configure();
301

    
302
/* start unbound service */
303
services_unbound_configure();
304

    
305
/* Enable ntpd */
306
echo "Starting NTP time client...";
307
system_ntp_configure();
308
echo "done.\n";
309

    
310
/* start load balancer daemon */
311
relayd_configure();
312

    
313
/* configure console menu and serial port*/
314
setup_serial_port();
315

    
316
/* start DHCP service */
317
services_dhcpd_configure();
318

    
319
/* start dhcpleases dhcp hosts leases program */
320
system_dhcpleases_configure();
321

    
322
/* start DHCP relay */
323
services_dhcrelay_configure();
324

    
325
/* start DHCP6 relay */
326
services_dhcrelay6_configure();
327

    
328
/* dyndns service updates */
329
send_event("service reload dyndnsall");
330

    
331
/* Run a filter configure now that most all services have started */
332
filter_configure_sync();
333

    
334
/* setup pppoe and pptp */
335
vpn_setup();
336

    
337
/* start the captive portal */
338
captiveportal_configure();
339

    
340
/* start Voucher support */
341
voucher_configure();
342

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

    
346
/* start IPsec tunnels */
347
$ipsec_dynamic_hosts = vpn_ipsec_configure();
348

    
349
/* start SNMP service */
350
services_snmpd_configure();
351

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

    
355
/* lock down console if necessary */
356
reload_ttys();
357

    
358
/* load graphing functions */
359
enable_rrd_graphing();
360

    
361
/* enable watchdog if supported */
362
enable_watchdog();
363

    
364
/* if <system><afterbootupshellcmd> exists, execute the command */
365
if ($config['system']['afterbootupshellcmd'] <> "") {
366
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
367
	mwexec($config['system']['afterbootupshellcmd']);
368
}
369

    
370
if ($physmem < $g['minimum_ram_warning']) {
371
	require_once("/etc/inc/notices.inc");
372
	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);
373
	set_sysctl(array(
374
		"net.inet.tcp.recvspace" => "4096",
375
		"net.inet.tcp.sendspace" => "4096"
376
	));
377
}
378

    
379
/* if we are operating at 1000 then increase timeouts.
380
   this was never accounted for after moving to 1000 hz */
381
$kern_hz = get_single_sysctl('kern.clockrate');
382
$kern_hz = substr($kern_hz, strpos($kern_hz, "hz = ") + 5);
383
$kern_hz = substr($kern_hz, 0, strpos($kern_hz, ","));
384
if ($kern_hz == "1000") {
385
	set_single_sysctl("net.inet.tcp.rexmit_min" , "30");
386
}
387

    
388
/* start the igmpproxy daemon */
389
services_igmpproxy_configure();
390

    
391
/* start the upnp daemon if it is enabled */
392
upnp_start();
393

    
394
/* If powerd is enabled, lets launch it */
395
activate_powerd();
396

    
397
/* Set preferred protocol */
398
prefer_ipv4_or_ipv6();
399

    
400
/* Remove the old shutdown binary if we kept it. */
401
if (file_exists("/sbin/shutdown.old")) {
402
	@unlink("/sbin/shutdown.old");
403
}
404

    
405
/* Resync / Reinstall packages if need be */
406
if (file_exists('/conf/needs_package_sync') &&
407
    ($g['platform'] == $g['product_name'] || $g['platform'] == "nanobsd")) {
408
	mark_subsystem_dirty('packagelock');
409
	if (package_reinstall_all()) {
410
		@unlink('/conf/needs_package_sync');
411
	}
412
	clear_subsystem_dirty('packagelock');
413
}
414

    
415
/* Detect installed binary pkgs that are not registered in the system */
416
if ($g['platform'] != "cdrom") {
417
	register_all_installed_packages();
418
}
419

    
420
/* Give syslogd a kick after everything else has been initialized, otherwise it can occasionally
421
   fail to route syslog messages properly on both IPv4 and IPv6 */
422
system_syslogd_start();
423

    
424
/* done */
425
unset($g['booting']);
426
@unlink("{$g['varrun_path']}/booting");
427

    
428
/* If there are ipsec dynamic hosts try again to reload the tunnels as rc.newipsecdns does */
429
if ($ipsec_dynamic_hosts) {
430
	vpn_ipsec_configure();
431
}
432
if ($ipsec_dynamic_hosts || !empty($filterdns)) {
433
	filter_configure();
434
}
435

    
436
led_normalize();
437

    
438
conf_mount_ro();
439

    
440
?>
(17-17/79)