Project

General

Profile

Download (10.9 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-2018 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("{$g['conf_path']}/needs_package_sync_after_reboot")) {
90
	touch("{$g['conf_path']}/needs_package_sync");
91
}
92

    
93
/* Triggering of the initial setup wizard after reboot has been requested */
94
if (file_exists("{$g['conf_path']}/trigger_initial_wizard_after_reboot")) {
95
	touch("{$g['conf_path']}/trigger_initial_wizard");
96
	@unlink("{$g['conf_path']}/trigger_initial_wizard_after_reboot");
97
}
98

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

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

    
111
mwexec("/usr/sbin/gnid > {$g['vardb_path']}/uniqueid 2>/dev/null");
112

    
113
/* run any early shell commands specified in config.xml */
114
system_do_shell_commands(1);
115

    
116
// Only do the alternate interface checks if:
117
// 1) The user has not yet run the initial wizard; and
118
// 2) The user has not used the console menu to setup interface assignments
119
if (file_exists("{$g['conf_path']}/trigger_initial_wizard") && !file_exists("{$g['conf_path']}/assign_complete")) {
120
	check_for_alternate_interfaces();
121
}
122

    
123
/* Convert configuration
124
 * This must happen before the interface mismatch test, see
125
 * https://redmine.pfsense.org/issues/7809 */
126
echo "Updating configuration...";
127
convert_config();
128
echo "done.\n";
129

    
130
/*
131
 *	Determine if we need to throw a interface exception
132
 *	and ask the user to reassign interfaces.  This will
133
 *	avoid a reboot and that is a good thing.
134
 */
135
while (is_interface_mismatch() == true) {
136
	led_assigninterfaces();
137
	if (isset($config['revision'])) {
138
		if (file_exists("{$g['tmp_path']}/missing_interfaces")) {
139
			echo "Warning: Configuration references interfaces that do not exist: " . file_get_contents("{$g['tmp_path']}/missing_interfaces") . "\n";
140
		}
141
		echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
142
	} else {
143
		echo "\nDefault interfaces not found -- Running interface assignment option.\n";
144
	}
145
	$ifaces = get_interface_list();
146
	if (is_array($ifaces)) {
147
		foreach ($ifaces as $iface => $ifdata) {
148
			interfaces_bring_up($iface);
149
		}
150
	}
151
	if (set_networking_interfaces_ports() == -1) {
152
		echo "\npfSense cannot continue without at least one Network Interface Card.\n";
153
		echo "\nHalting the system.\n";
154
		system("/sbin/shutdown -h now");
155
		exit(0);
156
	}
157
	reload_interfaces_sync();
158
	led_kitt();
159
}
160

    
161
echo "Checking config backups consistency...";
162
cleanup_backupcache(true);
163
echo "done.\n";
164

    
165
/* read in /etc/sysctl.conf and set values if needed */
166
echo "Setting up extended sysctls...";
167
system_setup_sysctl();
168
echo "done.\n";
169

    
170
/* enable optional crypto modules */
171
load_crypto();
172

    
173
/* enable optional thermal sensor modules */
174
load_thermal_hardware();
175

    
176
/* set up our timezone */
177
system_timezone_configure();
178

    
179
/* set up our hostname */
180
system_hostname_configure();
181

    
182
/* make hosts file */
183
system_hosts_generate();
184

    
185
/* configure loopback interface */
186
interfaces_loopback_configure();
187

    
188
/* start syslogd */
189
system_syslogd_start();
190

    
191
/* Log the RAM disk restore messages. */
192
if (file_exists("/var/log/restore_ramdisk_store.boot")) {
193
	exec("logger -f /var/log/restore_ramdisk_store.boot");
194
}
195

    
196
echo "Starting Secure Shell Services...";
197
send_event("service reload sshd");
198
echo "done.\n";
199

    
200
/* setup interface microcode which improves tcp/ip speed */
201
echo "Setting up interfaces microcode...";
202
setup_microcode();
203
echo "done.\n";
204

    
205
/* remove leftover dhcp6c lock files if they exist */
206
foreach ($config['interfaces'] as $interface) {
207
        if ($interface['ipaddrv6'] == "dhcp6") {
208
            if (file_exists("/tmp/dhcp6c_" . $interface['if'] . "_lock")) {
209
                @unlink("/tmp/dhcp6c_" . $interface['if'] . "_lock");
210
                echo("Removed leftover dhcp6c lock file: " . "/tmp/dhcp6c_" . $interface['if'] . "_lock\n");
211
            }
212
         }
213
     }
214

    
215
/* set up interfaces */
216
if (!$debugging) {
217
	mute_kernel_msgs();
218
}
219
interfaces_configure();
220
interfaces_sync_setup();
221
if (!$debugging) {
222
	unmute_kernel_msgs();
223
}
224

    
225
/* re-make hosts file after configuring interfaces */
226
system_hosts_generate();
227

    
228
/* start OpenVPN server & clients */
229
echo "Syncing OpenVPN settings...";
230
openvpn_resync_all();
231
echo "done.\n";
232

    
233
/* generate resolv.conf */
234
system_resolvconf_generate();
235

    
236
/* setup altq + pf */
237
filter_configure_sync();
238

    
239
/* start pflog */
240
echo "Starting PFLOG...";
241
filter_pflog_start();
242
echo "done.\n";
243

    
244
/* reconfigure our gateway monitor */
245
echo "Setting up gateway monitors...";
246
setup_gateways_monitor();
247
echo "done.\n";
248

    
249
/* set up static routes */
250
echo "Setting up static routes...";
251
system_routing_configure();
252
echo "done.\n";
253

    
254
echo "Setting up DNSs...";
255
/* start dnsmasq service */
256
services_dnsmasq_configure();
257

    
258
/* start unbound service */
259
services_unbound_configure();
260
echo "done.\n";
261

    
262
echo "Synchronizing user settings...";
263
local_reset_accounts();
264
echo "done.\n";
265

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

    
275
/* configure cron service */
276
echo "Configuring CRON...";
277
configure_cron();
278
echo "done.\n";
279

    
280
/* enable routing */
281
system_routing_enable();
282

    
283
/* Enable ntpd */
284
echo "Starting NTP time client...";
285
system_ntp_configure();
286
echo "done.\n";
287

    
288
/* start load balancer daemon */
289
relayd_configure();
290

    
291
/* configure console menu and serial port*/
292
setup_serial_port();
293

    
294
/* start DHCP service */
295
services_dhcpd_configure();
296

    
297
/* start dhcpleases dhcp hosts leases program */
298
system_dhcpleases_configure();
299

    
300
/* start DHCP relay */
301
services_dhcrelay_configure();
302

    
303
/* start DHCP6 relay */
304
services_dhcrelay6_configure();
305

    
306
/* dyndns service updates */
307
send_event("service reload dyndnsall");
308

    
309
/* Run a filter configure now that most all services have started */
310
filter_configure_sync();
311

    
312
/* setup pppoe and pptp */
313
vpn_setup();
314

    
315
/* start the captive portal */
316
captiveportal_configure();
317

    
318
/* start Voucher support */
319
voucher_configure();
320

    
321
/* run any shell commands specified in config.xml */
322
system_do_shell_commands();
323

    
324
/* start IPsec tunnels */
325
$ipsec_dynamic_hosts = vpn_ipsec_configure();
326

    
327
/* start SNMP service */
328
services_snmpd_configure();
329

    
330
/* power down hard drive if needed/set */
331
system_set_harddisk_standby();
332

    
333
/* lock down console if necessary */
334
reload_ttys();
335

    
336
/* load graphing functions */
337
enable_rrd_graphing();
338

    
339
/* enable watchdog if supported */
340
enable_watchdog();
341

    
342
/* if <system><afterbootupshellcmd> exists, execute the command */
343
if ($config['system']['afterbootupshellcmd'] <> "") {
344
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
345
	mwexec($config['system']['afterbootupshellcmd']);
346
}
347

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

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

    
366
/* start the igmpproxy daemon */
367
services_igmpproxy_configure();
368

    
369
/* start the upnp daemon if it is enabled */
370
upnp_start();
371

    
372
/* If powerd is enabled, lets launch it */
373
activate_powerd();
374

    
375
/* Set preferred protocol */
376
prefer_ipv4_or_ipv6();
377

    
378
/* Resync / Reinstall packages if need be */
379
if (file_exists("{$g['conf_path']}/needs_package_sync")) {
380
	mark_subsystem_dirty('packagelock');
381
	if (package_reinstall_all()) {
382
		@unlink("{$g['conf_path']}/needs_package_sync");
383
	}
384
	clear_subsystem_dirty('packagelock');
385
}
386

    
387
/* Detect installed binary pkgs that are not registered in the system */
388
register_all_installed_packages();
389

    
390
/* Now we used this file, delete it */
391
if (file_exists("{$g['conf_path']}/needs_package_sync_after_reboot")) {
392
	@unlink("{$g['conf_path']}/needs_package_sync_after_reboot");
393
}
394

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

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

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

    
411
led_normalize();
412

    
413
notify_all_remote("Bootup complete");
414
?>
(19-19/79)