AutoKey scripts to automatically connect and disconnect to/from a VPN using AnyConnect.
The scripts expects a few things:
- "Start VPN when AnyConnect is started" preference is disabled in AnyConnect.
- There's a default HostName, Group and User, so they're filled automatically by AnyConnect once it tries to connect. Logging in once manually and/or checking the
~/.anyconnect
file may help. - That, after logging in, a banner (dialog with some info/warning) will pop up.
- There's no external change by the user in the current focus of fields/buttons/etc in the UI.
Tested with:
- AutoKey 0.95.10
- Cisco AnyConnect Secure Mobility Client 4.9.05042
- Install AutoKey:
sudo apt-get install autokey-common autokey-gtk
- Clone this repository:
git clone https://github.com/g-otn/autokey-anyconnect.git
cd autokey-anyconnect
- Modify the
vpnui/connect-vpnui.py
file, inserting your password:
STARTUP_TIME = 0.5
PASSWORD = "#############" # <-- Your VPN user password here
CONTACTING_TIME = 2
CONNECTION_TIMEOUT = 15
- Run the
setup.sh
script. This will simplychmod
the.sh
files and move them and the AutoKey scripts to the AutoKey folder:
chmod +x setup.sh
./setup.sh
- Set up some aliases for ease of use. If you use bash, you can append these lines at your
.bashrc
:
# AnyConnect Aliases
alias connect-vpnui='bash ~/.config/autokey/data/vpnui/connect-vpnui.sh'
alias disconnect-vpnui='bash ~/.config/autokey/data/vpnui/disconnect-vpnui.sh'
- Use the aliases to run the scripts. Example:
# Make sure AnyConnect is closed or its initial focus has not been changed
# before running the script
connect-vpnui
The repository folder can now be deleted and the scripts will now be located at ~/.config/autokey/data/vpnui
.