#!/usr/local/bin/python2.5 # # Philippe Niquille # 15.5.2007 # # philippe a niquille d com # # This script checks the current (wireless) network location and connects the VPN, if required. # # Be aware of the fact that Kicker.xml runs this script when connecting and DISconnecting to/from a network. # import os, sys, re, time #gets SSID ssid = os.popen("/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I | fgrep -i ' ssid' | grep -Eo '[a-zA-Z0-9]+$'") #get's first part of IP in format 130.82 #ip=`ifconfig en0 | grep "inet " | grep -v 127.0.0.1 | cut -d\ -f2 | grep -Eo "[0-9]{3}.[0-9]{2}"` ip = os.popen('ifconfig en0 | grep "inet " | grep -v 127.0.0.1 | cut -d\ -f2 | cut -c -6') #the VPN user user = "04604658" #get the VPN password pwd = os.popen("security 2>&1 >/dev/null find-generic-password -s vpn -g login.keychain | grep 'password: ' | grep -Eo '\"(.*)\"$'") #strip the "" to pwd = re.sub(r'\"','',pwd.read()) pwd = re.sub(r'\n','',pwd) if ip.read() == '130.82\n' or ssid.read() == 'public\n' : #wait for the network to get up time.sleep(3) connect = os.system("screen -d -m /usr/local/bin/vpnclient connect UNISG user " + user + " pwd " + pwd +" &") if connect == 0: os.system("/usr/bin/logger -i 'auto-initiating VPN..'") else: os.system("/usr/bin/logger -i 'could not auto-initiate VPN!'") sys.exit()