From d46ac15fbe1b7509ca7a28ef4a8062a1bacef070 Mon Sep 17 00:00:00 2001 From: "kali kaneko (leap communications)" Date: Tue, 21 Apr 2020 19:56:39 +0200 Subject: [feat] handle version --- pkg/helper/helper.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'pkg/helper') 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 . +// 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) -- cgit v1.2.3