Files
gluetun/internal/provider/custom/connection.go
T
Quentin McGaw d9cc7dcffb refactor(storage): new storage file structure
- new directory structure containing manifest.json and one json file per provider, by default.
- the manifest.json file can specify a filepath for each vpn provider
- each vpn provider json data file can contain the `"preferred": true` field to enforce it is used even if outdated, unless there is a version mismatch
- `STORAGE_SERVERS_DIRECTORY_PATH` replaces `STORAGE_FILEPATH` (which is now a migration source only). It sets the directory where server manifest and per-provider JSON files are stored (default: `/gluetun/servers/`).
- First-run migration: On startup, gluetun checks for the old /gluetun/servers.json file; if found and no new manifest exists, it automatically migrates all data to /gluetun/servers/ directory structure
- Silent fallback: If legacy file isn't found, uses the new directory path normally
- Legacy cleanup: After successful migration, attempts to remove the old fat JSON file (logs warning only if removal fails, e.g., read-only bind mounts)
2026-05-11 04:53:04 +00:00

68 lines
2.0 KiB
Go

package custom
import (
"fmt"
"github.com/qdm12/gluetun-servers/pkg/constants"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/models"
)
// GetConnection gets the connection from the OpenVPN configuration file.
func (p *Provider) GetConnection(selection settings.ServerSelection, _ bool) (
connection models.Connection, err error,
) {
switch selection.VPN {
case constants.OpenVPN:
return getOpenVPNConnection(p.extractor, selection)
case constants.Wireguard, constants.AmneziaWg:
return getWireguardConnection(selection), nil
default:
return connection, fmt.Errorf("VPN type not supported for custom provider: %s", selection.VPN)
}
}
func getOpenVPNConnection(extractor Extractor,
selection settings.ServerSelection) (
connection models.Connection, err error,
) {
_, connection, err = extractor.Data(*selection.OpenVPN.ConfFile)
if err != nil {
return connection, fmt.Errorf("extracting connection: %w", err)
}
customPort := *selection.OpenVPN.CustomPort
if customPort > 0 {
connection.Port = customPort
}
// assume all custom provider servers support port forwarding
connection.PortForward = true
if len(selection.Names) > 0 {
// Set the server name for PIA port forwarding code used
// together with the custom provider.
connection.ServerName = selection.Names[0]
}
return connection, nil
}
func getWireguardConnection(selection settings.ServerSelection) (
connection models.Connection,
) {
connection = models.Connection{
Type: constants.Wireguard,
IP: selection.Wireguard.EndpointIP,
Port: *selection.Wireguard.EndpointPort,
Protocol: constants.UDP,
PubKey: selection.Wireguard.PublicKey,
PortForward: true, // assume all custom provider servers support port forwarding
}
if len(selection.Names) > 0 {
// Set the server name for PIA port forwarding code used
// together with the custom provider.
connection.ServerName = selection.Names[0]
}
return connection
}