Repurpose OPENVPN_TARGET_IP for #229
This commit is contained in:
@@ -43,6 +43,10 @@ func (c *cyberghost) filterServers(region, group string) (servers []models.Cyber
|
||||
}
|
||||
|
||||
func (c *cyberghost) GetOpenVPNConnection(selection models.ServerSelection) (connection models.OpenVPNConnection, err error) {
|
||||
if selection.TargetIP != nil {
|
||||
return models.OpenVPNConnection{IP: selection.TargetIP, Port: 443, Protocol: selection.Protocol}, nil
|
||||
}
|
||||
|
||||
servers := c.filterServers(selection.Region, selection.Group)
|
||||
if len(servers) == 0 {
|
||||
return connection, fmt.Errorf("no server found for region %q and group %q", selection.Region, selection.Group)
|
||||
@@ -51,20 +55,10 @@ func (c *cyberghost) GetOpenVPNConnection(selection models.ServerSelection) (con
|
||||
var connections []models.OpenVPNConnection
|
||||
for _, server := range servers {
|
||||
for _, IP := range server.IPs {
|
||||
if selection.TargetIP != nil {
|
||||
if selection.TargetIP.Equal(IP) {
|
||||
return models.OpenVPNConnection{IP: IP, Port: 443, Protocol: selection.Protocol}, nil
|
||||
}
|
||||
} else {
|
||||
connections = append(connections, models.OpenVPNConnection{IP: IP, Port: 443, Protocol: selection.Protocol})
|
||||
}
|
||||
connections = append(connections, models.OpenVPNConnection{IP: IP, Port: 443, Protocol: selection.Protocol})
|
||||
}
|
||||
}
|
||||
|
||||
if selection.TargetIP != nil {
|
||||
return connection, fmt.Errorf("target IP %s not found in IP addresses", selection.TargetIP)
|
||||
}
|
||||
|
||||
return pickRandomConnection(connections, c.randSource), nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user