all repos — flounder @ f538215f8cceaf1c7337329ad4aa3b79977042c2

A small site builder for the Gemini protocol

qa
alex wennerberg alex@alexwennerberg.com
Sun, 25 Oct 2020 23:16:08 -0700
commit

f538215f8cceaf1c7337329ad4aa3b79977042c2

parent

f434d18e0dcfbd41fe123bf9a5b853f8016929a8

7 files changed, 21 insertions(+), 17 deletions(-)

jump to
M .gitignore.gitignore

@@ -2,3 +2,4 @@ files/

*.crt *.key *.db +*.log
M config.goconfig.go

@@ -7,13 +7,12 @@

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
M flounder.tomlflounder.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 @@

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
M gemini.gogemini.go

@@ -20,12 +20,12 @@ }

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

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
M http.gohttp.go

@@ -394,7 +394,7 @@ serveMux.HandleFunc(hostname+"/delete/", deleteFileHandler)

// 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)
M main.gomain.go

@@ -66,10 +66,8 @@ })

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

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)
M templates/index.gmitemplates/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}}