diff --git a/cmd/server.go b/cmd/server.go index 9c3a61c3..873e407e 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -58,6 +58,10 @@ $ gowitness server --address 127.0.0.1:9000 --allow-insecure-uri`, log.Warn().Msg("exposing this server to other networks is dangerous! see the server command help for more information") } + if !strings.HasPrefix(options.BasePath, "/") { + log.Warn().Msg("base path does not start with a /") + } + // db dbh, err := db.Get() if err != nil { @@ -77,11 +81,22 @@ $ gowitness server --address 127.0.0.1:9000 --allow-insecure-uri`, r := gin.Default() r.Use(themeChooser(&theme)) + // add / suffix to the base url so that we can be certain about + // the trim in the template helper + if !strings.HasSuffix(options.BasePath, "/") { + options.BasePath += "/" + } + + log.Info().Str("base-path", options.BasePath).Msg("basepath") + funcMap := template.FuncMap{ "GetTheme": getTheme, "Contains": func(full string, search string) bool { return strings.Contains(full, search) }, + "URL": func(url string) string { + return options.BasePath + strings.TrimPrefix(url, "/") + }, } tmpl := template.Must(template.New("").Funcs(funcMap).ParseFS(Embedded, "web/ui-templates/*.html")) r.SetHTMLTemplate(tmpl) @@ -127,6 +142,7 @@ func init() { serverCmd.Flags().StringVarP(&options.ServerAddr, "address", "a", "localhost:7171", "server listening address") serverCmd.Flags().BoolVarP(&options.AllowInsecureURIs, "allow-insecure-uri", "A", false, "allow uris that dont start with http(s)") + serverCmd.Flags().StringVarP(&options.BasePath, "base-path", "b", "/", "set the servers base path (useful for some reverse proxy setups)") } // middleware diff --git a/lib/options.go b/lib/options.go index a29e9b40..8ec52028 100644 --- a/lib/options.go +++ b/lib/options.go @@ -21,6 +21,7 @@ type Options struct { NoHTTPS bool NoHTTP bool ServerAddr string + BasePath string // Server command AllowInsecureURIs bool diff --git a/web/ui-templates/base.html b/web/ui-templates/base.html index 61ae50c4..95b9caf0 100644 --- a/web/ui-templates/base.html +++ b/web/ui-templates/base.html @@ -14,8 +14,8 @@ - - + + @@ -27,7 +27,7 @@ - +
@@ -40,7 +40,7 @@