mirror of
https://github.com/qdm12/gluetun.git
synced 2026-05-15 13:00:16 +02:00
feat(vpn): VPN_UP_COMMAND and VPN_DOWN_COMMAND options
This commit is contained in:
+25
-1
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user