Skip to content

Commit

Permalink
(feat) add better reverse proxy from a sub path support
Browse files Browse the repository at this point in the history
fixes #153
  • Loading branch information
leonjza committed Sep 11, 2022
1 parent 5519deb commit e904933
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 37 deletions.
16 changes: 16 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Options struct {
NoHTTPS bool
NoHTTP bool
ServerAddr string
BasePath string

// Server command
AllowInsecureURIs bool
Expand Down
20 changes: 10 additions & 10 deletions web/ui-templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<meta name="mobile-web-app-capable" content="yes" />
<meta name="HandheldFriendly" content="True" />
<meta name="MobileOptimized" content="320" />
<link rel="icon" href="./favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" />
<link rel="icon" href='{{ URL "/favicon.ico" }}' type="image/x-icon" />
<link rel="shortcut icon" href='{{ URL "/favicon.ico" }}' type="image/x-icon" />
<meta name="description" content="gowitness - a golang, web screenshot utility using Chrome Headless" />
<meta name="twitter:site" content="@leonjza">
<meta name="twitter:card" content="summary">
Expand All @@ -27,7 +27,7 @@
<meta property="og:title" content="gowitness">
<meta property="og:description" content="gowitness - a golang, web screenshot utility using Chrome Headless">
<!-- CSS files -->
<link href="./assets/css/tabler.min.css" rel="stylesheet" />
<link href='{{ URL "/assets/css/tabler.min.css" }}' rel="stylesheet" />
</head>

<body class=" layout-fluid theme-{{ GetTheme }}">
Expand All @@ -40,7 +40,7 @@
<span class="navbar-toggler-icon"></span>
</button>
<h1 class="navbar-brand navbar-brand-autodark d-none-navbar-horizontal pe-0 pe-md-3">
<a href="/">
<a href='{{ URL "/" }}'>
馃攳 gowitness - a golang, web screenshot utility using Chrome Headless
</a>
</h1>
Expand Down Expand Up @@ -76,7 +76,7 @@ <h1 class="navbar-brand navbar-brand-autodark d-none-navbar-horizontal pe-0 pe-m
<ul class="navbar-nav">

<li class="nav-item">
<a class="nav-link" href="/">
<a class="nav-link" href='{{ URL "/" }}'>
<span class="nav-link-icon d-md-none d-lg-inline-block">
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24"
stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
Expand All @@ -93,7 +93,7 @@ <h1 class="navbar-brand navbar-brand-autodark d-none-navbar-horizontal pe-0 pe-m
</li>

<li class="nav-item">
<a class="nav-link" href="./gallery">
<a class="nav-link" href='{{ URL "/gallery" }}'>
<span class="nav-link-icon d-md-none d-lg-inline-block">
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24"
stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
Expand All @@ -109,7 +109,7 @@ <h1 class="navbar-brand navbar-brand-autodark d-none-navbar-horizontal pe-0 pe-m
</li>

<li class="nav-item">
<a class="nav-link" href="./table">
<a class="nav-link" href='{{ URL "/table" }}'>
<span class="nav-link-icon d-md-none d-lg-inline-block">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-list" width="24"
height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none"
Expand All @@ -130,7 +130,7 @@ <h1 class="navbar-brand navbar-brand-autodark d-none-navbar-horizontal pe-0 pe-m
</li>

<li class="nav-item">
<a class="nav-link" href="./submit">
<a class="nav-link" href='{{ URL "/submit" }}'>
<span class="nav-link-icon d-md-none d-lg-inline-block">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-circle-plus" width="24"
height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none"
Expand All @@ -151,7 +151,7 @@ <h1 class="navbar-brand navbar-brand-autodark d-none-navbar-horizontal pe-0 pe-m

<!-- search -->
<div class="my-2 my-md-0 flex-grow-1 flex-md-grow-0 order-first order-md-last">
<form action="./search" method="post">
<form action='{{ URL "/search" }}' method="post">
<div class="input-icon">
<span class="input-icon-addon">
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24"
Expand Down Expand Up @@ -204,7 +204,7 @@ <h1 class="navbar-brand navbar-brand-autodark d-none-navbar-horizontal pe-0 pe-m
</div>

</div> <!-- class=page -->
<script src="./assets/js/tabler.min.js"></script>
<script src='{{ URL "/assets/js/tabler.min.js" }}'></script>
</body>

</html>
Expand Down
16 changes: 8 additions & 8 deletions web/ui-templates/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h2 class="page-title">

<div class="col-12 col-md-auto ms-auto d-print-none">
<div class="btn-list">
<a href="/details/{{ .Previous }}"
<a href='{{ URL "/details/" }}{{ .Previous }}'
class="btn d-none d-sm-inline-block {{ if eq .Previous 0 }}disabled{{ end }}">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-chevrons-left" width="24"
height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
Expand All @@ -29,8 +29,8 @@ <h2 class="page-title">
Previous
</a>

<a href="/details/{{ .Next }}"
class="btn btn-primary d-none d-sm-inline-block {{ if eq .Next .Max }}disabled{{ end }}">
<a href='{{ URL "/details/" }}{{ .Next }}'
class="btn btn-primary d-none d-sm-inline-block {{ if gt .Next .Max }}disabled{{ end }}">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-chevrons-right" width="24"
height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
stroke-linejoin="round">
Expand Down Expand Up @@ -58,12 +58,12 @@ <h2 class="page-title">
<div class="col-12">
<div class="card card-sm">
{{ if .Data.IsPDF }}
<embed class="card-img-top" src="/screenshots/{{ .Data.Filename }}" type="application/pdf" frameBorder="0"
<embed class="card-img-top" src='{{ URL "/screenshots/" }}{{ .Data.Filename }}' type="application/pdf" frameBorder="0"
scrolling="auto" height="100%" width="100%"></embed>
{{ else }}
<a href="/screenshots/{{ .Data.Filename }}" target="_blank" class="d-block">
<img loading="lazy" src="/screenshots/{{ .Data.Filename }}"
onerror="this.onerror=null; this.src='/assets/img/blank.png'" class="card-img-top">
<a href='{{ URL "/screenshots/" }}{{ .Data.Filename }}' target="_blank" class="d-block">
<img loading="lazy" src='{{ URL "/screenshots/" }}{{ .Data.Filename }}'
onerror="this.onerror=null; this.src='{{ URL "/assets/img/blank.png" }}'" class="card-img-top">
</a>
{{ end }}
<div class="card-footer">
Expand Down Expand Up @@ -172,7 +172,7 @@ <h3 class="card-title">TLS Information</h3>
<h3 class="card-title">DOM Dump</h3>

<div class="card-actions">
<a href="/details/{{ .ID }}/dom" class="btn btn-primary">
<a href='{{ URL "/details/" }}{{ .ID }}/dom' class="btn btn-primary">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-download" width="24"
height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none"
stroke-linecap="round" stroke-linejoin="round">
Expand Down
22 changes: 11 additions & 11 deletions web/ui-templates/gallery.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h2 class="page-title">
<div class="col-12 col-md-auto ms-auto d-print-none">
<div class="btn-list">
{{ if .Data.Ordered }}
<a href="/gallery?perception_sort=false&limit={{ .Data.Limit }}&page={{ .Data.Page }}"
<a href='{{ URL "/gallery" }}?perception_sort=false&limit={{ .Data.Limit }}&page={{ .Data.Page }}'
class="btn btn-primary d-none d-sm-inline-block">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-sort-ascending-2" width="24"
height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
Expand All @@ -33,7 +33,7 @@ <h2 class="page-title">
Disable Perception Sort
</a>
{{ else }}
<a href="/gallery?perception_sort=true&limit={{ .Data.Limit }}&page={{ .Data.Page }}"
<a href='{{ URL "/gallery" }}?perception_sort=true&limit={{ .Data.Limit }}&page={{ .Data.Page }}'
class="btn btn-primary d-none d-sm-inline-block">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-sort-descending-2" width="24"
height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
Expand Down Expand Up @@ -77,12 +77,12 @@ <h2 class="page-title">

<div class="card card-sm">
{{ if .IsPDF }}
<embed src="/screenshots/{{ .Filename }}" type="application/pdf" frameBorder="0" scrolling="auto"
<embed src='{{ URL "/screenshots/" }}{{ .Filename }}' type="application/pdf" frameBorder="0" scrolling="auto"
height="100%" width="100%"></embed>
{{ else }}
<a href="/screenshots/{{ .Filename }}" target="_blank" class="d-block">
<img loading="lazy" src="/screenshots/{{ .Filename }}"
onerror="this.onerror=null; this.src='/assets/img/blank.png'" class="card-img-top">
<a href='{{ URL "/screenshots/" }}{{ .Filename }}' target="_blank" class="d-block">
<img loading="lazy" src='{{ URL "/screenshots/" }}{{ .Filename }}'
onerror="this.onerror=null; this.src='{{ URL "/assets/img/blank.png" }}'" class="card-img-top">
</a>
{{ end }}
<div class="card-body">
Expand All @@ -98,7 +98,7 @@ <h2 class="page-title">
</div>
</div>
<div class="ms-auto">
<a href="/details/{{ .ID }}" class="text-muted">
<a href='{{ URL "/details/" }}{{ .ID }}' class="text-muted">
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24"
stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
Expand Down Expand Up @@ -130,7 +130,7 @@ <h2 class="page-title">
<!-- first page -->
<li class="page-item {{ if le .Data.Page 1 }}disabled{{ end }}">
<a class="page-link"
href="/gallery?{{ if .Data.Ordered }}perception_sort=true&{{ end }}limit={{ .Data.Limit }}&page={{ .Data.PrevPage }}"
href='{{ URL "/gallery" }}?{{ if .Data.Ordered }}perception_sort=true&{{ end }}limit={{ .Data.Limit }}&page={{ .Data.PrevPage }}'
tabindex="-1" {{ if le .Data.Page 1 }}aria-disabled="true" {{ end }}>
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24"
stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
Expand All @@ -145,7 +145,7 @@ <h2 class="page-title">
{{ range $p := .Data.PrevPageRange }}
<li class="page-item">
<a class="page-link"
href="/gallery?{{ if $.Data.Ordered }}perception_sort=true&{{ end }}limit={{ $.Data.Limit }}&page={{ $p }}">
href='{{ URL "/gallery" }}?{{ if .Data.Ordered }}perception_sort=true&{{ end }}limit={{ .Data.Limit }}&page={{ $p }}'>
{{ $p }}
</a>
</li>
Expand All @@ -160,7 +160,7 @@ <h2 class="page-title">
{{ range $p := .Data.NextPageRange }}
<li class="page-item">
<a class="page-link"
href="/gallery?{{ if $.Data.Ordered }}perception_sort=true&{{ end }}limit={{ $.Data.Limit }}&page={{ $p }}">
href='{{ URL "/gallery" }}?{{ if .Data.Ordered }}perception_sort=true&{{ end }}limit={{ .Data.Limit }}&page={{ $p }}'>
{{ $p }}
</a>
</li>
Expand All @@ -169,7 +169,7 @@ <h2 class="page-title">
<!-- next -->
<li class="page-item {{ if eq .Data.Page .Data.NextPage }}disabled{{ end }}">
<a class="page-link"
href="/gallery?{{ if $.Data.Ordered }}perception_sort=true&{{ end }}limit={{ $.Data.Limit }}&page={{ .Data.NextPage }}">
href='{{ URL "/gallery" }}?{{ if .Data.Ordered }}perception_sort=true&{{ end }}limit={{ .Data.Limit }}&page={{ .Data.NextPage }}'>
next
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24"
stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
Expand Down
10 changes: 5 additions & 5 deletions web/ui-templates/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ <h2 class="page-title">
{{ range .URLS}}
<tr>
<td>
<a href="/details/{{ .ID }}">Detail</a>
<a href='{{ URL "/details" }}/{{ .ID }}'>Detail</a>
</td>
<td class="text-muted">
{{ if (eq 0 .ResponseCode)}}
Expand Down Expand Up @@ -116,7 +116,7 @@ <h2 class="page-title">
{{ range $tech := $url.Technologies}}
<tr>
<td>
<a href="/details/{{ $url.ID }}">Detail</a>
<a href='{{ URL "/details" }}/{{ $url.ID }}'>Detail</a>
</td>
<td>{{ $url.URL }}</td>
<td>{{ $tech.Value }}</td>
Expand Down Expand Up @@ -158,7 +158,7 @@ <h2 class="page-title">
{{ range $header := $url.Headers}}
<tr>
<td>
<a href="/details/{{ $url.ID }}">Detail</a>
<a href='{{ URL "/details" }}/{{ $url.ID }}'>Detail</a>
</td>
<td>{{ $url.URL }}</td>
<td class="text-nowrap">{{ .Key }}</td>
Expand Down Expand Up @@ -201,7 +201,7 @@ <h2 class="page-title">
{{ range $log := $url.Console }}
<tr>
<td>
<a href="/details/{{ $url.ID }}">Detail</a>
<a href='{{ URL "/details" }}/{{ $url.ID }}'>Detail</a>
</td>
<td>{{ $url.URL }}</td>
<td class="text-nowrap">{{ .Type }}</td>
Expand Down Expand Up @@ -248,7 +248,7 @@ <h2 class="page-title">
{{ range $log := $url.Network }}
<tr>
<td>
<a href="/details/{{ $url.ID }}">Detail</a>
<a href='{{ URL "/details" }}/{{ $url.ID }}'>Detail</a>
</td>
<td>
{{ if (eq $log.RequestType 0) }}
Expand Down
4 changes: 2 additions & 2 deletions web/ui-templates/submit.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h2 class="page-title">
<div class="container-xl">
<div class="card">
<div class="card-body">
<form action="/submit" method="post">
<form action='{{ URL "/submit" }}' method="post">
<div class="mb-3">
<label class="form-label">URL to screenshot</label>
<div class="input-group input-group-flat">
Expand All @@ -37,4 +37,4 @@ <h2 class="page-title">
</div>
</div>

{{ template "footer" . }}
{{ template "footer" . }}
2 changes: 1 addition & 1 deletion web/ui-templates/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h2 class="page-title">
{{ range .Data}}
<tr>
<td>
<a href="/details/{{ .ID }}">Detail</a>
<a href='{{ URL "/details" }}/{{ .ID }}'>Detail</a>
</td>
<td>{{ .CreatedAt.Format "Jan 02, 2006 15:04:05" }}</td>
<td class="text-muted">
Expand Down

0 comments on commit e904933

Please sign in to comment.