You are not logged in.

#1 2015-12-12 06:41:07

jbodhorn
Member
Registered: 2015-12-11
Posts: 130

cannot disconnect from vpn connected with network manager dispatcher

I followed the network manager arch wiki to set up network manager dispatcher to connect to vpn on boot and it does just that. Seeing as I need to turn off the vpn from time to time I figured I could just turn off it off with network manager.

If I do try turning it off with network manager the vpn just keeps disconnecting and reconnecting. Sometimes it will connect and stay connected if I keep toggling the on/off button in gnome. I thought turning the wifi off and back on with network manager would stop the vpn disconnecting/reconnecting but it just resumes the disconnect/reconnect thing that it's been doing.

This is the dispatcher script:

#!/bin/sh
VPN_NAME=vpn
ESSID=$(iwgetid -r)

interface=$1 status=$2
case $status in
  up|vpn-down)
    if iwgetid | grep -qs ":\"$ESSID\""; then
      nmcli con up id "$VPN_NAME"
    fi
    ;;
  down)
    if iwgetid | grep -qs ":\"$ESSID\""; then
      if nmcli con show --active | grep "$VPN_NAME"; then
        nmcli con down id "$VPN_NAME"
      fi
    fi
    ;;

Is my problem due to the script, the way I disconnected, or is it something else? I've only been using arch a few days now and I honestly don't know a whole lot about Linux. Most of my computer usage has been with windows, so atm I'm not sure how to figure out how to fix this.

In fedora the only way I could find to connect to vpn on boot was to create a service file and do:

systemctl enable vpn.service

This meant I had to disconnect via command line.

When I read about the dispatcher I thought could disconnect with a couple of clicks instead of typing a command, I'm still hoping I can...

Offline

#2 2016-08-07 18:09:23

Tidykoala
Member
Registered: 2015-07-05
Posts: 14

Re: cannot disconnect from vpn connected with network manager dispatcher

Hello,

I dig up this topic because I was facing the same problem when I wanted to shutdown manually the VPN. So, I improved the dispatcher script from the wiki to allow user to disable the VPN manually.

I also fixed this little issue which could print an error in `journalctl` when the VPN is already active:

NetworkManager[504]: <info>  [1470572233.4074] audit: op="connection-activate" uuid="The UUID" name="VPN Name" pid=7855 uid=0 result="fail" reason="Connection 'VPN Name' is already active"
nm-dispatcher[7757]: Error: Connection activation failed: Connection 'VPN Name' is already active
nm-dispatcher[7757]: req:2 'up' [tun0], "/etc/NetworkManager/dispatcher.d/vpn-up": complete: failed with Script '/etc/NetworkManager/dispatcher.d/vpn-up' exited with error status 4.
NetworkManager[504]: <warn>  [1470572233.4219] dispatcher: (152) vpn-up failed (failed): Script '/etc/NetworkManager/dispatcher.d/vpn-up' exited with error status 4.

Also, if the VPN gets disconnected either manually or automatically, I added a notification to inform the user that it has been disabled.

Here is the entire script:

#!/bin/sh
VPN_NAME="VPN Name"
ESSID=$(iwgetid -r)

interface=$1 status=$2
case $status in
  up)
    if iwgetid | grep -qs ":\"$ESSID\""; then
      if ! nmcli con show --active | grep "$VPN_NAME"; then
        nmcli con up id "$VPN_NAME"
      fi
    fi
    ;;
  down)
    if iwgetid | grep -qs ":\"$ESSID\""; then
      if nmcli con show --active | grep "$VPN_NAME"; then
        nmcli con down id "$VPN_NAME"
      fi
    fi
    ;;
  vpn-down)
    if iwgetid | grep -qs ":\"$ESSID\""; then
      # Replace here username by your user name
      sudo -u username DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus notify-send 'VPN' 'The VPN connection is disabled.' --icon=dialog-warning
    fi
    ;;
esac

Note that you need to put your user name on the line for sending a notification.

I hope it will help others having some issues to use the VPN correctly.

As I'm not at all a Bash expert / Network expert / Dbus expert , please let me know if you see some error in my script or if there is a way to improve it. If it looks okay to you, I may update the wiki with this new script.

Offline

#3 2016-09-21 03:38:02

jbodhorn
Member
Registered: 2015-12-11
Posts: 130

Re: cannot disconnect from vpn connected with network manager dispatcher

This is yet another issue I've had with arch that I gave up on. I'll have to give your solution a go, I hope it works for me also.

Offline

Board footer

Powered by FluxBB