flounder

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

commit 2890e1e0b79d5cc7dec041b2cfe4a475958ab78c
parent 376e8ed93ce9a9f3b8e56de4f49be96458fde336
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Mon, 25 Jan 2021 20:20:59 -0800

Update go-gemini

Diffstat:
Mgemini.go | 20+++++++++-----------
Mgo.mod | 2+-
Mgo.sum | 2++
Mhttp.go | 6++++--
Mlog.go | 7++++++-
Mproxy.go | 6+++---
6 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/gemini.go b/gemini.go @@ -5,6 +5,7 @@ import ( "crypto/tls" "crypto/x509/pkix" gmi "git.sr.ht/~adnano/go-gemini" + "git.sr.ht/~adnano/go-gemini/certificate" "io" "io/ioutil" "log" @@ -62,7 +63,7 @@ func gmiIndex(w *gmi.ResponseWriter, r *gmi.Request) { users, err := getActiveUserNames() if err != nil { log.Println(err) - w.WriteHeader(40, "Internal server error") + w.Status(gmi.StatusTemporaryFailure) } data := struct { Host string @@ -91,21 +92,21 @@ func gmiPage(w *gmi.ResponseWriter, r *gmi.Request) { if fileName == "/" { fileName = "index.gmi" } else if strings.HasPrefix(fileName, "/"+HiddenFolder) { - w.WriteStatus(gmi.StatusNotFound) + w.Status(gmi.StatusNotFound) return } fullPath := path.Join(c.FilesDirectory, userName, fileName) if fileName == "/gemlog" { // temp hack _, err := os.Stat(path.Join(fullPath, "index.gmi")) if err != nil { - w.SetMediaType("text/gemini") + w.Meta("text/gemini") io.Copy(w, strings.NewReader(generateGemfeedPage(userName))) return } } else if fileName == "/gemlog/atom.xml" { _, err := os.Stat(fullPath) if err != nil { - w.SetMediaType("application/atom+xml") + w.Meta("application/atom+xml") feed := generateFeedFromUser(userName) atomString := feed.toAtomFeed() io.Copy(w, strings.NewReader(atomString)) @@ -132,9 +133,9 @@ func runGeminiServer() { err = server.Certificates.Load(c.GeminiCertStore) if err != nil { } - server.CreateCertificate = func(h string) (tls.Certificate, error) { + server.GetCertificate = func(h string) (tls.Certificate, error) { log.Println("Generating certificate for", h) - return gmi.CreateCertificate(gmi.CertificateOptions{ + return certificate.Create(certificate.CreateOptions{ Subject: pkix.Name{ CommonName: h, }, @@ -149,11 +150,8 @@ func runGeminiServer() { var wildcardMux gmi.ServeMux wildcardMux.HandleFunc("/", gmiPage) - server.Register(hostname, &mux) - server.Register("*."+hostname, &wildcardMux) - for k, _ := range domains { // TODO fix - server.Register(k, &wildcardMux) - } + server.Handle(hostname, &mux) + server.Handle("*", &wildcardMux) err = server.ListenAndServe() if err != nil { diff --git a/go.mod b/go.mod @@ -3,7 +3,7 @@ module git.sr.ht/flounder go 1.15 require ( - git.sr.ht/~adnano/go-gemini v0.1.8 + git.sr.ht/~adnano/go-gemini v0.1.14-0.20210125155540-9e89b93bab84 github.com/BurntSushi/toml v0.3.1 github.com/LukeEmmet/html2gemini v0.0.0-20201115162526-e63bbe688236 github.com/emersion/go-webdav v0.3.0 diff --git a/go.sum b/go.sum @@ -12,6 +12,8 @@ git.sr.ht/~adnano/go-gemini v0.1.8 h1:93DxDNXB0bjnfDhZewf+QsEopfuOMh/I4v7ujoJ6WI git.sr.ht/~adnano/go-gemini v0.1.8/go.mod h1:If1VxEWcZDrRt5FeAFnGTcM2Ud1E3BXs3VJ5rnZWKq0= git.sr.ht/~adnano/go-gemini v0.1.10 h1:enuYuY2pC+1BsP1GE73wLIyhXc4r+Ryx6TUubynmSgo= git.sr.ht/~adnano/go-gemini v0.1.10/go.mod h1:If1VxEWcZDrRt5FeAFnGTcM2Ud1E3BXs3VJ5rnZWKq0= +git.sr.ht/~adnano/go-gemini v0.1.14-0.20210125155540-9e89b93bab84 h1:TEt97hCPo34Hjs8jgfeWqQDnZbM+5ne/5emUipyHu8Y= +git.sr.ht/~adnano/go-gemini v0.1.14-0.20210125155540-9e89b93bab84/go.mod h1:If1VxEWcZDrRt5FeAFnGTcM2Ud1E3BXs3VJ5rnZWKq0= git.sr.ht/~sircmpwn/getopt v0.0.0-20201218204720-9961a9c6298f h1:f5axCdaRzGDCihN3o1Lq0ydn0VlkhY+11G0JOyY5qss= git.sr.ht/~sircmpwn/getopt v0.0.0-20201218204720-9961a9c6298f/go.mod h1:wMEGFFFNuPos7vHmWXfszqImLppbc0wEhh6JBfJIUgw= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= diff --git a/http.go b/http.go @@ -603,10 +603,12 @@ func userFile(w http.ResponseWriter, r *http.Request) { var htmlString string if geminiContent == "" { file, _ := os.Open(fullPath) - htmlString = textToHTML(nil, gmi.ParseText(file)) + parse, _ := gmi.ParseText(file) + htmlString = textToHTML(nil, parse) defer file.Close() } else { - htmlString = textToHTML(nil, gmi.ParseText(strings.NewReader(geminiContent))) + parse, _ := gmi.ParseText(strings.NewReader(geminiContent)) + htmlString = textToHTML(nil, parse) } favicon := getFavicon(userName) hostname := strings.Split(r.Host, ":")[0] diff --git a/log.go b/log.go @@ -159,7 +159,12 @@ func appendQuoted(buf []byte, s string) []byte { // Anonymize user and IP? func logGemini(r *gmi.Request) { - ipAddr := r.RemoteAddr.String() + var ipAddr string + if r.RemoteAddr != nil { + ipAddr = r.RemoteAddr.String() + } else { + ipAddr = "" + } host, _, err := net.SplitHostPort(ipAddr) if err != nil { host = ipAddr diff --git a/proxy.go b/proxy.go @@ -37,8 +37,7 @@ func proxyGemini(w http.ResponseWriter, r *http.Request) { req.URL, err = url.Parse(fmt.Sprintf("gemini://%s/", spath[1])) } client := gemini.Client{ - Timeout: 60 * time.Second, - InsecureSkipTrust: true, + Timeout: 60 * time.Second, } if h := (url.URL{Host: req.Host}); h.Port() == "" { @@ -111,7 +110,8 @@ func proxyGemini(w http.ResponseWriter, r *http.Request) { } w.Header().Add("Content-Type", "text/html") - htmlString := textToHTML(req.URL, gemini.ParseText(resp.Body)) + parse, _ := gemini.ParseText(resp.Body) + htmlString := textToHTML(req.URL, parse) if strings.HasSuffix(r.URL.Path, "/") { r.URL.Path = path.Dir(r.URL.Path) }