From 60ec29612bd8c396870dad3adf42f6a8c76f3e17 Mon Sep 17 00:00:00 2001 From: Seednode Date: Fri, 5 Jan 2024 19:00:15 -0600 Subject: [PATCH] Add --redact option to hide admin prefix in log output --- README.md | 2 ++ cmd/root.go | 4 +++- cmd/web.go | 6 +++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index db5bf08..bedd5a8 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,7 @@ Usage: Flags: --admin-prefix string string to prepend to administrative paths -a, --all enable all supported file types + --allow-empty allow specifying paths containing no supported files --audio enable support for audio files --binary-prefix use IEC binary prefixes instead of SI decimal prefixes -b, --bind string address to bind to (default "0.0.0.0") @@ -166,6 +167,7 @@ Flags: --prefix string root path for http handlers (for reverse proxying) (default "/") --profile register net/http/pprof handlers -r, --recursive recurse into subdirectories + --redact redact admin prefix in log output --refresh enable automatic page refresh via query parameter --russian remove selected images after serving -s, --sort enable sorting diff --git a/cmd/root.go b/cmd/root.go index 325fef6..ea559e4 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -14,7 +14,7 @@ import ( const ( AllowedCharacters string = `^[A-z0-9.\-_]+$` - ReleaseVersion string = "3.8.0" + ReleaseVersion string = "3.9.0" ) var ( @@ -48,6 +48,7 @@ var ( Prefix string Profile bool Recursive bool + Redact bool Refresh bool Russian bool Sorting bool @@ -140,6 +141,7 @@ func init() { rootCmd.Flags().StringVar(&Prefix, "prefix", "/", "root path for http handlers (for reverse proxying)") rootCmd.Flags().BoolVar(&Profile, "profile", false, "register net/http/pprof handlers") rootCmd.Flags().BoolVarP(&Recursive, "recursive", "r", false, "recurse into subdirectories") + rootCmd.Flags().BoolVar(&Redact, "redact", false, "redact admin prefix in log output") rootCmd.Flags().BoolVar(&Refresh, "refresh", false, "enable automatic page refresh via query parameter") rootCmd.Flags().BoolVar(&Russian, "russian", false, "remove selected images after serving") rootCmd.Flags().BoolVarP(&Sorting, "sort", "s", false, "enable sorting") diff --git a/cmd/web.go b/cmd/web.go index 78503e8..43edc4b 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -62,7 +62,7 @@ func noFiles(w http.ResponseWriter, r *http.Request) { w.Write([]byte("No files found in the specified path(s).\n")) if Verbose { - fmt.Printf("%s | SERVE: Empty path notice served to %s\n", + fmt.Printf("%s | SERVE: Empty path notification to %s\n", startTime.Format(logDate), r.RemoteAddr, ) @@ -435,6 +435,10 @@ func serveVersion() httprouter.Handle { func registerHandler(mux *httprouter.Router, path string, handle httprouter.Handle) { mux.GET(path, handle) + if Redact && AdminPrefix != "" { + path = strings.ReplaceAll(path, AdminPrefix, "/") + } + if Handlers { fmt.Printf("%s | SERVE: Registered handler for %s\n", time.Now().Format(logDate),