Project

General

Profile

Download (17 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	system.inc
5
	part of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

    
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19

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

    
32
/* include all configuration functions */
33
require_once("functions.inc");
34

    
35
function system_resolvconf_generate($dynupdate = false) {
36
        global $config, $g;
37

    
38
        $syscfg = $config['system'];
39

    
40
        $fd = fopen("{$g['varetc_path']}/resolv.conf", "w");
41
        if (!$fd) {
42
                printf("Error: cannot open resolv.conf in system_resolvconf_generate().\n");
43
                return 1;
44
        }
45

    
46
        $resolvconf = "domain {$syscfg['domain']}\n";
47

    
48
        $havedns = false;
49

    
50
        if (isset($syscfg['dnsallowoverride'])) {
51
                /* get dynamically assigned DNS servers (if any) */
52
                $nfd = @fopen("{$g['varetc_path']}/nameservers.conf", "r");
53
                if ($nfd) {
54
                        while (!feof($nfd)) {
55
                                $dnss = trim(fgets($nfd));
56
                                if ($dnss) {
57
                                        $resolvconf .= "nameserver $dnss\n";
58
                                        $havedns = true;
59
                                }
60
                        }
61
                        fclose($nfd);
62
                }
63
                $nfd = @fopen("{$g['varetc_path']}/defaultdomain.conf", "r");
64
                if ($nfd and $havedns) {
65
                        while (!feof($nfd)) {
66
                                $dnss = trim(fgets($nfd));
67
                                if ($dnss) {
68
                                        $resolvconf .= "search $dnss\n";
69
                                }
70
                        }
71
                        fclose($nfd);
72
                }
73
        }
74
        if (!$havedns && is_array($syscfg['dnsserver'])) {
75
                foreach ($syscfg['dnsserver'] as $ns) {
76
                        if ($ns) {
77
				
78
                                $resolvconf .= "nameserver $ns\n";
79
				$havedns = true;
80
			}
81
                }
82
        }
83

    
84
	$ns = str_replace("nameserver nameserver ", "nameserver ", $resolvconf);
85

    
86
        fwrite($fd, $resolvconf);
87
        fclose($fd);
88

    
89
        if (!$g['booting']) {
90
                /* restart dhcpd (nameservers may have changed) */
91
                if (!$dynupdate)
92
                        services_dhcpd_configure();
93
        }
94

    
95
        return 0;
96
}
97

    
98
function system_hosts_generate() {
99
	global $config, $g;
100

    
101
	$syscfg = $config['system'];
102
	$lancfg = $config['interfaces']['lan'];
103
	$dnsmasqcfg = $config['dnsmasq'];
104

    
105
	if (!is_array($dnsmasqcfg['hosts'])) {
106
		$dnsmasqcfg['hosts'] = array();
107
	}
108
	$hostscfg = $dnsmasqcfg['hosts'];
109

    
110
	$fd = fopen("{$g['varetc_path']}/hosts", "w");
111
	if (!$fd) {
112
		printf("Error: cannot open hosts file in system_hosts_generate().\n");
113
		return 1;
114
	}
115

    
116
	$hosts = <<<EOD
117
127.0.0.1	localhost localhost.{$syscfg['domain']}
118
{$lancfg['ipaddr']}	{$syscfg['hostname']}.{$syscfg['domain']} {$syscfg['hostname']}
119

    
120
EOD;
121

    
122
	foreach ($hostscfg as $host) {
123
		if ($host['host'])
124
			$hosts .= "{$host['ip']}	{$host['host']}.{$host['domain']} {$host['host']}\n";
125
		else
126
			$hosts .= "{$host['ip']}	{$host['domain']}\n";
127
	}
128
	fwrite($fd, $hosts);
129
	fclose($fd);
130

    
131
	return 0;
132
}
133

    
134
function system_hostname_configure() {
135
	global $config, $g;
136

    
137
	$syscfg = $config['system'];
138

    
139
	/* set hostname */
140
	return mwexec("/bin/hostname " .
141
		escapeshellarg("{$syscfg['hostname']}.{$syscfg['domain']}"));
142
}
143

    
144
function system_routing_configure() {
145
	global $config, $g;
146

    
147
	/* Enable fast routing, if enabled */
148
	if(isset($config['staticroutes']['enablefastrouting']))
149
		mwexec("/sbin/sysctl net.inet.ip.fastforwarding=1");
150

    
151
	/* clear out old routes, if necessary */
152
	if (file_exists("{$g['vardb_path']}/routes.db")) {
153
		$fd = fopen("{$g['vardb_path']}/routes.db", "r");
154
		if (!$fd) {
155
			printf("Error: cannot open routes DB file in system_routing_configure().\n");
156
			return 1;
157
		}
158
		while (!feof($fd)) {
159
			$oldrt = fgets($fd);
160
			if ($oldrt)
161
				mwexec("/sbin/route delete " . escapeshellarg($oldrt));
162
		}
163
		fclose($fd);
164
		unlink("{$g['vardb_path']}/routes.db");
165
	}
166

    
167
	if (is_array($config['staticroutes']['route'])) {
168

    
169
		$fd = fopen("{$g['vardb_path']}/routes.db", "w");
170
		if (!$fd) {
171
			printf("Error: cannot open routes DB file in system_routing_configure().\n");
172
			return 1;
173
		}
174

    
175
		foreach ($config['staticroutes']['route'] as $rtent) {
176
			mwexec("/sbin/route add " . escapeshellarg($rtent['network']) .
177
				" " . escapeshellarg($rtent['gateway']));
178

    
179
			/* record route so it can be easily removed later (if necessary) */
180
			fwrite($fd, $rtent['network'] . "\n");
181
		}
182

    
183
		fclose($fd);
184
	}
185

    
186
	return 0;
187
}
188

    
189
function system_routing_enable() {
190
	global $config, $g;
191

    
192
	return mwexec("/sbin/sysctl net.inet.ip.forwarding=1");
193
}
194

    
195
function system_syslogd_start() {
196
	global $config, $g;
197

    
198
	$syslogcfg = $config['syslog'];
199

    
200
	if ($g['booting'])
201
		echo "Starting syslog... ";
202
	else
203
		killbypid("{$g['varrun_path']}/syslog.pid");
204

    
205
	if (isset($syslogcfg)) {
206
		if($config['installedpackages']['package']) {
207
                        foreach($config['installedpackages']['package'] as $package) {
208
                                if($package['logging']) {	
209
					$pkgfacilities[] = $package['logging']['facilityname'];
210
                                	$syslogconf .= '!' . $package['logging']['facilityname'] . "\n*.*\t\t\t\t\t\t%{$g['varlog_path']}/" . $package['logging']['logfilename'] . "\n";
211
				}
212
                        }
213
			if(is_array($pkgfacilities)) $syslogconf .= '!-' . implode(',', $pkgfacilities) . "\n";
214
                }
215

    
216
		/* write syslog.conf */
217
		$fd = fopen("{$g['varetc_path']}/syslog.conf", "w");
218
		if (!$fd) {
219
			printf("Error: cannot open syslog.conf in system_syslogd_start().\n");
220
			return 1;
221
		}
222
		if (!isset($syslogcfg['disablelocallogging'])) {
223
		$syslogconf .= <<<EOD
224
local0.*					%{$g['varlog_path']}/filter.log
225
local3.*					%{$g['varlog_path']}/vpn.log
226
local4.*					%{$g['varlog_path']}/portalauth.log
227
local7.*					%{$g['varlog_path']}/dhcpd.log
228
*.notice;kern.debug;lpr.info;mail.crit;		%{$g['varlog_path']}/system.log
229
news.err;local0.none;local3.none;local4.none;	%{$g['varlog_path']}/system.log
230
local7.none					%{$g['varlog_path']}/system.log
231
security.*					%{$g['varlog_path']}/system.log
232
auth.info;authpriv.info;daemon.info		%{$g['varlog_path']}/system.log
233
local1.*					%{$g['varlog_path']}/slbd.log
234
*.emerg						*
235

    
236
EOD;
237
		}
238

    
239
		if (isset($syslogcfg['filter'])) {
240
			$syslogconf .= <<<EOD
241
local0.*					@{$syslogcfg['remoteserver']}
242

    
243
EOD;
244
		}
245

    
246
		if (isset($syslogcfg['vpn'])) {
247
			$syslogconf .= <<<EOD
248
local3.*					@{$syslogcfg['remoteserver']}
249

    
250
EOD;
251
		}
252

    
253

    
254
		if (isset($syslogcfg['portalauth'])) {
255
			$syslogconf .= <<<EOD
256
local4.*					@{$syslogcfg['remoteserver']}
257

    
258
EOD;
259
		}
260

    
261

    
262
		if (isset($syslogcfg['dhcp'])) {
263
			$syslogconf .= <<<EOD
264
local7.*					@{$syslogcfg['remoteserver']}
265

    
266
EOD;
267
		}
268

    
269
		if (isset($syslogcfg['system'])) {
270
			$syslogconf .= <<<EOD
271
*.notice;kern.debug;lpr.info;mail.crit;		@{$syslogcfg['remoteserver']}
272
news.err;local0.none;local3.none;local7.none	@{$syslogcfg['remoteserver']}
273
security.*					@{$syslogcfg['remoteserver']}
274
auth.info;authpriv.info;daemon.info		@{$syslogcfg['remoteserver']}
275
*.emerg						@{$syslogcfg['remoteserver']}
276
EOD;
277
		}
278
		fwrite($fd, $syslogconf);
279
		fclose($fd);
280

    
281
		$retval = mwexec("/usr/sbin/syslogd -s -f {$g['varetc_path']}/syslog.conf");
282

    
283
	} else {
284
		$retval = mwexec("/usr/sbin/syslogd -ss");
285
	}
286

    
287
	if ($g['booting'])
288
		echo "done.\n";
289

    
290
	return $retval;
291
}
292

    
293
function system_pccard_start() {
294
	global $config, $g;
295

    
296
	if ($g['booting'])
297
		echo "Initializing PCMCIA... ";
298

    
299
	/* kill any running pccardd */
300
	killbypid("{$g['varrun_path']}/pccardd.pid");
301

    
302
	/* fire up pccardd */
303
	$res = mwexec("/usr/sbin/pccardd -z -f {$g['etc_path']}/pccard.conf");
304

    
305
	if ($g['booting']) {
306
		if ($res == 0)
307
			echo "done.\n";
308
		else
309
			echo "failed!\n";
310
	}
311

    
312
	return $res;
313
}
314

    
315
function system_webgui_start() {
316
	global $config, $g;
317

    
318
	if ($g['booting'])
319
		echo "Starting webGUI... ";
320

    
321
	/* kill any running mini_httpd */
322
	killbypid("{$g['varrun_path']}/mini_httpd.pid");
323

    
324
	/* generate password file */
325
	system_password_configure();
326

    
327
	chdir($g['www_path']);
328

    
329
	/* non-standard port? */
330
	if ($config['system']['webgui']['port'])
331
		$portarg = "-p {$config['system']['webgui']['port']}";
332
	else
333
		$portarg = "";
334

    
335
	if ($config['system']['webgui']['protocol'] == "https") {
336

    
337
		if ($config['system']['webgui']['certificate'] && $config['system']['webgui']['private-key']) {
338
			$cert = base64_decode($config['system']['webgui']['certificate']);
339
			$key = base64_decode($config['system']['webgui']['private-key']);
340
		} else {
341
			/* default certificate/key */
342
			$cert = <<<EOD
343
-----BEGIN CERTIFICATE-----
344
MIIC4zCCAkygAwIBAgIBADANBgkqhkiG9w0BAQQFADBbMQswCQYDVQQGEwJOQTEL
345
MAkGA1UECBMCTkExCzAJBgNVBAcTAk5BMQswCQYDVQQKEwJOQTELMAkGA1UECxMC
346
TkExCzAJBgNVBAMTAk5BMQswCQYDVQQGEwJVUzAeFw0wNTAzMDYwMDE1NDJaFw0x
347
NTAzMDQwMDE1NDJaMFsxCzAJBgNVBAYTAk5BMQswCQYDVQQIEwJOQTELMAkGA1UE
348
BxMCTkExCzAJBgNVBAoTAk5BMQswCQYDVQQLEwJOQTELMAkGA1UEAxMCTkExCzAJ
349
BgNVBAYTAlVTMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDF7luuy70OvHrl
350
xnW9ID6srsfxEFCF4d9LmlZ6XdW1rEUHQ6KTgz4iSD+pxEOxxlY+bCH6HTkAy5Sa
351
zt3eT7javvF+ILZgarwoY2x+NbDctd0VBJVkH0fEvBf1xqU7wpkOiWkw1RmfEvZI
352
6XnGi6VSjSmkm0UoQMKg9R7niRtE4QIDAQABo4G2MIGzMB0GA1UdDgQWBBTgvk9F
353
alPK6/OcZrkaE8BhBrRo2DCBgwYDVR0jBHwweoAU4L5PRWpTyuvznGa5GhPAYQa0
354
aNihX6RdMFsxCzAJBgNVBAYTAk5BMQswCQYDVQQIEwJOQTELMAkGA1UEBxMCTkEx
355
CzAJBgNVBAoTAk5BMQswCQYDVQQLEwJOQTELMAkGA1UEAxMCTkExCzAJBgNVBAYT
356
AlVTggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAv9+GXdYIWs2R
357
8B0zI4jAbHcaRsfohuzpNHD5re7ZK8H4fYbHIfmPY2UM3yOU7J2rLP8KGfKztay1
358
Z3RNW7SKJI/CagbdQOuYdMrlEyA4ZImM6NNzUbH6rNKtmDIDo1kHL3cXjzXEjBE+
359
ZZYTREFcdhtzUH5lYzJz1uVFeCSwozk=
360
-----END CERTIFICATE-----
361
EOD;
362

    
363
			$key = <<<EOD
364
-----BEGIN RSA PRIVATE KEY-----
365
MIICXAIBAAKBgQDF7luuy70OvHrlxnW9ID6srsfxEFCF4d9LmlZ6XdW1rEUHQ6KT
366
gz4iSD+pxEOxxlY+bCH6HTkAy5Sazt3eT7javvF+ILZgarwoY2x+NbDctd0VBJVk
367
H0fEvBf1xqU7wpkOiWkw1RmfEvZI6XnGi6VSjSmkm0UoQMKg9R7niRtE4QIDAQAB
368
AoGAF9dMJ9PWo+3EB+VNzUgTBI3Q+5JxgI7ibKLcg8TFtypW7jcRYB9Q3qRBNtuz
369
I7i2LrKrrQrUEOp0rej5BIwpwcjtEE2NsZwgYwDyywptoqt3WO86nPXYz2KhkQmP
370
YCDmPrff4vXCv6zgefb/AIgrOkgD3ViEoePhCAg+0l3fEIECQQD7C68Nb6KAWUND
371
Q9B0RxYrlgXikQ8yVHhlyM433APe/NCJ9kl5dLXpyjuvrWB+ml6TlLrcroLGejbd
372
tYXvIiyJAkEAydZVHqB4MpMtuY7VJoHNgl06YBoeTI+BJptPaOUNl4SlUKIYJMhX
373
oOXIGk9uDjfSNS7HvunZBjgz092GShWvmQJAQ8NhmwTZHj/58fwqFljh2R4DtKZn
374
LbSzUvYjA9z1holDWRoLtycTu2mFNuRbuZC9mqR40/ye/CgdCzdmUagt0QJBAKq1
375
00ySINd10Cive+yTwMPQIj2CGbpbbbq/hYyMntBWapQmZRFHOYZmkrZeFBGGeQ5u
376
QJdipiIyivNY2+nxKZECQCvumJPfZYxCeCAEC+G2xezrP6bC6FhzUOw6410UARTM
377
fuFjHpSfOiG62lfRdZgCPAr1L/1pJF+8RqjGlFfAuFA=
378
-----END RSA PRIVATE KEY-----
379
EOD;
380
		}
381

    
382
		$fd = fopen("{$g['varetc_path']}/cert.pem", "w");
383
		if (!$fd) {
384
			printf("Error: cannot open cert.pem in system_webgui_start().\n");
385
			return 1;
386
		}
387
		chmod("{$g['varetc_path']}/cert.pem", 0600);
388
		fwrite($fd, $cert);
389
		fwrite($fd, "\n");
390
		fwrite($fd, $key);
391
		fclose($fd);
392

    
393
		$res = mwexec("/usr/local/sbin/mini_httpd -S -E {$g['varetc_path']}/cert.pem" .
394
			" -c \"**.php|**.cgi\" -u root -maxproc 16 $portarg" .
395
			" -i {$g['varrun_path']}/mini_httpd.pid");
396
	} else {
397
		$res = mwexec("/usr/local/sbin/mini_httpd -c \"**.php|**.cgi\" -u root" .
398
			" -maxproc 16 $portarg -i {$g['varrun_path']}/mini_httpd.pid");
399
	}
400

    
401
	if ($g['booting']) {
402
		if ($res == 0)
403
			echo "done.\n";
404
		else
405
			echo "failed!\n";
406
	}
407

    
408
	return $res;
409
}
410

    
411
function system_password_configure() {
412
	global $config, $g;
413

    
414
	$fd = fopen("{$g['varrun_path']}/htpasswd", "w");
415
	if (!$fd) {
416
		printf("Error: cannot open htpasswd in system_password_configure().\n");
417
		return 1;
418
	}
419

    
420
	if ($config['system']['username'])
421
		$username = $config['system']['username'];
422
	else
423
		$username = "admin";
424

    
425
	fwrite($fd, $username . ":" . $config['system']['password'] . "\n");
426
	fclose($fd);
427
	chmod("{$g['varrun_path']}/htpasswd", 0600);
428

    
429
	return 0;
430
}
431

    
432
function system_timezone_configure() {
433
	global $config, $g;
434

    
435
	$syscfg = $config['system'];
436

    
437
	if ($g['booting'])
438
		echo "Setting timezone... ";
439

    
440
	/* extract appropriate timezone file */
441
	$timezone = $syscfg['timezone'];
442
	if (!$timezone)
443
		$timezone = "Etc/UTC";
444

    
445
	conf_mount_rw();
446

    
447
	exec("/usr/bin/tar xzfO /usr/share/zoneinfo.tgz " .
448
		escapeshellarg($timezone) . " > /etc/localtime");
449

    
450
	conf_mount_ro();
451

    
452
	if ($g['booting'])
453
		echo "done.\n";
454
}
455

    
456
function system_ntp_configure() {
457
	global $config, $g;
458

    
459
	$syscfg = $config['system'];
460

    
461
	if ($g['booting'])
462
		echo "Starting NTP client... ";
463
	else {
464
		killbypid("{$g['varrun_path']}/runmsntp.pid");
465
		killbypid("{$g['varrun_path']}/msntp.pid");
466
	}
467

    
468
	/* start ntp client if needed - needs to be forced into background */
469
	$updateinterval = $syscfg['time-update-interval'];
470

    
471
	if ($updateinterval > 0) {
472
		if ($updateinterval < 6)
473
			$updateinterval = 6;
474

    
475
		$timeservers = "";
476
		foreach (explode(' ', $syscfg['timeservers']) as $ts)
477
			$timeservers .= " " . $ts;
478

    
479
		mwexec_bg("/usr/local/bin/runmsntp.sh " .
480
			escapeshellarg("{$g['varrun_path']}/runmsntp.pid") . " " .
481
			escapeshellarg("{$g['varrun_path']}/msntp.pid") . " " .
482
			escapeshellarg($updateinterval) . " " .
483
			escapeshellarg($timeservers));
484
	}
485

    
486
	if ($g['booting'])
487
		echo "done.\n";
488
}
489

    
490
function system_halt() {
491
	global $g;
492

    
493
	system_reboot_cleanup();
494

    
495
	mwexec("nohup /etc/rc.halt > /dev/null 2>&1 &");
496
}
497

    
498
function system_reboot() {
499
	global $g;
500

    
501
	system_reboot_cleanup();
502

    
503
	mwexec("nohup /etc/rc.reboot > /dev/null 2>&1 &");
504
}
505

    
506
function system_reboot_sync() {
507
	global $g;
508

    
509
	system_reboot_cleanup();
510

    
511
	mwexec("/etc/rc.reboot > /dev/null 2>&1");
512
}
513

    
514
function system_reboot_cleanup() {
515
	captiveportal_radius_stop_all();
516
}
517

    
518
function system_do_shell_commands($early = 0) {
519
	global $config, $g;
520

    
521
	if ($early)
522
		$cmdn = "earlyshellcmd";
523
	else
524
		$cmdn = "shellcmd";
525

    
526
	if (is_array($config['system'][$cmdn])) {
527

    
528
		foreach ($config['system'][$cmdn] as $cmd) {
529
			exec($cmd);
530
		}
531
	}
532
}
533

    
534
function system_do_extensions($early = false) {
535
	global $config, $g;
536

    
537
	if (!is_dir("{$g['etc_path']}/inc/ext"))
538
		return;
539

    
540
	$dh = @opendir("{$g['etc_path']}/inc/ext");
541
	if ($dh) {
542
		while (($extd = readdir($dh)) !== false) {
543
			if (($extd === ".") || ($extd === ".."))
544
				continue;
545
			$rcfile = "{$g['etc_path']}/inc/ext/" . $extd . "/" . ($early ? "rc.early" : "rc");
546
			if (file_exists($rcfile))
547
				passthru($rcfile);
548
		}
549
		closedir($dh);
550
	}
551
}
552

    
553
function system_console_configure() {
554
	global $config, $g;
555

    
556
	if (isset($config['system']['disableconsolemenu'])) {
557
		touch("{$g['varetc_path']}/disableconsole");
558
	} else {
559
		unlink_if_exists("{$g['varetc_path']}/disableconsole");
560
	}
561
}
562

    
563
function system_dmesg_save() {
564
	global $g;
565

    
566
	exec("/sbin/dmesg", $dmesg);
567

    
568
	/* find last copyright line (output from previous boots may be present) */
569
	$lastcpline = 0;
570

    
571
	for ($i = 0; $i < count($dmesg); $i++) {
572
		if (strstr($dmesg[$i], "Copyright (c) 1992-"))
573
			$lastcpline = $i;
574
	}
575

    
576
	$fd = fopen("{$g['varlog_path']}/dmesg.boot", "w");
577
	if (!$fd) {
578
		printf("Error: cannot open dmesg.boot in system_dmesg_save().\n");
579
		return 1;
580
	}
581

    
582
	for ($i = $lastcpline; $i < count($dmesg); $i++)
583
		fwrite($fd, $dmesg[$i] . "\n");
584

    
585
	fclose($fd);
586

    
587
	return 0;
588
}
589

    
590
function system_set_harddisk_standby() {
591
	global $g, $config;
592

    
593
	if ($g['platform'] != "generic-pc")
594
		return;
595

    
596
	if (isset($config['system']['harddiskstandby'])) {
597
		if ($g['booting']) {
598
			echo 'Setting hard disk standby... ';
599
		}
600

    
601
		$standby = $config['system']['harddiskstandby'];
602
		// Check for a numeric value
603
		if (is_numeric($standby)) {
604
			// Sync the disk(s)
605
			mwexec('/bin/sync');
606
			if (!mwexec('/sbin/sysctl hw.ata.standby=' . ((int)$standby))) {
607
				// Reinitialize ATA-drives
608
				mwexec('/usr/local/sbin/atareinit');
609
				if ($g['booting']) {
610
					echo "done.\n";
611
				}
612
			} else if ($g['booting']) {
613
				echo "failed!\n";
614
			}
615
		} else if ($g['booting']) {
616
			echo "failed!\n";
617
		}
618
	}
619
}
620

    
621
function system_setup_sysctl() {
622
	global $config;
623

    
624
	$sysctl = return_filename_as_array("/etc/sysctl.conf");
625
	foreach($sysctl as $sysc) {
626
		if($sysc <> "")
627
			mwexec("sysctl {$sysc}");
628
	}
629
	if (isset($config['system']['sharednet'])) {
630
		system_disable_arp_wrong_if();
631
	}
632
}
633

    
634
function system_disable_arp_wrong_if() {
635
	mwexec("/sbin/sysctl -n net.link.ether.inet.log_arp_wrong_iface=0");
636
}
637

    
638
function system_enable_arp_wrong_if() {
639
	mwexec("/sbin/sysctl -n net.link.ether.inet.log_arp_wrong_iface=1");
640
}
641

    
642

    
643
?>
(16-16/23)