Skip to content

SwiftBar/xbar plugin to establish VPN connections via OpenConnect and monitor connection status

License

Notifications You must be signed in to change notification settings

niklasbogensperger/openconnect-menu-bar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

openconnect-menu-bar

SwiftBar/xbar plugin to establish VPN connections via OpenConnect and monitor connection status

Credit

Purpose

This script provides a convenient way to control and monitor the OpenConnect VPN connection status from the macOS menu bar using either of these two apps:

Important

This script was only tested with an AnyConnect-based VPN server. It assumes a VPN setup requiring basic login credentials and at most a TOTP/HOTP-based 2FA setup.

Caution

During the setup process (see below), you will be required to save your credentials (meaning password and 2FA seed secret, if applicable) in the macOS keychain.

PROCEED AT YOUR OWN RISK

Screenshots

Connected

Disconnected

Setup

1. Install the latest SwiftBar or xbar release

2. Install dependencies by a method of your choice

Needed are OpenConnect and optionally (depending on VPN server setup) oath-toolkit for 2FA functionality.

Installing can be done e.g. with the homebrew package manager:

brew install openconnect
brew install oath-toolkit

3. Test out the OpenConnect installation manually

Check to see if OpenConnect works out of the box with the provided vpnc-script:
(Change the URL to your own VPN host and also change connection parameters if needed - see here)

sudo openconnect https://vpn.example.tld

If there are errors such as "... is not a recognized network service", see the README in the vpnc-script/ folder of this repo.

4. Download the "openconnect.15s.sh" script and follow the steps inside to customize

  1. Download the file
  2. Open it in a plain text editor or IDE of your choice
  3. Follow all steps in the "CONFIGURATION STEPS" section
  4. Copy/Move it to the SwiftBar/xbar script folder that you or the app chose
  5. Make sure the file is executable: chmod +x openconnect.15s.sh

Miscellaneous tips/tricks and notes

Tip

Hold the ⌥ Option key while clicking on the menu bar entry to bring up SwiftBar options that are hidden by default (only applies to SwiftBar).

Tip

Hold the ⌘ Command key to drag the menu bar entry to the desired spot.

Note

When using SwiftBar, the script (and thus the menu entries) will update itself when the menu bar item is clicked in order to provide an accurate uptime. In case of connection loss, the script (and thus the icon) will update itself after around 15 seconds. Should you want to tweak this value, e.g. because you are using xbar where refresh-on-click is not an available feature or for performance reasons, you can rename the script according to this guide.

About

SwiftBar/xbar plugin to establish VPN connections via OpenConnect and monitor connection status

Topics

Resources

License

Stars

Watchers

Forks

Languages