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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Vladimir KozLove
bitmask-vpn
Commits
ce244d75
Verified
Commit
ce244d75
authored
6 years ago
by
meskio
Browse files
Options
Downloads
Patches
Plain Diff
[feat] add support for the helper in go
parent
e2435511
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
standalone/launcher.go
+35
-21
35 additions, 21 deletions
standalone/launcher.go
with
35 additions
and
21 deletions
standalone/launcher
_windows
.go
→
standalone/launcher.go
+
35
−
21
View file @
ce244d75
// +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
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment