summaryrefslogtreecommitdiff
path: root/pkg/backend
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2020-09-24 12:24:48 +0200
committerRuben Pollan <meskio@sindominio.net>2020-09-24 16:50:04 +0200
commit998b5cb54ad23be1f6df0ee8abd08af5614f38db (patch)
treeaafb1c6f11ba23da120b29170ed712d6a07d5336 /pkg/backend
parent3a74c28cce41fe783d9dde707ebb6de941d5cf0a (diff)
[feat] send cmd flags to the go backend
Also disable autostart if manual quit, remove custom printer that was used for i18n and disable previous autostart if -disable-autostart We didn't disable autostart after the migration to qt. - Resolves: #355 #289
Diffstat (limited to 'pkg/backend')
-rw-r--r--pkg/backend/api.go12
-rw-r--r--pkg/backend/init.go36
-rw-r--r--pkg/backend/status.go1
3 files changed, 44 insertions, 5 deletions
diff --git a/pkg/backend/api.go b/pkg/backend/api.go
index 9706bdf..a8d16a3 100644
--- a/pkg/backend/api.go
+++ b/pkg/backend/api.go
@@ -11,8 +11,8 @@ import (
"0xacab.org/leap/bitmask-vpn/pkg/bitmask"
"0xacab.org/leap/bitmask-vpn/pkg/config/version"
- "0xacab.org/leap/bitmask-vpn/pkg/pid"
"0xacab.org/leap/bitmask-vpn/pkg/pickle"
+ "0xacab.org/leap/bitmask-vpn/pkg/pid"
)
func Login(username, password string) {
@@ -48,6 +48,7 @@ func SwitchOff() {
}
func Quit() {
+ ctx.autostart.Disable()
if ctx.Status != off {
go setStatus(stopping)
ctx.cfg.SetUserStoppedVPN(false)
@@ -74,8 +75,11 @@ type Providers struct {
}
type InitOpts struct {
- ProviderOptions *bitmask.ProviderOpts
- SkipLaunch bool
+ ProviderOptions *bitmask.ProviderOpts
+ SkipLaunch bool
+ Obfs4 bool
+ DisableAutostart bool
+ StartVPN string
}
func InitOptsFromJSON(provider, providersJSON string) *InitOpts {
@@ -88,7 +92,7 @@ func InitOptsFromJSON(provider, providersJSON string) *InitOpts {
panic("BUG: we do not support multi-provider yet")
}
providerOpts := &providers.Data[0]
- return &InitOpts{providerOpts, false}
+ return &InitOpts{ProviderOptions: providerOpts}
}
func InitializeBitmaskContext(opts *InitOpts) {
diff --git a/pkg/backend/init.go b/pkg/backend/init.go
index c0d8f37..842c91b 100644
--- a/pkg/backend/init.go
+++ b/pkg/backend/init.go
@@ -52,6 +52,7 @@ func initializeBitmask(errCh chan string, opts *InitOpts) {
}
bitmask.InitializeLogger()
ctx.cfg = config.ParseConfig()
+ setConfigOpts(opts, ctx.cfg)
err := pid.AcquirePID()
if err != nil {
@@ -60,12 +61,13 @@ func initializeBitmask(errCh chan string, opts *InitOpts) {
return
}
- b, err := bitmask.InitializeBitmask(opts.SkipLaunch)
+ b, err := bitmask.InitializeBitmask(ctx.cfg)
if err != nil {
log.Println("error: cannot initialize bitmask")
errCh <- err.Error()
return
}
+ ctx.autostart = initializeAutostart(ctx.cfg)
helpers, privilege, err := b.VPNCheck()
@@ -85,3 +87,35 @@ func initializeBitmask(errCh chan string, opts *InitOpts) {
ctx.bm = b
}
+
+func setConfigOpts(opts *InitOpts, conf *config.Config) {
+ conf.SkipLaunch = opts.SkipLaunch
+ if opts.StartVPN != "" {
+ if opts.StartVPN != "on" && opts.StartVPN != "off" {
+ log.Println("-start-vpn should be 'on' or 'off'")
+ } else {
+ conf.StartVPN = opts.StartVPN == "on"
+ }
+ }
+ if opts.Obfs4 {
+ conf.Obfs4 = opts.Obfs4
+ }
+ if opts.DisableAutostart {
+ conf.DisableAustostart = opts.DisableAutostart
+ }
+}
+
+func initializeAutostart(conf *config.Config) bitmask.Autostart {
+ autostart := bitmask.NewAutostart(config.ApplicationName, "")
+ if conf.SkipLaunch || conf.DisableAustostart {
+ autostart.Disable()
+ autostart = &bitmask.DummyAutostart{}
+ }
+
+ err := autostart.Enable()
+ if err != nil {
+ log.Printf("Error enabling autostart: %v", err)
+ }
+ return autostart
+
+}
diff --git a/pkg/backend/status.go b/pkg/backend/status.go
index f06d26d..ffa79fc 100644
--- a/pkg/backend/status.go
+++ b/pkg/backend/status.go
@@ -43,6 +43,7 @@ type connectionCtx struct {
Errors string `json:"errors"`
Status status `json:"status"`
bm bitmask.Bitmask
+ autostart bitmask.Autostart
cfg *config.Config
}