ssl support

This commit is contained in:
Xavier Henner 2019-08-17 11:00:45 +02:00
parent 2eb4f9e4ea
commit b93211cdf2
5 changed files with 22 additions and 4 deletions

View File

@ -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

2
go.mod
View File

@ -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

1
go.sum
View File

@ -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=

View File

@ -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))
}
}

View File

@ -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()