openvpn-gui icon indicating copy to clipboard operation
openvpn-gui copied to clipboard

Add setting to reestablish last VPN connection on application start

Open justmedev opened this issue 1 year ago • 7 comments

(Feature Request/Discussion)

Hey,

I would like to implement a setting, that, when active, instantly reconnects to the last connected vpn when the application is started. My reasoning is, that whenever I start OpenVPN I always want to connect to my work vpn and it would be faster to just open the app and let it connect by itself then to wait for the loading and then press the connect switch.

Any opinions on the idea before I start implementing and opening a pull request?

justmedev avatar Mar 01 '24 06:03 justmedev

The GUI already supports this in some form. Start a connection and then exit the GUI without pressing disconnect. The GUI will kill the connection and exit. Now restart the GUI and all connections that were active in the last session will be automatically connected. Same if you logout with the GUI running and some connections active. On next logon the GUI and those connections will restart automatically.

This behaviour can be changed from the settings menu -- see "Auto restart of active connections"

selvanair avatar Mar 01 '24 15:03 selvanair

This is not the case on Windows 11 24H2 and OpenVPN GUI 11.50.0.0. I will say it does set the registry key auto_restart_list and that works great until a reboot. Upon reboot the other registry settings are still there show_script_window, silent_connection, etc but the auto_restart_list is removed on restart.

That doesn't matter if I reboot, or shutdown while being connected.

alturic avatar Oct 28 '24 13:10 alturic

There could be a timing issue here. At normal program stop we get WM_CLOSE and save the list of active connections before stopping them. At reboot time we expect to get WM_ENDSESSION at first where we essentially do the same -- i.e., save the list and then try to stop all active tunnels. If we get a subsequent WM_CLOSE before reboot/shutdown we may end up re-saving the list of active connections which could be empty by that point. Not sure how to improve on this.

selvanair avatar Oct 28 '24 15:10 selvanair

~What's super interesting to me is how the registry key auto_restart_list seems to get removed on reboot which is seemingly why it doesn't reconnect on reboot? I guess my (non-technical) question would be what would cause that key to be removed? Second question would of course then be why would it get removed?~

Thanks for such a quick response!

Edit: I think I see "what" would cause that to be removed, the connection might be disconnected so there is no connection left to keep in the list so the key is deleted?

So then my updated question would simply be (and yes, I do apologize for asking it here) is there a way to make the startup shortcut entry include the connection parameter? I tried with passing --connection I believe it was but it didn't work. :(

alturic avatar Oct 28 '24 15:10 alturic

Not sure how to improve on this.

maybe add a debounce timer? "do not execute save list when the last event-triggered save was less than 60? seconds ago"? Or "if we saw a WM_ENDSESSION, remember that and do not save on WM_CLOSE then"?

(You know I have no idea about windows GUI programming, just thinking loud)

cron2 avatar Oct 28 '24 15:10 cron2

maybe add a debounce timer?

Sounds like a good idea

is there a way to make the startup shortcut entry include the connection parameter

openvpn-gui.exe --connect foo.ovpn

should work (.ovpn extension maybe omitted)

selvanair avatar Oct 28 '24 16:10 selvanair

Maybe save connections statuses on each status change (on connect and disconnect)? That way it would not matter how app is closed and if it got correct signals on close.

pedjas avatar Jul 11 '25 09:07 pedjas