To use the script, simply run it with the default python interpreter like so:
```bash
python3 main.py
```
## What is the problem with Pulse Secure or Juniper Secure Connect ?
Since 2FA has become mandatory to connect to the VPN, standard VPN clients fail to parse the login forms correctly.
## How does this script work ?
The script uses Selenium, a Python module capable of controlling a headless web browser, to load the gateway webpage.
When redirected to the login form, the user is prompted to enter their credentials, which are then saved in a Firefox profile.
The next time it is used, the connection is made automatically.
Then, the session id cookie is extracted and passed to a commandline VPN client (openconnect).
## Why is it asking me for sudo privileges ?
There are two points for which sudo is required.
The first and most obvious is to enable the VPN, since your network interfaces are being modified.
The second one is due to how Firefox profiles work when installed as a snap package.
In fact, when launching Firefox with a given profile, a copy of said profile is made in a temporary directory. However, when Firefox is a snap, this temporary directory is isolated from the rest of the system, and sudo permissions are needed to copy the profile back to a persistent directory.
If you don't trust me, I encourage you to take a look at the source code and see by yourself that nothing suspicious is done.
I made this mainly for myself but thought I would share it in the hope it could help at least one other person. Feel free to make suggestions, create issues and/or pull requests.
## Credits
Thanks to [sh4dowb](https://gist.github.com/sh4dowb) for the workaround used to save Firefox profiles even when using Selenium ([gist](https://gist.github.com/sh4dowb/0054e4b25bf81bccca6f9e622c5cb160))
Thanks to [artfulrobot](https://stackoverflow.com/users/623519/artfulrobot) for their class allowing to "OR" multiple expected conditions ([StackOverflow answer](https://stackoverflow.com/a/16464305/11109181))