summaryrefslogtreecommitdiff
path: root/pkg/helper/helper.go
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2020-04-22 23:52:04 +0200
committerkali kaneko (leap communications) <kali@leap.se>2020-04-30 22:10:27 +0200
commite05f5aa352f6ba55562a0afade0fa9046aeaf0d1 (patch)
treee225f9c4cb33cd5d0b0fb2b1c9b4a07c47d836a4 /pkg/helper/helper.go
parente3baef0e9e36e1b0f3e899ef8e83520004b50a29 (diff)
[pkg] initialize service early for windows
Diffstat (limited to 'pkg/helper/helper.go')
-rw-r--r--pkg/helper/helper.go20
1 files changed, 13 insertions, 7 deletions
diff --git a/pkg/helper/helper.go b/pkg/helper/helper.go
index b5b90bb..4fa88b2 100644
--- a/pkg/helper/helper.go
+++ b/pkg/helper/helper.go
@@ -33,7 +33,19 @@ type openvpnT struct {
cmd *exec.Cmd
}
-func runCommandServer(bindAddr string) {
+// startHelper is the main entrypoint. It can react to cli args (used to install or manage the service in windows), and
+// eventually will start the http server.
+func StartHelper(port int) {
+ initializeService(port)
+ parseCliArgs()
+ daemonize()
+ runServer(port)
+}
+
+// serveHTTP will start the HTTP server that exposes the firewall and openvpn api.
+// this can be called at different times by the different implementations of the helper.
+func serveHTTP(bindAddr string) {
+ log.Println("Starting HTTP server at", bindAddr)
openvpn := openvpnT{nil}
http.HandleFunc("/openvpn/start", openvpn.start)
http.HandleFunc("/openvpn/stop", openvpn.stop)
@@ -45,12 +57,6 @@ func runCommandServer(bindAddr string) {
log.Fatal(http.ListenAndServe(bindAddr, nil))
}
-func ServeHTTP(port int) {
- parseCliArgs()
- daemonize()
- doHandleCommands(port)
-}
-
func (openvpn *openvpnT) start(w http.ResponseWriter, r *http.Request) {
args, err := getArgs(r)
if err != nil {