all repos — flounder @ f434d18e0dcfbd41fe123bf9a5b853f8016929a8

A small site builder for the Gemini protocol

more qa
alex wennerberg alex@alexwennerberg.com
Sun, 25 Oct 2020 22:39:27 -0700
commit

f434d18e0dcfbd41fe123bf9a5b853f8016929a8

parent

9bf79136159cacf43fc95e56b467fe1143317c96

3 files changed, 20 insertions(+), 16 deletions(-)

jump to
M admin.goadmin.go

@@ -37,11 +37,11 @@ }

log.Println("Activated user", username) baseIndex := `# Welcome to Flounder! ## About -Flounder is an ultra-lightweight platform for making and sharing small websites. You can get started by editing this page -- remove this content and replace it with whatever you like! It will be live at <your-name>.flounder.online. You can go there right now to see what this page currently looks like. Here is a link to a page which will give you more information about using flounder: -=> https://admin.flounder.online +Welcome to an ultra-lightweight platform for making and sharing small websites. You can get started by editing this page -- remove this content and replace it with whatever you like! It will be live at <your-name>.flounder.online. You can go there right now to see what this page currently looks like. Here is a link to a page which will give you more information about using flounder: +=> //admin.flounder.online And here's a guide to the text format that Flounder uses to create pages, Gemini. These pages are converted into HTML so they can be displayed in a web browser. -=> https://admin.flounder.online/gemini_text_guide.gmi +=> //admin.flounder.online/gemini_text_guide.gmi Have fun!` os.Mkdir(path.Join(c.FilesDirectory, username), os.ModePerm)
M http.gohttp.go

@@ -1,6 +1,7 @@

package main import ( + "bytes" "database/sql" "git.sr.ht/~adnano/gmi" "github.com/gorilla/handlers"

@@ -134,7 +135,7 @@ if !ok {

renderError(w, "Forbidden", 403) return } - r.ParseMultipartForm(10 << 20) + r.ParseMultipartForm(10 << 6) // why does this not work file, fileHeader, err := r.FormFile("file") fileName := filepath.Clean(fileHeader.Filename) defer file.Close()

@@ -143,9 +144,7 @@ log.Println(err)

renderError(w, err.Error(), 400) return } - var dest []byte - file.Read(dest) - log.Println("asdfadf") + dest, _ := ioutil.ReadAll(file) err = checkIfValidFile(fileName, dest) if err != nil { log.Println(err)

@@ -161,7 +160,7 @@ renderError(w, InternalServerErrorMsg, 500)

return } defer f.Close() - io.Copy(f, file) + io.Copy(f, bytes.NewReader(dest)) } http.Redirect(w, r, "/my_site", 302) }

@@ -221,11 +220,11 @@ } else if r.Method == "POST" {

r.ParseForm() name := r.Form.Get("username") password := r.Form.Get("password") - row := DB.QueryRow("SELECT password_hash, approved FROM user where username = $1", name) + row := DB.QueryRow("SELECT password_hash, active FROM user where username = $1", name) var db_password []byte var active bool _ = row.Scan(&db_password, &active) - if !active { + if db_password != nil && !active { data := struct { Error string PageTitle string

@@ -309,10 +308,12 @@ if !isOkUsername(username) {

errors = append(errors, "Username is invalid: can only contain letters, numbers and hypens. Maximum 32 characters.") } hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), 8) // TODO handle error - _, err = DB.Exec("insert into user (username, email, password_hash) values ($1, $2, $3)", username, email, string(hashedPassword)) - if err != nil { - log.Println(err) - errors = append(errors, "Username or email is already used") + if len(errors) == 0 { + _, err = DB.Exec("insert into user (username, email, password_hash) values ($1, $2, $3)", username, email, string(hashedPassword)) + if err != nil { + log.Println(err) + errors = append(errors, "Username or email is already used") + } } if len(errors) > 0 { data := struct {

@@ -344,7 +345,9 @@ extension := path.Ext(fileName)

if r.URL.Path == "/style.css" { http.ServeFile(w, r, path.Join(c.TemplatesDirectory, "static/style.css")) } - if extension == ".gmi" || extension == ".gemini" { + query := r.URL.Query() + _, raw := query["raw"] + if !raw && (extension == ".gmi" || extension == ".gemini") { _, err := os.Stat(fileName) if err != nil { renderError(w, "404: file not found", 404)
M utils.goutils.go

@@ -32,8 +32,9 @@ }

if !found { return fmt.Errorf("Invalid file extension: %s", ext) } + fmt.Println(len(fileBytes)) if len(fileBytes) > c.MaxFileSize { - return fmt.Errorf("File too large. File was %s bytes, Max file size is %s", len(fileBytes), c.MaxFileSize) + return fmt.Errorf("File too large. File was %d bytes, Max file size is %d", len(fileBytes), c.MaxFileSize) } return nil }