Project

General

Profile

Download (33.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	system.inc
5
	part of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

    
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19

    
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31

    
32
/* include all configuration functions */
33
require_once("functions.inc");
34

    
35
function opcode_cache_configuration() {
36
		global $g;
37
        if($g['platform'] == "cdrom")
38
        	return;
39
        /* get system memory amount */
40
        $memory = get_memory();
41
        $avail = $memory[0];
42

    
43
		/* disable apc for platforms less than 90 megs of ram */
44
        if($memory > 90) {
45
        	$opcode_cacher = "extension=apc.so\n";
46
        	$opcode_cacher .= "apc.enabled=\"1\"\n";
47
			$opcode_cacher .= "apc.enable_cli=\"1\"\n";
48
			$opcode_cacher .= "apc.shm_size=\"7\"\n";
49
        } else {
50
			$opcode_cacher = "";
51
        }
52

    
53
		/* create a php.ini variable */
54
		$php_conf = file_get_contents("/usr/local/lib/php.ini");
55

    
56
$php_ini = <<<EOFF
57
output_buffering = "0"
58
implicit_flush = true
59
magic_quotes_gpc = Off
60
max_execution_time = 99999999
61
max_input_time = 99999999
62
register_argc_argv = On
63
file_uploads = On
64
upload_tmp_dir = /tmp
65
upload_max_filesize = 100M
66
post_max_size = 100M
67
html_errors = Off
68
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
69
extension=radius.so
70
{$opcode_cacher}
71

    
72
EOFF;
73

    
74
		conf_mount_rw();
75

    
76
		/* open up php.ini and write back out contents */
77
		$fd = fopen("/usr/local/lib/php.ini","w");
78
		fwrite($fd, $php_ini);
79
		fclose($fd);
80

    
81
		conf_mount_ro();
82
}
83

    
84
function system_resolvconf_generate($dynupdate = false) {
85
	global $config, $g;
86
	if(isset($config['system']['developerspew'])) {
87
		$mt = microtime();
88
		echo "system_resolvconf_generate() being called $mt\n";
89
	}
90

    
91
        $syscfg = $config['system'];
92

    
93
        $fd = fopen("{$g['varetc_path']}/resolv.conf", "w");
94
        if (!$fd) {
95
                printf("Error: cannot open resolv.conf in system_resolvconf_generate().\n");
96
                return 1;
97
        }
98

    
99
        $resolvconf = "domain {$syscfg['domain']}\n";
100

    
101
        $havedns = false;
102

    
103
        if (isset($syscfg['dnsallowoverride'])) {
104
                /* get dynamically assigned DNS servers (if any) */
105
		$ns = array_unique(get_nameservers());
106
		foreach($ns as $nameserver) {
107
			if($nameserver) {
108
				$resolvconf .= "nameserver $nameserver\n";
109
				$havedns = true;
110
			}
111
		}
112
        }
113
        if (!$havedns && is_array($syscfg['dnsserver'])) {
114
                foreach ($syscfg['dnsserver'] as $ns) {
115
                        if ($ns) {
116
                                $resolvconf .= "nameserver $ns\n";
117
				$havedns = true;
118
			}
119
                }
120
        }
121

    
122
        fwrite($fd, $resolvconf);
123
        fclose($fd);
124

    
125
        if (!$g['booting']) {
126
                /* restart dhcpd (nameservers may have changed) */
127
                if (!$dynupdate)
128
                        services_dhcpd_configure();
129
        }
130

    
131
        return 0;
132
}
133

    
134
function get_nameservers() {
135
	global $config, $g;
136
	$master_list = array();
137
	$dns_lists = split("\n", `ls /var/etc/nameserver_* 2>/dev/null`);
138
	foreach($dns_lists as $dns) {
139
		$items = split("\n", file_get_contents($dns));
140
		foreach($items as $item)
141
			if($item <> "")
142
				$master_list[] = $item;
143
	}
144
	if(!file_exists("/var/etc/nameservers.conf"))
145
		return $master_list;
146
	$dns = `cat /var/etc/nameservers.conf`;
147
	$dns_s = split("\n", $dns);
148
	if(is_array($dns_s))
149
		foreach($dns_s as $dns)
150
			$master_list[] = $dns;
151
	return $master_list;
152
}
153

    
154
function system_hosts_generate() {
155
	global $config, $g;
156
	if(isset($config['system']['developerspew'])) {
157
		$mt = microtime();
158
		echo "system_hosts_generate() being called $mt\n";
159
	}
160

    
161
	$syscfg = $config['system'];
162
	$lancfg = $config['interfaces']['lan'];
163
	$dnsmasqcfg = $config['dnsmasq'];
164

    
165
	if (!is_array($dnsmasqcfg['hosts'])) {
166
		$dnsmasqcfg['hosts'] = array();
167
	}
168
	$hostscfg = $dnsmasqcfg['hosts'];
169

    
170
	$fd = fopen("{$g['varetc_path']}/hosts", "w");
171
	if (!$fd) {
172
		log_error("Error: cannot open hosts file in system_hosts_generate().\n");
173
		return 1;
174
	}
175

    
176
	$hosts = <<<EOD
177
127.0.0.1	localhost localhost.{$syscfg['domain']}
178
{$lancfg['ipaddr']}	{$syscfg['hostname']}.{$syscfg['domain']} {$syscfg['hostname']}
179

    
180
EOD;
181

    
182
	foreach ($hostscfg as $host) {
183
		if ($host['host'])
184
			$hosts .= "{$host['ip']}	{$host['host']}.{$host['domain']} {$host['host']}\n";
185
		else
186
			$hosts .= "{$host['ip']}	{$host['domain']}\n";
187
	}
188
	if (isset($dnsmasqcfg['regdhcpstatic'])) {
189
		foreach ($config['dhcpd'] as $dhcpif => $dhcpifconf)
190
			if(is_array($dhcpifconf['staticmap']) && isset($dhcpifconf['enable']))
191
					foreach ($dhcpifconf['staticmap'] as $host)
192
						if ($host['ipaddr'] && $host['hostname'])
193
							$hosts .= "{$host['ipaddr']}	{$host['hostname']}.{$syscfg['domain']} {$host['hostname']}\n";
194
	}
195
	fwrite($fd, $hosts);
196
	fclose($fd);
197

    
198
	return 0;
199
}
200

    
201
function system_hostname_configure() {
202
	global $config, $g;
203
	if(isset($config['system']['developerspew'])) {
204
		$mt = microtime();
205
		echo "system_hostname_configure() being called $mt\n";
206
	}
207

    
208
	$syscfg = $config['system'];
209

    
210
	/* set hostname */
211
	return mwexec("/bin/hostname " .
212
		escapeshellarg("{$syscfg['hostname']}.{$syscfg['domain']}"));
213
}
214

    
215
function system_routing_configure() {
216
	global $config, $g;
217
	if(isset($config['system']['developerspew'])) {
218
		$mt = microtime();
219
		echo "system_routing_configure() being called $mt\n";
220
	}
221

    
222
	/* Enable fast routing, if enabled */
223
	if(isset($config['staticroutes']['enablefastrouting']))
224
		mwexec("/sbin/sysctl net.inet.ip.fastforwarding=1");
225

    
226
	/* clear out old routes, if necessary */
227
	if (file_exists("{$g['vardb_path']}/routes.db")) {
228
		$fd = fopen("{$g['vardb_path']}/routes.db", "r");
229
		if (!$fd) {
230
			printf("Error: cannot open routes DB file in system_routing_configure().\n");
231
			return 1;
232
		}
233
		while (!feof($fd)) {
234
			$oldrt = fgets($fd);
235
			if ($oldrt)
236
				mwexec("/sbin/route delete " . escapeshellarg($oldrt));
237
		}
238
		fclose($fd);
239
		unlink("{$g['vardb_path']}/routes.db");
240
	}
241

    
242
	if (is_array($config['staticroutes']['route'])) {
243

    
244
		$fd = fopen("{$g['vardb_path']}/routes.db", "w");
245
		if (!$fd) {
246
			printf("Error: cannot open routes DB file in system_routing_configure().\n");
247
			return 1;
248
		}
249

    
250
		foreach ($config['staticroutes']['route'] as $rtent) {
251
			if(isset($rtent['interfacegateway'])) {
252
				mwexec("/sbin/route add " . escapeshellarg($rtent['network']) .
253
					" -iface " . escapeshellarg(convert_friendly_interface_to_real_interface_name($rtent['interface'])));
254
			} else {
255
				mwexec("/sbin/route add " . escapeshellarg($rtent['network']) .
256
					" " . escapeshellarg($rtent['gateway']));
257
			}
258
			/* record route so it can be easily removed later (if necessary) */
259
			fwrite($fd, $rtent['network'] . "\n");
260
		}
261

    
262
		fclose($fd);
263
	}
264

    
265
	return 0;
266
}
267

    
268
function system_routing_enable() {
269
	global $config, $g;
270
	if(isset($config['system']['developerspew'])) {
271
		$mt = microtime();
272
		echo "system_routing_enable() being called $mt\n";
273
	}
274

    
275
	return mwexec("/sbin/sysctl net.inet.ip.forwarding=1");
276
}
277

    
278
function system_syslogd_start() {
279
	global $config, $g;
280
	if(isset($config['system']['developerspew'])) {
281
		$mt = microtime();
282
		echo "system_syslogd_start() being called $mt\n";
283
	}
284

    
285
	$syslogcfg = $config['syslog'];
286

    
287
	if ($g['booting'])
288
		echo "Starting syslog...";
289
	else
290
		killbypid("{$g['varrun_path']}/syslog.pid");
291

    
292
	if (isset($syslogcfg)) {
293
		$separatelogfacilities = array('ntpd','racoon','openvpn');
294
		if($config['installedpackages']['package']) {
295
                        foreach($config['installedpackages']['package'] as $package) {
296
                                if($package['logging']) {
297
					$pkgfacilities[] = $package['logging']['facilityname'];
298
					$separatelogfacilities = $separatelogfacilities + $pkgfacilities;
299
					$facilitylist = implode(',', $pkgfacilities);
300
					mwexec("clog -i -s 10000 {$g['varlog_path']}/{$package['logging']['logfilename']}");
301
                                	$syslogconf .= "!{$facilitylist}\n*.*\t\t\t\t\t\t%{$g['varlog_path']}/{$package['logging']['logfilename']}\n";
302
				}
303
                        }
304
                }
305
		$facilitylist = implode(',', array_unique($separatelogfacilities));
306
		/* write syslog.conf */
307
		$fd = fopen("{$g['varetc_path']}/syslog.conf", "w");
308
		if (!$fd) {
309
			printf("Error: cannot open syslog.conf in system_syslogd_start().\n");
310
			return 1;
311
		}
312
		$syslogconf .= "!ntpd\n";
313
		if (!isset($syslogcfg['disablelocallogging'])) {
314
			$syslogconf .= <<<EOD
315
*.*						%{$g['varlog_path']}/ntpd.log
316

    
317
EOD;
318
		}
319
		$syslogconf .= "!racoon\n";
320
		if (!isset($syslogcfg['disablelocallogging'])) {
321
			$syslogconf .= <<<EOD
322
*.*						%{$g['varlog_path']}/ipsec.log
323

    
324
EOD;
325
		}
326
		if (isset($syslogcfg['vpn'])) {
327
			$syslogconf .= <<<EOD
328
*.*						@{$syslogcfg['remoteserver']}
329

    
330
EOD;
331
		}
332
		$syslogconf .= "!openvpn\n";
333
		if (!isset($syslogcfg['disablelocallogging'])) {
334
			$syslogconf .= <<<EOD
335
*.*						%{$g['varlog_path']}/openvpn.log
336

    
337
EOD;
338
		}
339
		if (isset($syslogcfg['vpn'])) {
340
			$syslogconf .= <<<EOD
341
*.*						@{$syslogcfg['remoteserver']}
342

    
343
EOD;
344
		}
345
		$syslogconf .= "!-{$facilitylist}\n";
346
		if (!isset($syslogcfg['disablelocallogging'])) {
347
		$syslogconf .= <<<EOD
348
local0.*					%{$g['varlog_path']}/filter.log
349
local3.*					%{$g['varlog_path']}/vpn.log
350
local4.*					%{$g['varlog_path']}/portalauth.log
351
local7.*					%{$g['varlog_path']}/dhcpd.log
352
*.notice;kern.debug;lpr.info;mail.crit; 	%{$g['varlog_path']}/system.log
353
news.err;local0.none;local3.none;local4.none; 	%{$g['varlog_path']}/system.log
354
local7.none					%{$g['varlog_path']}/system.log
355
security.*					%{$g['varlog_path']}/system.log
356
auth.info;authpriv.info;daemon.info		%{$g['varlog_path']}/system.log
357
local1.*					%{$g['varlog_path']}/slbd.log
358
auth.info;authpriv.info 			|exec /usr/local/sbin/sshlockout_pf
359
*.emerg						*
360

    
361
EOD;
362
		}
363

    
364
		if (isset($syslogcfg['filter'])) {
365
			$syslogconf .= <<<EOD
366
local0.*					@{$syslogcfg['remoteserver']}
367

    
368
EOD;
369
		}
370

    
371
		if (isset($syslogcfg['vpn'])) {
372
			$syslogconf .= <<<EOD
373
local3.*					@{$syslogcfg['remoteserver']}
374

    
375
EOD;
376
		}
377

    
378

    
379
		if (isset($syslogcfg['portalauth'])) {
380
			$syslogconf .= <<<EOD
381
local4.*					@{$syslogcfg['remoteserver']}
382

    
383
EOD;
384
		}
385

    
386

    
387
		if (isset($syslogcfg['dhcp'])) {
388
			$syslogconf .= <<<EOD
389
local7.*					@{$syslogcfg['remoteserver']}
390

    
391
EOD;
392
		}
393

    
394
		if (isset($syslogcfg['system'])) {
395
			$syslogconf .= <<<EOD
396
*.notice;kern.debug;lpr.info;mail.crit;		@{$syslogcfg['remoteserver']}
397
news.err;local0.none;local3.none;local7.none	@{$syslogcfg['remoteserver']}
398
security.*					@{$syslogcfg['remoteserver']}
399
auth.info;authpriv.info;daemon.info		@{$syslogcfg['remoteserver']}
400
*.emerg						@{$syslogcfg['remoteserver']}
401

    
402
EOD;
403
		}
404
		fwrite($fd, $syslogconf);
405
		fclose($fd);
406

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

    
409
	} else {
410
		$retval = mwexec("/usr/sbin/syslogd -ss");
411
	}
412

    
413
	if ($g['booting'])
414
		echo "done.\n";
415

    
416
	return $retval;
417
}
418

    
419
function system_pccard_start() {
420
	global $config, $g;
421
	if(isset($config['system']['developerspew'])) {
422
		$mt = microtime();
423
		echo "system_pccard_start() being called $mt\n";
424
	}
425

    
426
	if ($g['booting'])
427
		echo "Initializing PCMCIA...";
428

    
429
	/* kill any running pccardd */
430
	killbypid("{$g['varrun_path']}/pccardd.pid");
431

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

    
435
	if ($g['booting']) {
436
		if ($res == 0)
437
			echo "done.\n";
438
		else
439
			echo "failed!\n";
440
	}
441

    
442
	return $res;
443
}
444

    
445

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

    
449
	if ($g['booting'])
450
		echo "Starting webConfigurator...";
451

    
452
	/* kill any running lighttpd */
453
	killbypid("{$g['varrun_path']}/lighty-webConfigurator.pid");
454

    
455
	sleep(1);
456

    
457
	/* generate password file */
458
	system_password_configure();
459

    
460
	chdir($g['www_path']);
461

    
462
	/* non-standard port? */
463
	if ($config['system']['webgui']['port'])
464
		$portarg = "{$config['system']['webgui']['port']}";
465
	else
466
		$portarg = "";
467

    
468
	if ($config['system']['webgui']['protocol'] == "https") {
469

    
470
	if(!$config['system']['webgui']['port'])
471
		$portarg = "443";
472

    
473
		if ($config['system']['webgui']['certificate'] && $config['system']['webgui']['private-key']) {
474
			$cert = base64_decode($config['system']['webgui']['certificate']);
475
			$key = base64_decode($config['system']['webgui']['private-key']);
476
		} else {
477
			/* default certificate/key */
478
			$cert = <<<EOD
479
-----BEGIN CERTIFICATE-----
480
MIIDEzCCAnygAwIBAgIJAJM91W+s6qptMA0GCSqGSIb3DQEBBAUAMGUxCzAJBgNV
481
BAYTAlVTMQswCQYDVQQIEwJLWTETMBEGA1UEBxMKTG91aXN2aWxsZTEQMA4GA1UE
482
ChMHcGZTZW5zZTEQMA4GA1UECxMHcGZTZW5zZTEQMA4GA1UEAxMHcGZTZW5zZTAe
483
Fw0wNjAzMTAyMzQ1MTlaFw0xNjAzMDcyMzQ1MTlaMGUxCzAJBgNVBAYTAlVTMQsw
484
CQYDVQQIEwJLWTETMBEGA1UEBxMKTG91aXN2aWxsZTEQMA4GA1UEChMHcGZTZW5z
485
ZTEQMA4GA1UECxMHcGZTZW5zZTEQMA4GA1UEAxMHcGZTZW5zZTCBnzANBgkqhkiG
486
9w0BAQEFAAOBjQAwgYkCgYEA3lPNTFH6qge/ygaqe/BS4oH59O6KvAesWcRzSu5N
487
21lyVE5tBbL0zqOSXmlLyReMSbtAMZqt1P8EPYFoOcaEQHIWm2VQF80Z18+8Gh4O
488
UQGjHq88OeaLqyk3OLpSKzSpXuCFrSN7q9Kez8zp5dQEu7sIW30da3pAbdqYOimA
489
1VsCAwEAAaOByjCBxzAdBgNVHQ4EFgQUAnx+ggC4SzJ0CK+rhPhJ2ZpyunEwgZcG
490
A1UdIwSBjzCBjIAUAnx+ggC4SzJ0CK+rhPhJ2ZpyunGhaaRnMGUxCzAJBgNVBAYT
491
AlVTMQswCQYDVQQIEwJLWTETMBEGA1UEBxMKTG91aXN2aWxsZTEQMA4GA1UEChMH
492
cGZTZW5zZTEQMA4GA1UECxMHcGZTZW5zZTEQMA4GA1UEAxMHcGZTZW5zZYIJAJM9
493
1W+s6qptMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAAviQpdoeabL8
494
1HSZiD7Yjx82pdLpyQOdXvAu3jEAYz53ckx0zSMrzsQ5r7Vae6AE7Xd7Pj+1Yihs
495
AJZzOQujnmsuim7qu6YSxzP34xonKwd1C9tZUlyNRNnEmtXOEDupn05bih1ugtLG
496
kqfPIgDbDLXuPtEAA6QDUypaunI6+1E=
497
-----END CERTIFICATE-----
498

    
499
EOD;
500

    
501
			$key = <<<EOD
502
-----BEGIN RSA PRIVATE KEY-----
503
MIICXgIBAAKBgQDeU81MUfqqB7/KBqp78FLigfn07oq8B6xZxHNK7k3bWXJUTm0F
504
svTOo5JeaUvJF4xJu0Axmq3U/wQ9gWg5xoRAchabZVAXzRnXz7waHg5RAaMerzw5
505
5ourKTc4ulIrNKle4IWtI3ur0p7PzOnl1AS7uwhbfR1rekBt2pg6KYDVWwIDAQAB
506
AoGAP7E0VFP8Aq/7os3sE1uS8y8XQ7L+7cUo/AKKoQHKLjfeyAY7t3FALt6vdPqn
507
anGjkA/j4RIWELoKJfCnwj17703NDCPwB7klcmZvmTx5Om1ZrRyZdQ6RJs0pOOO1
508
r2wOnZNaNWStXE9Afpw3dj20Gh0V/Ioo5HXn3sHfxZm8dnkCQQDwv8OaUdp2Hl8t
509
FDfXB1CMvUG1hEAvbQvZK1ODkE7na2/ChKjVPddEI3DvfzG+nLrNuTrAyVWgRLte
510
r8qX5PQHAkEA7GlKx0S18LdiKo6wy2QeGu6HYkPncaHNFOWX8cTpvGGtQoWYSh0J
511
tjCt1/mz4/XkvZWuZyTNx2FdkVlNF5nHDQJBAIRWVTZqEjVlwpmsCHnp6mxCyHD4
512
DrRDNAUfnNuwIr9xPlDlzUzSnpc1CCqOd5C45LKbRGGfCrN7tKd66FmQoFcCQQCy
513
Kvw3R1pTCvHJnvYwoshphaC0dvaDVeyINiwYAk4hMf/wpVxLZqz+CJvLrB1dzOBR
514
3O+uPjdzbrakpweJpNQ1AkEA3ZtlgEj9eWsLAJP8aKlwB8VqD+EtG9OJSUMnCDiQ
515
WFFNj/t3Ze3IVuAyL/yMpiv3JNEnZhIxCta42eDFpIZAKw==
516
-----END RSA PRIVATE KEY-----
517

    
518
EOD;
519
		}
520
	} else {
521
		$cert = "";
522
		$key = "";
523
	}
524

    
525
	/* generate lighttpd configuration */
526
	system_generate_lighty_config("{$g['varetc_path']}/lighty-webConfigurator.conf",
527
		$cert, $key, "lighty-webConfigurator.pid", $portarg, "/usr/local/www/");
528

    
529
	/* attempt to start lighthttpd */
530
	$res = mwexec("/usr/local/sbin/lighttpd -f {$g['varetc_path']}/lighty-webConfigurator.conf");
531

    
532
	if ($g['booting']) {
533
		if ($res == 0)
534
			echo "done.\n";
535
		else
536
			echo "failed!\n";
537
	}
538

    
539
	return $res;
540
}
541

    
542
function system_webgui_start_old() {
543
	global $config, $g;
544
	if(isset($config['system']['developerspew'])) {
545
		$mt = microtime();
546
		echo "system_webgui_start() being called $mt\n";
547
	}
548

    
549
        if ($g['booting'])
550
                echo "Starting webConfigurator...";
551

    
552
        /* kill any running mini_httpd */
553
        killbypid("{$g['varrun_path']}/mini_httpd.pid");
554

    
555
        /* generate password file */
556
        system_password_configure();
557

    
558
        chdir($g['www_path']);
559

    
560
        /* non-standard port? */
561
        if ($config['system']['webgui']['port'])
562
                $portarg = "-p {$config['system']['webgui']['port']}";
563
        else
564
                $portarg = "";
565

    
566
        if ($config['system']['webgui']['protocol'] == "https") {
567

    
568
                if ($config['system']['webgui']['certificate'] && $config['system']['webgui']['private-key']) {
569
                        $cert = base64_decode($config['system']['webgui']['certificate']);
570
                        $key  = base64_decode($config['system']['webgui']['private-key']);
571
                } else {
572
                        /* default certificate/key */
573
                        $cert = <<<EOD
574
-----BEGIN CERTIFICATE-----
575
MIIBlDCB/gIBADANBgkqhkiG9w0BAQQFADATMREwDwYDVQQKEwhtMG4wd2FsbDAe
576
Fw0wNTA1MTAxMjI0NDRaFw0wNzA1MTAxMjI0NDRaMBMxETAPBgNVBAoTCG0wbjB3
577
YWxsMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDAShszhFz+o8lsMWTGgTxs
578
TMPR+v4+qL5jXDyY97MLTGFK7aqQOtpIQc+TcTc4jklgOVlHoR7oBXrsi8YrbCd+
579
83LPQmQoSPC0VqhfU3uYf3NzxiK8r97aPCsmWgwT2pQ6TcESTm6sF7nLprOf/zFP
580
C4jE2fvjkbzyVolPywBuewIDAQABMA0GCSqGSIb3DQEBBAUAA4GBAFR962c4R5tV
581
cTn0OQcszYoW6WC+ini9tQQh5ku5jYDAiC+00atawJEVLnL3lwAcpSKTIWlTkD20
582
tl3lz5br1qFgYky+Rd0kwS2nk9jRbkxSXxd6KJVnNRCKre28aw3ENzZfCSurPQsX
583
UPp5er+NtwMT1g7s/JDmKTC4w1rGr5/c
584
-----END CERTIFICATE-----
585

    
586
EOD;
587

    
588
                        $key = <<<EOD
589
-----BEGIN RSA PRIVATE KEY-----
590
MIICXQIBAAKBgQDAShszhFz+o8lsMWTGgTxsTMPR+v4+qL5jXDyY97MLTGFK7aqQ
591
OtpIQc+TcTc4jklgOVlHoR7oBXrsi8YrbCd+83LPQmQoSPC0VqhfU3uYf3NzxiK8
592
r97aPCsmWgwT2pQ6TcESTm6sF7nLprOf/zFPC4jE2fvjkbzyVolPywBuewIDAQAB
593
AoGAbJJrQW9fQrggJuLMz/hwsYW2m31oyOBmf5u463YQtjRuSuxe/gj87weZuNqY
594
H2rXq2k2K+ehl8hgW+egASyUL3L7kCkEAsVREujKTEyhSqqIRDPWTxo9S/YA9Gvn
595
2ZnJvkrcKjqCO9aHX3rvJOK/ErYI6akctgI3KmgkYw5XNmECQQDuZU97RTWH9rmP
596
aQr57ysNXxgFsyhetOOqeYkPtIVwpOiNbfwE1zi5RGdtO4Ku3fG1lV4J2UoWJ9yD
597
awdoyYIHAkEAzn0xJ90IjPsHk+8SODEj5JGdHSZPNu1tgtrbjEi9sfGWg4K7XTxr
598
QW90pWb1bKKU1uh5FzW6OhnFfuQXt1kC7QJAPSthqY+onKqCEnoxhtAHi/bKgyvl
599
P+fKQwPMV2tKkgy+XwvJjrRqqZ8TqsOKVLQ+QQmCh6RpjiXMPyxHSmvqIQJBAKLR
600
HF1ucDuaBROkwx0DwmWMW/KMLpIFDQDNSaiIAuu4rxHrl4mhBoGGPNffI04RtILw
601
s+qVNs5xW8T+XaT4ztECQQDFHPnZeoPWE5z+AX/UUQIUWaDExz3XRzmIxRbOrlFi
602
CsF1s0TdJLi/wzNQRAL37A8vqCeVFR/ng3Xpg96Yg+8Z
603
-----END RSA PRIVATE KEY-----
604

    
605
EOD;
606
                }
607

    
608
				$cert = str_replace("\r", "", $cert);
609
				$key = str_replace("\r", "", $key);
610

    
611
                $fd = fopen("{$g['varetc_path']}/cert.pem", "w");
612
                if (!$fd) {
613
                        printf("Error: cannot open cert.pem in system_webgui_start().\n");
614
                        return 1;
615
                }
616
                chmod("{$g['varetc_path']}/cert.pem", 0600);
617
                fwrite($fd, $cert);
618
                fwrite($fd, "\n");
619
                fwrite($fd, $key);
620
                fclose($fd);
621

    
622
                $res = mwexec("/usr/local/sbin/mini_httpd -S -E {$g['varetc_path']}/cert.pem" .
623
                        " -c \"**.php|**.cgi\" -u root -maxproc 16 $portarg" .
624
                        " -i {$g['varrun_path']}/mini_httpd.pid");
625
        } else {
626
                $res = mwexec("/usr/local/sbin/mini_httpd -c \"**.php|**.cgi\" -u root" .
627
                        " -maxproc 16 $portarg -i {$g['varrun_path']}/mini_httpd.pid");
628
        }
629

    
630
        if ($g['booting']) {
631
                if ($res == 0)
632
                        echo "done\n";
633
                else
634
                        echo "failed\n";
635
        }
636

    
637
        return $res;
638
}
639

    
640
function system_generate_lighty_config($filename,
641
	$cert,
642
	$key,
643
	$pid_file,
644
	$port = 80,
645
	$document_root = "/usr/local/www/",
646
	$cert_location = "cert.pem",
647
	$max_procs = 2,
648
	$max_requests = "1",
649
	$fast_cgi_enable = true,
650
	$captive_portal = false) {
651

    
652
	global $config, $g;
653

    
654
	/* only use freebsd-sendfile network handler on full installations
655
	 * tests have shown that it is actually slower on embedded.
656
	 */
657
	if(stristr("pfSense", $g['platform']))
658
		$network_handler = "server.network-backend		= \"freebsd-sendfile\"\n";
659
	else
660
		$network_handler = "";
661

    
662
	if(isset($config['system']['developerspew'])) {
663
		$mt = microtime();
664
		echo "system_generate_lighty_config() being called $mt\n";
665
	}
666

    
667
	if($captive_portal == true)  {
668
		$captiveportal = ",\"mod_rewrite\"";
669
		$captive_portal_rewrite = "url.rewrite-once = ( \"(.*captiveportal.*)\" => \"$1\", \"(.*)\" => \"/index.php?redirurl=$1\" )\n";
670
		$captive_portal_module = "\"mod_accesslog\", ";
671
		$maxprocperip = $config['captiveportal']['maxprocperip'];
672
		if(!$maxprocperip and $maxprocperip > 0)
673
			$captive_portal_mod_evasive = "evasive.max-conns-per-ip = {$maxprocperip}";
674
		else
675
			$captive_portal_mod_evasive = "";
676
	} else {
677
		$captive_portal_module = "";
678
		$captive_portal_mod_evasive = "";
679
	}
680

    
681
	if($port <> "")
682
		$lighty_port = $port;
683
	else
684
		$lighty_port = "80";
685

    
686
	$memory = get_memory();
687
	$avail = $memory[0];
688

    
689
	if($avail > 0 and $avail < 98) {
690
		$max_procs = 1;
691
		$max_requests = 1;
692
	}
693

    
694
	if($avail > 97 and $avail < 128) {
695
		$max_procs = 2;
696
		$max_requests = 1;
697
	}
698

    
699
	if($avail > 127 and $avail < 256) {
700
		$max_procs = 2;
701
		$max_requests = 1;
702
	}
703

    
704
	if($avail > 255 and $avail < 384) {
705
		$max_procs = 3;
706
		$max_requests = 1;
707
	}
708

    
709
	if($avail > 383 and $avail < 512) {
710
		$max_procs = 4;
711
		$max_requests = 1;
712
	}
713

    
714
	/* we told you that 64 megs would be slow */
715
	if ($avail > 0 and $avail < 65)
716
		$fast_cgi_enable = false;
717

    
718
	if($fast_cgi_enable == true) {
719
		$module = "\"mod_fastcgi\", \"mod_cgi\"";
720
		$cgi_config = "";
721
		$fastcgi_config = <<<EOD
722
#### fastcgi module
723
## read fastcgi.txt for more info
724
fastcgi.server = ( ".php" =>
725
	( "localhost" =>
726
		(
727
			"socket" => "/tmp/php-fastcgi.socket",
728
			"min-procs" => 1,
729
			"max-procs" => {$max_procs},
730
			"bin-path" => "/usr/local/bin/php"
731
		)
732
	)
733
)
734

    
735
#### CGI module
736
cgi.assign                 = ( ".cgi" => "" )
737

    
738
EOD;
739
	} else {
740
		$fastcgi_config = "";
741
		$module = "\"mod_cgi\"";
742
		$cgi_config = <<<EOD
743
#### CGI module
744
cgi.assign                 = ( ".php"  => "/usr/local/bin/php",
745
                               ".cgi" => "" )
746

    
747
EOD;
748
	}
749

    
750
	$lighty_config .= <<<EOD
751
#
752
# lighttpd configuration file
753
#
754
# use a it as base for lighttpd 1.0.0 and above
755
#
756
############ Options you really have to take care of ####################
757

    
758
## FreeBSD!
759
server.event-handler		= "freebsd-kqueue"
760

    
761
{$network_handler}
762

    
763
## modules to load
764
server.modules              =   (
765
				  {$captive_portal_module}
766
				  "mod_access", "mod_accesslog",
767
                                  {$module}{$captiveportal}
768
				)
769

    
770
## Unused modules
771
#                               "mod_setenv",
772
#                               "mod_compress"
773
#				"mod_redirect",
774
#                               "mod_rewrite",
775
#                               "mod_ssi",
776
#                               "mod_usertrack",
777
#                               "mod_expire",
778
#                               "mod_secdownload",
779
#                               "mod_rrdtool",
780
#                               "mod_auth",
781
#                               "mod_status",
782
#                               "mod_alias",
783
#                               "mod_proxy",
784
#                               "mod_simple_vhost",
785
#                               "mod_evhost",
786
#                               "mod_userdir",
787
#                               "mod_cgi",
788
#                                "mod_accesslog"
789

    
790
## a static document-root, for virtual-hosting take look at the
791
## server.virtual-* options
792
server.document-root        = "{$document_root}"
793
{$captive_portal_rewrite}
794

    
795
## where to send error-messages to
796
server.errorlog             = "/var/log/lighttpd.error.log"
797

    
798
# files to check for if .../ is requested
799
server.indexfiles           = ( "index.php", "index.html",
800
                                "index.htm", "default.htm" )
801

    
802
# mimetype mapping
803
mimetype.assign             = (
804
  ".pdf"          =>      "application/pdf",
805
  ".sig"          =>      "application/pgp-signature",
806
  ".spl"          =>      "application/futuresplash",
807
  ".class"        =>      "application/octet-stream",
808
  ".ps"           =>      "application/postscript",
809
  ".torrent"      =>      "application/x-bittorrent",
810
  ".dvi"          =>      "application/x-dvi",
811
  ".gz"           =>      "application/x-gzip",
812
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
813
  ".swf"          =>      "application/x-shockwave-flash",
814
  ".tar.gz"       =>      "application/x-tgz",
815
  ".tgz"          =>      "application/x-tgz",
816
  ".tar"          =>      "application/x-tar",
817
  ".zip"          =>      "application/zip",
818
  ".mp3"          =>      "audio/mpeg",
819
  ".m3u"          =>      "audio/x-mpegurl",
820
  ".wma"          =>      "audio/x-ms-wma",
821
  ".wax"          =>      "audio/x-ms-wax",
822
  ".ogg"          =>      "audio/x-wav",
823
  ".wav"          =>      "audio/x-wav",
824
  ".gif"          =>      "image/gif",
825
  ".jpg"          =>      "image/jpeg",
826
  ".jpeg"         =>      "image/jpeg",
827
  ".png"          =>      "image/png",
828
  ".xbm"          =>      "image/x-xbitmap",
829
  ".xpm"          =>      "image/x-xpixmap",
830
  ".xwd"          =>      "image/x-xwindowdump",
831
  ".css"          =>      "text/css",
832
  ".html"         =>      "text/html",
833
  ".htm"          =>      "text/html",
834
  ".js"           =>      "text/javascript",
835
  ".asc"          =>      "text/plain",
836
  ".c"            =>      "text/plain",
837
  ".conf"         =>      "text/plain",
838
  ".text"         =>      "text/plain",
839
  ".txt"          =>      "text/plain",
840
  ".dtd"          =>      "text/xml",
841
  ".xml"          =>      "text/xml",
842
  ".mpeg"         =>      "video/mpeg",
843
  ".mpg"          =>      "video/mpeg",
844
  ".mov"          =>      "video/quicktime",
845
  ".qt"           =>      "video/quicktime",
846
  ".avi"          =>      "video/x-msvideo",
847
  ".asf"          =>      "video/x-ms-asf",
848
  ".asx"          =>      "video/x-ms-asf",
849
  ".wmv"          =>      "video/x-ms-wmv",
850
  ".bz2"          =>      "application/x-bzip",
851
  ".tbz"          =>      "application/x-bzip-compressed-tar",
852
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar"
853
 )
854

    
855
# Use the "Content-Type" extended attribute to obtain mime type if possible
856
#mimetypes.use-xattr        = "enable"
857

    
858
#### accesslog module
859
#accesslog.filename          = "/dev/null"
860

    
861
## deny access the file-extensions
862
#
863
# ~    is for backupfiles from vi, emacs, joe, ...
864
# .inc is often used for code includes which should in general not be part
865
#      of the document-root
866
url.access-deny             = ( "~", ".inc" )
867

    
868

    
869
######### Options that are good to be but not neccesary to be changed #######
870

    
871
## bind to port (default: 80)
872
server.port                = {$lighty_port}
873

    
874
## error-handler for status 404
875
#server.error-handler-404   = "/error-handler.html"
876
#server.error-handler-404   = "/error-handler.php"
877

    
878
## to help the rc.scripts
879
server.pid-file            = "/var/run/{$pid_file}"
880

    
881
## virtual directory listings
882
server.dir-listing         = "disable"
883

    
884
## enable debugging
885
debug.log-request-header   = "disable"
886
debug.log-response-header  = "disable"
887
debug.log-request-handling = "disable"
888
debug.log-file-not-found   = "disable"
889

    
890
#### compress module
891
#compress.cache-dir         = "/tmp/lighttpd/cache/compress/"
892
#compress.filetype          = ("text/plain", "text/html")
893

    
894
#server.network-backend = "writev"
895

    
896
server.upload-dirs = ( "{$g['upload_path']}", "/tmp", "/var/" )
897

    
898
server.max-request-size = 2097152
899

    
900
{$fastcgi_config}
901

    
902
{$cgi_config}
903

    
904
{$captive_portal_mod_evasive}
905

    
906
EOD;
907

    
908
	$cert = str_replace("\r", "", $cert);
909
	$key = str_replace("\r", "", $key);
910

    
911
	$cert = str_replace("\n\n", "\n", $cert);
912
	$key = str_replace("\n\n", "\n", $key);
913

    
914
	if($cert <> "" and $key <> "") {
915
		$fd = fopen("{$g['varetc_path']}/{$cert_location}", "w");
916
		if (!$fd) {
917
			printf("Error: cannot open cert.pem in system_webgui_start().\n");
918
			return 1;
919
		}
920
		chmod("{$g['varetc_path']}/{$cert_location}", 0600);
921
		fwrite($fd, $cert);
922
		fwrite($fd, "\n");
923
		fwrite($fd, $key);
924
		fclose($fd);
925
		$lighty_config .= "\n";
926
		$lighty_config .= "## ssl configuration\n";
927
		$lighty_config .= "ssl.engine = \"enable\"\n";
928
		$lighty_config .= "ssl.pemfile = \"{$g['varetc_path']}/{$cert_location}\"\n\n";
929
	}
930

    
931
	$fd = fopen("{$filename}", "w");
932
	if (!$fd) {
933
		printf("Error: cannot open {$filename} in system_generate_lighty_config().\n");
934
		return 1;
935
	}
936
	fwrite($fd, $lighty_config);
937
	fclose($fd);
938

    
939
	return 0;
940

    
941
}
942

    
943
function system_password_configure() {
944
	global $config, $g;
945
	if(isset($config['system']['developerspew'])) {
946
		$mt = microtime();
947
		echo "system_password_configure() being called $mt\n";
948
	}
949

    
950
	/* sync passwords */
951
	sync_webgui_passwords();
952

    
953
	/* !NOTE! conf_mount_ro is done by sync_webgui_passwords() */
954

    
955
	return 0;
956
}
957

    
958
function system_timezone_configure() {
959
	global $config, $g;
960
	if(isset($config['system']['developerspew'])) {
961
		$mt = microtime();
962
		echo "system_timezone_configure() being called $mt\n";
963
	}
964

    
965
	$syscfg = $config['system'];
966

    
967
	if ($g['booting'])
968
		echo "Setting timezone...";
969

    
970
	/* extract appropriate timezone file */
971
	$timezone = $syscfg['timezone'];
972
	if (!$timezone)
973
		$timezone = "Etc/UTC";
974

    
975
	conf_mount_rw();
976

    
977
	exec("LANG=C /usr/bin/tar xzfO /usr/share/zoneinfo.tgz " .
978
		escapeshellarg($timezone) . " > /etc/localtime");
979

    
980
	conf_mount_ro();
981

    
982
	if ($g['booting'])
983
		echo "done.\n";
984
}
985

    
986
function system_ntp_configure() {
987
	global $config, $g;
988

    
989
	$syscfg = $config['system'];
990

    
991
	/* open configuration for wrting or bail */
992
	$fd = fopen("{$g['varetc_path']}/ntpd.conf","w");
993
	if(!$fd) {
994
		log_error("Could not open {$g['varetc_path']}/ntpd.conf for writing");
995
		return;
996
	}
997

    
998
	fwrite($fd, "# \n");
999
	fwrite($fd, "# pfSense OpenNTPD configuration file \n");
1000
	fwrite($fd, "# \n\n");
1001

    
1002
	/* foreach through servers and write out to ntpd.conf */
1003
	$timeservers = "";
1004
	foreach (explode(' ', $syscfg['timeservers']) as $ts)
1005
		fwrite($fd, "servers {$ts}\n");
1006

    
1007
	fwrite($fd, "\n");
1008

    
1009
	/* slurp! */
1010
	fclose($fd);
1011

    
1012
	/* if openntpd is running, kill it */
1013
	while(is_process_running("ntpd")) {
1014
		exec("/usr/bin/killall ntpd");
1015
		sleep(3);
1016
	}
1017

    
1018
	/* if /var/empty does not exist, create it */
1019
	if(!is_dir("/var/empty"))
1020
		exec("/bin/mkdir -p /var/empty && chmod ug+rw /var/empty/.");
1021

    
1022
	sleep(1);
1023

    
1024
	/* start opentpd, set time now and use /var/etc/ntpd.conf */
1025
	exec("/usr/local/sbin/ntpd -s -f {$g['varetc_path']}/ntpd.conf");
1026

    
1027
}
1028

    
1029
function system_halt() {
1030
	global $g;
1031

    
1032
	system_reboot_cleanup();
1033

    
1034
	mwexec("nohup /etc/rc.halt > /dev/null 2>&1 &");
1035
}
1036

    
1037
function system_reboot() {
1038
	global $g;
1039

    
1040
	system_reboot_cleanup();
1041

    
1042
	mwexec("nohup /etc/rc.reboot > /dev/null 2>&1 &");
1043
}
1044

    
1045
function system_reboot_sync() {
1046
	global $g;
1047

    
1048
	system_reboot_cleanup();
1049

    
1050
	mwexec("/etc/rc.reboot > /dev/null 2>&1");
1051
}
1052

    
1053
function system_reboot_cleanup() {
1054
	mwexec("/usr/local/bin/beep.sh stop");
1055
	captiveportal_radius_stop_all();
1056
}
1057

    
1058
function system_do_shell_commands($early = 0) {
1059
	global $config, $g;
1060
	if(isset($config['system']['developerspew'])) {
1061
		$mt = microtime();
1062
		echo "system_do_shell_commands() being called $mt\n";
1063
	}
1064

    
1065
	if ($early)
1066
		$cmdn = "earlyshellcmd";
1067
	else
1068
		$cmdn = "shellcmd";
1069

    
1070
	if (is_array($config['system'][$cmdn])) {
1071

    
1072
		/* *cmd is an array, loop through */
1073
		foreach ($config['system'][$cmdn] as $cmd) {
1074
			exec($cmd);
1075
		}
1076

    
1077
	} elseif($config['system'][$cmdn] <> "") {
1078

    
1079
		/* execute single item */
1080
		exec($config['system'][$cmdn]);
1081

    
1082
	}
1083
}
1084

    
1085
function system_console_configure() {
1086
	global $config, $g;
1087
	if(isset($config['system']['developerspew'])) {
1088
		$mt = microtime();
1089
		echo "system_console_configure() being called $mt\n";
1090
	}
1091

    
1092
	if (isset($config['system']['disableconsolemenu'])) {
1093
		touch("{$g['varetc_path']}/disableconsole");
1094
	} else {
1095
		unlink_if_exists("{$g['varetc_path']}/disableconsole");
1096
	}
1097
}
1098

    
1099
function system_dmesg_save() {
1100
	global $g;
1101
	if(isset($config['system']['developerspew'])) {
1102
		$mt = microtime();
1103
		echo "system_dmesg_save() being called $mt\n";
1104
	}
1105

    
1106
	$dmesg = "";
1107
	exec("/sbin/dmesg", $dmesg);
1108

    
1109
	/* find last copyright line (output from previous boots may be present) */
1110
	$lastcpline = 0;
1111

    
1112
	for ($i = 0; $i < count($dmesg); $i++) {
1113
		if (strstr($dmesg[$i], "Copyright (c) 1992-"))
1114
			$lastcpline = $i;
1115
	}
1116

    
1117
	$fd = fopen("{$g['varlog_path']}/dmesg.boot", "w");
1118
	if (!$fd) {
1119
		printf("Error: cannot open dmesg.boot in system_dmesg_save().\n");
1120
		return 1;
1121
	}
1122

    
1123
	for ($i = $lastcpline; $i < count($dmesg); $i++)
1124
		fwrite($fd, $dmesg[$i] . "\n");
1125

    
1126
	fclose($fd);
1127

    
1128
	return 0;
1129
}
1130

    
1131
function system_set_harddisk_standby() {
1132
	global $g, $config;
1133
	if(isset($config['system']['developerspew'])) {
1134
		$mt = microtime();
1135
		echo "system_set_harddisk_standby() being called $mt\n";
1136
	}
1137

    
1138
	if (isset($config['system']['harddiskstandby'])) {
1139
		if ($g['booting']) {
1140
			echo 'Setting hard disk standby... ';
1141
		}
1142

    
1143
		$standby = $config['system']['harddiskstandby'];
1144
		// Check for a numeric value
1145
		if (is_numeric($standby)) {
1146
			// Sync the disk(s)
1147
			mwexec('/bin/sync');
1148
			if (!mwexec('/sbin/sysctl hw.ata.standby=' . ((int)$standby))) {
1149
				// Reinitialize ATA-drives
1150
				mwexec('/usr/local/sbin/atareinit');
1151
				if ($g['booting']) {
1152
					echo "done.\n";
1153
				}
1154
			} else if ($g['booting']) {
1155
				echo "failed!\n";
1156
			}
1157
		} else if ($g['booting']) {
1158
			echo "failed!\n";
1159
		}
1160
	}
1161
}
1162

    
1163
function system_setup_sysctl() {
1164
	global $config;
1165
	if(isset($config['system']['developerspew'])) {
1166
		$mt = microtime();
1167
		echo "system_setup_sysctl() being called $mt\n";
1168
	}
1169

    
1170
	$sysctl = return_filename_as_array("/etc/sysctl.conf");
1171
	foreach($sysctl as $sysc) {
1172
		if($sysc <> "")
1173
			mwexec("sysctl {$sysc} 2>/dev/null");
1174
	}
1175
	if (isset($config['system']['sharednet'])) {
1176
		system_disable_arp_wrong_if();
1177
	}
1178
}
1179

    
1180
function system_disable_arp_wrong_if() {
1181
	global $config;
1182
	if(isset($config['system']['developerspew'])) {
1183
		$mt = microtime();
1184
		echo "system_disable_arp_wrong_if() being called $mt\n";
1185
	}
1186
	system("/sbin/sysctl -n net.link.ether.inet.log_arp_wrong_iface=0 2>/dev/null");
1187
}
1188

    
1189
function system_enable_arp_wrong_if() {
1190
	global $config;
1191
	if(isset($config['system']['developerspew'])) {
1192
		$mt = microtime();
1193
		echo "system_enable_arp_wrong_if() being called $mt\n";
1194
	}
1195
	mwexec("/sbin/sysctl -n net.link.ether.inet.log_arp_wrong_iface=1");
1196
}
1197

    
1198
function enable_watchdog() {
1199
	global $config;
1200
	$install_watchdog = false;
1201
	$supported_watchdogs = array("Geode");
1202
	$file = file_get_contents("/var/log/dmesg.boot");
1203
	foreach($supported_watchdogs as $sd) {
1204
		if(stristr($file, "Geode")) {
1205
			$install_watchdog = true;
1206
		}
1207
	}
1208
	if($install_watchdog == true) {
1209
		if(is_process_running("watchdogd"))
1210
			exec("/usr/bin/killall watchdogd");
1211
		exec("/usr/sbin/watchdogd");
1212
	}
1213
}
1214

    
1215
?>
(20-20/27)