Project

General

Profile

Download (14.4 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2
/*
3
	system.inc
4
	part of m0n0wall (http://m0n0.ch/wall)
5 0f282d7a Scott Ullrich
6 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
7
	All rights reserved.
8 0f282d7a Scott Ullrich
9 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
10
	modification, are permitted provided that the following conditions are met:
11 0f282d7a Scott Ullrich
12 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
13
	   this list of conditions and the following disclaimer.
14 0f282d7a Scott Ullrich
15 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
16
	   notice, this list of conditions and the following disclaimer in the
17
	   documentation and/or other materials provided with the distribution.
18 0f282d7a Scott Ullrich
19 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
	POSSIBILITY OF SUCH DAMAGE.
29
*/
30
31
/* include all configuration functions */
32
require_once("functions.inc");
33 0f282d7a Scott Ullrich
34 5b237745 Scott Ullrich
function system_resolvconf_generate($dynupdate = false) {
35
	global $config, $g;
36 0f282d7a Scott Ullrich
37 5b237745 Scott Ullrich
	$syscfg = $config['system'];
38 0f282d7a Scott Ullrich
39 5b237745 Scott Ullrich
	$fd = fopen("{$g['varetc_path']}/resolv.conf", "w");
40
	if (!$fd) {
41
		printf("Error: cannot open resolv.conf in system_resolvconf_generate().\n");
42
		return 1;
43
	}
44 0f282d7a Scott Ullrich
45 5b237745 Scott Ullrich
	$resolvconf = "domain {$syscfg['domain']}\n";
46 0f282d7a Scott Ullrich
47 5b237745 Scott Ullrich
	$havedns = false;
48 0f282d7a Scott Ullrich
49 5b237745 Scott Ullrich
	if (isset($syscfg['dnsallowoverride'])) {
50
		/* get dynamically assigned DNS servers (if any) */
51
		$nfd = @fopen("{$g['varetc_path']}/nameservers.conf", "r");
52
		if ($nfd) {
53
			while (!feof($nfd)) {
54
				$dnss = trim(fgets($nfd));
55
				if ($dnss) {
56
					$resolvconf .= "nameserver $dnss\n";
57
					$havedns = true;
58
				}
59
			}
60
			fclose($nfd);
61
		}
62
	}
63
	if (!$havedns && is_array($syscfg['dnsserver'])) {
64
		foreach ($syscfg['dnsserver'] as $ns) {
65
			if ($ns)
66
				$resolvconf .= "nameserver $ns\n";
67
			$havedns = true;
68
		}
69
	}
70 0f282d7a Scott Ullrich
71 5b237745 Scott Ullrich
	fwrite($fd, $resolvconf);
72
	fclose($fd);
73 0f282d7a Scott Ullrich
74 5b237745 Scott Ullrich
	if (!$g['booting']) {
75
		/* restart dhcpd (nameservers may have changed) */
76
		if (!$dynupdate)
77
			services_dhcpd_configure();
78
	}
79 0f282d7a Scott Ullrich
80 5b237745 Scott Ullrich
	return 0;
81
}
82
83
function system_hosts_generate() {
84
	global $config, $g;
85 0f282d7a Scott Ullrich
86 5b237745 Scott Ullrich
	$syscfg = $config['system'];
87
	$lancfg = $config['interfaces']['lan'];
88
	$dnsmasqcfg = $config['dnsmasq'];
89
90
	if (!is_array($dnsmasqcfg['hosts'])) {
91
		$dnsmasqcfg['hosts'] = array();
92
	}
93
	$hostscfg = $dnsmasqcfg['hosts'];
94 0f282d7a Scott Ullrich
95 5b237745 Scott Ullrich
	$fd = fopen("{$g['varetc_path']}/hosts", "w");
96
	if (!$fd) {
97
		printf("Error: cannot open hosts file in system_hosts_generate().\n");
98
		return 1;
99
	}
100 0f282d7a Scott Ullrich
101 5b237745 Scott Ullrich
	$hosts = <<<EOD
102
127.0.0.1	localhost localhost.{$syscfg['domain']}
103
{$lancfg['ipaddr']}	{$syscfg['hostname']}.{$syscfg['domain']} {$syscfg['hostname']}
104
105
EOD;
106 0f282d7a Scott Ullrich
107 5b237745 Scott Ullrich
	foreach ($hostscfg as $host) {
108
		if ($host['host'])
109
			$hosts .= "{$host['ip']}	{$host['host']}.{$host['domain']} {$host['host']}\n";
110
		else
111
			$hosts .= "{$host['ip']}	{$host['domain']}\n";
112
	}
113
	fwrite($fd, $hosts);
114
	fclose($fd);
115 0f282d7a Scott Ullrich
116 5b237745 Scott Ullrich
	return 0;
117
}
118
119
function system_hostname_configure() {
120
	global $config, $g;
121 0f282d7a Scott Ullrich
122 5b237745 Scott Ullrich
	$syscfg = $config['system'];
123 0f282d7a Scott Ullrich
124 5b237745 Scott Ullrich
	/* set hostname */
125
	return mwexec("/bin/hostname " .
126
		escapeshellarg("{$syscfg['hostname']}.{$syscfg['domain']}"));
127
}
128
129
function system_routing_configure() {
130
	global $config, $g;
131 0f282d7a Scott Ullrich
132
	/* Enable fast routing, if enabled */
133
	if(isset($config['staticroutes']['enablefastrouting']))
134
		mwexec("/sbin/sysctl net.inet.ip.fastforwarding=1");
135
136 5b237745 Scott Ullrich
	/* clear out old routes, if necessary */
137
	if (file_exists("{$g['vardb_path']}/routes.db")) {
138
		$fd = fopen("{$g['vardb_path']}/routes.db", "r");
139
		if (!$fd) {
140
			printf("Error: cannot open routes DB file in system_routing_configure().\n");
141 0f282d7a Scott Ullrich
			return 1;
142 5b237745 Scott Ullrich
		}
143
		while (!feof($fd)) {
144
			$oldrt = fgets($fd);
145
			if ($oldrt)
146
				mwexec("/sbin/route delete " . escapeshellarg($oldrt));
147
		}
148
		fclose($fd);
149
		unlink("{$g['vardb_path']}/routes.db");
150
	}
151 0f282d7a Scott Ullrich
152 5b237745 Scott Ullrich
	if (is_array($config['staticroutes']['route'])) {
153 0f282d7a Scott Ullrich
154 5b237745 Scott Ullrich
		$fd = fopen("{$g['vardb_path']}/routes.db", "w");
155
		if (!$fd) {
156
			printf("Error: cannot open routes DB file in system_routing_configure().\n");
157 0f282d7a Scott Ullrich
			return 1;
158 5b237745 Scott Ullrich
		}
159 0f282d7a Scott Ullrich
160 5b237745 Scott Ullrich
		foreach ($config['staticroutes']['route'] as $rtent) {
161 0f282d7a Scott Ullrich
			mwexec("/sbin/route add " . escapeshellarg($rtent['network']) .
162 5b237745 Scott Ullrich
				" " . escapeshellarg($rtent['gateway']));
163 0f282d7a Scott Ullrich
164 5b237745 Scott Ullrich
			/* record route so it can be easily removed later (if necessary) */
165
			fwrite($fd, $rtent['network'] . "\n");
166
		}
167 0f282d7a Scott Ullrich
168
		fclose($fd);
169 5b237745 Scott Ullrich
	}
170 0f282d7a Scott Ullrich
171 5b237745 Scott Ullrich
	return 0;
172
}
173
174
function system_routing_enable() {
175
	global $config, $g;
176 0f282d7a Scott Ullrich
177 5b237745 Scott Ullrich
	return mwexec("/sbin/sysctl net.inet.ip.forwarding=1");
178
}
179
180
function system_syslogd_start() {
181
	global $config, $g;
182 0f282d7a Scott Ullrich
183 5b237745 Scott Ullrich
	$syslogcfg = $config['syslog'];
184
185 0f282d7a Scott Ullrich
	if ($g['booting'])
186 5b237745 Scott Ullrich
		echo "Starting syslog service... ";
187
	else
188
		killbypid("{$g['varrun_path']}/syslog.pid");
189 0f282d7a Scott Ullrich
190 5b237745 Scott Ullrich
	if (isset($syslogcfg['enable'])) {
191
192
		/* write syslog.conf */
193
		$fd = fopen("{$g['varetc_path']}/syslog.conf", "w");
194
		if (!$fd) {
195
			printf("Error: cannot open syslog.conf in system_syslogd_start().\n");
196
			return 1;
197
		}
198 0f282d7a Scott Ullrich
199 5b237745 Scott Ullrich
		$syslogconf = <<<EOD
200 bc328042 Bill Marquette
local0.*					%{$g['varlog_path']}/filter.log
201
local3.*					%{$g['varlog_path']}/vpn.log
202
local4.*					%{$g['varlog_path']}/portalauth.log
203
local7.*					%{$g['varlog_path']}/dhcpd.log
204
*.notice;kern.debug;lpr.info;mail.crit;news.err;local0.none;local3.none;local4.none;local7.none %{$g['varlog_path']}/system.log
205
security.*					%{$g['varlog_path']}/system.log
206
auth.info;authpriv.info;daemon.info		%{$g['varlog_path']}/system.log
207 5b237745 Scott Ullrich
*.emerg						*
208
209
EOD;
210
211
		if (isset($syslogcfg['filter'])) {
212
			$syslogconf .= <<<EOD
213
local0.*					@{$syslogcfg['remoteserver']}
214
215
EOD;
216
		}
217 0f282d7a Scott Ullrich
218 5b237745 Scott Ullrich
		if (isset($syslogcfg['vpn'])) {
219
			$syslogconf .= <<<EOD
220
local3.*					@{$syslogcfg['remoteserver']}
221 3f2b92d2 Scott Ullrich
EOD;
222
		}
223
224 5b237745 Scott Ullrich
225 3f2b92d2 Scott Ullrich
		if (isset($syslogcfg['portalauth'])) {
226
			$syslogconf .= <<<EOD
227
local4.*					@{$syslogcfg['remoteserver']}
228 5b237745 Scott Ullrich
EOD;
229
		}
230
231 3f2b92d2 Scott Ullrich
232 5b237745 Scott Ullrich
		if (isset($syslogcfg['dhcp'])) {
233
			$syslogconf .= <<<EOD
234
local7.*					@{$syslogcfg['remoteserver']}
235
EOD;
236
		}
237
238
		if (isset($syslogcfg['system'])) {
239
			$syslogconf .= <<<EOD
240 a23d7248 Scott Ullrich
*.notice;kern.debug;lpr.info;mail.crit;news.err;local0.none;local3.none;local7.none @{$syslogcfg['remoteserver']}
241 5b237745 Scott Ullrich
security.*					@{$syslogcfg['remoteserver']}
242
auth.info;authpriv.info;daemon.info		@{$syslogcfg['remoteserver']}
243
*.emerg						@{$syslogcfg['remoteserver']}
244
245
EOD;
246
		}
247
248
		fwrite($fd, $syslogconf);
249
		fclose($fd);
250 0f282d7a Scott Ullrich
251 5b237745 Scott Ullrich
		$retval = mwexec("/usr/sbin/syslogd -s -f {$g['varetc_path']}/syslog.conf");
252
253
	} else {
254
		$retval = mwexec("/usr/sbin/syslogd -ss");
255
	}
256 0f282d7a Scott Ullrich
257 5b237745 Scott Ullrich
	if ($g['booting'])
258
		echo "done\n";
259 0f282d7a Scott Ullrich
260 5b237745 Scott Ullrich
	return $retval;
261
}
262
263
function system_pccard_start() {
264
	global $config, $g;
265 0f282d7a Scott Ullrich
266 5b237745 Scott Ullrich
	if ($g['booting'])
267
		echo "Initializing PC cards... ";
268 0f282d7a Scott Ullrich
269 5b237745 Scott Ullrich
	/* kill any running pccardd */
270
	killbypid("{$g['varrun_path']}/pccardd.pid");
271 0f282d7a Scott Ullrich
272 5b237745 Scott Ullrich
	/* fire up pccardd */
273
	$res = mwexec("/usr/sbin/pccardd -z -f {$g['etc_path']}/pccard.conf");
274 0f282d7a Scott Ullrich
275 5b237745 Scott Ullrich
	if ($g['booting']) {
276
		if ($res == 0)
277
			echo "done\n";
278
		else
279
			echo "failed (probably no PC card controller present)\n";
280
	}
281 0f282d7a Scott Ullrich
282 5b237745 Scott Ullrich
	return $res;
283
}
284
285
function system_webgui_start() {
286
	global $config, $g;
287 0f282d7a Scott Ullrich
288 5b237745 Scott Ullrich
	if ($g['booting'])
289
		echo "Starting webGUI... ";
290 0f282d7a Scott Ullrich
291 5b237745 Scott Ullrich
	/* kill any running mini_httpd */
292
	killbypid("{$g['varrun_path']}/mini_httpd.pid");
293 0f282d7a Scott Ullrich
294 5b237745 Scott Ullrich
	/* generate password file */
295
	system_password_configure();
296 0f282d7a Scott Ullrich
297 5b237745 Scott Ullrich
	chdir($g['www_path']);
298 0f282d7a Scott Ullrich
299 5b237745 Scott Ullrich
	/* non-standard port? */
300
	if ($config['system']['webgui']['port'])
301
		$portarg = "-p {$config['system']['webgui']['port']}";
302
	else
303
		$portarg = "";
304 0f282d7a Scott Ullrich
305 5b237745 Scott Ullrich
	if ($config['system']['webgui']['protocol'] == "https") {
306 0f282d7a Scott Ullrich
307 5b237745 Scott Ullrich
		if ($config['system']['webgui']['certificate'] && $config['system']['webgui']['private-key']) {
308
			$cert = base64_decode($config['system']['webgui']['certificate']);
309
			$key = base64_decode($config['system']['webgui']['private-key']);
310
		} else {
311
			/* default certificate/key */
312
			$cert = <<<EOD
313
-----BEGIN CERTIFICATE-----
314
MIIBlDCB/gIBADANBgkqhkiG9w0BAQQFADATMREwDwYDVQQKEwhtMG4wd2FsbDAe
315
Fw0wMzA5MDgxNzAzNDZaFw0wNDA5MDcxNzAzNDZaMBMxETAPBgNVBAoTCG0wbjB3
316
YWxsMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDAShszhFz+o8lsMWTGgTxs
317
TMPR+v4+qL5jXDyY97MLTGFK7aqQOtpIQc+TcTc4jklgOVlHoR7oBXrsi8YrbCd+
318
83LPQmQoSPC0VqhfU3uYf3NzxiK8r97aPCsmWgwT2pQ6TcESTm6sF7nLprOf/zFP
319
C4jE2fvjkbzyVolPywBuewIDAQABMA0GCSqGSIb3DQEBBAUAA4GBAK2D8NqQSlUs
320
pFCe5J9ue1LrjfGHHy4HE9zA9avgrz3Qju+1JOshEwy/1BJjZ93tQUbiRS7RwvDO
321
4crGG4IejjhFczzA2CIX3rd2rYM2oGpojKgm5YuuhV5lYPwAHUOLbBaLOVqlLhzw
322
VqjD7R2DkXUIfhJ5ZekqK5ZwzqJXta8U
323
-----END CERTIFICATE-----
324
325
EOD;
326
327
			$key = <<<EOD
328
-----BEGIN RSA PRIVATE KEY-----
329
MIICXQIBAAKBgQDAShszhFz+o8lsMWTGgTxsTMPR+v4+qL5jXDyY97MLTGFK7aqQ
330
OtpIQc+TcTc4jklgOVlHoR7oBXrsi8YrbCd+83LPQmQoSPC0VqhfU3uYf3NzxiK8
331
r97aPCsmWgwT2pQ6TcESTm6sF7nLprOf/zFPC4jE2fvjkbzyVolPywBuewIDAQAB
332
AoGAbJJrQW9fQrggJuLMz/hwsYW2m31oyOBmf5u463YQtjRuSuxe/gj87weZuNqY
333
H2rXq2k2K+ehl8hgW+egASyUL3L7kCkEAsVREujKTEyhSqqIRDPWTxo9S/YA9Gvn
334
2ZnJvkrcKjqCO9aHX3rvJOK/ErYI6akctgI3KmgkYw5XNmECQQDuZU97RTWH9rmP
335
aQr57ysNXxgFsyhetOOqeYkPtIVwpOiNbfwE1zi5RGdtO4Ku3fG1lV4J2UoWJ9yD
336
awdoyYIHAkEAzn0xJ90IjPsHk+8SODEj5JGdHSZPNu1tgtrbjEi9sfGWg4K7XTxr
337
QW90pWb1bKKU1uh5FzW6OhnFfuQXt1kC7QJAPSthqY+onKqCEnoxhtAHi/bKgyvl
338
P+fKQwPMV2tKkgy+XwvJjrRqqZ8TqsOKVLQ+QQmCh6RpjiXMPyxHSmvqIQJBAKLR
339
HF1ucDuaBROkwx0DwmWMW/KMLpIFDQDNSaiIAuu4rxHrl4mhBoGGPNffI04RtILw
340
s+qVNs5xW8T+XaT4ztECQQDFHPnZeoPWE5z+AX/UUQIUWaDExz3XRzmIxRbOrlFi
341
CsF1s0TdJLi/wzNQRAL37A8vqCeVFR/ng3Xpg96Yg+8Z
342
-----END RSA PRIVATE KEY-----
343
344
EOD;
345
		}
346 0f282d7a Scott Ullrich
347 5b237745 Scott Ullrich
		$fd = fopen("{$g['varetc_path']}/cert.pem", "w");
348
		if (!$fd) {
349
			printf("Error: cannot open cert.pem in system_webgui_start().\n");
350
			return 1;
351
		}
352
		chmod("{$g['varetc_path']}/cert.pem", 0600);
353
		fwrite($fd, $cert);
354
		fwrite($fd, "\n");
355
		fwrite($fd, $key);
356
		fclose($fd);
357 0f282d7a Scott Ullrich
358 5b237745 Scott Ullrich
		$res = mwexec("/usr/local/sbin/mini_httpd -S -E {$g['varetc_path']}/cert.pem" .
359
			" -c \"**.php|**.cgi\" -u root -maxproc 16 $portarg" .
360
			" -i {$g['varrun_path']}/mini_httpd.pid");
361
	} else {
362
		$res = mwexec("/usr/local/sbin/mini_httpd -c \"**.php|**.cgi\" -u root" .
363
			" -maxproc 16 $portarg -i {$g['varrun_path']}/mini_httpd.pid");
364
	}
365 0f282d7a Scott Ullrich
366 5b237745 Scott Ullrich
	if ($g['booting']) {
367
		if ($res == 0)
368
			echo "done\n";
369
		else
370
			echo "failed\n";
371
	}
372 0f282d7a Scott Ullrich
373 5b237745 Scott Ullrich
	return $res;
374
}
375
376
function system_password_configure() {
377
	global $config, $g;
378 0f282d7a Scott Ullrich
379 5b237745 Scott Ullrich
	$fd = fopen("{$g['varrun_path']}/htpasswd", "w");
380
	if (!$fd) {
381
		printf("Error: cannot open htpasswd in system_password_configure().\n");
382
		return 1;
383
	}
384 0f282d7a Scott Ullrich
385 5b237745 Scott Ullrich
	if ($config['system']['username'])
386
		$username = $config['system']['username'];
387
	else
388
		$username = "admin";
389 0f282d7a Scott Ullrich
390 5b237745 Scott Ullrich
	fwrite($fd, $username . ":" . $config['system']['password'] . "\n");
391
	fclose($fd);
392
	chmod("{$g['varrun_path']}/htpasswd", 0600);
393 0f282d7a Scott Ullrich
394 5b237745 Scott Ullrich
	return 0;
395
}
396
397
function system_timezone_configure() {
398
	global $config, $g;
399
400
	$syscfg = $config['system'];
401
402
	if ($g['booting'])
403
		echo "Initializing timezone... ";
404
405
	/* extract appropriate timezone file */
406
	$timezone = $syscfg['timezone'];
407
	if (!$timezone)
408
		$timezone = "Etc/UTC";
409 0f282d7a Scott Ullrich
410
	exec("/usr/bin/tar xzfO /usr/share/zoneinfo.tgz " .
411 5b237745 Scott Ullrich
		escapeshellarg($timezone) . " > /etc/localtime");
412
413
	if ($g['booting'])
414
		echo "done\n";
415
}
416
417
function system_ntp_configure() {
418
	global $config, $g;
419
420
	$syscfg = $config['system'];
421
422
	if ($g['booting'])
423
		echo "Starting NTP client... ";
424
	else {
425
		killbypid("{$g['varrun_path']}/runmsntp.pid");
426
		killbypid("{$g['varrun_path']}/msntp.pid");
427
	}
428
429
	/* start ntp client if needed - needs to be forced into background */
430
	$updateinterval = $syscfg['time-update-interval'];
431 0f282d7a Scott Ullrich
432 5b237745 Scott Ullrich
	if ($updateinterval > 0) {
433
		if ($updateinterval < 6)
434
			$updateinterval = 6;
435 0f282d7a Scott Ullrich
436 5b237745 Scott Ullrich
		$timeservers = "";
437
		foreach (explode(' ', $syscfg['timeservers']) as $ts)
438
			$timeservers .= " " . $ts;
439 0f282d7a Scott Ullrich
440 5b237745 Scott Ullrich
		mwexec_bg("/usr/local/bin/runmsntp.sh " .
441
			escapeshellarg("{$g['varrun_path']}/runmsntp.pid") . " " .
442
			escapeshellarg("{$g['varrun_path']}/msntp.pid") . " " .
443
			escapeshellarg($updateinterval) . " " .
444
			escapeshellarg($timeservers));
445
	}
446 0f282d7a Scott Ullrich
447 5b237745 Scott Ullrich
	if ($g['booting'])
448
		echo "done\n";
449
}
450
451 405e5de0 Scott Ullrich
function system_halt() {
452
	global $g;
453
454
	system_reboot_cleanup();
455
456
	mwexec("nohup /etc/rc.halt > /dev/null 2>&1 &");
457
}
458
459 5b237745 Scott Ullrich
function system_reboot() {
460
	global $g;
461 0f282d7a Scott Ullrich
462 5b237745 Scott Ullrich
	system_reboot_cleanup();
463 0f282d7a Scott Ullrich
464 5b237745 Scott Ullrich
	mwexec("nohup /etc/rc.reboot > /dev/null 2>&1 &");
465
}
466
467
function system_reboot_sync() {
468
	global $g;
469 0f282d7a Scott Ullrich
470 5b237745 Scott Ullrich
	system_reboot_cleanup();
471 0f282d7a Scott Ullrich
472 5b237745 Scott Ullrich
	mwexec("/etc/rc.reboot > /dev/null 2>&1");
473
}
474
475
function system_reboot_cleanup() {
476
	captiveportal_radius_stop_all();
477
}
478
479
function system_do_shell_commands($early = 0) {
480
	global $config, $g;
481 0f282d7a Scott Ullrich
482 5b237745 Scott Ullrich
	if ($early)
483
		$cmdn = "earlyshellcmd";
484
	else
485
		$cmdn = "shellcmd";
486 0f282d7a Scott Ullrich
487 5b237745 Scott Ullrich
	if (is_array($config['system'][$cmdn])) {
488 0f282d7a Scott Ullrich
489 5b237745 Scott Ullrich
		foreach ($config['system'][$cmdn] as $cmd) {
490
			exec($cmd);
491
		}
492
	}
493
}
494
495 a23d7248 Scott Ullrich
function system_do_extensions($early = false) {
496 5b237745 Scott Ullrich
	global $config, $g;
497 0f282d7a Scott Ullrich
498 5b237745 Scott Ullrich
	if (!is_dir("{$g['etc_path']}/inc/ext"))
499
		return;
500 0f282d7a Scott Ullrich
501 5b237745 Scott Ullrich
	$dh = @opendir("{$g['etc_path']}/inc/ext");
502
	if ($dh) {
503
		while (($extd = readdir($dh)) !== false) {
504
			if (($extd === ".") || ($extd === ".."))
505
				continue;
506 a23d7248 Scott Ullrich
			$rcfile = "{$g['etc_path']}/inc/ext/" . $extd . "/" . ($early ? "rc.early" : "rc");
507 5b237745 Scott Ullrich
			if (file_exists($rcfile))
508
				passthru($rcfile);
509
		}
510
		closedir($dh);
511
	}
512
}
513
514
function system_console_configure() {
515
	global $config, $g;
516 0f282d7a Scott Ullrich
517 5b237745 Scott Ullrich
	if (isset($config['system']['disableconsolemenu'])) {
518
		touch("{$g['varetc_path']}/disableconsole");
519
	} else {
520
		unlink_if_exists("{$g['varetc_path']}/disableconsole");
521
	}
522
}
523
524
function system_dmesg_save() {
525
	global $g;
526 0f282d7a Scott Ullrich
527 5b237745 Scott Ullrich
	exec("/sbin/dmesg", $dmesg);
528 0f282d7a Scott Ullrich
529 5b237745 Scott Ullrich
	/* find last copyright line (output from previous boots may be present) */
530
	$lastcpline = 0;
531 0f282d7a Scott Ullrich
532 5b237745 Scott Ullrich
	for ($i = 0; $i < count($dmesg); $i++) {
533
		if (strstr($dmesg[$i], "Copyright (c) 1992-"))
534
			$lastcpline = $i;
535
	}
536 0f282d7a Scott Ullrich
537 5b237745 Scott Ullrich
	$fd = fopen("{$g['varlog_path']}/dmesg.boot", "w");
538
	if (!$fd) {
539
		printf("Error: cannot open dmesg.boot in system_dmesg_save().\n");
540
		return 1;
541
	}
542 0f282d7a Scott Ullrich
543 5b237745 Scott Ullrich
	for ($i = $lastcpline; $i < count($dmesg); $i++)
544
		fwrite($fd, $dmesg[$i] . "\n");
545 0f282d7a Scott Ullrich
546 5b237745 Scott Ullrich
	fclose($fd);
547 0f282d7a Scott Ullrich
548 5b237745 Scott Ullrich
	return 0;
549
}
550
551
function system_set_harddisk_standby() {
552
	global $g, $config;
553
554
	if ($g['platform'] != "generic-pc")
555
		return;
556
557
	if (isset($config['system']['harddiskstandby'])) {
558
		if ($g['booting']) {
559
			echo 'Setting harddisk standby time... ';
560
		}
561
562
		$standby = $config['system']['harddiskstandby'];
563
		// Check for a numeric value
564
		if (is_numeric($standby)) {
565
			// Sync the disk(s)
566
			mwexec('/bin/sync');
567
			if (!mwexec('/sbin/sysctl hw.ata.standby=' . ((int)$standby))) {
568
				// Reinitialize ATA-drives
569
				mwexec('/usr/local/sbin/atareinit');
570
				if ($g['booting']) {
571
					echo "done\n";
572
				}
573
			} else if ($g['booting']) {
574
				echo "failed\n";
575
			}
576
		} else if ($g['booting']) {
577
			echo "failed\n";
578
		}
579
	}
580
}
581
582 3ff9d424 Scott Ullrich
function system_setup_sysctl() {
583
	$sysctl = return_filename_as_array("/etc/sysctl.conf");
584
	foreach($sysctl as $sysc) {
585 89f7e23c Scott Ullrich
		if($sysc <> "")
586
			mwexec("sysctl {$sysc}");
587 3ff9d424 Scott Ullrich
	}
588
}
589
590 5b237745 Scott Ullrich
?>