From b93211cdf293d898342b8934cb28a21bd3494cb3 Mon Sep 17 00:00:00 2001 From: Xavier Henner Date: Sat, 17 Aug 2019 11:00:45 +0200 Subject: [PATCH] ssl support --- Makefile | 12 ++++++++++++ go.mod | 2 +- go.sum | 1 - httpd.go | 9 +++++++-- main.go | 2 ++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index c6f6e91..035a262 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,22 @@ all: build build: fmt lint gobuild +vendor: govendor deps: godeps fmt: gofmt lint: golint test: gotest +deb: + debuild -e GOROOT -e PATH -i -us -uc -b + +debclean: + debuild clean + rm -f ../openvpn-mgt + +govendor: + GO111MODULE=on go mod tidy + GO111MODULE=on go mod vendor + gobuild: statik -src=./web/ go build diff --git a/go.mod b/go.mod index b49c50e..fa882a7 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module gitlab.dm.gg/vwf/openvpn-dm-mgt-server +module git.euclide.org/euclide/openvpn-mgt require ( github.com/pyke369/golang-support v0.0.0-20190703174728-34ca97aa79e9 diff --git a/go.sum b/go.sum index b657620..cd48d93 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,3 @@ -git.euclide.org/euclide/openvpn-mgt v0.0.0-20190815091940-a82131c8c881 h1:HXhjoWj3DcY1M5O077Q7kxNhMJmbK6qC8QUSifIUIpU= github.com/pyke369/golang-support v0.0.0-20190703174728-34ca97aa79e9 h1:H1vjQ+Mfc8dFAOTuF541/tScdKoynzll9iKuWgaLLxM= github.com/pyke369/golang-support v0.0.0-20190703174728-34ca97aa79e9/go.mod h1:0XGrzgrEp0fa/+JSV8XZePUwyjnU6C3bMc7Xz2bHHKI= github.com/rakyll/statik v0.1.6 h1:uICcfUXpgqtw2VopbIncslhAmE5hwc4g20TEyEENBNs= diff --git a/httpd.go b/httpd.go index 28d58fa..b00002d 100644 --- a/httpd.go +++ b/httpd.go @@ -114,7 +114,7 @@ func (h *HttpServer) ajaxHandler(w http.ResponseWriter, r *http.Request) { return } -func NewHTTPServer(port string, s *OpenVpnMgt) { +func NewHTTPServer(port, key, cert string, s *OpenVpnMgt) { h := &HttpServer{ Port: port, ovpn: s, @@ -128,5 +128,10 @@ func NewHTTPServer(port string, s *OpenVpnMgt) { http.HandleFunc("/ajax", h.ajaxHandler) http.Handle("/", http.FileServer(statikFS)) - log.Fatal(http.ListenAndServe(port, nil)) + switch { + case key == "" && cert == "": + log.Fatal(http.ListenAndServeTLS(port, cert, key, nil)) + default: + log.Fatal(http.ListenAndServe(port, nil)) + } } diff --git a/main.go b/main.go index 25821c0..a84f7db 100644 --- a/main.go +++ b/main.go @@ -43,6 +43,8 @@ func main() { // time to start the listeners go NewHTTPServer( config.GetString("config.http.port", "127.0.0.01:8080"), + config.GetString("config.http.key", ""), + config.GetString("config.http.cert", ""), server) server.Run()