Project

General

Profile

Download (33.5 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
	if(isset($config['system']['developerspew'])) {
655
		$mt = microtime();
656
		echo "system_generate_lighty_config() being called $mt\n";
657
	}
658

    
659
	if($captive_portal == true)  {
660
		$captiveportal = ",\"mod_rewrite\"";
661
		$captive_portal_rewrite = "url.rewrite-once = ( \"(.*captiveportal.*)\" => \"$1\", \"(.*)\" => \"/index.php?redirurl=$1\" )\n";
662
		$captive_portal_module = "\"mod_accesslog\", ";
663
		$maxprocperip = $config['captiveportal']['maxprocperip'];
664
		if(!$maxprocperip and $maxprocperip > 0)
665
			$captive_portal_mod_evasive = "evasive.max-conns-per-ip = {$maxprocperip}";
666
		else
667
			$captive_portal_mod_evasive = "";
668
	} else {
669
		$captive_portal_module = "";
670
		$captive_portal_mod_evasive = "";
671
	}
672

    
673
	if($port <> "")
674
		$lighty_port = $port;
675
	else
676
		$lighty_port = "80";
677

    
678
	$memory = get_memory();
679
	$avail = $memory[0];
680

    
681
	if($avail > 0 and $avail < 98) {
682
		$max_procs = 1;
683
		$max_requests = 1;
684
	}
685

    
686
	if($avail > 97 and $avail < 128) {
687
		$max_procs = 2;
688
		$max_requests = 1;
689
	}
690

    
691
	if($avail > 127 and $avail < 256) {
692
		$max_procs = 2;
693
		$max_requests = 1;
694
	}
695

    
696
	if($avail > 255 and $avail < 384) {
697
		$max_procs = 3;
698
		$max_requests = 1;
699
	}
700

    
701
	if($avail > 383 and $avail < 512) {
702
		$max_procs = 4;
703
		$max_requests = 1;
704
	}
705

    
706
	/* we told you that 64 megs would be slow */
707
	if ($avail > 0 and $avail < 65)
708
		$fast_cgi_enable = false;
709

    
710
	if($fast_cgi_enable == true) {
711
		$module = "\"mod_fastcgi\", \"mod_cgi\"";
712
		$cgi_config = "";
713
		$fastcgi_config = <<<EOD
714
#### fastcgi module
715
## read fastcgi.txt for more info
716
fastcgi.server = ( ".php" =>
717
	( "localhost" =>
718
		(
719
			"socket" => "/tmp/php-fastcgi.socket",
720
			"min-procs" => 1,
721
			"max-procs" => {$max_procs},
722
			"bin-path" => "/usr/local/bin/php"
723
		)
724
	)
725
)
726

    
727
#### CGI module
728
cgi.assign                 = ( ".cgi" => "" )
729

    
730
EOD;
731
	} else {
732
		$fastcgi_config = "";
733
		$module = "\"mod_cgi\"";
734
		$cgi_config = <<<EOD
735
#### CGI module
736
cgi.assign                 = ( ".php"  => "/usr/local/bin/php",
737
                               ".cgi" => "" )
738

    
739
EOD;
740
	}
741

    
742
	$lighty_config .= <<<EOD
743
#
744
# lighttpd configuration file
745
#
746
# use a it as base for lighttpd 1.0.0 and above
747
#
748
############ Options you really have to take care of ####################
749

    
750
# FreeBSD!
751
server.event-handler        = "freebsd-kqueue"
752

    
753
## modules to load
754
server.modules              =   (
755
				  {$captive_portal_module}
756
				  "mod_access", "mod_accesslog",
757
                                  {$module}{$captiveportal}
758
				)
759

    
760
## Unused modules
761
#                               "mod_setenv",
762
#                               "mod_compress"
763
#				"mod_redirect",
764
#                               "mod_rewrite",
765
#                               "mod_ssi",
766
#                               "mod_usertrack",
767
#                               "mod_expire",
768
#                               "mod_secdownload",
769
#                               "mod_rrdtool",
770
#                               "mod_auth",
771
#                               "mod_status",
772
#                               "mod_alias",
773
#                               "mod_proxy",
774
#                               "mod_simple_vhost",
775
#                               "mod_evhost",
776
#                               "mod_userdir",
777
#                               "mod_cgi",
778
#                                "mod_accesslog"
779

    
780
## a static document-root, for virtual-hosting take look at the
781
## server.virtual-* options
782
server.document-root        = "{$document_root}"
783
{$captive_portal_rewrite}
784

    
785
## where to send error-messages to
786
server.errorlog             = "/var/log/lighttpd.error.log"
787

    
788
# files to check for if .../ is requested
789
server.indexfiles           = ( "index.php", "index.html",
790
                                "index.htm", "default.htm" )
791

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

    
845
# Use the "Content-Type" extended attribute to obtain mime type if possible
846
#mimetypes.use-xattr        = "enable"
847

    
848
#### accesslog module
849
#accesslog.filename          = "/dev/null"
850

    
851
## deny access the file-extensions
852
#
853
# ~    is for backupfiles from vi, emacs, joe, ...
854
# .inc is often used for code includes which should in general not be part
855
#      of the document-root
856
url.access-deny             = ( "~", ".inc" )
857

    
858

    
859
######### Options that are good to be but not neccesary to be changed #######
860

    
861
## bind to port (default: 80)
862
server.port                = {$lighty_port}
863

    
864
## error-handler for status 404
865
#server.error-handler-404   = "/error-handler.html"
866
#server.error-handler-404   = "/error-handler.php"
867

    
868
## to help the rc.scripts
869
server.pid-file            = "/var/run/{$pid_file}"
870

    
871
## virtual directory listings
872
server.dir-listing         = "disable"
873

    
874
## enable debugging
875
debug.log-request-header   = "disable"
876
debug.log-response-header  = "disable"
877
debug.log-request-handling = "disable"
878
debug.log-file-not-found   = "disable"
879

    
880
#### compress module
881
#compress.cache-dir         = "/tmp/lighttpd/cache/compress/"
882
#compress.filetype          = ("text/plain", "text/html")
883

    
884
#server.network-backend = "writev"
885

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

    
888
server.max-request-size = 2097152
889

    
890
{$fastcgi_config}
891

    
892
{$cgi_config}
893

    
894
{$captive_portal_mod_evasive}
895

    
896
EOD;
897

    
898
	$cert = str_replace("\r", "", $cert);
899
	$key = str_replace("\r", "", $key);
900

    
901
	$cert = str_replace("\n\n", "\n", $cert);
902
	$key = str_replace("\n\n", "\n", $key);
903

    
904
	if($cert <> "" and $key <> "") {
905
		$fd = fopen("{$g['varetc_path']}/{$cert_location}", "w");
906
		if (!$fd) {
907
			printf("Error: cannot open cert.pem in system_webgui_start().\n");
908
			return 1;
909
		}
910
		chmod("{$g['varetc_path']}/{$cert_location}", 0600);
911
		fwrite($fd, $cert);
912
		fwrite($fd, "\n");
913
		fwrite($fd, $key);
914
		fclose($fd);
915
		$lighty_config .= "\n";
916
		$lighty_config .= "## ssl configuration\n";
917
		$lighty_config .= "ssl.engine = \"enable\"\n";
918
		$lighty_config .= "ssl.pemfile = \"{$g['varetc_path']}/{$cert_location}\"\n\n";
919
	}
920

    
921
	$fd = fopen("{$filename}", "w");
922
	if (!$fd) {
923
		printf("Error: cannot open {$filename} in system_generate_lighty_config().\n");
924
		return 1;
925
	}
926
	fwrite($fd, $lighty_config);
927
	fclose($fd);
928

    
929
	return 0;
930

    
931
}
932

    
933
function system_password_configure() {
934
	global $config, $g;
935
	if(isset($config['system']['developerspew'])) {
936
		$mt = microtime();
937
		echo "system_password_configure() being called $mt\n";
938
	}
939

    
940
	/* sync passwords */
941
	sync_webgui_passwords();
942

    
943
	/* !NOTE! conf_mount_ro is done by sync_webgui_passwords() */
944

    
945
	return 0;
946
}
947

    
948
function system_timezone_configure() {
949
	global $config, $g;
950
	if(isset($config['system']['developerspew'])) {
951
		$mt = microtime();
952
		echo "system_timezone_configure() being called $mt\n";
953
	}
954

    
955
	$syscfg = $config['system'];
956

    
957
	if ($g['booting'])
958
		echo "Setting timezone...";
959

    
960
	/* extract appropriate timezone file */
961
	$timezone = $syscfg['timezone'];
962
	if (!$timezone)
963
		$timezone = "Etc/UTC";
964

    
965
	conf_mount_rw();
966

    
967
	exec("LANG=C /usr/bin/tar xzfO /usr/share/zoneinfo.tgz " .
968
		escapeshellarg($timezone) . " > /etc/localtime");
969

    
970
	conf_mount_ro();
971

    
972
	if ($g['booting'])
973
		echo "done.\n";
974
}
975

    
976
function system_ntp_configure() {
977
	global $config, $g;
978

    
979
	$syscfg = $config['system'];
980

    
981
	/* open configuration for wrting or bail */
982
	$fd = fopen("{$g['varetc_path']}/ntpd.conf","w");
983
	if(!$fd) {
984
		log_error("Could not open {$g['varetc_path']}/ntpd.conf for writing");
985
		return;
986
	}
987

    
988
	fwrite($fd, "# \n");
989
	fwrite($fd, "# pfSense OpenNTPD configuration file \n");
990
	fwrite($fd, "# \n\n");
991

    
992
	/* foreach through servers and write out to ntpd.conf */
993
	$timeservers = "";
994
	foreach (explode(' ', $syscfg['timeservers']) as $ts)
995
		fwrite($fd, "servers {$ts}\n");
996

    
997
	fwrite($fd, "\n");
998

    
999
	/* slurp! */
1000
	fclose($fd);
1001

    
1002
	/* if openntpd is running, kill it */
1003
	while(is_process_running("ntpd")) {
1004
		exec("/usr/bin/killall ntpd");
1005
		sleep(3);
1006
	}
1007

    
1008
	/* if /var/empty does not exist, create it */
1009
	if(!is_dir("/var/empty"))
1010
		exec("/bin/mkdir -p /var/empty && chmod ug+rw /var/empty/.");
1011

    
1012
	sleep(1);
1013

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

    
1017
}
1018

    
1019
function system_halt() {
1020
	global $g;
1021

    
1022
	system_reboot_cleanup();
1023

    
1024
	mwexec("nohup /etc/rc.halt > /dev/null 2>&1 &");
1025
}
1026

    
1027
function system_reboot() {
1028
	global $g;
1029

    
1030
	system_reboot_cleanup();
1031

    
1032
	mwexec("nohup /etc/rc.reboot > /dev/null 2>&1 &");
1033
}
1034

    
1035
function system_reboot_sync() {
1036
	global $g;
1037

    
1038
	system_reboot_cleanup();
1039

    
1040
	mwexec("/etc/rc.reboot > /dev/null 2>&1");
1041
}
1042

    
1043
function system_reboot_cleanup() {
1044
	mwexec("/usr/local/bin/beep.sh stop");
1045
	captiveportal_radius_stop_all();
1046
}
1047

    
1048
function system_do_shell_commands($early = 0) {
1049
	global $config, $g;
1050
	if(isset($config['system']['developerspew'])) {
1051
		$mt = microtime();
1052
		echo "system_do_shell_commands() being called $mt\n";
1053
	}
1054

    
1055
	if ($early)
1056
		$cmdn = "earlyshellcmd";
1057
	else
1058
		$cmdn = "shellcmd";
1059

    
1060
	if (is_array($config['system'][$cmdn])) {
1061

    
1062
		/* *cmd is an array, loop through */
1063
		foreach ($config['system'][$cmdn] as $cmd) {
1064
			exec($cmd);
1065
		}
1066

    
1067
	} elseif($config['system'][$cmdn] <> "") {
1068

    
1069
		/* execute single item */
1070
		exec($config['system'][$cmdn]);
1071

    
1072
	}
1073
}
1074

    
1075
function system_console_configure() {
1076
	global $config, $g;
1077
	if(isset($config['system']['developerspew'])) {
1078
		$mt = microtime();
1079
		echo "system_console_configure() being called $mt\n";
1080
	}
1081

    
1082
	if (isset($config['system']['disableconsolemenu'])) {
1083
		touch("{$g['varetc_path']}/disableconsole");
1084
	} else {
1085
		unlink_if_exists("{$g['varetc_path']}/disableconsole");
1086
	}
1087
}
1088

    
1089
function system_dmesg_save() {
1090
	global $g;
1091
	if(isset($config['system']['developerspew'])) {
1092
		$mt = microtime();
1093
		echo "system_dmesg_save() being called $mt\n";
1094
	}
1095

    
1096
	$dmesg = "";
1097
	exec("/sbin/dmesg", $dmesg);
1098

    
1099
	/* find last copyright line (output from previous boots may be present) */
1100
	$lastcpline = 0;
1101

    
1102
	for ($i = 0; $i < count($dmesg); $i++) {
1103
		if (strstr($dmesg[$i], "Copyright (c) 1992-"))
1104
			$lastcpline = $i;
1105
	}
1106

    
1107
	$fd = fopen("{$g['varlog_path']}/dmesg.boot", "w");
1108
	if (!$fd) {
1109
		printf("Error: cannot open dmesg.boot in system_dmesg_save().\n");
1110
		return 1;
1111
	}
1112

    
1113
	for ($i = $lastcpline; $i < count($dmesg); $i++)
1114
		fwrite($fd, $dmesg[$i] . "\n");
1115

    
1116
	fclose($fd);
1117

    
1118
	return 0;
1119
}
1120

    
1121
function system_set_harddisk_standby() {
1122
	global $g, $config;
1123
	if(isset($config['system']['developerspew'])) {
1124
		$mt = microtime();
1125
		echo "system_set_harddisk_standby() being called $mt\n";
1126
	}
1127

    
1128
	if (isset($config['system']['harddiskstandby'])) {
1129
		if ($g['booting']) {
1130
			echo 'Setting hard disk standby... ';
1131
		}
1132

    
1133
		$standby = $config['system']['harddiskstandby'];
1134
		// Check for a numeric value
1135
		if (is_numeric($standby)) {
1136
			// Sync the disk(s)
1137
			mwexec('/bin/sync');
1138
			if (!mwexec('/sbin/sysctl hw.ata.standby=' . ((int)$standby))) {
1139
				// Reinitialize ATA-drives
1140
				mwexec('/usr/local/sbin/atareinit');
1141
				if ($g['booting']) {
1142
					echo "done.\n";
1143
				}
1144
			} else if ($g['booting']) {
1145
				echo "failed!\n";
1146
			}
1147
		} else if ($g['booting']) {
1148
			echo "failed!\n";
1149
		}
1150
	}
1151
}
1152

    
1153
function system_setup_sysctl() {
1154
	global $config;
1155
	if(isset($config['system']['developerspew'])) {
1156
		$mt = microtime();
1157
		echo "system_setup_sysctl() being called $mt\n";
1158
	}
1159

    
1160
	$sysctl = return_filename_as_array("/etc/sysctl.conf");
1161
	foreach($sysctl as $sysc) {
1162
		if($sysc <> "")
1163
			mwexec("sysctl {$sysc} 2>/dev/null");
1164
	}
1165
	if (isset($config['system']['sharednet'])) {
1166
		system_disable_arp_wrong_if();
1167
	}
1168
}
1169

    
1170
function system_disable_arp_wrong_if() {
1171
	global $config;
1172
	if(isset($config['system']['developerspew'])) {
1173
		$mt = microtime();
1174
		echo "system_disable_arp_wrong_if() being called $mt\n";
1175
	}
1176
	system("/sbin/sysctl -n net.link.ether.inet.log_arp_wrong_iface=0 2>/dev/null");
1177
}
1178

    
1179
function system_enable_arp_wrong_if() {
1180
	global $config;
1181
	if(isset($config['system']['developerspew'])) {
1182
		$mt = microtime();
1183
		echo "system_enable_arp_wrong_if() being called $mt\n";
1184
	}
1185
	mwexec("/sbin/sysctl -n net.link.ether.inet.log_arp_wrong_iface=1");
1186
}
1187

    
1188
function enable_watchdog() {
1189
	global $config;
1190
	$install_watchdog = false;
1191
	$supported_watchdogs = array("Geode");
1192
	$file = file_get_contents("/var/log/dmesg.boot");
1193
	foreach($supported_watchdogs as $sd) {
1194
		if(stristr($file, "Geode")) {
1195
			$install_watchdog = true;
1196
		}
1197
	}
1198
	if($install_watchdog == true) {
1199
		if(is_process_running("watchdogd"))
1200
			exec("/usr/bin/killall watchdogd");
1201
		exec("/usr/sbin/watchdogd");
1202
	}
1203
}
1204

    
1205
?>
(20-20/27)