vivien/i3blocks-contrib

nm-vpn fails to display my input

gnzlbg opened this issue · 4 comments

Expected behavior

I expect the only side-effect of this script to be displaying the vpn name when connected.

Actual behavior

The script does not display anything, and the adjacent wifi indicator icon disappears when it is used.

i3blocks config relevant to blocklet(s)

nm-vpn

Reproducer

The current script is:

#!/bin/sh
nmcli -t connection show --active | awk -F ':' '
/tun0/{vpn="ON"} /vpn/{name=$1}
END{if(vpn) printf("%s\n%s\n%s\n", name, vpn, "#00FF00")}'

when I execute nmcli -t connection show --active I get (note: I've modified the hashes in the middle):

MY-VPN-NAME:ab6ab8-a86ba6ab8-ab6ba9ba:vpn:wlp0s30g4
MY-WLAN-NAME:bf323-23-5ff-sd-4-254:802-11-wireless:wlp0s30g4
vpn0:4282484-22482-424824:tun:vpn0

The script looks for tun0, which does not appear in my input, and therefore, nothing happens. The script probably makes an assumption that just does not hold in my system.

I expected the script to show MY-VPN-NAME as the active vpn.

For now this should do the trick:

nmcli -t connection show --active | awk -F ':' '
$3=="vpn" {printf ("%s\n%s\n%s\n", $1, "ON", "#00FF00") }
'

I have no idea why the original blocklet checks for the presence of 'tun' interface, it is only present when a VPN is running, but '--active' option for nmcli already does filter only running connections. Also there would be no 'tun' interface for tap connections.

Looking at the output on my machine, a vpn connection would be fully established when the tun0 interface is created. If you loop over the input, you can see that the vpn interface is still yellow when it is initialising.

I didn't realise that interface names weren't standard across devices. I'd probably recommend setting the proper interface name as the BLOCK_INSTANCE. I've moved on to using i3status-rs, so consider this blocklet abandoned. Now it's time for someone else to patch it ;).

@The-King-of-Toasters, thank you for the info. #306 should fix the issue. I tried to not overcomplicate the awk part so that it remains somewhat POSIX compliant. awk script looks for 'tun' 'tap' and 'vpn' substrings which I expect to reliably appear in TYPE field of nm-cli output.

There will be false positives if there will be other connection names containing substrings awk is looking for.

upd: 71a9be1 should reduce the amount of false positives. It is not clear to how tap mode VPNs are created by NetworkManager, they're rarely used though.