2021-02-06 16:26:23 +00:00
|
|
|
// Package openvpn defines interfaces to interact with openvpn
|
|
|
|
|
// and run it in a stateful loop.
|
2020-02-06 20:42:46 -05:00
|
|
|
package openvpn
|
|
|
|
|
|
|
|
|
|
import (
|
2020-04-19 18:13:48 +00:00
|
|
|
"context"
|
2020-02-06 20:42:46 -05:00
|
|
|
|
2021-07-23 16:06:19 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/constants"
|
2020-12-29 01:02:47 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/unix"
|
2020-02-06 20:42:46 -05:00
|
|
|
"github.com/qdm12/golibs/command"
|
|
|
|
|
"github.com/qdm12/golibs/logging"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Configurator interface {
|
2021-05-31 18:54:36 +00:00
|
|
|
Version24(ctx context.Context) (version string, err error)
|
|
|
|
|
Version25(ctx context.Context) (version string, err error)
|
2020-12-29 16:44:35 +00:00
|
|
|
WriteAuthFile(user, password string, puid, pgid int) error
|
2020-02-06 20:42:46 -05:00
|
|
|
CheckTUN() error
|
2020-02-08 15:30:28 +00:00
|
|
|
CreateTUN() error
|
2021-07-19 15:10:53 +00:00
|
|
|
Start(ctx context.Context, version string, flags []string) (
|
2021-05-31 18:54:36 +00:00
|
|
|
stdoutLines, stderrLines chan string, waitError chan error, err error)
|
2020-02-06 20:42:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type configurator struct {
|
2021-07-23 16:06:19 +00:00
|
|
|
logger logging.Logger
|
2021-07-24 17:59:22 +00:00
|
|
|
cmder command.RunStarter
|
2021-07-23 16:06:19 +00:00
|
|
|
unix unix.Unix
|
|
|
|
|
authFilePath string
|
|
|
|
|
tunDevPath string
|
2020-02-06 20:42:46 -05:00
|
|
|
}
|
|
|
|
|
|
2021-07-23 18:25:30 +00:00
|
|
|
func NewConfigurator(logger logging.Logger, unix unix.Unix,
|
2021-07-24 17:59:22 +00:00
|
|
|
cmder command.RunStarter) Configurator {
|
2020-02-06 20:42:46 -05:00
|
|
|
return &configurator{
|
2021-07-23 16:06:19 +00:00
|
|
|
logger: logger,
|
2021-07-24 17:59:22 +00:00
|
|
|
cmder: cmder,
|
2021-07-23 16:06:19 +00:00
|
|
|
unix: unix,
|
|
|
|
|
authFilePath: constants.OpenVPNAuthConf,
|
|
|
|
|
tunDevPath: constants.TunnelDevice,
|
2020-02-06 20:42:46 -05:00
|
|
|
}
|
|
|
|
|
}
|