Compare commits
14 commits
Author | SHA1 | Date | |
---|---|---|---|
92aa6b341f | |||
1f089236dc | |||
ee1bc68760 | |||
09cd37aa3b | |||
8a11deed01 | |||
6c05d9f126 | |||
5291903718 | |||
c08af75dc5 | |||
5fac42f17b | |||
9993d9a8ef | |||
d6e0b063e0 | |||
174a06e8b5 | |||
94537e9238 | |||
Simon Vieille | 4fee95a165 |
|
@ -1,4 +1,4 @@
|
||||||
/capture
|
/build
|
||||||
/.woodpecker.yml
|
/.woodpecker.yml
|
||||||
/.git
|
/.git
|
||||||
/.gitignore
|
/.gitignore
|
||||||
|
|
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -1,5 +1 @@
|
||||||
.idea
|
/build
|
||||||
debug
|
|
||||||
debug.test
|
|
||||||
*.exe
|
|
||||||
capture
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
variables:
|
variables:
|
||||||
- &golang "golang:1.19"
|
- &golang "golang:1.19"
|
||||||
- &volumes
|
- &volumes
|
||||||
- /var/www/html/artifacts/capture/deblan:/artifacts
|
- /var/www/html/artifacts/deblan/capture:/artifacts
|
||||||
|
|
||||||
pipeline:
|
steps:
|
||||||
test:
|
test:
|
||||||
image: *golang
|
image: *golang
|
||||||
commands:
|
commands:
|
||||||
|
@ -14,6 +14,7 @@ pipeline:
|
||||||
volumes: *volumes
|
volumes: *volumes
|
||||||
commands:
|
commands:
|
||||||
- make
|
- make
|
||||||
|
- cp build/* /artifacts
|
||||||
|
|
||||||
push_release:
|
push_release:
|
||||||
image: plugins/gitea-release
|
image: plugins/gitea-release
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## v1.4.0
|
||||||
|
### Added
|
||||||
|
- add option to skil TLS verification
|
||||||
|
### Changed
|
||||||
|
- build binaries are nenamed
|
||||||
|
|
||||||
## v1.3.1
|
## v1.3.1
|
||||||
### Added
|
### Added
|
||||||
- add makefile to manage build
|
- add makefile to manage build
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FROM golang:1.19 as builder
|
FROM golang:1.21-bullseye as builder
|
||||||
|
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
|
@ -7,9 +7,9 @@ RUN go mod download
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN BUILD_DIR=/app make
|
RUN BUILD_DIR=/app make
|
||||||
|
|
||||||
FROM debian:stable-slim
|
FROM debian:bullseye-slim
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y ca-certificates
|
RUN apt-get update && apt-get install -y ca-certificates
|
||||||
COPY --from=builder /app/capture /usr/bin/capture
|
COPY --from=builder /app/capture-linux-amd64 /usr/bin/capture
|
||||||
|
|
||||||
ENTRYPOINT ["/usr/bin/capture"]
|
ENTRYPOINT ["/usr/bin/capture"]
|
||||||
|
|
6
Makefile
6
Makefile
|
@ -4,11 +4,11 @@ CFLAGS = -trimpath
|
||||||
LDFLAGS = all=-w -s
|
LDFLAGS = all=-w -s
|
||||||
GCFLAGS = all=
|
GCFLAGS = all=
|
||||||
ASMFLAGS = all=
|
ASMFLAGS = all=
|
||||||
GOARCH ?= amd64
|
GOARCH = amd64
|
||||||
|
|
||||||
BUILD_DIR ?= build
|
BUILD_DIR ?= build
|
||||||
LINUX_BIN ?= capture
|
LINUX_BIN ?= capture-linux-amd64
|
||||||
WIN_BIN ?= capture.exe
|
WIN_BIN ?= capture-window-amd64.exe
|
||||||
|
|
||||||
all: build
|
all: build
|
||||||
|
|
||||||
|
|
16
README.md
16
README.md
|
@ -19,13 +19,14 @@ docker run -p 9000:9000 -p 9001:9001 deblan/capture -url=https://example.com/ -p
|
||||||
|
|
||||||
#### Settings
|
#### Settings
|
||||||
|
|
||||||
| param | description |
|
| param | description |
|
||||||
| -------------- | ------------- |
|
| -------------- | ------------- |
|
||||||
| `-url` | **Required.** Set the url you want to proxy |
|
| `-url` | **Required.** Set the url you want to proxy |
|
||||||
| `-port` | Set the proxy port. Default: *9000* |
|
| `-port` | Set the proxy port. Default: *9000* |
|
||||||
| `-dashboard` | Set the dashboard port. Default: *9001* |
|
| `-dashboard` | Set the dashboard port. Default: *9001* |
|
||||||
| `-captures` | Set how many captures to show in the dashboard. Default: *16* |
|
| `-captures` | Set how many captures to show in the dashboard. Default: *16* |
|
||||||
| `-config` | Set the configuration file. Default: *.capture.ini* |
|
| `-tls-skip-verify` | Skip TLS vertificaton. Default: *false* |
|
||||||
|
| `-config` | Set the configuration file. Default: *.capture.ini* |
|
||||||
|
|
||||||
You can create a file named `.capture.ini` and set the configuration inside:
|
You can create a file named `.capture.ini` and set the configuration inside:
|
||||||
|
|
||||||
|
@ -34,6 +35,7 @@ url = https://example.com/
|
||||||
port = 9000
|
port = 9000
|
||||||
dashboard = 9001
|
dashboard = 9001
|
||||||
captures = 16
|
captures = 16
|
||||||
|
tls_skip_verify = false
|
||||||
```
|
```
|
||||||
|
|
||||||
## Using
|
## Using
|
||||||
|
|
|
@ -12,6 +12,7 @@ type Config struct {
|
||||||
TargetURL string
|
TargetURL string
|
||||||
ProxyPort string
|
ProxyPort string
|
||||||
DashboardPort string
|
DashboardPort string
|
||||||
|
TLSSkipVerify bool
|
||||||
MaxCaptures int
|
MaxCaptures int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,12 +23,14 @@ func ReadConfig() Config {
|
||||||
defaultDashboardPort := "9001"
|
defaultDashboardPort := "9001"
|
||||||
defaultMaxCaptures := 16
|
defaultMaxCaptures := 16
|
||||||
defaultConfigFile := ".capture.ini"
|
defaultConfigFile := ".capture.ini"
|
||||||
|
defaultTLSSkipVerify := false
|
||||||
|
|
||||||
targetURL := flag.String("url", defaultTargetURL, "Required. Set the url you want to proxy")
|
targetURL := flag.String("url", defaultTargetURL, "Required. Set the url you want to proxy")
|
||||||
configFile := flag.String("config", defaultConfigFile, "Set the configuration file")
|
configFile := flag.String("config", defaultConfigFile, "Set the configuration file")
|
||||||
proxyPort := flag.String("port", defaultProxyPort, "Set the proxy port")
|
proxyPort := flag.String("port", defaultProxyPort, "Set the proxy port")
|
||||||
dashboardPort := flag.String("dashboard", defaultDashboardPort, "Set the dashboard port")
|
dashboardPort := flag.String("dashboard", defaultDashboardPort, "Set the dashboard port")
|
||||||
maxCaptures := flag.Int("captures", defaultMaxCaptures, "Set how many captures to show in the dashboard")
|
maxCaptures := flag.Int("captures", defaultMaxCaptures, "Set how many captures to show in the dashboard")
|
||||||
|
TLSSkipVerify := flag.Bool("tls-skip-verify", defaultTLSSkipVerify, "Skip TLS vertification")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
@ -46,6 +49,7 @@ func ReadConfig() Config {
|
||||||
ProxyPort: section.Key("port").MustString(*proxyPort),
|
ProxyPort: section.Key("port").MustString(*proxyPort),
|
||||||
MaxCaptures: section.Key("captures").MustInt(*maxCaptures),
|
MaxCaptures: section.Key("captures").MustInt(*maxCaptures),
|
||||||
DashboardPort: section.Key("dashboard").MustString(*dashboardPort),
|
DashboardPort: section.Key("dashboard").MustString(*dashboardPort),
|
||||||
|
TLSSkipVerify: section.Key("tls_skip_verify").MustBool(*TLSSkipVerify),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,5 +58,6 @@ func ReadConfig() Config {
|
||||||
ProxyPort: *proxyPort,
|
ProxyPort: *proxyPort,
|
||||||
MaxCaptures: *maxCaptures,
|
MaxCaptures: *maxCaptures,
|
||||||
DashboardPort: *dashboardPort,
|
DashboardPort: *dashboardPort,
|
||||||
|
TLSSkipVerify: *TLSSkipVerify,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
main.go
10
main.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"crypto/tls"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -36,7 +37,7 @@ func main() {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
||||||
srv := NewCaptureService(cfg.MaxCaptures)
|
srv := NewCaptureService(cfg.MaxCaptures)
|
||||||
hdr := NewRecorderHandler(srv, NewPluginHandler(NewProxyHandler(cfg.TargetURL)))
|
hdr := NewRecorderHandler(srv, NewPluginHandler(NewProxyHandler(cfg.TargetURL, cfg.TLSSkipVerify)))
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
fmt.Println(http.ListenAndServe(":"+cfg.DashboardPort, NewDashboardHandler(hdr, srv, cfg)))
|
fmt.Println(http.ListenAndServe(":"+cfg.DashboardPort, NewDashboardHandler(hdr, srv, cfg)))
|
||||||
|
@ -230,9 +231,14 @@ func NewRecorderHandler(srv *CaptureService, next http.HandlerFunc) http.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewProxyHandler is the reverse proxy handler.
|
// NewProxyHandler is the reverse proxy handler.
|
||||||
func NewProxyHandler(URL string) http.HandlerFunc {
|
func NewProxyHandler(URL string, TLSSkipVerify bool) http.HandlerFunc {
|
||||||
url, _ := url.Parse(URL)
|
url, _ := url.Parse(URL)
|
||||||
proxy := httputil.NewSingleHostReverseProxy(url)
|
proxy := httputil.NewSingleHostReverseProxy(url)
|
||||||
|
insecureTransport := &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: TLSSkipVerify},
|
||||||
|
}
|
||||||
|
proxy.Transport = insecureTransport
|
||||||
|
|
||||||
proxy.ErrorHandler = func(rw http.ResponseWriter, req *http.Request, err error) {
|
proxy.ErrorHandler = func(rw http.ResponseWriter, req *http.Request, err error) {
|
||||||
fmt.Printf("Uh oh | %v | %s %s\n", err, req.Method, req.URL)
|
fmt.Printf("Uh oh | %v | %s %s\n", err, req.Method, req.URL)
|
||||||
rw.WriteHeader(StatusInternalProxyError)
|
rw.WriteHeader(StatusInternalProxyError)
|
||||||
|
|
|
@ -22,7 +22,7 @@ func TestProxyHandler(t *testing.T) {
|
||||||
for _, tc := range tt {
|
for _, tc := range tt {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
service := httptest.NewServer(http.HandlerFunc(tc.service))
|
service := httptest.NewServer(http.HandlerFunc(tc.service))
|
||||||
capture := httptest.NewServer(NewProxyHandler(service.URL))
|
capture := httptest.NewServer(NewProxyHandler(service.URL, false))
|
||||||
|
|
||||||
// when
|
// when
|
||||||
resp := tc.request(capture.URL)
|
resp := tc.request(capture.URL)
|
||||||
|
|
Loading…
Reference in a new issue