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 |
cfc707f7
|
Scott Ullrich
|
|
169 |
5b237745
|
Scott Ullrich
|
if (isset($config['bridge']['filteringbridge']))
|
170 |
a0ff9696
|
Scott Ullrich
|
mwexec("/sbin/sysctl net.link.ether.bridge.pf=1");
|
171 |
cfc707f7
|
Scott Ullrich
|
|
172 |
5b237745
|
Scott Ullrich
|
mwexec("/sbin/sysctl net.link.ether.bridge=1");
|
173 |
|
|
} else {
|
174 |
a0ff9696
|
Scott Ullrich
|
mwexec("/sbin/sysctl net.link.ether.bridge.pf=0");
|
175 |
5b237745
|
Scott Ullrich
|
mwexec("/sbin/sysctl net.link.ether.bridge=0");
|
176 |
|
|
}
|
177 |
cfc707f7
|
Scott Ullrich
|
|
178 |
5b237745
|
Scott Ullrich
|
if (!$g['booting']) {
|
179 |
|
|
/* reconfigure static routes (kernel may have deleted them) */
|
180 |
|
|
system_routing_configure();
|
181 |
cfc707f7
|
Scott Ullrich
|
|
182 |
5b237745
|
Scott Ullrich
|
/* reload ipfilter (address may have changed) */
|
183 |
|
|
filter_configure();
|
184 |
cfc707f7
|
Scott Ullrich
|
|
185 |
5b237745
|
Scott Ullrich
|
/* reload IPsec tunnels */
|
186 |
|
|
vpn_ipsec_configure();
|
187 |
cfc707f7
|
Scott Ullrich
|
|
188 |
5b237745
|
Scott Ullrich
|
/* reload dhcpd (interface enabled/disabled/bridged status may have changed) */
|
189 |
|
|
services_dhcpd_configure();
|
190 |
cfc707f7
|
Scott Ullrich
|
|
191 |
5b237745
|
Scott Ullrich
|
/* restart dnsmasq */
|
192 |
|
|
services_dnsmasq_configure();
|
193 |
|
|
}
|
194 |
cfc707f7
|
Scott Ullrich
|
|
195 |
5b237745
|
Scott Ullrich
|
return 0;
|
196 |
|
|
}
|
197 |
|
|
|
198 |
|
|
function interfaces_optional_configure_if($opti) {
|
199 |
|
|
global $config, $g;
|
200 |
|
|
global $bridgeconfig;
|
201 |
cfc707f7
|
Scott Ullrich
|
|
202 |
5b237745
|
Scott Ullrich
|
$optcfg = $config['interfaces']['opt' . $opti];
|
203 |
cfc707f7
|
Scott Ullrich
|
|
204 |
5b237745
|
Scott Ullrich
|
if ($g['booting']) {
|
205 |
|
|
$optdescr = "";
|
206 |
|
|
if ($optcfg['descr'])
|
207 |
|
|
$optdescr = " ({$optcfg['descr']})";
|
208 |
|
|
echo "Configuring OPT{$opti}{$optdescr} interface... ";
|
209 |
|
|
}
|
210 |
cfc707f7
|
Scott Ullrich
|
|
211 |
5b237745
|
Scott Ullrich
|
if (isset($optcfg['enable'])) {
|
212 |
|
|
/* wireless configuration? */
|
213 |
|
|
if (is_array($optcfg['wireless']))
|
214 |
|
|
interfaces_wireless_configure($optcfg['if'], $optcfg['wireless']);
|
215 |
cfc707f7
|
Scott Ullrich
|
|
216 |
5b237745
|
Scott Ullrich
|
/* MAC spoofing? */
|
217 |
|
|
if ($optcfg['spoofmac'])
|
218 |
cfc707f7
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) .
|
219 |
5b237745
|
Scott Ullrich
|
" link " . escapeshellarg($optcfg['spoofmac']));
|
220 |
cfc707f7
|
Scott Ullrich
|
|
221 |
5b237745
|
Scott Ullrich
|
/* 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 |
cfc707f7
|
Scott Ullrich
|
|
231 |
5b237745
|
Scott Ullrich
|
/* OpenVPN configuration? */
|
232 |
|
|
if (isset($optcfg['ovpn'])) {
|
233 |
|
|
if (strstr($if, "tap"))
|
234 |
|
|
ovpn_link_tap();
|
235 |
|
|
}
|
236 |
cfc707f7
|
Scott Ullrich
|
|
237 |
5b237745
|
Scott Ullrich
|
/* bridged? */
|
238 |
|
|
if ($optcfg['bridge']) {
|
239 |
cfc707f7
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) .
|
240 |
5b237745
|
Scott Ullrich
|
" delete up");
|
241 |
cfc707f7
|
Scott Ullrich
|
|
242 |
5b237745
|
Scott Ullrich
|
if ($bridgeconfig != "")
|
243 |
|
|
$bridgeconfig .= ",";
|
244 |
cfc707f7
|
Scott Ullrich
|
|
245 |
5b237745
|
Scott Ullrich
|
$bridgeconfig .= $optcfg['if'] . ":" . $opti . "," .
|
246 |
|
|
$config['interfaces'][$optcfg['bridge']]['if'] .
|
247 |
|
|
":" . $opti;
|
248 |
|
|
} else {
|
249 |
cfc707f7
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) . " " .
|
250 |
5b237745
|
Scott Ullrich
|
escapeshellarg($optcfg['ipaddr'] . "/" . $optcfg['subnet']));
|
251 |
|
|
}
|
252 |
|
|
} else {
|
253 |
cfc707f7
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) .
|
254 |
5b237745
|
Scott Ullrich
|
" delete down");
|
255 |
|
|
}
|
256 |
cfc707f7
|
Scott Ullrich
|
|
257 |
c9b4da10
|
Scott Ullrich
|
enable_hardware_offloading(escapeshellarg($optcfg['if']));
|
258 |
ed059571
|
Scott Ullrich
|
|
259 |
5b237745
|
Scott Ullrich
|
if ($g['booting'])
|
260 |
|
|
echo "done\n";
|
261 |
cfc707f7
|
Scott Ullrich
|
|
262 |
5b237745
|
Scott Ullrich
|
return 0;
|
263 |
|
|
}
|
264 |
|
|
|
265 |
|
|
function interfaces_wireless_configure($if, $wlcfg) {
|
266 |
|
|
global $config, $g;
|
267 |
cfc707f7
|
Scott Ullrich
|
|
268 |
5b237745
|
Scott Ullrich
|
/* wireless configuration */
|
269 |
cfc707f7
|
Scott Ullrich
|
$ifcargs = escapeshellarg($if) .
|
270 |
|
|
" ssid " . escapeshellarg($wlcfg['ssid']) . " channel " .
|
271 |
5b237745
|
Scott Ullrich
|
escapeshellarg($wlcfg['channel']) . " ";
|
272 |
cfc707f7
|
Scott Ullrich
|
|
273 |
5b237745
|
Scott Ullrich
|
if ($wlcfg['stationname'])
|
274 |
|
|
$ifcargs .= "stationname " . escapeshellarg($wlcfg['stationname']) . " ";
|
275 |
cfc707f7
|
Scott Ullrich
|
|
276 |
5b237745
|
Scott Ullrich
|
if (isset($wlcfg['wep']['enable']) && is_array($wlcfg['wep']['key'])) {
|
277 |
|
|
$ifcargs .= "wepmode on ";
|
278 |
cfc707f7
|
Scott Ullrich
|
|
279 |
5b237745
|
Scott Ullrich
|
$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 |
cfc707f7
|
Scott Ullrich
|
|
291 |
5b237745
|
Scott Ullrich
|
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 |
cfc707f7
|
Scott Ullrich
|
|
312 |
5b237745
|
Scott Ullrich
|
$ifcargs .= "up";
|
313 |
cfc707f7
|
Scott Ullrich
|
|
314 |
5b237745
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . $ifcargs);
|
315 |
cfc707f7
|
Scott Ullrich
|
|
316 |
5b237745
|
Scott Ullrich
|
return 0;
|
317 |
|
|
}
|
318 |
|
|
|
319 |
|
|
function interfaces_wan_configure() {
|
320 |
|
|
global $config, $g;
|
321 |
cfc707f7
|
Scott Ullrich
|
|
322 |
5b237745
|
Scott Ullrich
|
$wancfg = $config['interfaces']['wan'];
|
323 |
cfc707f7
|
Scott Ullrich
|
|
324 |
5b237745
|
Scott Ullrich
|
if ($g['booting'])
|
325 |
|
|
echo "Configuring WAN interface... ";
|
326 |
|
|
else {
|
327 |
|
|
/* kill dhclient */
|
328 |
|
|
killbypid("{$g['varrun_path']}/dhclient.pid");
|
329 |
cfc707f7
|
Scott Ullrich
|
|
330 |
5b237745
|
Scott Ullrich
|
/* kill PPPoE client (mpd) */
|
331 |
|
|
killbypid("{$g['varrun_path']}/mpd.pid");
|
332 |
cfc707f7
|
Scott Ullrich
|
|
333 |
5b237745
|
Scott Ullrich
|
/* wait for processes to die */
|
334 |
|
|
sleep(2);
|
335 |
cfc707f7
|
Scott Ullrich
|
|
336 |
a23d7248
|
Scott Ullrich
|
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 |
5b237745
|
Scott Ullrich
|
}
|
343 |
cfc707f7
|
Scott Ullrich
|
|
344 |
5b237745
|
Scott Ullrich
|
/* remove all addresses first */
|
345 |
|
|
while (mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " -alias") == 0);
|
346 |
|
|
mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " down");
|
347 |
cfc707f7
|
Scott Ullrich
|
|
348 |
5b237745
|
Scott Ullrich
|
/* wireless configuration? */
|
349 |
|
|
if (is_array($wancfg['wireless']))
|
350 |
|
|
interfaces_wireless_configure($wancfg['if'], $wancfg['wireless']);
|
351 |
cfc707f7
|
Scott Ullrich
|
|
352 |
5b237745
|
Scott Ullrich
|
if ($wancfg['spoofmac'])
|
353 |
cfc707f7
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) .
|
354 |
5b237745
|
Scott Ullrich
|
" link " . escapeshellarg($wancfg['spoofmac']));
|
355 |
cfc707f7
|
Scott Ullrich
|
|
356 |
5b237745
|
Scott Ullrich
|
/* 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 |
cfc707f7
|
Scott Ullrich
|
|
366 |
5b237745
|
Scott Ullrich
|
switch ($wancfg['ipaddr']) {
|
367 |
cfc707f7
|
Scott Ullrich
|
|
368 |
5b237745
|
Scott Ullrich
|
case 'dhcp':
|
369 |
|
|
interfaces_wan_dhcp_configure();
|
370 |
|
|
break;
|
371 |
cfc707f7
|
Scott Ullrich
|
|
372 |
5b237745
|
Scott Ullrich
|
case 'pppoe':
|
373 |
|
|
interfaces_wan_pppoe_configure();
|
374 |
|
|
break;
|
375 |
cfc707f7
|
Scott Ullrich
|
|
376 |
5b237745
|
Scott Ullrich
|
case 'pptp':
|
377 |
|
|
interfaces_wan_pptp_configure();
|
378 |
|
|
break;
|
379 |
cfc707f7
|
Scott Ullrich
|
|
380 |
5b237745
|
Scott Ullrich
|
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 |
cfc707f7
|
Scott Ullrich
|
|
385 |
5b237745
|
Scott Ullrich
|
default:
|
386 |
a23d7248
|
Scott Ullrich
|
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 |
5b237745
|
Scott Ullrich
|
/* install default route */
|
395 |
|
|
mwexec("/sbin/route delete default");
|
396 |
|
|
mwexec("/sbin/route add default " . escapeshellarg($wancfg['gateway']));
|
397 |
cfc707f7
|
Scott Ullrich
|
|
398 |
5b237745
|
Scott Ullrich
|
/* resync ipfilter (done automatically for DHCP/PPPoE/PPTP) */
|
399 |
|
|
filter_resync();
|
400 |
|
|
}
|
401 |
cfc707f7
|
Scott Ullrich
|
|
402 |
5b237745
|
Scott Ullrich
|
if (!$g['booting']) {
|
403 |
|
|
/* reconfigure static routes (kernel may have deleted them) */
|
404 |
|
|
system_routing_configure();
|
405 |
cfc707f7
|
Scott Ullrich
|
|
406 |
5b237745
|
Scott Ullrich
|
/* reload ipfilter */
|
407 |
|
|
filter_configure();
|
408 |
cfc707f7
|
Scott Ullrich
|
|
409 |
5b237745
|
Scott Ullrich
|
/* reload ipsec tunnels */
|
410 |
|
|
vpn_ipsec_configure();
|
411 |
cfc707f7
|
Scott Ullrich
|
|
412 |
5b237745
|
Scott Ullrich
|
/* restart ez-ipupdate */
|
413 |
|
|
services_dyndns_configure();
|
414 |
cfc707f7
|
Scott Ullrich
|
|
415 |
a23d7248
|
Scott Ullrich
|
/* force DNS update */
|
416 |
|
|
services_dnsupdate_process();
|
417 |
|
|
|
418 |
5b237745
|
Scott Ullrich
|
/* restart dnsmasq */
|
419 |
|
|
services_dnsmasq_configure();
|
420 |
|
|
}
|
421 |
cfc707f7
|
Scott Ullrich
|
|
422 |
ed059571
|
Scott Ullrich
|
enable_hardware_offloading($wancfg['if']);
|
423 |
|
|
|
424 |
5b237745
|
Scott Ullrich
|
if ($g['booting'])
|
425 |
|
|
echo "done\n";
|
426 |
cfc707f7
|
Scott Ullrich
|
|
427 |
5b237745
|
Scott Ullrich
|
return 0;
|
428 |
|
|
}
|
429 |
|
|
|
430 |
|
|
function interfaces_wan_dhcp_configure() {
|
431 |
|
|
global $config, $g;
|
432 |
cfc707f7
|
Scott Ullrich
|
|
433 |
5b237745
|
Scott Ullrich
|
$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 |
cfc707f7
|
Scott Ullrich
|
|
442 |
5b237745
|
Scott Ullrich
|
$dhclientconf = "";
|
443 |
cfc707f7
|
Scott Ullrich
|
|
444 |
5b237745
|
Scott Ullrich
|
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 |
cfc707f7
|
Scott Ullrich
|
|
457 |
5b237745
|
Scott Ullrich
|
/* 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 |
cfc707f7
|
Scott Ullrich
|
|
461 |
5b237745
|
Scott Ullrich
|
return 0;
|
462 |
|
|
}
|
463 |
|
|
|
464 |
a23d7248
|
Scott Ullrich
|
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 |
5b237745
|
Scott Ullrich
|
function interfaces_wan_pppoe_configure() {
|
475 |
|
|
global $config, $g;
|
476 |
cfc707f7
|
Scott Ullrich
|
|
477 |
5b237745
|
Scott Ullrich
|
$wancfg = $config['interfaces']['wan'];
|
478 |
|
|
$pppoecfg = $config['pppoe'];
|
479 |
cfc707f7
|
Scott Ullrich
|
|
480 |
5b237745
|
Scott Ullrich
|
/* 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 |
cfc707f7
|
Scott Ullrich
|
|
487 |
5b237745
|
Scott Ullrich
|
$idle = 0;
|
488 |
cfc707f7
|
Scott Ullrich
|
|
489 |
5b237745
|
Scott Ullrich
|
if (isset($pppoecfg['ondemand'])) {
|
490 |
|
|
$ondemand = "enable";
|
491 |
|
|
if ($pppoecfg['timeout'])
|
492 |
|
|
$idle = $pppoecfg['timeout'];
|
493 |
|
|
} else {
|
494 |
|
|
$ondemand = "disable";
|
495 |
|
|
}
|
496 |
cfc707f7
|
Scott Ullrich
|
|
497 |
5b237745
|
Scott Ullrich
|
$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 |
cfc707f7
|
Scott Ullrich
|
|
507 |
5b237745
|
Scott Ullrich
|
if (isset($pppoecfg['ondemand'])) {
|
508 |
|
|
$mpdconf .= <<<EOD
|
509 |
|
|
set iface addrs 10.0.0.1 10.0.0.2
|
510 |
|
|
|
511 |
|
|
EOD;
|
512 |
|
|
}
|
513 |
cfc707f7
|
Scott Ullrich
|
|
514 |
5b237745
|
Scott Ullrich
|
$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 |
a23d7248
|
Scott Ullrich
|
|
527 |
|
|
EOD;
|
528 |
|
|
|
529 |
|
|
if (isset($config['system']['dnsallowoverride'])) {
|
530 |
|
|
$mpdconf .= <<<EOD
|
531 |
5b237745
|
Scott Ullrich
|
set ipcp enable req-pri-dns
|
532 |
|
|
set ipcp enable req-sec-dns
|
533 |
a23d7248
|
Scott Ullrich
|
|
534 |
|
|
EOD;
|
535 |
|
|
}
|
536 |
a0ff9696
|
Scott Ullrich
|
|
537 |
a23d7248
|
Scott Ullrich
|
$mpdconf .= <<<EOD
|
538 |
5b237745
|
Scott Ullrich
|
open iface
|
539 |
|
|
|
540 |
|
|
EOD;
|
541 |
|
|
|
542 |
|
|
fwrite($fd, $mpdconf);
|
543 |
|
|
fclose($fd);
|
544 |
cfc707f7
|
Scott Ullrich
|
|
545 |
5b237745
|
Scott Ullrich
|
/* 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 |
cfc707f7
|
Scott Ullrich
|
|
552 |
5b237745
|
Scott Ullrich
|
$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 |
cfc707f7
|
Scott Ullrich
|
|
565 |
5b237745
|
Scott Ullrich
|
/* fire up mpd */
|
566 |
|
|
mwexec("/usr/local/sbin/mpd -b -d {$g['varetc_path']} -p {$g['varrun_path']}/mpd.pid pppoe");
|
567 |
cfc707f7
|
Scott Ullrich
|
|
568 |
5b237745
|
Scott Ullrich
|
return 0;
|
569 |
|
|
}
|
570 |
|
|
|
571 |
a23d7248
|
Scott Ullrich
|
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 |
5b237745
|
Scott Ullrich
|
function interfaces_wan_pptp_configure() {
|
584 |
|
|
global $config, $g;
|
585 |
cfc707f7
|
Scott Ullrich
|
|
586 |
5b237745
|
Scott Ullrich
|
$wancfg = $config['interfaces']['wan'];
|
587 |
|
|
$pptpcfg = $config['pptp'];
|
588 |
cfc707f7
|
Scott Ullrich
|
|
589 |
5b237745
|
Scott Ullrich
|
/* 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 |
cfc707f7
|
Scott Ullrich
|
|
596 |
5b237745
|
Scott Ullrich
|
$idle = 0;
|
597 |
cfc707f7
|
Scott Ullrich
|
|
598 |
5b237745
|
Scott Ullrich
|
if (isset($pptpcfg['ondemand'])) {
|
599 |
|
|
$ondemand = "enable";
|
600 |
|
|
if ($pptpcfg['timeout'])
|
601 |
|
|
$idle = $pptpcfg['timeout'];
|
602 |
|
|
} else {
|
603 |
|
|
$ondemand = "disable";
|
604 |
|
|
}
|
605 |
cfc707f7
|
Scott Ullrich
|
|
606 |
5b237745
|
Scott Ullrich
|
$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 |
cfc707f7
|
Scott Ullrich
|
|
616 |
5b237745
|
Scott Ullrich
|
if (isset($pptpcfg['ondemand'])) {
|
617 |
|
|
$mpdconf .= <<<EOD
|
618 |
a23d7248
|
Scott Ullrich
|
set iface addrs 10.0.0.1 10.0.0.2
|
619 |
5b237745
|
Scott Ullrich
|
|
620 |
|
|
EOD;
|
621 |
|
|
}
|
622 |
cfc707f7
|
Scott Ullrich
|
|
623 |
5b237745
|
Scott Ullrich
|
$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 |
a23d7248
|
Scott Ullrich
|
|
635 |
|
|
EOD;
|
636 |
a0ff9696
|
Scott Ullrich
|
|
637 |
a23d7248
|
Scott Ullrich
|
if (isset($config['system']['dnsallowoverride'])) {
|
638 |
|
|
$mpdconf .= <<<EOD
|
639 |
5b237745
|
Scott Ullrich
|
set ipcp enable req-pri-dns
|
640 |
|
|
set ipcp enable req-sec-dns
|
641 |
a23d7248
|
Scott Ullrich
|
|
642 |
|
|
EOD;
|
643 |
|
|
}
|
644 |
a0ff9696
|
Scott Ullrich
|
|
645 |
a23d7248
|
Scott Ullrich
|
$mpdconf .= <<<EOD
|
646 |
5b237745
|
Scott Ullrich
|
open
|
647 |
|
|
|
648 |
|
|
EOD;
|
649 |
|
|
|
650 |
|
|
fwrite($fd, $mpdconf);
|
651 |
|
|
fclose($fd);
|
652 |
cfc707f7
|
Scott Ullrich
|
|
653 |
5b237745
|
Scott Ullrich
|
/* 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 |
cfc707f7
|
Scott Ullrich
|
|
660 |
5b237745
|
Scott Ullrich
|
$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 |
cfc707f7
|
Scott Ullrich
|
|
673 |
5b237745
|
Scott Ullrich
|
/* configure interface */
|
674 |
cfc707f7
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " " .
|
675 |
5b237745
|
Scott Ullrich
|
escapeshellarg($pptpcfg['local'] . "/" . $pptpcfg['subnet']));
|
676 |
cfc707f7
|
Scott Ullrich
|
|
677 |
5b237745
|
Scott Ullrich
|
/* fire up mpd */
|
678 |
|
|
mwexec("/usr/local/sbin/mpd -b -d {$g['varetc_path']} -p {$g['varrun_path']}/mpd.pid pptp");
|
679 |
cfc707f7
|
Scott Ullrich
|
|
680 |
5b237745
|
Scott Ullrich
|
return 0;
|
681 |
|
|
}
|
682 |
|
|
|
683 |
a23d7248
|
Scott Ullrich
|
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 |
5b237745
|
Scott Ullrich
|
function interfaces_wan_bigpond_configure($curwanip) {
|
696 |
|
|
global $config, $g;
|
697 |
cfc707f7
|
Scott Ullrich
|
|
698 |
5b237745
|
Scott Ullrich
|
$bpcfg = $config['bigpond'];
|
699 |
cfc707f7
|
Scott Ullrich
|
|
700 |
5b237745
|
Scott Ullrich
|
if (!$curwanip) {
|
701 |
|
|
/* IP address not configured yet, exit */
|
702 |
|
|
return 0;
|
703 |
|
|
}
|
704 |
cfc707f7
|
Scott Ullrich
|
|
705 |
5b237745
|
Scott Ullrich
|
/* kill bpalogin */
|
706 |
|
|
killbyname("bpalogin");
|
707 |
cfc707f7
|
Scott Ullrich
|
|
708 |
5b237745
|
Scott Ullrich
|
/* wait a moment */
|
709 |
|
|
sleep(1);
|
710 |
cfc707f7
|
Scott Ullrich
|
|
711 |
5b237745
|
Scott Ullrich
|
/* 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 |
cfc707f7
|
Scott Ullrich
|
|
718 |
5b237745
|
Scott Ullrich
|
/* 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 |
cfc707f7
|
Scott Ullrich
|
|
725 |
5b237745
|
Scott Ullrich
|
if (!$bpcfg['authserver'])
|
726 |
|
|
$bpcfg['authserver'] = "dce-server";
|
727 |
|
|
if (!$bpcfg['authdomain'])
|
728 |
|
|
$bpcfg['authdomain'] = $defaultdomain;
|
729 |
cfc707f7
|
Scott Ullrich
|
|
730 |
5b237745
|
Scott Ullrich
|
$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 |
cfc707f7
|
Scott Ullrich
|
|
745 |
5b237745
|
Scott Ullrich
|
/* fire up bpalogin */
|
746 |
|
|
mwexec("/usr/local/sbin/bpalogin -c {$g['varetc_path']}/bpalogin.conf");
|
747 |
cfc707f7
|
Scott Ullrich
|
|
748 |
5b237745
|
Scott Ullrich
|
return 0;
|
749 |
|
|
}
|
750 |
|
|
|
751 |
|
|
function get_real_wan_interface() {
|
752 |
|
|
global $config, $g;
|
753 |
cfc707f7
|
Scott Ullrich
|
|
754 |
5b237745
|
Scott Ullrich
|
$wancfg = $config['interfaces']['wan'];
|
755 |
cfc707f7
|
Scott Ullrich
|
|
756 |
5b237745
|
Scott Ullrich
|
$wanif = $wancfg['if'];
|
757 |
|
|
if (($wancfg['ipaddr'] == "pppoe") || ($wancfg['ipaddr'] == "pptp")) {
|
758 |
|
|
$wanif = $g['pppoe_interface'];
|
759 |
|
|
}
|
760 |
cfc707f7
|
Scott Ullrich
|
|
761 |
5b237745
|
Scott Ullrich
|
return $wanif;
|
762 |
|
|
}
|
763 |
|
|
|
764 |
|
|
function get_current_wan_address() {
|
765 |
|
|
global $config, $g;
|
766 |
cfc707f7
|
Scott Ullrich
|
|
767 |
5b237745
|
Scott Ullrich
|
$wancfg = $config['interfaces']['wan'];
|
768 |
cfc707f7
|
Scott Ullrich
|
|
769 |
5b237745
|
Scott Ullrich
|
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 |
cfc707f7
|
Scott Ullrich
|
|
773 |
5b237745
|
Scott Ullrich
|
/* get interface info with netstat */
|
774 |
|
|
exec("/usr/bin/netstat -nWI " . escapeshellarg($wanif) . " -f inet", $ifinfo);
|
775 |
cfc707f7
|
Scott Ullrich
|
|
776 |
5b237745
|
Scott Ullrich
|
if (isset($ifinfo[1])) {
|
777 |
|
|
$aif = preg_split("/\s+/", $ifinfo[1]);
|
778 |
|
|
$curwanip = chop($aif[3]);
|
779 |
cfc707f7
|
Scott Ullrich
|
|
780 |
5b237745
|
Scott Ullrich
|
if ($curwanip && is_ipaddr($curwanip) && ($curwanip != "0.0.0.0"))
|
781 |
|
|
return $curwanip;
|
782 |
|
|
}
|
783 |
cfc707f7
|
Scott Ullrich
|
|
784 |
5b237745
|
Scott Ullrich
|
return null;
|
785 |
|
|
} else {
|
786 |
|
|
/* static WAN IP address */
|
787 |
|
|
return $wancfg['ipaddr'];
|
788 |
|
|
}
|
789 |
|
|
}
|
790 |
|
|
|
791 |
|
|
?>
|