Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
bitmask-vpn
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
leap
bitmask-vpn
Merge requests
!21
[feat] add support for the helper in go
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
[feat] add support for the helper in go
meskio/bitmask-vpn:helper
into
master
Overview
0
Commits
1
Pipelines
1
Changes
1
Merged
meskio
requested to merge
meskio/bitmask-vpn:helper
into
master
6 years ago
Overview
0
Commits
1
Pipelines
1
Changes
1
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
ce244d75
1 commit,
6 years ago
1 file
+
35
−
21
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
standalone/launcher
_windows
.go
→
standalone/launcher.go
+
35
−
21
Options
// +build
windows
// +build
!linux
// Copyright (C) 2018 LEAP
//
// This program is free software: you can redistribute it and/or modify
@@ -17,57 +17,71 @@
package
bitmask
import
(
"bytes"
"encoding/json"
"net/textproto"
"strings"
"fmt"
"io"
"io/ioutil"
"net/http"
)
const
(
helperAddr
=
"localhost:7171"
helperAddr
=
"
http://
localhost:7171"
)
type
launcher
struct
{
conn
*
textproto
.
Conn
}
func
newLauncher
()
(
*
launcher
,
error
)
{
conn
,
err
:=
textproto
.
Dial
(
"tcp"
,
helperAddr
)
return
&
launcher
{
conn
},
err
return
&
launcher
{},
nil
}
func
(
l
*
launcher
)
close
()
error
{
return
l
.
conn
.
Close
()
return
nil
}
func
(
l
*
launcher
)
openvpnStart
(
flags
...
string
)
error
{
return
l
.
send
(
"openvpn_start"
,
flags
...
)
byteFlags
,
err
:=
json
.
Marshal
(
flags
)
if
err
!=
nil
{
return
err
}
return
l
.
send
(
"/openvpn/start"
,
byteFlags
)
}
func
(
l
*
launcher
)
openvpnStop
()
error
{
return
l
.
send
(
"openvpn
_
stop"
)
return
l
.
send
(
"
/
openvpn
/
stop"
,
nil
)
}
func
(
l
*
launcher
)
firewallStart
(
gateways
[]
gateway
)
error
{
return
nil
ipList
:=
make
([]
string
,
len
(
gateways
))
for
i
,
gw
:=
range
gateways
{
ipList
[
i
]
=
gw
.
IPAddress
}
byteIPs
,
err
:=
json
.
Marshal
(
ipList
)
if
err
!=
nil
{
return
err
}
return
l
.
send
(
"/firewall/start"
,
byteIPs
)
}
func
(
l
*
launcher
)
firewallStop
()
error
{
return
nil
return
l
.
send
(
"/firewall/stop"
,
nil
)
}
func
(
l
*
launcher
)
send
(
cmd
string
,
args
...
string
)
error
{
if
args
==
nil
{
args
=
[]
string
{
"null"
}
func
(
l
*
launcher
)
send
(
path
string
,
body
[]
byte
)
error
{
var
reader
io
.
Reader
if
body
!=
nil
{
reader
=
bytes
.
NewReader
(
body
)
}
command
:=
struct
{
Cmd
string
`json:"cmd"`
Args
string
`json:"args"`
}{
cmd
,
strings
.
Join
(
args
,
" "
)}
bytesCmd
,
err
:=
json
.
Marshal
(
command
)
res
,
err
:=
http
.
Post
(
helperAddr
+
path
,
""
,
reader
)
if
err
!=
nil
{
return
err
}
defer
res
.
Body
.
Close
()
_
,
err
=
l
.
conn
.
Cmd
(
string
(
bytesCmd
))
resErr
,
err
:=
ioutil
.
ReadAll
(
res
.
Body
)
if
len
(
resErr
)
>
0
{
return
fmt
.
Errorf
(
"Helper returned an error: %q"
,
resErr
)
}
return
err
}
Loading