diff --git a/cmd/gluetun/main.go b/cmd/gluetun/main.go index f72dd51d..5aef6013 100644 --- a/cmd/gluetun/main.go +++ b/cmd/gluetun/main.go @@ -302,9 +302,10 @@ func _main(ctx context.Context, buildInfo models.BuildInformation, return err } - if err := tun.Check(constants.TunnelDevice); err != nil { + const tunDevice = "/dev/net/tun" + if err := tun.Check(tunDevice); err != nil { logger.Info(err.Error() + "; creating it...") - err = tun.Create(constants.TunnelDevice) + err = tun.Create(tunDevice) if err != nil { return err } diff --git a/internal/cli/clientkey.go b/internal/cli/clientkey.go index e897e5ca..d95c242d 100644 --- a/internal/cli/clientkey.go +++ b/internal/cli/clientkey.go @@ -7,7 +7,7 @@ import ( "os" "strings" - "github.com/qdm12/gluetun/internal/constants" + "github.com/qdm12/gluetun/internal/configuration/sources/files" ) type ClientKeyFormatter interface { @@ -16,7 +16,7 @@ type ClientKeyFormatter interface { func (c *CLI) ClientKey(args []string) error { flagSet := flag.NewFlagSet("clientkey", flag.ExitOnError) - filepath := flagSet.String("path", constants.ClientKey, "file path to the client.key file") + filepath := flagSet.String("path", files.OpenVPNClientKeyPath, "file path to the client.key file") if err := flagSet.Parse(args); err != nil { return err } diff --git a/internal/configuration/sources/files/openvpn.go b/internal/configuration/sources/files/openvpn.go index 151564e9..5064b3ea 100644 --- a/internal/configuration/sources/files/openvpn.go +++ b/internal/configuration/sources/files/openvpn.go @@ -4,16 +4,22 @@ import ( "fmt" "github.com/qdm12/gluetun/internal/configuration/settings" - "github.com/qdm12/gluetun/internal/constants" +) + +const ( + // OpenVPNClientKeyPath is the OpenVPN client key filepath. + OpenVPNClientKeyPath = "/gluetun/client.key" + // OpenVPNClientCertificatePath is the OpenVPN client certificate filepath. + OpenVPNClientCertificatePath = "/gluetun/client.crt" ) func (r *Reader) readOpenVPN() (settings settings.OpenVPN, err error) { - settings.ClientKey, err = ReadFromFile(constants.ClientKey) + settings.ClientKey, err = ReadFromFile(OpenVPNClientKeyPath) if err != nil { return settings, fmt.Errorf("cannot read client key: %w", err) } - settings.ClientCrt, err = ReadFromFile(constants.ClientCertificate) + settings.ClientCrt, err = ReadFromFile(OpenVPNClientCertificatePath) if err != nil { return settings, fmt.Errorf("cannot read client certificate: %w", err) } diff --git a/internal/constants/paths.go b/internal/constants/paths.go index 2a118b7c..c1d7cf35 100644 --- a/internal/constants/paths.go +++ b/internal/constants/paths.go @@ -1,30 +1,8 @@ package constants const ( - // UnboundConf is the file path to the Unbound configuration file. - UnboundConf string = "/etc/unbound/unbound.conf" - // ResolvConf is the file path to the system resolv.conf file. - ResolvConf string = "/etc/resolv.conf" - // CACertificates is the file path to the CA certificates file. - CACertificates string = "/etc/ssl/certs/ca-certificates.crt" // OpenVPNAuthConf is the file path to the OpenVPN auth file. - OpenVPNAuthConf string = "/etc/openvpn/auth.conf" - // OpenVPNConf is the file path to the OpenVPN client configuration file. - OpenVPNConf string = "/etc/openvpn/target.ovpn" - // PIAPortForward is the file path to the port forwarding JSON information for PIA servers. - PIAPortForward string = "/gluetun/piaportforward.json" - // TunnelDevice is the file path to tun device. - TunnelDevice string = "/dev/net/tun" - // NetRoute is the path to the file containing information on the network route. - NetRoute string = "/proc/net/route" - // RootHints is the filepath to the root.hints file used by Unbound. - RootHints string = "/etc/unbound/root.hints" - // RootKey is the filepath to the root.key file used by Unbound. - RootKey string = "/etc/unbound/root.key" - // ClientKey is the client key filepath. - ClientKey string = "/gluetun/client.key" - // ClientCertificate is the client certificate filepath. - ClientCertificate string = "/gluetun/client.crt" + OpenVPNAuthConf = "/etc/openvpn/auth.conf" // ServersData is the server information filepath. ServersData = "/gluetun/servers.json" ) diff --git a/internal/openvpn/openvpn.go b/internal/openvpn/openvpn.go index dcf1f1e5..d3813be6 100644 --- a/internal/openvpn/openvpn.go +++ b/internal/openvpn/openvpn.go @@ -26,7 +26,7 @@ func New(logger Infoer, cmder command.RunStarter, return &Configurator{ logger: logger, cmder: cmder, - configPath: constants.OpenVPNConf, + configPath: configPath, authFilePath: constants.OpenVPNAuthConf, puid: puid, pgid: pgid, diff --git a/internal/openvpn/paths.go b/internal/openvpn/paths.go new file mode 100644 index 00000000..5b20d5e1 --- /dev/null +++ b/internal/openvpn/paths.go @@ -0,0 +1,3 @@ +package openvpn + +const configPath = "/etc/openvpn/target.ovpn" diff --git a/internal/openvpn/start.go b/internal/openvpn/start.go index 377bc3e3..64b1f8c0 100644 --- a/internal/openvpn/start.go +++ b/internal/openvpn/start.go @@ -30,7 +30,7 @@ func start(ctx context.Context, starter command.Starter, version string, flags [ return nil, nil, nil, fmt.Errorf("%w: %s", ErrVersionUnknown, version) } - args := []string{"--config", constants.OpenVPNConf} + args := []string{"--config", configPath} args = append(args, flags...) cmd := exec.CommandContext(ctx, bin, args...) cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} diff --git a/internal/provider/privateinternetaccess/provider.go b/internal/provider/privateinternetaccess/provider.go index 635a4843..8fa33878 100644 --- a/internal/provider/privateinternetaccess/provider.go +++ b/internal/provider/privateinternetaccess/provider.go @@ -19,11 +19,12 @@ type PIA struct { func New(servers []models.PIAServer, randSource rand.Source, timeNow func() time.Time) *PIA { + const jsonPortForwardPath = "/gluetun/piaportforward.json" return &PIA{ servers: servers, timeNow: timeNow, randSource: randSource, - portForwardPath: constants.PIAPortForward, + portForwardPath: jsonPortForwardPath, authFilePath: constants.OpenVPNAuthConf, } }