blob: ff8c1bbe2a3a5479a141f746b1404cf40f80e172 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
/* All the exported functions should be added here */
package backend
import (
"C"
"log"
"strconv"
"unsafe"
"0xacab.org/leap/bitmask-vpn/pkg/bitmask"
"0xacab.org/leap/bitmask-vpn/pkg/config/version"
"0xacab.org/leap/bitmask-vpn/pkg/pickle"
)
func SwitchOn() {
go setStatus(starting)
go startVPN()
}
func SwitchOff() {
go setStatus(stopping)
go stopVPN()
}
func Quit() {
if ctx.Status != off {
go setStatus(stopping)
ctx.cfg.SetUserStoppedVPN(false)
} else {
ctx.cfg.SetUserStoppedVPN(true)
}
if ctx.bm != nil {
ctx.bm.Close()
}
}
func DonateAccepted() {
donateAccepted()
}
func SubscribeToEvent(event string, f unsafe.Pointer) {
subscribe(event, f)
}
type InitOpts struct {
Provider string
AppName string
SkipLaunch bool
}
func InitializeBitmaskContext(opts *InitOpts) {
p := bitmask.GetConfiguredProvider()
opts.Provider = p.Provider
opts.AppName = p.AppName
initOnce.Do(func() { initializeContext(opts) })
runDonationReminder()
if ctx.bm != nil {
go ctx.updateStatus()
}
}
func RefreshContext() *C.char {
c, _ := ctx.toJson()
return C.CString(string(c))
}
func InstallHelpers() {
pickle.InstallHelpers()
}
func EnableMockBackend() {
log.Println("[+] Mocking ui interaction on port 8080. \nTry 'curl localhost:8080/{on|off|failed}' to toggle status.")
go enableMockBackend()
}
func EnableWebAPI(port string) {
intPort, err := strconv.Atoi(port)
if err != nil {
log.Fatal("Cannot parse port", port)
}
go enableWebAPI(intPort)
}
/* these two are a bit redundant since we already add them to ctx. however, we
want to have them available before everything else, to be able to parse cli
arguments. In the long run, we probably want to move all vendoring to qt, so
this probably should not live in the backend. */
func GetVersion() *C.char {
return C.CString(version.VERSION)
}
func GetAppName() *C.char {
p := bitmask.GetConfiguredProvider()
return C.CString(p.AppName)
}
|