2021-02-06 11:05:50 -05:00
|
|
|
package configuration
|
|
|
|
|
|
|
|
|
|
import (
|
2021-07-23 02:34:15 +00:00
|
|
|
"fmt"
|
|
|
|
|
|
2021-02-06 11:05:50 -05:00
|
|
|
"github.com/qdm12/gluetun/internal/constants"
|
2021-08-23 10:25:00 -07:00
|
|
|
"github.com/qdm12/gluetun/internal/models"
|
2021-08-24 13:12:40 +00:00
|
|
|
"github.com/qdm12/golibs/params"
|
2021-02-06 11:05:50 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (settings *Provider) readSurfshark(r reader) (err error) {
|
|
|
|
|
settings.Name = constants.Surfshark
|
|
|
|
|
|
|
|
|
|
settings.ServerSelection.TargetIP, err = readTargetIP(r.env)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-23 10:25:00 -07:00
|
|
|
settings.ServerSelection.Countries, err = r.env.CSVInside("COUNTRY", constants.SurfsharkCountryChoices())
|
2021-02-06 11:05:50 -05:00
|
|
|
if err != nil {
|
2021-08-23 10:25:00 -07:00
|
|
|
return fmt.Errorf("environment variable COUNTRY: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
settings.ServerSelection.Cities, err = r.env.CSVInside("CITY", constants.SurfsharkCityChoices())
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("environment variable CITY: %w", err)
|
2021-02-06 11:05:50 -05:00
|
|
|
}
|
|
|
|
|
|
2021-05-10 01:24:46 +00:00
|
|
|
settings.ServerSelection.Hostnames, err = r.env.CSVInside("SERVER_HOSTNAME", constants.SurfsharkHostnameChoices())
|
|
|
|
|
if err != nil {
|
2021-07-23 02:34:15 +00:00
|
|
|
return fmt.Errorf("environment variable SERVER_HOSTNAME: %w", err)
|
2021-05-10 01:24:46 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-23 10:25:00 -07:00
|
|
|
regionChoices := constants.SurfsharkRegionChoices()
|
|
|
|
|
regionChoices = append(regionChoices, constants.SurfsharkRetroLocChoices()...)
|
|
|
|
|
regions, err := r.env.CSVInside("REGION", regionChoices)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("environment variable REGION: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Retro compatibility
|
|
|
|
|
// TODO remove in v4
|
|
|
|
|
for i, region := range regions {
|
|
|
|
|
locationData, isRetro :=
|
|
|
|
|
surfsharkConvertRetroLoc(region)
|
|
|
|
|
if !isRetro {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
regions[i] = locationData.Region
|
|
|
|
|
settings.ServerSelection.Countries = append(settings.ServerSelection.Countries, locationData.Country)
|
|
|
|
|
if locationData.City != "" { // city is empty for some servers
|
|
|
|
|
settings.ServerSelection.Cities = append(settings.ServerSelection.Cities, locationData.City)
|
|
|
|
|
}
|
|
|
|
|
settings.ServerSelection.Hostnames = append(settings.ServerSelection.Hostnames, locationData.Hostname)
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-24 13:12:40 +00:00
|
|
|
settings.ServerSelection.MultiHopOnly, err = r.env.YesNo("MULTIHOP_ONLY", params.Default("no"))
|
2021-08-23 10:25:00 -07:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("environment variable MULTIHOP_ONLY: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-17 16:54:22 +00:00
|
|
|
return settings.ServerSelection.OpenVPN.readProtocolOnly(r.env)
|
2021-02-06 11:05:50 -05:00
|
|
|
}
|
2021-08-23 10:25:00 -07:00
|
|
|
|
|
|
|
|
// TODO remove in v4.
|
|
|
|
|
func surfsharkConvertRetroLoc(retroLoc string) (
|
|
|
|
|
locationData models.SurfsharkLocationData, isRetro bool) {
|
|
|
|
|
for _, data := range constants.SurfsharkLocationData() {
|
|
|
|
|
if retroLoc == data.RetroLoc {
|
|
|
|
|
return data, true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return locationData, false
|
|
|
|
|
}
|