OpenVPN / openvpn3-linux

OpenVPN 3 Linux client
GNU Affero General Public License v3.0
554 stars 148 forks source link

Remove multiple configs having same name #21

Closed rajeshisnepali closed 3 years ago

rajeshisnepali commented 4 years ago

I was doing the openvpn3-autoload test and ended up with multiple same config name.

image

openvpn3 config-remove -c openvpn-in* --force config-remove: ERROR No configuration profiles found ➜ openvpn3 config-remove -c openvpn-in --force config-remove: ERROR More than one configuration profile was found with the given name

I tried doing above but had no success.
Isn't there any hack to remove all the same configs so that I don't have to manually remove each of them.

dsommers commented 3 years ago

One alternative is to stop the openvpn3-service-configmgr process. Configuration profiles imported by openvpn3-autoload is kept in memory during the lifetime of the Configuration Manager (openvpn3-service-configmgr).

Another approach is to write a Python 3 script which uses the openvpn3 module, which provides the openvpn3.ConfigManager class. This class contains a LookupConfigName() method which returns a list of Configuration objects for each configuration profile matching the given name. Calling the Remove() method in each of these objects will do the trick.

Just beware, the openvpn3-autoload utility is not a proper replacement for openvpn3 session-start, it only provides a solution to situations where you want to automatically load VPN profiles and optionally start them. Typically during boot or login situations. But it can be run manually as well, which is why the manual run approach is considered a workaround for the --auth-user-pass with credentials saved in a file.

You may also write your own utility doing similar things, using the D-Bus API provied by OpenVPN 3 Linux. The openvpn2 and openvpn3-autoload programs are just Python scripts making use of that API. There is also an openvpn3.SessionManager class, which can be used to start VPN sessions and provide user credentials programmatically.

dsommers commented 3 years ago

The complete D-Bus interface is documented here: OpenVPN 3 Linux Client - D-Bus overview