diff --git a/.gitignore b/.gitignore index afa094d..78347ed 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ wireguard-ui +bindata.go diff --git a/Dockerfile b/Dockerfile index c2db8be..2af5e11 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,13 @@ FROM golang:1.12 AS build WORKDIR /build +RUN go get -u github.com/go-bindata/go-bindata/... &&\ + go get github.com/elazarl/go-bindata-assetfs/... COPY go.mod . COPY go.sum . RUN go mod download COPY . . -RUN go install . +RUN go-bindata-assetfs -prefix html html html/img &&\ + go install . FROM gcr.io/distroless/base:latest COPY --from=build /go/bin/wireguard-ui / diff --git a/go.mod b/go.mod index 10d1fbc..461dc12 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible + github.com/elazarl/go-bindata-assetfs v1.0.0 github.com/google/nftables v0.0.0-20190430150743-07c974e3643d github.com/julienschmidt/httprouter v1.2.0 github.com/koneu/natend v0.0.0-20150829182554-ec0926ea948d // indirect diff --git a/go.sum b/go.sum index ba125e1..649e888 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk= +github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4= github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/nftables v0.0.0-20190430150743-07c974e3643d h1:TC4HtISCtWOTUVPQmq4CAqe0+8R2fvnkJlQn47ep2hI= diff --git a/html/img/wireguard.png b/html/img/wireguard.png new file mode 100644 index 0000000..306dabb Binary files /dev/null and b/html/img/wireguard.png differ diff --git a/html/index.html b/html/index.html new file mode 100644 index 0000000..086af36 --- /dev/null +++ b/html/index.html @@ -0,0 +1,12 @@ + + + Wireguard + + +

Wireguard UI

+ +

+ hello, ui +

+ + diff --git a/server.go b/server.go index 0d60abf..d22da33 100644 --- a/server.go +++ b/server.go @@ -13,6 +13,7 @@ import ( "sync" "github.com/dgrijalva/jwt-go" + "github.com/elazarl/go-bindata-assetfs" "github.com/google/nftables" "github.com/google/nftables/expr" "github.com/julienschmidt/httprouter" @@ -43,6 +44,7 @@ type Server struct { Config *ServerConfig ipAddr net.IP clientIPRange *net.IPNet + assets http.Handler } type WgLink struct { @@ -82,12 +84,14 @@ func NewServer() *Server { config := NewServerConfig(cfgPath) log.Debug("Configuration loaded with public key: ", config.PublicKey) + assets := http.FileServer(&assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, AssetInfo: AssetInfo, Prefix: ""}) s := Server{ serverConfigPath: cfgPath, Config: config, ipAddr: ipAddr, clientIPRange: ipNet, + assets: assets, } log.Debug("Server initialized: ", *dataDir) @@ -271,6 +275,7 @@ func (s *Server) Start() error { router := httprouter.New() router.GET("/", s.Index) + router.GET("/img/*filepath", s.Index) router.GET("/api/v1/users/:user/devices/:device", s.withAuth(s.GetDevice)) router.PUT("/api/v1/users/:user/devices/:device", s.withAuth(s.EditDevice)) router.DELETE("/api/v1/users/:user/devices/:device", s.withAuth(s.DeleteDevice)) @@ -339,7 +344,7 @@ func (s *Server) withAuth(handler httprouter.Handle) httprouter.Handle { func (s *Server) Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { log.Debug("Index") - w.Write([]byte("Hello World")) + s.assets.ServeHTTP(w, r) } func (s *Server) GetDevices(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {