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