Clears port forward status file at exit, fix #125

This commit is contained in:
Quentin McGaw
2020-04-09 12:11:36 +00:00
parent e7a475a303
commit 60cec716b2
3 changed files with 11 additions and 0 deletions

View File

@@ -274,6 +274,11 @@ func main() {
go streamMerger.Merge("openvpn", stream)
go signals.WaitForExit(func(signal string) int {
logger.Warn("Caught OS signal %s, shutting down", signal)
if allSettings.VPNSP == "pia" && allSettings.PIA.PortForwarding.Enabled {
if err := piaConf.ClearPortForward(allSettings.PIA.PortForwarding.Filepath, allSettings.System.UID, allSettings.System.GID); err != nil {
logger.Error(err)
}
}
time.Sleep(100 * time.Millisecond) // wait for other processes to exit
return 0
})

View File

@@ -21,6 +21,7 @@ type Configurator interface {
BuildConf(connections []models.OpenVPNConnection, encryption models.PIAEncryption, verbosity, uid, gid int, root bool, cipher, auth string) (err error)
GetPortForward() (port uint16, err error)
WritePortForward(filepath models.Filepath, port uint16, uid, gid int) (err error)
ClearPortForward(filepath models.Filepath, uid, gid int) (err error)
AllowPortForwardFirewall(device models.VPNDevice, port uint16) (err error)
}

View File

@@ -49,3 +49,8 @@ func (c *configurator) AllowPortForwardFirewall(device models.VPNDevice, port ui
c.logger.Info("%s: Allowing forwarded port %d through firewall", logPrefix, port)
return c.firewall.AllowInputTrafficOnPort(device, port)
}
func (c *configurator) ClearPortForward(filepath models.Filepath, uid, gid int) (err error) {
c.logger.Info("%s: Clearing forwarded port status file %s", logPrefix, filepath)
return c.fileManager.WriteToFile(string(filepath), nil, files.Ownership(uid, gid), files.Permissions(400))
}