Project

General

Profile

Download (34.2 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=\"10\"\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
extension_dir=/usr/local/lib/php/extensions/no-debug-non-zts-20020429/
65
upload_tmp_dir = /tmp
66
upload_max_filesize = 100M
67
post_max_size = 100M
68
html_errors = Off
69
memory_limit = 32M
70
include_path = ".:/etc/inc:/usr/local/www:/usr/local/captiveportal:/usr/local/pkg"
71
extension=radius.so
72
{$opcode_cacher}
73

    
74
EOFF;
75

    
76
		conf_mount_rw();
77

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

    
83
		conf_mount_ro();
84
}
85

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

    
93
        $syscfg = $config['system'];
94

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

    
101
        $resolvconf = "domain {$syscfg['domain']}\n";
102

    
103
        $havedns = false;
104

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

    
124
        fwrite($fd, $resolvconf);
125
        fclose($fd);
126

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

    
133
        return 0;
134
}
135

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

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

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

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

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

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

    
182
EOD;
183

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

    
200
	return 0;
201
}
202

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

    
210
	$syscfg = $config['system'];
211

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

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

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

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

    
244
	if (is_array($config['staticroutes']['route'])) {
245

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

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

    
264
		fclose($fd);
265
	}
266

    
267
	return 0;
268
}
269

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

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

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

    
287
	$syslogcfg = $config['syslog'];
288

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

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

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

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

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

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

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

    
363
EOD;
364
		}
365

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

    
370
EOD;
371
		}
372

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

    
377
EOD;
378
		}
379

    
380

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

    
385
EOD;
386
		}
387

    
388

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

    
393
EOD;
394
		}
395

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

    
404
EOD;
405
		}
406
		fwrite($fd, $syslogconf);
407
		fclose($fd);
408

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

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

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

    
418
	return $retval;
419
}
420

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

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

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

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

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

    
444
	return $res;
445
}
446

    
447

    
448
function system_webgui_start() {
449
	global $config, $g;
450

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

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

    
457
	sleep(1);
458

    
459
	/* generate password file */
460
	system_password_configure();
461

    
462
	chdir($g['www_path']);
463

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

    
470
	if ($config['system']['webgui']['protocol'] == "https") {
471

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

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

    
501
EOD;
502

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

    
520
EOD;
521
		}
522
	} else {
523
		$cert = "";
524
		$key = "";
525
	}
526

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

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

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

    
541
	return $res;
542
}
543

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

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

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

    
557
        /* generate password file */
558
        system_password_configure();
559

    
560
        chdir($g['www_path']);
561

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

    
568
        if ($config['system']['webgui']['protocol'] == "https") {
569

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

    
588
EOD;
589

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

    
607
EOD;
608
                }
609

    
610
				$cert = str_replace("\r", "", $cert);
611
				$key = str_replace("\r", "", $key);
612

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

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

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

    
639
        return $res;
640
}
641

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

    
654
	global $config, $g;
655

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

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

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

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

    
688
	$memory = get_memory();
689
	$avail = $memory[0];
690

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

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

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

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

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

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

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

    
737
#### CGI module
738
cgi.assign                 = ( ".cgi" => "" )
739

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

    
749
EOD;
750
	}
751

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

    
760
## FreeBSD!
761
server.event-handler		= "freebsd-kqueue"
762

    
763
{$network_handler}
764

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

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

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

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

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

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

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

    
860
#### accesslog module
861
#accesslog.filename          = "/dev/null"
862

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

    
870

    
871
######### Options that are good to be but not neccesary to be changed #######
872

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

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

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

    
883
## virtual directory listings
884
server.dir-listing         = "disable"
885

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

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

    
896
#server.network-backend = "writev"
897

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

    
900
server.max-request-size = 2097152
901

    
902
{$fastcgi_config}
903

    
904
{$cgi_config}
905

    
906
{$captive_portal_mod_evasive}
907

    
908
EOD;
909

    
910
	$cert = str_replace("\r", "", $cert);
911
	$key = str_replace("\r", "", $key);
912

    
913
	$cert = str_replace("\n\n", "\n", $cert);
914
	$key = str_replace("\n\n", "\n", $key);
915

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

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

    
941
	return 0;
942

    
943
}
944

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

    
952
	/* sync passwords */
953
	sync_webgui_passwords();
954

    
955
	/* !NOTE! conf_mount_ro is done by sync_webgui_passwords() */
956

    
957
	return 0;
958
}
959

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

    
967
	$syscfg = $config['system'];
968

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

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

    
977
	conf_mount_rw();
978

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

    
982
	conf_mount_ro();
983

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

    
988
function system_ntp_configure() {
989
	global $config, $g;
990

    
991
	$syscfg = $config['system'];
992

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

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

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

    
1009
	fwrite($fd, "\n");
1010

    
1011
	/* slurp! */
1012
	fclose($fd);
1013

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

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

    
1024
	sleep(1);
1025

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

    
1029
}
1030

    
1031
function sync_system_time() {
1032
	global $config, $g;
1033

    
1034
	$syscfg = $config['system'];
1035

    
1036
	if ($g['booting'])
1037
		echo "Syncing system time before startup...";
1038

    
1039
	/* foreach through servers and write out to ntpd.conf */
1040
	foreach (explode(' ', $syscfg['timeservers']) as $ts) {
1041
		mwexec("/usr/sbin/ntpdate -s $ts");
1042
	}
1043
	
1044
	if ($g['booting'])
1045
		echo "done.\n";
1046
	
1047
}
1048

    
1049
function system_halt() {
1050
	global $g;
1051

    
1052
	system_reboot_cleanup();
1053

    
1054
	mwexec("nohup /etc/rc.halt > /dev/null 2>&1 &");
1055
}
1056

    
1057
function system_reboot() {
1058
	global $g;
1059

    
1060
	system_reboot_cleanup();
1061

    
1062
	mwexec("nohup /etc/rc.reboot > /dev/null 2>&1 &");
1063
}
1064

    
1065
function system_reboot_sync() {
1066
	global $g;
1067

    
1068
	system_reboot_cleanup();
1069

    
1070
	mwexec("/etc/rc.reboot > /dev/null 2>&1");
1071
}
1072

    
1073
function system_reboot_cleanup() {
1074
	mwexec("/usr/local/bin/beep.sh stop");
1075
	captiveportal_radius_stop_all();
1076
}
1077

    
1078
function system_do_shell_commands($early = 0) {
1079
	global $config, $g;
1080
	if(isset($config['system']['developerspew'])) {
1081
		$mt = microtime();
1082
		echo "system_do_shell_commands() being called $mt\n";
1083
	}
1084

    
1085
	if ($early)
1086
		$cmdn = "earlyshellcmd";
1087
	else
1088
		$cmdn = "shellcmd";
1089

    
1090
	if (is_array($config['system'][$cmdn])) {
1091

    
1092
		/* *cmd is an array, loop through */
1093
		foreach ($config['system'][$cmdn] as $cmd) {
1094
			exec($cmd);
1095
		}
1096

    
1097
	} elseif($config['system'][$cmdn] <> "") {
1098

    
1099
		/* execute single item */
1100
		exec($config['system'][$cmdn]);
1101

    
1102
	}
1103
}
1104

    
1105
function system_console_configure() {
1106
	global $config, $g;
1107
	if(isset($config['system']['developerspew'])) {
1108
		$mt = microtime();
1109
		echo "system_console_configure() being called $mt\n";
1110
	}
1111

    
1112
	if (isset($config['system']['disableconsolemenu'])) {
1113
		touch("{$g['varetc_path']}/disableconsole");
1114
	} else {
1115
		unlink_if_exists("{$g['varetc_path']}/disableconsole");
1116
	}
1117
}
1118

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

    
1126
	$dmesg = "";
1127
	exec("/sbin/dmesg", $dmesg);
1128

    
1129
	/* find last copyright line (output from previous boots may be present) */
1130
	$lastcpline = 0;
1131

    
1132
	for ($i = 0; $i < count($dmesg); $i++) {
1133
		if (strstr($dmesg[$i], "Copyright (c) 1992-"))
1134
			$lastcpline = $i;
1135
	}
1136

    
1137
	$fd = fopen("{$g['varlog_path']}/dmesg.boot", "w");
1138
	if (!$fd) {
1139
		printf("Error: cannot open dmesg.boot in system_dmesg_save().\n");
1140
		return 1;
1141
	}
1142

    
1143
	for ($i = $lastcpline; $i < count($dmesg); $i++)
1144
		fwrite($fd, $dmesg[$i] . "\n");
1145

    
1146
	fclose($fd);
1147

    
1148
	return 0;
1149
}
1150

    
1151
function system_set_harddisk_standby() {
1152
	global $g, $config;
1153
	if(isset($config['system']['developerspew'])) {
1154
		$mt = microtime();
1155
		echo "system_set_harddisk_standby() being called $mt\n";
1156
	}
1157

    
1158
	if (isset($config['system']['harddiskstandby'])) {
1159
		if ($g['booting']) {
1160
			echo 'Setting hard disk standby... ';
1161
		}
1162

    
1163
		$standby = $config['system']['harddiskstandby'];
1164
		// Check for a numeric value
1165
		if (is_numeric($standby)) {
1166
			// Sync the disk(s)
1167
			mwexec('/bin/sync');
1168
			if (!mwexec('/sbin/sysctl hw.ata.standby=' . ((int)$standby))) {
1169
				// Reinitialize ATA-drives
1170
				mwexec('/usr/local/sbin/atareinit');
1171
				if ($g['booting']) {
1172
					echo "done.\n";
1173
				}
1174
			} else if ($g['booting']) {
1175
				echo "failed!\n";
1176
			}
1177
		} else if ($g['booting']) {
1178
			echo "failed!\n";
1179
		}
1180
	}
1181
}
1182

    
1183
function system_setup_sysctl() {
1184
	global $config;
1185
	if(isset($config['system']['developerspew'])) {
1186
		$mt = microtime();
1187
		echo "system_setup_sysctl() being called $mt\n";
1188
	}
1189

    
1190
	$sysctl = return_filename_as_array("/etc/sysctl.conf");
1191
	foreach($sysctl as $sysc) {
1192
		if($sysc <> "")
1193
			mwexec("sysctl {$sysc} 2>/dev/null");
1194
	}
1195
	if (isset($config['system']['sharednet'])) {
1196
		system_disable_arp_wrong_if();
1197
	}
1198
}
1199

    
1200
function system_disable_arp_wrong_if() {
1201
	global $config;
1202
	if(isset($config['system']['developerspew'])) {
1203
		$mt = microtime();
1204
		echo "system_disable_arp_wrong_if() being called $mt\n";
1205
	}
1206
	system("/sbin/sysctl -n net.link.ether.inet.log_arp_wrong_iface=0 2>/dev/null");
1207
}
1208

    
1209
function system_enable_arp_wrong_if() {
1210
	global $config;
1211
	if(isset($config['system']['developerspew'])) {
1212
		$mt = microtime();
1213
		echo "system_enable_arp_wrong_if() being called $mt\n";
1214
	}
1215
	mwexec("/sbin/sysctl -n net.link.ether.inet.log_arp_wrong_iface=1");
1216
}
1217

    
1218
function enable_watchdog() {
1219
	global $config;
1220
	$install_watchdog = false;
1221
	$supported_watchdogs = array("Geode");
1222
	$file = file_get_contents("/var/log/dmesg.boot");
1223
	foreach($supported_watchdogs as $sd) {
1224
		if(stristr($file, "Geode")) {
1225
			$install_watchdog = true;
1226
		}
1227
	}
1228
	if($install_watchdog == true) {
1229
		if(is_process_running("watchdogd"))
1230
			exec("/usr/bin/killall watchdogd");
1231
		exec("/usr/sbin/watchdogd");
1232
	}
1233
}
1234

    
1235
?>
(20-20/27)