Feat: specify Openvpn flags with OPENVPN_FLAGS
This commit is contained in:
@@ -73,6 +73,7 @@ ENV VPNSP=pia \
|
|||||||
PROTOCOL=udp \
|
PROTOCOL=udp \
|
||||||
OPENVPN_VERSION=2.5 \
|
OPENVPN_VERSION=2.5 \
|
||||||
OPENVPN_VERBOSITY=1 \
|
OPENVPN_VERBOSITY=1 \
|
||||||
|
OPENVPN_FLAGS= \
|
||||||
OPENVPN_ROOT=yes \
|
OPENVPN_ROOT=yes \
|
||||||
OPENVPN_TARGET_IP= \
|
OPENVPN_TARGET_IP= \
|
||||||
OPENVPN_IPV6=off \
|
OPENVPN_IPV6=off \
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ type OpenVPN struct {
|
|||||||
User string `json:"user"`
|
User string `json:"user"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
Verbosity int `json:"verbosity"`
|
Verbosity int `json:"verbosity"`
|
||||||
|
Flags []string `json:"flags"`
|
||||||
MSSFix uint16 `json:"mssfix"`
|
MSSFix uint16 `json:"mssfix"`
|
||||||
Root bool `json:"run_as_root"`
|
Root bool `json:"run_as_root"`
|
||||||
Cipher string `json:"cipher"`
|
Cipher string `json:"cipher"`
|
||||||
@@ -35,6 +36,10 @@ func (settings *OpenVPN) lines() (lines []string) {
|
|||||||
|
|
||||||
lines = append(lines, indent+lastIndent+"Verbosity level: "+strconv.Itoa(settings.Verbosity))
|
lines = append(lines, indent+lastIndent+"Verbosity level: "+strconv.Itoa(settings.Verbosity))
|
||||||
|
|
||||||
|
if len(settings.Flags) > 0 {
|
||||||
|
lines = append(lines, indent+lastIndent+"Flags: "+strings.Join(settings.Flags, " "))
|
||||||
|
}
|
||||||
|
|
||||||
if settings.Root {
|
if settings.Root {
|
||||||
lines = append(lines, indent+lastIndent+"Run as root: enabled")
|
lines = append(lines, indent+lastIndent+"Run as root: enabled")
|
||||||
}
|
}
|
||||||
@@ -120,6 +125,15 @@ func (settings *OpenVPN) read(r reader) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
settings.Flags = []string{}
|
||||||
|
flagsStr, err := r.env.Get("OPENVPN_FLAGS")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if flagsStr != "" {
|
||||||
|
settings.Flags = strings.Fields(flagsStr)
|
||||||
|
}
|
||||||
|
|
||||||
settings.Root, err = r.env.YesNo("OPENVPN_ROOT", params.Default("yes"))
|
settings.Root, err = r.env.YesNo("OPENVPN_ROOT", params.Default("yes"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ import (
|
|||||||
func Test_OpenVPN_JSON(t *testing.T) {
|
func Test_OpenVPN_JSON(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
in := OpenVPN{
|
in := OpenVPN{
|
||||||
Root: true,
|
Root: true,
|
||||||
|
Flags: []string{},
|
||||||
Provider: Provider{
|
Provider: Provider{
|
||||||
Name: "name",
|
Name: "name",
|
||||||
},
|
},
|
||||||
@@ -22,6 +23,7 @@ func Test_OpenVPN_JSON(t *testing.T) {
|
|||||||
"user": "",
|
"user": "",
|
||||||
"password": "",
|
"password": "",
|
||||||
"verbosity": 0,
|
"verbosity": 0,
|
||||||
|
"flags": [],
|
||||||
"mssfix": 0,
|
"mssfix": 0,
|
||||||
"run_as_root": true,
|
"run_as_root": true,
|
||||||
"cipher": "",
|
"cipher": "",
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const (
|
|||||||
binOpenvpn25 = "openvpn"
|
binOpenvpn25 = "openvpn"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *configurator) Start(ctx context.Context, version string) (
|
func (c *configurator) Start(ctx context.Context, version string, flags []string) (
|
||||||
stdoutLines, stderrLines chan string, waitError chan error, err error) {
|
stdoutLines, stderrLines chan string, waitError chan error, err error) {
|
||||||
var bin string
|
var bin string
|
||||||
switch version {
|
switch version {
|
||||||
@@ -32,7 +32,9 @@ func (c *configurator) Start(ctx context.Context, version string) (
|
|||||||
|
|
||||||
c.logger.Info("starting OpenVPN " + version)
|
c.logger.Info("starting OpenVPN " + version)
|
||||||
|
|
||||||
cmd := exec.CommandContext(ctx, bin, "--config", constants.OpenVPNConf)
|
args := []string{"--config", constants.OpenVPNConf}
|
||||||
|
args = append(args, flags...)
|
||||||
|
cmd := exec.CommandContext(ctx, bin, args...)
|
||||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||||
|
|
||||||
return c.commander.Start(cmd)
|
return c.commander.Start(cmd)
|
||||||
|
|||||||
@@ -169,7 +169,8 @@ func (l *looper) Run(ctx context.Context, done chan<- struct{}) {
|
|||||||
|
|
||||||
openvpnCtx, openvpnCancel := context.WithCancel(context.Background())
|
openvpnCtx, openvpnCancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
stdoutLines, stderrLines, waitError, err := l.conf.Start(openvpnCtx, settings.Version)
|
stdoutLines, stderrLines, waitError, err := l.conf.Start(
|
||||||
|
openvpnCtx, settings.Version, settings.Flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
openvpnCancel()
|
openvpnCancel()
|
||||||
l.signalOrSetStatus(constants.Crashed)
|
l.signalOrSetStatus(constants.Crashed)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ type Configurator interface {
|
|||||||
WriteAuthFile(user, password string, puid, pgid int) error
|
WriteAuthFile(user, password string, puid, pgid int) error
|
||||||
CheckTUN() error
|
CheckTUN() error
|
||||||
CreateTUN() error
|
CreateTUN() error
|
||||||
Start(ctx context.Context, version string) (
|
Start(ctx context.Context, version string, flags []string) (
|
||||||
stdoutLines, stderrLines chan string, waitError chan error, err error)
|
stdoutLines, stderrLines chan string, waitError chan error, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user