flounder

A simple gemini site builder
Log | Files | Refs | README | LICENSE

commit f538215f8cceaf1c7337329ad4aa3b79977042c2
parent f434d18e0dcfbd41fe123bf9a5b853f8016929a8
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sun, 25 Oct 2020 23:16:08 -0700

qa

Diffstat:
M.gitignore | 1+
Mconfig.go | 3+--
Mflounder.toml | 2+-
Mgemini.go | 9+++++----
Mhttp.go | 2+-
Mmain.go | 11+++++++----
Mtemplates/index.gmi | 10+++++-----
7 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -2,3 +2,4 @@ files/ *.crt *.key *.db +*.log diff --git a/config.go b/config.go @@ -7,13 +7,12 @@ import ( type Config struct { FilesDirectory string TemplatesDirectory string - Hostname string Host string SiteTitle string Debug bool SecretKey string DBFile string - PasswdFile string // TODO remove + LogFile string CookieStoreKey string OkExtensions []string MaxFileSize int diff --git a/flounder.toml b/flounder.toml @@ -6,6 +6,7 @@ Host="localhost:8443" # Folder containing subfolders for each user's files FilesDirectory="./files" +LogFile="./flounder.log" # A wildcard TLS cert TLSCertFile="./server.crt" @@ -19,4 +20,3 @@ DBFile="./flounder.db" MaxFileSize=128000 # 128 KB OkExtensions=["", ".gmi", ".txt", ".jpg", ".jpeg", ".gif", ".png", ".svg", ".webp", ".midi", ".json", ".csv", ".gemini", ".mp3", ".css", ".ttf", ".otf", ".woff", ".woff2"] -# log file diff --git a/gemini.go b/gemini.go @@ -20,12 +20,12 @@ func gmiIndex(w *gmi.ResponseWriter, r *gmi.Request) { files, _ := getIndexFiles() users, _ := getUsers() data := struct { - Domain string + Host string SiteTitle string Files []*File Users []string }{ - Domain: c.Hostname, + Host: c.Host, SiteTitle: c.SiteTitle, Files: files, Users: users, @@ -57,12 +57,13 @@ func runGeminiServer() { if err := server.CertificateStore.Load("./tmpcerts"); err != nil { log.Fatal(err) } + // is this necc? server.GetCertificate = func(hostname string, store *gmi.CertificateStore) *tls.Certificate { - cert, err := store.Lookup(hostname) + cert, err := tls.LoadX509KeyPair(c.TLSCertFile, c.TLSKeyFile) if err != nil { log.Fatal("Invalid TLS cert") } - return cert + return &cert } // replace with wildcard cert diff --git a/http.go b/http.go @@ -394,7 +394,7 @@ func runHTTPServer() { // TODO rate limit login https://github.com/ulule/limiter - wrapped := handlers.LoggingHandler(os.Stdout, serveMux) + wrapped := handlers.LoggingHandler(log.Writer(), serveMux) // handle user files based on subdomain serveMux.HandleFunc("/", userFile) diff --git a/main.go b/main.go @@ -66,10 +66,8 @@ func getIndexFiles() ([]*File, error) { // cache this function if err != nil { return nil, err } - // sort - // truncate sort.Slice(result, func(i, j int) bool { - return result[i].UpdatedTime.Before(result[j].UpdatedTime) + return result[i].UpdatedTime.After(result[j].UpdatedTime) }) if len(result) > 50 { result = result[:50] @@ -149,11 +147,16 @@ func main() { flag.Parse() var err error - log.Println("Loading config", *configPath) c, err = getConfig(*configPath) if err != nil { log.Fatal(err) } + logFile, err := os.OpenFile(c.LogFile, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0644) + if err != nil { + panic(err) + } + mw := io.MultiWriter(os.Stdout, logFile) + log.SetOutput(mw) // Generate self signed cert if does not exist. This is not suitable for production. _, err1 := os.Stat(c.TLSCertFile) diff --git a/templates/index.gmi b/templates/index.gmi @@ -1,15 +1,15 @@ -{{$domain := .Host}} +{{$host := .Host}} # {{.SiteTitle}}! Welcome to flounder, a home for Gemini sites. Flounder hosts small Gemini web pages over https and Gemini. Right now, the only way to make an account is via the https portal, but I'm working on adding alternatives. Feel free to make an account and join if you'd like! -=> gemini://admin.{{$domain}} Admin page -=> https://{{$domain}} View on HTTPS +=> gemini://admin.{{$host}} Admin page +=> https://{{$host}} View on HTTPS ## All Users: -{{range .Users}}=> gemini://{{.}}.{{$domain}} +{{range .Users}}=> gemini://{{.}}.{{$host}} {{end}} ## Recently updated files: -{{range .Files}}=> gemini://{{.Creator}}.{{$domain}}/{{.Name}} {{.Name}} ({{.UpdatedTime}}) +{{range .Files}}=> gemini://{{.Creator}}.{{$host}}/{{.Name}} {{.Name}} ({{.UpdatedTime}}) {{end}}