Project

General

Profile

Download (15.8 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.new", "w");
41
	if (!$fd) {
42
		printf("Error: cannot open resolv.conf.new 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 for ppp (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
	}
64

    
65
	/* if we didn't get assigned DNS servers and have some set add 'em */
66
	if (!$havedns && is_array($syscfg['dnsserver'])) {
67
		foreach ($syscfg['dnsserver'] as $ns) {
68
			if ($ns)
69
				$resolvconf .= "nameserver $ns\n";
70
			$havedns = true;
71
		}
72
	}
73

    
74
	fwrite($fd, $resolvconf);
75
	fclose($fd);
76

    
77
	/* If we now have DNS servers, overwrite resolv.conf */
78
	if ($havedns) {
79
		if (file_exists("{$g['varetc_path']}/resolv.conf"))
80
			unlink("{$g['varetc_path']}/resolv.conf");
81
		rename("{$g['varetc_path']}/resolv.conf.new", "{$g['varetc_path']}/resolv.conf");
82
	} else {
83
		unlink("{$g['varetc_path']}/resolv.conf.new");
84
	}
85

    
86

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

    
93
	return 0;
94
}
95

    
96
function system_hosts_generate() {
97
	global $config, $g;
98

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

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

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

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

    
118
EOD;
119

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

    
129
	return 0;
130
}
131

    
132
function system_hostname_configure() {
133
	global $config, $g;
134

    
135
	$syscfg = $config['system'];
136

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

    
142
function system_routing_configure() {
143
	global $config, $g;
144

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

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

    
165
	if (is_array($config['staticroutes']['route'])) {
166

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

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

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

    
181
		fclose($fd);
182
	}
183

    
184
	return 0;
185
}
186

    
187
function system_routing_enable() {
188
	global $config, $g;
189

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

    
193
function system_syslogd_start() {
194
	global $config, $g;
195

    
196
	$syslogcfg = $config['syslog'];
197

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

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

    
214
		/* write syslog.conf */
215
		$fd = fopen("{$g['varetc_path']}/syslog.conf", "w");
216
		if (!$fd) {
217
			printf("Error: cannot open syslog.conf in system_syslogd_start().\n");
218
			return 1;
219
		}
220

    
221
		$syslogconf .= <<<EOD
222
local0.*					%{$g['varlog_path']}/filter.log
223
local3.*					%{$g['varlog_path']}/vpn.log
224
local4.*					%{$g['varlog_path']}/portalauth.log
225
local7.*					%{$g['varlog_path']}/dhcpd.log
226
*.notice;kern.debug;lpr.info;mail.crit;news.err;local0.none;local3.none;local4.none;local7.none %{$g['varlog_path']}/system.log
227
security.*					%{$g['varlog_path']}/system.log
228
auth.info;authpriv.info;daemon.info		%{$g['varlog_path']}/system.log
229
*.emerg						*
230

    
231
EOD;
232

    
233
		if (isset($syslogcfg['filter'])) {
234
			$syslogconf .= <<<EOD
235
local0.*					@{$syslogcfg['remoteserver']}
236

    
237
EOD;
238
		}
239

    
240
		if (isset($syslogcfg['vpn'])) {
241
			$syslogconf .= <<<EOD
242
local3.*					@{$syslogcfg['remoteserver']}
243
EOD;
244
		}
245

    
246

    
247
		if (isset($syslogcfg['portalauth'])) {
248
			$syslogconf .= <<<EOD
249
local4.*					@{$syslogcfg['remoteserver']}
250
EOD;
251
		}
252

    
253

    
254
		if (isset($syslogcfg['dhcp'])) {
255
			$syslogconf .= <<<EOD
256
local7.*					@{$syslogcfg['remoteserver']}
257
EOD;
258
		}
259

    
260
		if (isset($syslogcfg['system'])) {
261
			$syslogconf .= <<<EOD
262
*.notice;kern.debug;lpr.info;mail.crit;news.err;local0.none;local3.none;local7.none @{$syslogcfg['remoteserver']}
263
security.*					@{$syslogcfg['remoteserver']}
264
auth.info;authpriv.info;daemon.info		@{$syslogcfg['remoteserver']}
265
*.emerg						@{$syslogcfg['remoteserver']}
266
EOD;
267
		}
268
		fwrite($fd, $syslogconf);
269
		fclose($fd);
270

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

    
273
	} else {
274
		$retval = mwexec("/usr/sbin/syslogd -ss");
275
	}
276

    
277
	if ($g['booting'])
278
		echo "done.\n";
279

    
280
	return $retval;
281
}
282

    
283
function system_pccard_start() {
284
	global $config, $g;
285

    
286
	if ($g['booting'])
287
		echo "Initializing PCMCIA... ";
288

    
289
	/* kill any running pccardd */
290
	killbypid("{$g['varrun_path']}/pccardd.pid");
291

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

    
295
	if ($g['booting']) {
296
		if ($res == 0)
297
			echo "done.\n";
298
		else
299
			echo "failed!\n";
300
	}
301

    
302
	return $res;
303
}
304

    
305
function system_webgui_start() {
306
	global $config, $g;
307

    
308
	if ($g['booting'])
309
		echo "Starting webGUI... ";
310

    
311
	/* kill any running mini_httpd */
312
	killbypid("{$g['varrun_path']}/mini_httpd.pid");
313

    
314
	/* generate password file */
315
	system_password_configure();
316

    
317
	chdir($g['www_path']);
318

    
319
	/* non-standard port? */
320
	if ($config['system']['webgui']['port'])
321
		$portarg = "-p {$config['system']['webgui']['port']}";
322
	else
323
		$portarg = "";
324

    
325
	if ($config['system']['webgui']['protocol'] == "https") {
326

    
327
		if ($config['system']['webgui']['certificate'] && $config['system']['webgui']['private-key']) {
328
			$cert = base64_decode($config['system']['webgui']['certificate']);
329
			$key = base64_decode($config['system']['webgui']['private-key']);
330
		} else {
331
			/* default certificate/key */
332
			$cert = <<<EOD
333
-----BEGIN CERTIFICATE-----
334
MIIC4zCCAkygAwIBAgIBADANBgkqhkiG9w0BAQQFADBbMQswCQYDVQQGEwJOQTEL
335
MAkGA1UECBMCTkExCzAJBgNVBAcTAk5BMQswCQYDVQQKEwJOQTELMAkGA1UECxMC
336
TkExCzAJBgNVBAMTAk5BMQswCQYDVQQGEwJVUzAeFw0wNTAzMDYwMDE1NDJaFw0x
337
NTAzMDQwMDE1NDJaMFsxCzAJBgNVBAYTAk5BMQswCQYDVQQIEwJOQTELMAkGA1UE
338
BxMCTkExCzAJBgNVBAoTAk5BMQswCQYDVQQLEwJOQTELMAkGA1UEAxMCTkExCzAJ
339
BgNVBAYTAlVTMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDF7luuy70OvHrl
340
xnW9ID6srsfxEFCF4d9LmlZ6XdW1rEUHQ6KTgz4iSD+pxEOxxlY+bCH6HTkAy5Sa
341
zt3eT7javvF+ILZgarwoY2x+NbDctd0VBJVkH0fEvBf1xqU7wpkOiWkw1RmfEvZI
342
6XnGi6VSjSmkm0UoQMKg9R7niRtE4QIDAQABo4G2MIGzMB0GA1UdDgQWBBTgvk9F
343
alPK6/OcZrkaE8BhBrRo2DCBgwYDVR0jBHwweoAU4L5PRWpTyuvznGa5GhPAYQa0
344
aNihX6RdMFsxCzAJBgNVBAYTAk5BMQswCQYDVQQIEwJOQTELMAkGA1UEBxMCTkEx
345
CzAJBgNVBAoTAk5BMQswCQYDVQQLEwJOQTELMAkGA1UEAxMCTkExCzAJBgNVBAYT
346
AlVTggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAv9+GXdYIWs2R
347
8B0zI4jAbHcaRsfohuzpNHD5re7ZK8H4fYbHIfmPY2UM3yOU7J2rLP8KGfKztay1
348
Z3RNW7SKJI/CagbdQOuYdMrlEyA4ZImM6NNzUbH6rNKtmDIDo1kHL3cXjzXEjBE+
349
ZZYTREFcdhtzUH5lYzJz1uVFeCSwozk=
350
-----END CERTIFICATE-----
351
EOD;
352

    
353
			$key = <<<EOD
354
-----BEGIN RSA PRIVATE KEY-----
355
MIICXAIBAAKBgQDF7luuy70OvHrlxnW9ID6srsfxEFCF4d9LmlZ6XdW1rEUHQ6KT
356
gz4iSD+pxEOxxlY+bCH6HTkAy5Sazt3eT7javvF+ILZgarwoY2x+NbDctd0VBJVk
357
H0fEvBf1xqU7wpkOiWkw1RmfEvZI6XnGi6VSjSmkm0UoQMKg9R7niRtE4QIDAQAB
358
AoGAF9dMJ9PWo+3EB+VNzUgTBI3Q+5JxgI7ibKLcg8TFtypW7jcRYB9Q3qRBNtuz
359
I7i2LrKrrQrUEOp0rej5BIwpwcjtEE2NsZwgYwDyywptoqt3WO86nPXYz2KhkQmP
360
YCDmPrff4vXCv6zgefb/AIgrOkgD3ViEoePhCAg+0l3fEIECQQD7C68Nb6KAWUND
361
Q9B0RxYrlgXikQ8yVHhlyM433APe/NCJ9kl5dLXpyjuvrWB+ml6TlLrcroLGejbd
362
tYXvIiyJAkEAydZVHqB4MpMtuY7VJoHNgl06YBoeTI+BJptPaOUNl4SlUKIYJMhX
363
oOXIGk9uDjfSNS7HvunZBjgz092GShWvmQJAQ8NhmwTZHj/58fwqFljh2R4DtKZn
364
LbSzUvYjA9z1holDWRoLtycTu2mFNuRbuZC9mqR40/ye/CgdCzdmUagt0QJBAKq1
365
00ySINd10Cive+yTwMPQIj2CGbpbbbq/hYyMntBWapQmZRFHOYZmkrZeFBGGeQ5u
366
QJdipiIyivNY2+nxKZECQCvumJPfZYxCeCAEC+G2xezrP6bC6FhzUOw6410UARTM
367
fuFjHpSfOiG62lfRdZgCPAr1L/1pJF+8RqjGlFfAuFA=
368
-----END RSA PRIVATE KEY-----
369
EOD;
370
		}
371

    
372
		$fd = fopen("{$g['varetc_path']}/cert.pem", "w");
373
		if (!$fd) {
374
			printf("Error: cannot open cert.pem in system_webgui_start().\n");
375
			return 1;
376
		}
377
		chmod("{$g['varetc_path']}/cert.pem", 0600);
378
		fwrite($fd, $cert);
379
		fwrite($fd, "\n");
380
		fwrite($fd, $key);
381
		fclose($fd);
382

    
383
		$res = mwexec("/usr/local/sbin/mini_httpd -S -E {$g['varetc_path']}/cert.pem" .
384
			" -c \"**.php|**.cgi\" -u root -maxproc 16 $portarg" .
385
			" -i {$g['varrun_path']}/mini_httpd.pid");
386
	} else {
387
		$res = mwexec("/usr/local/sbin/mini_httpd -c \"**.php|**.cgi\" -u root" .
388
			" -maxproc 16 $portarg -i {$g['varrun_path']}/mini_httpd.pid");
389
	}
390

    
391
	if ($g['booting']) {
392
		if ($res == 0)
393
			echo "done.\n";
394
		else
395
			echo "failed!\n";
396
	}
397

    
398
	return $res;
399
}
400

    
401
function system_password_configure() {
402
	global $config, $g;
403

    
404
	$fd = fopen("{$g['varrun_path']}/htpasswd", "w");
405
	if (!$fd) {
406
		printf("Error: cannot open htpasswd in system_password_configure().\n");
407
		return 1;
408
	}
409

    
410
	if ($config['system']['username'])
411
		$username = $config['system']['username'];
412
	else
413
		$username = "admin";
414

    
415
	fwrite($fd, $username . ":" . $config['system']['password'] . "\n");
416
	fclose($fd);
417
	chmod("{$g['varrun_path']}/htpasswd", 0600);
418

    
419
	return 0;
420
}
421

    
422
function system_timezone_configure() {
423
	global $config, $g;
424

    
425
	$syscfg = $config['system'];
426

    
427
	if ($g['booting'])
428
		echo "Setting timezone... ";
429

    
430
	/* extract appropriate timezone file */
431
	$timezone = $syscfg['timezone'];
432
	if (!$timezone)
433
		$timezone = "Etc/UTC";
434

    
435
	conf_mount_rw();
436

    
437
	exec("/usr/bin/tar xzfO /usr/share/zoneinfo.tgz " .
438
		escapeshellarg($timezone) . " > /etc/localtime");
439

    
440
	conf_mount_ro();
441

    
442
	if ($g['booting'])
443
		echo "done.\n";
444
}
445

    
446
function system_ntp_configure() {
447
	global $config, $g;
448

    
449
	$syscfg = $config['system'];
450

    
451
	if ($g['booting'])
452
		echo "Starting NTP client... ";
453
	else {
454
		killbypid("{$g['varrun_path']}/runmsntp.pid");
455
		killbypid("{$g['varrun_path']}/msntp.pid");
456
	}
457

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

    
461
	if ($updateinterval > 0) {
462
		if ($updateinterval < 6)
463
			$updateinterval = 6;
464

    
465
		$timeservers = "";
466
		foreach (explode(' ', $syscfg['timeservers']) as $ts)
467
			$timeservers .= " " . $ts;
468

    
469
		mwexec_bg("/usr/local/bin/runmsntp.sh " .
470
			escapeshellarg("{$g['varrun_path']}/runmsntp.pid") . " " .
471
			escapeshellarg("{$g['varrun_path']}/msntp.pid") . " " .
472
			escapeshellarg($updateinterval) . " " .
473
			escapeshellarg($timeservers));
474
	}
475

    
476
	if ($g['booting'])
477
		echo "done.\n";
478
}
479

    
480
function system_halt() {
481
	global $g;
482

    
483
	system_reboot_cleanup();
484

    
485
	mwexec("nohup /etc/rc.halt > /dev/null 2>&1 &");
486
}
487

    
488
function system_reboot() {
489
	global $g;
490

    
491
	system_reboot_cleanup();
492

    
493
	mwexec("nohup /etc/rc.reboot > /dev/null 2>&1 &");
494
}
495

    
496
function system_reboot_sync() {
497
	global $g;
498

    
499
	system_reboot_cleanup();
500

    
501
	mwexec("/etc/rc.reboot > /dev/null 2>&1");
502
}
503

    
504
function system_reboot_cleanup() {
505
	captiveportal_radius_stop_all();
506
}
507

    
508
function system_do_shell_commands($early = 0) {
509
	global $config, $g;
510

    
511
	if ($early)
512
		$cmdn = "earlyshellcmd";
513
	else
514
		$cmdn = "shellcmd";
515

    
516
	if (is_array($config['system'][$cmdn])) {
517

    
518
		foreach ($config['system'][$cmdn] as $cmd) {
519
			exec($cmd);
520
		}
521
	}
522
}
523

    
524
function system_do_extensions($early = false) {
525
	global $config, $g;
526

    
527
	if (!is_dir("{$g['etc_path']}/inc/ext"))
528
		return;
529

    
530
	$dh = @opendir("{$g['etc_path']}/inc/ext");
531
	if ($dh) {
532
		while (($extd = readdir($dh)) !== false) {
533
			if (($extd === ".") || ($extd === ".."))
534
				continue;
535
			$rcfile = "{$g['etc_path']}/inc/ext/" . $extd . "/" . ($early ? "rc.early" : "rc");
536
			if (file_exists($rcfile))
537
				passthru($rcfile);
538
		}
539
		closedir($dh);
540
	}
541
}
542

    
543
function system_console_configure() {
544
	global $config, $g;
545

    
546
	if (isset($config['system']['disableconsolemenu'])) {
547
		touch("{$g['varetc_path']}/disableconsole");
548
	} else {
549
		unlink_if_exists("{$g['varetc_path']}/disableconsole");
550
	}
551
}
552

    
553
function system_dmesg_save() {
554
	global $g;
555

    
556
	exec("/sbin/dmesg", $dmesg);
557

    
558
	/* find last copyright line (output from previous boots may be present) */
559
	$lastcpline = 0;
560

    
561
	for ($i = 0; $i < count($dmesg); $i++) {
562
		if (strstr($dmesg[$i], "Copyright (c) 1992-"))
563
			$lastcpline = $i;
564
	}
565

    
566
	$fd = fopen("{$g['varlog_path']}/dmesg.boot", "w");
567
	if (!$fd) {
568
		printf("Error: cannot open dmesg.boot in system_dmesg_save().\n");
569
		return 1;
570
	}
571

    
572
	for ($i = $lastcpline; $i < count($dmesg); $i++)
573
		fwrite($fd, $dmesg[$i] . "\n");
574

    
575
	fclose($fd);
576

    
577
	return 0;
578
}
579

    
580
function system_set_harddisk_standby() {
581
	global $g, $config;
582

    
583
	if ($g['platform'] != "generic-pc")
584
		return;
585

    
586
	if (isset($config['system']['harddiskstandby'])) {
587
		if ($g['booting']) {
588
			echo 'Setting hard disk standby... ';
589
		}
590

    
591
		$standby = $config['system']['harddiskstandby'];
592
		// Check for a numeric value
593
		if (is_numeric($standby)) {
594
			// Sync the disk(s)
595
			mwexec('/bin/sync');
596
			if (!mwexec('/sbin/sysctl hw.ata.standby=' . ((int)$standby))) {
597
				// Reinitialize ATA-drives
598
				mwexec('/usr/local/sbin/atareinit');
599
				if ($g['booting']) {
600
					echo "done.\n";
601
				}
602
			} else if ($g['booting']) {
603
				echo "failed!\n";
604
			}
605
		} else if ($g['booting']) {
606
			echo "failed!\n";
607
		}
608
	}
609
}
610

    
611
function system_setup_sysctl() {
612
	$sysctl = return_filename_as_array("/etc/sysctl.conf");
613
	foreach($sysctl as $sysc) {
614
		if($sysc <> "")
615
			mwexec("sysctl {$sysc}");
616
	}
617
}
618

    
619
?>
(15-15/21)