Project

General

Profile

Download (9.67 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
/* run any early shell commands specified in config.xml */
113
system_do_shell_commands(1);
114

    
115
if (file_exists("/conf/trigger_initial_wizard")) {
116
	check_for_alternate_interfaces();
117
}
118

    
119
/*
120
 *	Determine if we need to throw a interface exception
121
 *	and ask the user to reassign interfaces.  This will
122
 *	avoid a reboot and that is a good thing.
123
 */
124
while (is_interface_mismatch() == true) {
125
	led_assigninterfaces();
126
	if (isset($config['revision'])) {
127
		if (file_exists("{$g['tmp_path']}/missing_interfaces")) {
128
			echo "Warning: Configuration references interfaces that do not exist: " . file_get_contents("{$g['tmp_path']}/missing_interfaces") . "\n";
129
		}
130
		echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
131
	} else {
132
		echo "\nDefault interfaces not found -- Running interface assignment option.\n";
133
	}
134
	$ifaces = get_interface_list();
135
	if (is_array($ifaces)) {
136
		foreach ($ifaces as $iface => $ifdata) {
137
			interfaces_bring_up($iface);
138
		}
139
	}
140
	set_networking_interfaces_ports();
141
	led_kitt();
142
}
143

    
144
/* convert config and clean backups */
145
echo "Updating configuration...";
146
convert_config();
147
echo "done.\n";
148

    
149
echo "Cleaning backup cache...";
150
cleanup_backupcache(true);
151
echo "done.\n";
152

    
153
/* read in /etc/sysctl.conf and set values if needed */
154
echo "Setting up extended sysctls...";
155
system_setup_sysctl();
156
echo "done.\n";
157

    
158
/* enable optional crypto modules */
159
load_crypto();
160

    
161
/* enable optional thermal sensor modules */
162
load_thermal_hardware();
163

    
164
/* set up our timezone */
165
system_timezone_configure();
166

    
167
/* set up our hostname */
168
system_hostname_configure();
169

    
170
/* make hosts file */
171
system_hosts_generate();
172

    
173
/* configure loopback interface */
174
interfaces_loopback_configure();
175

    
176
/* start syslogd */
177
system_syslogd_start();
178

    
179
/* restore alias tables */
180
restore_aliastables();
181

    
182
echo "Starting Secure Shell Services...";
183
send_event("service reload sshd");
184
echo "done.\n";
185

    
186
/* setup polling */
187
echo "Setting up polling defaults...";
188
setup_polling();
189
echo "done.\n";
190

    
191
/* setup interface microcode which improves tcp/ip speed */
192
echo "Setting up interfaces microcode...";
193
setup_microcode();
194
echo "done.\n";
195

    
196
/* set up interfaces */
197
if (!$debugging) {
198
	mute_kernel_msgs();
199
}
200
interfaces_configure();
201
interfaces_sync_setup();
202
if (!$debugging) {
203
	unmute_kernel_msgs();
204
}
205

    
206
/* re-make hosts file after configuring interfaces */
207
system_hosts_generate();
208

    
209
/* start OpenVPN server & clients */
210
echo "Syncing OpenVPN settings...";
211
openvpn_resync_all();
212
echo "done.\n";
213

    
214
/* generate resolv.conf */
215
system_resolvconf_generate();
216

    
217
/* setup altq + pf */
218
filter_configure_sync();
219

    
220
/* start pflog */
221
echo "Starting PFLOG...";
222
filter_pflog_start();
223
echo "done.\n";
224

    
225
/* reconfigure our gateway monitor */
226
echo "Setting up gateway monitors...";
227
setup_gateways_monitor();
228
echo "done.\n";
229

    
230
/* set up static routes */
231
system_routing_configure();
232

    
233
/* start dnsmasq service */
234
services_dnsmasq_configure();
235

    
236
/* start unbound service */
237
services_unbound_configure();
238

    
239
echo "Synchronizing user settings...";
240
local_sync_accounts();
241
echo "done.\n";
242

    
243
if ($realmem > 0 and $realmem < 65) {
244
	echo "System has less than 65 megabytes of ram {$realmem}.  Delaying webConfigurator startup.\n";
245
	/* start webConfigurator up on final pass */
246
	mwexec("/usr/local/sbin/pfSctl -c 'service restart webgui'");
247
} else {
248
	/* start web server */
249
	system_webgui_start();
250
}
251

    
252
/* configure cron service */
253
echo "Configuring CRON...";
254
configure_cron();
255
echo "done.\n";
256

    
257
/* enable routing */
258
system_routing_enable();
259

    
260
/* Enable ntpd */
261
echo "Starting NTP time client...";
262
system_ntp_configure();
263
echo "done.\n";
264

    
265
/* start load balancer daemon */
266
relayd_configure();
267

    
268
/* configure console menu and serial port*/
269
setup_serial_port();
270

    
271
/* start DHCP service */
272
services_dhcpd_configure();
273

    
274
/* start dhcpleases dhcp hosts leases program */
275
system_dhcpleases_configure();
276

    
277
/* start DHCP relay */
278
services_dhcrelay_configure();
279

    
280
/* start DHCP6 relay */
281
services_dhcrelay6_configure();
282

    
283
/* dyndns service updates */
284
send_event("service reload dyndnsall");
285

    
286
/* Run a filter configure now that most all services have started */
287
filter_configure_sync();
288

    
289
/* setup pppoe and pptp */
290
vpn_setup();
291

    
292
/* start the captive portal */
293
captiveportal_configure();
294

    
295
/* start Voucher support */
296
voucher_configure();
297

    
298
/* run any shell commands specified in config.xml */
299
system_do_shell_commands();
300

    
301
/* start IPsec tunnels */
302
$ipsec_dynamic_hosts = vpn_ipsec_configure();
303

    
304
/* start SNMP service */
305
services_snmpd_configure();
306

    
307
/* power down hard drive if needed/set */
308
system_set_harddisk_standby();
309

    
310
/* lock down console if necessary */
311
reload_ttys();
312

    
313
/* load graphing functions */
314
enable_rrd_graphing();
315

    
316
/* enable watchdog if supported */
317
enable_watchdog();
318

    
319
/* if <system><afterbootupshellcmd> exists, execute the command */
320
if ($config['system']['afterbootupshellcmd'] <> "") {
321
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
322
	mwexec($config['system']['afterbootupshellcmd']);
323
}
324

    
325
if ($physmem < $g['minimum_ram_warning']) {
326
	require_once("/etc/inc/notices.inc");
327
	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);
328
	set_sysctl(array(
329
		"net.inet.tcp.recvspace" => "4096",
330
		"net.inet.tcp.sendspace" => "4096"
331
	));
332
}
333

    
334
/* if we are operating at 1000 then increase timeouts.
335
   this was never accounted for after moving to 1000 hz */
336
$kern_hz = get_single_sysctl('kern.clockrate');
337
$kern_hz = substr($kern_hz, strpos($kern_hz, "hz = ") + 5);
338
$kern_hz = substr($kern_hz, 0, strpos($kern_hz, ","));
339
if ($kern_hz == "1000") {
340
	set_single_sysctl("net.inet.tcp.rexmit_min" , "30");
341
}
342

    
343
/* start the igmpproxy daemon */
344
services_igmpproxy_configure();
345

    
346
/* start the upnp daemon if it is enabled */
347
upnp_start();
348

    
349
/* If powerd is enabled, lets launch it */
350
activate_powerd();
351

    
352
/* Set preferred protocol */
353
prefer_ipv4_or_ipv6();
354

    
355
/* Remove the old shutdown binary if we kept it. */
356
if (file_exists("/sbin/shutdown.old")) {
357
	@unlink("/sbin/shutdown.old");
358
}
359

    
360
/* Resync / Reinstall packages if need be */
361
if (file_exists('/conf/needs_package_sync')) {
362
	mark_subsystem_dirty('packagelock');
363
	if (package_reinstall_all()) {
364
		@unlink('/conf/needs_package_sync');
365
	}
366
	clear_subsystem_dirty('packagelock');
367
}
368

    
369
/* Detect installed binary pkgs that are not registered in the system */
370
register_all_installed_packages();
371

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

    
376
/* done */
377
unset($g['booting']);
378
@unlink("{$g['varrun_path']}/booting");
379

    
380
/* If there are ipsec dynamic hosts try again to reload the tunnels as rc.newipsecdns does */
381
if ($ipsec_dynamic_hosts) {
382
	vpn_ipsec_configure();
383
}
384
if ($ipsec_dynamic_hosts || !empty($filterdns)) {
385
	filter_configure();
386
}
387

    
388
led_normalize();
389

    
390

    
391
?>
(18-18/77)