diff options
author | kali kaneko (leap communications) <kali@leap.se> | 2020-09-02 21:38:13 +0200 |
---|---|---|
committer | kali kaneko (leap communications) <kali@leap.se> | 2021-05-04 14:58:39 +0200 |
commit | 335bb742b957370bbf40ae77a661559805ab307f (patch) | |
tree | 3d8b9a8023b1bcca2b531bf57b1fd846916f4a8e /pkg/vpn/status.go | |
parent | 68f566cf7fddbe9e5eb08c4c07a76375148b682b (diff) |
[feat] expose gateway selection in webapi
Diffstat (limited to 'pkg/vpn/status.go')
-rw-r--r-- | pkg/vpn/status.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/pkg/vpn/status.go b/pkg/vpn/status.go index 7901276..005db7e 100644 --- a/pkg/vpn/status.go +++ b/pkg/vpn/status.go @@ -73,13 +73,23 @@ func (b *Bitmask) eventHandler(eventCh <-chan openvpn.Event) { b.statusCh <- status } if statusName == "CONNECTED" { - b.onGateway = strings.Split(stateEvent.String(), ": ")[1] - log.Println(">>> CONNECTED TO", b.onGateway) + ip := strings.Split(stateEvent.String(), ": ")[1] + gw, err := b.bonafide.GetGatewayByIP(ip) + if err == nil { + b.onGateway = gw + log.Println("Connected to gateway:", b.onGateway.Label) + } else { + log.Println("ERROR: connected to unknown gateway", ip) + } } } b.statusCh <- Off } +func (b *Bitmask) GetCurrentGateway() string { + return b.onGateway.Label +} + func (b *Bitmask) getOpenvpnState() (string, error) { if b.managementClient == nil { return "", fmt.Errorf("No management connected") |