1 |
5b237745
|
Scott Ullrich
|
<?php
|
2 |
|
|
/*
|
3 |
|
|
interfaces.inc
|
4 |
cfc707f7
|
Scott Ullrich
|
Copyright (C) 2004 Scott Ullrich
|
5 |
|
|
All rights reserved.
|
6 |
|
|
|
7 |
|
|
originally part of m0n0wall (http://m0n0.ch/wall)
|
8 |
5b237745
|
Scott Ullrich
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
9 |
|
|
All rights reserved.
|
10 |
cfc707f7
|
Scott Ullrich
|
|
11 |
5b237745
|
Scott Ullrich
|
Redistribution and use in source and binary forms, with or without
|
12 |
|
|
modification, are permitted provided that the following conditions are met:
|
13 |
cfc707f7
|
Scott Ullrich
|
|
14 |
5b237745
|
Scott Ullrich
|
1. Redistributions of source code must retain the above copyright notice,
|
15 |
|
|
this list of conditions and the following disclaimer.
|
16 |
cfc707f7
|
Scott Ullrich
|
|
17 |
5b237745
|
Scott Ullrich
|
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 |
cfc707f7
|
Scott Ullrich
|
|
21 |
5b237745
|
Scott Ullrich
|
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 |
cfc707f7
|
Scott Ullrich
|
|
41 |
5b237745
|
Scott Ullrich
|
return 0;
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
function interfaces_vlan_configure() {
|
45 |
|
|
global $config, $g;
|
46 |
cfc707f7
|
Scott Ullrich
|
|
47 |
5b237745
|
Scott Ullrich
|
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
|
48 |
cfc707f7
|
Scott Ullrich
|
|
49 |
5b237745
|
Scott Ullrich
|
/* load the VLAN module */
|
50 |
|
|
mwexec("/sbin/kldload if_vlan");
|
51 |
cfc707f7
|
Scott Ullrich
|
|
52 |
5b237745
|
Scott Ullrich
|
/* devices with native VLAN support */
|
53 |
|
|
$vlan_native_supp = explode(" ", "bge em gx nge ti txp");
|
54 |
cfc707f7
|
Scott Ullrich
|
|
55 |
5b237745
|
Scott Ullrich
|
/* devices with long frame support */
|
56 |
|
|
$vlan_long_supp = explode(" ", "dc fxp sis ste tl tx xl");
|
57 |
cfc707f7
|
Scott Ullrich
|
|
58 |
5b237745
|
Scott Ullrich
|
$i = 0;
|
59 |
cfc707f7
|
Scott Ullrich
|
|
60 |
5b237745
|
Scott Ullrich
|
foreach ($config['vlans']['vlan'] as $vlan) {
|
61 |
cfc707f7
|
Scott Ullrich
|
|
62 |
|
|
$cmd = "/sbin/ifconfig vlan{$i} create vlan " .
|
63 |
|
|
escapeshellarg($vlan['tag']) . " vlandev " .
|
64 |
5b237745
|
Scott Ullrich
|
escapeshellarg($vlan['if']);
|
65 |
cfc707f7
|
Scott Ullrich
|
|
66 |
5b237745
|
Scott Ullrich
|
/* 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 |
cfc707f7
|
Scott Ullrich
|
|
73 |
5b237745
|
Scott Ullrich
|
if (in_array($drvname, $vlan_native_supp))
|
74 |
|
|
$cmd .= " link0";
|
75 |
|
|
else if (in_array($drvname, $vlan_long_supp))
|
76 |
|
|
$cmd .= " mtu 1500";
|
77 |
cfc707f7
|
Scott Ullrich
|
|
78 |
5b237745
|
Scott Ullrich
|
mwexec($cmd);
|
79 |
cfc707f7
|
Scott Ullrich
|
|
80 |
5b237745
|
Scott Ullrich
|
/* make sure the parent interface is up */
|
81 |
|
|
mwexec("/sbin/ifconfig " . escapeshellarg($vlan['if']) . " up");
|
82 |
cfc707f7
|
Scott Ullrich
|
|
83 |
5b237745
|
Scott Ullrich
|
$i++;
|
84 |
|
|
}
|
85 |
|
|
}
|
86 |
cfc707f7
|
Scott Ullrich
|
|
87 |
5b237745
|
Scott Ullrich
|
return 0;
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
function interfaces_lan_configure() {
|
91 |
|
|
global $config, $g;
|
92 |
cfc707f7
|
Scott Ullrich
|
|
93 |
5b237745
|
Scott Ullrich
|
if ($g['booting'])
|
94 |
|
|
echo "Configuring LAN interface... ";
|
95 |
cfc707f7
|
Scott Ullrich
|
|
96 |
5b237745
|
Scott Ullrich
|
$lancfg = $config['interfaces']['lan'];
|
97 |
cfc707f7
|
Scott Ullrich
|
|
98 |
5b237745
|
Scott Ullrich
|
/* wireless configuration? */
|
99 |
|
|
if (is_array($lancfg['wireless']))
|
100 |
|
|
interfaces_wireless_configure($lancfg['if'], $lancfg['wireless']);
|
101 |
cfc707f7
|
Scott Ullrich
|
|
102 |
5b237745
|
Scott Ullrich
|
/* MAC spoofing? */
|
103 |
|
|
if ($lancfg['spoofmac'])
|
104 |
cfc707f7
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . escapeshellarg($lancfg['if']) .
|
105 |
5b237745
|
Scott Ullrich
|
" link " . escapeshellarg($lancfg['spoofmac']));
|
106 |
cfc707f7
|
Scott Ullrich
|
|
107 |
5b237745
|
Scott Ullrich
|
/* 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 |
cfc707f7
|
Scott Ullrich
|
|
117 |
|
|
mwexec("/sbin/ifconfig " . escapeshellarg($lancfg['if']) . " " .
|
118 |
5b237745
|
Scott Ullrich
|
escapeshellarg($lancfg['ipaddr'] . "/" . $lancfg['subnet']));
|
119 |
cfc707f7
|
Scott Ullrich
|
|
120 |
5b237745
|
Scott Ullrich
|
if (!$g['booting']) {
|
121 |
|
|
/* make new hosts file */
|
122 |
|
|
system_hosts_generate();
|
123 |
cfc707f7
|
Scott Ullrich
|
|
124 |
5b237745
|
Scott Ullrich
|
/* reconfigure static routes (kernel may have deleted them) */
|
125 |
|
|
system_routing_configure();
|
126 |
cfc707f7
|
Scott Ullrich
|
|
127 |
5b237745
|
Scott Ullrich
|
/* reload ipfilter (address may have changed) */
|
128 |
|
|
filter_configure();
|
129 |
cfc707f7
|
Scott Ullrich
|
|
130 |
5b237745
|
Scott Ullrich
|
/* reload IPsec tunnels */
|
131 |
|
|
vpn_ipsec_configure();
|
132 |
cfc707f7
|
Scott Ullrich
|
|
133 |
5b237745
|
Scott Ullrich
|
/* reload dhcpd (gateway may have changed) */
|
134 |
|
|
services_dhcpd_configure();
|
135 |
cfc707f7
|
Scott Ullrich
|
|
136 |
5b237745
|
Scott Ullrich
|
/* reload dnsmasq */
|
137 |
|
|
services_dnsmasq_configure();
|
138 |
cfc707f7
|
Scott Ullrich
|
|
139 |
5b237745
|
Scott Ullrich
|
/* reload webgui */
|
140 |
|
|
system_webgui_start();
|
141 |
cfc707f7
|
Scott Ullrich
|
|
142 |
5b237745
|
Scott Ullrich
|
/* reload captive portal */
|
143 |
|
|
captiveportal_configure();
|
144 |
|
|
}
|
145 |
cfc707f7
|
Scott Ullrich
|
|
146 |
ed059571
|
Scott Ullrich
|
enable_hardware_offloading($lancfg['if']);
|
147 |
c9b4da10
|
Scott Ullrich
|
|
148 |
5b237745
|
Scott Ullrich
|
if ($g['booting'])
|
149 |
|
|
echo "done\n";
|
150 |
cfc707f7
|
Scott Ullrich
|
|
151 |
5b237745
|
Scott Ullrich
|
return 0;
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
function interfaces_optional_configure() {
|
155 |
|
|
global $config, $g;
|
156 |
|
|
global $bridgeconfig;
|
157 |
cfc707f7
|
Scott Ullrich
|
|
158 |
5b237745
|
Scott Ullrich
|
/* Reset bridge configuration. Interfaces will add to it. */
|
159 |
|
|
$bridgeconfig = "";
|
160 |
cfc707f7
|
Scott Ullrich
|
|
161 |
5b237745
|
Scott Ullrich
|
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
|
162 |
|
|
interfaces_optional_configure_if($i);
|
163 |
|
|
}
|
164 |
cfc707f7
|
Scott Ullrich
|
|
165 |
5b237745
|
Scott Ullrich
|
if ($bridgeconfig) {
|
166 |
|
|
/* Set the system bridge configuration and enable bridging. */
|
167 |
|
|
mwexec("/sbin/sysctl net.link.ether.bridge_cfg=" . $bridgeconfig);
|
168 |
fc5e6f70
|
Bill Marquette
|
mwexec("/sbin/sysctl net.link.ether.bridge.enable=1");
|
169 |
5b237745
|
Scott Ullrich
|
if (isset($config['bridge']['filteringbridge']))
|
170 |
a0ff9696
|
Scott Ullrich
|
mwexec("/sbin/sysctl net.link.ether.bridge.pf=1");
|
171 |
5b237745
|
Scott Ullrich
|
} else {
|
172 |
a0ff9696
|
Scott Ullrich
|
mwexec("/sbin/sysctl net.link.ether.bridge.pf=0");
|
173 |
fc5e6f70
|
Bill Marquette
|
mwexec("/sbin/sysctl net.link.ether.bridge.enable=0");
|
174 |
5b237745
|
Scott Ullrich
|
}
|
175 |
cfc707f7
|
Scott Ullrich
|
|
176 |
5b237745
|
Scott Ullrich
|
if (!$g['booting']) {
|
177 |
|
|
/* reconfigure static routes (kernel may have deleted them) */
|
178 |
|
|
system_routing_configure();
|
179 |
cfc707f7
|
Scott Ullrich
|
|
180 |
5b237745
|
Scott Ullrich
|
/* reload ipfilter (address may have changed) */
|
181 |
|
|
filter_configure();
|
182 |
cfc707f7
|
Scott Ullrich
|
|
183 |
5b237745
|
Scott Ullrich
|
/* reload IPsec tunnels */
|
184 |
|
|
vpn_ipsec_configure();
|
185 |
cfc707f7
|
Scott Ullrich
|
|
186 |
5b237745
|
Scott Ullrich
|
/* reload dhcpd (interface enabled/disabled/bridged status may have changed) */
|
187 |
|
|
services_dhcpd_configure();
|
188 |
cfc707f7
|
Scott Ullrich
|
|
189 |
5b237745
|
Scott Ullrich
|
/* restart dnsmasq */
|
190 |
|
|
services_dnsmasq_configure();
|
191 |
|
|
}
|
192 |
cfc707f7
|
Scott Ullrich
|
|
193 |
5b237745
|
Scott Ullrich
|
return 0;
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
function interfaces_optional_configure_if($opti) {
|
197 |
|
|
global $config, $g;
|
198 |
|
|
global $bridgeconfig;
|
199 |
cfc707f7
|
Scott Ullrich
|
|
200 |
5b237745
|
Scott Ullrich
|
$optcfg = $config['interfaces']['opt' . $opti];
|
201 |
cfc707f7
|
Scott Ullrich
|
|
202 |
5b237745
|
Scott Ullrich
|
if ($g['booting']) {
|
203 |
|
|
$optdescr = "";
|
204 |
|
|
if ($optcfg['descr'])
|
205 |
|
|
$optdescr = " ({$optcfg['descr']})";
|
206 |
|
|
echo "Configuring OPT{$opti}{$optdescr} interface... ";
|
207 |
|
|
}
|
208 |
cfc707f7
|
Scott Ullrich
|
|
209 |
5b237745
|
Scott Ullrich
|
if (isset($optcfg['enable'])) {
|
210 |
|
|
/* wireless configuration? */
|
211 |
|
|
if (is_array($optcfg['wireless']))
|
212 |
|
|
interfaces_wireless_configure($optcfg['if'], $optcfg['wireless']);
|
213 |
cfc707f7
|
Scott Ullrich
|
|
214 |
5b237745
|
Scott Ullrich
|
/* MAC spoofing? */
|
215 |
|
|
if ($optcfg['spoofmac'])
|
216 |
cfc707f7
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) .
|
217 |
5b237745
|
Scott Ullrich
|
" link " . escapeshellarg($optcfg['spoofmac']));
|
218 |
cfc707f7
|
Scott Ullrich
|
|
219 |
5b237745
|
Scott Ullrich
|
/* media */
|
220 |
|
|
if ($optcfg['media'] || $optcfg['mediaopt']) {
|
221 |
|
|
$cmd = "/sbin/ifconfig " . escapeshellarg($optcfg['if']);
|
222 |
|
|
if ($optcfg['media'])
|
223 |
|
|
$cmd .= " media " . escapeshellarg($optcfg['media']);
|
224 |
|
|
if ($optcfg['mediaopt'])
|
225 |
|
|
$cmd .= " mediaopt " . escapeshellarg($optcfg['mediaopt']);
|
226 |
|
|
mwexec($cmd);
|
227 |
|
|
}
|
228 |
cfc707f7
|
Scott Ullrich
|
|
229 |
5b237745
|
Scott Ullrich
|
/* OpenVPN configuration? */
|
230 |
|
|
if (isset($optcfg['ovpn'])) {
|
231 |
|
|
if (strstr($if, "tap"))
|
232 |
|
|
ovpn_link_tap();
|
233 |
|
|
}
|
234 |
cfc707f7
|
Scott Ullrich
|
|
235 |
5b237745
|
Scott Ullrich
|
/* bridged? */
|
236 |
|
|
if ($optcfg['bridge']) {
|
237 |
cfc707f7
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) .
|
238 |
5b237745
|
Scott Ullrich
|
" delete up");
|
239 |
cfc707f7
|
Scott Ullrich
|
|
240 |
5b237745
|
Scott Ullrich
|
if ($bridgeconfig != "")
|
241 |
|
|
$bridgeconfig .= ",";
|
242 |
cfc707f7
|
Scott Ullrich
|
|
243 |
5b237745
|
Scott Ullrich
|
$bridgeconfig .= $optcfg['if'] . ":" . $opti . "," .
|
244 |
|
|
$config['interfaces'][$optcfg['bridge']]['if'] .
|
245 |
|
|
":" . $opti;
|
246 |
|
|
} else {
|
247 |
cfc707f7
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) . " " .
|
248 |
5b237745
|
Scott Ullrich
|
escapeshellarg($optcfg['ipaddr'] . "/" . $optcfg['subnet']));
|
249 |
|
|
}
|
250 |
|
|
} else {
|
251 |
cfc707f7
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) .
|
252 |
5b237745
|
Scott Ullrich
|
" delete down");
|
253 |
|
|
}
|
254 |
cfc707f7
|
Scott Ullrich
|
|
255 |
c9b4da10
|
Scott Ullrich
|
enable_hardware_offloading(escapeshellarg($optcfg['if']));
|
256 |
ed059571
|
Scott Ullrich
|
|
257 |
5b237745
|
Scott Ullrich
|
if ($g['booting'])
|
258 |
|
|
echo "done\n";
|
259 |
cfc707f7
|
Scott Ullrich
|
|
260 |
5b237745
|
Scott Ullrich
|
return 0;
|
261 |
|
|
}
|
262 |
|
|
|
263 |
|
|
function interfaces_wireless_configure($if, $wlcfg) {
|
264 |
|
|
global $config, $g;
|
265 |
cfc707f7
|
Scott Ullrich
|
|
266 |
5b237745
|
Scott Ullrich
|
/* wireless configuration */
|
267 |
cfc707f7
|
Scott Ullrich
|
$ifcargs = escapeshellarg($if) .
|
268 |
|
|
" ssid " . escapeshellarg($wlcfg['ssid']) . " channel " .
|
269 |
5b237745
|
Scott Ullrich
|
escapeshellarg($wlcfg['channel']) . " ";
|
270 |
cfc707f7
|
Scott Ullrich
|
|
271 |
5b237745
|
Scott Ullrich
|
if ($wlcfg['stationname'])
|
272 |
|
|
$ifcargs .= "stationname " . escapeshellarg($wlcfg['stationname']) . " ";
|
273 |
cfc707f7
|
Scott Ullrich
|
|
274 |
5b237745
|
Scott Ullrich
|
if (isset($wlcfg['wep']['enable']) && is_array($wlcfg['wep']['key'])) {
|
275 |
|
|
$ifcargs .= "wepmode on ";
|
276 |
cfc707f7
|
Scott Ullrich
|
|
277 |
5b237745
|
Scott Ullrich
|
$i = 1;
|
278 |
|
|
foreach ($wlcfg['wep']['key'] as $wepkey) {
|
279 |
|
|
$ifcargs .= "wepkey " . escapeshellarg("{$i}:{$wepkey['value']}") . " ";
|
280 |
|
|
if (isset($wepkey['txkey'])) {
|
281 |
|
|
$ifcargs .= "weptxkey {$i} ";
|
282 |
|
|
}
|
283 |
|
|
$i++;
|
284 |
|
|
}
|
285 |
|
|
} else {
|
286 |
|
|
$ifcargs .= "wepmode off ";
|
287 |
|
|
}
|
288 |
cfc707f7
|
Scott Ullrich
|
|
289 |
5b237745
|
Scott Ullrich
|
switch ($wlcfg['mode']) {
|
290 |
|
|
case 'hostap':
|
291 |
|
|
if (strstr($if, "wi"))
|
292 |
|
|
$ifcargs .= "-mediaopt ibss mediaopt hostap ";
|
293 |
|
|
break;
|
294 |
|
|
case 'ibss':
|
295 |
|
|
case 'IBSS':
|
296 |
|
|
if (strstr($if, "wi"))
|
297 |
|
|
$ifcargs .= "-mediaopt hostap mediaopt ibss ";
|
298 |
|
|
else if (strstr($if, "an"))
|
299 |
|
|
$ifcargs .= "mediaopt adhoc ";
|
300 |
|
|
break;
|
301 |
|
|
case 'bss':
|
302 |
|
|
case 'BSS':
|
303 |
|
|
if (strstr($if, "wi"))
|
304 |
|
|
$ifcargs .= "-mediaopt hostap -mediaopt ibss ";
|
305 |
|
|
else if (strstr($if, "an"))
|
306 |
|
|
$ifcargs .= "-mediaopt adhoc ";
|
307 |
|
|
break;
|
308 |
|
|
}
|
309 |
cfc707f7
|
Scott Ullrich
|
|
310 |
5b237745
|
Scott Ullrich
|
$ifcargs .= "up";
|
311 |
cfc707f7
|
Scott Ullrich
|
|
312 |
5b237745
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . $ifcargs);
|
313 |
cfc707f7
|
Scott Ullrich
|
|
314 |
5b237745
|
Scott Ullrich
|
return 0;
|
315 |
|
|
}
|
316 |
|
|
|
317 |
|
|
function interfaces_wan_configure() {
|
318 |
|
|
global $config, $g;
|
319 |
cfc707f7
|
Scott Ullrich
|
|
320 |
5b237745
|
Scott Ullrich
|
$wancfg = $config['interfaces']['wan'];
|
321 |
cfc707f7
|
Scott Ullrich
|
|
322 |
5b237745
|
Scott Ullrich
|
if ($g['booting'])
|
323 |
|
|
echo "Configuring WAN interface... ";
|
324 |
|
|
else {
|
325 |
|
|
/* kill dhclient */
|
326 |
|
|
killbypid("{$g['varrun_path']}/dhclient.pid");
|
327 |
cfc707f7
|
Scott Ullrich
|
|
328 |
5b237745
|
Scott Ullrich
|
/* kill PPPoE client (mpd) */
|
329 |
|
|
killbypid("{$g['varrun_path']}/mpd.pid");
|
330 |
cfc707f7
|
Scott Ullrich
|
|
331 |
5b237745
|
Scott Ullrich
|
/* wait for processes to die */
|
332 |
|
|
sleep(2);
|
333 |
cfc707f7
|
Scott Ullrich
|
|
334 |
a23d7248
|
Scott Ullrich
|
unlink_if_exists("{$g['varetc_path']}/dhclient.conf");
|
335 |
|
|
unlink_if_exists("{$g['varetc_path']}/mpd.conf");
|
336 |
|
|
unlink_if_exists("{$g['varetc_path']}/mpd.links");
|
337 |
|
|
unlink_if_exists("{$g['vardb_path']}/wanip");
|
338 |
|
|
unlink_if_exists("{$g['varetc_path']}/nameservers.conf");
|
339 |
|
|
|
340 |
5b237745
|
Scott Ullrich
|
}
|
341 |
cfc707f7
|
Scott Ullrich
|
|
342 |
5b237745
|
Scott Ullrich
|
/* remove all addresses first */
|
343 |
|
|
while (mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " -alias") == 0);
|
344 |
|
|
mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " down");
|
345 |
cfc707f7
|
Scott Ullrich
|
|
346 |
5b237745
|
Scott Ullrich
|
/* wireless configuration? */
|
347 |
|
|
if (is_array($wancfg['wireless']))
|
348 |
|
|
interfaces_wireless_configure($wancfg['if'], $wancfg['wireless']);
|
349 |
cfc707f7
|
Scott Ullrich
|
|
350 |
5b237745
|
Scott Ullrich
|
if ($wancfg['spoofmac'])
|
351 |
cfc707f7
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) .
|
352 |
5b237745
|
Scott Ullrich
|
" link " . escapeshellarg($wancfg['spoofmac']));
|
353 |
cfc707f7
|
Scott Ullrich
|
|
354 |
5b237745
|
Scott Ullrich
|
/* media */
|
355 |
|
|
if ($wancfg['media'] || $wancfg['mediaopt']) {
|
356 |
|
|
$cmd = "/sbin/ifconfig " . escapeshellarg($wancfg['if']);
|
357 |
|
|
if ($wancfg['media'])
|
358 |
|
|
$cmd .= " media " . escapeshellarg($wancfg['media']);
|
359 |
|
|
if ($wancfg['mediaopt'])
|
360 |
|
|
$cmd .= " mediaopt " . escapeshellarg($wancfg['mediaopt']);
|
361 |
|
|
mwexec($cmd);
|
362 |
|
|
}
|
363 |
cfc707f7
|
Scott Ullrich
|
|
364 |
5b237745
|
Scott Ullrich
|
switch ($wancfg['ipaddr']) {
|
365 |
cfc707f7
|
Scott Ullrich
|
|
366 |
5b237745
|
Scott Ullrich
|
case 'dhcp':
|
367 |
|
|
interfaces_wan_dhcp_configure();
|
368 |
|
|
break;
|
369 |
cfc707f7
|
Scott Ullrich
|
|
370 |
5b237745
|
Scott Ullrich
|
case 'pppoe':
|
371 |
|
|
interfaces_wan_pppoe_configure();
|
372 |
|
|
break;
|
373 |
cfc707f7
|
Scott Ullrich
|
|
374 |
5b237745
|
Scott Ullrich
|
case 'pptp':
|
375 |
|
|
interfaces_wan_pptp_configure();
|
376 |
|
|
break;
|
377 |
cfc707f7
|
Scott Ullrich
|
|
378 |
5b237745
|
Scott Ullrich
|
case 'bigpond':
|
379 |
|
|
/* just configure DHCP for now; fire up bpalogin when we've got the lease */
|
380 |
|
|
interfaces_wan_dhcp_configure();
|
381 |
|
|
break;
|
382 |
cfc707f7
|
Scott Ullrich
|
|
383 |
5b237745
|
Scott Ullrich
|
default:
|
384 |
a23d7248
|
Scott Ullrich
|
if (isset($wancfg['ispointtopoint']) && $wancfg['pointtopoint']) {
|
385 |
|
|
mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " " .
|
386 |
|
|
escapeshellarg($wancfg['ipaddr'] . "/" . $wancfg['subnet']) .
|
387 |
|
|
" " . escapeshellarg($wancfg['pointtopoint']) . " up");
|
388 |
|
|
} else {
|
389 |
|
|
mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " " .
|
390 |
|
|
escapeshellarg($wancfg['ipaddr'] . "/" . $wancfg['subnet']));
|
391 |
|
|
}
|
392 |
5b237745
|
Scott Ullrich
|
/* install default route */
|
393 |
|
|
mwexec("/sbin/route delete default");
|
394 |
|
|
mwexec("/sbin/route add default " . escapeshellarg($wancfg['gateway']));
|
395 |
cfc707f7
|
Scott Ullrich
|
|
396 |
5b237745
|
Scott Ullrich
|
/* resync ipfilter (done automatically for DHCP/PPPoE/PPTP) */
|
397 |
|
|
filter_resync();
|
398 |
|
|
}
|
399 |
cfc707f7
|
Scott Ullrich
|
|
400 |
5b237745
|
Scott Ullrich
|
if (!$g['booting']) {
|
401 |
|
|
/* reconfigure static routes (kernel may have deleted them) */
|
402 |
|
|
system_routing_configure();
|
403 |
cfc707f7
|
Scott Ullrich
|
|
404 |
5b237745
|
Scott Ullrich
|
/* reload ipfilter */
|
405 |
|
|
filter_configure();
|
406 |
cfc707f7
|
Scott Ullrich
|
|
407 |
5b237745
|
Scott Ullrich
|
/* reload ipsec tunnels */
|
408 |
|
|
vpn_ipsec_configure();
|
409 |
cfc707f7
|
Scott Ullrich
|
|
410 |
5b237745
|
Scott Ullrich
|
/* restart ez-ipupdate */
|
411 |
|
|
services_dyndns_configure();
|
412 |
cfc707f7
|
Scott Ullrich
|
|
413 |
a23d7248
|
Scott Ullrich
|
/* force DNS update */
|
414 |
|
|
services_dnsupdate_process();
|
415 |
|
|
|
416 |
5b237745
|
Scott Ullrich
|
/* restart dnsmasq */
|
417 |
|
|
services_dnsmasq_configure();
|
418 |
|
|
}
|
419 |
cfc707f7
|
Scott Ullrich
|
|
420 |
ed059571
|
Scott Ullrich
|
enable_hardware_offloading($wancfg['if']);
|
421 |
|
|
|
422 |
5b237745
|
Scott Ullrich
|
if ($g['booting'])
|
423 |
|
|
echo "done\n";
|
424 |
cfc707f7
|
Scott Ullrich
|
|
425 |
5b237745
|
Scott Ullrich
|
return 0;
|
426 |
|
|
}
|
427 |
|
|
|
428 |
|
|
function interfaces_wan_dhcp_configure() {
|
429 |
|
|
global $config, $g;
|
430 |
cfc707f7
|
Scott Ullrich
|
|
431 |
5b237745
|
Scott Ullrich
|
$wancfg = $config['interfaces']['wan'];
|
432 |
|
|
|
433 |
|
|
/* generate dhclient.conf */
|
434 |
|
|
$fd = fopen("{$g['varetc_path']}/dhclient.conf", "w");
|
435 |
|
|
if (!$fd) {
|
436 |
|
|
printf("Error: cannot open dhclient.conf in interfaces_wan_dhcp_configure().\n");
|
437 |
|
|
return 1;
|
438 |
|
|
}
|
439 |
cfc707f7
|
Scott Ullrich
|
|
440 |
5b237745
|
Scott Ullrich
|
$dhclientconf = "";
|
441 |
cfc707f7
|
Scott Ullrich
|
|
442 |
5b237745
|
Scott Ullrich
|
if ($wancfg['dhcphostname']) {
|
443 |
|
|
$dhclientconf .= <<<EOD
|
444 |
|
|
send dhcp-client-identifier "{$wancfg['dhcphostname']}";
|
445 |
|
|
interface "{$wancfg['if']}" {
|
446 |
|
|
send host-name "{$wancfg['dhcphostname']}";
|
447 |
|
|
}
|
448 |
|
|
|
449 |
|
|
EOD;
|
450 |
|
|
}
|
451 |
|
|
|
452 |
|
|
fwrite($fd, $dhclientconf);
|
453 |
|
|
fclose($fd);
|
454 |
cfc707f7
|
Scott Ullrich
|
|
455 |
5b237745
|
Scott Ullrich
|
/* fire up dhclient - don't wait for the lease (-nw) */
|
456 |
|
|
mwexec("/sbin/dhclient -nw -cf {$g['varetc_path']}/dhclient.conf " .
|
457 |
|
|
escapeshellarg($wancfg['if']) . " &");
|
458 |
cfc707f7
|
Scott Ullrich
|
|
459 |
5b237745
|
Scott Ullrich
|
return 0;
|
460 |
|
|
}
|
461 |
|
|
|
462 |
a23d7248
|
Scott Ullrich
|
function interfaces_wan_dhcp_down() {
|
463 |
|
|
mwexec("/sbin/dhclient -r");
|
464 |
|
|
sleep(3);
|
465 |
|
|
}
|
466 |
|
|
|
467 |
|
|
function interfaces_wan_dhcp_up() {
|
468 |
|
|
interfaces_wan_dhcp_configure();
|
469 |
|
|
sleep(3);
|
470 |
|
|
}
|
471 |
|
|
|
472 |
5b237745
|
Scott Ullrich
|
function interfaces_wan_pppoe_configure() {
|
473 |
|
|
global $config, $g;
|
474 |
cfc707f7
|
Scott Ullrich
|
|
475 |
5b237745
|
Scott Ullrich
|
$wancfg = $config['interfaces']['wan'];
|
476 |
|
|
$pppoecfg = $config['pppoe'];
|
477 |
cfc707f7
|
Scott Ullrich
|
|
478 |
5b237745
|
Scott Ullrich
|
/* generate mpd.conf */
|
479 |
|
|
$fd = fopen("{$g['varetc_path']}/mpd.conf", "w");
|
480 |
|
|
if (!$fd) {
|
481 |
|
|
printf("Error: cannot open mpd.conf in interfaces_wan_pppoe_configure().\n");
|
482 |
|
|
return 1;
|
483 |
|
|
}
|
484 |
cfc707f7
|
Scott Ullrich
|
|
485 |
5b237745
|
Scott Ullrich
|
$idle = 0;
|
486 |
cfc707f7
|
Scott Ullrich
|
|
487 |
5b237745
|
Scott Ullrich
|
if (isset($pppoecfg['ondemand'])) {
|
488 |
|
|
$ondemand = "enable";
|
489 |
|
|
if ($pppoecfg['timeout'])
|
490 |
|
|
$idle = $pppoecfg['timeout'];
|
491 |
|
|
} else {
|
492 |
|
|
$ondemand = "disable";
|
493 |
|
|
}
|
494 |
cfc707f7
|
Scott Ullrich
|
|
495 |
5b237745
|
Scott Ullrich
|
$mpdconf = <<<EOD
|
496 |
|
|
pppoe:
|
497 |
|
|
new -i ng0 pppoe pppoe
|
498 |
|
|
set iface route default
|
499 |
|
|
set iface {$ondemand} on-demand
|
500 |
|
|
set iface idle {$idle}
|
501 |
|
|
set iface up-script /usr/local/sbin/ppp-linkup
|
502 |
|
|
|
503 |
|
|
EOD;
|
504 |
cfc707f7
|
Scott Ullrich
|
|
505 |
5b237745
|
Scott Ullrich
|
if (isset($pppoecfg['ondemand'])) {
|
506 |
|
|
$mpdconf .= <<<EOD
|
507 |
|
|
set iface addrs 10.0.0.1 10.0.0.2
|
508 |
|
|
|
509 |
|
|
EOD;
|
510 |
|
|
}
|
511 |
cfc707f7
|
Scott Ullrich
|
|
512 |
5b237745
|
Scott Ullrich
|
$mpdconf .= <<<EOD
|
513 |
|
|
set bundle disable multilink
|
514 |
|
|
set bundle authname "{$pppoecfg['username']}"
|
515 |
|
|
set bundle password "{$pppoecfg['password']}"
|
516 |
|
|
set link keep-alive 10 60
|
517 |
|
|
set link max-redial 0
|
518 |
|
|
set link no acfcomp protocomp
|
519 |
|
|
set link disable pap chap
|
520 |
|
|
set link accept chap
|
521 |
|
|
set link mtu 1492
|
522 |
|
|
set ipcp yes vjcomp
|
523 |
|
|
set ipcp ranges 0.0.0.0/0 0.0.0.0/0
|
524 |
a23d7248
|
Scott Ullrich
|
|
525 |
|
|
EOD;
|
526 |
|
|
|
527 |
|
|
if (isset($config['system']['dnsallowoverride'])) {
|
528 |
|
|
$mpdconf .= <<<EOD
|
529 |
5b237745
|
Scott Ullrich
|
set ipcp enable req-pri-dns
|
530 |
|
|
set ipcp enable req-sec-dns
|
531 |
a23d7248
|
Scott Ullrich
|
|
532 |
|
|
EOD;
|
533 |
|
|
}
|
534 |
a0ff9696
|
Scott Ullrich
|
|
535 |
a23d7248
|
Scott Ullrich
|
$mpdconf .= <<<EOD
|
536 |
5b237745
|
Scott Ullrich
|
open iface
|
537 |
|
|
|
538 |
|
|
EOD;
|
539 |
|
|
|
540 |
|
|
fwrite($fd, $mpdconf);
|
541 |
|
|
fclose($fd);
|
542 |
cfc707f7
|
Scott Ullrich
|
|
543 |
5b237745
|
Scott Ullrich
|
/* generate mpd.links */
|
544 |
|
|
$fd = fopen("{$g['varetc_path']}/mpd.links", "w");
|
545 |
|
|
if (!$fd) {
|
546 |
|
|
printf("Error: cannot open mpd.links in interfaces_wan_pppoe_configure().\n");
|
547 |
|
|
return 1;
|
548 |
|
|
}
|
549 |
cfc707f7
|
Scott Ullrich
|
|
550 |
5b237745
|
Scott Ullrich
|
$mpdconf = <<<EOD
|
551 |
|
|
pppoe:
|
552 |
|
|
set link type pppoe
|
553 |
|
|
set pppoe iface {$wancfg['if']}
|
554 |
|
|
set pppoe service "{$pppoecfg['provider']}"
|
555 |
|
|
set pppoe enable originate
|
556 |
|
|
set pppoe disable incoming
|
557 |
|
|
|
558 |
|
|
EOD;
|
559 |
|
|
|
560 |
|
|
fwrite($fd, $mpdconf);
|
561 |
|
|
fclose($fd);
|
562 |
cfc707f7
|
Scott Ullrich
|
|
563 |
5b237745
|
Scott Ullrich
|
/* fire up mpd */
|
564 |
|
|
mwexec("/usr/local/sbin/mpd -b -d {$g['varetc_path']} -p {$g['varrun_path']}/mpd.pid pppoe");
|
565 |
cfc707f7
|
Scott Ullrich
|
|
566 |
5b237745
|
Scott Ullrich
|
return 0;
|
567 |
|
|
}
|
568 |
|
|
|
569 |
a23d7248
|
Scott Ullrich
|
function interfaces_wan_pppoe_down() {
|
570 |
|
|
global $g;
|
571 |
|
|
sigkillbypid("{$g['varrun_path']}/mpd.pid", "SIGUSR2");
|
572 |
|
|
sleep(3);
|
573 |
|
|
}
|
574 |
|
|
|
575 |
|
|
function interfaces_wan_pppoe_up() {
|
576 |
|
|
global $g;
|
577 |
|
|
sigkillbypid("{$g['varrun_path']}/mpd.pid", "SIGUSR1");
|
578 |
|
|
sleep(3);
|
579 |
|
|
}
|
580 |
|
|
|
581 |
5b237745
|
Scott Ullrich
|
function interfaces_wan_pptp_configure() {
|
582 |
|
|
global $config, $g;
|
583 |
cfc707f7
|
Scott Ullrich
|
|
584 |
5b237745
|
Scott Ullrich
|
$wancfg = $config['interfaces']['wan'];
|
585 |
|
|
$pptpcfg = $config['pptp'];
|
586 |
cfc707f7
|
Scott Ullrich
|
|
587 |
5b237745
|
Scott Ullrich
|
/* generate mpd.conf */
|
588 |
|
|
$fd = fopen("{$g['varetc_path']}/mpd.conf", "w");
|
589 |
|
|
if (!$fd) {
|
590 |
|
|
printf("Error: cannot open mpd.conf in interfaces_wan_pptp_configure().\n");
|
591 |
|
|
return 1;
|
592 |
|
|
}
|
593 |
cfc707f7
|
Scott Ullrich
|
|
594 |
5b237745
|
Scott Ullrich
|
$idle = 0;
|
595 |
cfc707f7
|
Scott Ullrich
|
|
596 |
5b237745
|
Scott Ullrich
|
if (isset($pptpcfg['ondemand'])) {
|
597 |
|
|
$ondemand = "enable";
|
598 |
|
|
if ($pptpcfg['timeout'])
|
599 |
|
|
$idle = $pptpcfg['timeout'];
|
600 |
|
|
} else {
|
601 |
|
|
$ondemand = "disable";
|
602 |
|
|
}
|
603 |
cfc707f7
|
Scott Ullrich
|
|
604 |
5b237745
|
Scott Ullrich
|
$mpdconf = <<<EOD
|
605 |
|
|
pptp:
|
606 |
|
|
new -i ng0 pptp pptp
|
607 |
|
|
set iface route default
|
608 |
|
|
set iface {$ondemand} on-demand
|
609 |
|
|
set iface idle {$idle}
|
610 |
|
|
set iface up-script /usr/local/sbin/ppp-linkup
|
611 |
|
|
|
612 |
|
|
EOD;
|
613 |
cfc707f7
|
Scott Ullrich
|
|
614 |
5b237745
|
Scott Ullrich
|
if (isset($pptpcfg['ondemand'])) {
|
615 |
|
|
$mpdconf .= <<<EOD
|
616 |
a23d7248
|
Scott Ullrich
|
set iface addrs 10.0.0.1 10.0.0.2
|
617 |
5b237745
|
Scott Ullrich
|
|
618 |
|
|
EOD;
|
619 |
|
|
}
|
620 |
cfc707f7
|
Scott Ullrich
|
|
621 |
5b237745
|
Scott Ullrich
|
$mpdconf .= <<<EOD
|
622 |
|
|
set bundle disable multilink
|
623 |
|
|
set bundle authname "{$pptpcfg['username']}"
|
624 |
|
|
set bundle password "{$pptpcfg['password']}"
|
625 |
|
|
set link keep-alive 10 60
|
626 |
|
|
set link max-redial 0
|
627 |
|
|
set link no acfcomp protocomp
|
628 |
|
|
set link disable pap chap
|
629 |
|
|
set link accept chap
|
630 |
|
|
set ipcp no vjcomp
|
631 |
|
|
set ipcp ranges 0.0.0.0/0 0.0.0.0/0
|
632 |
a23d7248
|
Scott Ullrich
|
|
633 |
|
|
EOD;
|
634 |
a0ff9696
|
Scott Ullrich
|
|
635 |
a23d7248
|
Scott Ullrich
|
if (isset($config['system']['dnsallowoverride'])) {
|
636 |
|
|
$mpdconf .= <<<EOD
|
637 |
5b237745
|
Scott Ullrich
|
set ipcp enable req-pri-dns
|
638 |
|
|
set ipcp enable req-sec-dns
|
639 |
a23d7248
|
Scott Ullrich
|
|
640 |
|
|
EOD;
|
641 |
|
|
}
|
642 |
a0ff9696
|
Scott Ullrich
|
|
643 |
a23d7248
|
Scott Ullrich
|
$mpdconf .= <<<EOD
|
644 |
5b237745
|
Scott Ullrich
|
open
|
645 |
|
|
|
646 |
|
|
EOD;
|
647 |
|
|
|
648 |
|
|
fwrite($fd, $mpdconf);
|
649 |
|
|
fclose($fd);
|
650 |
cfc707f7
|
Scott Ullrich
|
|
651 |
5b237745
|
Scott Ullrich
|
/* generate mpd.links */
|
652 |
|
|
$fd = fopen("{$g['varetc_path']}/mpd.links", "w");
|
653 |
|
|
if (!$fd) {
|
654 |
|
|
printf("Error: cannot open mpd.links in interfaces_wan_pptp_configure().\n");
|
655 |
|
|
return 1;
|
656 |
|
|
}
|
657 |
cfc707f7
|
Scott Ullrich
|
|
658 |
5b237745
|
Scott Ullrich
|
$mpdconf = <<<EOD
|
659 |
|
|
pptp:
|
660 |
|
|
set link type pptp
|
661 |
|
|
set pptp enable originate outcall
|
662 |
|
|
set pptp disable windowing
|
663 |
|
|
set pptp self {$pptpcfg['local']}
|
664 |
|
|
set pptp peer {$pptpcfg['remote']}
|
665 |
|
|
|
666 |
|
|
EOD;
|
667 |
|
|
|
668 |
|
|
fwrite($fd, $mpdconf);
|
669 |
|
|
fclose($fd);
|
670 |
cfc707f7
|
Scott Ullrich
|
|
671 |
5b237745
|
Scott Ullrich
|
/* configure interface */
|
672 |
cfc707f7
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " " .
|
673 |
5b237745
|
Scott Ullrich
|
escapeshellarg($pptpcfg['local'] . "/" . $pptpcfg['subnet']));
|
674 |
cfc707f7
|
Scott Ullrich
|
|
675 |
5b237745
|
Scott Ullrich
|
/* fire up mpd */
|
676 |
|
|
mwexec("/usr/local/sbin/mpd -b -d {$g['varetc_path']} -p {$g['varrun_path']}/mpd.pid pptp");
|
677 |
cfc707f7
|
Scott Ullrich
|
|
678 |
5b237745
|
Scott Ullrich
|
return 0;
|
679 |
|
|
}
|
680 |
|
|
|
681 |
a23d7248
|
Scott Ullrich
|
function interfaces_wan_pptp_down() {
|
682 |
|
|
global $g;
|
683 |
|
|
sigkillbypid("{$g['varrun_path']}/mpd.pid", "SIGUSR2");
|
684 |
|
|
sleep(3);
|
685 |
|
|
}
|
686 |
|
|
|
687 |
|
|
function interfaces_wan_pptp_up() {
|
688 |
|
|
global $g;
|
689 |
|
|
sigkillbypid("{$g['varrun_path']}/mpd.pid", "SIGUSR1");
|
690 |
|
|
sleep(3);
|
691 |
|
|
}
|
692 |
|
|
|
693 |
5b237745
|
Scott Ullrich
|
function interfaces_wan_bigpond_configure($curwanip) {
|
694 |
|
|
global $config, $g;
|
695 |
cfc707f7
|
Scott Ullrich
|
|
696 |
5b237745
|
Scott Ullrich
|
$bpcfg = $config['bigpond'];
|
697 |
cfc707f7
|
Scott Ullrich
|
|
698 |
5b237745
|
Scott Ullrich
|
if (!$curwanip) {
|
699 |
|
|
/* IP address not configured yet, exit */
|
700 |
|
|
return 0;
|
701 |
|
|
}
|
702 |
cfc707f7
|
Scott Ullrich
|
|
703 |
5b237745
|
Scott Ullrich
|
/* kill bpalogin */
|
704 |
|
|
killbyname("bpalogin");
|
705 |
cfc707f7
|
Scott Ullrich
|
|
706 |
5b237745
|
Scott Ullrich
|
/* wait a moment */
|
707 |
|
|
sleep(1);
|
708 |
cfc707f7
|
Scott Ullrich
|
|
709 |
5b237745
|
Scott Ullrich
|
/* get the default domain */
|
710 |
|
|
$nfd = @fopen("{$g['varetc_path']}/defaultdomain.conf", "r");
|
711 |
|
|
if ($nfd) {
|
712 |
|
|
$defaultdomain = trim(fgets($nfd));
|
713 |
|
|
fclose($nfd);
|
714 |
|
|
}
|
715 |
cfc707f7
|
Scott Ullrich
|
|
716 |
5b237745
|
Scott Ullrich
|
/* generate bpalogin.conf */
|
717 |
|
|
$fd = fopen("{$g['varetc_path']}/bpalogin.conf", "w");
|
718 |
|
|
if (!$fd) {
|
719 |
|
|
printf("Error: cannot open bpalogin.conf in interfaces_wan_bigpond_configure().\n");
|
720 |
|
|
return 1;
|
721 |
|
|
}
|
722 |
cfc707f7
|
Scott Ullrich
|
|
723 |
5b237745
|
Scott Ullrich
|
if (!$bpcfg['authserver'])
|
724 |
|
|
$bpcfg['authserver'] = "dce-server";
|
725 |
|
|
if (!$bpcfg['authdomain'])
|
726 |
|
|
$bpcfg['authdomain'] = $defaultdomain;
|
727 |
cfc707f7
|
Scott Ullrich
|
|
728 |
5b237745
|
Scott Ullrich
|
$bpconf = <<<EOD
|
729 |
|
|
username {$bpcfg['username']}
|
730 |
|
|
password {$bpcfg['password']}
|
731 |
|
|
authserver {$bpcfg['authserver']}
|
732 |
|
|
authdomain {$bpcfg['authdomain']}
|
733 |
|
|
localport 5050
|
734 |
|
|
|
735 |
|
|
EOD;
|
736 |
|
|
|
737 |
|
|
if ($bpcfg['minheartbeatinterval'])
|
738 |
|
|
$bpconf .= "minheartbeatinterval {$bpcfg['minheartbeatinterval']}\n";
|
739 |
|
|
|
740 |
|
|
fwrite($fd, $bpconf);
|
741 |
|
|
fclose($fd);
|
742 |
cfc707f7
|
Scott Ullrich
|
|
743 |
5b237745
|
Scott Ullrich
|
/* fire up bpalogin */
|
744 |
|
|
mwexec("/usr/local/sbin/bpalogin -c {$g['varetc_path']}/bpalogin.conf");
|
745 |
cfc707f7
|
Scott Ullrich
|
|
746 |
5b237745
|
Scott Ullrich
|
return 0;
|
747 |
|
|
}
|
748 |
|
|
|
749 |
|
|
function get_real_wan_interface() {
|
750 |
|
|
global $config, $g;
|
751 |
cfc707f7
|
Scott Ullrich
|
|
752 |
5b237745
|
Scott Ullrich
|
$wancfg = $config['interfaces']['wan'];
|
753 |
cfc707f7
|
Scott Ullrich
|
|
754 |
5b237745
|
Scott Ullrich
|
$wanif = $wancfg['if'];
|
755 |
|
|
if (($wancfg['ipaddr'] == "pppoe") || ($wancfg['ipaddr'] == "pptp")) {
|
756 |
|
|
$wanif = $g['pppoe_interface'];
|
757 |
|
|
}
|
758 |
cfc707f7
|
Scott Ullrich
|
|
759 |
5b237745
|
Scott Ullrich
|
return $wanif;
|
760 |
|
|
}
|
761 |
|
|
|
762 |
|
|
function get_current_wan_address() {
|
763 |
|
|
global $config, $g;
|
764 |
cfc707f7
|
Scott Ullrich
|
|
765 |
5b237745
|
Scott Ullrich
|
$wancfg = $config['interfaces']['wan'];
|
766 |
cfc707f7
|
Scott Ullrich
|
|
767 |
5b237745
|
Scott Ullrich
|
if (in_array($wancfg['ipaddr'], array('pppoe','dhcp','pptp','bigpond'))) {
|
768 |
|
|
/* dynamic WAN IP address, find out which one */
|
769 |
|
|
$wanif = get_real_wan_interface();
|
770 |
cfc707f7
|
Scott Ullrich
|
|
771 |
5b237745
|
Scott Ullrich
|
/* get interface info with netstat */
|
772 |
|
|
exec("/usr/bin/netstat -nWI " . escapeshellarg($wanif) . " -f inet", $ifinfo);
|
773 |
cfc707f7
|
Scott Ullrich
|
|
774 |
5b237745
|
Scott Ullrich
|
if (isset($ifinfo[1])) {
|
775 |
|
|
$aif = preg_split("/\s+/", $ifinfo[1]);
|
776 |
|
|
$curwanip = chop($aif[3]);
|
777 |
cfc707f7
|
Scott Ullrich
|
|
778 |
5b237745
|
Scott Ullrich
|
if ($curwanip && is_ipaddr($curwanip) && ($curwanip != "0.0.0.0"))
|
779 |
|
|
return $curwanip;
|
780 |
|
|
}
|
781 |
cfc707f7
|
Scott Ullrich
|
|
782 |
5b237745
|
Scott Ullrich
|
return null;
|
783 |
|
|
} else {
|
784 |
|
|
/* static WAN IP address */
|
785 |
|
|
return $wancfg['ipaddr'];
|
786 |
|
|
}
|
787 |
|
|
}
|
788 |
|
|
|
789 |
|
|
?>
|