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 ( preg_match('/^(nameserver )(.*)/',$dnss, $catch) )
|
57
|
$dnss = $catch[2];
|
58
|
if (is_ipaddr($dnss)) {
|
59
|
$resolvconf .= "nameserver $dnss\n";
|
60
|
$havedns = true;
|
61
|
}
|
62
|
}
|
63
|
fclose($nfd);
|
64
|
}
|
65
|
}
|
66
|
|
67
|
/* if we didn't get assigned DNS servers and have some set add 'em */
|
68
|
if (!$havedns && is_array($syscfg['dnsserver'])) {
|
69
|
foreach ($syscfg['dnsserver'] as $ns) {
|
70
|
if ($ns)
|
71
|
$resolvconf .= "nameserver $ns\n";
|
72
|
$havedns = true;
|
73
|
}
|
74
|
}
|
75
|
|
76
|
fwrite($fd, $resolvconf);
|
77
|
fclose($fd);
|
78
|
|
79
|
/* If we now have DNS servers, overwrite resolv.conf */
|
80
|
if ($havedns) {
|
81
|
if (file_exists("{$g['varetc_path']}/resolv.conf"))
|
82
|
unlink("{$g['varetc_path']}/resolv.conf");
|
83
|
rename("{$g['varetc_path']}/resolv.conf.new", "{$g['varetc_path']}/resolv.conf");
|
84
|
} else {
|
85
|
unlink("{$g['varetc_path']}/resolv.conf.new");
|
86
|
}
|
87
|
|
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['enable'])) {
|
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
|
*.emerg *
|
234
|
|
235
|
EOD;
|
236
|
}
|
237
|
|
238
|
if (isset($syslogcfg['filter'])) {
|
239
|
$syslogconf .= <<<EOD
|
240
|
local0.* @{$syslogcfg['remoteserver']}
|
241
|
|
242
|
EOD;
|
243
|
}
|
244
|
|
245
|
if (isset($syslogcfg['vpn'])) {
|
246
|
$syslogconf .= <<<EOD
|
247
|
local3.* @{$syslogcfg['remoteserver']}
|
248
|
|
249
|
EOD;
|
250
|
}
|
251
|
|
252
|
|
253
|
if (isset($syslogcfg['portalauth'])) {
|
254
|
$syslogconf .= <<<EOD
|
255
|
local4.* @{$syslogcfg['remoteserver']}
|
256
|
|
257
|
EOD;
|
258
|
}
|
259
|
|
260
|
|
261
|
if (isset($syslogcfg['dhcp'])) {
|
262
|
$syslogconf .= <<<EOD
|
263
|
local7.* @{$syslogcfg['remoteserver']}
|
264
|
|
265
|
EOD;
|
266
|
}
|
267
|
|
268
|
if (isset($syslogcfg['system'])) {
|
269
|
$syslogconf .= <<<EOD
|
270
|
*.notice;kern.debug;lpr.info;mail.crit; @{$syslogcfg['remoteserver']}
|
271
|
news.err;local0.none;local3.none;local7.none @{$syslogcfg['remoteserver']}
|
272
|
security.* @{$syslogcfg['remoteserver']}
|
273
|
auth.info;authpriv.info;daemon.info @{$syslogcfg['remoteserver']}
|
274
|
*.emerg @{$syslogcfg['remoteserver']}
|
275
|
EOD;
|
276
|
}
|
277
|
fwrite($fd, $syslogconf);
|
278
|
fclose($fd);
|
279
|
|
280
|
$retval = mwexec("/usr/sbin/syslogd -s -f {$g['varetc_path']}/syslog.conf");
|
281
|
|
282
|
} else {
|
283
|
$retval = mwexec("/usr/sbin/syslogd -ss");
|
284
|
}
|
285
|
|
286
|
if ($g['booting'])
|
287
|
echo "done.\n";
|
288
|
|
289
|
return $retval;
|
290
|
}
|
291
|
|
292
|
function system_pccard_start() {
|
293
|
global $config, $g;
|
294
|
|
295
|
if ($g['booting'])
|
296
|
echo "Initializing PCMCIA... ";
|
297
|
|
298
|
/* kill any running pccardd */
|
299
|
killbypid("{$g['varrun_path']}/pccardd.pid");
|
300
|
|
301
|
/* fire up pccardd */
|
302
|
$res = mwexec("/usr/sbin/pccardd -z -f {$g['etc_path']}/pccard.conf");
|
303
|
|
304
|
if ($g['booting']) {
|
305
|
if ($res == 0)
|
306
|
echo "done.\n";
|
307
|
else
|
308
|
echo "failed!\n";
|
309
|
}
|
310
|
|
311
|
return $res;
|
312
|
}
|
313
|
|
314
|
function system_webgui_start() {
|
315
|
global $config, $g;
|
316
|
|
317
|
if ($g['booting'])
|
318
|
echo "Starting webGUI... ";
|
319
|
|
320
|
/* kill any running mini_httpd */
|
321
|
killbypid("{$g['varrun_path']}/mini_httpd.pid");
|
322
|
|
323
|
/* generate password file */
|
324
|
system_password_configure();
|
325
|
|
326
|
chdir($g['www_path']);
|
327
|
|
328
|
/* non-standard port? */
|
329
|
if ($config['system']['webgui']['port'])
|
330
|
$portarg = "-p {$config['system']['webgui']['port']}";
|
331
|
else
|
332
|
$portarg = "";
|
333
|
|
334
|
if ($config['system']['webgui']['protocol'] == "https") {
|
335
|
|
336
|
if ($config['system']['webgui']['certificate'] && $config['system']['webgui']['private-key']) {
|
337
|
$cert = base64_decode($config['system']['webgui']['certificate']);
|
338
|
$key = base64_decode($config['system']['webgui']['private-key']);
|
339
|
} else {
|
340
|
/* default certificate/key */
|
341
|
$cert = <<<EOD
|
342
|
-----BEGIN CERTIFICATE-----
|
343
|
MIIC4zCCAkygAwIBAgIBADANBgkqhkiG9w0BAQQFADBbMQswCQYDVQQGEwJOQTEL
|
344
|
MAkGA1UECBMCTkExCzAJBgNVBAcTAk5BMQswCQYDVQQKEwJOQTELMAkGA1UECxMC
|
345
|
TkExCzAJBgNVBAMTAk5BMQswCQYDVQQGEwJVUzAeFw0wNTAzMDYwMDE1NDJaFw0x
|
346
|
NTAzMDQwMDE1NDJaMFsxCzAJBgNVBAYTAk5BMQswCQYDVQQIEwJOQTELMAkGA1UE
|
347
|
BxMCTkExCzAJBgNVBAoTAk5BMQswCQYDVQQLEwJOQTELMAkGA1UEAxMCTkExCzAJ
|
348
|
BgNVBAYTAlVTMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDF7luuy70OvHrl
|
349
|
xnW9ID6srsfxEFCF4d9LmlZ6XdW1rEUHQ6KTgz4iSD+pxEOxxlY+bCH6HTkAy5Sa
|
350
|
zt3eT7javvF+ILZgarwoY2x+NbDctd0VBJVkH0fEvBf1xqU7wpkOiWkw1RmfEvZI
|
351
|
6XnGi6VSjSmkm0UoQMKg9R7niRtE4QIDAQABo4G2MIGzMB0GA1UdDgQWBBTgvk9F
|
352
|
alPK6/OcZrkaE8BhBrRo2DCBgwYDVR0jBHwweoAU4L5PRWpTyuvznGa5GhPAYQa0
|
353
|
aNihX6RdMFsxCzAJBgNVBAYTAk5BMQswCQYDVQQIEwJOQTELMAkGA1UEBxMCTkEx
|
354
|
CzAJBgNVBAoTAk5BMQswCQYDVQQLEwJOQTELMAkGA1UEAxMCTkExCzAJBgNVBAYT
|
355
|
AlVTggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAv9+GXdYIWs2R
|
356
|
8B0zI4jAbHcaRsfohuzpNHD5re7ZK8H4fYbHIfmPY2UM3yOU7J2rLP8KGfKztay1
|
357
|
Z3RNW7SKJI/CagbdQOuYdMrlEyA4ZImM6NNzUbH6rNKtmDIDo1kHL3cXjzXEjBE+
|
358
|
ZZYTREFcdhtzUH5lYzJz1uVFeCSwozk=
|
359
|
-----END CERTIFICATE-----
|
360
|
EOD;
|
361
|
|
362
|
$key = <<<EOD
|
363
|
-----BEGIN RSA PRIVATE KEY-----
|
364
|
MIICXAIBAAKBgQDF7luuy70OvHrlxnW9ID6srsfxEFCF4d9LmlZ6XdW1rEUHQ6KT
|
365
|
gz4iSD+pxEOxxlY+bCH6HTkAy5Sazt3eT7javvF+ILZgarwoY2x+NbDctd0VBJVk
|
366
|
H0fEvBf1xqU7wpkOiWkw1RmfEvZI6XnGi6VSjSmkm0UoQMKg9R7niRtE4QIDAQAB
|
367
|
AoGAF9dMJ9PWo+3EB+VNzUgTBI3Q+5JxgI7ibKLcg8TFtypW7jcRYB9Q3qRBNtuz
|
368
|
I7i2LrKrrQrUEOp0rej5BIwpwcjtEE2NsZwgYwDyywptoqt3WO86nPXYz2KhkQmP
|
369
|
YCDmPrff4vXCv6zgefb/AIgrOkgD3ViEoePhCAg+0l3fEIECQQD7C68Nb6KAWUND
|
370
|
Q9B0RxYrlgXikQ8yVHhlyM433APe/NCJ9kl5dLXpyjuvrWB+ml6TlLrcroLGejbd
|
371
|
tYXvIiyJAkEAydZVHqB4MpMtuY7VJoHNgl06YBoeTI+BJptPaOUNl4SlUKIYJMhX
|
372
|
oOXIGk9uDjfSNS7HvunZBjgz092GShWvmQJAQ8NhmwTZHj/58fwqFljh2R4DtKZn
|
373
|
LbSzUvYjA9z1holDWRoLtycTu2mFNuRbuZC9mqR40/ye/CgdCzdmUagt0QJBAKq1
|
374
|
00ySINd10Cive+yTwMPQIj2CGbpbbbq/hYyMntBWapQmZRFHOYZmkrZeFBGGeQ5u
|
375
|
QJdipiIyivNY2+nxKZECQCvumJPfZYxCeCAEC+G2xezrP6bC6FhzUOw6410UARTM
|
376
|
fuFjHpSfOiG62lfRdZgCPAr1L/1pJF+8RqjGlFfAuFA=
|
377
|
-----END RSA PRIVATE KEY-----
|
378
|
EOD;
|
379
|
}
|
380
|
|
381
|
$fd = fopen("{$g['varetc_path']}/cert.pem", "w");
|
382
|
if (!$fd) {
|
383
|
printf("Error: cannot open cert.pem in system_webgui_start().\n");
|
384
|
return 1;
|
385
|
}
|
386
|
chmod("{$g['varetc_path']}/cert.pem", 0600);
|
387
|
fwrite($fd, $cert);
|
388
|
fwrite($fd, "\n");
|
389
|
fwrite($fd, $key);
|
390
|
fclose($fd);
|
391
|
|
392
|
$res = mwexec("/usr/local/sbin/mini_httpd -S -E {$g['varetc_path']}/cert.pem" .
|
393
|
" -c \"**.php|**.cgi\" -u root -maxproc 16 $portarg" .
|
394
|
" -i {$g['varrun_path']}/mini_httpd.pid");
|
395
|
} else {
|
396
|
$res = mwexec("/usr/local/sbin/mini_httpd -c \"**.php|**.cgi\" -u root" .
|
397
|
" -maxproc 16 $portarg -i {$g['varrun_path']}/mini_httpd.pid");
|
398
|
}
|
399
|
|
400
|
if ($g['booting']) {
|
401
|
if ($res == 0)
|
402
|
echo "done.\n";
|
403
|
else
|
404
|
echo "failed!\n";
|
405
|
}
|
406
|
|
407
|
return $res;
|
408
|
}
|
409
|
|
410
|
function system_password_configure() {
|
411
|
global $config, $g;
|
412
|
|
413
|
$fd = fopen("{$g['varrun_path']}/htpasswd", "w");
|
414
|
if (!$fd) {
|
415
|
printf("Error: cannot open htpasswd in system_password_configure().\n");
|
416
|
return 1;
|
417
|
}
|
418
|
|
419
|
if ($config['system']['username'])
|
420
|
$username = $config['system']['username'];
|
421
|
else
|
422
|
$username = "admin";
|
423
|
|
424
|
fwrite($fd, $username . ":" . $config['system']['password'] . "\n");
|
425
|
fclose($fd);
|
426
|
chmod("{$g['varrun_path']}/htpasswd", 0600);
|
427
|
|
428
|
return 0;
|
429
|
}
|
430
|
|
431
|
function system_timezone_configure() {
|
432
|
global $config, $g;
|
433
|
|
434
|
$syscfg = $config['system'];
|
435
|
|
436
|
if ($g['booting'])
|
437
|
echo "Setting timezone... ";
|
438
|
|
439
|
/* extract appropriate timezone file */
|
440
|
$timezone = $syscfg['timezone'];
|
441
|
if (!$timezone)
|
442
|
$timezone = "Etc/UTC";
|
443
|
|
444
|
conf_mount_rw();
|
445
|
|
446
|
exec("/usr/bin/tar xzfO /usr/share/zoneinfo.tgz " .
|
447
|
escapeshellarg($timezone) . " > /etc/localtime");
|
448
|
|
449
|
conf_mount_ro();
|
450
|
|
451
|
if ($g['booting'])
|
452
|
echo "done.\n";
|
453
|
}
|
454
|
|
455
|
function system_ntp_configure() {
|
456
|
global $config, $g;
|
457
|
|
458
|
$syscfg = $config['system'];
|
459
|
|
460
|
if ($g['booting'])
|
461
|
echo "Starting NTP client... ";
|
462
|
else {
|
463
|
killbypid("{$g['varrun_path']}/runmsntp.pid");
|
464
|
killbypid("{$g['varrun_path']}/msntp.pid");
|
465
|
}
|
466
|
|
467
|
/* start ntp client if needed - needs to be forced into background */
|
468
|
$updateinterval = $syscfg['time-update-interval'];
|
469
|
|
470
|
if ($updateinterval > 0) {
|
471
|
if ($updateinterval < 6)
|
472
|
$updateinterval = 6;
|
473
|
|
474
|
$timeservers = "";
|
475
|
foreach (explode(' ', $syscfg['timeservers']) as $ts)
|
476
|
$timeservers .= " " . $ts;
|
477
|
|
478
|
mwexec_bg("/usr/local/bin/runmsntp.sh " .
|
479
|
escapeshellarg("{$g['varrun_path']}/runmsntp.pid") . " " .
|
480
|
escapeshellarg("{$g['varrun_path']}/msntp.pid") . " " .
|
481
|
escapeshellarg($updateinterval) . " " .
|
482
|
escapeshellarg($timeservers));
|
483
|
}
|
484
|
|
485
|
if ($g['booting'])
|
486
|
echo "done.\n";
|
487
|
}
|
488
|
|
489
|
function system_halt() {
|
490
|
global $g;
|
491
|
|
492
|
system_reboot_cleanup();
|
493
|
|
494
|
mwexec("nohup /etc/rc.halt > /dev/null 2>&1 &");
|
495
|
}
|
496
|
|
497
|
function system_reboot() {
|
498
|
global $g;
|
499
|
|
500
|
system_reboot_cleanup();
|
501
|
|
502
|
mwexec("nohup /etc/rc.reboot > /dev/null 2>&1 &");
|
503
|
}
|
504
|
|
505
|
function system_reboot_sync() {
|
506
|
global $g;
|
507
|
|
508
|
system_reboot_cleanup();
|
509
|
|
510
|
mwexec("/etc/rc.reboot > /dev/null 2>&1");
|
511
|
}
|
512
|
|
513
|
function system_reboot_cleanup() {
|
514
|
captiveportal_radius_stop_all();
|
515
|
}
|
516
|
|
517
|
function system_do_shell_commands($early = 0) {
|
518
|
global $config, $g;
|
519
|
|
520
|
if ($early)
|
521
|
$cmdn = "earlyshellcmd";
|
522
|
else
|
523
|
$cmdn = "shellcmd";
|
524
|
|
525
|
if (is_array($config['system'][$cmdn])) {
|
526
|
|
527
|
foreach ($config['system'][$cmdn] as $cmd) {
|
528
|
exec($cmd);
|
529
|
}
|
530
|
}
|
531
|
}
|
532
|
|
533
|
function system_do_extensions($early = false) {
|
534
|
global $config, $g;
|
535
|
|
536
|
if (!is_dir("{$g['etc_path']}/inc/ext"))
|
537
|
return;
|
538
|
|
539
|
$dh = @opendir("{$g['etc_path']}/inc/ext");
|
540
|
if ($dh) {
|
541
|
while (($extd = readdir($dh)) !== false) {
|
542
|
if (($extd === ".") || ($extd === ".."))
|
543
|
continue;
|
544
|
$rcfile = "{$g['etc_path']}/inc/ext/" . $extd . "/" . ($early ? "rc.early" : "rc");
|
545
|
if (file_exists($rcfile))
|
546
|
passthru($rcfile);
|
547
|
}
|
548
|
closedir($dh);
|
549
|
}
|
550
|
}
|
551
|
|
552
|
function system_console_configure() {
|
553
|
global $config, $g;
|
554
|
|
555
|
if (isset($config['system']['disableconsolemenu'])) {
|
556
|
touch("{$g['varetc_path']}/disableconsole");
|
557
|
} else {
|
558
|
unlink_if_exists("{$g['varetc_path']}/disableconsole");
|
559
|
}
|
560
|
}
|
561
|
|
562
|
function system_dmesg_save() {
|
563
|
global $g;
|
564
|
|
565
|
exec("/sbin/dmesg", $dmesg);
|
566
|
|
567
|
/* find last copyright line (output from previous boots may be present) */
|
568
|
$lastcpline = 0;
|
569
|
|
570
|
for ($i = 0; $i < count($dmesg); $i++) {
|
571
|
if (strstr($dmesg[$i], "Copyright (c) 1992-"))
|
572
|
$lastcpline = $i;
|
573
|
}
|
574
|
|
575
|
$fd = fopen("{$g['varlog_path']}/dmesg.boot", "w");
|
576
|
if (!$fd) {
|
577
|
printf("Error: cannot open dmesg.boot in system_dmesg_save().\n");
|
578
|
return 1;
|
579
|
}
|
580
|
|
581
|
for ($i = $lastcpline; $i < count($dmesg); $i++)
|
582
|
fwrite($fd, $dmesg[$i] . "\n");
|
583
|
|
584
|
fclose($fd);
|
585
|
|
586
|
return 0;
|
587
|
}
|
588
|
|
589
|
function system_set_harddisk_standby() {
|
590
|
global $g, $config;
|
591
|
|
592
|
if ($g['platform'] != "generic-pc")
|
593
|
return;
|
594
|
|
595
|
if (isset($config['system']['harddiskstandby'])) {
|
596
|
if ($g['booting']) {
|
597
|
echo 'Setting hard disk standby... ';
|
598
|
}
|
599
|
|
600
|
$standby = $config['system']['harddiskstandby'];
|
601
|
// Check for a numeric value
|
602
|
if (is_numeric($standby)) {
|
603
|
// Sync the disk(s)
|
604
|
mwexec('/bin/sync');
|
605
|
if (!mwexec('/sbin/sysctl hw.ata.standby=' . ((int)$standby))) {
|
606
|
// Reinitialize ATA-drives
|
607
|
mwexec('/usr/local/sbin/atareinit');
|
608
|
if ($g['booting']) {
|
609
|
echo "done.\n";
|
610
|
}
|
611
|
} else if ($g['booting']) {
|
612
|
echo "failed!\n";
|
613
|
}
|
614
|
} else if ($g['booting']) {
|
615
|
echo "failed!\n";
|
616
|
}
|
617
|
}
|
618
|
}
|
619
|
|
620
|
function system_setup_sysctl() {
|
621
|
$sysctl = return_filename_as_array("/etc/sysctl.conf");
|
622
|
foreach($sysctl as $sysc) {
|
623
|
if($sysc <> "")
|
624
|
mwexec("sysctl {$sysc}");
|
625
|
}
|
626
|
}
|
627
|
|
628
|
?>
|