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 opcode_cache_configuration() {
|
36
|
global $g;
|
37
|
if($g['platform'] == "cdrom")
|
38
|
return;
|
39
|
|
40
|
/* get system memory amount */
|
41
|
$memory = get_memory();
|
42
|
$avail = $memory[0];
|
43
|
|
44
|
/* disable apc for platforms less than 90 megs of ram */
|
45
|
if($memory > 90) {
|
46
|
$opcode_cacher = "extension=apc.so\n";
|
47
|
$opcode_cacher .= "apc.enabled=\"1\"\n";
|
48
|
$opcode_cacher .= "apc.enable_cli=\"1\"\n";
|
49
|
$opcode_cacher .= "apc.shm_size=\"8\"\n";
|
50
|
} else {
|
51
|
$opcode_cacher = "";
|
52
|
}
|
53
|
|
54
|
/* create a php.ini variable */
|
55
|
$php_conf = file_get_contents("/usr/local/lib/php.ini");
|
56
|
|
57
|
$php_ini = <<<EOFF
|
58
|
output_buffering = "0"
|
59
|
implicit_flush = true
|
60
|
magic_quotes_gpc = Off
|
61
|
max_execution_time = 99999999
|
62
|
max_input_time = 99999999
|
63
|
memory_limit = 32M
|
64
|
register_argc_argv = On
|
65
|
file_uploads = On
|
66
|
extension_dir=/usr/local/lib/php/extensions/no-debug-non-zts-20020429/
|
67
|
upload_tmp_dir = /tmp
|
68
|
upload_max_filesize = 100M
|
69
|
post_max_size = 100M
|
70
|
html_errors = Off
|
71
|
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
|
72
|
extension=radius.so
|
73
|
{$opcode_cacher}
|
74
|
|
75
|
EOFF;
|
76
|
|
77
|
config_lock();
|
78
|
conf_mount_rw();
|
79
|
|
80
|
/* open up php.ini and write back out contents */
|
81
|
$fd = fopen("/usr/local/lib/php.ini","w");
|
82
|
fwrite($fd, $php_ini);
|
83
|
fclose($fd);
|
84
|
|
85
|
mwexec("sync");
|
86
|
conf_mount_ro();
|
87
|
exec("sync");
|
88
|
config_unlock();
|
89
|
}
|
90
|
|
91
|
function system_resolvconf_generate($dynupdate = false) {
|
92
|
global $config, $g;
|
93
|
if(isset($config['system']['developerspew'])) {
|
94
|
$mt = microtime();
|
95
|
echo "system_resolvconf_generate() being called $mt\n";
|
96
|
}
|
97
|
|
98
|
$syscfg = $config['system'];
|
99
|
|
100
|
$fd = fopen("{$g['varetc_path']}/resolv.conf", "w");
|
101
|
if (!$fd) {
|
102
|
printf("Error: cannot open resolv.conf in system_resolvconf_generate().\n");
|
103
|
return 1;
|
104
|
}
|
105
|
|
106
|
$resolvconf = "domain {$syscfg['domain']}\n";
|
107
|
|
108
|
$havedns = false;
|
109
|
|
110
|
if (isset($syscfg['dnsallowoverride'])) {
|
111
|
/* get dynamically assigned DNS servers (if any) */
|
112
|
$ns = array_unique(get_nameservers());
|
113
|
foreach($ns as $nameserver) {
|
114
|
if($nameserver) {
|
115
|
$resolvconf .= "nameserver $nameserver\n";
|
116
|
$havedns = true;
|
117
|
}
|
118
|
}
|
119
|
}
|
120
|
if (!$havedns && is_array($syscfg['dnsserver'])) {
|
121
|
foreach ($syscfg['dnsserver'] as $ns) {
|
122
|
if ($ns) {
|
123
|
$resolvconf .= "nameserver $ns\n";
|
124
|
$havedns = true;
|
125
|
}
|
126
|
}
|
127
|
}
|
128
|
|
129
|
fwrite($fd, $resolvconf);
|
130
|
fclose($fd);
|
131
|
|
132
|
if (!$g['booting']) {
|
133
|
/* restart dhcpd (nameservers may have changed) */
|
134
|
if (!$dynupdate)
|
135
|
services_dhcpd_configure();
|
136
|
}
|
137
|
|
138
|
return 0;
|
139
|
}
|
140
|
|
141
|
function get_nameservers() {
|
142
|
global $config, $g;
|
143
|
$master_list = array();
|
144
|
$dns_lists = split("\n", `ls /var/etc/nameserver_* 2>/dev/null`);
|
145
|
foreach($dns_lists as $dns) {
|
146
|
$items = split("\n", file_get_contents($dns));
|
147
|
foreach($items as $item)
|
148
|
if($item <> "")
|
149
|
$master_list[] = $item;
|
150
|
}
|
151
|
if(!file_exists("/var/etc/nameservers.conf"))
|
152
|
return $master_list;
|
153
|
$dns = `cat /var/etc/nameservers.conf`;
|
154
|
$dns_s = split("\n", $dns);
|
155
|
if(is_array($dns_s))
|
156
|
foreach($dns_s as $dns)
|
157
|
$master_list[] = $dns;
|
158
|
return $master_list;
|
159
|
}
|
160
|
|
161
|
function system_hosts_generate() {
|
162
|
global $config, $g;
|
163
|
if(isset($config['system']['developerspew'])) {
|
164
|
$mt = microtime();
|
165
|
echo "system_hosts_generate() being called $mt\n";
|
166
|
}
|
167
|
|
168
|
$syscfg = $config['system'];
|
169
|
$lancfg = $config['interfaces']['lan'];
|
170
|
$dnsmasqcfg = $config['dnsmasq'];
|
171
|
|
172
|
if (!is_array($dnsmasqcfg['hosts'])) {
|
173
|
$dnsmasqcfg['hosts'] = array();
|
174
|
}
|
175
|
$hostscfg = $dnsmasqcfg['hosts'];
|
176
|
|
177
|
$fd = fopen("{$g['varetc_path']}/hosts", "w");
|
178
|
if (!$fd) {
|
179
|
log_error("Error: cannot open hosts file in system_hosts_generate().\n");
|
180
|
return 1;
|
181
|
}
|
182
|
|
183
|
$hosts = <<<EOD
|
184
|
127.0.0.1 localhost localhost.{$syscfg['domain']}
|
185
|
{$lancfg['ipaddr']} {$syscfg['hostname']}.{$syscfg['domain']} {$syscfg['hostname']}
|
186
|
|
187
|
EOD;
|
188
|
|
189
|
foreach ($hostscfg as $host) {
|
190
|
if ($host['host'])
|
191
|
$hosts .= "{$host['ip']} {$host['host']}.{$host['domain']} {$host['host']}\n";
|
192
|
else
|
193
|
$hosts .= "{$host['ip']} {$host['domain']}\n";
|
194
|
}
|
195
|
if (isset($dnsmasqcfg['regdhcpstatic'])) {
|
196
|
foreach ($config['dhcpd'] as $dhcpif => $dhcpifconf)
|
197
|
if(is_array($dhcpifconf['staticmap']) && isset($dhcpifconf['enable']))
|
198
|
foreach ($dhcpifconf['staticmap'] as $host)
|
199
|
if ($host['ipaddr'] && $host['hostname'])
|
200
|
$hosts .= "{$host['ipaddr']} {$host['hostname']}.{$syscfg['domain']} {$host['hostname']}\n";
|
201
|
}
|
202
|
fwrite($fd, $hosts);
|
203
|
fclose($fd);
|
204
|
|
205
|
return 0;
|
206
|
}
|
207
|
|
208
|
function system_hostname_configure() {
|
209
|
global $config, $g;
|
210
|
if(isset($config['system']['developerspew'])) {
|
211
|
$mt = microtime();
|
212
|
echo "system_hostname_configure() being called $mt\n";
|
213
|
}
|
214
|
|
215
|
$syscfg = $config['system'];
|
216
|
|
217
|
/* set hostname */
|
218
|
$status = mwexec("/bin/hostname " .
|
219
|
escapeshellarg("{$syscfg['hostname']}.{$syscfg['domain']}"));
|
220
|
|
221
|
/* Setup host GUID ID. This is used by ZFS. */
|
222
|
mwexec("/etc/rc.d/hostid start");
|
223
|
|
224
|
return $status;
|
225
|
}
|
226
|
|
227
|
function system_routing_configure() {
|
228
|
global $config, $g;
|
229
|
if(isset($config['system']['developerspew'])) {
|
230
|
$mt = microtime();
|
231
|
echo "system_routing_configure() being called $mt\n";
|
232
|
}
|
233
|
|
234
|
/* Enable fast routing, if enabled */
|
235
|
if(isset($config['staticroutes']['enablefastrouting']))
|
236
|
mwexec("/sbin/sysctl net.inet.ip.fastforwarding=1");
|
237
|
|
238
|
/* clear out old routes, if necessary */
|
239
|
exec("/usr/bin/netstat -rn", $route_arr, $retval);
|
240
|
$route_str = implode("\n", $route_arr);
|
241
|
|
242
|
if (file_exists("{$g['vardb_path']}/routes.db")) {
|
243
|
$fd = fopen("{$g['vardb_path']}/routes.db", "r");
|
244
|
if (!$fd) {
|
245
|
printf("Error: cannot open routes DB file in system_routing_configure().\n");
|
246
|
return 1;
|
247
|
}
|
248
|
while (!feof($fd)) {
|
249
|
$oldrt = trim(fgets($fd));
|
250
|
if (($oldrt) && (stristr($route_str, $oldrt)))
|
251
|
mwexec("/sbin/route delete " . escapeshellarg($oldrt));
|
252
|
}
|
253
|
fclose($fd);
|
254
|
unlink("{$g['vardb_path']}/routes.db");
|
255
|
}
|
256
|
|
257
|
if (is_array($config['staticroutes']['route'])) {
|
258
|
|
259
|
$fd = fopen("{$g['vardb_path']}/routes.db", "w");
|
260
|
if (!$fd) {
|
261
|
printf("Error: cannot open routes DB file in system_routing_configure().\n");
|
262
|
return 1;
|
263
|
}
|
264
|
|
265
|
foreach ($config['staticroutes']['route'] as $rtent) {
|
266
|
if(isset($rtent['interfacegateway'])) {
|
267
|
mwexec("/sbin/route add " . escapeshellarg($rtent['network']) .
|
268
|
" -iface " . escapeshellarg(convert_friendly_interface_to_real_interface_name($rtent['interface'])));
|
269
|
} else {
|
270
|
mwexec("/sbin/route add " . escapeshellarg($rtent['network']) .
|
271
|
" " . escapeshellarg($rtent['gateway']));
|
272
|
}
|
273
|
/* record route so it can be easily removed later (if necessary) */
|
274
|
fwrite($fd, $rtent['network'] . "\n");
|
275
|
}
|
276
|
|
277
|
fclose($fd);
|
278
|
}
|
279
|
|
280
|
/* Make sure default gateway is present */
|
281
|
$result = `/usr/bin/netstat -rn | grep default`;
|
282
|
if(!$result) {
|
283
|
if(is_ipaddr($config['interfaces']['wan']['gateway'])) {
|
284
|
log_error("No default gateway detected, adding {$config['interfaces']['wan']['gateway']}");
|
285
|
mwexec("/sbin/route add default " . escapeshellarg($config['interfaces']['wan']['gateway']));
|
286
|
}
|
287
|
}
|
288
|
return 0;
|
289
|
}
|
290
|
|
291
|
function system_routing_enable() {
|
292
|
global $config, $g;
|
293
|
if(isset($config['system']['developerspew'])) {
|
294
|
$mt = microtime();
|
295
|
echo "system_routing_enable() being called $mt\n";
|
296
|
}
|
297
|
|
298
|
return mwexec("/sbin/sysctl net.inet.ip.forwarding=1");
|
299
|
}
|
300
|
|
301
|
function system_syslogd_start() {
|
302
|
global $config, $g;
|
303
|
if(isset($config['system']['developerspew'])) {
|
304
|
$mt = microtime();
|
305
|
echo "system_syslogd_start() being called $mt\n";
|
306
|
}
|
307
|
|
308
|
$syslogcfg = $config['syslog'];
|
309
|
|
310
|
if ($g['booting'])
|
311
|
echo "Starting syslog...";
|
312
|
else
|
313
|
killbypid("{$g['varrun_path']}/syslog.pid");
|
314
|
|
315
|
if (isset($syslogcfg)) {
|
316
|
$separatelogfacilities = array('ntpd','racoon','openvpn');
|
317
|
if($config['installedpackages']['package']) {
|
318
|
foreach($config['installedpackages']['package'] as $package) {
|
319
|
if($package['logging']) {
|
320
|
$pkgfacilities[] = $package['logging']['facilityname'];
|
321
|
$separatelogfacilities = $separatelogfacilities + $pkgfacilities;
|
322
|
$facilitylist = implode(',', $pkgfacilities);
|
323
|
mwexec("clog -i -s 10000 {$g['varlog_path']}/{$package['logging']['logfilename']}");
|
324
|
$syslogconf .= "!{$facilitylist}\n*.*\t\t\t\t\t\t%{$g['varlog_path']}/{$package['logging']['logfilename']}\n";
|
325
|
}
|
326
|
}
|
327
|
}
|
328
|
$facilitylist = implode(',', array_unique($separatelogfacilities));
|
329
|
/* write syslog.conf */
|
330
|
$fd = fopen("{$g['varetc_path']}/syslog.conf", "w");
|
331
|
if (!$fd) {
|
332
|
printf("Error: cannot open syslog.conf in system_syslogd_start().\n");
|
333
|
return 1;
|
334
|
}
|
335
|
$syslogconf .= "!ntpdate,!ntpd\n";
|
336
|
if (!isset($syslogcfg['disablelocallogging'])) {
|
337
|
$syslogconf .= <<<EOD
|
338
|
*.* %{$g['varlog_path']}/ntpd.log
|
339
|
|
340
|
EOD;
|
341
|
}
|
342
|
$syslogconf .= "!apinger\n";
|
343
|
if (!isset($syslogcfg['disablelocallogging'])) {
|
344
|
$syslogconf .= <<<EOD
|
345
|
*.* %{$g['varlog_path']}/slbd.log
|
346
|
|
347
|
EOD;
|
348
|
}
|
349
|
$syslogconf .= "!racoon\n";
|
350
|
if (!isset($syslogcfg['disablelocallogging'])) {
|
351
|
$syslogconf .= <<<EOD
|
352
|
*.* %{$g['varlog_path']}/ipsec.log
|
353
|
|
354
|
EOD;
|
355
|
}
|
356
|
if (isset($syslogcfg['vpn'])) {
|
357
|
$syslogconf .= <<<EOD
|
358
|
*.* @{$syslogcfg['remoteserver']}
|
359
|
|
360
|
EOD;
|
361
|
}
|
362
|
$syslogconf .= "!openvpn\n";
|
363
|
if (!isset($syslogcfg['disablelocallogging'])) {
|
364
|
$syslogconf .= <<<EOD
|
365
|
*.* %{$g['varlog_path']}/openvpn.log
|
366
|
|
367
|
EOD;
|
368
|
}
|
369
|
if (isset($syslogcfg['vpn'])) {
|
370
|
$syslogconf .= <<<EOD
|
371
|
*.* @{$syslogcfg['remoteserver']}
|
372
|
|
373
|
EOD;
|
374
|
}
|
375
|
$syslogconf .= "!-{$facilitylist}\n";
|
376
|
if (!isset($syslogcfg['disablelocallogging'])) {
|
377
|
$syslogconf .= <<<EOD
|
378
|
local0.* %{$g['varlog_path']}/filter.log
|
379
|
local3.* %{$g['varlog_path']}/vpn.log
|
380
|
local4.* %{$g['varlog_path']}/portalauth.log
|
381
|
local7.* %{$g['varlog_path']}/dhcpd.log
|
382
|
*.notice;kern.debug;lpr.info;mail.crit; %{$g['varlog_path']}/system.log
|
383
|
news.err;local0.none;local3.none;local4.none; %{$g['varlog_path']}/system.log
|
384
|
local7.none %{$g['varlog_path']}/system.log
|
385
|
security.* %{$g['varlog_path']}/system.log
|
386
|
auth.info;authpriv.info;daemon.info %{$g['varlog_path']}/system.log
|
387
|
local1.* %{$g['varlog_path']}/slbd.log
|
388
|
auth.info;authpriv.info |exec /usr/local/sbin/sshlockout_pf
|
389
|
*.emerg *
|
390
|
|
391
|
EOD;
|
392
|
}
|
393
|
|
394
|
if (isset($syslogcfg['filter'])) {
|
395
|
$syslogconf .= <<<EOD
|
396
|
local0.* @{$syslogcfg['remoteserver']}
|
397
|
|
398
|
EOD;
|
399
|
}
|
400
|
|
401
|
if (isset($syslogcfg['vpn'])) {
|
402
|
$syslogconf .= <<<EOD
|
403
|
local3.* @{$syslogcfg['remoteserver']}
|
404
|
|
405
|
EOD;
|
406
|
}
|
407
|
|
408
|
|
409
|
if (isset($syslogcfg['portalauth'])) {
|
410
|
$syslogconf .= <<<EOD
|
411
|
local4.* @{$syslogcfg['remoteserver']}
|
412
|
|
413
|
EOD;
|
414
|
}
|
415
|
|
416
|
|
417
|
if (isset($syslogcfg['dhcp'])) {
|
418
|
$syslogconf .= <<<EOD
|
419
|
local7.* @{$syslogcfg['remoteserver']}
|
420
|
|
421
|
EOD;
|
422
|
}
|
423
|
|
424
|
if (isset($syslogcfg['system'])) {
|
425
|
$syslogconf .= <<<EOD
|
426
|
*.notice;kern.debug;lpr.info;mail.crit; @{$syslogcfg['remoteserver']}
|
427
|
news.err;local0.none;local3.none;local7.none @{$syslogcfg['remoteserver']}
|
428
|
security.* @{$syslogcfg['remoteserver']}
|
429
|
auth.info;authpriv.info;daemon.info @{$syslogcfg['remoteserver']}
|
430
|
*.emerg @{$syslogcfg['remoteserver']}
|
431
|
|
432
|
EOD;
|
433
|
}
|
434
|
fwrite($fd, $syslogconf);
|
435
|
fclose($fd);
|
436
|
|
437
|
// Are we logging to a least one remote server ?
|
438
|
if(strpos($syslogconf, "@") != false)
|
439
|
$retval = mwexec("/usr/sbin/syslogd -s -f {$g['varetc_path']}/syslog.conf");
|
440
|
else
|
441
|
$retval = mwexec("/usr/sbin/syslogd -ss -f {$g['varetc_path']}/syslog.conf");
|
442
|
|
443
|
} else {
|
444
|
$retval = mwexec("/usr/sbin/syslogd -ss");
|
445
|
}
|
446
|
|
447
|
if ($g['booting'])
|
448
|
echo "done.\n";
|
449
|
|
450
|
return $retval;
|
451
|
}
|
452
|
|
453
|
function system_pccard_start() {
|
454
|
global $config, $g;
|
455
|
if(isset($config['system']['developerspew'])) {
|
456
|
$mt = microtime();
|
457
|
echo "system_pccard_start() being called $mt\n";
|
458
|
}
|
459
|
|
460
|
if ($g['booting'])
|
461
|
echo "Initializing PCMCIA...";
|
462
|
|
463
|
/* kill any running pccardd */
|
464
|
killbypid("{$g['varrun_path']}/pccardd.pid");
|
465
|
|
466
|
/* fire up pccardd */
|
467
|
$res = mwexec("/usr/sbin/pccardd -z -f {$g['etc_path']}/pccard.conf");
|
468
|
|
469
|
if ($g['booting']) {
|
470
|
if ($res == 0)
|
471
|
echo "done.\n";
|
472
|
else
|
473
|
echo "failed!\n";
|
474
|
}
|
475
|
|
476
|
return $res;
|
477
|
}
|
478
|
|
479
|
|
480
|
function system_webgui_start() {
|
481
|
global $config, $g;
|
482
|
|
483
|
if ($g['booting'])
|
484
|
echo "Starting webConfigurator...";
|
485
|
|
486
|
/* kill any running lighttpd */
|
487
|
killbypid("{$g['varrun_path']}/lighty-webConfigurator.pid");
|
488
|
|
489
|
sleep(1);
|
490
|
|
491
|
/* generate password file */
|
492
|
system_password_configure();
|
493
|
|
494
|
chdir($g['www_path']);
|
495
|
|
496
|
/* non-standard port? */
|
497
|
if ($config['system']['webgui']['port'])
|
498
|
$portarg = "{$config['system']['webgui']['port']}";
|
499
|
else
|
500
|
$portarg = "";
|
501
|
|
502
|
if ($config['system']['webgui']['protocol'] == "https") {
|
503
|
|
504
|
if(!$config['system']['webgui']['port'])
|
505
|
$portarg = "443";
|
506
|
|
507
|
if ($config['system']['webgui']['certificate'] && $config['system']['webgui']['private-key']) {
|
508
|
$cert = base64_decode($config['system']['webgui']['certificate']);
|
509
|
$key = base64_decode($config['system']['webgui']['private-key']);
|
510
|
} else {
|
511
|
/* default certificate/key */
|
512
|
$cert = <<<EOD
|
513
|
-----BEGIN CERTIFICATE-----
|
514
|
MIIDEzCCAnygAwIBAgIJAJM91W+s6qptMA0GCSqGSIb3DQEBBAUAMGUxCzAJBgNV
|
515
|
BAYTAlVTMQswCQYDVQQIEwJLWTETMBEGA1UEBxMKTG91aXN2aWxsZTEQMA4GA1UE
|
516
|
ChMHcGZTZW5zZTEQMA4GA1UECxMHcGZTZW5zZTEQMA4GA1UEAxMHcGZTZW5zZTAe
|
517
|
Fw0wNjAzMTAyMzQ1MTlaFw0xNjAzMDcyMzQ1MTlaMGUxCzAJBgNVBAYTAlVTMQsw
|
518
|
CQYDVQQIEwJLWTETMBEGA1UEBxMKTG91aXN2aWxsZTEQMA4GA1UEChMHcGZTZW5z
|
519
|
ZTEQMA4GA1UECxMHcGZTZW5zZTEQMA4GA1UEAxMHcGZTZW5zZTCBnzANBgkqhkiG
|
520
|
9w0BAQEFAAOBjQAwgYkCgYEA3lPNTFH6qge/ygaqe/BS4oH59O6KvAesWcRzSu5N
|
521
|
21lyVE5tBbL0zqOSXmlLyReMSbtAMZqt1P8EPYFoOcaEQHIWm2VQF80Z18+8Gh4O
|
522
|
UQGjHq88OeaLqyk3OLpSKzSpXuCFrSN7q9Kez8zp5dQEu7sIW30da3pAbdqYOimA
|
523
|
1VsCAwEAAaOByjCBxzAdBgNVHQ4EFgQUAnx+ggC4SzJ0CK+rhPhJ2ZpyunEwgZcG
|
524
|
A1UdIwSBjzCBjIAUAnx+ggC4SzJ0CK+rhPhJ2ZpyunGhaaRnMGUxCzAJBgNVBAYT
|
525
|
AlVTMQswCQYDVQQIEwJLWTETMBEGA1UEBxMKTG91aXN2aWxsZTEQMA4GA1UEChMH
|
526
|
cGZTZW5zZTEQMA4GA1UECxMHcGZTZW5zZTEQMA4GA1UEAxMHcGZTZW5zZYIJAJM9
|
527
|
1W+s6qptMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAAviQpdoeabL8
|
528
|
1HSZiD7Yjx82pdLpyQOdXvAu3jEAYz53ckx0zSMrzsQ5r7Vae6AE7Xd7Pj+1Yihs
|
529
|
AJZzOQujnmsuim7qu6YSxzP34xonKwd1C9tZUlyNRNnEmtXOEDupn05bih1ugtLG
|
530
|
kqfPIgDbDLXuPtEAA6QDUypaunI6+1E=
|
531
|
-----END CERTIFICATE-----
|
532
|
|
533
|
EOD;
|
534
|
|
535
|
$key = <<<EOD
|
536
|
-----BEGIN RSA PRIVATE KEY-----
|
537
|
MIICXgIBAAKBgQDeU81MUfqqB7/KBqp78FLigfn07oq8B6xZxHNK7k3bWXJUTm0F
|
538
|
svTOo5JeaUvJF4xJu0Axmq3U/wQ9gWg5xoRAchabZVAXzRnXz7waHg5RAaMerzw5
|
539
|
5ourKTc4ulIrNKle4IWtI3ur0p7PzOnl1AS7uwhbfR1rekBt2pg6KYDVWwIDAQAB
|
540
|
AoGAP7E0VFP8Aq/7os3sE1uS8y8XQ7L+7cUo/AKKoQHKLjfeyAY7t3FALt6vdPqn
|
541
|
anGjkA/j4RIWELoKJfCnwj17703NDCPwB7klcmZvmTx5Om1ZrRyZdQ6RJs0pOOO1
|
542
|
r2wOnZNaNWStXE9Afpw3dj20Gh0V/Ioo5HXn3sHfxZm8dnkCQQDwv8OaUdp2Hl8t
|
543
|
FDfXB1CMvUG1hEAvbQvZK1ODkE7na2/ChKjVPddEI3DvfzG+nLrNuTrAyVWgRLte
|
544
|
r8qX5PQHAkEA7GlKx0S18LdiKo6wy2QeGu6HYkPncaHNFOWX8cTpvGGtQoWYSh0J
|
545
|
tjCt1/mz4/XkvZWuZyTNx2FdkVlNF5nHDQJBAIRWVTZqEjVlwpmsCHnp6mxCyHD4
|
546
|
DrRDNAUfnNuwIr9xPlDlzUzSnpc1CCqOd5C45LKbRGGfCrN7tKd66FmQoFcCQQCy
|
547
|
Kvw3R1pTCvHJnvYwoshphaC0dvaDVeyINiwYAk4hMf/wpVxLZqz+CJvLrB1dzOBR
|
548
|
3O+uPjdzbrakpweJpNQ1AkEA3ZtlgEj9eWsLAJP8aKlwB8VqD+EtG9OJSUMnCDiQ
|
549
|
WFFNj/t3Ze3IVuAyL/yMpiv3JNEnZhIxCta42eDFpIZAKw==
|
550
|
-----END RSA PRIVATE KEY-----
|
551
|
|
552
|
EOD;
|
553
|
}
|
554
|
} else {
|
555
|
$cert = "";
|
556
|
$key = "";
|
557
|
}
|
558
|
|
559
|
/* generate lighttpd configuration */
|
560
|
system_generate_lighty_config("{$g['varetc_path']}/lighty-webConfigurator.conf",
|
561
|
$cert, $key, "lighty-webConfigurator.pid", $portarg, "/usr/local/www/");
|
562
|
|
563
|
/* attempt to start lighthttpd */
|
564
|
$res = mwexec("/usr/local/sbin/lighttpd -f {$g['varetc_path']}/lighty-webConfigurator.conf");
|
565
|
|
566
|
if ($g['booting']) {
|
567
|
if ($res == 0)
|
568
|
echo "done.\n";
|
569
|
else
|
570
|
echo "failed!\n";
|
571
|
}
|
572
|
|
573
|
return $res;
|
574
|
}
|
575
|
|
576
|
function system_webgui_start_old() {
|
577
|
global $config, $g;
|
578
|
if(isset($config['system']['developerspew'])) {
|
579
|
$mt = microtime();
|
580
|
echo "system_webgui_start() being called $mt\n";
|
581
|
}
|
582
|
|
583
|
if ($g['booting'])
|
584
|
echo "Starting webConfigurator...";
|
585
|
|
586
|
/* kill any running mini_httpd */
|
587
|
killbypid("{$g['varrun_path']}/mini_httpd.pid");
|
588
|
|
589
|
/* generate password file */
|
590
|
system_password_configure();
|
591
|
|
592
|
chdir($g['www_path']);
|
593
|
|
594
|
/* non-standard port? */
|
595
|
if ($config['system']['webgui']['port'])
|
596
|
$portarg = "-p {$config['system']['webgui']['port']}";
|
597
|
else
|
598
|
$portarg = "";
|
599
|
|
600
|
if ($config['system']['webgui']['protocol'] == "https") {
|
601
|
|
602
|
if ($config['system']['webgui']['certificate'] && $config['system']['webgui']['private-key']) {
|
603
|
$cert = base64_decode($config['system']['webgui']['certificate']);
|
604
|
$key = base64_decode($config['system']['webgui']['private-key']);
|
605
|
} else {
|
606
|
/* default certificate/key */
|
607
|
$cert = <<<EOD
|
608
|
-----BEGIN CERTIFICATE-----
|
609
|
MIIBlDCB/gIBADANBgkqhkiG9w0BAQQFADATMREwDwYDVQQKEwhtMG4wd2FsbDAe
|
610
|
Fw0wNTA1MTAxMjI0NDRaFw0wNzA1MTAxMjI0NDRaMBMxETAPBgNVBAoTCG0wbjB3
|
611
|
YWxsMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDAShszhFz+o8lsMWTGgTxs
|
612
|
TMPR+v4+qL5jXDyY97MLTGFK7aqQOtpIQc+TcTc4jklgOVlHoR7oBXrsi8YrbCd+
|
613
|
83LPQmQoSPC0VqhfU3uYf3NzxiK8r97aPCsmWgwT2pQ6TcESTm6sF7nLprOf/zFP
|
614
|
C4jE2fvjkbzyVolPywBuewIDAQABMA0GCSqGSIb3DQEBBAUAA4GBAFR962c4R5tV
|
615
|
cTn0OQcszYoW6WC+ini9tQQh5ku5jYDAiC+00atawJEVLnL3lwAcpSKTIWlTkD20
|
616
|
tl3lz5br1qFgYky+Rd0kwS2nk9jRbkxSXxd6KJVnNRCKre28aw3ENzZfCSurPQsX
|
617
|
UPp5er+NtwMT1g7s/JDmKTC4w1rGr5/c
|
618
|
-----END CERTIFICATE-----
|
619
|
|
620
|
EOD;
|
621
|
|
622
|
$key = <<<EOD
|
623
|
-----BEGIN RSA PRIVATE KEY-----
|
624
|
MIICXQIBAAKBgQDAShszhFz+o8lsMWTGgTxsTMPR+v4+qL5jXDyY97MLTGFK7aqQ
|
625
|
OtpIQc+TcTc4jklgOVlHoR7oBXrsi8YrbCd+83LPQmQoSPC0VqhfU3uYf3NzxiK8
|
626
|
r97aPCsmWgwT2pQ6TcESTm6sF7nLprOf/zFPC4jE2fvjkbzyVolPywBuewIDAQAB
|
627
|
AoGAbJJrQW9fQrggJuLMz/hwsYW2m31oyOBmf5u463YQtjRuSuxe/gj87weZuNqY
|
628
|
H2rXq2k2K+ehl8hgW+egASyUL3L7kCkEAsVREujKTEyhSqqIRDPWTxo9S/YA9Gvn
|
629
|
2ZnJvkrcKjqCO9aHX3rvJOK/ErYI6akctgI3KmgkYw5XNmECQQDuZU97RTWH9rmP
|
630
|
aQr57ysNXxgFsyhetOOqeYkPtIVwpOiNbfwE1zi5RGdtO4Ku3fG1lV4J2UoWJ9yD
|
631
|
awdoyYIHAkEAzn0xJ90IjPsHk+8SODEj5JGdHSZPNu1tgtrbjEi9sfGWg4K7XTxr
|
632
|
QW90pWb1bKKU1uh5FzW6OhnFfuQXt1kC7QJAPSthqY+onKqCEnoxhtAHi/bKgyvl
|
633
|
P+fKQwPMV2tKkgy+XwvJjrRqqZ8TqsOKVLQ+QQmCh6RpjiXMPyxHSmvqIQJBAKLR
|
634
|
HF1ucDuaBROkwx0DwmWMW/KMLpIFDQDNSaiIAuu4rxHrl4mhBoGGPNffI04RtILw
|
635
|
s+qVNs5xW8T+XaT4ztECQQDFHPnZeoPWE5z+AX/UUQIUWaDExz3XRzmIxRbOrlFi
|
636
|
CsF1s0TdJLi/wzNQRAL37A8vqCeVFR/ng3Xpg96Yg+8Z
|
637
|
-----END RSA PRIVATE KEY-----
|
638
|
|
639
|
EOD;
|
640
|
}
|
641
|
|
642
|
$cert = str_replace("\r", "", $cert);
|
643
|
$key = str_replace("\r", "", $key);
|
644
|
|
645
|
$fd = fopen("{$g['varetc_path']}/cert.pem", "w");
|
646
|
if (!$fd) {
|
647
|
printf("Error: cannot open cert.pem in system_webgui_start().\n");
|
648
|
return 1;
|
649
|
}
|
650
|
chmod("{$g['varetc_path']}/cert.pem", 0600);
|
651
|
fwrite($fd, $cert);
|
652
|
fwrite($fd, "\n");
|
653
|
fwrite($fd, $key);
|
654
|
fclose($fd);
|
655
|
|
656
|
$res = mwexec("/usr/local/sbin/mini_httpd -S -E {$g['varetc_path']}/cert.pem" .
|
657
|
" -c \"**.php|**.cgi\" -u root -maxproc 16 $portarg" .
|
658
|
" -i {$g['varrun_path']}/mini_httpd.pid");
|
659
|
} else {
|
660
|
$res = mwexec("/usr/local/sbin/mini_httpd -c \"**.php|**.cgi\" -u root" .
|
661
|
" -maxproc 16 $portarg -i {$g['varrun_path']}/mini_httpd.pid");
|
662
|
}
|
663
|
|
664
|
if ($g['booting']) {
|
665
|
if ($res == 0)
|
666
|
echo "done\n";
|
667
|
else
|
668
|
echo "failed\n";
|
669
|
}
|
670
|
|
671
|
return $res;
|
672
|
}
|
673
|
|
674
|
function system_generate_lighty_config($filename,
|
675
|
$cert,
|
676
|
$key,
|
677
|
$pid_file,
|
678
|
$port = 80,
|
679
|
$document_root = "/usr/local/www/",
|
680
|
$cert_location = "cert.pem",
|
681
|
$max_procs = 2,
|
682
|
$max_requests = "1",
|
683
|
$fast_cgi_enable = true,
|
684
|
$captive_portal = false) {
|
685
|
|
686
|
global $config, $g;
|
687
|
|
688
|
if(isset($config['system']['developerspew'])) {
|
689
|
$mt = microtime();
|
690
|
echo "system_generate_lighty_config() being called $mt\n";
|
691
|
}
|
692
|
|
693
|
if($captive_portal == true) {
|
694
|
$captiveportal = ",\"mod_rewrite\"";
|
695
|
$captive_portal_rewrite = "url.rewrite-once = ( \"(.*captiveportal.*)\" => \"$1\", \"(.*)\" => \"/index.php?redirurl=$1\" )\n";
|
696
|
$captive_portal_module = "\"mod_accesslog\", ";
|
697
|
$maxprocperip = $config['captiveportal']['maxprocperip'];
|
698
|
if(!$maxprocperip and $maxprocperip > 0)
|
699
|
$captive_portal_mod_evasive = "evasive.max-conns-per-ip = {$maxprocperip}";
|
700
|
else
|
701
|
$captive_portal_mod_evasive = "";
|
702
|
$server_upload_dirs = "server.upload-dirs = ( \"/tmp/captiveportal/\" )\n";
|
703
|
exec("mkdir -p /tmp/captiveportal");
|
704
|
exec("chmod a-w /tmp/captiveportal");
|
705
|
$server_max_request_size = "server.max-request-size = 384";
|
706
|
} else {
|
707
|
$captive_portal_module = "";
|
708
|
$captive_portal_mod_evasive = "";
|
709
|
$server_upload_dirs = "server.upload-dirs = ( \"{$g['upload_path']}/\", \"/tmp/\", \"/var/\" )\n";
|
710
|
$server_max_request_size = "server.max-request-size = 2097152";
|
711
|
}
|
712
|
|
713
|
if($port <> "")
|
714
|
$lighty_port = $port;
|
715
|
else
|
716
|
$lighty_port = "80";
|
717
|
|
718
|
$memory = get_memory();
|
719
|
$avail = $memory[0];
|
720
|
|
721
|
if($avail > 0 and $avail < 98) {
|
722
|
$max_procs = 1;
|
723
|
$max_requests = 1;
|
724
|
}
|
725
|
|
726
|
if($avail > 97 and $avail < 128) {
|
727
|
$max_procs = 1;
|
728
|
$max_requests = 3;
|
729
|
}
|
730
|
|
731
|
if($avail > 127 and $avail < 256) {
|
732
|
$max_procs = 1;
|
733
|
$max_requests = 5;
|
734
|
}
|
735
|
|
736
|
if($avail > 255 and $avail < 384) {
|
737
|
$max_procs = 3;
|
738
|
$max_requests = 10;
|
739
|
}
|
740
|
|
741
|
if($avail > 384) {
|
742
|
$max_procs = 4;
|
743
|
$max_requests = 16;
|
744
|
}
|
745
|
|
746
|
if($captive_portal == true) {
|
747
|
$bin_environment = <<<EOC
|
748
|
"bin-environment" => (
|
749
|
"PHP_FCGI_CHILDREN" => "16",
|
750
|
"PHP_FCGI_MAX_REQUESTS" => "{$max_requests}"
|
751
|
),
|
752
|
EOC;
|
753
|
|
754
|
} else {
|
755
|
$bin_environment = "";
|
756
|
}
|
757
|
|
758
|
if($fast_cgi_enable == true) {
|
759
|
$module = "\"mod_fastcgi\", \"mod_cgi\"";
|
760
|
$cgi_config = "";
|
761
|
$fastcgi_config = <<<EOD
|
762
|
#### fastcgi module
|
763
|
## read fastcgi.txt for more info
|
764
|
fastcgi.server = ( ".php" =>
|
765
|
( "localhost" =>
|
766
|
(
|
767
|
"socket" => "/tmp/php-fastcgi.socket",
|
768
|
"min-procs" => 1,
|
769
|
"max-procs" => {$max_procs},
|
770
|
"idle-timeout" => 0,
|
771
|
{$bin_environment}
|
772
|
"bin-path" => "/usr/local/bin/php"
|
773
|
)
|
774
|
)
|
775
|
)
|
776
|
|
777
|
#### CGI module
|
778
|
cgi.assign = ( ".cgi" => "" )
|
779
|
|
780
|
EOD;
|
781
|
} else {
|
782
|
$fastcgi_config = "";
|
783
|
$module = "\"mod_cgi\"";
|
784
|
$cgi_config = <<<EOD
|
785
|
#### CGI module
|
786
|
cgi.assign = ( ".php" => "/usr/local/bin/php",
|
787
|
".cgi" => "" )
|
788
|
|
789
|
EOD;
|
790
|
}
|
791
|
|
792
|
$lighty_config .= <<<EOD
|
793
|
#
|
794
|
# lighttpd configuration file
|
795
|
#
|
796
|
# use a it as base for lighttpd 1.0.0 and above
|
797
|
#
|
798
|
############ Options you really have to take care of ####################
|
799
|
|
800
|
## FreeBSD!
|
801
|
server.event-handler = "freebsd-kqueue"
|
802
|
server.network-backend = "writev" ## Fixes 7.x upload issues
|
803
|
|
804
|
{$network_handler}
|
805
|
|
806
|
## modules to load
|
807
|
server.modules = (
|
808
|
{$captive_portal_module}
|
809
|
"mod_access", "mod_accesslog",
|
810
|
{$module}{$captiveportal}
|
811
|
)
|
812
|
|
813
|
## Unused modules
|
814
|
# "mod_setenv",
|
815
|
# "mod_compress"
|
816
|
# "mod_redirect",
|
817
|
# "mod_rewrite",
|
818
|
# "mod_ssi",
|
819
|
# "mod_usertrack",
|
820
|
# "mod_expire",
|
821
|
# "mod_secdownload",
|
822
|
# "mod_rrdtool",
|
823
|
# "mod_auth",
|
824
|
# "mod_status",
|
825
|
# "mod_alias",
|
826
|
# "mod_proxy",
|
827
|
# "mod_simple_vhost",
|
828
|
# "mod_evhost",
|
829
|
# "mod_userdir",
|
830
|
# "mod_cgi",
|
831
|
# "mod_accesslog"
|
832
|
|
833
|
## a static document-root, for virtual-hosting take look at the
|
834
|
## server.virtual-* options
|
835
|
server.document-root = "{$document_root}"
|
836
|
{$captive_portal_rewrite}
|
837
|
|
838
|
# Maximum idle time with nothing being written (php downloading)
|
839
|
server.max-write-idle = 999
|
840
|
|
841
|
## where to send error-messages to
|
842
|
server.errorlog = "/var/log/lighttpd.error.log"
|
843
|
|
844
|
# files to check for if .../ is requested
|
845
|
server.indexfiles = ( "index.php", "index.html",
|
846
|
"index.htm", "default.htm" )
|
847
|
|
848
|
# mimetype mapping
|
849
|
mimetype.assign = (
|
850
|
".pdf" => "application/pdf",
|
851
|
".sig" => "application/pgp-signature",
|
852
|
".spl" => "application/futuresplash",
|
853
|
".class" => "application/octet-stream",
|
854
|
".ps" => "application/postscript",
|
855
|
".torrent" => "application/x-bittorrent",
|
856
|
".dvi" => "application/x-dvi",
|
857
|
".gz" => "application/x-gzip",
|
858
|
".pac" => "application/x-ns-proxy-autoconfig",
|
859
|
".swf" => "application/x-shockwave-flash",
|
860
|
".tar.gz" => "application/x-tgz",
|
861
|
".tgz" => "application/x-tgz",
|
862
|
".tar" => "application/x-tar",
|
863
|
".zip" => "application/zip",
|
864
|
".mp3" => "audio/mpeg",
|
865
|
".m3u" => "audio/x-mpegurl",
|
866
|
".wma" => "audio/x-ms-wma",
|
867
|
".wax" => "audio/x-ms-wax",
|
868
|
".ogg" => "audio/x-wav",
|
869
|
".wav" => "audio/x-wav",
|
870
|
".gif" => "image/gif",
|
871
|
".jpg" => "image/jpeg",
|
872
|
".jpeg" => "image/jpeg",
|
873
|
".png" => "image/png",
|
874
|
".xbm" => "image/x-xbitmap",
|
875
|
".xpm" => "image/x-xpixmap",
|
876
|
".xwd" => "image/x-xwindowdump",
|
877
|
".css" => "text/css",
|
878
|
".html" => "text/html",
|
879
|
".htm" => "text/html",
|
880
|
".js" => "text/javascript",
|
881
|
".asc" => "text/plain",
|
882
|
".c" => "text/plain",
|
883
|
".conf" => "text/plain",
|
884
|
".text" => "text/plain",
|
885
|
".txt" => "text/plain",
|
886
|
".dtd" => "text/xml",
|
887
|
".xml" => "text/xml",
|
888
|
".mpeg" => "video/mpeg",
|
889
|
".mpg" => "video/mpeg",
|
890
|
".mov" => "video/quicktime",
|
891
|
".qt" => "video/quicktime",
|
892
|
".avi" => "video/x-msvideo",
|
893
|
".asf" => "video/x-ms-asf",
|
894
|
".asx" => "video/x-ms-asf",
|
895
|
".wmv" => "video/x-ms-wmv",
|
896
|
".bz2" => "application/x-bzip",
|
897
|
".tbz" => "application/x-bzip-compressed-tar",
|
898
|
".tar.bz2" => "application/x-bzip-compressed-tar"
|
899
|
)
|
900
|
|
901
|
# Use the "Content-Type" extended attribute to obtain mime type if possible
|
902
|
#mimetypes.use-xattr = "enable"
|
903
|
|
904
|
#### accesslog module
|
905
|
#accesslog.filename = "/dev/null"
|
906
|
|
907
|
## deny access the file-extensions
|
908
|
#
|
909
|
# ~ is for backupfiles from vi, emacs, joe, ...
|
910
|
# .inc is often used for code includes which should in general not be part
|
911
|
# of the document-root
|
912
|
url.access-deny = ( "~", ".inc" )
|
913
|
|
914
|
|
915
|
######### Options that are good to be but not neccesary to be changed #######
|
916
|
|
917
|
## bind to port (default: 80)
|
918
|
server.port = {$lighty_port}
|
919
|
|
920
|
## error-handler for status 404
|
921
|
#server.error-handler-404 = "/error-handler.html"
|
922
|
#server.error-handler-404 = "/error-handler.php"
|
923
|
|
924
|
## to help the rc.scripts
|
925
|
server.pid-file = "/var/run/{$pid_file}"
|
926
|
|
927
|
## virtual directory listings
|
928
|
server.dir-listing = "disable"
|
929
|
|
930
|
## enable debugging
|
931
|
debug.log-request-header = "disable"
|
932
|
debug.log-response-header = "disable"
|
933
|
debug.log-request-handling = "disable"
|
934
|
debug.log-file-not-found = "disable"
|
935
|
|
936
|
#### compress module
|
937
|
#compress.cache-dir = "/tmp/lighttpd/cache/compress/"
|
938
|
#compress.filetype = ("text/plain", "text/html")
|
939
|
|
940
|
#server.network-backend = "writev"
|
941
|
|
942
|
{$server_upload_dirs}
|
943
|
|
944
|
{$server_max_request_size}
|
945
|
|
946
|
{$fastcgi_config}
|
947
|
|
948
|
{$cgi_config}
|
949
|
|
950
|
{$captive_portal_mod_evasive}
|
951
|
|
952
|
EOD;
|
953
|
|
954
|
$cert = str_replace("\r", "", $cert);
|
955
|
$key = str_replace("\r", "", $key);
|
956
|
|
957
|
$cert = str_replace("\n\n", "\n", $cert);
|
958
|
$key = str_replace("\n\n", "\n", $key);
|
959
|
|
960
|
if($cert <> "" and $key <> "") {
|
961
|
$fd = fopen("{$g['varetc_path']}/{$cert_location}", "w");
|
962
|
if (!$fd) {
|
963
|
printf("Error: cannot open cert.pem in system_webgui_start().\n");
|
964
|
return 1;
|
965
|
}
|
966
|
chmod("{$g['varetc_path']}/{$cert_location}", 0600);
|
967
|
fwrite($fd, $cert);
|
968
|
fwrite($fd, "\n");
|
969
|
fwrite($fd, $key);
|
970
|
fclose($fd);
|
971
|
$lighty_config .= "\n";
|
972
|
$lighty_config .= "## ssl configuration\n";
|
973
|
$lighty_config .= "ssl.engine = \"enable\"\n";
|
974
|
$lighty_config .= "ssl.pemfile = \"{$g['varetc_path']}/{$cert_location}\"\n\n";
|
975
|
}
|
976
|
|
977
|
$fd = fopen("{$filename}", "w");
|
978
|
if (!$fd) {
|
979
|
printf("Error: cannot open {$filename} in system_generate_lighty_config().\n");
|
980
|
return 1;
|
981
|
}
|
982
|
fwrite($fd, $lighty_config);
|
983
|
fclose($fd);
|
984
|
|
985
|
return 0;
|
986
|
|
987
|
}
|
988
|
|
989
|
function system_password_configure() {
|
990
|
global $config, $g;
|
991
|
if(isset($config['system']['developerspew'])) {
|
992
|
$mt = microtime();
|
993
|
echo "system_password_configure() being called $mt\n";
|
994
|
}
|
995
|
|
996
|
/* sync passwords */
|
997
|
sync_webgui_passwords();
|
998
|
|
999
|
/* !NOTE! conf_mount_ro is done by sync_webgui_passwords() */
|
1000
|
|
1001
|
return 0;
|
1002
|
}
|
1003
|
|
1004
|
function system_timezone_configure() {
|
1005
|
global $config, $g;
|
1006
|
if(isset($config['system']['developerspew'])) {
|
1007
|
$mt = microtime();
|
1008
|
echo "system_timezone_configure() being called $mt\n";
|
1009
|
}
|
1010
|
|
1011
|
$syscfg = $config['system'];
|
1012
|
|
1013
|
if ($g['booting'])
|
1014
|
echo "Setting timezone...";
|
1015
|
|
1016
|
/* extract appropriate timezone file */
|
1017
|
$timezone = $syscfg['timezone'];
|
1018
|
if (!$timezone)
|
1019
|
$timezone = "Etc/UTC";
|
1020
|
|
1021
|
conf_mount_rw();
|
1022
|
|
1023
|
exec("LANG=C /usr/bin/tar xzfO /usr/share/zoneinfo.tgz " .
|
1024
|
escapeshellarg($timezone) . " > /etc/localtime");
|
1025
|
|
1026
|
mwexec("sync");
|
1027
|
conf_mount_ro();
|
1028
|
|
1029
|
if ($g['booting'])
|
1030
|
echo "done.\n";
|
1031
|
}
|
1032
|
|
1033
|
function system_ntp_configure() {
|
1034
|
global $config, $g;
|
1035
|
|
1036
|
$syscfg = $config['system'];
|
1037
|
|
1038
|
/* open configuration for wrting or bail */
|
1039
|
$fd = fopen("{$g['varetc_path']}/ntpd.conf","w");
|
1040
|
if(!$fd) {
|
1041
|
log_error("Could not open {$g['varetc_path']}/ntpd.conf for writing");
|
1042
|
return;
|
1043
|
}
|
1044
|
|
1045
|
fwrite($fd, "# \n");
|
1046
|
fwrite($fd, "# pfSense OpenNTPD configuration file \n");
|
1047
|
fwrite($fd, "# \n\n");
|
1048
|
|
1049
|
/* foreach through servers and write out to ntpd.conf */
|
1050
|
foreach (explode(' ', $syscfg['timeservers']) as $ts)
|
1051
|
fwrite($fd, "servers {$ts}\n");
|
1052
|
|
1053
|
/* server config is in coregui1 */
|
1054
|
$xmlsettings = $config['installedpackages']['openntpd']['config'][0];
|
1055
|
if ($xmlsettings['enable'] == 'on') {
|
1056
|
$ifaces = explode(',', $xmlsettings['interface']);
|
1057
|
$ifaces = array_map('convert_friendly_interface_to_real_interface_name', $ifaces);
|
1058
|
$ifaces = array_filter($ifaces, 'does_interface_exist');
|
1059
|
$ips = array_map('find_interface_ip', $ifaces);
|
1060
|
foreach ($ips as $ip) {
|
1061
|
if (is_ipaddr($ip))
|
1062
|
fwrite($fd, "listen on $ip\n");
|
1063
|
}
|
1064
|
}
|
1065
|
|
1066
|
fwrite($fd, "\n");
|
1067
|
|
1068
|
/* slurp! */
|
1069
|
fclose($fd);
|
1070
|
|
1071
|
/* if openntpd is running, kill it */
|
1072
|
while(is_process_running("ntpd")) {
|
1073
|
mwexec("/usr/bin/killall ntpd", true);
|
1074
|
}
|
1075
|
|
1076
|
/* if /var/empty does not exist, create it */
|
1077
|
if(!is_dir("/var/empty"))
|
1078
|
exec("/bin/mkdir -p /var/empty && chmod ug+rw /var/empty/.");
|
1079
|
|
1080
|
if($g['booting'])
|
1081
|
return;
|
1082
|
|
1083
|
/* start opentpd, set time now and use /var/etc/ntpd.conf */
|
1084
|
exec("/usr/local/sbin/ntpd -s -f {$g['varetc_path']}/ntpd.conf");
|
1085
|
|
1086
|
}
|
1087
|
|
1088
|
function sync_system_time() {
|
1089
|
global $config, $g;
|
1090
|
|
1091
|
$syscfg = $config['system'];
|
1092
|
|
1093
|
if ($g['booting'])
|
1094
|
echo "Syncing system time before startup...";
|
1095
|
|
1096
|
/* foreach through servers and write out to ntpd.conf */
|
1097
|
foreach (explode(' ', $syscfg['timeservers']) as $ts) {
|
1098
|
mwexec("/usr/sbin/ntpdate -s $ts");
|
1099
|
}
|
1100
|
|
1101
|
if ($g['booting'])
|
1102
|
echo "done.\n";
|
1103
|
|
1104
|
}
|
1105
|
|
1106
|
function system_halt() {
|
1107
|
global $g;
|
1108
|
|
1109
|
system_reboot_cleanup();
|
1110
|
|
1111
|
mwexec("nohup /etc/rc.halt > /dev/null 2>&1 &");
|
1112
|
}
|
1113
|
|
1114
|
function system_reboot() {
|
1115
|
global $g;
|
1116
|
|
1117
|
system_reboot_cleanup();
|
1118
|
|
1119
|
mwexec("nohup /etc/rc.reboot > /dev/null 2>&1 &");
|
1120
|
}
|
1121
|
|
1122
|
function system_reboot_sync() {
|
1123
|
global $g;
|
1124
|
|
1125
|
system_reboot_cleanup();
|
1126
|
|
1127
|
mwexec("/etc/rc.reboot > /dev/null 2>&1");
|
1128
|
}
|
1129
|
|
1130
|
function system_reboot_cleanup() {
|
1131
|
mwexec("/usr/local/bin/beep.sh stop");
|
1132
|
captiveportal_radius_stop_all();
|
1133
|
}
|
1134
|
|
1135
|
function system_do_shell_commands($early = 0) {
|
1136
|
global $config, $g;
|
1137
|
if(isset($config['system']['developerspew'])) {
|
1138
|
$mt = microtime();
|
1139
|
echo "system_do_shell_commands() being called $mt\n";
|
1140
|
}
|
1141
|
|
1142
|
if ($early)
|
1143
|
$cmdn = "earlyshellcmd";
|
1144
|
else
|
1145
|
$cmdn = "shellcmd";
|
1146
|
|
1147
|
if (is_array($config['system'][$cmdn])) {
|
1148
|
|
1149
|
/* *cmd is an array, loop through */
|
1150
|
foreach ($config['system'][$cmdn] as $cmd) {
|
1151
|
exec($cmd);
|
1152
|
}
|
1153
|
|
1154
|
} elseif($config['system'][$cmdn] <> "") {
|
1155
|
|
1156
|
/* execute single item */
|
1157
|
exec($config['system'][$cmdn]);
|
1158
|
|
1159
|
}
|
1160
|
}
|
1161
|
|
1162
|
function system_console_configure() {
|
1163
|
global $config, $g;
|
1164
|
if(isset($config['system']['developerspew'])) {
|
1165
|
$mt = microtime();
|
1166
|
echo "system_console_configure() being called $mt\n";
|
1167
|
}
|
1168
|
|
1169
|
if (isset($config['system']['disableconsolemenu'])) {
|
1170
|
touch("{$g['varetc_path']}/disableconsole");
|
1171
|
} else {
|
1172
|
unlink_if_exists("{$g['varetc_path']}/disableconsole");
|
1173
|
}
|
1174
|
}
|
1175
|
|
1176
|
function system_dmesg_save() {
|
1177
|
global $g;
|
1178
|
if(isset($config['system']['developerspew'])) {
|
1179
|
$mt = microtime();
|
1180
|
echo "system_dmesg_save() being called $mt\n";
|
1181
|
}
|
1182
|
|
1183
|
$dmesg = "";
|
1184
|
exec("/sbin/dmesg", $dmesg);
|
1185
|
|
1186
|
/* find last copyright line (output from previous boots may be present) */
|
1187
|
$lastcpline = 0;
|
1188
|
|
1189
|
for ($i = 0; $i < count($dmesg); $i++) {
|
1190
|
if (strstr($dmesg[$i], "Copyright (c) 1992-"))
|
1191
|
$lastcpline = $i;
|
1192
|
}
|
1193
|
|
1194
|
$fd = fopen("{$g['varlog_path']}/dmesg.boot", "w");
|
1195
|
if (!$fd) {
|
1196
|
printf("Error: cannot open dmesg.boot in system_dmesg_save().\n");
|
1197
|
return 1;
|
1198
|
}
|
1199
|
|
1200
|
for ($i = $lastcpline; $i < count($dmesg); $i++)
|
1201
|
fwrite($fd, $dmesg[$i] . "\n");
|
1202
|
|
1203
|
fclose($fd);
|
1204
|
|
1205
|
return 0;
|
1206
|
}
|
1207
|
|
1208
|
function system_set_harddisk_standby() {
|
1209
|
global $g, $config;
|
1210
|
if(isset($config['system']['developerspew'])) {
|
1211
|
$mt = microtime();
|
1212
|
echo "system_set_harddisk_standby() being called $mt\n";
|
1213
|
}
|
1214
|
|
1215
|
if (isset($config['system']['harddiskstandby'])) {
|
1216
|
if ($g['booting']) {
|
1217
|
echo 'Setting hard disk standby... ';
|
1218
|
}
|
1219
|
|
1220
|
$standby = $config['system']['harddiskstandby'];
|
1221
|
// Check for a numeric value
|
1222
|
if (is_numeric($standby)) {
|
1223
|
// Sync the disk(s)
|
1224
|
mwexec('/bin/sync');
|
1225
|
if (!mwexec('/sbin/sysctl hw.ata.standby=' . ((int)$standby))) {
|
1226
|
// Reinitialize ATA-drives
|
1227
|
mwexec('/usr/local/sbin/atareinit');
|
1228
|
if ($g['booting']) {
|
1229
|
echo "done.\n";
|
1230
|
}
|
1231
|
} else if ($g['booting']) {
|
1232
|
echo "failed!\n";
|
1233
|
}
|
1234
|
} else if ($g['booting']) {
|
1235
|
echo "failed!\n";
|
1236
|
}
|
1237
|
}
|
1238
|
}
|
1239
|
|
1240
|
function system_setup_sysctl() {
|
1241
|
global $config;
|
1242
|
if(isset($config['system']['developerspew'])) {
|
1243
|
$mt = microtime();
|
1244
|
echo "system_setup_sysctl() being called $mt\n";
|
1245
|
}
|
1246
|
|
1247
|
$sysctl = return_filename_as_array("/etc/sysctl.conf");
|
1248
|
foreach($sysctl as $sysc) {
|
1249
|
$sysc = rtrim($sysc);
|
1250
|
if($sysc <> "")
|
1251
|
mwexec("sysctl {$sysc} 2>/dev/null");
|
1252
|
}
|
1253
|
if (isset($config['system']['sharednet'])) {
|
1254
|
system_disable_arp_wrong_if();
|
1255
|
}
|
1256
|
}
|
1257
|
|
1258
|
function system_disable_arp_wrong_if() {
|
1259
|
global $config;
|
1260
|
if(isset($config['system']['developerspew'])) {
|
1261
|
$mt = microtime();
|
1262
|
echo "system_disable_arp_wrong_if() being called $mt\n";
|
1263
|
}
|
1264
|
mwexec("/sbin/sysctl -n net.link.ether.inet.log_arp_wrong_iface=0");
|
1265
|
mwexec("/sbin/sysctl -n net.link.ether.inet.log_arp_movements=0");
|
1266
|
}
|
1267
|
|
1268
|
function system_enable_arp_wrong_if() {
|
1269
|
global $config;
|
1270
|
if(isset($config['system']['developerspew'])) {
|
1271
|
$mt = microtime();
|
1272
|
echo "system_enable_arp_wrong_if() being called $mt\n";
|
1273
|
}
|
1274
|
mwexec("/sbin/sysctl -n net.link.ether.inet.log_arp_wrong_iface=1");
|
1275
|
mwexec("/sbin/sysctl -n net.link.ether.inet.log_arp_movements=1");
|
1276
|
}
|
1277
|
|
1278
|
?>
|