2020-06-13 14:08:29 -04:00
|
|
|
package provider
|
|
|
|
|
|
|
|
|
|
import (
|
2020-10-12 10:55:08 -04:00
|
|
|
"context"
|
|
|
|
|
"net"
|
|
|
|
|
"net/http"
|
|
|
|
|
|
2020-07-26 12:07:06 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/constants"
|
2020-10-12 10:55:08 -04:00
|
|
|
"github.com/qdm12/gluetun/internal/firewall"
|
2020-07-26 12:07:06 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/models"
|
2020-10-12 10:55:08 -04:00
|
|
|
"github.com/qdm12/golibs/files"
|
|
|
|
|
"github.com/qdm12/golibs/logging"
|
2020-06-13 14:08:29 -04:00
|
|
|
)
|
|
|
|
|
|
2020-10-20 02:45:28 +00:00
|
|
|
// Provider contains methods to read and modify the openvpn configuration to connect as a client.
|
2020-06-13 14:08:29 -04:00
|
|
|
type Provider interface {
|
2020-10-12 15:29:58 -04:00
|
|
|
GetOpenVPNConnection(selection models.ServerSelection) (connection models.OpenVPNConnection, err error)
|
2020-10-20 02:45:28 +00:00
|
|
|
BuildConf(connection models.OpenVPNConnection, verbosity, uid, gid int,
|
|
|
|
|
root bool, cipher, auth string, extras models.ExtraConfigOptions) (lines []string)
|
2020-10-12 10:55:08 -04:00
|
|
|
PortForward(ctx context.Context, client *http.Client,
|
|
|
|
|
fileManager files.FileManager, pfLogger logging.Logger, gateway net.IP, fw firewall.Configurator,
|
|
|
|
|
syncState func(port uint16) (pfFilepath models.Filepath))
|
2020-06-13 14:08:29 -04:00
|
|
|
}
|
|
|
|
|
|
2020-10-12 15:29:58 -04:00
|
|
|
func New(provider models.VPNProvider, allServers models.AllServers, timeNow timeNowFunc) Provider {
|
2020-06-13 14:08:29 -04:00
|
|
|
switch provider {
|
|
|
|
|
case constants.PrivateInternetAccess:
|
2020-10-12 15:29:58 -04:00
|
|
|
return newPrivateInternetAccessV4(allServers.Pia.Servers, timeNow)
|
2020-06-13 14:08:29 -04:00
|
|
|
case constants.Mullvad:
|
2020-10-12 15:29:58 -04:00
|
|
|
return newMullvad(allServers.Mullvad.Servers, timeNow)
|
2020-06-13 14:08:29 -04:00
|
|
|
case constants.Windscribe:
|
2020-10-12 15:29:58 -04:00
|
|
|
return newWindscribe(allServers.Windscribe.Servers, timeNow)
|
2020-06-13 14:08:29 -04:00
|
|
|
case constants.Surfshark:
|
2020-10-12 15:29:58 -04:00
|
|
|
return newSurfshark(allServers.Surfshark.Servers, timeNow)
|
2020-06-13 14:08:29 -04:00
|
|
|
case constants.Cyberghost:
|
2020-10-12 15:29:58 -04:00
|
|
|
return newCyberghost(allServers.Cyberghost.Servers, timeNow)
|
2020-07-13 08:04:35 -04:00
|
|
|
case constants.Vyprvpn:
|
2020-10-12 15:29:58 -04:00
|
|
|
return newVyprvpn(allServers.Vyprvpn.Servers, timeNow)
|
2020-07-15 18:14:45 -04:00
|
|
|
case constants.Nordvpn:
|
2020-10-12 15:29:58 -04:00
|
|
|
return newNordvpn(allServers.Nordvpn.Servers, timeNow)
|
2020-07-25 11:19:45 -04:00
|
|
|
case constants.Purevpn:
|
2020-10-12 15:29:58 -04:00
|
|
|
return newPurevpn(allServers.Purevpn.Servers, timeNow)
|
2020-06-13 14:08:29 -04:00
|
|
|
default:
|
|
|
|
|
return nil // should never occur
|
|
|
|
|
}
|
|
|
|
|
}
|