VPNSP value custom for OpenVPN custom config files (#621)
- Retro-compatibility: `OPENVPN_CUSTOM_CONFIG` set implies `VPNSP=custom` - Change: `up` and `down` options are not filtered out - Change: `OPENVPN_INTERFACE` overrides the network interface defined in the configuration file - Change: `PORT` overrides any port found in the configuration file - Feat: config file is read when building the OpenVPN configuration, so it's effectively reloaded on VPN restarts - Feat: extract values from custom file at start to log out valid settings - Maint: `internal/openvpn/extract` package instead of `internal/openvpn/custom` package - Maint: All providers' `BuildConf` method return an error - Maint: rename `CustomConfig` to `ConfFile` in Settings structures
This commit is contained in:
@@ -7,15 +7,14 @@ import (
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/firewall"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/openvpn"
|
||||
"github.com/qdm12/gluetun/internal/openvpn/custom"
|
||||
"github.com/qdm12/gluetun/internal/provider"
|
||||
"github.com/qdm12/golibs/command"
|
||||
"github.com/qdm12/golibs/logging"
|
||||
)
|
||||
|
||||
var (
|
||||
errServerConn = errors.New("failed finding a valid server connection")
|
||||
errBuildConfig = errors.New("failed building configuration")
|
||||
errWriteConfig = errors.New("failed writing configuration to file")
|
||||
errWriteAuth = errors.New("failed writing auth to file")
|
||||
@@ -28,18 +27,12 @@ func setupOpenVPN(ctx context.Context, fw firewall.VPNConnectionSetter,
|
||||
openvpnConf openvpn.Interface, providerConf provider.Provider,
|
||||
settings configuration.VPN, starter command.Starter, logger logging.Logger) (
|
||||
runner vpnRunner, serverName string, err error) {
|
||||
var connection models.Connection
|
||||
var netInterface string
|
||||
var lines []string
|
||||
if settings.OpenVPN.Config == "" {
|
||||
netInterface = settings.OpenVPN.Interface
|
||||
connection, err = providerConf.GetConnection(settings.Provider.ServerSelection)
|
||||
if err == nil {
|
||||
lines = providerConf.BuildConf(connection, settings.OpenVPN)
|
||||
}
|
||||
} else {
|
||||
lines, connection, netInterface, err = custom.BuildConfig(settings.OpenVPN)
|
||||
connection, err := providerConf.GetConnection(settings.Provider.ServerSelection)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("%w: %s", errServerConn, err)
|
||||
}
|
||||
|
||||
lines, err := providerConf.BuildConf(connection, settings.OpenVPN)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("%w: %s", errBuildConfig, err)
|
||||
}
|
||||
@@ -55,7 +48,7 @@ func setupOpenVPN(ctx context.Context, fw firewall.VPNConnectionSetter,
|
||||
}
|
||||
}
|
||||
|
||||
if err := fw.SetVPNConnection(ctx, connection, netInterface); err != nil {
|
||||
if err := fw.SetVPNConnection(ctx, connection, settings.OpenVPN.Interface); err != nil {
|
||||
return nil, "", fmt.Errorf("%w: %s", errFirewall, err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user