Project

General

Profile

Download (10.7 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 Rubicon Communications, LLC (Netgate). 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
echo " done.\n";
28

    
29
echo "Initializing...";
30
echo ".";
31
require_once("/etc/inc/globals.inc");
32
echo ".";
33
require_once("/etc/inc/led.inc");
34
led_normalize();
35
echo ".";
36
if (led_count() >= 3) {
37
	led_kitt();
38
}
39

    
40
/* let the other functions know we're booting */
41
$pkg_interface = 'console';
42
$g['booting'] = true;
43

    
44
/* parse the configuration and include all functions used below */
45
require_once("/etc/inc/config.inc");
46
echo ".";
47
require_once("/etc/inc/config.console.inc");
48
echo ".";
49
require_once("/etc/inc/auth.inc");
50
echo ".";
51
require_once("/etc/inc/functions.inc");
52
echo ".";
53
require_once("/etc/inc/filter.inc");
54
echo ".";
55
require_once("/etc/inc/shaper.inc");
56
echo ".";
57
require_once("/etc/inc/ipsec.inc");
58
echo ".";
59
require_once("/etc/inc/vpn.inc");
60
echo ".";
61
require_once("/etc/inc/openvpn.inc");
62
echo ".";
63
require_once("/etc/inc/captiveportal.inc");
64
echo ".";
65
require_once("/etc/inc/rrd.inc");
66
echo ".";
67
require_once("/etc/inc/pfsense-utils.inc");
68
echo ".";
69

    
70
/* get system memory amount */
71
$memory = get_memory();
72
$physmem = $memory[0];
73
$realmem = $memory[1];
74
echo " done.\n";
75

    
76

    
77
/* save dmesg output to file */
78
system_dmesg_save();
79

    
80
/* check whether config reset is desired (via hardware button on WRAP/ALIX) */
81
system_check_reset_button();
82

    
83
/* remove previous firmware upgrade if present */
84
if (file_exists("/root/firmware.tgz")) {
85
	unlink("/root/firmware.tgz");
86
}
87

    
88
/* Reinstall of packages after reboot has been requested */
89
if (file_exists('/conf/needs_package_sync_after_reboot')) {
90
	touch('/conf/needs_package_sync');
91
	@unlink('/conf/needs_package_sync_after_reboot');
92
}
93

    
94
/* Triggering of the initial setup wizard after reboot has been requested */
95
if (file_exists('/conf/trigger_initial_wizard_after_reboot')) {
96
	touch('/conf/trigger_initial_wizard');
97
	@unlink('/conf/trigger_initial_wizard_after_reboot');
98
}
99

    
100
/* start devd (dhclient now uses it) */
101
echo "Starting device manager (devd)...";
102
mute_kernel_msgs();
103
start_devd();
104
set_device_perms();
105
unmute_kernel_msgs();
106
echo "done.\n";
107

    
108
echo "Loading configuration...";
109
parse_config_bootup();
110
echo "done.\n";
111

    
112
/* If pfSense.boot kenv is set, it's a reroot */
113
if (mwexec("/bin/kenv -q pfSense.boot 2>/dev/null") != 0) {
114
	/* Collect vendor MAC address for all interfaces */
115
	$ifs = pfSense_interface_listget();
116
	foreach ($ifs as $if) {
117
		$if_details = pfSense_get_interface_addresses($if);
118
		if (isset($if_details['iftype']) &&
119
		    $if_details['iftype'] == 'virtual') {
120
			continue;
121
		}
122

    
123
		if (empty($if_details['macaddr']) ||
124
		    $if_details['macaddr'] == "00:00:00:00:00:00") {
125
			continue;
126
		}
127

    
128
		$vendor_mac_arr[$if] = $if_details['macaddr'];
129
	}
130
	$vendor_mac_arr_json = json_encode($vendor_mac_arr);
131
	if (@file_get_contents("{$g['vardb_path']}/vendor_mac") !== $vendor_mac_arr_json) {
132
		@file_put_contents("{$g['vardb_path']}/vendor_mac", $vendor_mac_arr_json);
133
	}
134
	unset($ifs, $if, $vendor_mac_arr, $vendor_mac_arr_json);
135
	mwexec("/usr/sbin/gnid > {$g['vardb_path']}/uniqueid 2>/dev/null");
136
	mwexec("/bin/kenv pfSense.boot=1");
137
}
138

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

    
142
// Only do the alternate interface checks if:
143
// 1) The user has not yet run the initial wizard; and
144
// 2) The user has not used the console menu to setup interface assignments
145
if (file_exists("/conf/trigger_initial_wizard") && !file_exists("/conf/assign_complete")) {
146
	check_for_alternate_interfaces();
147
}
148

    
149
/*
150
 *	Determine if we need to throw a interface exception
151
 *	and ask the user to reassign interfaces.  This will
152
 *	avoid a reboot and that is a good thing.
153
 */
154
while (is_interface_mismatch() == true) {
155
	led_assigninterfaces();
156
	if (isset($config['revision'])) {
157
		if (file_exists("{$g['tmp_path']}/missing_interfaces")) {
158
			echo "Warning: Configuration references interfaces that do not exist: " . file_get_contents("{$g['tmp_path']}/missing_interfaces") . "\n";
159
		}
160
		echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
161
	} else {
162
		echo "\nDefault interfaces not found -- Running interface assignment option.\n";
163
	}
164
	$ifaces = get_interface_list();
165
	if (is_array($ifaces)) {
166
		foreach ($ifaces as $iface => $ifdata) {
167
			interfaces_bring_up($iface);
168
		}
169
	}
170
	set_networking_interfaces_ports();
171
	led_kitt();
172
}
173

    
174
/* convert config and clean backups */
175
echo "Updating configuration...";
176
convert_config();
177
echo "done.\n";
178

    
179
echo "Cleaning backup cache...";
180
cleanup_backupcache(true);
181
echo "done.\n";
182

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

    
188
/* enable optional crypto modules */
189
load_crypto();
190

    
191
/* enable optional thermal sensor modules */
192
load_thermal_hardware();
193

    
194
/* set up our timezone */
195
system_timezone_configure();
196

    
197
/* set up our hostname */
198
system_hostname_configure();
199

    
200
/* make hosts file */
201
system_hosts_generate();
202

    
203
/* configure loopback interface */
204
interfaces_loopback_configure();
205

    
206
/* start syslogd */
207
system_syslogd_start();
208

    
209
/* Log the RAM disk restore messages. */
210
if (file_exists("/var/log/restore_ramdisk_store.boot")) {
211
	exec("logger -f /var/log/restore_ramdisk_store.boot");
212
}
213

    
214
echo "Starting Secure Shell Services...";
215
send_event("service reload sshd");
216
echo "done.\n";
217

    
218
/* setup interface microcode which improves tcp/ip speed */
219
echo "Setting up interfaces microcode...";
220
setup_microcode();
221
echo "done.\n";
222

    
223
/* set up interfaces */
224
if (!$debugging) {
225
	mute_kernel_msgs();
226
}
227
interfaces_configure();
228
interfaces_sync_setup();
229
if (!$debugging) {
230
	unmute_kernel_msgs();
231
}
232

    
233
/* re-make hosts file after configuring interfaces */
234
system_hosts_generate();
235

    
236
/* start OpenVPN server & clients */
237
echo "Syncing OpenVPN settings...";
238
openvpn_resync_all();
239
echo "done.\n";
240

    
241
/* generate resolv.conf */
242
system_resolvconf_generate();
243

    
244
/* setup altq + pf */
245
filter_configure_sync();
246

    
247
/* start pflog */
248
echo "Starting PFLOG...";
249
filter_pflog_start();
250
echo "done.\n";
251

    
252
/* reconfigure our gateway monitor */
253
echo "Setting up gateway monitors...";
254
setup_gateways_monitor();
255
echo "done.\n";
256

    
257
/* set up static routes */
258
system_routing_configure();
259

    
260
/* start dnsmasq service */
261
services_dnsmasq_configure();
262

    
263
/* start unbound service */
264
services_unbound_configure();
265

    
266
echo "Synchronizing user settings...";
267
local_sync_accounts();
268
echo "done.\n";
269

    
270
if ($realmem > 0 and $realmem < 65) {
271
	echo "System has less than 65 megabytes of ram {$realmem}.  Delaying webConfigurator startup.\n";
272
	/* start webConfigurator up on final pass */
273
	mwexec("/usr/local/sbin/pfSctl -c 'service restart webgui'");
274
} else {
275
	/* start web server */
276
	system_webgui_start();
277
}
278

    
279
/* configure cron service */
280
echo "Configuring CRON...";
281
configure_cron();
282
echo "done.\n";
283

    
284
/* enable routing */
285
system_routing_enable();
286

    
287
/* Enable ntpd */
288
echo "Starting NTP time client...";
289
system_ntp_configure();
290
echo "done.\n";
291

    
292
/* start load balancer daemon */
293
relayd_configure();
294

    
295
/* configure console menu and serial port*/
296
setup_serial_port();
297

    
298
/* start DHCP service */
299
services_dhcpd_configure();
300

    
301
/* start dhcpleases dhcp hosts leases program */
302
system_dhcpleases_configure();
303

    
304
/* start DHCP relay */
305
services_dhcrelay_configure();
306

    
307
/* start DHCP6 relay */
308
services_dhcrelay6_configure();
309

    
310
/* dyndns service updates */
311
send_event("service reload dyndnsall");
312

    
313
/* Run a filter configure now that most all services have started */
314
filter_configure_sync();
315

    
316
/* setup pppoe and pptp */
317
vpn_setup();
318

    
319
/* start the captive portal */
320
captiveportal_configure();
321

    
322
/* start Voucher support */
323
voucher_configure();
324

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

    
328
/* start IPsec tunnels */
329
$ipsec_dynamic_hosts = vpn_ipsec_configure();
330

    
331
/* start SNMP service */
332
services_snmpd_configure();
333

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

    
337
/* lock down console if necessary */
338
reload_ttys();
339

    
340
/* load graphing functions */
341
enable_rrd_graphing();
342

    
343
/* enable watchdog if supported */
344
enable_watchdog();
345

    
346
/* if <system><afterbootupshellcmd> exists, execute the command */
347
if ($config['system']['afterbootupshellcmd'] <> "") {
348
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
349
	mwexec($config['system']['afterbootupshellcmd']);
350
}
351

    
352
if ($physmem < $g['minimum_ram_warning']) {
353
	require_once("/etc/inc/notices.inc");
354
	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);
355
	set_sysctl(array(
356
		"net.inet.tcp.recvspace" => "4096",
357
		"net.inet.tcp.sendspace" => "4096"
358
	));
359
}
360

    
361
/* if we are operating at 1000 then increase timeouts.
362
   this was never accounted for after moving to 1000 hz */
363
$kern_hz = get_single_sysctl('kern.clockrate');
364
$kern_hz = substr($kern_hz, strpos($kern_hz, "hz = ") + 5);
365
$kern_hz = substr($kern_hz, 0, strpos($kern_hz, ","));
366
if ($kern_hz == "1000") {
367
	set_single_sysctl("net.inet.tcp.rexmit_min" , "30");
368
}
369

    
370
/* start the igmpproxy daemon */
371
services_igmpproxy_configure();
372

    
373
/* start the upnp daemon if it is enabled */
374
upnp_start();
375

    
376
/* If powerd is enabled, lets launch it */
377
activate_powerd();
378

    
379
/* Set preferred protocol */
380
prefer_ipv4_or_ipv6();
381

    
382
/* Resync / Reinstall packages if need be */
383
if (file_exists('/conf/needs_package_sync')) {
384
	mark_subsystem_dirty('packagelock');
385
	if (package_reinstall_all()) {
386
		@unlink('/conf/needs_package_sync');
387
	}
388
	clear_subsystem_dirty('packagelock');
389
}
390

    
391
/* Detect installed binary pkgs that are not registered in the system */
392
register_all_installed_packages();
393

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

    
398
/* done */
399
unset($g['booting']);
400
@unlink("{$g['varrun_path']}/booting");
401

    
402
/* If there are ipsec dynamic hosts try again to reload the tunnels as rc.newipsecdns does */
403
if ($ipsec_dynamic_hosts) {
404
	vpn_ipsec_configure();
405
}
406
if ($ipsec_dynamic_hosts || !empty($filterdns)) {
407
	filter_configure();
408
}
409

    
410
led_normalize();
411

    
412

    
413
?>
(19-19/78)