flounder

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

commit 32af0a1eec17cd169a70968f8debfc4fb6d9ba83
parent 6a0bb8c4666e72f8d7f8d15c1787e3d334333fc6
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Tue, 30 Nov 2021 08:07:09 -0800

hopefully fix path nightmare

Diffstat:
Madmin.go | 2+-
Mgemini.go | 5++++-
Mhttp.go | 9+++++----
Mutils.go | 2+-
4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/admin.go b/admin.go @@ -103,7 +103,7 @@ And here's a guide to the text format that this site uses to create pages. These Have fun!` // Redundant cleanPath call just in case. - username = cleanPath(username) + username = cleanPath(username)[1:] os.Mkdir(path.Join(c.FilesDirectory, username), os.ModePerm) ioutil.WriteFile(path.Join(c.FilesDirectory, username, "index.gmi"), []byte(baseIndex), 0644) os.Mkdir(path.Join(c.FilesDirectory, username), os.ModePerm) diff --git a/gemini.go b/gemini.go @@ -89,7 +89,7 @@ func gmiPage(_ context.Context, w gmi.ResponseWriter, r *gmi.Request) { if custom != "" { userName = custom } else { - userName = cleanPath(strings.Split(r.URL.Host, ".")[0]) // clean probably unnecessary + userName = cleanPath(strings.Split(r.URL.Host, ".")[0])[1:] // clean probably unnecessary } fileName := cleanPath(r.URL.Path) if strings.HasPrefix(fileName, "/"+HiddenFolder) { @@ -114,6 +114,9 @@ func gmiPage(_ context.Context, w gmi.ResponseWriter, r *gmi.Request) { return } } + if fileName == "" { // mess + fileName = "/" + } gmi.ServeFile(w, os.DirFS(path.Join(c.FilesDirectory, userName)), fileName) } diff --git a/http.go b/http.go @@ -91,7 +91,7 @@ func updatesHandler(w http.ResponseWriter, r *http.Request) { authUser := getAuthUser(r) var username string if strings.HasSuffix(r.URL.Path, "atom.xml") { - username = cleanPath(r.URL.Path[len("/updates/") : len(r.URL.Path)-len("atom.xml")]) + username = cleanPath(r.URL.Path[len("/updates/") : len(r.URL.Path)-len("atom.xml")])[1:] w.Header().Set("Content-Type", "application/atom+xml") // build atom feed files, err := getUpdatedFiles(authUser.IsAdmin, username) @@ -121,7 +121,7 @@ func updatesHandler(w http.ResponseWriter, r *http.Request) { io.Copy(w, strings.NewReader(res)) return } else { - username = cleanPath(r.URL.Path[len("/updates/"):]) + username = cleanPath(r.URL.Path[len("/updates/"):])[1:] } files, err := getUpdatedFiles(authUser.IsAdmin, username) if err != nil { @@ -232,7 +232,8 @@ func editFileHandler(w http.ResponseWriter, r *http.Request) { IsGemlog bool Alert string Warnings []string - }{fileName, string(fileBytes), c, user, c.Host, isText, isGemini(fileName), strings.HasPrefix(fileName, "gemlog"), alert, warnings} + }{fileName[1:], // remove starting slash + string(fileBytes), c, user, c.Host, isText, isGemini(fileName), strings.HasPrefix(fileName, "gemlog"), alert, warnings} err = t.ExecuteTemplate(w, "edit_file.html", data) if err != nil { serverError(w, err) @@ -568,7 +569,7 @@ func userFile(w http.ResponseWriter, r *http.Request) { if custom != "" { userName = custom } else { - userName = cleanPath(strings.Split(r.Host, ".")[0]) // Clean probably unnecessary + userName = cleanPath(strings.Split(r.Host, ".")[0])[1:] // Clean probably unnecessary } unescaped, err := url.QueryUnescape(r.URL.Path) if err != nil { diff --git a/utils.go b/utils.go @@ -147,7 +147,7 @@ func cleanPath(thepath string) string { if strings.Contains(res, "..") { // sanity check return "" } - return res[1:] + return res } func dirSize(path string) (int64, error) {