@@ -224,15 +224,22 @@ async function listDevices() {
224224 // check and retrieve VPN networks only the first time
225225
226226 if (loading .value .networkDevices ) {
227+ const openvpnTunnelDevices = allDevices .value .filter ((d ) => isOpenVpnTunnel (d ))
228+ const hasIpsec = allDevices .value .some ((d ) => isIpsec (d ))
229+
227230 for (const device of allDevices .value ) {
228231 if (isOpenVpnRw (device )) {
229232 fetchOpenVpnRwNetwork (device )
230- } else if (isOpenVpnTunnel (device )) {
231- fetchOpenVpnTunnelNetworks (device )
232- } else if (isIpsec (device )) {
233- fetchIpsecNetworks ()
234233 }
235234 }
235+
236+ if (openvpnTunnelDevices .length > 0 ) {
237+ fetchOpenVpnTunnelNetworks (openvpnTunnelDevices )
238+ }
239+
240+ if (hasIpsec ) {
241+ fetchIpsecNetworks ()
242+ }
236243 }
237244 } catch (err : any ) {
238245 console .error (err )
@@ -280,29 +287,31 @@ async function fetchIpsecNetworks() {
280287 }
281288}
282289
283- async function fetchOpenVpnTunnelNetworks(device : DeviceOrIface ) {
290+ async function fetchOpenVpnTunnelNetworks(devices : DeviceOrIface [] ) {
284291 error .value .getVpnNetworks = ' '
285292 error .value .getVpnNetworksDetails = ' '
286293
287294 try {
288295 const res = await ubusCall (' ns.ovpntunnel' , ' list-tunnels' )
289-
290296 const tunnels = res .data
291- const tunnelName = device .openvpn .ns_name
292297
293- if (device .openvpn .server ) {
294- // server tunnel
295- const tunFound = tunnels .servers .find ((tun : any ) => tun .ns_name === tunnelName )
298+ for (const device of devices ) {
299+ const tunnelName = device .openvpn .ns_name
296300
297- if (tunFound ) {
298- vpnNetworks .value .openvpn [tunnelName ] = tunFound .remote_network
299- }
300- } else {
301- // client tunnel
302- const tunFound = tunnels .clients .find ((tun : any ) => tun .ns_name === tunnelName )
301+ if (device .openvpn .server ) {
302+ // server tunnel
303+ const tunFound = tunnels .servers .find ((tun : any ) => tun .ns_name === tunnelName )
303304
304- if (tunFound ) {
305- vpnNetworks .value .openvpn [tunnelName ] = tunFound .remote_network
305+ if (tunFound ) {
306+ vpnNetworks .value .openvpn [tunnelName ] = tunFound .remote_network
307+ }
308+ } else {
309+ // client tunnel
310+ const tunFound = tunnels .clients .find ((tun : any ) => tun .ns_name === tunnelName )
311+
312+ if (tunFound ) {
313+ vpnNetworks .value .openvpn [tunnelName ] = tunFound .remote_network
314+ }
306315 }
307316 }
308317 } catch (err : any ) {
0 commit comments