summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2020-04-21 19:56:39 +0200
committerkali kaneko (leap communications) <kali@leap.se>2020-04-30 22:10:22 +0200
commitd46ac15fbe1b7509ca7a28ef4a8062a1bacef070 (patch)
tree994259b8671132cd2cad1ed2a98d1b6365be5cef
parent210ea87c05a30d53ca2f96a8082d50cb422b76ce (diff)
[feat] handle version
-rw-r--r--cmd/bitmask-helper/main.go5
-rw-r--r--pkg/config/config.go4
-rw-r--r--pkg/helper/helper.go13
3 files changed, 20 insertions, 2 deletions
diff --git a/cmd/bitmask-helper/main.go b/cmd/bitmask-helper/main.go
index de180ab..3d19046 100644
--- a/cmd/bitmask-helper/main.go
+++ b/cmd/bitmask-helper/main.go
@@ -1,4 +1,4 @@
-// Copyright (C) 2018 LEAP
+// Copyright (C) 2018-2020 LEAP
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -28,6 +28,8 @@ const (
logFile = "helper.log"
)
+var version string
+
func main() {
logger, err := config.ConfigureLogger(path.Join(helper.LogFolder, logFile))
if err != nil {
@@ -35,6 +37,7 @@ func main() {
} else {
defer logger.Close()
}
+ config.Version = version
helper.ServeHTTP(preferredPort)
}
diff --git a/pkg/config/config.go b/pkg/config/config.go
index b7987e4..4228dae 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -1,6 +1,6 @@
// Code generated by go generate; DO NOT EDIT.
// This file was generated by vendorize.py
-// At 2019-10-11 16:05:25
+// At 2020-04-14 18:42:06
package config
@@ -18,6 +18,8 @@ const (
GeolocationAPI = "https://api.black.riseup.net:9001/json"
)
+var Version string
+
/*
CaCert : a string containing a representation of the provider CA, used to
diff --git a/pkg/helper/helper.go b/pkg/helper/helper.go
index b5404c2..b5b90bb 100644
--- a/pkg/helper/helper.go
+++ b/pkg/helper/helper.go
@@ -13,9 +13,16 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
+// This helper is intended to be long-lived, and run with administrator privileges.
+// It will launch a http server and expose a REST API to control OpenVPN and the firewall.
+// At the moment, it is only used in Darwin and Windows - although it could also be used in GNU/Linux systems (but we use the one-shot bitmask-root wrapper in GNU/Linux instead).
+// In Windows, this helper will run on the first available port after the standard one (7171).
+// In other systems, the 7171 port is hardcoded.
+
package helper
import (
+ "0xacab.org/leap/bitmask-vpn/pkg/config"
"encoding/json"
"log"
"net/http"
@@ -33,6 +40,7 @@ func runCommandServer(bindAddr string) {
http.HandleFunc("/firewall/start", firewallStartHandler)
http.HandleFunc("/firewall/stop", firewallStopHandler)
http.HandleFunc("/firewall/isup", firewallIsUpHandler)
+ http.HandleFunc("/version", versionHandler)
log.Fatal(http.ListenAndServe(bindAddr, nil))
}
@@ -136,6 +144,11 @@ func firewallIsUpHandler(w http.ResponseWriter, r *http.Request) {
}
}
+func versionHandler(w http.ResponseWriter, r *http.Request) {
+ w.Write([]byte(config.ApplicationName + "/" + config.Version + "\n"))
+ w.WriteHeader(http.StatusOK)
+}
+
func getArgs(r *http.Request) ([]string, error) {
args := []string{}
decoder := json.NewDecoder(r.Body)