feat(vpn): VPN_ENDPOINT_PORT

- Deprecate `OPENVPN_PORT`
- Deprecate `WIREGUARD_ENDPOINT_PORT`
This commit is contained in:
Quentin McGaw
2022-01-28 00:10:23 +00:00
parent a951110461
commit ea143c0c9a
3 changed files with 26 additions and 12 deletions

View File

@@ -61,16 +61,23 @@ func (r *Reader) readOpenVPNProtocol() (tcp *bool, err error) {
}
func (r *Reader) readOpenVPNCustomPort() (customPort *uint16, err error) {
key := "OPENVPN_PORT"
s := os.Getenv(key)
const currentKey = "VPN_ENDPOINT_PORT"
key := "PORT"
s := os.Getenv(key) // Retro-compatibility
if s == "" {
// Retro-compatibility
key = "PORT"
key = "OPENVPN_PORT" // Retro-compatibility
s = os.Getenv(key)
if s == "" {
key = currentKey
s = os.Getenv(key)
if s == "" {
return nil, nil //nolint:nilnil
}
r.onRetroActive("PORT", "OPENVPN_PORT")
}
}
if key != currentKey {
r.onRetroActive(key, currentKey)
}
customPort = new(uint16)

View File

@@ -55,16 +55,23 @@ func (r *Reader) readWireguardEndpointIP() (endpointIP net.IP, err error) {
}
func (r *Reader) readWireguardCustomPort() (customPort *uint16, err error) {
key := "WIREGUARD_ENDPOINT_PORT"
const currentKey = "VPN_ENDPOINT_PORT"
key := "WIREGUARD_PORT" // Retro-compatibility
s := os.Getenv(key)
if s == "" {
// Retro-compatibility
key = "WIREGUARD_PORT"
key = "WIREGUARD_ENDPOINT_PORT" // Retro-compatibility
s = os.Getenv(key)
if s == "" {
key = currentKey
s = os.Getenv(key)
if s == "" {
return nil, nil //nolint:nilnil
}
r.onRetroActive("WIREGUARD_PORT", "WIREGUARD_ENDPOINT_PORT")
}
}
if key != currentKey {
r.onRetroActive(key, currentKey)
}
customPort = new(uint16)

View File

@@ -53,7 +53,7 @@ func getWireguardConnection(selection settings.ServerSelection) (
}
}
// Port found is overridden by custom port set with `PORT` or `WIREGUARD_ENDPOINT_PORT`.
// Port found is overridden by custom port set with `VPN_ENDPOINT_PORT`.
func getPort(foundPort uint16, selection settings.ServerSelection) (port uint16) {
return utils.GetPort(selection, foundPort, foundPort, foundPort)
}