diff options
author | Ruben Pollan <meskio@sindominio.net> | 2019-01-09 12:49:33 +0100 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2019-01-09 12:49:33 +0100 |
commit | f274ec2beaf060cc8bfe4f5eb6f2ce3b5c6aa1f3 (patch) | |
tree | 198930362039654cc03b50703512ce1ca6819003 | |
parent | 9434d2534b0031c20de64ba03518aa7a150b265d (diff) |
[feat] use firewall status to check if the vpn is in failed status
If openvpn is off, but the firewall is up, we are in a fail-close status
and we should report it properly.
- Resolves: #97
-rw-r--r-- | standalone/launcher.go | 10 | ||||
-rw-r--r-- | standalone/launcher_linux.go | 5 | ||||
-rw-r--r-- | standalone/vpn.go | 3 |
3 files changed, 18 insertions, 0 deletions
diff --git a/standalone/launcher.go b/standalone/launcher.go index 03178c5..0a95dd1 100644 --- a/standalone/launcher.go +++ b/standalone/launcher.go @@ -68,6 +68,16 @@ func (l *launcher) firewallStop() error { return l.send("/firewall/stop", nil) } +func (l *launcher) firewallIsUp() bool { + res, err := http.Post(helperAddr+"/firewall/isup", "", nil) + if err != nil { + return false + } + defer res.Body.Close() + + return res.StatusCode == http.StatusOK +} + func (l *launcher) send(path string, body []byte) error { var reader io.Reader if body != nil { diff --git a/standalone/launcher_linux.go b/standalone/launcher_linux.go index a434ecd..5266fa1 100644 --- a/standalone/launcher_linux.go +++ b/standalone/launcher_linux.go @@ -75,6 +75,11 @@ func (l *launcher) firewallStop() error { return runBitmaskRoot("firewall", "stop") } +func (l *launcher) firewallIsUp() bool { + err := runBitmaskRoot("firewall", "isup") + return err == nil +} + func (l *launcher) openvpnRunner(arg ...string) { running := false runOpenvpn := func(arg []string) { diff --git a/standalone/vpn.go b/standalone/vpn.go index e3ecca4..0ff090c 100644 --- a/standalone/vpn.go +++ b/standalone/vpn.go @@ -88,6 +88,9 @@ func (b *Bitmask) GetStatus() (string, error) { if err != nil { status = Off } + if status == Off && b.launch.firewallIsUp() { + return Failed, nil + } return status, nil } |