Project

General

Profile

Download (35.9 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

    
33
function activate_powerd() {
34
	global $config, $g;
35
	if(isset($config['system']['powerd_enable'])) {
36
		exec("/usr/sbin/powerd -b adp -a adp");
37
	} else {
38
		exec("/usr/bin/killall powerd");
39
	}
40
}
41

    
42
function activate_sysctls() {
43
	global $config, $g;
44
	
45
	exec("/sbin/sysctl net.enc.out.ipsec_bpf_mask=0x00000001");
46
	exec("/sbin/sysctl net.enc.out.ipsec_filter_mask=0x00000001");
47
	exec("/sbin/sysctl net.enc.in.ipsec_bpf_mask=0x00000002");
48
	exec("/sbin/sysctl net.enc.in.ipsec_filter_mask=0x00000002");
49

    
50
	if (is_array($config['sysctl'])) 
51
		foreach ($config['sysctl']['item'] as $tunable) 
52
			mwexec("sysctl " . $tunable['tunable'] . "=\"" 
53
				. $tunable['value'] .  "\"");
54
}
55

    
56
function system_resolvconf_generate($dynupdate = false) {
57
	global $config, $g;
58

    
59
	if(isset($config['system']['developerspew'])) {
60
		$mt = microtime();
61
		echo "system_resolvconf_generate() being called $mt\n";
62
	}
63

    
64
        $syscfg = $config['system'];
65

    
66
        $fd = fopen("{$g['varetc_path']}/resolv.conf", "w");
67
        if (!$fd) {
68
                printf("Error: cannot open resolv.conf in system_resolvconf_generate().\n");
69
                return 1;
70
        }
71

    
72
        $resolvconf = "domain {$syscfg['domain']}\n";
73

    
74
        $havedns = false;
75

    
76
        if (isset($syscfg['dnsallowoverride'])) {
77
		/* get dynamically assigned DNS servers (if any) */
78
		$ns = array_unique(get_nameservers());
79
		foreach($ns as $nameserver) {
80
			if($nameserver) {
81
				$resolvconf .= "nameserver $nameserver\n";
82
				$havedns = true;
83
			}
84
		}
85
        }
86
        if (!$havedns && is_array($syscfg['dnsserver'])) {
87
		foreach ($syscfg['dnsserver'] as $ns) {
88
			if ($ns) {
89
				$resolvconf .= "nameserver $ns\n";
90
				$havedns = true;
91
			}
92
		}
93
	}
94

    
95
        fwrite($fd, $resolvconf);
96
        fclose($fd);
97

    
98
        if (!$g['booting']) {
99
		/* restart dhcpd (nameservers may have changed) */
100
		if (!$dynupdate)
101
			services_dhcpd_configure();
102
        }
103

    
104
	/* setup static routes for DNS servers. */
105
	for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
106
		/* setup static routes for dns servers */
107
		$dnsgw = "dns{$dnscounter}gwint";
108
		if (isset($config['system'][$dnsgw])) {
109
			$interface = $config['system'][$dnsgw];
110
			if (($interface <> "") && ($interface <> "none")) {
111
				$gatewayip = get_interface_gateway($interface);
112
				if(is_ipaddr($gatewayip)) {
113
					/* dns server array starts at 0 */
114
					$dnscountermo = $dnscounter - 1;
115
					mwexec("route delete -host {$syscfg['dnsserver'][$dnscountermo]}");
116
					mwexec("route add -host {$syscfg['dnsserver'][$dnscountermo]} {$gatewayip}");
117
				}
118
			}
119
		}
120
	}
121
	
122
	return 0;
123
}
124

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

    
149
function system_hosts_generate() {
150
	global $config, $g;
151
	if(isset($config['system']['developerspew'])) {
152
		$mt = microtime();
153
		echo "system_hosts_generate() being called $mt\n";
154
	}
155

    
156
	$syscfg = $config['system'];
157
	$lancfg = $config['interfaces']['lan'];
158
	$lancfgip = get_interface_ip("lan");
159
	$dnsmasqcfg = $config['dnsmasq'];
160

    
161
	if (!is_array($dnsmasqcfg['hosts'])) {
162
		$dnsmasqcfg['hosts'] = array();
163
	}
164
	$hostscfg = $dnsmasqcfg['hosts'];
165

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

    
172
	$hosts = <<<EOD
173
127.0.0.1	localhost localhost.{$syscfg['domain']}
174

    
175
EOD;
176
	if (is_ipaddr($lancfgip))
177
		$hosts .= <<<EOD
178
{$lancfgip}	{$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
	$status = mwexec("/bin/hostname " .
212
		escapeshellarg("{$syscfg['hostname']}.{$syscfg['domain']}"));
213

    
214
    /* Setup host GUID ID.  This is used by ZFS. */
215
	mwexec("/etc/rc.d/hostid start");
216

    
217
	return $status;
218
}
219

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

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

    
231
	$route_str = exec_command("/usr/bin/netstat -rn");
232

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

    
249
	/* if list */
250
	$iflist = get_configured_interface_list();
251

    
252
	$dont_remove_route = false;
253
	foreach ($iflist as $ifent => $ifname) {
254
		/* 
255
		 * XXX: The value of this is really when this function can take
256
		 * 	an interface as parameter.
257
		 */
258
		/* do not process interfaces that will end up with gateways */
259
		if (interface_has_gateway($ifent) || 
260
			$config['interfaces'][$ifent]['ipaddr'] == "carpdev-dhcp") {
261
			$dont_remove_route = true;
262
			break;
263
		}
264
	}
265

    
266
	if ($dont_remove_route == false) {
267
		/* remove default route */
268
		mwexec("/sbin/route delete default", true);
269
	}
270

    
271
	$dont_add_route = false;
272
	/* if OLSRD is enabled, allow WAN to house DHCP. */
273
	if($config['installedpackages']['olsrd']) {
274
		foreach($config['installedpackages']['olsrd']['config'] as $olsrd) {
275
			if($olsrd['enabledyngw'] == "on") {
276
				$dont_add_route = true;
277
				break;
278
			}
279
		}
280
	}
281

    
282
	if($dont_add_route == false) {
283
		if(is_array($config['gateways']['gateway_item'])) {
284
			foreach($config['gateways']['gateway_item'] as $gateway) {
285
		        	if(isset($gateway['defaultgw'])) {
286
					$gatewayip = $gateway['gateway'];
287
					$interfacegw = $gateway['interface'];
288
				}
289
			}
290
			if(($interfacegw <> "bgpd") && (is_ipaddr($gatewayip)))
291
				mwexec("/sbin/route add default " . escapeshellarg($gatewayip), true);
292
		} else {
293
			/* FIXME */
294
			/* adding gateway for 1.2-style configs without the new
295
			  gateway setup configured.
296
			  Force WAN to be default gateway because that is the
297
			  1.2 behavior.
298
			*/
299
			if (is_ipaddr($config['interfaces']['wan']['gateway'])) {
300
				$gatewayip = $config['interfaces']['wan']['gateway'];
301
				mwexec("/sbin/route add default " . escapeshellarg($gatewayip), true);
302
			}
303
		}
304
	}
305

    
306
	if (is_array($config['staticroutes']['route'])) {
307

    
308
		$fd = fopen("{$g['vardb_path']}/routes.db", "w");
309
		if (!$fd) {
310
			printf("Error: cannot open routes DB file in system_routing_configure().\n");
311
			return 1;
312
		}
313

    
314
		foreach ($config['staticroutes']['route'] as $rtent) {
315
			unset($gatewayip);
316
			unset($interfacegw);
317
			if(is_array($config['gateways']['gateway_item'])) {
318
				foreach($config['gateways']['gateway_item'] as $gateway) {
319
					if($rtent['gateway'] == $gateway['name']) {
320
						$gatewayip = $gateway['gateway'];
321
						$interfacegw = $gateway['interface'];
322
					}
323
				}
324
			}
325
			if((is_ipaddr($rtent['gateway'])) && ($gatewayip == ""))  {
326
				$gatewayip = $rtent['gateway'];
327
				$interfacegw = $rtent['interface'];
328
			}			
329
			if((isset($rtent['interfacegateway'])) && (! is_ipaddr($gatewayip))){
330
				mwexec("/sbin/route add " . escapeshellarg($rtent['network']) .
331
					" -iface " . escapeshellarg(convert_friendly_interface_to_real_interface_name($interfacegw)));
332
			} else {
333
				mwexec("/sbin/route add " . escapeshellarg($rtent['network']) .
334
					" " . escapeshellarg($gatewayip));
335
			}
336
			/* record route so it can be easily removed later (if necessary) */
337
			fwrite($fd, $rtent['network'] . "\n");
338
		}
339
		fclose($fd);
340
	}
341

    
342
	return 0;
343
}
344

    
345

    
346
function system_routing_enable() {
347
	global $config, $g;
348
	if(isset($config['system']['developerspew'])) {
349
		$mt = microtime();
350
		echo "system_routing_enable() being called $mt\n";
351
	}
352

    
353
	return mwexec("/sbin/sysctl net.inet.ip.forwarding=1");
354
}
355

    
356
function system_syslogd_start() {
357
	global $config, $g;
358
	if(isset($config['system']['developerspew'])) {
359
		$mt = microtime();
360
		echo "system_syslogd_start() being called $mt\n";
361
	}
362

    
363
	$syslogcfg = $config['syslog'];
364

    
365
	if ($g['booting'])
366
		echo "Starting syslog...";
367
	else
368
		killbypid("{$g['varrun_path']}/syslog.pid");
369

    
370
	mwexec("/usr/bin/killall -9 syslogd");
371
	mwexec("/usr/bin/killall -9 fifolog_writer");
372
	
373
	// Define carious commands for logging
374
	$fifolog_create = "/usr/sbin/fifolog_create -s ";
375
	$fifolog_log = "|/usr/sbin/fifolog_writer ";
376
	$clog_create = "/usr/sbin/clog -i -s ";
377
	$clog_log = "%";
378

    
379
	// Which logging type are we using this week??
380
	if(isset($config['system']['usefifolog'])) {
381
		$log_directive = $fifolog_log;
382
		$log_create_directive = $fifolog_create;		
383
	} else { // Defaults to CLOG
384
		$log_directive = $clog_log;
385
		$log_create_directive = $clog_create;
386
	}
387
	
388
	if (isset($syslogcfg)) {
389
		$separatelogfacilities = array('ntpd','racoon','openvpn');
390
		if($config['installedpackages']['package']) {
391
			foreach($config['installedpackages']['package'] as $package) {
392
				if($package['logging']) {
393
					$pkgfacilities[] = $package['logging']['facilityname'];
394
					$separatelogfacilities = $separatelogfacilities + $pkgfacilities;
395
					$facilitylist = implode(',', $pkgfacilities);
396
					mwexec("{$log_create_directive} 10240 {$g['varlog_path']}/{$package['logging']['logfilename']}");
397
					$syslogconf .= "!{$facilitylist}\n*.*\t\t\t\t\t\t {$log_directive}{$g['varlog_path']}/{$package['logging']['logfilename']}\n";
398
				}
399
			}
400
		}
401
		$facilitylist = implode(',', array_unique($separatelogfacilities));
402
		/* write syslog.conf */		
403
		$fd = fopen("{$g['varetc_path']}/syslog.conf", "w");
404
		if (!$fd) {
405
			printf("Error: cannot open syslog.conf in system_syslogd_start().\n");
406
			return 1;
407
		}
408
		$syslogconf .= "!ntpdate,!ntpd\n";
409
		if (!isset($syslogcfg['disablelocallogging'])) 
410
			$syslogconf .= "*.*					 {$log_directive}{$g['varlog_path']}/ntpd.log\n";
411
		$syslogconf .= "!racoon\n";
412
		if (!isset($syslogcfg['disablelocallogging'])) 
413
			$syslogconf .= "*.*					 {$log_directive}{$g['varlog_path']}/ipsec.log\n";
414
		$syslogconf .= "!apinger\n";
415
		if (!isset($syslogcfg['disablelocallogging'])) 
416
			$syslogconf .= "*.*					 {$log_directive}{$g['varlog_path']}/slbd.log\n";
417
		if (isset($syslogcfg['vpn'])) {
418
			if($syslogcfg['remoteserver'])
419
				$syslogconf .= "*.*					 @{$syslogcfg['remoteserver']}\n";
420
			if($syslogcfg['remoteserver2'])
421
				$syslogconf .= "*.*					 @{$syslogcfg['remoteserver2']}\n";
422
			if($syslogcfg['remoteserver3'])
423
				$syslogconf .= "*.*					 @{$syslogcfg['remoteserver3']}\n";
424
		}
425
		$syslogconf .= "!openvpn\n";
426
		if (!isset($syslogcfg['disablelocallogging'])) 
427
			$syslogconf .= "*.*					 {$log_directive}{$g['varlog_path']}/openvpn.log\n";
428
		if (isset($syslogcfg['vpn'])) {
429
			if($syslogcfg['remoteserver'])
430
				$syslogconf .= "*.*					 @{$syslogcfg['remoteserver']}\n";
431
			if($syslogcfg['remoteserver2'])
432
				$syslogconf .= "*.*					 @{$syslogcfg['remoteserver3']}\n";
433
			if($syslogcfg['remoteserver3'])
434
				$syslogconf .= "*.*					 @{$syslogcfg['remoteserver3']}\n";
435
		}
436
		$syslogconf .= "!-{$facilitylist}\n";
437
		if (!isset($syslogcfg['disablelocallogging'])) 
438
			$syslogconf .= <<<EOD
439
local0.*										 {$log_directive}{$g['varlog_path']}/filter.log
440
local3.*										 {$log_directive}{$g['varlog_path']}/vpn.log
441
local4.*										 {$log_directive}{$g['varlog_path']}/portalauth.log
442
local7.*										 {$log_directive}{$g['varlog_path']}/dhcpd.log
443
*.notice;kern.debug;lpr.info;mail.crit; 		 {$log_directive}{$g['varlog_path']}/system.log
444
news.err;local0.none;local3.none;local4.none; 	 {$log_directive}{$g['varlog_path']}/system.log
445
local7.none										 {$log_directive}{$g['varlog_path']}/system.log
446
security.*										 {$log_directive}{$g['varlog_path']}/system.log
447
auth.info;authpriv.info;daemon.info				 {$log_directive}{$g['varlog_path']}/system.log
448
local1.*										 {$log_directive}{$g['varlog_path']}/relayd.log
449
auth.info;authpriv.info 						 |exec /usr/local/sbin/sshlockout_pf
450
*.emerg											 *
451

    
452
EOD;
453
		if (isset($syslogcfg['filter'])) {
454
			if($syslogcfg['remoteserver'])
455
				$syslogconf .= "local0.*			 @{$syslogcfg['remoteserver']}\n";
456
			if($syslogcfg['remoteserver2'])
457
				$syslogconf .= "local0.*			 @{$syslogcfg['remoteserver2']}\n";
458
			if($syslogcfg['remoteserver3'])
459
				$syslogconf .= "local0.*			 @{$syslogcfg['remoteserver3']}\n";
460

    
461
		}
462
		if (isset($syslogcfg['vpn'])) {
463
			if($syslogcfg['remoteserver'])
464
				$syslogconf .= "local3.*			 @{$syslogcfg['remoteserver']}\n";
465
			if($syslogcfg['remoteserver2'])
466
				$syslogconf .= "local3.*			 @{$syslogcfg['remoteserver2']}\n";
467
			if($syslogcfg['remoteserver3'])
468
				$syslogconf .= "local3.*			 @{$syslogcfg['remoteserver3']}\n";
469
		}
470
		if (isset($syslogcfg['portalauth'])) {
471
			if($syslogcfg['remoteserver'])
472
				$syslogconf .= "local4.*			 @{$syslogcfg['remoteserver']}\n";
473
			if($syslogcfg['remoteserver2'])
474
				$syslogconf .= "local4.*			 @{$syslogcfg['remoteserver2']}\n";
475
			if($syslogcfg['remoteserver3'])
476
				$syslogconf .= "local4.*			 @{$syslogcfg['remoteserver3']}\n";
477
		}
478
		if (isset($syslogcfg['dhcp'])) {
479
			if($syslogcfg['remoteserver'])
480
				$syslogconf .= "local7.*			 @{$syslogcfg['remoteserver']}\n";
481
			if($syslogcfg['remoteserver2'])
482
				$syslogconf .= "local7.*			 @{$syslogcfg['remoteserver2']}\n";
483
			if($syslogcfg['remoteserver3'])
484
				$syslogconf .= "local7.*			 @{$syslogcfg['remoteserver3']}\n";
485
		}
486
		if (isset($syslogcfg['system'])) {
487
			if($syslogcfg['remoteserver'])
488
				$syslogconf .= <<<EOD
489
*.notice;kern.debug;lpr.info;mail.crit;			 @{$syslogcfg['remoteserver']}
490
news.err;local0.none;local3.none;local7.none	 @{$syslogcfg['remoteserver']}
491
security.*										 @{$syslogcfg['remoteserver']}
492
auth.info;authpriv.info;daemon.info				 @{$syslogcfg['remoteserver']}
493
*.emerg											 @{$syslogcfg['remoteserver']}
494

    
495
EOD;
496

    
497
		if (isset($syslogcfg['system'])) {
498
			if($syslogcfg['remoteserver2'])
499
				$syslogconf .= <<<EOD
500
*.notice;kern.debug;lpr.info;mail.crit;			 @{$syslogcfg['remoteserver2']}
501
news.err;local0.none;local3.none;local7.none	 @{$syslogcfg['remoteserver2']}
502
security.*										 @{$syslogcfg['remoteserver2']}
503
auth.info;authpriv.info;daemon.info				 @{$syslogcfg['remoteserver2']}
504
*.emerg											 @{$syslogcfg['remoteserver2']}
505

    
506
EOD;
507

    
508
		if (isset($syslogcfg['system'])) {
509
			if($syslogcfg['remoteserver3'])
510
				$syslogconf .= <<<EOD
511
*.notice;kern.debug;lpr.info;mail.crit;			 @{$syslogcfg['remoteserver3']}
512
news.err;local0.none;local3.none;local7.none	 @{$syslogcfg['remoteserver3']}
513
security.*										 @{$syslogcfg['remoteserver3']}
514
auth.info;authpriv.info;daemon.info				 @{$syslogcfg['remoteserver3']}
515
*.emerg											 @{$syslogcfg['remoteserver3']}
516

    
517
EOD;
518

    
519
}
520
		if (isset($syslogcfg['logall'])) {
521
			if($syslogcfg['remoteserver'])
522
				$syslogconf .= <<<EOD
523
*.*								@{$syslogcfg['remoteserver']}
524

    
525
EOD;
526

    
527
}
528
			if($syslogcfg['remoteserver2'])
529
				$syslogconf .= <<<EOD
530
*.*								@{$syslogcfg['remoteserver2']}
531

    
532
EOD;
533

    
534
}
535
			if($syslogcfg['remoteserver3'])
536
				$syslogconf .= <<<EOD
537
*.*								@{$syslogcfg['remoteserver3']}
538

    
539
EOD;
540

    
541
}
542
		fwrite($fd, $syslogconf);
543
		fclose($fd);
544
		// Are we logging to a least one remote server ?
545
		if(strpos($syslogconf, "@") != false)
546
			$retval = system("/usr/sbin/syslogd -c -f {$g['varetc_path']}/syslog.conf");
547
		else
548
			$retval = system("/usr/sbin/syslogd -c -f {$g['varetc_path']}/syslog.conf");
549

    
550
	} else {
551
		$retval = mwexec("/usr/sbin/syslogd -c");
552
	}
553

    
554
	if ($g['booting'])
555
		echo "done.\n";
556

    
557
	return $retval;
558
}
559

    
560
function system_pccard_start() {
561
	global $config, $g;
562
	if(isset($config['system']['developerspew'])) {
563
		$mt = microtime();
564
		echo "system_pccard_start() being called $mt\n";
565
	}
566

    
567
	if ($g['booting'])
568
		echo "Initializing PCMCIA...";
569

    
570
	/* kill any running pccardd */
571
	killbypid("{$g['varrun_path']}/pccardd.pid");
572

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

    
576
	if ($g['booting']) {
577
		if ($res == 0)
578
			echo "done.\n";
579
		else
580
			echo "failed!\n";
581
	}
582

    
583
	return $res;
584
}
585

    
586

    
587
function system_webgui_start() {
588
	global $config, $g;
589

    
590
	if ($g['booting'])
591
		echo "Starting webConfigurator...";
592

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

    
596
	sleep(1);
597

    
598
	chdir($g['www_path']);
599

    
600
	/* defaults */
601
	$portarg = "80";
602
	$crt = "";
603
	$key = "";
604
	$ca = "";
605

    
606
	/* non-standard port? */
607
	if (isset($config['system']['webgui']['port']) && $config['system']['webgui']['port'] <> "")
608
		$portarg = "{$config['system']['webgui']['port']}";
609

    
610
	if ($config['system']['webgui']['protocol'] == "https") {
611

    
612
		$cert =& lookup_cert($config['system']['webgui']['ssl-certref']);
613
		if(is_array($cert) && $cert['crt'] && $cert['prv']) {
614
			$crt = base64_decode($cert['crt']);
615
			$key = base64_decode($cert['prv']);
616
			if(!$config['system']['webgui']['port'])
617
				$portarg = "443";
618
			$ca = ca_chain($cert);
619
		} else
620
			log_error("Invalid webConfigurator https certificate, defaulting to http");
621
	}
622

    
623
	/* generate lighttpd configuration */
624
	system_generate_lighty_config("{$g['varetc_path']}/lighty-webConfigurator.conf",
625
		$crt, $key, $ca, "lighty-webConfigurator.pid", $portarg, "/usr/local/www/");
626

    
627
	/* attempt to start lighthttpd */
628
	$res = mwexec("/usr/local/sbin/lighttpd -f {$g['varetc_path']}/lighty-webConfigurator.conf");
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
	$ca,
644
	$pid_file,
645
	$port = 80,
646
	$document_root = "/usr/local/www/",
647
	$cert_location = "cert.pem",
648
	$ca_location = "ca.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
	if(isset($config['system']['developerspew'])) {
657
		$mt = microtime();
658
		echo "system_generate_lighty_config() being called $mt\n";
659
	}
660

    
661
	if($captive_portal == true)  {
662
		$captiveportal = ",\"mod_rewrite\"";
663
		$captive_portal_rewrite = "url.rewrite-once = ( \"(.*captiveportal.*)\" => \"$1\", \"(.*)\" => \"/index.php?redirurl=$1\" )\n";
664
		$captive_portal_module = "\"mod_accesslog\", ";
665
		$maxprocperip = $config['captiveportal']['maxprocperip'];
666
		if(!$maxprocperip and $maxprocperip > 0)
667
			$captive_portal_mod_evasive = "evasive.max-conns-per-ip = {$maxprocperip}";
668
		else
669
			$captive_portal_mod_evasive = "";
670
		$server_upload_dirs = "server.upload-dirs = ( \"/tmp/captiveportal/\" )\n";
671
		exec("mkdir -p /tmp/captiveportal");
672
		exec("chmod a-w /tmp/captiveportal");
673
		$server_max_request_size = "server.max-request-size    = 384";
674
	} else {
675
		$captive_portal_module = "";
676
		$captive_portal_mod_evasive = "";
677
		$server_upload_dirs = "server.upload-dirs = ( \"{$g['upload_path']}/\", \"/tmp/\", \"/var/\" )\n";
678
		$server_max_request_size = "server.max-request-size    = 2097152";
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 < 65) {
690
		$fast_cgi_enable = false;
691
	}
692

    
693
	if($avail > 65 and $avail < 98) {
694
		$max_procs = 1;
695
		$max_requests = 1;
696
	}
697

    
698
	if($avail > 97 and $avail < 128) {
699
		$max_procs = 1;
700
		$max_requests = 3;
701
	}
702

    
703
	if($avail > 127 and $avail < 256) {
704
		$max_procs = 1;
705
		$max_requests = 5;
706
	}
707

    
708
	if($avail > 255 and $avail < 384) {
709
		$max_procs = 3;
710
		$max_requests = 10;
711
	}
712

    
713
	if($avail > 383) {
714
		$max_procs = 4;
715
		$max_requests = 16;
716
	}
717

    
718
	if($captive_portal == true)  {	
719
		$bin_environment =  <<<EOC
720
        "bin-environment" => (
721
           "PHP_FCGI_CHILDREN" => "16",
722
           "PHP_FCGI_MAX_REQUESTS" => "{$max_requests}"
723
        ), 
724
EOC;
725

    
726
	} else if ($avail > 0 and $avail < 128) {
727
		$bin_environment = <<<EOC
728
	"bin-environment" => (
729
		"PHP_FCGI_CHILDREN" => "1",
730
		"PHP_FCGI_MAX_REQUESTS" => "{$max_requests}"
731
	),
732

    
733
EOC;
734
	} else
735
		$bin_environment = "";
736
		
737
	if($fast_cgi_enable == true) {
738
		$module = "\"mod_fastcgi\", \"mod_cgi\"";
739
		$cgi_config = "";
740
		$fastcgi_config = <<<EOD
741
#### fastcgi module
742
## read fastcgi.txt for more info
743
fastcgi.server = ( ".php" =>
744
	( "localhost" =>
745
		(
746
			"socket" => "/tmp/php-fastcgi.socket",
747
			"min-procs" => 1,
748
			"max-procs" => {$max_procs},
749
			{$bin_environment}			
750
			"bin-path" => "/usr/local/bin/php"
751
		)
752
	)
753
)
754

    
755
#### CGI module
756
cgi.assign                 = ( ".cgi" => "" )
757

    
758
EOD;
759
	} else {
760
		$fastcgi_config = "";
761
		$module = "\"mod_cgi\"";
762
		$cgi_config = <<<EOD
763
#### CGI module
764
cgi.assign                 = ( ".php"  => "/usr/local/bin/php",
765
                               ".cgi" => "" )
766

    
767
EOD;
768
	}
769

    
770
	$lighty_config .= <<<EOD
771
#
772
# lighttpd configuration file
773
#
774
# use a it as base for lighttpd 1.0.0 and above
775
#
776
############ Options you really have to take care of ####################
777

    
778
## FreeBSD!
779
server.event-handler	= "freebsd-kqueue"
780
server.network-backend 	= "writev"
781

    
782
## modules to load
783
server.modules              =   (
784
									{$captive_portal_module}
785
									"mod_access", "mod_accesslog", "mod_expire", "mod_compress",
786
									{$module}{$captiveportal}
787
								)
788

    
789
## Unused modules
790
#                               "mod_setenv",
791
#                               "mod_compress"
792
#				"mod_redirect",
793
#                               "mod_rewrite",
794
#                               "mod_ssi",
795
#                               "mod_usertrack",
796
#                               "mod_expire",
797
#                               "mod_secdownload",
798
#                               "mod_rrdtool",
799
#                               "mod_auth",
800
#                               "mod_status",
801
#                               "mod_alias",
802
#                               "mod_proxy",
803
#                               "mod_simple_vhost",
804
#                               "mod_evhost",
805
#                               "mod_userdir",
806
#                               "mod_cgi",
807
#                                "mod_accesslog"
808

    
809
server.max-keep-alive-requests = 15
810
server.max-keep-alive-idle = 30
811

    
812
## a static document-root, for virtual-hosting take look at the
813
## server.virtual-* options
814
server.document-root        = "{$document_root}"
815
{$captive_portal_rewrite}
816

    
817
# Maximum idle time with nothing being written (php downloading)
818
server.max-write-idle = 999
819

    
820
## where to send error-messages to
821
server.errorlog             = "/var/log/lighttpd.error.log"
822

    
823
# files to check for if .../ is requested
824
server.indexfiles           = ( "index.php", "index.html",
825
                                "index.htm", "default.htm" )
826

    
827
# mimetype mapping
828
mimetype.assign             = (
829
  ".pdf"          =>      "application/pdf",
830
  ".sig"          =>      "application/pgp-signature",
831
  ".spl"          =>      "application/futuresplash",
832
  ".class"        =>      "application/octet-stream",
833
  ".ps"           =>      "application/postscript",
834
  ".torrent"      =>      "application/x-bittorrent",
835
  ".dvi"          =>      "application/x-dvi",
836
  ".gz"           =>      "application/x-gzip",
837
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
838
  ".swf"          =>      "application/x-shockwave-flash",
839
  ".tar.gz"       =>      "application/x-tgz",
840
  ".tgz"          =>      "application/x-tgz",
841
  ".tar"          =>      "application/x-tar",
842
  ".zip"          =>      "application/zip",
843
  ".mp3"          =>      "audio/mpeg",
844
  ".m3u"          =>      "audio/x-mpegurl",
845
  ".wma"          =>      "audio/x-ms-wma",
846
  ".wax"          =>      "audio/x-ms-wax",
847
  ".ogg"          =>      "audio/x-wav",
848
  ".wav"          =>      "audio/x-wav",
849
  ".gif"          =>      "image/gif",
850
  ".jpg"          =>      "image/jpeg",
851
  ".jpeg"         =>      "image/jpeg",
852
  ".png"          =>      "image/png",
853
  ".xbm"          =>      "image/x-xbitmap",
854
  ".xpm"          =>      "image/x-xpixmap",
855
  ".xwd"          =>      "image/x-xwindowdump",
856
  ".css"          =>      "text/css",
857
  ".html"         =>      "text/html",
858
  ".htm"          =>      "text/html",
859
  ".js"           =>      "text/javascript",
860
  ".asc"          =>      "text/plain",
861
  ".c"            =>      "text/plain",
862
  ".conf"         =>      "text/plain",
863
  ".text"         =>      "text/plain",
864
  ".txt"          =>      "text/plain",
865
  ".dtd"          =>      "text/xml",
866
  ".xml"          =>      "text/xml",
867
  ".mpeg"         =>      "video/mpeg",
868
  ".mpg"          =>      "video/mpeg",
869
  ".mov"          =>      "video/quicktime",
870
  ".qt"           =>      "video/quicktime",
871
  ".avi"          =>      "video/x-msvideo",
872
  ".asf"          =>      "video/x-ms-asf",
873
  ".asx"          =>      "video/x-ms-asf",
874
  ".wmv"          =>      "video/x-ms-wmv",
875
  ".bz2"          =>      "application/x-bzip",
876
  ".tbz"          =>      "application/x-bzip-compressed-tar",
877
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar"
878
 )
879

    
880
# Use the "Content-Type" extended attribute to obtain mime type if possible
881
#mimetypes.use-xattr        = "enable"
882

    
883
#### accesslog module
884
#accesslog.filename          = "/dev/null"
885

    
886
## deny access the file-extensions
887
#
888
# ~    is for backupfiles from vi, emacs, joe, ...
889
# .inc is often used for code includes which should in general not be part
890
#      of the document-root
891
url.access-deny             = ( "~", ".inc" )
892

    
893

    
894
######### Options that are good to be but not neccesary to be changed #######
895

    
896
## bind to port (default: 80)
897
server.port                = {$lighty_port}
898

    
899
## error-handler for status 404
900
#server.error-handler-404   = "/error-handler.html"
901
#server.error-handler-404   = "/error-handler.php"
902

    
903
## to help the rc.scripts
904
server.pid-file            = "/var/run/{$pid_file}"
905

    
906
## virtual directory listings
907
server.dir-listing         = "disable"
908

    
909
## enable debugging
910
debug.log-request-header   = "disable"
911
debug.log-response-header  = "disable"
912
debug.log-request-handling = "disable"
913
debug.log-file-not-found   = "disable"
914

    
915
{$server_upload_dirs}
916

    
917
{$server_max_request_size}
918

    
919
{$fastcgi_config}
920

    
921
{$cgi_config}
922

    
923
{$captive_portal_mod_evasive}
924

    
925
# Turn on Lighty caching directives
926
compress.cache-dir         = "/tmp/"
927
compress.filetype          = ("text/plain", "text/html", "text/javascript", "text/css")
928

    
929
expire.url = (
930
				"" => "access 50 hours",	
931
        )
932

    
933
EOD;
934

    
935
	$cert = str_replace("\r", "", $cert);
936
	$key = str_replace("\r", "", $key);
937
	$ca = str_replace("\r", "", $ca);
938

    
939
	$cert = str_replace("\n\n", "\n", $cert);
940
	$key = str_replace("\n\n", "\n", $key);
941
	$ca = str_replace("\n\n", "\n", $ca);
942

    
943
	if($cert <> "" and $key <> "") {
944
		$fd = fopen("{$g['varetc_path']}/{$cert_location}", "w");
945
		if (!$fd) {
946
			printf("Error: cannot open cert.pem in system_webgui_start().\n");
947
			return 1;
948
		}
949
		chmod("{$g['varetc_path']}/{$cert_location}", 0600);
950
		fwrite($fd, $cert);
951
		fwrite($fd, "\n");
952
		fwrite($fd, $key);
953
		fclose($fd);
954
		if($ca <> "") {
955
			$fd = fopen("{$g['varetc_path']}/{$ca_location}", "w");
956
			if (!$fd) {
957
				printf("Error: cannot open ca.pem in system_webgui_start().\n");
958
				return 1;
959
			}
960
			chmod("{$g['varetc_path']}/{$ca_location}", 0600);
961
			fwrite($fd, $ca);
962
			fclose($fd);
963
		}
964
		$lighty_config .= "\n";
965
		$lighty_config .= "## ssl configuration\n";
966
		$lighty_config .= "ssl.engine = \"enable\"\n";
967
		$lighty_config .= "ssl.pemfile = \"{$g['varetc_path']}/{$cert_location}\"\n\n";
968
		if($ca <> "")
969
			$lighty_config .= "ssl.ca-file = \"{$g['varetc_path']}/{$ca_location}\"\n\n";
970
	}
971

    
972
	$fd = fopen("{$filename}", "w");
973
	if (!$fd) {
974
		printf("Error: cannot open {$filename} in system_generate_lighty_config().\n");
975
		return 1;
976
	}
977
	fwrite($fd, $lighty_config);
978
	fclose($fd);
979

    
980
	return 0;
981

    
982
}
983

    
984
function system_timezone_configure() {
985
	global $config, $g;
986
	if(isset($config['system']['developerspew'])) {
987
		$mt = microtime();
988
		echo "system_timezone_configure() being called $mt\n";
989
	}
990

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

    
993
	if ($g['booting'])
994
		echo "Setting timezone...";
995

    
996
	/* extract appropriate timezone file */
997
	$timezone = $syscfg['timezone'];
998
	if (!$timezone)
999
		$timezone = "Etc/UTC";
1000

    
1001
	conf_mount_rw();
1002

    
1003
	exec("LANG=C /usr/bin/tar xzfO /usr/share/zoneinfo.tgz " .
1004
		escapeshellarg($timezone) . " > /etc/localtime");
1005

    
1006
	mwexec("sync");
1007
	conf_mount_ro();
1008

    
1009
	if ($g['booting'])
1010
		echo "done.\n";
1011
}
1012

    
1013
function system_ntp_configure() {
1014
	global $config, $g;
1015

    
1016
	$syscfg = $config['system'];
1017

    
1018
	/* open configuration for wrting or bail */
1019
	$fd = fopen("{$g['varetc_path']}/ntpd.conf","w");
1020
	if(!$fd) {
1021
		log_error("Could not open {$g['varetc_path']}/ntpd.conf for writing");
1022
		return;
1023
	}
1024

    
1025
	fwrite($fd, "# \n");
1026
	fwrite($fd, "# pfSense OpenNTPD configuration file \n");
1027
	fwrite($fd, "# \n\n");
1028

    
1029
	/* foreach through servers and write out to ntpd.conf */
1030
	foreach (explode(' ', $syscfg['timeservers']) as $ts)
1031
		fwrite($fd, "servers {$ts}\n");
1032

    
1033
	/* Setup listener(s) if the user has configured one */
1034
        if ($config['installedpackages']['openntpd']) {
1035
    		/* server config is in coregui1 */
1036
		$xmlsettings = $config['installedpackages']['openntpd']['config'][0];
1037
		if ($xmlsettings['enable'] == 'on') {
1038
			$ifaces = explode(',', $xmlsettings['interface']);
1039
			$ifaces = array_map('convert_friendly_interface_to_real_interface_name', $ifaces);
1040
			$ifaces = array_filter($ifaces, 'does_interface_exist');
1041
			$ips = array_map('find_interface_ip', $ifaces);
1042
			foreach ($ips as $ip) {
1043
				if (is_ipaddr($ip))
1044
					fwrite($fd, "listen on $ip\n");
1045
			}
1046
		}
1047
	}
1048

    
1049
	fwrite($fd, "\n");
1050

    
1051
	/* slurp! */
1052
	fclose($fd);
1053

    
1054
	/* if openntpd is running, kill it */
1055
	while(is_process_running("ntpd")) {
1056
		mwexec("/usr/bin/killall ntpd", true);
1057
	}
1058

    
1059
	/* if /var/empty does not exist, create it */
1060
	if(!is_dir("/var/empty"))
1061
		exec("/bin/mkdir -p /var/empty && chmod ug+rw /var/empty/.");
1062

    
1063
	if($g['booting'])
1064
		return;
1065
	
1066
	/* start opentpd, set time now and use /var/etc/ntpd.conf */
1067
	exec("/usr/local/sbin/ntpd -s -f {$g['varetc_path']}/ntpd.conf");
1068
	
1069
	// Note that we are starting up
1070
	exec("echo 'OpenNTPD is starting up' >> {$g['varlog_path']}/ntpd.log");
1071

    
1072
}
1073

    
1074
function sync_system_time() {
1075
	global $config, $g;
1076

    
1077
	$syscfg = $config['system'];
1078

    
1079
	if ($g['booting'])
1080
		echo "Syncing system time before startup...";
1081

    
1082
	/* foreach through servers and write out to ntpd.conf */
1083
	foreach (explode(' ', $syscfg['timeservers']) as $ts) {
1084
		mwexec("/usr/sbin/ntpdate -s $ts");
1085
	}
1086
	
1087
	if ($g['booting'])
1088
		echo "done.\n";
1089
	
1090
}
1091

    
1092
function system_halt() {
1093
	global $g;
1094

    
1095
	system_reboot_cleanup();
1096

    
1097
	mwexec("nohup /etc/rc.halt > /dev/null 2>&1 &");
1098
}
1099

    
1100
function system_reboot() {
1101
	global $g;
1102

    
1103
	system_reboot_cleanup();
1104

    
1105
	mwexec("nohup /etc/rc.reboot > /dev/null 2>&1 &");
1106
}
1107

    
1108
function system_reboot_sync() {
1109
	global $g;
1110

    
1111
	system_reboot_cleanup();
1112

    
1113
	mwexec("/etc/rc.reboot > /dev/null 2>&1");
1114
}
1115

    
1116
function system_reboot_cleanup() {
1117
	mwexec("/usr/local/bin/beep.sh stop");
1118
	captiveportal_radius_stop_all();
1119
	require_once("voucher.inc");
1120
	voucher_save_db_to_config();
1121
}
1122

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

    
1130
	if ($early)
1131
		$cmdn = "earlyshellcmd";
1132
	else
1133
		$cmdn = "shellcmd";
1134

    
1135
	if (is_array($config['system'][$cmdn])) {
1136

    
1137
		/* *cmd is an array, loop through */
1138
		foreach ($config['system'][$cmdn] as $cmd) {
1139
			exec($cmd);
1140
		}
1141

    
1142
	} elseif($config['system'][$cmdn] <> "") {
1143

    
1144
		/* execute single item */
1145
		exec($config['system'][$cmdn]);
1146

    
1147
	}
1148
}
1149

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

    
1157
	if (isset($config['system']['disableconsolemenu'])) {
1158
		touch("{$g['varetc_path']}/disableconsole");
1159
	} else {
1160
		unlink_if_exists("{$g['varetc_path']}/disableconsole");
1161
	}
1162
}
1163

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

    
1171
	$dmesg = "";
1172
	exec("/sbin/dmesg", $dmesg);
1173

    
1174
	/* find last copyright line (output from previous boots may be present) */
1175
	$lastcpline = 0;
1176

    
1177
	for ($i = 0; $i < count($dmesg); $i++) {
1178
		if (strstr($dmesg[$i], "Copyright (c) 1992-"))
1179
			$lastcpline = $i;
1180
	}
1181

    
1182
	$fd = fopen("{$g['varlog_path']}/dmesg.boot", "w");
1183
	if (!$fd) {
1184
		printf("Error: cannot open dmesg.boot in system_dmesg_save().\n");
1185
		return 1;
1186
	}
1187

    
1188
	for ($i = $lastcpline; $i < count($dmesg); $i++)
1189
		fwrite($fd, $dmesg[$i] . "\n");
1190

    
1191
	fclose($fd);
1192

    
1193
	return 0;
1194
}
1195

    
1196
function system_set_harddisk_standby() {
1197
	global $g, $config;
1198
	if(isset($config['system']['developerspew'])) {
1199
		$mt = microtime();
1200
		echo "system_set_harddisk_standby() being called $mt\n";
1201
	}
1202

    
1203
	if (isset($config['system']['harddiskstandby'])) {
1204
		if ($g['booting']) {
1205
			echo 'Setting hard disk standby... ';
1206
		}
1207

    
1208
		$standby = $config['system']['harddiskstandby'];
1209
		// Check for a numeric value
1210
		if (is_numeric($standby)) {
1211
			// Sync the disk(s)
1212
			mwexec('/bin/sync');
1213
			if (!mwexec('/sbin/sysctl hw.ata.standby=' . ((int)$standby))) {
1214
				// Reinitialize ATA-drives
1215
				mwexec('/usr/local/sbin/atareinit');
1216
				if ($g['booting']) {
1217
					echo "done.\n";
1218
				}
1219
			} else if ($g['booting']) {
1220
				echo "failed!\n";
1221
			}
1222
		} else if ($g['booting']) {
1223
			echo "failed!\n";
1224
		}
1225
	}
1226
}
1227

    
1228
function system_setup_sysctl() {
1229
	global $config;
1230
	if(isset($config['system']['developerspew'])) {
1231
		$mt = microtime();
1232
		echo "system_setup_sysctl() being called $mt\n";
1233
	}
1234

    
1235
	activate_sysctls();	
1236

    
1237
	if (isset($config['system']['sharednet'])) {
1238
		system_disable_arp_wrong_if();
1239
	}
1240
}
1241

    
1242
function system_disable_arp_wrong_if() {
1243
	global $config;
1244
	if(isset($config['system']['developerspew'])) {
1245
		$mt = microtime();
1246
		echo "system_disable_arp_wrong_if() being called $mt\n";
1247
	}
1248
	mwexec("/sbin/sysctl -n net.link.ether.inet.log_arp_wrong_iface=0");
1249
	mwexec("/sbin/sysctl -n net.link.ether.inet.log_arp_movements=0");
1250
}
1251

    
1252
function system_enable_arp_wrong_if() {
1253
	global $config;
1254
	if(isset($config['system']['developerspew'])) {
1255
		$mt = microtime();
1256
		echo "system_enable_arp_wrong_if() being called $mt\n";
1257
	}
1258
	mwexec("/sbin/sysctl -n net.link.ether.inet.log_arp_wrong_iface=1");
1259
	mwexec("/sbin/sysctl -n net.link.ether.inet.log_arp_movements=1");
1260
}
1261

    
1262
function enable_watchdog() {
1263
	global $config;
1264
	return;
1265
	$install_watchdog = false;
1266
	$supported_watchdogs = array("Geode");
1267
	$file = file_get_contents("/var/log/dmesg.boot");
1268
	foreach($supported_watchdogs as $sd) {
1269
		if(stristr($file, "Geode")) {
1270
			$install_watchdog = true;
1271
		}
1272
	}
1273
	if($install_watchdog == true) {
1274
		if(is_process_running("watchdogd"))
1275
			mwexec("/usr/bin/killall watchdogd", true);
1276
		exec("/usr/sbin/watchdogd");
1277
	}
1278
}
1279

    
1280
?>
(35-35/44)