2020-03-29 16:42:06 -04:00
|
|
|
package params
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
2020-07-26 12:07:06 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/constants"
|
|
|
|
|
"github.com/qdm12/gluetun/internal/models"
|
2020-03-29 16:42:06 -04:00
|
|
|
libparams "github.com/qdm12/golibs/params"
|
|
|
|
|
)
|
|
|
|
|
|
2020-10-18 17:15:42 -04:00
|
|
|
// GetWindscribeRegions obtains the regions for the Windscribe servers from the
|
2020-10-20 02:45:28 +00:00
|
|
|
// environment variable REGION.
|
2020-10-18 17:15:42 -04:00
|
|
|
func (r *reader) GetWindscribeRegions() (regions []string, err error) {
|
2020-07-23 01:48:18 +00:00
|
|
|
choices := append(constants.WindscribeRegionChoices(), "")
|
2020-10-18 17:15:42 -04:00
|
|
|
return r.envParams.GetCSVInPossibilities("REGION", choices)
|
2020-03-29 16:42:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetMullvadPort obtains the port to reach the Mullvad server on from the
|
2020-10-20 02:45:28 +00:00
|
|
|
// environment variable PORT.
|
|
|
|
|
//nolint:gomnd
|
2020-06-12 17:07:32 +00:00
|
|
|
func (r *reader) GetWindscribePort(protocol models.NetworkProtocol) (port uint16, err error) {
|
|
|
|
|
n, err := r.envParams.GetEnvIntRange("PORT", 0, 65535, libparams.Default("0"))
|
2020-03-29 16:42:06 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return 0, err
|
|
|
|
|
}
|
|
|
|
|
if n == 0 {
|
|
|
|
|
return 0, nil
|
|
|
|
|
}
|
|
|
|
|
switch protocol {
|
|
|
|
|
case constants.TCP:
|
|
|
|
|
switch n {
|
|
|
|
|
case 21, 22, 80, 123, 143, 443, 587, 1194, 3306, 8080, 54783:
|
|
|
|
|
default:
|
|
|
|
|
return 0, fmt.Errorf("port %d is not valid for protocol %s", n, protocol)
|
|
|
|
|
}
|
|
|
|
|
case constants.UDP:
|
|
|
|
|
switch n {
|
|
|
|
|
case 53, 80, 123, 443, 1194, 54783:
|
|
|
|
|
default:
|
|
|
|
|
return 0, fmt.Errorf("port %d is not valid for protocol %s", n, protocol)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return uint16(n), nil
|
|
|
|
|
}
|