Skip to content

Instantly share code, notes, and snippets.

@fabiosantoscode
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiosantoscode/baf2cac5b21ebbad9e79 to your computer and use it in GitHub Desktop.
Save fabiosantoscode/baf2cac5b21ebbad9e79 to your computer and use it in GitHub Desktop.
Execute something when I has VPN
#!/usr/bin/env python
# 1. look for the tokens in upper case and replace them with your stuff
# 2. drop this in /etc/NetworkManager/dispatcher.d/02atuatia
import sys
import os
eligible_connections = ['SOME VPN NAME', 'ANOTHER VPN NAME']
event = sys.argv[2]
if event != 'vpn-up':
sys.exit(0)
try:
conn = os.environ['CONNECTION_ID']
command = ('sudo su YOUR_USER -c '
'"/PATH/TO/YOURSCRIPT" '
'| logger')
if conn in eligible_connections:
os.system(command)
except Exception as e:
os.system('logger %r' % e)
sys.exit(1)
# HOWTO
. Drop this in /etc/NetworkManager/dispatcher.d/02atuatia
. chmod 700
. chown root
. ???
. profit!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment