Projet

Général

Profil

Télécharger (12,6 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / etc / rc.bootup @ master

1
#!/usr/local/bin/php -f
2
<?php
3
ini_set('apc.enabled', '0');
4

    
5
/* $Id$ */
6
/*
7
	rc.bootup
8
	part of pfSense by Scott Ullrich
9
	originally based on m0n0wall (http://m0n0.ch/wall)
10
	Copyright (C) 2004-2009 Scott Ullrich <sullrich@pfsense.org>.
11
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
12
	Copyright (C) 2009 Erik Kristensen
13
	All rights reserved.
14

    
15
	Redistribution and use in source and binary forms, with or without
16
	modification, are permitted provided that the following conditions are met:
17

    
18
	1. Redistributions of source code must retain the above copyright notice,
19
	   this list of conditions and the following disclaimer.
20

    
21
	2. Redistributions in binary form must reproduce the above copyright
22
	   notice, this list of conditions and the following disclaimer in the
23
	   documentation and/or other materials provided with the distribution.
24

    
25
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
26
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
29
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
	POSSIBILITY OF SUCH DAMAGE.
35
*/
36

    
37
function rescue_detect_keypress() {
38
	// How long do you want the script to wait before moving on (in seconds)
39
	$timeout=9;
40
	echo "\n";
41
    echo "[ Press R to enter recovery mode or ]\n";
42
	echo "[  press I to launch the installer  ]\n\n";
43
	echo "(R)ecovery mode can assist by rescuing config.xml\n";
44
	echo "from a broken hard disk installation, etc.\n\n";
45
	echo "(I)nstaller may be invoked now if you do \n";
46
	echo "not wish to boot into the liveCD environment at this time.\n\n";
47
	echo "(C) continues the LiveCD bootup without further pause.\n\n";
48
	echo "Timeout before auto boot continues (seconds): {$timeout}";
49
	$key = null;
50
	exec("/bin/stty erase " . chr(8));
51
	while(!in_array($key, array("c", "C", "r","R", "i", "I", "~", "!"))) {
52
	        echo chr(8) . "{$timeout}";
53
	        `/bin/stty -icanon min 0 time 25`;
54
	        $key = trim(`KEY=\`dd count=1 2>/dev/null\`; echo \$KEY`);
55
	        `/bin/stty icanon`;
56
	        // Decrement our timeout value
57
	        $timeout--;
58
	        // If we have reached 0 exit and continue on
59
	        if ($timeout == 0) 
60
				break;
61
	}
62
	// If R or I was pressed do our logic here
63
	if (in_array($key, array("r", "R"))) {
64
	  putenv("TERM=cons25");
65
	  echo "\n\nRecovery mode selected...\n";
66
	  passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer_rescue");
67
	} elseif (in_array($key, array("i", "I"))) {
68
	  putenv("TERM=cons25");
69
	  echo "\n\nInstaller mode selected...\n";
70
	  passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer");
71
	  if(file_exists("/tmp/install_complete")) {
72
		passthru("/etc/rc.reboot");
73
		exit;
74
	  }
75
	} elseif (in_array($key, array("!", "~"))) {
76
		putenv("TERM=cons25");
77
		echo "\n\nRecovery shell selected...\n";
78
		echo "\n";
79
		touch("/tmp/donotbootup");
80
		exit;
81
	} else {
82
		echo "\n\n";
83
	}
84
}
85

    
86
echo " done.\n";
87

    
88
echo "Initializing...";
89
echo ".";
90
require_once("/etc/inc/globals.inc");
91
echo ".";
92
require_once("/etc/inc/led.inc");
93
led_normalize();
94
echo ".";
95
if (led_count() >= 3) {
96
	led_kitt();
97
}
98

    
99
/* let the other functions know we're booting */
100
$pkg_interface = 'console';
101
$g['booting'] = true;
102

    
103
/* parse the configuration and include all functions used below */
104
require_once("/etc/inc/config.inc");
105
echo ".";
106
require_once("/etc/inc/config.console.inc");
107
echo ".";
108
require_once("/etc/inc/auth.inc");
109
echo ".";
110
require_once("/etc/inc/functions.inc");
111
echo ".";
112
require_once("/etc/inc/filter.inc");
113
echo ".";
114
require_once("/etc/inc/shaper.inc");
115
echo ".";
116
require_once("/etc/inc/ipsec.inc");
117
echo ".";
118
require_once("/etc/inc/vpn.inc");
119
echo ".";
120
require_once("/etc/inc/openvpn.inc");
121
echo ".";
122
require_once("/etc/inc/captiveportal.inc");
123
echo ".";
124
require_once("/etc/inc/rrd.inc");
125
echo ".";
126
require_once("/etc/inc/pfsense-utils.inc");
127
echo ".";
128

    
129
/* get system memory amount */
130
$memory = get_memory();
131
$physmem = $memory[0];
132
$realmem = $memory[1];
133
echo " done.\n";
134

    
135
conf_mount_rw();
136

    
137
/* save dmesg output to file */
138
system_dmesg_save();
139

    
140
/* check whether config reset is desired (via hardware button on WRAP/ALIX) */
141
system_check_reset_button();
142

    
143
/* remove previous firmware upgrade if present */
144
if (file_exists("/root/firmware.tgz")) 
145
	unlink("/root/firmware.tgz");
146

    
147
/* start devd (dhclient now uses it) */
148
echo "Starting device manager (devd)...";
149
mute_kernel_msgs();
150
start_devd();
151
set_device_perms();
152
unmute_kernel_msgs();
153
echo "done.\n";
154

    
155
// Display rescue configuration option
156
if($g['platform'] == "cdrom") 
157
		rescue_detect_keypress();
158

    
159
echo "Loading configuration...";
160
parse_config_bootup();
161
echo "done.\n";
162

    
163
if($g['platform'] == "jail") {
164
	/* We must determine what network settings have been configured for us */
165
	$wanif = "lo0";	/* defaults, if the jail admin hasn't set us up */
166
	$ipaddr = "127.0.0.1";
167
	$iflist = get_interface_list();
168
	foreach ($iflist as $iface => $ifa) {
169
		if (isset($ifa['ipaddr'])) {
170
			$wanif = $iface;
171
			$ipaddr = $ifa['ipaddr'];
172
			break;
173
		}
174
	}
175
	$config['interfaces'] = array();
176
	$config['interfaces']['lan'] = array();
177
	$config['interfaces']['lan']['enable'] = false;
178
	$config['interfaces']['wan'] = array();
179
	/* XXX, todo */
180
	$config['interfaces']['wan']['if'] = $wanif;
181
	$config['interfaces']['wan']['ipaddr'] = $ipaddr;
182
	$config['interfaces']['wan']['subnet'] = "32";	/* XXX right? */
183
	$config['interfaces']['wan']['enable'] = true;
184
	if($config['dhcpd']['lan']) 
185
		unset($config['dhcpd']['lan']['enable']);
186
	unlink_if_exists('/conf/trigger_initial_wizard');
187
	write_config();
188
} else {
189
	/*
190
	 *  Determine if we need to throw a interface exception
191
	 *  and ask the user to reassign interfaces.  This will
192
	 *  avoid a reboot and thats a good thing.
193
	 */
194
	while(is_interface_mismatch() == true) {
195
		led_assigninterfaces();
196
		if (isset($config['revision'])) {
197
			if (file_exists("{$g['tmp_path']}/missing_interfaces"))
198
				echo "Warning: Configuration references interfaces that do not exist: " . file_get_contents("{$g['tmp_path']}/missing_interfaces") . "\n";
199
			echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
200
		} else
201
			echo "\nDefault interfaces not found -- Running interface assignment option.\n";
202
		$ifaces = get_interface_list();
203
		if (is_array($ifaces)) {
204
			foreach($ifaces as $iface => $ifdata)
205
				interfaces_bring_up($iface);
206
		}
207
		set_networking_interfaces_ports();
208
		led_kitt();
209
	}
210
}
211

    
212
/* convert config and clean backups */
213
echo "Updating configuration...";
214
convert_config();
215
echo "done.\n";
216

    
217
echo "Cleaning backup cache...";
218
cleanup_backupcache(true);
219
echo "done.\n";
220

    
221
/* read in /etc/sysctl.conf and set values if needed */
222
echo "Setting up extended sysctls...";
223
system_setup_sysctl();
224
echo "done.\n";
225

    
226
/* enable optional crypto modules */
227
load_crypto();
228

    
229
/* enable optional thermal sensor modules */
230
load_thermal_hardware();
231

    
232
/* run any early shell commands specified in config.xml */
233
system_do_shell_commands(1);
234

    
235
/* set up our timezone */
236
system_timezone_configure();
237

    
238
/* set up our hostname */
239
system_hostname_configure();
240

    
241
/* make hosts file */
242
system_hosts_generate();
243

    
244
/* configure loopback interface */
245
interfaces_loopback_configure();
246

    
247
/* start syslogd */
248
system_syslogd_start();
249

    
250
echo "Starting Secure Shell Services...";
251
send_event("service reload sshd");
252
echo "done.\n";
253

    
254
/* setup polling */
255
echo "Setting up polling defaults...";
256
setup_polling();
257
echo "done.\n";
258

    
259
/* setup interface microcode which improves tcp/ip speed */
260
echo "Setting up interfaces microcode...";
261
setup_microcode();
262
echo "done.\n";
263

    
264
/* set up interfaces */
265
if(!$debugging)
266
	mute_kernel_msgs();
267
interfaces_configure();
268
interfaces_sync_setup();
269
if(!$debugging)
270
	unmute_kernel_msgs();
271

    
272
/* re-make hosts file after configuring interfaces */
273
system_hosts_generate();
274

    
275
/* start OpenVPN server & clients */
276
echo "Syncing OpenVPN settings...";
277
openvpn_resync_all();
278
echo "done.\n";
279

    
280
/* generate resolv.conf */
281
system_resolvconf_generate();
282

    
283
/* setup altq + pf */
284
filter_configure_sync();
285

    
286
/* start pflog */
287
echo "Starting PFLOG...";
288
filter_pflog_start();
289
echo "done.\n";
290

    
291
/* reconfigure our gateway monitor */
292
echo "Setting up gateway monitors...";
293
setup_gateways_monitor();
294
echo "done.\n";
295

    
296
echo "Synchronizing user settings...";
297
local_sync_accounts();
298
echo "done.\n";
299

    
300
if($realmem > 0 and $realmem < 65) {
301
	echo "System has less than 65 megabytes of ram {$realmem}.  Delaying webConfigurator startup.\n";
302
	/* start webConfigurator up on final pass */
303
	mwexec("/usr/local/sbin/pfSctl -c 'service restart webgui'");
304
} else {
305
	/* start web server */
306
	system_webgui_start();
307
}
308

    
309
/* configure cron service */
310
echo "Configuring CRON...";
311
configure_cron();
312
echo "done.\n";
313

    
314
/* set up static routes */
315
system_routing_configure();
316

    
317
/* enable routing */
318
system_routing_enable();
319

    
320
/* start dnsmasq service */
321
services_dnsmasq_configure();
322

    
323
/* start unbound service */
324
services_unbound_configure();
325

    
326
/* Do an initial time sync */
327
echo "Starting NTP time client...";
328
/* At bootup this will just write the config, ntpd will launch from ntpdate_sync_once.sh */
329
system_ntp_configure(false);
330
mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh", true);
331
echo "done.\n";
332

    
333
/* start load balancer daemon */
334
relayd_configure();
335

    
336
/* configure console menu */
337
system_console_configure();
338

    
339
/* start DHCP service */
340
services_dhcpd_configure();
341

    
342
/* start dhcpleases dhpcp hosts leases program */
343
system_dhcpleases_configure();
344

    
345
/* start DHCP relay */
346
services_dhcrelay_configure();
347

    
348
/* start DHCP6 relay */
349
services_dhcrelay6_configure();
350

    
351
/* dyndns service updates */
352
send_event("service reload dyndnsall");
353

    
354
/* Run a filter configure now that most all services have started */
355
filter_configure_sync();
356

    
357
/* setup pppoe and pptp */
358
vpn_setup();
359

    
360
/* start the captive portal */
361
captiveportal_configure();
362

    
363
/* start Voucher support */
364
voucher_configure();
365

    
366
/* run any shell commands specified in config.xml */
367
system_do_shell_commands();
368

    
369
/* start IPsec tunnels */
370
$ipsec_dynamic_hosts = vpn_ipsec_configure();
371

    
372
/* start SNMP service */
373
services_snmpd_configure();
374

    
375
/* power down hard drive if needed/set */
376
system_set_harddisk_standby();
377

    
378
/* lock down console if necessary */
379
reload_ttys();
380

    
381
/* load graphing functions */
382
enable_rrd_graphing();
383

    
384
/* enable watchdog if supported */
385
enable_watchdog();
386

    
387
/* if <system><afterbootupshellcmd> exists, execute the command */
388
if($config['system']['afterbootupshellcmd'] <> "") {
389
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
390
	mwexec($config['system']['afterbootupshellcmd']);
391
}
392

    
393
if($physmem < $g['minimum_ram_warning']) {
394
	require_once("/etc/inc/notices.inc");
395
	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);
396
	set_sysctl(array(
397
		"net.inet.tcp.recvspace" => "4096",
398
		"net.inet.tcp.sendspace" => "4096"
399
	));
400
}
401

    
402
/* if we are operating at 1000 then increase timeouts.
403
   this was never accounted for after moving to 1000 hz */
404
$kern_hz = get_single_sysctl('kern.clockrate');
405
$kern_hz = substr($kern_hz, strpos($kern_hz, "hz = ") + 5);
406
$kern_hz = substr($kern_hz, 0, strpos($kern_hz, ","));
407
if($kern_hz == "1000") 
408
	set_single_sysctl("net.inet.tcp.rexmit_min" , "30");
409

    
410
/* start the igmpproxy daemon */
411
services_igmpproxy_configure();
412

    
413
/* start the upnp daemon if it is enabled */
414
upnp_start();
415

    
416
/* If powerd is enabled, lets launch it */
417
activate_powerd();
418

    
419
/* Set preferred protocol */
420
prefer_ipv4_or_ipv6();
421

    
422
/* Remove the old shutdown binary if we kept it. */
423
if (file_exists("/sbin/shutdown.old"))
424
	@unlink("/sbin/shutdown.old");
425

    
426
/* Resync / Reinstall packages if need be */
427
if(file_exists('/conf/needs_package_sync')) {
428
	if($config['installedpackages'] <> '' && is_array($config['installedpackages']['package'])) {
429
		require_once("pkg-utils.inc");
430
		if($g['platform'] == "pfSense" || $g['platform'] == "nanobsd") {
431
			mark_subsystem_dirty('packagelock');
432
			pkg_reinstall_all();
433
			clear_subsystem_dirty('packagelock');
434
		}
435
	}
436
	@unlink('/conf/needs_package_sync');
437
}
438

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

    
443
/* done */
444
unset($g['booting']);
445

    
446
/* If there are ipsec dynamic hosts try again to reload the tunnels as rc.newipsecdns does */
447
if ($ipsec_dynamic_hosts) {
448
	vpn_ipsec_configure();
449
	filter_configure();
450
}
451

    
452
led_normalize();
453

    
454
conf_mount_ro();
455

    
456
?>
(33-33/103)