feat(vpn): VPN_ENDPOINT_IP

- Deprecate `OPENVPN_TARGET_IP`
- Deprecate `WIREGUARD_ENDPOINT_IP`
This commit is contained in:
Quentin McGaw
2022-01-28 00:09:58 +00:00
parent 7a8f5f53d5
commit a951110461
3 changed files with 33 additions and 14 deletions

View File

@@ -68,6 +68,8 @@ LABEL \
org.opencontainers.image.description="VPN swiss-knife like client to tunnel to multiple VPN servers using OpenVPN, IPtables, DNS over TLS, Shadowsocks, an HTTP proxy and Alpine Linux"
ENV VPNSP=pia \
VPN_TYPE=openvpn \
# Common VPN options
VPN_ENDPOINT_IP= \
# OpenVPN
OPENVPN_PROTOCOL=udp \
OPENVPN_USER= \
@@ -80,7 +82,6 @@ ENV VPNSP=pia \
OPENVPN_CIPHER= \
OPENVPN_AUTH= \
OPENVPN_PROCESS_USER= \
OPENVPN_TARGET_IP= \
OPENVPN_IPV6=off \
OPENVPN_CUSTOM_CONFIG= \
OPENVPN_INTERFACE=tun0 \
@@ -90,7 +91,6 @@ ENV VPNSP=pia \
WIREGUARD_PRESHARED_KEY= \
WIREGUARD_PUBLIC_KEY= \
WIREGUARD_ADDRESS= \
WIREGUARD_ENDPOINT_IP= \
WIREGUARD_ENDPOINT_PORT= \
WIREGUARD_INTERFACE=wg0 \
# VPN server filtering

View File

@@ -20,7 +20,7 @@ func (r *Reader) readServerSelection(vpnProvider, vpnType string) (
ss settings.ServerSelection, err error) {
ss.VPN = vpnType
ss.TargetIP, err = readOpenVPNTargetIP()
ss.TargetIP, err = r.readOpenVPNTargetIP()
if err != nil {
return ss, err
}
@@ -99,16 +99,23 @@ var (
ErrInvalidIP = errors.New("invalid IP address")
)
func readOpenVPNTargetIP() (ip net.IP, err error) {
s := os.Getenv("OPENVPN_TARGET_IP")
func (r *Reader) readOpenVPNTargetIP() (ip net.IP, err error) {
envKey := "OPENVPN_TARGET_IP"
s := os.Getenv(envKey) // Retro-compatibility
if s == "" {
return nil, nil
envKey = "VPN_ENDPOINT_IP"
s = os.Getenv(envKey)
if s == "" {
return nil, nil
}
} else {
r.onRetroActive("OPENVPN_TARGET_IP", "VPN_ENDPOINT_IP")
}
ip = net.ParseIP(s)
if ip == nil {
return nil, fmt.Errorf("environment variable OPENVPN_TARGET_IP: %w: %s",
ErrInvalidIP, s)
return nil, fmt.Errorf("environment variable %s: %w: %s",
envKey, ErrInvalidIP, s)
}
return ip, nil

View File

@@ -12,7 +12,7 @@ import (
func (r *Reader) readWireguardSelection() (
selection settings.WireguardSelection, err error) {
selection.EndpointIP, err = readWireguardEndpointIP()
selection.EndpointIP, err = r.readWireguardEndpointIP()
if err != nil {
return selection, err
}
@@ -29,16 +29,28 @@ func (r *Reader) readWireguardSelection() (
var ErrIPAddressParse = errors.New("cannot parse IP address")
func readWireguardEndpointIP() (endpointIP net.IP, err error) {
s := os.Getenv("WIREGUARD_ENDPOINT_IP")
func (r *Reader) readWireguardEndpointIP() (endpointIP net.IP, err error) {
const currentKey = "VPN_ENDPOINT_IP"
key := "WIREGUARD_ENDPOINT_IP"
s := os.Getenv(key) // Retro-compatibility
if s == "" {
return nil, nil
key = currentKey
s = os.Getenv(key)
if s == "" {
return nil, nil
}
}
if key != currentKey {
r.onRetroActive(key, currentKey)
}
endpointIP = net.ParseIP(s)
if endpointIP == nil {
return nil, fmt.Errorf("environment variable WIREGUARD_ENDPOINT_IP: %w: %s",
ErrIPAddressParse, s)
return nil, fmt.Errorf("environment variable %s: %w: %s",
key, ErrIPAddressParse, s)
}
return endpointIP, nil
}