#!/bin/bash # Credit for original concept and initial work to: Jesse Jarzynka # # Updated by: Ventz Petkov (11-08-23) # * Modified VPN_EXECUTABLE default path due to dir change within `brew` on M-series Macs (m1, m2, m3) to /opt/homebrew/ # * Modified sudoers to reflect new openconnect VPN_EXECUTABLE path # * Cleaned up KeyChain instructions around KeyChain Item name vs Account Name # # Updated by: Ventz Petkov (7-25-23) # * added useragent for AnyConnect (needed for recent deployments) # * added "VPN_GROUP" option, which is replacing the phased out "#VPN_TUNNEL_OPTIONALLY" within the "VPN_USERNAME" # Updated by: Ventz Petkov (8-31-18) # * merged feature for token/pin input (ex: Duo/Yubikey/Google Authenticator) contributed by Harry Hoffman # * added option to pick "push/sms/phone" (ex: Duo) vs token/pin (Yubikey/Google Authenticator/Duo) # Updated by: Ventz Petkov (11-15-17) # * cleared up documentation # * incremented 'VPN_INTERFACE' to 'utun99' to avoid collisions with other VPNs # Updated by: Ventz Petkov (9-28-17) # * fixed for Mac OS X High Sierra (10.13) # Updated by: Ventz Petkov (7-24-17) # * fixed openconnect (did not work with new 2nd password prompt) # * added ability to work with "Duo" 2-factor auth # * changed icons # VPN Status # v1.1 # Ventz Petkov # ventz # Connect/Disconnect OpenConnect + show status # ######################################################### # USER CHANGES # ######################################################### # 1.) Updated your sudo config with (edit "mac-username" with your username): # (NOTE: You can obtain the "mac-username" with "whoami" in a terminal) #mac-username ALL=(ALL) NOPASSWD: /opt/homebrew/bin/openconnect #mac-username ALL=(ALL) NOPASSWD: /usr/bin/killall -2 openconnect # 2.) Make sure openconnect binary is located here: # (If you don't have it installed: "brew install openconnect") VPN_EXECUTABLE=/opt/homebrew/bin/openconnect # 3.) Update your AnyConnect VPN host VPN_HOST="vpn.domain.tld" # NOTE: If you are using a VPN_GROUP (ex: domain.tld/group) -- use this, instead of "#VPN_TUNNEL" within VPN_USERNAME VPN_GROUP="VPN_GROUP_TUNNEL_OPTIONALLY" # 4.) Update your AnyConnect username + tunnel # NOTE: If you are NOT using the VPN_GROUP, set it to empty, and use "#VPN_TUNNEL" within the VPN_USERNAME VPN_USERNAME="vpn_username@domain.tld#VPN_TUNNEL_OPTIONALLY" # 5.) Push 2FA (ex: Duo), or Pin/Token (ex: Yubikey, Google Authenticator, TOTP) PUSH_OR_PIN="push" #PUSH_OR_PIN="Yubikey" # --- # * For Push (and other Duo specifics), options include: # "push", "sms", or "phone" # --- # * For Yubikey/Google Authenticator/other TOTP, specify any name for prompt: # "any-name-of-product-to-be-prompted-about" # PUSH_OR_PIN="Yubikey" | PUSH_OR_PIN="Google Authenticator" | PUSH_OR_PIN="Duo" # (essentially, anything _other_ than the "push", "sms", or "phone" options) # --- # 6.) Create an encrypted password entry in your OS X Keychain: # a.) Open "Keychain Access" and # b.) Click on "login" keychain (top left corner) # c.) Click on "Passwords" category (bottom left corner) # d.) From the "File" menu, select -> "New Password Item..." # e.) For "Keychain Item Name" "VPN_HOST" (ex: vpn.domain.tld) # f.) For "Account Name" use the value for "VPN_USERNAME" (ex: email@domain.tld) # g.) For "Password" enter your VPN AnyConnect password. # This will retrieve that password securely at run time when you connect, and feed it to openconnect # No storing passwords unenin plain text files! :) GET_VPN_PASSWORD="security find-generic-password -wl $VPN_HOST" # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # END-OF-USER-SETTINGS # ######################################################### VPN_INTERFACE="utun99" # Command to determine if VPN is connected or disconnected VPN_CONNECTED="/sbin/ifconfig | grep -A3 $VPN_INTERFACE | grep inet" # Command to run to disconnect VPN VPN_DISCONNECT_CMD="sudo killall -2 openconnect" # GUI Prompt for your token/key (ex: Duo/Yubikey/Google Authenticator) function prompt_2fa_method() { if [ "$1" == "push" ]; then echo "push" elif [ "$1" == "sms" ]; then echo "sms" elif [ "$1" == "phone" ]; then echo "phone" else osascript <