feat(vpn): VPN_UP_COMMAND and VPN_DOWN_COMMAND options

This commit is contained in:
Quentin McGaw
2026-03-08 16:06:16 +00:00
parent c0af198155
commit 57c53bc19e
14 changed files with 152 additions and 68 deletions
+25 -1
View File
@@ -3,9 +3,22 @@ package vpn
import (
"context"
"errors"
"strings"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants/vpn"
)
func (l *Loop) cleanup() {
settings := l.GetSettings()
var err error
commandString := strings.ReplaceAll(*settings.DownCommand, "{{VPN_INTERFACE}}", getVPNInterface(settings))
err = l.cmder.RunAndLog(context.Background(), commandString, l.logger)
if err != nil {
l.logger.Error("failed to run VPN down command: " + err.Error())
}
for _, vpnPort := range l.vpnInputPorts {
err := l.fw.RemoveAllowedPort(context.Background(), vpnPort)
if err != nil {
@@ -13,7 +26,7 @@ func (l *Loop) cleanup() {
}
}
err := l.publicip.ClearData()
err = l.publicip.ClearData()
if err != nil {
l.logger.Error("clearing public IP data: " + err.Error())
}
@@ -31,3 +44,14 @@ func (l *Loop) cleanup() {
l.logger.Error("stopping boring poll: " + err.Error())
}
}
func getVPNInterface(settings settings.VPN) string {
switch settings.Type {
case vpn.OpenVPN:
return settings.OpenVPN.Interface
case vpn.Wireguard:
return settings.Wireguard.Interface
default:
panic("invalid VPN type: " + settings.Type)
}
}