Skip to content

Instantly share code, notes, and snippets.

@Karunamon
Last active August 29, 2015 14:12
Show Gist options
  • Save Karunamon/832d88959fc575185687 to your computer and use it in GitHub Desktop.
Save Karunamon/832d88959fc575185687 to your computer and use it in GitHub Desktop.
AnyConnect VPN Quick Connector Applescript
<?xml version="1.0" encoding="utf-8"?>
<AnyConnectLocalPolicy acversion="str1234">
<!--WARNING: If your network administrators have defined this file already, then replacing the existing version with this will
almost certainly break things. In this case, try just changing the 'BypassDownloader' option to true, rather than
replacing this file outright.-->
<FipsMode>false</FipsMode>
<BypassDownloader>true</BypassDownloader>
<RestrictWebLaunch>false</RestrictWebLaunch>
<StrictCertificateTrust>false</StrictCertificateTrust>
<RestrictTunnelProtocols>false</RestrictTunnelProtocols>
<RestrictPreferenceCaching>false</RestrictPreferenceCaching>
<ExcludePemFileCertStore>false</ExcludePemFileCertStore>
<ExcludeWinNativeCertStore>false</ExcludeWinNativeCertStore>
<ExcludeMacNativeCertStore>false</ExcludeMacNativeCertStore>
<ExcludeFirefoxNSSCertStore>false</ExcludeFirefoxNSSCertStore>
<UpdatePolicy>
<AllowSoftwareUpdatesFromAnyServer>true</AllowSoftwareUpdatesFromAnyServer>
<AllowVPNProfileUpdatesFromAnyServer>true</AllowVPNProfileUpdatesFromAnyServer>
<AllowServiceProfileUpdatesFromAnyServer>true</AllowServiceProfileUpdatesFromAnyServer>
</UpdatePolicy>
</AnyConnectLocalPolicy>
--1) Save locally with .scpt extension
--2) Configure IP, username, and password below
--3) Save the other file in this gist to your local machine, in /opt/cisco/anyconnect/AnyConnectLocalPolicy.xml (Note if one is already there, THIS PROBABLY WILL CAUSE PROBLEMS)
--4) Run!
--Configuration
set VPNApp to "Cisco AnyConnect Secure Mobility Client"
set VPNIP to ""
set VPNUser to ""
set VPNPass to ""
set AnyconnectPath to "/opt/cisco/anyconnect"
set AnyconnectPolicyFilePath to "/opt/cisco/anyconnect/AnyConnectLocalPolicy.xml"
--Is anyconnect installed?
if exists AnyconnectPath then
--Does the relevant policy file exist?
if exists AnyconnectPolicyFilePath then
--We do nothing and move on
else
display dialog "Anyconnect policy file is not installed. Please make sure the file /opt/cisco/anyconnect/AnyConnectLocalPolicy.xml exists and VPNDownloader is disabled. This script cannot function with the default settings" with title "Anyconnect policy error" with icon stop buttons {"OK"} giving up after 5
error number -1
end if
else
display dialog "Anyconnect is unavailable or inaccessable. Check your install and try again." with title "Anyconnect access error" with icon stop buttons {"OK"} giving up after 5
error number -1
end if
--Actually connect to the VPN
tell application VPNApp to activate
repeat until application VPNApp is running
delay 1
end repeat
tell application "System Events"
repeat until (window 1 of process VPNApp exists)
delay 1
end repeat
--Fill the IP and hit connect
tell process VPNApp
keystroke (VPNIP as string)
keystroke return
end tell
--Wait for the connection to initialize
repeat until (window 2 of process VPNApp exists)
delay 1
end repeat
--Click past the certificate warning
set ConnectAnyway to button 2 of window 1 of process VPNApp
click ConnectAnyway
--Further waiting for the user/password prompt
repeat until (window 2 of process VPNApp exists)
delay 1
end repeat
--Fill in our login dialog and finish connecting!
tell process VPNApp
set value of text field 1 of window 1 to VPNUser as string
set value of text field 2 of window 1 to VPNPass as string
click button "OK" of window 1
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment