From 4416820862dd82dfa1532ce298e1e5c15727bf47 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Wed, 20 Jan 2021 07:15:22 -0700 Subject: [PATCH] include organice in the binary --- README.md | 6 +++--- main.go | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7464889..43ad7a9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ [![builds.sr.ht status](https://builds.sr.ht/~qbit/gavin.svg)](https://builds.sr.ht/~qbit/gavin?) -Simple utility to serve password protected WebDAV. +Simple utility to serve password protected, HTTPS'd WebDAV server and +[Organice](https://github.com/200ok-ch/organice) instance. ## Installation @@ -20,10 +21,9 @@ to host organice via WebDAV. |-----------|---------------------|-----------------------------------------------------------------------------------------| | `-davdir` | /tmp/org | The directory we have our .org files in. | | `-htpass` | /tmp/.htpasswd | Standard `htpasswd` file generated with `htpasswd`. Currently only bcrypt is supported. | -| `-static` | /tmp/organice/build | The directory that contains the built organice files. | ``` -gavin -davdir /tmp/org -htpass /tmp/.htpasswd -static /tmp/organice/build/ +gavin -davdir /tmp/org -htpass /tmp/.htpasswd ``` Now you can open your browser to diff --git a/main.go b/main.go index 75a349a..08727a6 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,8 @@ package main import ( "crypto/tls" + "embed" + _ "embed" "encoding/csv" "flag" "fmt" @@ -19,6 +21,9 @@ import ( "suah.dev/protect" ) +//go:embed organice +var content embed.FS + var ( acmeDomain string test bool @@ -28,7 +33,6 @@ var ( davPath string listen string passPath string - staticDir string users map[string]string ) @@ -48,12 +52,11 @@ func init() { flag.StringVar(&listen, "http", ":8080", "Listen on") flag.StringVar(&passPath, "htpass", fmt.Sprintf("%s/.htpasswd", dir), "Path to .htpasswd file..") flag.StringVar(&davPath, "davpath", "/dav/", "Directory containing files to serve over WebDAV.") - flag.StringVar(&staticDir, "static", dir, "Directory to serve static resources from. Served at '/'.") flag.BoolVar(&test, "test", false, "Enable testing mode (uses staging LetsEncrypt).") flag.Parse() // These are OpenBSD specific protections used to prevent unnecessary file access. - _ = protect.Unveil(staticDir, "r") + _ = protect.Pledge("stdio wpath rpath cpath inet dns unveil") _ = protect.Unveil(passPath, "r") _ = protect.Unveil(davDir, "rwc") _ = protect.Unveil(cacheDir, "rwc") @@ -125,13 +128,18 @@ func main() { }, } - fileServer := http.FileServer(http.Dir(staticDir)) + fileServer := http.FileServer(http.FS(content)) mux := http.NewServeMux() mux.HandleFunc("/", logger(func(w http.ResponseWriter, r *http.Request) { + // embed.FS contains the top level directory 'organice' + // This modifies the request path to match. + r.URL.Path = fmt.Sprintf("/organice%s", r.URL.Path) + httpLog(r) fileServer.ServeHTTP(w, r) })) + mux.HandleFunc(davPath, func(w http.ResponseWriter, r *http.Request) { user, pass, ok := r.BasicAuth() if !(ok && authenticate(user, pass)) {