Project

General

Profile

Download (33.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	services.inc
5
	part of the pfSense project (http://www.pfsense.com)
6

    
7
	originally part of m0n0wall (http://m0n0.ch/wall)
8
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10

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

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

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

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

    
33
/*
34
	pfSense_BUILDER_BINARIES:	/usr/bin/killall	/bin/sh	/usr/local/sbin/dhcpd	/usr/local/sbin/igmpproxy
35
	pfSense_BUILDER_BINARIES:	/sbin/ifconfig	/usr/sbin/arp	/sbin/ifconfig	/usr/local/sbin/dnsmasq
36
	pfSense_BUILDER_BINARIES:	/usr/sbin/bsnmpd	/sbin/route	/usr/local/sbin/olsrd
37
	pfSense_BUILDER_BINARIES:	/usr/local/sbin/miniupnpd	
38
	pfSense_MODULE:	utils
39
*/
40

    
41
/* include all configuration functions */
42

    
43
function services_dhcpd_configure() {
44
	global $config, $g;
45
	
46
	if($g['services_dhcp_server_enable'] == false) 
47
		return;
48

    
49
	if(isset($config['system']['developerspew'])) {
50
		$mt = microtime();
51
		echo "services_dhcpd_configure($if) being called $mt\n";
52
	}
53
	
54
	/* kill any running dhcpd */
55
	if(is_process_running("dhcpd"))
56
		mwexec("killall dhcpd", true);
57

    
58
	/* DHCP enabled on any interfaces? */
59
	if (!is_dhcp_server_enabled())
60
		return 0;
61

    
62
	/* if OLSRD is enabled, allow WAN to house DHCP. */
63
	if($config['installedpackages']['olsrd'])
64
		foreach($config['installedpackages']['olsrd']['config'] as $olsrd)
65
				if($olsrd['enable'])
66
					$is_olsr_enabled = true;
67

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

    
89
	$syscfg = $config['system'];
90
	$dhcpdcfg = $config['dhcpd'];
91
	$Iflist = get_configured_interface_list();
92
		
93
	if ($g['booting'])
94
		echo "Starting DHCP service...";
95
	else
96
		sleep(1);
97

    
98
	/* write dhcpd.conf */
99
	$fd = fopen("{$g['dhcpd_chroot_path']}/etc/dhcpd.conf", "w");
100
	if (!$fd) {
101
		printf("Error: cannot open dhcpd.conf in services_dhcpd_configure().\n");
102
		return 1;
103
	}
104

    
105
	$optcounter = 0;
106
	$custoptions = "";
107
	foreach ($dhcpdcfg as $dhcpif => $dhcpifconf) {	
108
		if($dhcpifconf['numberoptions']['item']) {
109
			foreach($dhcpifconf['numberoptions']['item'] as $item) {
110
				$custoptions .= "option custom-opt-$optcounter code {$item['number']} = text;\n";
111
				$optcounter++;
112
			}
113
		}
114
	}
115

    
116
	$dhcpdconf = <<<EOD
117
	
118
option domain-name "{$syscfg['domain']}";
119
option ldap-server code 95 = text;
120
option domain-search-list code 119 = text;
121
{$custoptions}
122
default-lease-time 7200;
123
max-lease-time 86400;
124
log-facility local7;
125
ddns-update-style none;
126
one-lease-per-client true;
127
deny duplicates;
128
ping-check true;
129

    
130
EOD;
131

    
132
	if(isset($dhcpifconf['alwaysbroadcast'])) 
133
		$dhcpdconf .= "always-broadcast on\n";
134

    
135
	$dhcpdifs = array();
136

    
137
	/*    loop through and deterimine if we need to setup
138
	 *    failover peer "bleh" entries
139
	 */
140
	$dhcpnum = 0;
141
	foreach ($dhcpdcfg as $dhcpif => $dhcpifconf) {
142

    
143
		if (!isset($dhcpifconf['enable']))
144
			continue;
145

    
146
		if(!isset($dhcpifconf['disableauthoritative']))
147
			$dhcpdconf .= "authoritative;\n";
148

    
149
		if($dhcpifconf['failover_peerip'] <> "") {
150
			/*
151
			 *    yep, failover peer is defined.
152
			 *    does it match up to a defined vip?
153
			 */
154
			$skew = 110;
155
			$a_vip = &$config['virtualip']['vip'];
156
			if(is_array($a_vip)) {
157
				foreach ($a_vip as $vipent) {
158
					$int = guess_interface_from_ip($dhcpifconf['failover_peerip']);
159
					$intip = find_interface_ip($int);
160
					$real_dhcpif = convert_friendly_interface_to_real_interface_name($dhcpif);
161
					if($int == $real_dhcpif) {
162
						/* this is the interface! */
163
						if($vipent['advskew'] < "20")
164
							$skew = 0;
165
					}
166
				}
167
			} else {
168
				log_error("Warning!  DHCP Failover setup and no CARP virtual IP's defined!");
169
			}
170
			if($skew > 10) {
171
				$type = "secondary";
172
				$dhcpdconf_pri  = "mclt 600;\n";
173
				$my_port = "520";
174
				$peer_port = "519";
175
			} else {
176
				$my_port = "519";
177
				$peer_port = "520";
178
				$type = "primary";
179
				$dhcpdconf_pri  = "split 128;\n";
180
				$dhcpdconf_pri .= "  mclt 600;\n";
181
			}
182
			$dhcpdconf .= <<<EOPP
183
failover peer "dhcp{$dhcpnum}" {
184
  {$type};
185
  address {$intip};
186
  port {$my_port};
187
  peer address {$dhcpifconf['failover_peerip']};
188
  peer port {$peer_port};
189
  max-response-delay 10;
190
  max-unacked-updates 10;
191
  {$dhcpdconf_pri}
192
  load balance max seconds 3;
193
}
194

    
195
EOPP;
196
		$dhcpnum++;
197
		}
198
	}
199

    
200
	$dhcpnum = 0;
201

    
202
	foreach ($dhcpdcfg as $dhcpif => $dhcpifconf) {
203

    
204
		$ifcfg = $config['interfaces'][$dhcpif];
205

    
206
		if (!isset($dhcpifconf['enable']) || !isset($Iflist[$dhcpif]))
207
			continue;
208
		$ifcfgip = get_interface_ip($dhcpif);
209
		$ifcfgsn = get_interface_subnet($dhcpif);
210
		$subnet = gen_subnet($ifcfgip, $ifcfgsn);
211
		$subnetmask = gen_subnet_mask($ifcfgsn);
212

    
213
		if($is_olsr_enabled == true)
214
			if($dhcpifconf['netmask'])
215
				$subnetmask = gen_subnet_mask($dhcpifconf['netmask']);
216

    
217
		$dnscfg = "";
218

    
219
		if ($dhcpifconf['domain']) {
220
			$dnscfg .= "	option domain-name \"{$dhcpifconf['domain']}\";\n";
221
		}
222
		
223
    		if($dhcpifconf['domainsearchlist'] <> "") {
224
			$dnscfg .= "	option domain-search-list \"{$dhcpifconf['domainsearchlist']}\";\n";
225
    		}
226

    
227
		if (isset($dhcpifconf['ddnsupdate'])) {
228
			if($dhcpifconf['ddnsdomain'] <> "") {
229
				$dnscfg .= "	ddns-domainname \"{$dhcpifconf['ddnsdomain']}\";\n";
230
			}
231
			$dnscfg .= "	ddns-update-style interim;\n";
232
		}
233

    
234
		if (is_array($dhcpifconf['dnsserver']) && ($dhcpifconf['dnsserver'][0])) {
235
			$dnscfg .= "	option domain-name-servers " . join(",", $dhcpifconf['dnsserver']) . ";";
236
		} else if (isset($config['dnsmasq']['enable'])) {
237
			$dnscfg .= "	option domain-name-servers {$ifcfgip};";
238
		} else if (is_array($syscfg['dnsserver']) && ($syscfg['dnsserver'][0])) {
239
			$dnscfg .= "	option domain-name-servers " . join(",", $syscfg['dnsserver']) . ";";
240
		}
241

    
242
		$dhcpdconf .= "subnet $subnet netmask $subnetmask {\n";
243
		$dhcpdconf .= "	pool {\n";
244

    
245
		/* is failover dns setup? */
246
		if (is_array($dhcpifconf['dnsserver']) && $dhcpifconf['dnsserver'][0] <> "") {
247
			$dhcpdconf .= "		option domain-name-servers {$dhcpifconf['dnsserver'][0]}";
248
			if($dhcpifconf['dnsserver'][1] <> "")
249
				$dhcpdconf .= ",{$dhcpifconf['dnsserver'][1]}";
250
			$dhcpdconf .= ";\n";
251
		}
252

    
253
		if($dhcpifconf['failover_peerip'] <> "")
254
			$dhcpdconf .= "		deny dynamic bootp clients;\n";
255

    
256
		if (isset($dhcpifconf['denyunknown']))
257
		   $dhcpdconf .= "		deny unknown clients;\n";
258

    
259
		if ($dhcpifconf['gateway'])
260
			$routers = $dhcpifconf['gateway'];
261
		else
262
			$routers = $ifcfgip;
263

    
264
		if($dhcpifconf['failover_peerip'] <> "") {
265
			$dhcpdconf .= "		failover peer \"dhcp{$dhcpnum}\";\n";
266
			$dhcpnum++;
267
		}
268

    
269
		$dhcpdconf .= <<<EOD
270
		range {$dhcpifconf['range']['from']} {$dhcpifconf['range']['to']};
271
	}
272
	option routers {$routers};
273
$dnscfg
274

    
275
EOD;
276
    
277
		// default-lease-time
278
		if ($dhcpifconf['defaultleasetime'])
279
			$dhcpdconf .= "	default-lease-time {$dhcpifconf['defaultleasetime']};\n";
280

    
281
		// max-lease-time
282
		if ($dhcpifconf['maxleasetime'])
283
			$dhcpdconf .= "	max-lease-time {$dhcpifconf['maxleasetime']};\n";
284

    
285
		// netbios-name*
286
		if (is_array($dhcpifconf['winsserver']) && $dhcpifconf['winsserver'][0]) {
287
			$dhcpdconf .= "	option netbios-name-servers " . join(",", $dhcpifconf['winsserver']) . ";\n";
288
			$dhcpdconf .= "	option netbios-node-type 8;\n";
289
		}
290

    
291
		// ntp-servers
292
		if (is_array($dhcpifconf['ntpserver']) && $dhcpifconf['ntpserver'][0])
293
			$dhcpdconf .= "	option ntp-servers " . join(",", $dhcpifconf['ntpserver']) . ";\n";
294

    
295
		// tftp-server-name
296
		if ($dhcpifconf['tftp'] <> "")
297
			$dhcpdconf .= "	option tftp-server-name \"{$dhcpifconf['tftp']}\";\n";
298

    
299
		// Handle option, number rowhelper values
300
		$optcounter = 0;
301
		$dhcpdconf .= "\n";
302
		if($dhcpifconf['numberoptions']['item']) {
303
			foreach($dhcpifconf['numberoptions']['item'] as $item) {
304
				$dhcpdconf .= "	option custom-opt-$optcounter \"{$item['value']}\";\n";
305
				$optcounter++;
306
			}
307
		}
308

    
309
		// ldap-server
310
		if ($dhcpifconf['ldap'] <> "")
311
			$dhcpdconf .= "	option ldap-server \"{$dhcpifconf['ldap']}\";\n";
312

    
313
		// net boot information
314
		if(isset($dhcpifconf['netboot'])) {
315
			if (($dhcpifconf['next-server'] <> "") && ($dhcpifconf['filename'] <> "")) {
316
				$dhcpdconf .= "	next-server {$dhcpifconf['next-server']};\n";
317
				$dhcpdconf .= "	filename \"{$dhcpifconf['filename']}\";\n";
318
			}
319
			if ($dhcpifconf['rootpath'] <> "") {
320
				$dhcpdconf .= "	option root-path \"{$dhcpifconf['rootpath']}\";\n";
321
      		}
322
		}
323
		
324
		$dhcpdconf .= <<<EOD
325
}
326

    
327
EOD;
328

    
329
		/* add static mappings */
330
		if (is_array($dhcpifconf['staticmap'])) {
331

    
332
			$i = 0;
333
			foreach ($dhcpifconf['staticmap'] as $sm) {
334
				$dhcpdconf .= <<<EOD
335
host s_{$dhcpif}_{$i} {
336
	hardware ethernet {$sm['mac']};
337

    
338
EOD;
339
				if ($sm['ipaddr'])
340
					$dhcpdconf .= "	fixed-address {$sm['ipaddr']};\n";
341

    
342
				if ($sm['hostname']) {
343
					$dhhostname = str_replace(" ", "_", $sm['hostname']);
344
					$dhcpdconf .= "	option host-name {$dhhostname};\n";
345
				}
346

    
347
				$dhcpdconf .= "}\n";
348
				$i++;
349
			}
350
		}
351

    
352
		$dhcpdifs[] = get_real_interface($dhcpif);
353
	}
354

    
355
	fwrite($fd, $dhcpdconf);
356
	fclose($fd);
357

    
358
	/* create an empty leases database */
359
	touch("{$g['dhcpd_chroot_path']}/var/db/dhcpd.leases");
360
	touch("{$g['varrun_path']}/dhcpd.pid");
361
	
362

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

    
367
	if ($g['booting']) {
368
		print "done.\n";
369
	}
370

    
371
	return 0;
372
}
373

    
374
function services_igmpproxy_configure() {
375
        global $config, $g;
376

    
377
        $iflist = get_configured_interface_list();
378

    
379
        /* kill any running igmpproxy */
380
        killbyname("igmpproxy");
381

    
382
	if (!is_array($config['igmpproxy']['igmpentry']))
383
		return 1;
384

    
385
        $igmpconf = <<<EOD
386

    
387
##------------------------------------------------------
388
## Enable Quickleave mode (Sends Leave instantly)
389
##------------------------------------------------------
390
quickleave
391

    
392
EOD;
393

    
394
        foreach ($config['igmpproxy']['igmpentry'] as $igmpcf) {
395
                unset($iflist[$igmpcf['ifname']]);
396
                $realif = get_real_interface($igmpcf['ifname']);
397
                if (empty($igmpcf['threshold']))
398
                        $threshld = 1;
399
                else
400
                        $threshld = $igmpcf['threshold'];
401
                $igmpconf .= "phyint {$realif} {$igmpcf['type']} ratelimit 0 threshold {$threshld}\n";
402

    
403
                if ($igmpcf['address'] <> "") {
404
                        $item = explode(" ", $igmpcf['address']);
405
                        foreach($item as $iww)
406
                                $igmpconf .= "altnet {$iww}\n";
407
                }
408
                $igmpconf .= "\n";
409
        }
410
        foreach ($iflist as $ifn) {
411
                $realif = get_real_interface($ifn);
412
                $igmpconf .= "phyint {$realif} disabled\n";
413
        }
414

    
415
        $igmpfl = fopen($g['tmp_path'] . "/igmpproxy.conf", "w");
416
        if (!$igmpfl) {
417
                log_error("Could not write Igmpproxy configuration file!");
418
                return;
419
        }
420
        fwrite($igmpfl, $igmpconf);
421
        fclose($igmpfl);
422

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

    
426
        return 0;
427
}
428

    
429
function interfaces_staticarp_configure($if) {
430
	global $config, $g;
431
	if(isset($config['system']['developerspew'])) {
432
		$mt = microtime();
433
		echo "interfaces_staticarp_configure($if) being called $mt\n";
434
	}
435

    
436
        $ifcfg = $config['interfaces'][$if];
437

    
438
        /* Enable staticarp, if enabled */
439
        if(isset($config['dhcpd'][$if]['staticarp'])) {
440
                mwexec("/sbin/ifconfig " . escapeshellarg($ifcfg['if']) . " staticarp " );
441
                mwexec("/usr/sbin/arp -ad > /dev/null 2>&1 ");
442
                if (is_array($config['dhcpd'][$if]['staticmap'])) {
443

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

    
447
                        }
448

    
449
                }
450
        } else {
451
                mwexec("/sbin/ifconfig " . escapeshellarg($ifcfg['if']) . " -staticarp " );
452
                mwexec("/usr/sbin/arp -da > /dev/null 2>&1 ");
453
        }
454

    
455
        return 0;
456
}
457

    
458
function services_dhcrelay_configure() {
459
	global $config, $g;
460
	if(isset($config['system']['developerspew'])) {
461
		$mt = microtime();
462
		echo "services_dhcrelay_configure() being called $mt\n";
463
	}
464

    
465
	/* kill any running dhcrelay */
466
	killbypid("{$g['varrun_path']}/dhcrelay.pid");
467

    
468
	$dhcrelaycfg = $config['dhcrelay'];
469

    
470
	/* DHCPRelay enabled on any interfaces? */
471
	$dhcrelayenable = false;
472
	if(is_array($dhcrelaycfg)) {
473
		foreach ($dhcrelaycfg as $dhcrelayif => $dhcrelayifconf) {
474
			if (isset($dhcrelayifconf['enable']) &&
475
				(($dhcrelayif == "lan") ||
476
				(isset($config['interfaces'][$dhcrelayif]['enable']) &&
477
				$config['interfaces'][$dhcrelayif]['if'] && (!link_interface_to_bridge($dhcrelayif)))))
478
				$dhcrelayenable = true;
479
		}
480
	}
481

    
482
	if (!$dhcrelayenable)
483
		return 0;
484

    
485
	if ($g['booting'])
486
		echo "Starting DHCP relay service...";
487
	else
488
		sleep(1);
489

    
490
	$dhcrelayifs = array();
491
	foreach ($dhcrelaycfg as $dhcrelayif => $dhcrelayifconf) {
492

    
493
		$ifcfg = $config['interfaces'][$dhcrelayif];
494

    
495
		if (!isset($dhcrelayifconf['enable']) ||
496
			(($dhcrelayif != "lan") &&
497
			(!isset($ifcfg['enable']) || !$ifcfg['if'] || 
498
			link_interface_to_bridge($dhcrelayif))))
499
			continue;
500

    
501
		$dhcrelayifs[] = get_real_interface($dhcprelayif);
502
	}
503

    
504
	/* In order for the relay to work, it needs to be active on the
505
	   interface in which the destination server sits */
506
	$dhrelayifs = get_configured_interface_list();
507
	foreach ($dhrelayifs as $ifname) {
508
		$subnet = get_interface_ip($ifname) . "/" . get_interface_subnet($ifname);
509
		if (ip_in_subnet($dhcrelaycfg['server'],$subnet))
510
			$destif = $ifname['if'];
511
	}
512

    
513
	if (!isset($destif))
514
		$destif = $config['interfaces']['wan']['if'];
515

    
516
	$dhcrelayifs[] = $destif;
517
	$dhcrelayifs = array_unique($dhcrelayifs);
518

    
519
	/* fire up dhcrelay */
520
	$cmd = "/usr/local/sbin/dhcrelay -i " .  join(" -i ", $dhcrelayifs);
521

    
522
	if (isset($dhcrelaycfg['agentoption']))
523
		$cmd .=  " -a -m replace";
524

    
525
	$cmd .= " {$dhcrelaycfg['server']}";
526
	mwexec($cmd);
527

    
528
	return 0;
529
}
530

    
531
function services_dyndns_reset($interface = "wan" ) {
532
	global $config, $g;
533
	if(isset($config['system']['developerspew'])) {
534
		$mt = microtime();
535
		echo "services_dyndns_reset() being called $mt\n";
536
	}
537

    
538
	$dyndnscfg = $config['dyndnses']['dyndns'];
539

    
540
        if (is_array($dyndnscfg)) {
541
                foreach ($dyndnscfg as $dyndns) {
542
                        if (!isset($dyndns['enable']))
543
                                continue;
544
			if ($dyndns['interface'] != $interface)
545
				continue;
546

    
547
                        services_dyndns_configure_client($dyndns);
548

    
549
                        sleep(1);
550
                }
551

    
552
        }
553

    
554
	return 0;
555
}
556

    
557
function services_dyndns_configure_client($conf) {
558

    
559
	/* load up the dyndns.class */
560
	require_once("dyndns.class");
561

    
562
	log_error("DynDns: Running updatedns()");
563

    
564
	$dns = new updatedns($dnsService = $conf['type'],
565
		$dnsHost = $conf['host'],
566
		$dnsUser = $conf['username'],
567
		$dnsPass = $conf['password'],
568
		$dnsWilcard = $conf['wildcard'],
569
		$dnsMX = $conf['mx'], $dnsIf = "{$conf['interface']}");
570

    
571
}
572

    
573
function services_dyndns_configure() {
574
	global $config, $g;
575
	if(isset($config['system']['developerspew'])) {
576
		$mt = microtime();
577
		echo "services_dyndns_configure() being called $mt\n";
578
	}
579

    
580
	$dyndnscfg = $config['dyndnses']['dyndns'];
581

    
582
	if (is_array($dyndnscfg)) {
583
		if ($g['booting']) 
584
			echo "Starting DynDNS clients...";
585

    
586
		foreach ($dyndnscfg as $dyndns) {
587
			if (!isset($dyndns['enable']))
588
				continue;
589

    
590
			services_dyndns_configure_client($dyndns);
591

    
592
			sleep(1);
593
		}
594

    
595
		if ($g['booting'])
596
			echo "done.\n";
597
	}
598

    
599
	return 0;
600
}
601

    
602
function services_dnsmasq_configure() {
603
	global $config, $g;
604
	$return = 0;
605
	
606
	if(isset($config['system']['developerspew'])) {
607
		$mt = microtime();
608
		echo "services_dnsmasq_configure() being called $mt\n";
609
	}
610

    
611
	/* kill any running dnsmasq */
612
	sigkillbypid("{$g['varrun_path']}/dnsmasq.pid", "TERM");
613

    
614
	if (isset($config['dnsmasq']['enable'])) {
615

    
616
		if ($g['booting'])
617
			echo "Starting DNS forwarder...";
618
		else
619
			sleep(1);
620

    
621
		/* generate hosts file */
622
		if(system_hosts_generate()!=0)
623
			$return = 1;
624

    
625
		$args = "";
626

    
627
		if (isset($config['dnsmasq']['regdhcp'])) {
628
			$args .= " -l {$g['dhcpd_chroot_path']}/var/db/dhcpd.leases" .
629
				" -s {$config['system']['domain']}";
630
		}
631

    
632
		if (isset($config['dnsmasq']['domainoverrides']) && is_array($config['dnsmasq']['domainoverrides'])) {
633
			foreach($config['dnsmasq']['domainoverrides'] as $override) {
634
			        $args .= ' --server=/' . $override['domain'] . '/' . $override['ip'];
635
			}
636
		}
637

    
638
		/* suppose that dnsmasq handles our domain and don't send
639
		requests for our local domain to upstream servers */
640
		//if (!empty($config['system']['domain'])) {
641
		//	$args .= sprintf(' --local=/%s/', $config['system']['domain']);
642
		//}
643

    
644
		/* run dnsmasq */
645
		mwexec("/usr/local/sbin/dnsmasq --all-servers --cache-size=10000 {$args}");
646

    
647
		if ($g['booting'])
648
			echo "done.\n";
649
	}
650

    
651
	if (!$g['booting']) {
652
		if(services_dhcpd_configure()!=0)
653
			$return = 1;
654
	}
655

    
656
	return $return;
657
}
658

    
659
function services_snmpd_configure() {
660
	global $config, $g;
661
	if(isset($config['system']['developerspew'])) {
662
		$mt = microtime();
663
		echo "services_snmpd_configure() being called $mt\n";
664
	}
665

    
666
	/* kill any running snmpd */
667
	sigkillbypid("{$g['varrun_path']}/snmpd.pid", "TERM");
668
	if(is_process_running("bsnmpd")) 
669
		mwexec("/usr/bin/killall bsnmpd", true);
670

    
671
	if (isset($config['snmpd']['enable'])) {
672

    
673
		if ($g['booting'])
674
			echo "Starting SNMP daemon... ";
675

    
676
		/* generate snmpd.conf */
677
		$fd = fopen("{$g['varetc_path']}/snmpd.conf", "w");
678
		if (!$fd) {
679
			printf("Error: cannot open snmpd.conf in services_snmpd_configure().\n");
680
			return 1;
681
		}
682

    
683

    
684
		$snmpdconf = <<<EOD
685
location := "{$config['snmpd']['syslocation']}"
686
contact := "{$config['snmpd']['syscontact']}"
687
read := "{$config['snmpd']['rocommunity']}"
688

    
689
EOD;
690

    
691
/* No docs on what write strings do there for disable for now.
692
		if(isset($config['snmpd']['rwenable']) && preg_match('/^\S+$/', $config['snmpd']['rwcommunity'])){
693
		    $snmpdconf .= <<<EOD
694
# write string
695
write := "{$config['snmpd']['rwcommunity']}"
696

    
697
EOD;
698
		}
699
*/
700

    
701

    
702
		if(isset($config['snmpd']['trapenable']) && preg_match('/^\S+$/', $config['snmpd']['trapserver'])){
703
		    $snmpdconf .= <<<EOD
704
# SNMP Trap support.
705
traphost := {$config['snmpd']['trapserver']}
706
trapport := {$config['snmpd']['trapserverport']}
707
trap := "{$config['snmpd']['trapstring']}"
708

    
709

    
710
EOD;
711
		}
712

    
713

    
714
		$snmpdconf .= <<<EOD
715
system := 1     # pfSense
716
%snmpd
717
begemotSnmpdDebugDumpPdus       = 2
718
begemotSnmpdDebugSyslogPri      = 7
719
begemotSnmpdCommunityString.0.1 = $(read)
720

    
721
EOD;
722

    
723
/* No docs on what write strings do there for disable for now.
724
		if(isset($config['snmpd']['rwcommunity']) && preg_match('/^\S+$/', $config['snmpd']['rwcommunity'])){
725
		    $snmpdconf .= <<<EOD
726
begemotSnmpdCommunityString.0.2 = $(write)
727

    
728
EOD;
729
		}
730
*/
731

    
732

    
733
		if(isset($config['snmpd']['trapenable']) && preg_match('/^\S+$/', $config['snmpd']['trapserver'])){
734
		    $snmpdconf .= <<<EOD
735
begemotTrapSinkStatus.[$(traphost)].$(trapport) = 4
736
begemotTrapSinkVersion.[$(traphost)].$(trapport) = 2
737
begemotTrapSinkComm.[$(traphost)].$(trapport) = $(trap)
738

    
739
EOD;
740
		}
741

    
742

    
743
		$snmpdconf .= <<<EOD
744
begemotSnmpdCommunityDisable    = 1
745

    
746
EOD;
747

    
748
		if(isset($config['snmpd']['bindlan'])) {
749
			$bind_to_ip = get_interface_ip("lan");
750
		} else {
751
			$bind_to_ip = "0.0.0.0";
752
		}
753

    
754
		if(is_port( $config['snmpd']['pollport'] )) {
755
		    $snmpdconf .= <<<EOD
756
begemotSnmpdPortStatus.{$bind_to_ip}.{$config['snmpd']['pollport']} = 1
757

    
758
EOD;
759

    
760
		}
761

    
762
		$snmpdconf .= <<<EOD
763
begemotSnmpdLocalPortStatus."/var/run/snmpd.sock" = 1
764
begemotSnmpdLocalPortType."/var/run/snmpd.sock" = 4
765

    
766
# These are bsnmp macros not php vars.
767
sysContact      = $(contact)
768
sysLocation     = $(location)
769
sysObjectId     = 1.3.6.1.4.1.12325.1.1.2.1.$(system)
770

    
771
snmpEnableAuthenTraps = 2
772

    
773
EOD;
774

    
775
		if (is_array( $config['snmpd']['modules'] )) {
776
		    if(isset($config['snmpd']['modules']['mibii'])) {
777
			$snmpdconf .= <<<EOD
778
begemotSnmpdModulePath."mibII"  = "/usr/lib/snmp_mibII.so"
779

    
780
EOD;
781
		    }
782

    
783
		    if(isset($config['snmpd']['modules']['netgraph'])) {
784
			$snmpdconf .= <<<EOD
785
begemotSnmpdModulePath."netgraph" = "/usr/lib/snmp_netgraph.so"
786
%netgraph
787
begemotNgControlNodeName = "snmpd"
788

    
789
EOD;
790
		    }
791

    
792
		    if(isset($config['snmpd']['modules']['pf'])) {
793
			$snmpdconf .= <<<EOD
794
begemotSnmpdModulePath."pf"     = "/usr/lib/snmp_pf.so"
795

    
796
EOD;
797
		    }
798

    
799
		    if(isset($config['snmpd']['modules']['hostres'])) {
800
			$snmpdconf .= <<<EOD
801
begemotSnmpdModulePath."hostres"     = "/usr/lib/snmp_hostres.so"
802

    
803
EOD;
804
		    }
805
		    if(isset($config['snmpd']['modules']['bridge'])) {
806
			$snmpdconf .= <<<EOD
807
begemotSnmpdModulePath."bridge"     = "/usr/lib/snmp_bridge.so"
808
# config must end with blank line
809

    
810

    
811
EOD;
812
		    }
813
		}
814

    
815
		fwrite($fd, $snmpdconf);
816
		fclose($fd);
817

    
818
		if (isset($config['snmpd']['bindlan'])) {
819
			$bindlan = "";
820
		}
821

    
822
		/* run bsnmpd */
823
		mwexec("/usr/sbin/bsnmpd -c {$g['varetc_path']}/snmpd.conf" .
824
			"{$bindlan} -p {$g['varrun_path']}/snmpd.pid");
825

    
826
		if ($g['booting'])
827
			echo "done.\n";
828
	}
829

    
830
	return 0;
831
}
832

    
833
function services_dnsupdate_process() {
834
	global $config, $g;
835
	if(isset($config['system']['developerspew'])) {
836
		$mt = microtime();
837
		echo "services_dnsupdate_process() being called $mt\n";
838
	}
839

    
840
	/* Dynamic DNS updating active? */
841
	if (is_array($config['dnsupdates']['dnsupdate'])) {
842
		foreach ($config['dnsupdates']['dnsupdate'] as $i => $dnsupdate) {
843
		if (!isset($dyndns['enable']))
844
				continue;
845
			/* determine interface name */
846
			if ($dyndns['interface'] == "wan")
847
				$if = get_real_interface();
848
			else
849
				$if = convert_friendly_interface_to_real_interface_name($dyndns['interface']);
850

    
851
			$wanip = get_interface_ip($if);
852
			if ($wanip) {
853

    
854
				$keyname = $dnsupdate['keyname'];
855
				/* trailing dot */
856
				if (substr($keyname, -1) != ".")
857
					$keyname .= ".";
858

    
859
				$hostname = $dnsupdate['host'];
860
				/* trailing dot */
861
				if (substr($hostname, -1) != ".")
862
					$hostname .= ".";
863

    
864
				/* write private key file
865
				   this is dumb - public and private keys are the same for HMAC-MD5,
866
				   but nsupdate insists on having both */
867
				$fd = fopen("{$g['varetc_path']}/K{$i}{$keyname}+157+00000.private", "w");
868
				$privkey .= <<<EOD
869
Private-key-format: v1.2
870
Algorithm: 157 (HMAC)
871
Key: {$dnsupdate['keydata']}
872

    
873
EOD;
874
				fwrite($fd, $privkey);
875
				fclose($fd);
876

    
877
				/* write public key file */
878
				if ($dnsupdate['keytype'] == "zone") {
879
					$flags = 257;
880
					$proto = 3;
881
				} else if ($dnsupdate['keytype'] == "host") {
882
					$flags = 513;
883
					$proto = 3;
884
				} else if ($dnsupdate['keytype'] == "user") {
885
					$flags = 0;
886
					$proto = 2;
887
				}
888

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

    
893
				/* generate update instructions */
894
				$upinst = "";
895
				if (!empty($dnsupdate['server']))
896
					$upinst .= "server {$dnsupdate['server']}\n";
897
				$upinst .= "update delete {$dnsupdate['host']} A\n";
898
				$upinst .= "update add {$dnsupdate['host']} {$dnsupdate['ttl']} A {$wanip}\n";
899
				$upinst .= "\n";	/* mind that trailing newline! */
900

    
901
				$fd = fopen("{$g['varetc_path']}/nsupdatecmds{$i}", "w");
902
				fwrite($fd, $upinst);
903
				fclose($fd);
904

    
905
				/* invoke nsupdate */
906
				$cmd = "/usr/sbin/nsupdate -k {$g['varetc_path']}/K{$i}{$keyname}+157+00000.key";
907
				if (isset($dnsupdate['usetcp']))
908
					$cmd .= " -v";
909
				$cmd .= " {$g['varetc_path']}/nsupdatecmds{$i}";
910
	
911
				mwexec_bg($cmd);
912
			}
913
		}
914
	}
915

    
916
	return 0;
917
}
918

    
919
function setup_wireless_olsr() {
920
	global $config, $g;
921
	if(!$config['installedpackages']['olsrd'] || !$config['installedpackages'])
922
		return;
923
	if(isset($config['system']['developerspew'])) {
924
		$mt = microtime();
925
		echo "setup_wireless_olsr($interface) being called $mt\n";
926
	}
927
	conf_mount_rw();
928
	foreach($config['installedpackages']['olsrd']['config'] as $olsrd) {
929
		$olsr_enable = $olsrd['enable'];
930
		if($olsr_enable <> "on")
931
			return;
932
		$fd = fopen("{$g['varetc_path']}/olsr.conf", "w");
933

    
934
		if($olsrd['announcedynamicroute'] or $olsrd['enableannounce'] == "on") {
935
			$enableannounce .= "\nHna4\n";
936
			$enableannounce .= "{\n";
937
		if($olsrd['announcedynamicroute'])
938
			$enableannounce .= "\t{$olsrd['announcedynamicroute']}\n";
939
		if($olsrd['enableannounce'] == "on")
940
			$enableannounce .= "0.0.0.0 0.0.0.0";
941
			$enableannounce .= "\n}\n";
942
		} else {
943
			$enableannounce = "";
944
		}
945

    
946
		$olsr .= <<<EODA
947
#
948
# olsr.org OLSR daemon config file
949
#
950
# Lines starting with a # are discarded
951
#
952
# This file was generated by setup_wireless_olsr() in services.inc
953
#
954

    
955
# This file is an example of a typical
956
# configuration for a mostly static
957
# network(regarding mobility) using
958
# the LQ extention
959

    
960
# Debug level(0-9)
961
# If set to 0 the daemon runs in the background
962

    
963
DebugLevel	2
964

    
965
# IP version to use (4 or 6)
966

    
967
IpVersion	4
968

    
969
# Clear the screen each time the internal state changes
970

    
971
ClearScreen     yes
972

    
973
{$enableannounce}
974

    
975
# Should olsrd keep on running even if there are
976
# no interfaces available? This is a good idea
977
# for a PCMCIA/USB hotswap environment.
978
# "yes" OR "no"
979

    
980
AllowNoInt	yes
981

    
982
# TOS(type of service) value for
983
# the IP header of control traffic.
984
# If not set it will default to 16
985

    
986
#TosValue	16
987

    
988
# The fixed willingness to use(0-7)
989
# If not set willingness will be calculated
990
# dynamically based on battery/power status
991
# if such information is available
992

    
993
#Willingness    	4
994

    
995
# Allow processes like the GUI front-end
996
# to connect to the daemon.
997

    
998
IpcConnect
999
{
1000
     # Determines how many simultaneously
1001
     # IPC connections that will be allowed
1002
     # Setting this to 0 disables IPC
1003

    
1004
     MaxConnections  0
1005

    
1006
     # By default only 127.0.0.1 is allowed
1007
     # to connect. Here allowed hosts can
1008
     # be added
1009

    
1010
     Host            127.0.0.1
1011
     #Host            10.0.0.5
1012

    
1013
     # You can also specify entire net-ranges
1014
     # that are allowed to connect. Multiple
1015
     # entries are allowed
1016

    
1017
     #Net             192.168.1.0 255.255.255.0
1018
}
1019

    
1020
# Wether to use hysteresis or not
1021
# Hysteresis adds more robustness to the
1022
# link sensing but delays neighbor registration.
1023
# Used by default. 'yes' or 'no'
1024

    
1025
UseHysteresis	no
1026

    
1027
# Hysteresis parameters
1028
# Do not alter these unless you know
1029
# what you are doing!
1030
# Set to auto by default. Allowed
1031
# values are floating point values
1032
# in the interval 0,1
1033
# THR_LOW must always be lower than
1034
# THR_HIGH.
1035

    
1036
#HystScaling	0.50
1037
#HystThrHigh	0.80
1038
#HystThrLow	0.30
1039

    
1040

    
1041
# Link quality level
1042
# 0 = do not use link quality
1043
# 1 = use link quality for MPR selection
1044
# 2 = use link quality for MPR selection and routing
1045
# Defaults to 0
1046

    
1047
LinkQualityLevel	{$olsrd['enablelqe']}
1048

    
1049
# Link quality window size
1050
# Defaults to 10
1051

    
1052
LinkQualityWinSize	10
1053

    
1054
# Polling rate in seconds(float).
1055
# Default value 0.05 sec
1056

    
1057
Pollrate	0.05
1058

    
1059

    
1060
# TC redundancy
1061
# Specifies how much neighbor info should
1062
# be sent in TC messages
1063
# Possible values are:
1064
# 0 - only send MPR selectors
1065
# 1 - send MPR selectors and MPRs
1066
# 2 - send all neighbors
1067
#
1068
# defaults to 0
1069

    
1070
TcRedundancy	2
1071

    
1072
#
1073
# MPR coverage
1074
# Specifies how many MPRs a node should
1075
# try select to reach every 2 hop neighbor
1076
#
1077
# Can be set to any integer >0
1078
#
1079
# defaults to 1
1080

    
1081
MprCoverage	3
1082

    
1083
# Example plugin entry with parameters:
1084

    
1085
EODA;
1086

    
1087
if($olsrd['enablehttpinfo'] == "on") {
1088
	$olsr .= <<<EODB
1089

    
1090
LoadPlugin "/usr/local/lib/olsrd_httpinfo.so.0.1"
1091
{
1092
    PlParam     "port"   "{$olsrd['port']}"
1093
    PlParam     "Net"    "{$olsrd['allowedhttpinfohost']} {$olsrd['allowedhttpinfosubnet']}"
1094
}
1095

    
1096
EODB;
1097

    
1098
}
1099

    
1100
if($olsrd['enabledsecure'] == "on") {
1101
	$olsr .= <<<EODC
1102

    
1103
LoadPlugin "/usr/local/lib/olsrd_secure.so.0.5"
1104
{
1105
    PlParam     "Keyfile"   "/usr/local/etc/olsrkey.txt"
1106
}
1107

    
1108
EODC;
1109

    
1110
}
1111

    
1112
if($olsrd['enabledyngw'] == "on") {
1113

    
1114
	/* unset default route, olsr auto negotiates */
1115
	mwexec("/sbin/route delete default");
1116

    
1117
	$olsr .= <<<EODE
1118

    
1119
LoadPlugin "/usr/local/lib/olsrd_dyn_gw.so.0.4"
1120
{
1121
    # how often to look for a inet gw, in seconds
1122
    # defaults to 5 secs, if commented out
1123
    PlParam     "Interval"   "{$olsrd['polling']}"
1124

    
1125
    # if one or more IPv4 addresses are given, do a ping on these in
1126
    # descending order to validate that there is not only an entry in
1127
    # routing table, but also a real internet connection. If any of
1128
    # these addresses could be pinged successfully, the test was
1129
    # succesful, i.e. if the ping on the 1st address was successful,the
1130
    # 2nd won't be pinged
1131
    PlParam     "Ping"       "{$olsrd['ping']}"
1132
    #PlParam     "HNA"   "192.168.81.0 255.255.255.0"
1133
}
1134

    
1135
EODE;
1136

    
1137
}
1138

    
1139
foreach($config['installedpackages']['olsrd']['config'] as $conf) {
1140
	$interfaces = explode(',', $conf['iface_array']);
1141
	foreach($interfaces as $interface) {
1142
		$realinterface = convert_friendly_interface_to_real_interface_name($interface);
1143
$olsr .= <<<EODAD
1144
Interface "{$realinterface}"
1145
{
1146

    
1147
    # Hello interval in seconds(float)
1148
    HelloInterval    2.0
1149

    
1150
    # HELLO validity time
1151
    HelloValidityTime	20.0
1152

    
1153
    # TC interval in seconds(float)
1154
    TcInterval        5.0
1155

    
1156
    # TC validity time
1157
    TcValidityTime	30.0
1158

    
1159
    # MID interval in seconds(float)
1160
    MidInterval	5.0
1161

    
1162
    # MID validity time
1163
    MidValidityTime	30.0
1164

    
1165
    # HNA interval in seconds(float)
1166
    HnaInterval	5.0
1167

    
1168
    # HNA validity time
1169
    HnaValidityTime 	30.0
1170

    
1171
    # When multiple links exist between hosts
1172
    # the weight of interface is used to determine
1173
    # the link to use. Normally the weight is
1174
    # automatically calculated by olsrd based
1175
    # on the characteristics of the interface,
1176
    # but here you can specify a fixed value.
1177
    # Olsrd will choose links with the lowest value.
1178

    
1179
    # Weight 0
1180

    
1181

    
1182
}
1183

    
1184
EODAD;
1185

    
1186
	}
1187
	break;
1188
}
1189
		fwrite($fd, $olsr);
1190
		fclose($fd);
1191
	}
1192

    
1193
	if(is_process_running("olsrd"))
1194
		mwexec("/usr/bin/killall olsrd", true);
1195

    
1196
	sleep(2);
1197

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

    
1200
	conf_mount_ro();
1201
}
1202

    
1203
/* configure cron service */
1204
function configure_cron() {
1205
	global $g, $config;
1206
	conf_mount_rw();
1207
	/* preserve existing crontab entries */
1208
	$crontab_contents = file_get_contents("/etc/crontab");
1209
	$crontab_contents_a = split("\n", $crontab_contents);
1210
	
1211
	for ($i = 0; $i < count($crontab_contents_a); $i++) {
1212
		$item =& $crontab_contents_a[$i];
1213
		if (strpos($item, "# pfSense specific crontab entries") !== false) {
1214
			array_splice($crontab_contents_a, $i - 1);
1215
			break;
1216
		}
1217
	}
1218
	$crontab_contents = implode("\n", $crontab_contents_a) . "\n";
1219
	
1220
	
1221
	if (is_array($config['cron']['item'])) {
1222
		$crontab_contents .= "#\n";
1223
		$crontab_contents .= "# pfSense specific crontab entries\n";
1224
		$crontab_contents .= "# Created: " . date("F j, Y, g:i a") . "\n";
1225
		$crontab_contents .= "#\n";
1226

    
1227
		foreach ($config['cron']['item'] as $item) {
1228
			$crontab_contents .= "\n{$item['minute']}\t";
1229
			$crontab_contents .= "{$item['hour']}\t";
1230
			$crontab_contents .= "{$item['mday']}\t";
1231
			$crontab_contents .= "{$item['month']}\t";
1232
			$crontab_contents .= "{$item['wday']}\t";
1233
			$crontab_contents .= "{$item['who']}\t";
1234
			$crontab_contents .= "{$item['command']}";
1235
		}
1236
    
1237
		$crontab_contents .= "\n#\n";
1238
		$crontab_contents .= "# If possible do not add items to this file manually.\n";
1239
		$crontab_contents .= "# If you do so, this file must be terminated with a blank line (e.g. new line)\n";
1240
		$crontab_contents .= "#\n\n";
1241
	}
1242
	
1243
	/* please maintain the newline at the end of file */
1244
	file_put_contents("/etc/crontab", $crontab_contents);
1245
	
1246
	if (!$g['booting'])
1247
		conf_mount_ro();
1248
}
1249

    
1250
function upnp_action ($action) {
1251
	switch($action) {
1252
		case "start":
1253
			if(file_exists('/var/etc/miniupnpd.conf'))
1254
				mwexec_bg('/usr/local/sbin/miniupnpd -f /var/etc/miniupnpd.conf');
1255
			break;
1256
		case "stop":
1257
			while((int)exec("pgrep miniupnpd | wc -l") > 0)
1258
				mwexec('killall miniupnpd 2>/dev/null', true);
1259
			mwexec('/sbin/pfctl -aminiupnpd -Fr 2>&1 >/dev/null');
1260
			mwexec('/sbin/pfctl -aminiupnpd -Fn 2>&1 >/dev/null');
1261
			break;
1262
		case "restart":
1263
			upnp_action('stop');
1264
			upnp_action('start');
1265
			break;
1266
	}
1267
}
1268

    
1269
function upnp_start() {
1270
	global $config, $g;
1271
	if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
1272
		if($g['booting']) {
1273
			echo "Starting UPnP service... ";
1274
			include('/usr/local/pkg/miniupnpd.inc');
1275
			sync_package_miniupnpd();
1276
			echo "done.\n";
1277
		}
1278
		else {
1279
			upnp_action('start');
1280
		}
1281
	}
1282
}
1283

    
1284
?>
(36-36/50)