summaryrefslogtreecommitdiff
path: root/pkg/backend
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2020-09-02 23:47:05 +0200
committerkali kaneko (leap communications) <kali@leap.se>2021-05-04 14:58:39 +0200
commit4bd6bbd788454367cc89d78543312f333051b840 (patch)
tree6a3d01bf804ea4bd841c013dbe96ffe3df29323a /pkg/backend
parent335bb742b957370bbf40ae77a661559805ab307f (diff)
[feat] expose gateway selector in gui
Diffstat (limited to 'pkg/backend')
-rw-r--r--pkg/backend/api.go9
-rw-r--r--pkg/backend/status.go36
2 files changed, 31 insertions, 14 deletions
diff --git a/pkg/backend/api.go b/pkg/backend/api.go
index 8d6d049..761c03d 100644
--- a/pkg/backend/api.go
+++ b/pkg/backend/api.go
@@ -7,6 +7,7 @@ import (
"encoding/json"
"log"
"strconv"
+ "time"
"unsafe"
"0xacab.org/leap/bitmask-vpn/pkg/bitmask"
@@ -54,10 +55,14 @@ func SwitchOff() {
go stopVPN()
}
-// TODO implement Reconnect?
+// TODO implement Reconnect - do not tear whole fw down in between
func UseGateway(label string) {
- ctx.bm.UseGateway(label)
+ ctx.bm.UseGateway(string(label))
+ time.Sleep(200 * time.Millisecond)
+ SwitchOff()
+ time.Sleep(500 * time.Millisecond)
+ SwitchOn()
}
func UseTransport(label string) {
diff --git a/pkg/backend/status.go b/pkg/backend/status.go
index 16db227..20128ca 100644
--- a/pkg/backend/status.go
+++ b/pkg/backend/status.go
@@ -8,6 +8,7 @@ import (
"0xacab.org/leap/bitmask-vpn/pkg/bitmask"
"0xacab.org/leap/bitmask-vpn/pkg/config"
+ "0xacab.org/leap/bitmask-vpn/pkg/vpn/bonafide"
)
const (
@@ -32,18 +33,20 @@ var updateMutex sync.Mutex
// them.
type connectionCtx struct {
- AppName string `json:"appName"`
- Provider string `json:"provider"`
- TosURL string `json:"tosURL"`
- HelpURL string `json:"helpURL"`
- AskForDonations bool `json:"askForDonations"`
- DonateDialog bool `json:"donateDialog"`
- DonateURL string `json:"donateURL"`
- LoginDialog bool `json:"loginDialog"`
- LoginOk bool `json:"loginOk"`
- Version string `json:"version"`
- Errors string `json:"errors"`
- Status status `json:"status"`
+ AppName string `json:"appName"`
+ Provider string `json:"provider"`
+ TosURL string `json:"tosURL"`
+ HelpURL string `json:"helpURL"`
+ AskForDonations bool `json:"askForDonations"`
+ DonateDialog bool `json:"donateDialog"`
+ DonateURL string `json:"donateURL"`
+ LoginDialog bool `json:"loginDialog"`
+ LoginOk bool `json:"loginOk"`
+ Version string `json:"version"`
+ Errors string `json:"errors"`
+ Status status `json:"status"`
+ Gateways map[string]bonafide.Gateway `json:"gateways"`
+ CurrentGateway string `json:"currentGateway"`
bm bitmask.Bitmask
autostart bitmask.Autostart
cfg *config.Config
@@ -51,6 +54,15 @@ type connectionCtx struct {
func (c connectionCtx) toJson() ([]byte, error) {
statusMutex.Lock()
+ if c.bm != nil {
+ c.Gateways = map[string]bonafide.Gateway{}
+ gateways, _ := c.bm.ListGateways("openvpn")
+ for _, label := range gateways {
+ gw, _ := c.bm.GetGatewayDetails(label)
+ c.Gateways[label] = gw.(bonafide.Gateway)
+ }
+ c.CurrentGateway = c.bm.GetCurrentGateway()
+ }
defer statusMutex.Unlock()
b, err := json.Marshal(c)
if err != nil {