Last active
August 29, 2015 14:11
-
-
Save fabiosantoscode/baf2cac5b21ebbad9e79 to your computer and use it in GitHub Desktop.
Execute something when I has VPN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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