Project

General

Profile

Download (33.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	services.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 services_dhcpd_configure() {
36
	global $config, $g;
37
	
38
	if($g['services_dhcp_server_enable'] == false) 
39
		return;
40

    
41
	if(isset($config['system']['developerspew'])) {
42
		$mt = microtime();
43
		echo "services_dhcpd_configure($if) being called $mt\n";
44
	}
45
	
46
	/* kill any running dhcpd */
47
	if(is_process_running("dhcpd"))
48
		mwexec("killall dhcpd", true);
49

    
50
	/* DHCP enabled on any interfaces? */
51
	if (!is_dhcp_server_enabled())
52
		return 0;
53

    
54
	/* if OLSRD is enabled, allow WAN to house DHCP. */
55
	if($config['installedpackages']['olsrd'])
56
		foreach($config['installedpackages']['olsrd']['config'] as $olsrd)
57
				if($olsrd['enable'])
58
					$is_olsr_enabled = true;
59

    
60
	/* configure DHCPD chroot */
61
	$fd = fopen("/tmp/dhcpd.sh","w");
62
	$status = `mount | grep "{$g['dhcpd_chroot_path']}/dev"`;
63
	fwrite($fd, "mkdir -p {$g['dhcpd_chroot_path']}\n");
64
	fwrite($fd, "mkdir -p {$g['dhcpd_chroot_path']}/dev\n");
65
	fwrite($fd, "mkdir -p {$g['dhcpd_chroot_path']}/etc\n");
66
	fwrite($fd, "mkdir -p {$g['dhcpd_chroot_path']}/usr/local/sbin\n");
67
	fwrite($fd, "mkdir -p {$g['dhcpd_chroot_path']}/var/db\n");
68
	fwrite($fd, "mkdir -p {$g['dhcpd_chroot_path']}/var/run\n");	
69
	fwrite($fd, "mkdir -p {$g['dhcpd_chroot_path']}/usr\n");
70
	fwrite($fd, "mkdir -p {$g['dhcpd_chroot_path']}/lib\n");
71
	fwrite($fd, "mkdir -p {$g['dhcpd_chroot_path']}/run\n");
72
	fwrite($fd, "chown -R dhcpd:_dhcp {$g['dhcpd_chroot_path']}/*\n");
73
	fwrite($fd, "cp /lib/libc.so.* {$g['dhcpd_chroot_path']}/lib/\n");
74
	fwrite($fd, "cp /usr/local/sbin/dhcpd {$g['dhcpd_chroot_path']}/usr/local/sbin/\n");
75
	fwrite($fd, "chmod a+rx {$g['dhcpd_chroot_path']}/usr/local/sbin/dhcpd\n");
76
	if(!trim($status))
77
		fwrite($fd, "mount -t devfs devfs {$g['dhcpd_chroot_path']}/dev\n");
78
	fclose($fd);
79
	mwexec("/bin/sh /tmp/dhcpd.sh");
80

    
81
	$syscfg = $config['system'];
82
	$dhcpdcfg = $config['dhcpd'];
83
	$Iflist = get_configured_interface_list();
84
		
85
	if ($g['booting'])
86
		echo "Starting DHCP service...";
87
	else
88
		sleep(1);
89

    
90
	/* write dhcpd.conf */
91
	$fd = fopen("{$g['dhcpd_chroot_path']}/etc/dhcpd.conf", "w");
92
	if (!$fd) {
93
		printf("Error: cannot open dhcpd.conf in services_dhcpd_configure().\n");
94
		return 1;
95
	}
96

    
97

    
98

    
99
	$dhcpdconf = <<<EOD
100
	
101
option domain-name "{$syscfg['domain']}";
102
option ldap-server code 95 = text;
103
option domain-search-list code 119 = text;
104
default-lease-time 7200;
105
max-lease-time 86400;
106
log-facility local7;
107
ddns-update-style none;
108
one-lease-per-client true;
109
deny duplicates;
110
ping-check true;
111

    
112
EOD;
113

    
114
	if(isset($dhcpifconf['alwaysbroadcast'])) 
115
		$dhcpdconf .= "always-broadcast on\n";
116

    
117
	$dhcpdifs = array();
118

    
119
	/*    loop through and deterimine if we need to setup
120
	 *    failover peer "bleh" entries
121
	 */
122
	$dhcpnum = 0;
123
	foreach ($dhcpdcfg as $dhcpif => $dhcpifconf) {
124

    
125
		if (!isset($dhcpifconf['enable']))
126
			continue;
127

    
128
		if(!isset($dhcpifconf['disableauthoritative']))
129
			$dhcpdconf .= "authoritative;\n";
130

    
131
		if($dhcpifconf['failover_peerip'] <> "") {
132
			/*
133
			 *    yep, failover peer is defined.
134
			 *    does it match up to a defined vip?
135
			 */
136
			$skew = 110;
137
			$a_vip = &$config['virtualip']['vip'];
138
			if(is_array($a_vip)) {
139
				foreach ($a_vip as $vipent) {
140
					$int = guess_interface_from_ip($dhcpifconf['failover_peerip']);
141
					$intip = find_interface_ip($int);
142
					$real_dhcpif = convert_friendly_interface_to_real_interface_name($dhcpif);
143
					if($int == $real_dhcpif) {
144
						/* this is the interface! */
145
						if($vipent['advskew'] < "20")
146
							$skew = 0;
147
					}
148
				}
149
			} else {
150
				log_error("Warning!  DHCP Failover setup and no CARP virtual IP's defined!");
151
			}
152
			if($skew > 10) {
153
				$type = "secondary";
154
				$dhcpdconf_pri  = "mclt 600;\n";
155
				$my_port = "520";
156
				$peer_port = "519";
157
			} else {
158
				$my_port = "519";
159
				$peer_port = "520";
160
				$type = "primary";
161
				$dhcpdconf_pri  = "split 128;\n";
162
				$dhcpdconf_pri .= "  mclt 600;\n";
163
			}
164
			$dhcpdconf .= <<<EOPP
165
failover peer "dhcp{$dhcpnum}" {
166
  {$type};
167
  address {$intip};
168
  port {$my_port};
169
  peer address {$dhcpifconf['failover_peerip']};
170
  peer port {$peer_port};
171
  max-response-delay 10;
172
  max-unacked-updates 10;
173
  {$dhcpdconf_pri}
174
  load balance max seconds 3;
175
}
176

    
177
EOPP;
178
		$dhcpnum++;
179
		}
180
	}
181

    
182
	$dhcpnum = 0;
183

    
184
	foreach ($dhcpdcfg as $dhcpif => $dhcpifconf) {
185

    
186
		$ifcfg = $config['interfaces'][$dhcpif];
187

    
188
		if (!isset($dhcpifconf['enable']) || !isset($Iflist[$dhcpif]))
189
			continue;
190
		$ifcfgip = get_interface_ip($dhcpif);
191
		$ifcfgsn = get_interface_subnet($dhcpif);
192
		$subnet = gen_subnet($ifcfgip, $ifcfgsn);
193
		$subnetmask = gen_subnet_mask($ifcfgsn);
194

    
195
		if($is_olsr_enabled == true)
196
			if($dhcpifconf['netmask'])
197
				$subnetmask = gen_subnet_mask($dhcpifconf['netmask']);
198

    
199
		$dnscfg = "";
200

    
201
		if ($dhcpifconf['domain']) {
202
			$dnscfg .= "	option domain-name \"{$dhcpifconf['domain']}\";\n";
203
		}
204
		
205
    		if($dhcpifconf['domainsearchlist'] <> "") {
206
			$dnscfg .= "	option domain-search-list \"{$dhcpifconf['domainsearchlist']}\";\n";
207
    		}
208

    
209
		if (isset($dhcpifconf['ddnsupdate'])) {
210
			if($dhcpifconf['ddnsdomain'] <> "") {
211
				$dnscfg .= "	ddns-domainname \"{$dhcpifconf['ddnsdomain']}\";\n";
212
			}
213
			$dnscfg .= "	ddns-update-style interim;\n";
214
		}
215

    
216
		if (is_array($dhcpifconf['dnsserver']) && ($dhcpifconf['dnsserver'][0])) {
217
			$dnscfg .= "	option domain-name-servers " . join(",", $dhcpifconf['dnsserver']) . ";";
218
		} else if (isset($config['dnsmasq']['enable'])) {
219
			$dnscfg .= "	option domain-name-servers {$ifcfgip};";
220
		} else if (is_array($syscfg['dnsserver']) && ($syscfg['dnsserver'][0])) {
221
			$dnscfg .= "	option domain-name-servers " . join(",", $syscfg['dnsserver']) . ";";
222
		}
223

    
224
		$dhcpdconf .= "subnet $subnet netmask $subnetmask {\n";
225
		$dhcpdconf .= "	pool {\n";
226

    
227
		/* is failover dns setup? */
228
		if (is_array($dhcpifconf['dnsserver']) && $dhcpifconf['dnsserver'][0] <> "") {
229
			$dhcpdconf .= "		option domain-name-servers {$dhcpifconf['dnsserver'][0]}";
230
			if($dhcpifconf['dnsserver'][1] <> "")
231
				$dhcpdconf .= ",{$dhcpifconf['dnsserver'][1]}";
232
			$dhcpdconf .= ";\n";
233
		}
234

    
235
		if($dhcpifconf['failover_peerip'] <> "")
236
			$dhcpdconf .= "		deny dynamic bootp clients;\n";
237

    
238
		if (isset($dhcpifconf['denyunknown']))
239
		   $dhcpdconf .= "		deny unknown clients;\n";
240

    
241
		if ($dhcpifconf['gateway'])
242
			$routers = $dhcpifconf['gateway'];
243
		else
244
			$routers = $ifcfgip;
245

    
246
		if($dhcpifconf['failover_peerip'] <> "") {
247
			$dhcpdconf .= "		failover peer \"dhcp{$dhcpnum}\";\n";
248
			$dhcpnum++;
249
		}
250

    
251
		$dhcpdconf .= <<<EOD
252
		range {$dhcpifconf['range']['from']} {$dhcpifconf['range']['to']};
253
	}
254
	option routers {$routers};
255
$dnscfg
256

    
257
EOD;
258
    
259
    		if ($dhcpifconf['defaultleasetime'])
260
			$dhcpdconf .= "	default-lease-time {$dhcpifconf['defaultleasetime']};\n";
261
		if ($dhcpifconf['maxleasetime'])
262
			$dhcpdconf .= "	max-lease-time {$dhcpifconf['maxleasetime']};\n";
263

    
264
		if (is_array($dhcpifconf['winsserver']) && $dhcpifconf['winsserver'][0]) {
265
			$dhcpdconf .= "	option netbios-name-servers " . join(",", $dhcpifconf['winsserver']) . ";\n";
266
			$dhcpdconf .= "	option netbios-node-type 8;\n";
267
		}
268

    
269
		if (is_array($dhcpifconf['ntpserver']) && $dhcpifconf['ntpserver'][0])
270
			$dhcpdconf .= "	option ntp-servers " . join(",", $dhcpifconf['ntpserver']) . ";\n";
271

    
272
		if ($dhcpifconf['tftp'] <> "")
273
			$dhcpdconf .= "	option tftp-server-name \"{$dhcpifconf['tftp']}\";\n";
274

    
275
    if ($dhcpifconf['ldap'] <> "")
276
			$dhcpdconf .= "	option ldap-server \"{$dhcpifconf['ldap']}\";\n";
277

    
278
		if(isset($dhcpifconf['netboot'])) {
279
			if (($dhcpifconf['next-server'] <> "") && ($dhcpifconf['filename'] <> "")) {
280
				$dhcpdconf .= "	next-server {$dhcpifconf['next-server']};\n";
281
				$dhcpdconf .= "	filename \"{$dhcpifconf['filename']}\";\n";
282
			}
283
			if ($dhcpifconf['rootpath'] <> "") {
284
				$dhcpdconf .= "	option root-path \"{$dhcpifconf['rootpath']}\";\n";
285
      }
286
		}
287
		
288
		$dhcpdconf .= <<<EOD
289
}
290

    
291
EOD;
292

    
293
		/* add static mappings */
294
		if (is_array($dhcpifconf['staticmap'])) {
295

    
296
			$i = 0;
297
			foreach ($dhcpifconf['staticmap'] as $sm) {
298
				$dhcpdconf .= <<<EOD
299
host s_{$dhcpif}_{$i} {
300
	hardware ethernet {$sm['mac']};
301

    
302
EOD;
303
				if ($sm['ipaddr'])
304
					$dhcpdconf .= "	fixed-address {$sm['ipaddr']};\n";
305

    
306
				if ($sm['hostname'])
307
					$dhcpdconf .= "	option host-name {$sm['hostname']};\n";
308

    
309
				$dhcpdconf .= "}\n";
310
				$i++;
311
			}
312
		}
313

    
314
		$dhcpdifs[] = get_real_interface($dhcpif);
315
	}
316

    
317
	fwrite($fd, $dhcpdconf);
318
	fclose($fd);
319

    
320
	/* create an empty leases database */
321
	touch("{$g['dhcpd_chroot_path']}/var/db/dhcpd.leases");
322
	touch("{$g['varrun_path']}/dhcpd.pid");
323
	
324

    
325
	/* fire up dhcpd in a chroot */
326
	mwexec("/usr/local/sbin/dhcpd -user dhcpd -group _dhcp -chroot {$g['dhcpd_chroot_path']} -cf {$g['dhcpd_chroot_path']}/etc/dhcpd.conf " .
327
		join(" ", $dhcpdifs));
328

    
329
	if ($g['booting']) {
330
		print "done.\n";
331
	}
332

    
333
	return 0;
334
}
335

    
336
function services_igmpproxy_configure() {
337
        global $config, $g;
338

    
339
        $iflist = get_configured_interface_list();
340

    
341
        /* kill any running igmpproxy */
342
        killbyname("igmpproxy");
343

    
344
	if (!is_array($config['igmpproxy']['igmpentry']))
345
		return 1;
346

    
347
        $igmpconf = <<<EOD
348

    
349
##------------------------------------------------------
350
## Enable Quickleave mode (Sends Leave instantly)
351
##------------------------------------------------------
352
quickleave
353

    
354
EOD;
355

    
356
        foreach ($config['igmpproxy']['igmpentry'] as $igmpcf) {
357
                unset($iflist[$igmpcf['ifname']]);
358
                $realif = get_real_interface($igmpcf['ifname']);
359
                if (empty($igmpcf['threshold']))
360
                        $threshld = 1;
361
                else
362
                        $threshld = $igmpcf['threshold'];
363
                $igmpconf .= "phyint {$realif} {$igmpcf['type']} ratelimit 0 threshold {$threshld}\n";
364

    
365
                if ($igmpcf['address'] <> "") {
366
                        $item = explode(" ", $igmpcf['address']);
367
                        foreach($item as $iww)
368
                                $igmpconf .= "altnet {$iww}\n";
369
                }
370
                $igmpconf .= "\n";
371
        }
372
        foreach ($iflist as $ifn) {
373
                $realif = get_real_interface($ifn);
374
                $igmpconf .= "phyint {$realif} disabled\n";
375
        }
376

    
377
        $igmpfl = fopen($g['tmp_path'] . "/igmpproxy.conf", "w");
378
        if (!$igmpfl) {
379
                log_error("Could not write Igmpproxy configuration file!");
380
                return;
381
        }
382
        fwrite($igmpfl, $igmpconf);
383
        fclose($igmpfl);
384

    
385
        mwexec("/usr/local/sbin/igmpproxy -c " . $g['tmp_path'] . "/igmpproxy.conf");
386
        log_error("Started Igmpproxy service sucsesfully.");
387

    
388
        return 0;
389
}
390

    
391
function interfaces_staticarp_configure($if) {
392
	global $config, $g;
393
	if(isset($config['system']['developerspew'])) {
394
		$mt = microtime();
395
		echo "interfaces_staticarp_configure($if) being called $mt\n";
396
	}
397

    
398
        $ifcfg = $config['interfaces'][$if];
399

    
400
        /* Enable staticarp, if enabled */
401
        if(isset($config['dhcpd'][$if]['staticarp'])) {
402
                mwexec("/sbin/ifconfig " . escapeshellarg($ifcfg['if']) . " staticarp " );
403
                mwexec("/usr/sbin/arp -ad > /dev/null 2>&1 ");
404
                if (is_array($config['dhcpd'][$if]['staticmap'])) {
405

    
406
                        foreach ($config['dhcpd'][$if]['staticmap'] as $arpent) {
407
                                mwexec("/usr/sbin/arp -s " . escapeshellarg($arpent['ipaddr']) . " " . escapeshellarg($arpent['mac']));
408

    
409
                        }
410

    
411
                }
412
        } else {
413
                mwexec("/sbin/ifconfig " . escapeshellarg($ifcfg['if']) . " -staticarp " );
414
                mwexec("/usr/sbin/arp -da > /dev/null 2>&1 ");
415
        }
416

    
417
        return 0;
418
}
419

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

    
427
	/* kill any running dhcrelay */
428
	killbypid("{$g['varrun_path']}/dhcrelay.pid");
429

    
430
	$dhcrelaycfg = $config['dhcrelay'];
431

    
432
	/* DHCPRelay enabled on any interfaces? */
433
	$dhcrelayenable = false;
434
	if(is_array($dhcrelaycfg)) {
435
		foreach ($dhcrelaycfg as $dhcrelayif => $dhcrelayifconf) {
436
			if (isset($dhcrelayifconf['enable']) &&
437
				(($dhcrelayif == "lan") ||
438
				(isset($config['interfaces'][$dhcrelayif]['enable']) &&
439
				$config['interfaces'][$dhcrelayif]['if'] && (!link_interface_to_bridge($dhcrelayif)))))
440
				$dhcrelayenable = true;
441
		}
442
	}
443

    
444
	if (!$dhcrelayenable)
445
		return 0;
446

    
447
	if ($g['booting'])
448
		echo "Starting DHCP relay service...";
449
	else
450
		sleep(1);
451

    
452
	$dhcrelayifs = array();
453
	foreach ($dhcrelaycfg as $dhcrelayif => $dhcrelayifconf) {
454

    
455
		$ifcfg = $config['interfaces'][$dhcrelayif];
456

    
457
		if (!isset($dhcrelayifconf['enable']) ||
458
			(($dhcrelayif != "lan") &&
459
			(!isset($ifcfg['enable']) || !$ifcfg['if'] || 
460
			link_interface_to_bridge($dhcrelayif))))
461
			continue;
462

    
463
		$dhcrelayifs[] = get_real_interface($dhcprelayif);
464
	}
465

    
466
	/* In order for the relay to work, it needs to be active on the
467
	   interface in which the destination server sits */
468
	$dhrelayifs = get_configured_interface_list();
469
	foreach ($dhrelayifs as $ifname) {
470
		$subnet = get_interface_ip($ifname) . "/" . get_interface_subnet($ifname);
471
		if (ip_in_subnet($dhcrelaycfg['server'],$subnet))
472
			$destif = $ifname['if'];
473
	}
474

    
475
	if (!isset($destif))
476
		$destif = $config['interfaces']['wan']['if'];
477

    
478
	$dhcrelayifs[] = $destif;
479
	$dhcrelayifs = array_unique($dhcrelayifs);
480

    
481
	/* fire up dhcrelay */
482
	$cmd = "/usr/local/sbin/dhcrelay -i " .  join(" -i ", $dhcrelayifs);
483

    
484
	if (isset($dhcrelaycfg['agentoption']))
485
		$cmd .=  " -a -m replace";
486

    
487
	$cmd .= " {$dhcrelaycfg['server']}";
488
	mwexec($cmd);
489

    
490
	if (!$g['booting']) {
491
		/* set the reload filter dity flag */
492
		filter_configure();
493
	}
494

    
495
	return 0;
496
}
497

    
498
function services_dyndns_reset($interface = "wan" ) {
499
	global $config, $g;
500
	if(isset($config['system']['developerspew'])) {
501
		$mt = microtime();
502
		echo "services_dyndns_reset() being called $mt\n";
503
	}
504

    
505
	$dyndnscfg = $config['dyndnses']['dyndns'];
506

    
507
        if (is_array($dyndnscfg)) {
508
                foreach ($dyndnscfg as $dyndns) {
509
                        if (!isset($dyndns['enable']))
510
                                continue;
511
			if ($dyndns['interface'] != $interface)
512
				continue;
513

    
514
                        services_dyndns_configure_client($dyndns);
515

    
516
                        sleep(1);
517
                }
518

    
519
        }
520

    
521
	return 0;
522
}
523

    
524
function services_dyndns_configure_client($conf) {
525

    
526
	/* load up the dyndns.class */
527
	require_once("dyndns.class");
528

    
529
	log_error("DynDns: Running updatedns()");
530

    
531
	$dns = new updatedns($dnsService = $conf['type'],
532
		$dnsHost = $conf['host'],
533
		$dnsUser = $conf['username'],
534
		$dnsPass = $conf['password'],
535
		$dnsWilcard = $conf['wildcard'],
536
		$dnsMX = $conf['mx'], $dnsIf = "{$conf['interface']}");
537

    
538
}
539

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

    
547
	$dyndnscfg = $config['dyndnses']['dyndns'];
548

    
549
	if (is_array($dyndnscfg)) {
550
		if ($g['booting']) 
551
			echo "Starting DynDNS clients...";
552

    
553
		foreach ($dyndnscfg as $dyndns) {
554
			if (!isset($dyndns['enable']))
555
				continue;
556

    
557
			services_dyndns_configure_client($dyndns);
558

    
559
			sleep(1);
560
		}
561

    
562
		if ($g['booting'])
563
			echo "done.\n";
564
	}
565

    
566
	return 0;
567
}
568

    
569
function services_dnsmasq_configure() {
570
	global $config, $g;
571
	$return = 0;
572
	
573
	if(isset($config['system']['developerspew'])) {
574
		$mt = microtime();
575
		echo "services_dnsmasq_configure() being called $mt\n";
576
	}
577

    
578
	/* kill any running dnsmasq */
579
	sigkillbypid("{$g['varrun_path']}/dnsmasq.pid", "TERM");
580

    
581
	if (isset($config['dnsmasq']['enable'])) {
582

    
583
		if ($g['booting'])
584
			echo "Starting DNS forwarder...";
585
		else
586
			sleep(1);
587

    
588
		/* generate hosts file */
589
		if(system_hosts_generate()!=0)
590
			$return = 1;
591

    
592
		$args = "";
593

    
594
		if (isset($config['dnsmasq']['regdhcp'])) {
595
			$args .= " -l {$g['dhcpd_chroot_path']}/var/db/dhcpd.leases" .
596
				" -s {$config['system']['domain']}";
597
		}
598

    
599
		if (isset($config['dnsmasq']['domainoverrides']) && is_array($config['dnsmasq']['domainoverrides'])) {
600
			foreach($config['dnsmasq']['domainoverrides'] as $override) {
601
			        $args .= ' --server=/' . $override['domain'] . '/' . $override['ip'];
602
			}
603
		}
604

    
605
		/* suppose that dnsmasq handles our domain and don't send
606
		requests for our local domain to upstream servers */
607
		//if (!empty($config['system']['domain'])) {
608
		//	$args .= sprintf(' --local=/%s/', $config['system']['domain']);
609
		//}
610

    
611
		/* run dnsmasq */
612
		mwexec("/usr/local/sbin/dnsmasq --all-servers --cache-size=10000 {$args}");
613

    
614
		if ($g['booting'])
615
			echo "done.\n";
616
	}
617

    
618
	if (!$g['booting']) {
619
		if(services_dhcpd_configure()!=0)
620
			$return = 1;
621
	}
622

    
623
	return $return;
624
}
625

    
626
function services_snmpd_configure() {
627
	global $config, $g;
628
	if(isset($config['system']['developerspew'])) {
629
		$mt = microtime();
630
		echo "services_snmpd_configure() being called $mt\n";
631
	}
632

    
633
	/* kill any running snmpd */
634
	sigkillbypid("{$g['varrun_path']}/snmpd.pid", "TERM");
635
	if(is_process_running("bsnmpd")) 
636
		mwexec("/usr/bin/killall bsnmpd", true);
637

    
638
	if (isset($config['snmpd']['enable'])) {
639

    
640
		if ($g['booting'])
641
			echo "Starting SNMP daemon... ";
642

    
643
		/* generate snmpd.conf */
644
		$fd = fopen("{$g['varetc_path']}/snmpd.conf", "w");
645
		if (!$fd) {
646
			printf("Error: cannot open snmpd.conf in services_snmpd_configure().\n");
647
			return 1;
648
		}
649

    
650

    
651
		$snmpdconf = <<<EOD
652
location := "{$config['snmpd']['syslocation']}"
653
contact := "{$config['snmpd']['syscontact']}"
654
read := "{$config['snmpd']['rocommunity']}"
655

    
656
EOD;
657

    
658
/* No docs on what write strings do there for disable for now.
659
		if(isset($config['snmpd']['rwenable']) && preg_match('/^\S+$/', $config['snmpd']['rwcommunity'])){
660
		    $snmpdconf .= <<<EOD
661
# write string
662
write := "{$config['snmpd']['rwcommunity']}"
663

    
664
EOD;
665
		}
666
*/
667

    
668

    
669
		if(isset($config['snmpd']['trapenable']) && preg_match('/^\S+$/', $config['snmpd']['trapserver'])){
670
		    $snmpdconf .= <<<EOD
671
# SNMP Trap support.
672
traphost := {$config['snmpd']['trapserver']}
673
trapport := {$config['snmpd']['trapserverport']}
674
trap := "{$config['snmpd']['trapstring']}"
675

    
676

    
677
EOD;
678
		}
679

    
680

    
681
		$snmpdconf .= <<<EOD
682
system := 1     # pfSense
683
%snmpd
684
begemotSnmpdDebugDumpPdus       = 2
685
begemotSnmpdDebugSyslogPri      = 7
686
begemotSnmpdCommunityString.0.1 = $(read)
687

    
688
EOD;
689

    
690
/* No docs on what write strings do there for disable for now.
691
		if(isset($config['snmpd']['rwcommunity']) && preg_match('/^\S+$/', $config['snmpd']['rwcommunity'])){
692
		    $snmpdconf .= <<<EOD
693
begemotSnmpdCommunityString.0.2 = $(write)
694

    
695
EOD;
696
		}
697
*/
698

    
699

    
700
		if(isset($config['snmpd']['trapenable']) && preg_match('/^\S+$/', $config['snmpd']['trapserver'])){
701
		    $snmpdconf .= <<<EOD
702
begemotTrapSinkStatus.[$(traphost)].$(trapport) = 4
703
begemotTrapSinkVersion.[$(traphost)].$(trapport) = 2
704
begemotTrapSinkComm.[$(traphost)].$(trapport) = $(trap)
705

    
706
EOD;
707
		}
708

    
709

    
710
		$snmpdconf .= <<<EOD
711
begemotSnmpdCommunityDisable    = 1
712

    
713
EOD;
714

    
715
		if(isset($config['snmpd']['bindlan'])) {
716
			$bind_to_ip = get_interface_ip("lan");
717
		} else {
718
			$bind_to_ip = "0.0.0.0";
719
		}
720

    
721
		if(is_port( $config['snmpd']['pollport'] )) {
722
		    $snmpdconf .= <<<EOD
723
begemotSnmpdPortStatus.{$bind_to_ip}.{$config['snmpd']['pollport']} = 1
724

    
725
EOD;
726

    
727
		}
728

    
729
		$snmpdconf .= <<<EOD
730
begemotSnmpdLocalPortStatus."/var/run/snmpd.sock" = 1
731
begemotSnmpdLocalPortType."/var/run/snmpd.sock" = 4
732

    
733
# These are bsnmp macros not php vars.
734
sysContact      = $(contact)
735
sysLocation     = $(location)
736
sysObjectId     = 1.3.6.1.4.1.12325.1.1.2.1.$(system)
737

    
738
snmpEnableAuthenTraps = 2
739

    
740
EOD;
741

    
742
		if (is_array( $config['snmpd']['modules'] )) {
743
		    if(isset($config['snmpd']['modules']['mibii'])) {
744
			$snmpdconf .= <<<EOD
745
begemotSnmpdModulePath."mibII"  = "/usr/lib/snmp_mibII.so"
746

    
747
EOD;
748
		    }
749

    
750
		    if(isset($config['snmpd']['modules']['netgraph'])) {
751
			$snmpdconf .= <<<EOD
752
begemotSnmpdModulePath."netgraph" = "/usr/lib/snmp_netgraph.so"
753
%netgraph
754
begemotNgControlNodeName = "snmpd"
755

    
756
EOD;
757
		    }
758

    
759
		    if(isset($config['snmpd']['modules']['pf'])) {
760
			$snmpdconf .= <<<EOD
761
begemotSnmpdModulePath."pf"     = "/usr/lib/snmp_pf.so"
762

    
763
EOD;
764
		    }
765

    
766
		    if(isset($config['snmpd']['modules']['hostres'])) {
767
			$snmpdconf .= <<<EOD
768
begemotSnmpdModulePath."hostres"     = "/usr/lib/snmp_hostres.so"
769

    
770
EOD;
771
		    }
772
		    if(isset($config['snmpd']['modules']['bridge'])) {
773
			$snmpdconf .= <<<EOD
774
begemotSnmpdModulePath."bridge"     = "/usr/lib/snmp_bridge.so"
775
# config must end with blank line
776

    
777

    
778
EOD;
779
		    }
780
		}
781

    
782
		fwrite($fd, $snmpdconf);
783
		fclose($fd);
784

    
785
		if (isset($config['snmpd']['bindlan'])) {
786
			$bindlan = "";
787
		}
788

    
789
		/* run bsnmpd */
790
		mwexec("/usr/sbin/bsnmpd -c {$g['varetc_path']}/snmpd.conf" .
791
			"{$bindlan} -p {$g['varrun_path']}/snmpd.pid");
792

    
793
		if ($g['booting'])
794
			echo "done.\n";
795
	}
796

    
797
	return 0;
798
}
799

    
800
function services_proxyarp_configure() {
801
	global $config, $g;
802
	if(isset($config['system']['developerspew'])) {
803
		$mt = microtime();
804
		echo "services_proxyarp_configure() being called $mt\n";
805
	}
806

    
807
	/* kill any running choparp */
808
	killbyname("choparp");
809

    
810
	if (isset($config['virtualip']) && is_array($config['virtualip']['vip'])) {
811
		$paa = array();
812

    
813
		/* group by interface */
814
		foreach ($config['virtualip']['vip'] as $vipent) {
815
			if ($vipent['mode'] === "proxyarp") {
816
				if ($vipent['interface'])
817
					$if = $vipent['interface'];
818
				else
819
					$if = "wan";
820

    
821
				if (!is_array($paa[$if]))
822
					$paa[$if] = array();
823

    
824
				$paa[$if][] = $vipent;
825
			}
826
		}
827

    
828
		if (count($paa))
829
		foreach ($paa as $paif => $paents) {
830
			$paaifip = get_interface_ip($paif);
831
			if (!(is_ipaddr($paaifip)))
832
                               continue;
833

    
834
			$args = get_real_interface($paif) . " auto";
835

    
836
			foreach ($paents as $paent) {
837

    
838
				if (isset($paent['subnet']))
839
					$args .= " " . escapeshellarg("{$paent['subnet']}/{$paent['subnet_bits']}");
840
				else if (isset($paent['range']))
841
					$args .= " " . escapeshellarg($paent['range']['from'] . "-" .
842
						$paent['range']['to']);
843
			}
844

    
845
			mwexec_bg("/usr/local/sbin/choparp " . $args);
846
		}
847
	}
848
}
849

    
850
function services_dnsupdate_process() {
851
	global $config, $g;
852
	if(isset($config['system']['developerspew'])) {
853
		$mt = microtime();
854
		echo "services_dnsupdate_process() being called $mt\n";
855
	}
856

    
857
	/* Dynamic DNS updating active? */
858
	if (is_array($config['dnsupdates']['dnsupdate'])) {
859
		foreach ($config['dnsupdates']['dnsupdate'] as $i => $dnsupdate) {
860
		if (!isset($dyndns['enable']))
861
				continue;
862
			/* determine interface name */
863
			if ($dyndns['interface'] == "wan")
864
				$if = get_real_interface();
865
			else
866
				$if = convert_friendly_interface_to_real_interface_name($dyndns['interface']);
867

    
868
			$wanip = get_interface_ip($if);
869
			if ($wanip) {
870

    
871
				$keyname = $dnsupdate['keyname'];
872
				/* trailing dot */
873
				if (substr($keyname, -1) != ".")
874
					$keyname .= ".";
875

    
876
				$hostname = $dnsupdate['host'];
877
				/* trailing dot */
878
				if (substr($hostname, -1) != ".")
879
					$hostname .= ".";
880

    
881
				/* write private key file
882
				   this is dumb - public and private keys are the same for HMAC-MD5,
883
				   but nsupdate insists on having both */
884
				$fd = fopen("{$g['varetc_path']}/K{$i}{$keyname}+157+00000.private", "w");
885
				$privkey .= <<<EOD
886
Private-key-format: v1.2
887
Algorithm: 157 (HMAC)
888
Key: {$dnsupdate['keydata']}
889

    
890
EOD;
891
				fwrite($fd, $privkey);
892
				fclose($fd);
893

    
894
				/* write public key file */
895
				if ($dnsupdate['keytype'] == "zone") {
896
					$flags = 257;
897
					$proto = 3;
898
				} else if ($dnsupdate['keytype'] == "host") {
899
					$flags = 513;
900
					$proto = 3;
901
				} else if ($dnsupdate['keytype'] == "user") {
902
					$flags = 0;
903
					$proto = 2;
904
				}
905

    
906
				$fd = fopen("{$g['varetc_path']}/K{$keyname}+157+00000.key", "w");
907
				fwrite($fd, "{$keyname} IN KEY {$flags} {$proto} 157 {$dnsupdate['keydata']}\n");
908
				fclose($fd);
909

    
910
				/* generate update instructions */
911
				$upinst = "";
912
				if (!empty($dnsupdate['server']))
913
					$upinst .= "server {$dnsupdate['server']}\n";
914
				$upinst .= "update delete {$dnsupdate['host']} A\n";
915
				$upinst .= "update add {$dnsupdate['host']} {$dnsupdate['ttl']} A {$wanip}\n";
916
				$upinst .= "\n";	/* mind that trailing newline! */
917

    
918
				$fd = fopen("{$g['varetc_path']}/nsupdatecmds{$i}", "w");
919
				fwrite($fd, $upinst);
920
				fclose($fd);
921

    
922
				/* invoke nsupdate */
923
				$cmd = "/usr/sbin/nsupdate -k {$g['varetc_path']}/K{$i}{$keyname}+157+00000.key";
924
				if (isset($dnsupdate['usetcp']))
925
					$cmd .= " -v";
926
				$cmd .= " {$g['varetc_path']}/nsupdatecmds{$i}";
927
	
928
				mwexec_bg($cmd);
929
			}
930
		}
931
	}
932

    
933
	return 0;
934
}
935

    
936
function setup_wireless_olsr() {
937
	global $config, $g;
938
	if(!$config['installedpackages']['olsrd'] || !$config['installedpackages'])
939
		return;
940
	if(isset($config['system']['developerspew'])) {
941
		$mt = microtime();
942
		echo "setup_wireless_olsr($interface) being called $mt\n";
943
	}
944
	conf_mount_rw();
945
	foreach($config['installedpackages']['olsrd']['config'] as $olsrd) {
946
		$olsr_enable = $olsrd['enable'];
947
		if($olsr_enable <> "on")
948
			return;
949
		$fd = fopen("{$g['varetc_path']}/olsr.conf", "w");
950

    
951
		if($olsrd['announcedynamicroute'] or $olsrd['enableannounce'] == "on") {
952
			$enableannounce .= "\nHna4\n";
953
			$enableannounce .= "{\n";
954
		if($olsrd['announcedynamicroute'])
955
			$enableannounce .= "\t{$olsrd['announcedynamicroute']}\n";
956
		if($olsrd['enableannounce'] == "on")
957
			$enableannounce .= "0.0.0.0 0.0.0.0";
958
			$enableannounce .= "\n}\n";
959
		} else {
960
			$enableannounce = "";
961
		}
962

    
963
		$olsr .= <<<EODA
964
#
965
# olsr.org OLSR daemon config file
966
#
967
# Lines starting with a # are discarded
968
#
969
# This file was generated by setup_wireless_olsr() in services.inc
970
#
971

    
972
# This file is an example of a typical
973
# configuration for a mostly static
974
# network(regarding mobility) using
975
# the LQ extention
976

    
977
# Debug level(0-9)
978
# If set to 0 the daemon runs in the background
979

    
980
DebugLevel	2
981

    
982
# IP version to use (4 or 6)
983

    
984
IpVersion	4
985

    
986
# Clear the screen each time the internal state changes
987

    
988
ClearScreen     yes
989

    
990
{$enableannounce}
991

    
992
# Should olsrd keep on running even if there are
993
# no interfaces available? This is a good idea
994
# for a PCMCIA/USB hotswap environment.
995
# "yes" OR "no"
996

    
997
AllowNoInt	yes
998

    
999
# TOS(type of service) value for
1000
# the IP header of control traffic.
1001
# If not set it will default to 16
1002

    
1003
#TosValue	16
1004

    
1005
# The fixed willingness to use(0-7)
1006
# If not set willingness will be calculated
1007
# dynamically based on battery/power status
1008
# if such information is available
1009

    
1010
#Willingness    	4
1011

    
1012
# Allow processes like the GUI front-end
1013
# to connect to the daemon.
1014

    
1015
IpcConnect
1016
{
1017
     # Determines how many simultaneously
1018
     # IPC connections that will be allowed
1019
     # Setting this to 0 disables IPC
1020

    
1021
     MaxConnections  0
1022

    
1023
     # By default only 127.0.0.1 is allowed
1024
     # to connect. Here allowed hosts can
1025
     # be added
1026

    
1027
     Host            127.0.0.1
1028
     #Host            10.0.0.5
1029

    
1030
     # You can also specify entire net-ranges
1031
     # that are allowed to connect. Multiple
1032
     # entries are allowed
1033

    
1034
     #Net             192.168.1.0 255.255.255.0
1035
}
1036

    
1037
# Wether to use hysteresis or not
1038
# Hysteresis adds more robustness to the
1039
# link sensing but delays neighbor registration.
1040
# Used by default. 'yes' or 'no'
1041

    
1042
UseHysteresis	no
1043

    
1044
# Hysteresis parameters
1045
# Do not alter these unless you know
1046
# what you are doing!
1047
# Set to auto by default. Allowed
1048
# values are floating point values
1049
# in the interval 0,1
1050
# THR_LOW must always be lower than
1051
# THR_HIGH.
1052

    
1053
#HystScaling	0.50
1054
#HystThrHigh	0.80
1055
#HystThrLow	0.30
1056

    
1057

    
1058
# Link quality level
1059
# 0 = do not use link quality
1060
# 1 = use link quality for MPR selection
1061
# 2 = use link quality for MPR selection and routing
1062
# Defaults to 0
1063

    
1064
LinkQualityLevel	{$olsrd['enablelqe']}
1065

    
1066
# Link quality window size
1067
# Defaults to 10
1068

    
1069
LinkQualityWinSize	10
1070

    
1071
# Polling rate in seconds(float).
1072
# Default value 0.05 sec
1073

    
1074
Pollrate	0.05
1075

    
1076

    
1077
# TC redundancy
1078
# Specifies how much neighbor info should
1079
# be sent in TC messages
1080
# Possible values are:
1081
# 0 - only send MPR selectors
1082
# 1 - send MPR selectors and MPRs
1083
# 2 - send all neighbors
1084
#
1085
# defaults to 0
1086

    
1087
TcRedundancy	2
1088

    
1089
#
1090
# MPR coverage
1091
# Specifies how many MPRs a node should
1092
# try select to reach every 2 hop neighbor
1093
#
1094
# Can be set to any integer >0
1095
#
1096
# defaults to 1
1097

    
1098
MprCoverage	3
1099

    
1100
# Example plugin entry with parameters:
1101

    
1102
EODA;
1103

    
1104
if($olsrd['enablehttpinfo'] == "on") {
1105
	$olsr .= <<<EODB
1106

    
1107
LoadPlugin "/usr/local/lib/olsrd_httpinfo.so.0.1"
1108
{
1109
    PlParam     "port"   "{$olsrd['port']}"
1110
    PlParam     "Net"    "{$olsrd['allowedhttpinfohost']} {$olsrd['allowedhttpinfosubnet']}"
1111
}
1112

    
1113
EODB;
1114

    
1115
}
1116

    
1117
if($olsrd['enabledsecure'] == "on") {
1118
	$olsr .= <<<EODC
1119

    
1120
LoadPlugin "/usr/local/lib/olsrd_secure.so.0.5"
1121
{
1122
    PlParam     "Keyfile"   "/usr/local/etc/olsrkey.txt"
1123
}
1124

    
1125
EODC;
1126

    
1127
}
1128

    
1129
if($olsrd['enabledyngw'] == "on") {
1130

    
1131
	/* unset default route, olsr auto negotiates */
1132
	mwexec("/sbin/route delete default");
1133

    
1134
	$olsr .= <<<EODE
1135

    
1136
LoadPlugin "/usr/local/lib/olsrd_dyn_gw.so.0.4"
1137
{
1138
    # how often to look for a inet gw, in seconds
1139
    # defaults to 5 secs, if commented out
1140
    PlParam     "Interval"   "{$olsrd['polling']}"
1141

    
1142
    # if one or more IPv4 addresses are given, do a ping on these in
1143
    # descending order to validate that there is not only an entry in
1144
    # routing table, but also a real internet connection. If any of
1145
    # these addresses could be pinged successfully, the test was
1146
    # succesful, i.e. if the ping on the 1st address was successful,the
1147
    # 2nd won't be pinged
1148
    PlParam     "Ping"       "{$olsrd['ping']}"
1149
    #PlParam     "HNA"   "192.168.81.0 255.255.255.0"
1150
}
1151

    
1152
EODE;
1153

    
1154
}
1155

    
1156
foreach($config['installedpackages']['olsrd']['config'] as $conf) {
1157
	$interfaces = explode(',', $conf['iface_array']);
1158
	foreach($interfaces as $interface) {
1159
		$realinterface = convert_friendly_interface_to_real_interface_name($interface);
1160
$olsr .= <<<EODAD
1161
Interface "{$realinterface}"
1162
{
1163

    
1164
    # Hello interval in seconds(float)
1165
    HelloInterval    2.0
1166

    
1167
    # HELLO validity time
1168
    HelloValidityTime	20.0
1169

    
1170
    # TC interval in seconds(float)
1171
    TcInterval        5.0
1172

    
1173
    # TC validity time
1174
    TcValidityTime	30.0
1175

    
1176
    # MID interval in seconds(float)
1177
    MidInterval	5.0
1178

    
1179
    # MID validity time
1180
    MidValidityTime	30.0
1181

    
1182
    # HNA interval in seconds(float)
1183
    HnaInterval	5.0
1184

    
1185
    # HNA validity time
1186
    HnaValidityTime 	30.0
1187

    
1188
    # When multiple links exist between hosts
1189
    # the weight of interface is used to determine
1190
    # the link to use. Normally the weight is
1191
    # automatically calculated by olsrd based
1192
    # on the characteristics of the interface,
1193
    # but here you can specify a fixed value.
1194
    # Olsrd will choose links with the lowest value.
1195

    
1196
    # Weight 0
1197

    
1198

    
1199
}
1200

    
1201
EODAD;
1202

    
1203
	}
1204
	break;
1205
}
1206
		fwrite($fd, $olsr);
1207
		fclose($fd);
1208
	}
1209

    
1210
	if(is_process_running("olsrd"))
1211
		mwexec("/usr/bin/killall olsrd", true);
1212

    
1213
	sleep(2);
1214

    
1215
	mwexec_bg("/usr/local/sbin/olsrd -f {$g['varetc_path']}/olsr.conf");
1216

    
1217
	conf_mount_ro();
1218
}
1219

    
1220
/* configure cron service */
1221
function configure_cron() {
1222
	global $g, $config;
1223
	conf_mount_rw();
1224
	/* preserve existing crontab entries */
1225
	$crontab_contents = file_get_contents("/etc/crontab");
1226
	$crontab_contents_a = split("\n", $crontab_contents);
1227
	
1228
	for ($i = 0; $i < count($crontab_contents_a); $i++) {
1229
		$item =& $crontab_contents_a[$i];
1230
		if (strpos($item, "# pfSense specific crontab entries") !== false) {
1231
			array_splice($crontab_contents_a, $i - 1);
1232
			break;
1233
		}
1234
	}
1235
	$crontab_contents = implode("\n", $crontab_contents_a) . "\n";
1236
	
1237
	
1238
	if (is_array($config['cron']['item'])) {
1239
		$crontab_contents .= "#\n";
1240
		$crontab_contents .= "# pfSense specific crontab entries\n";
1241
		$crontab_contents .= "# Created: " . date("F j, Y, g:i a") . "\n";
1242
		$crontab_contents .= "#\n";
1243

    
1244
		foreach ($config['cron']['item'] as $item) {
1245
			$crontab_contents .= "\n{$item['minute']}\t";
1246
			$crontab_contents .= "{$item['hour']}\t";
1247
			$crontab_contents .= "{$item['mday']}\t";
1248
			$crontab_contents .= "{$item['month']}\t";
1249
			$crontab_contents .= "{$item['wday']}\t";
1250
			$crontab_contents .= "{$item['who']}\t";
1251
			$crontab_contents .= "{$item['command']}";
1252
		}
1253
    
1254
		$crontab_contents .= "\n#\n";
1255
		$crontab_contents .= "# If possible do not add items to this file manually.\n";
1256
		$crontab_contents .= "# If you do so, this file must be terminated with a blank line (e.g. new line)\n";
1257
		$crontab_contents .= "#\n\n";
1258
	}
1259
	
1260
	/* please maintain the newline at the end of file */
1261
	file_put_contents("/etc/crontab", $crontab_contents);
1262
	
1263
	if (!$g['booting'])
1264
		conf_mount_ro();
1265
}
1266

    
1267
function upnp_action ($action) {
1268
	switch($action) {
1269
		case "start":
1270
			if(file_exists('/var/etc/miniupnpd.conf'))
1271
				mwexec_bg('/usr/local/sbin/miniupnpd -f /var/etc/miniupnpd.conf');
1272
			break;
1273
		case "stop":
1274
			while((int)exec("pgrep miniupnpd | wc -l") > 0)
1275
				mwexec('killall miniupnpd 2>/dev/null', true);
1276
			mwexec('/sbin/pfctl -aminiupnpd -Fr 2>&1 >/dev/null');
1277
			mwexec('/sbin/pfctl -aminiupnpd -Fn 2>&1 >/dev/null');
1278
			break;
1279
		case "restart":
1280
			upnp_action('stop');
1281
			upnp_action('start');
1282
			break;
1283
	}
1284
}
1285

    
1286
function upnp_start() {
1287
	global $config, $g;
1288
	if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
1289
		if($g['booting']) {
1290
			echo "Starting UPnP service... ";
1291
			include('/usr/local/pkg/miniupnpd.inc');
1292
			sync_package_miniupnpd();
1293
			echo "done.\n";
1294
		}
1295
		else {
1296
			upnp_action('start');
1297
		}
1298
	}
1299
}
1300

    
1301
?>
(29-29/40)