diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..a04493b --- /dev/null +++ b/.env.example @@ -0,0 +1,18 @@ +# directory where uploads are stored +MINIBIN_UPLOAD_DIR=uploads +MINIBIN_DATABASE_PATH=minibin.sqlite +# the public host of minibin +MINIBIN_HOST=https://example.tld +# the address minibin binds to +MINIBIN_ADDR=localhost:8080 +# max size uploadable in KiB, 97657 is around 100 MB +MINIBIN_MAX_PASTE_KIB=97657 +MINIBIN_MAX_FILE_KIB=97657 +# allowed expiries, shown in the order they are written +# syntax: h(our),d(ay),w(eek),mo(nth),y(ear), 0 = indefinite/no expiry +MINIBIN_EXPIRIES=1h,12h,1d,7d,2w,1mo,6mo,1y,5y,0 +# when set to true, will normalize mime types +# the browser could execute to text/plain to prevent it +MINIBIN_NORMALIZE_MIME_TYPES=true +# prevents uploads with these mime types, separated by commas +MINIBIN_BANNED_MIME_TYPES="application/vnd.microsoft.portable-executable,application/java-archive,application/x-executable" diff --git a/.gitignore b/.gitignore index 2f8ecd8..0661755 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ !/templates/** !/static/** !.prettierrc +!.env.example # !Makefile diff --git a/config.go b/config.go index 7c6d2ea..f04bf71 100644 --- a/config.go +++ b/config.go @@ -16,10 +16,12 @@ type Config struct { MaxFileBytes int64 Expiries []Expiry NormalizeMIMETypes bool + BannedMIMETypes []string DatabasePath string // public host like "https://bin.zip", NOT the address minbin listens on Host string + Addr string } func loadConfig() (Config, error) { @@ -61,10 +63,12 @@ func loadConfig() (Config, error) { MaxPasteBytes: maxPasteKiB * 1024, MaxFileBytes: maxFileKiB * 1024, Expiries: expiries, - NormalizeMIMETypes: envOrDefault("MINIBIN_NORMALIZE_MIME_TYPE", "true") == "true", + NormalizeMIMETypes: envOrDefault("MINIBIN_NORMALIZE_MIME_TYPES", "true") == "true", + BannedMIMETypes: strings.Split(envOrDefault("MINIBIN_BANNED_MIME_TYPES", ""), ","), DatabasePath: envOrDefault("MINIBIN_DATABASE_PATH", "minibin.sqlite"), Host: envOrDefault("MINIBIN_HOST", "http://localhost:8080"), + Addr: envOrDefault("MINIBIN_ADDR", "localhost:8080"), }, nil } diff --git a/main.go b/main.go index 3d869b3..8fb8b2d 100644 --- a/main.go +++ b/main.go @@ -131,9 +131,9 @@ func main() { mux.HandleFunc("POST /{id}/delete", deleteHandler(db, config)) mux.HandleFunc("GET /health", health) - log.Println("listening on http://localhost:8080") + log.Println("listening on", config.Addr) - err = http.ListenAndServe("localhost:8080", mux) + err = http.ListenAndServe(config.Addr, mux) if err != nil { log.Fatal(err) } diff --git a/readme.md b/readme.md index 871513e..cbf1d3f 100644 --- a/readme.md +++ b/readme.md @@ -26,7 +26,8 @@ goals: - [ ] size based expiry - exclusions if below a certain size (like 5mb) - [x] delete content endpoints -- [x] return a page for nojs clients, such as on delete or upload +- [ ] return a page for nojs clients, such as on delete or upload + - need to return one on failures as well 💔💔💔 - [ ] max total storage usage - [x] normalize mime types (like html) - converts specific mime types to text/plain to prevent rendering