Project

General

Profile

Download (18.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	interfaces.inc
4
	Copyright (C) 2004 Scott Ullrich
5
	All rights reserved.
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
/* include all configuration functions */
34
require_once("functions.inc");
35

    
36
function interfaces_loopback_configure() {
37
	global $config, $g;
38

    
39
	mwexec("/sbin/ifconfig lo0 127.0.0.1");
40

    
41
	return 0;
42
}
43

    
44
function interfaces_vlan_configure() {
45
	global $config, $g;
46

    
47
	if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
48

    
49
		/* load the VLAN module */
50
		mwexec("/sbin/kldload if_vlan");
51

    
52
		/* devices with native VLAN support */
53
		$vlan_native_supp = explode(" ", "bge em gx nge ti txp");
54

    
55
		/* devices with long frame support */
56
		$vlan_long_supp = explode(" ", "dc fxp sis ste tl tx xl");
57

    
58
		$i = 0;
59

    
60
		foreach ($config['vlans']['vlan'] as $vlan) {
61

    
62
			$cmd = "/sbin/ifconfig vlan{$i} create vlan " .
63
				escapeshellarg($vlan['tag']) . " vlandev " .
64
				escapeshellarg($vlan['if']);
65

    
66
			/* get driver name */
67
			for ($j = 0; $j < strlen($vlan['if']); $j++) {
68
				if ($vlan['if'][$j] >= '0' && $vlan['if'][$j] <= '9')
69
					break;
70
			}
71
			$drvname = substr($vlan['if'], 0, $j);
72

    
73
			if (in_array($drvname, $vlan_native_supp))
74
				$cmd .= " link0";
75
			else if (in_array($drvname, $vlan_long_supp))
76
				$cmd .= " mtu 1500";
77

    
78
			mwexec($cmd);
79

    
80
			/* make sure the parent interface is up */
81
			mwexec("/sbin/ifconfig " . escapeshellarg($vlan['if']) . " up");
82

    
83
			$i++;
84
		}
85
	}
86

    
87
	return 0;
88
}
89

    
90
function interfaces_lan_configure() {
91
	global $config, $g;
92

    
93
	if ($g['booting'])
94
		echo "Configuring LAN interface... ";
95

    
96
	$lancfg = $config['interfaces']['lan'];
97

    
98
	/* wireless configuration? */
99
	if (is_array($lancfg['wireless']))
100
		interfaces_wireless_configure($lancfg['if'], $lancfg['wireless']);
101

    
102
	/* MAC spoofing? */
103
	if ($lancfg['spoofmac'])
104
		mwexec("/sbin/ifconfig " . escapeshellarg($lancfg['if']) .
105
			" link " . escapeshellarg($lancfg['spoofmac']));
106

    
107
	/* media */
108
	if ($lancfg['media'] || $lancfg['mediaopt']) {
109
		$cmd = "/sbin/ifconfig " . escapeshellarg($lancfg['if']);
110
		if ($lancfg['media'])
111
			$cmd .= " media " . escapeshellarg($lancfg['media']);
112
		if ($lancfg['mediaopt'])
113
			$cmd .= " mediaopt " . escapeshellarg($lancfg['mediaopt']);
114
		mwexec($cmd);
115
	}
116

    
117
	mwexec("/sbin/ifconfig " . escapeshellarg($lancfg['if']) . " " .
118
		escapeshellarg($lancfg['ipaddr'] . "/" . $lancfg['subnet']));
119

    
120
	if (!$g['booting']) {
121
		/* make new hosts file */
122
		system_hosts_generate();
123

    
124
		/* reconfigure static routes (kernel may have deleted them) */
125
		system_routing_configure();
126

    
127
		/* reload ipfilter (address may have changed) */
128
		filter_configure();
129

    
130
		/* reload IPsec tunnels */
131
		vpn_ipsec_configure();
132

    
133
		/* reload dhcpd (gateway may have changed) */
134
		services_dhcpd_configure();
135

    
136
		/* reload dnsmasq */
137
		services_dnsmasq_configure();
138

    
139
		/* reload webgui */
140
		system_webgui_start();
141

    
142
		/* reload captive portal */
143
		captiveportal_configure();
144
	}
145

    
146
	enable_hardware_offloading($lancfg['if']);
147

    
148
	if ($g['booting'])
149
		echo "done\n";
150

    
151
	return 0;
152
}
153

    
154
function interfaces_optional_configure() {
155
	global $config, $g;
156
	global $bridgeconfig;
157

    
158
	/* Reset bridge configuration.	Interfaces will add to it. */
159
	$bridgeconfig = "";
160

    
161
	for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
162
		interfaces_optional_configure_if($i);
163
	}
164

    
165
	if ($bridgeconfig) {
166
		/* Set the system bridge configuration and enable bridging. */
167
		mwexec("/sbin/sysctl net.link.ether.bridge_cfg=" . $bridgeconfig);
168

    
169
		if (isset($config['bridge']['filteringbridge']))
170
			mwexec("/sbin/sysctl net.link.ether.bridge.pf=1");
171

    
172
		mwexec("/sbin/sysctl net.link.ether.bridge=1");
173
	} else {
174
		mwexec("/sbin/sysctl net.link.ether.bridge.pf=0");
175
		mwexec("/sbin/sysctl net.link.ether.bridge=0");
176
	}
177

    
178
	if (!$g['booting']) {
179
		/* reconfigure static routes (kernel may have deleted them) */
180
		system_routing_configure();
181

    
182
		/* reload ipfilter (address may have changed) */
183
		filter_configure();
184

    
185
		/* reload IPsec tunnels */
186
		vpn_ipsec_configure();
187

    
188
		/* reload dhcpd (interface enabled/disabled/bridged status may have changed) */
189
		services_dhcpd_configure();
190

    
191
		/* restart dnsmasq */
192
		services_dnsmasq_configure();
193
	}
194

    
195
	return 0;
196
}
197

    
198
function interfaces_optional_configure_if($opti) {
199
	global $config, $g;
200
	global $bridgeconfig;
201

    
202
	$optcfg = $config['interfaces']['opt' . $opti];
203

    
204
	if ($g['booting']) {
205
		$optdescr = "";
206
		if ($optcfg['descr'])
207
			$optdescr = " ({$optcfg['descr']})";
208
		echo "Configuring OPT{$opti}{$optdescr} interface... ";
209
	}
210

    
211
	if (isset($optcfg['enable'])) {
212
		/* wireless configuration? */
213
		if (is_array($optcfg['wireless']))
214
			interfaces_wireless_configure($optcfg['if'], $optcfg['wireless']);
215

    
216
		/* MAC spoofing? */
217
		if ($optcfg['spoofmac'])
218
			mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) .
219
				" link " . escapeshellarg($optcfg['spoofmac']));
220

    
221
		/* media */
222
		if ($optcfg['media'] || $optcfg['mediaopt']) {
223
			$cmd = "/sbin/ifconfig " . escapeshellarg($optcfg['if']);
224
			if ($optcfg['media'])
225
				$cmd .= " media " . escapeshellarg($optcfg['media']);
226
			if ($optcfg['mediaopt'])
227
				$cmd .= " mediaopt " . escapeshellarg($optcfg['mediaopt']);
228
			mwexec($cmd);
229
		}
230

    
231
		/* OpenVPN configuration? */
232
 		if (isset($optcfg['ovpn'])) {
233
 			if (strstr($if, "tap"))
234
 				ovpn_link_tap();
235
 		}
236

    
237
		/* bridged? */
238
		if ($optcfg['bridge']) {
239
			mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) .
240
				" delete up");
241

    
242
			if ($bridgeconfig != "")
243
				$bridgeconfig .= ",";
244

    
245
			$bridgeconfig .= $optcfg['if'] . ":" . $opti . "," .
246
				$config['interfaces'][$optcfg['bridge']]['if'] .
247
				":" . $opti;
248
		} else {
249
			mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) . " " .
250
				escapeshellarg($optcfg['ipaddr'] . "/" . $optcfg['subnet']));
251
		}
252
	} else {
253
		mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) .
254
			" delete down");
255
	}
256

    
257
	enable_hardware_offloading(escapeshellarg($optcfg['if']));
258

    
259
	if ($g['booting'])
260
		echo "done\n";
261

    
262
	return 0;
263
}
264

    
265
function interfaces_wireless_configure($if, $wlcfg) {
266
	global $config, $g;
267

    
268
	/* wireless configuration */
269
	$ifcargs = escapeshellarg($if) .
270
		" ssid " . escapeshellarg($wlcfg['ssid']) . " channel " .
271
		escapeshellarg($wlcfg['channel']) . " ";
272

    
273
	if ($wlcfg['stationname'])
274
		$ifcargs .= "stationname " . escapeshellarg($wlcfg['stationname']) . " ";
275

    
276
	if (isset($wlcfg['wep']['enable']) && is_array($wlcfg['wep']['key'])) {
277
		$ifcargs .= "wepmode on ";
278

    
279
		$i = 1;
280
		foreach ($wlcfg['wep']['key'] as $wepkey) {
281
			$ifcargs .= "wepkey " . escapeshellarg("{$i}:{$wepkey['value']}") . " ";
282
			if (isset($wepkey['txkey'])) {
283
				$ifcargs .= "weptxkey {$i} ";
284
			}
285
			$i++;
286
		}
287
	} else {
288
		$ifcargs .= "wepmode off ";
289
	}
290

    
291
	switch ($wlcfg['mode']) {
292
		case 'hostap':
293
			if (strstr($if, "wi"))
294
				$ifcargs .= "-mediaopt ibss mediaopt hostap ";
295
			break;
296
		case 'ibss':
297
		case 'IBSS':
298
			if (strstr($if, "wi"))
299
				$ifcargs .= "-mediaopt hostap mediaopt ibss ";
300
			else if (strstr($if, "an"))
301
				$ifcargs .= "mediaopt adhoc ";
302
			break;
303
		case 'bss':
304
		case 'BSS':
305
			if (strstr($if, "wi"))
306
				$ifcargs .= "-mediaopt hostap -mediaopt ibss ";
307
			else if (strstr($if, "an"))
308
				$ifcargs .= "-mediaopt adhoc ";
309
			break;
310
	}
311

    
312
	$ifcargs .= "up";
313

    
314
	mwexec("/sbin/ifconfig " . $ifcargs);
315

    
316
	return 0;
317
}
318

    
319
function interfaces_wan_configure() {
320
	global $config, $g;
321

    
322
	$wancfg = $config['interfaces']['wan'];
323

    
324
	if ($g['booting'])
325
		echo "Configuring WAN interface... ";
326
	else {
327
		/* kill dhclient */
328
		killbypid("{$g['varrun_path']}/dhclient.pid");
329

    
330
		/* kill PPPoE client (mpd) */
331
		killbypid("{$g['varrun_path']}/mpd.pid");
332

    
333
		/* wait for processes to die */
334
		sleep(2);
335

    
336
		unlink_if_exists("{$g['varetc_path']}/dhclient.conf");
337
		unlink_if_exists("{$g['varetc_path']}/mpd.conf");
338
		unlink_if_exists("{$g['varetc_path']}/mpd.links");
339
		unlink_if_exists("{$g['vardb_path']}/wanip");
340
		unlink_if_exists("{$g['varetc_path']}/nameservers.conf");
341

    
342
	}
343

    
344
	/* remove all addresses first */
345
	while (mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " -alias") == 0);
346
	mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " down");
347

    
348
	/* wireless configuration? */
349
	if (is_array($wancfg['wireless']))
350
		interfaces_wireless_configure($wancfg['if'], $wancfg['wireless']);
351

    
352
	if ($wancfg['spoofmac'])
353
		mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) .
354
			" link " . escapeshellarg($wancfg['spoofmac']));
355

    
356
	/* media */
357
	if ($wancfg['media'] || $wancfg['mediaopt']) {
358
		$cmd = "/sbin/ifconfig " . escapeshellarg($wancfg['if']);
359
		if ($wancfg['media'])
360
			$cmd .= " media " . escapeshellarg($wancfg['media']);
361
		if ($wancfg['mediaopt'])
362
			$cmd .= " mediaopt " . escapeshellarg($wancfg['mediaopt']);
363
		mwexec($cmd);
364
	}
365

    
366
	switch ($wancfg['ipaddr']) {
367

    
368
		case 'dhcp':
369
			interfaces_wan_dhcp_configure();
370
			break;
371

    
372
		case 'pppoe':
373
			interfaces_wan_pppoe_configure();
374
			break;
375

    
376
		case 'pptp':
377
			interfaces_wan_pptp_configure();
378
			break;
379

    
380
		case 'bigpond':
381
			/* just configure DHCP for now; fire up bpalogin when we've got the lease */
382
			interfaces_wan_dhcp_configure();
383
			break;
384

    
385
		default:
386
			if (isset($wancfg['ispointtopoint']) && $wancfg['pointtopoint']) {
387
				mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " " .
388
					escapeshellarg($wancfg['ipaddr'] . "/" . $wancfg['subnet']) .
389
					" " . escapeshellarg($wancfg['pointtopoint']) . " up");
390
			} else {
391
				mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " " .
392
					escapeshellarg($wancfg['ipaddr'] . "/" . $wancfg['subnet']));
393
			}
394
			/* install default route */
395
			mwexec("/sbin/route delete default");
396
			mwexec("/sbin/route add default " . escapeshellarg($wancfg['gateway']));
397

    
398
			/* resync ipfilter (done automatically for DHCP/PPPoE/PPTP) */
399
			filter_resync();
400
	}
401

    
402
	if (!$g['booting']) {
403
		/* reconfigure static routes (kernel may have deleted them) */
404
		system_routing_configure();
405

    
406
		/* reload ipfilter */
407
		filter_configure();
408

    
409
		/* reload ipsec tunnels */
410
		vpn_ipsec_configure();
411

    
412
		/* restart ez-ipupdate */
413
		services_dyndns_configure();
414

    
415
		/* force DNS update */
416
		services_dnsupdate_process();
417

    
418
		/* restart dnsmasq */
419
		services_dnsmasq_configure();
420
	}
421

    
422
	enable_hardware_offloading($wancfg['if']);
423

    
424
	if ($g['booting'])
425
		echo "done\n";
426

    
427
	return 0;
428
}
429

    
430
function interfaces_wan_dhcp_configure() {
431
	global $config, $g;
432

    
433
	$wancfg = $config['interfaces']['wan'];
434

    
435
	/* generate dhclient.conf */
436
	$fd = fopen("{$g['varetc_path']}/dhclient.conf", "w");
437
	if (!$fd) {
438
		printf("Error: cannot open dhclient.conf in interfaces_wan_dhcp_configure().\n");
439
		return 1;
440
	}
441

    
442
 	$dhclientconf = "";
443

    
444
 	if ($wancfg['dhcphostname']) {
445
		$dhclientconf .= <<<EOD
446
send dhcp-client-identifier "{$wancfg['dhcphostname']}";
447
interface "{$wancfg['if']}" {
448
	send host-name "{$wancfg['dhcphostname']}";
449
}
450

    
451
EOD;
452
	}
453

    
454
	fwrite($fd, $dhclientconf);
455
	fclose($fd);
456

    
457
	/* fire up dhclient - don't wait for the lease (-nw) */
458
	mwexec("/sbin/dhclient -nw -cf {$g['varetc_path']}/dhclient.conf " .
459
		escapeshellarg($wancfg['if']) . " &");
460

    
461
	return 0;
462
}
463

    
464
function interfaces_wan_dhcp_down() {
465
	mwexec("/sbin/dhclient -r");
466
	sleep(3);
467
}
468

    
469
function interfaces_wan_dhcp_up() {
470
	interfaces_wan_dhcp_configure();
471
	sleep(3);
472
}
473

    
474
function interfaces_wan_pppoe_configure() {
475
	global $config, $g;
476

    
477
	$wancfg = $config['interfaces']['wan'];
478
	$pppoecfg = $config['pppoe'];
479

    
480
	/* generate mpd.conf */
481
	$fd = fopen("{$g['varetc_path']}/mpd.conf", "w");
482
	if (!$fd) {
483
		printf("Error: cannot open mpd.conf in interfaces_wan_pppoe_configure().\n");
484
		return 1;
485
	}
486

    
487
	$idle = 0;
488

    
489
	if (isset($pppoecfg['ondemand'])) {
490
		$ondemand = "enable";
491
		if ($pppoecfg['timeout'])
492
			$idle = $pppoecfg['timeout'];
493
	} else {
494
		$ondemand = "disable";
495
	}
496

    
497
	$mpdconf = <<<EOD
498
pppoe:
499
	new -i ng0 pppoe pppoe
500
	set iface route default
501
	set iface {$ondemand} on-demand
502
	set iface idle {$idle}
503
	set iface up-script /usr/local/sbin/ppp-linkup
504

    
505
EOD;
506

    
507
	if (isset($pppoecfg['ondemand'])) {
508
		$mpdconf .= <<<EOD
509
	set iface addrs 10.0.0.1 10.0.0.2
510

    
511
EOD;
512
	}
513

    
514
	$mpdconf .= <<<EOD
515
	set bundle disable multilink
516
	set bundle authname "{$pppoecfg['username']}"
517
	set bundle password "{$pppoecfg['password']}"
518
	set link keep-alive 10 60
519
	set link max-redial 0
520
	set link no acfcomp protocomp
521
	set link disable pap chap
522
	set link accept chap
523
	set link mtu 1492
524
	set ipcp yes vjcomp
525
	set ipcp ranges 0.0.0.0/0 0.0.0.0/0
526

    
527
EOD;
528

    
529
	if (isset($config['system']['dnsallowoverride'])) {
530
		$mpdconf .= <<<EOD
531
	set ipcp enable req-pri-dns
532
	set ipcp enable req-sec-dns
533

    
534
EOD;
535
	}
536

    
537
	$mpdconf .= <<<EOD
538
	open iface
539

    
540
EOD;
541

    
542
	fwrite($fd, $mpdconf);
543
	fclose($fd);
544

    
545
	/* generate mpd.links */
546
	$fd = fopen("{$g['varetc_path']}/mpd.links", "w");
547
	if (!$fd) {
548
		printf("Error: cannot open mpd.links in interfaces_wan_pppoe_configure().\n");
549
		return 1;
550
	}
551

    
552
	$mpdconf = <<<EOD
553
pppoe:
554
	set link type pppoe
555
	set pppoe iface {$wancfg['if']}
556
	set pppoe service "{$pppoecfg['provider']}"
557
	set pppoe enable originate
558
	set pppoe disable incoming
559

    
560
EOD;
561

    
562
	fwrite($fd, $mpdconf);
563
	fclose($fd);
564

    
565
	/* fire up mpd */
566
	mwexec("/usr/local/sbin/mpd -b -d {$g['varetc_path']} -p {$g['varrun_path']}/mpd.pid pppoe");
567

    
568
	return 0;
569
}
570

    
571
function interfaces_wan_pppoe_down() {
572
	global $g;
573
	sigkillbypid("{$g['varrun_path']}/mpd.pid", "SIGUSR2");
574
	sleep(3);
575
}
576

    
577
function interfaces_wan_pppoe_up() {
578
	global $g;
579
	sigkillbypid("{$g['varrun_path']}/mpd.pid", "SIGUSR1");
580
	sleep(3);
581
}
582

    
583
function interfaces_wan_pptp_configure() {
584
	global $config, $g;
585

    
586
	$wancfg = $config['interfaces']['wan'];
587
	$pptpcfg = $config['pptp'];
588

    
589
	/* generate mpd.conf */
590
	$fd = fopen("{$g['varetc_path']}/mpd.conf", "w");
591
	if (!$fd) {
592
		printf("Error: cannot open mpd.conf in interfaces_wan_pptp_configure().\n");
593
		return 1;
594
	}
595

    
596
	$idle = 0;
597

    
598
	if (isset($pptpcfg['ondemand'])) {
599
		$ondemand = "enable";
600
		if ($pptpcfg['timeout'])
601
			$idle = $pptpcfg['timeout'];
602
	} else {
603
		$ondemand = "disable";
604
	}
605

    
606
	$mpdconf = <<<EOD
607
pptp:
608
	new -i ng0 pptp pptp
609
	set iface route default
610
	set iface {$ondemand} on-demand
611
	set iface idle {$idle}
612
	set iface up-script /usr/local/sbin/ppp-linkup
613

    
614
EOD;
615

    
616
	if (isset($pptpcfg['ondemand'])) {
617
		$mpdconf .= <<<EOD
618
	set iface addrs 10.0.0.1 10.0.0.2
619

    
620
EOD;
621
	}
622

    
623
	$mpdconf .= <<<EOD
624
	set bundle disable multilink
625
	set bundle authname "{$pptpcfg['username']}"
626
	set bundle password "{$pptpcfg['password']}"
627
	set link keep-alive 10 60
628
	set link max-redial 0
629
	set link no acfcomp protocomp
630
	set link disable pap chap
631
	set link accept chap
632
	set ipcp no vjcomp
633
	set ipcp ranges 0.0.0.0/0 0.0.0.0/0
634

    
635
EOD;
636

    
637
	if (isset($config['system']['dnsallowoverride'])) {
638
		$mpdconf .= <<<EOD
639
	set ipcp enable req-pri-dns
640
	set ipcp enable req-sec-dns
641

    
642
EOD;
643
	}
644

    
645
	$mpdconf .= <<<EOD
646
	open
647

    
648
EOD;
649

    
650
	fwrite($fd, $mpdconf);
651
	fclose($fd);
652

    
653
	/* generate mpd.links */
654
	$fd = fopen("{$g['varetc_path']}/mpd.links", "w");
655
	if (!$fd) {
656
		printf("Error: cannot open mpd.links in interfaces_wan_pptp_configure().\n");
657
		return 1;
658
	}
659

    
660
	$mpdconf = <<<EOD
661
pptp:
662
	set link type pptp
663
	set pptp enable originate outcall
664
	set pptp disable windowing
665
	set pptp self {$pptpcfg['local']}
666
	set pptp peer {$pptpcfg['remote']}
667

    
668
EOD;
669

    
670
	fwrite($fd, $mpdconf);
671
	fclose($fd);
672

    
673
	/* configure interface */
674
	mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " " .
675
		escapeshellarg($pptpcfg['local'] . "/" . $pptpcfg['subnet']));
676

    
677
	/* fire up mpd */
678
	mwexec("/usr/local/sbin/mpd -b -d {$g['varetc_path']} -p {$g['varrun_path']}/mpd.pid pptp");
679

    
680
	return 0;
681
}
682

    
683
function interfaces_wan_pptp_down() {
684
	global $g;
685
	sigkillbypid("{$g['varrun_path']}/mpd.pid", "SIGUSR2");
686
	sleep(3);
687
}
688

    
689
function interfaces_wan_pptp_up() {
690
	global $g;
691
	sigkillbypid("{$g['varrun_path']}/mpd.pid", "SIGUSR1");
692
	sleep(3);
693
}
694

    
695
function interfaces_wan_bigpond_configure($curwanip) {
696
	global $config, $g;
697

    
698
	$bpcfg = $config['bigpond'];
699

    
700
	if (!$curwanip) {
701
		/* IP address not configured yet, exit */
702
		return 0;
703
	}
704

    
705
	/* kill bpalogin */
706
	killbyname("bpalogin");
707

    
708
	/* wait a moment */
709
	sleep(1);
710

    
711
	/* get the default domain */
712
	$nfd = @fopen("{$g['varetc_path']}/defaultdomain.conf", "r");
713
	if ($nfd) {
714
		$defaultdomain = trim(fgets($nfd));
715
		fclose($nfd);
716
	}
717

    
718
	/* generate bpalogin.conf */
719
	$fd = fopen("{$g['varetc_path']}/bpalogin.conf", "w");
720
	if (!$fd) {
721
		printf("Error: cannot open bpalogin.conf in interfaces_wan_bigpond_configure().\n");
722
		return 1;
723
	}
724

    
725
	if (!$bpcfg['authserver'])
726
		$bpcfg['authserver'] = "dce-server";
727
	if (!$bpcfg['authdomain'])
728
		$bpcfg['authdomain'] = $defaultdomain;
729

    
730
	$bpconf = <<<EOD
731
username {$bpcfg['username']}
732
password {$bpcfg['password']}
733
authserver {$bpcfg['authserver']}
734
authdomain {$bpcfg['authdomain']}
735
localport 5050
736

    
737
EOD;
738

    
739
	if ($bpcfg['minheartbeatinterval'])
740
		$bpconf .= "minheartbeatinterval {$bpcfg['minheartbeatinterval']}\n";
741

    
742
	fwrite($fd, $bpconf);
743
	fclose($fd);
744

    
745
	/* fire up bpalogin */
746
	mwexec("/usr/local/sbin/bpalogin -c {$g['varetc_path']}/bpalogin.conf");
747

    
748
	return 0;
749
}
750

    
751
function get_real_wan_interface() {
752
	global $config, $g;
753

    
754
	$wancfg = $config['interfaces']['wan'];
755

    
756
	$wanif = $wancfg['if'];
757
	if (($wancfg['ipaddr'] == "pppoe") || ($wancfg['ipaddr'] == "pptp")) {
758
		$wanif = $g['pppoe_interface'];
759
	}
760

    
761
	return $wanif;
762
}
763

    
764
function get_current_wan_address() {
765
	global $config, $g;
766

    
767
	$wancfg = $config['interfaces']['wan'];
768

    
769
	if (in_array($wancfg['ipaddr'], array('pppoe','dhcp','pptp','bigpond'))) {
770
		/* dynamic WAN IP address, find out which one */
771
		$wanif = get_real_wan_interface();
772

    
773
		/* get interface info with netstat */
774
		exec("/usr/bin/netstat -nWI " . escapeshellarg($wanif) . " -f inet", $ifinfo);
775

    
776
		if (isset($ifinfo[1])) {
777
			$aif = preg_split("/\s+/", $ifinfo[1]);
778
			$curwanip = chop($aif[3]);
779

    
780
			if ($curwanip && is_ipaddr($curwanip) && ($curwanip != "0.0.0.0"))
781
				return $curwanip;
782
		}
783

    
784
		return null;
785
	} else {
786
		/* static WAN IP address */
787
		return $wancfg['ipaddr'];
788
	}
789
}
790

    
791
?>
(6-6/14)