Project

General

Profile

Download (10.8 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
	@unlink('{$g['conf_path']}/needs_package_sync_after_reboot');
92
}
93

    
94
/* Triggering of the initial setup wizard after reboot has been requested */
95
if (file_exists('{$g['conf_path']}/trigger_initial_wizard_after_reboot')) {
96
	touch('{$g['conf_path']}/trigger_initial_wizard');
97
	@unlink('{$g['conf_path']}/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
mwexec("/usr/sbin/gnid > {$g['vardb_path']}/uniqueid 2>/dev/null");
113

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
395
/* done */
396
unset($g['booting']);
397
@unlink("{$g['varrun_path']}/booting");
398

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

    
407
led_normalize();
408

    
409
notify_all_remote("Bootup complete");
410
?>
(19-19/79)