Compare commits
No commits in common. "main" and "v1.2.0" have entirely different histories.
|
@ -1,4 +0,0 @@
|
||||||
/build
|
|
||||||
/.woodpecker.yml
|
|
||||||
/.git
|
|
||||||
/.gitignore
|
|
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -1 +1,5 @@
|
||||||
/build
|
.idea
|
||||||
|
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/deblan/capture:/artifacts
|
- /var/www/html/artifacts/capture/deblan:/artifacts
|
||||||
|
|
||||||
steps:
|
pipeline:
|
||||||
test:
|
test:
|
||||||
image: *golang
|
image: *golang
|
||||||
commands:
|
commands:
|
||||||
|
@ -13,10 +13,9 @@ steps:
|
||||||
image: *golang
|
image: *golang
|
||||||
volumes: *volumes
|
volumes: *volumes
|
||||||
commands:
|
commands:
|
||||||
- make
|
- go build -o /artifacts/capture
|
||||||
- cp build/* /artifacts
|
|
||||||
|
|
||||||
push_release:
|
push-release:
|
||||||
image: plugins/gitea-release
|
image: plugins/gitea-release
|
||||||
volumes: *volumes
|
volumes: *volumes
|
||||||
settings:
|
settings:
|
||||||
|
@ -24,20 +23,6 @@ steps:
|
||||||
from_secret: gitnet_api_key
|
from_secret: gitnet_api_key
|
||||||
base_url: https://gitnet.fr
|
base_url: https://gitnet.fr
|
||||||
note: ${CI_COMMIT_MESSAGE}
|
note: ${CI_COMMIT_MESSAGE}
|
||||||
files: build/*
|
files: /artifacts/capture
|
||||||
when:
|
when:
|
||||||
event: [tag]
|
event: [tag]
|
||||||
|
|
||||||
docker_build_push:
|
|
||||||
image: docker:dind
|
|
||||||
secrets:
|
|
||||||
- registry_user
|
|
||||||
- registry_password
|
|
||||||
commands:
|
|
||||||
- echo "$REGISTRY_PASSWORD" | docker login -u "$REGISTRY_USER" --password-stdin
|
|
||||||
- "docker build -t deblan/capture:${CI_PIPELINE_DEPLOY_TARGET} ."
|
|
||||||
- "docker push deblan/capture:${CI_PIPELINE_DEPLOY_TARGET}"
|
|
||||||
volumes:
|
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
when:
|
|
||||||
event: [deployment]
|
|
||||||
|
|
14
CHANGELOG.md
14
CHANGELOG.md
|
@ -1,19 +1,5 @@
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
## v1.4.0
|
|
||||||
### Added
|
|
||||||
- add option to skil TLS verification
|
|
||||||
### Changed
|
|
||||||
- build binaries are nenamed
|
|
||||||
|
|
||||||
## v1.3.1
|
|
||||||
### Added
|
|
||||||
- add makefile to manage build
|
|
||||||
|
|
||||||
## v1.3.0
|
|
||||||
### Added
|
|
||||||
- add argument to define the configuration file
|
|
||||||
|
|
||||||
## v1.2.0
|
## v1.2.0
|
||||||
### Added
|
### Added
|
||||||
- allow to use a configuration file
|
- allow to use a configuration file
|
||||||
|
|
15
Dockerfile
15
Dockerfile
|
@ -1,15 +0,0 @@
|
||||||
FROM golang:1.21-bullseye as builder
|
|
||||||
|
|
||||||
WORKDIR /src
|
|
||||||
COPY go.mod go.sum ./
|
|
||||||
RUN go mod download
|
|
||||||
|
|
||||||
COPY . .
|
|
||||||
RUN BUILD_DIR=/app make
|
|
||||||
|
|
||||||
FROM debian:bullseye-slim
|
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y ca-certificates
|
|
||||||
COPY --from=builder /app/capture-linux-amd64 /usr/bin/capture
|
|
||||||
|
|
||||||
ENTRYPOINT ["/usr/bin/capture"]
|
|
24
Makefile
24
Makefile
|
@ -1,24 +0,0 @@
|
||||||
CGO_ENABLED = 0
|
|
||||||
CC = go build
|
|
||||||
CFLAGS = -trimpath
|
|
||||||
LDFLAGS = all=-w -s
|
|
||||||
GCFLAGS = all=
|
|
||||||
ASMFLAGS = all=
|
|
||||||
GOARCH = amd64
|
|
||||||
|
|
||||||
BUILD_DIR ?= build
|
|
||||||
LINUX_BIN ?= capture-linux-amd64
|
|
||||||
WIN_BIN ?= capture-window-amd64.exe
|
|
||||||
|
|
||||||
all: build
|
|
||||||
|
|
||||||
deps:
|
|
||||||
go install github.com/GeertJohan/go.rice/rice@latest
|
|
||||||
rice embed-go
|
|
||||||
|
|
||||||
.PHONY:
|
|
||||||
build: deps
|
|
||||||
export CGO_ENABLED=$(CGO_ENABLED)
|
|
||||||
export GOARCH=$(GOARCH)
|
|
||||||
GOOS=linux $(CC) $(CFLAGS) -o $(BUILD_DIR)/$(LINUX_BIN) -ldflags="$(LDFLAGS)" -gcflags="$(GCFLAGS)" -asmflags="$(ASMFLAGS)"
|
|
||||||
GOOS=windows $(CC) $(CFLAGS) -o $(BUILD_DIR)/$(WIN_BIN) -ldflags="$(LDFLAGS)" -gcflags="$(GCFLAGS)" -asmflags="$(ASMFLAGS)"
|
|
25
README.md
25
README.md
|
@ -11,22 +11,15 @@ Forked from [ofabricio/capture](https://github.com/ofabricio/capture).
|
||||||
./capture -url=https://example.com/ -port 9000 -dashboard 9001 -captures 16
|
./capture -url=https://example.com/ -port 9000 -dashboard 9001 -captures 16
|
||||||
```
|
```
|
||||||
|
|
||||||
Via docker:
|
|
||||||
|
|
||||||
```
|
|
||||||
docker run -p 9000:9000 -p 9001:9001 deblan/capture -url=https://example.com/ -port 9000 -dashboard 9001 -captures 16
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 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* |
|
||||||
| `-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:
|
||||||
|
|
||||||
|
@ -35,7 +28,6 @@ url = https://example.com/
|
||||||
port = 9000
|
port = 9000
|
||||||
dashboard = 9001
|
dashboard = 9001
|
||||||
captures = 16
|
captures = 16
|
||||||
tls_skip_verify = false
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Using
|
## Using
|
||||||
|
@ -45,9 +37,10 @@ address. Hence, calling `http://localhost:9000/users/1` is like calling `http://
|
||||||
|
|
||||||
*Capture* saves all requests and responses so that you can see them in the dashboard.
|
*Capture* saves all requests and responses so that you can see them in the dashboard.
|
||||||
|
|
||||||
|
|
||||||
## Dashboard
|
## Dashboard
|
||||||
|
|
||||||
To access the dashboard go to `http://127.0.0.1:9001/`
|
To access the dashboard go to `http://localhost:9001/`
|
||||||
|
|
||||||
##### Preview
|
##### Preview
|
||||||
|
|
||||||
|
|
37
config.go
37
config.go
|
@ -12,7 +12,6 @@ type Config struct {
|
||||||
TargetURL string
|
TargetURL string
|
||||||
ProxyPort string
|
ProxyPort string
|
||||||
DashboardPort string
|
DashboardPort string
|
||||||
TLSSkipVerify bool
|
|
||||||
MaxCaptures int
|
MaxCaptures int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,42 +21,36 @@ func ReadConfig() Config {
|
||||||
defaultProxyPort := "9000"
|
defaultProxyPort := "9000"
|
||||||
defaultDashboardPort := "9001"
|
defaultDashboardPort := "9001"
|
||||||
defaultMaxCaptures := 16
|
defaultMaxCaptures := 16
|
||||||
defaultConfigFile := ".capture.ini"
|
|
||||||
defaultTLSSkipVerify := false
|
|
||||||
|
|
||||||
targetURL := flag.String("url", defaultTargetURL, "Required. Set the url you want to proxy")
|
configFile := ".capture.ini"
|
||||||
configFile := flag.String("config", defaultConfigFile, "Set the configuration file")
|
|
||||||
proxyPort := flag.String("port", defaultProxyPort, "Set the proxy port")
|
|
||||||
dashboardPort := flag.String("dashboard", defaultDashboardPort, "Set the dashboard port")
|
|
||||||
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()
|
if _, err := os.Stat(configFile); err == nil {
|
||||||
|
cfg, err := ini.Load(configFile)
|
||||||
if _, err := os.Stat(*configFile); err == nil {
|
|
||||||
cfg, err := ini.Load(*configFile)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Fail to read file %s: %v", *configFile, err)
|
fmt.Printf("Fail to read file %s: %v", configFile, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
section := cfg.Section("")
|
section := cfg.Section("")
|
||||||
|
|
||||||
return Config{
|
defaultTargetURL = section.Key("url").MustString(defaultTargetURL)
|
||||||
TargetURL: section.Key("url").MustString(*targetURL),
|
defaultProxyPort = section.Key("port").MustString(defaultProxyPort)
|
||||||
ProxyPort: section.Key("port").MustString(*proxyPort),
|
defaultDashboardPort = section.Key("dashboard").MustString(defaultDashboardPort)
|
||||||
MaxCaptures: section.Key("captures").MustInt(*maxCaptures),
|
defaultMaxCaptures = section.Key("captures").MustInt(defaultMaxCaptures)
|
||||||
DashboardPort: section.Key("dashboard").MustString(*dashboardPort),
|
|
||||||
TLSSkipVerify: section.Key("tls_skip_verify").MustBool(*TLSSkipVerify),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
targetURL := flag.String("url", defaultTargetURL, "Required. Set the url you want to proxy")
|
||||||
|
proxyPort := flag.String("port", defaultProxyPort, "Set the proxy port")
|
||||||
|
dashboardPort := flag.String("dashboard", defaultDashboardPort, "Set the dashboard port")
|
||||||
|
maxCaptures := flag.Int("captures", defaultMaxCaptures, "Set how many captures to show in the dashboard")
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
return Config{
|
return Config{
|
||||||
TargetURL: *targetURL,
|
TargetURL: *targetURL,
|
||||||
ProxyPort: *proxyPort,
|
ProxyPort: *proxyPort,
|
||||||
MaxCaptures: *maxCaptures,
|
MaxCaptures: *maxCaptures,
|
||||||
DashboardPort: *dashboardPort,
|
DashboardPort: *dashboardPort,
|
||||||
TLSSkipVerify: *TLSSkipVerify,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
main.go
16
main.go
|
@ -3,7 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"crypto/tls"
|
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -31,13 +30,13 @@ var dashboardHTML []byte
|
||||||
func main() {
|
func main() {
|
||||||
cfg := ReadConfig()
|
cfg := ReadConfig()
|
||||||
|
|
||||||
fmt.Printf("Target is %s\n", cfg.TargetURL)
|
fmt.Printf("Target is %s", cfg.TargetURL)
|
||||||
fmt.Printf("Listening on http://127.0.0.1:%s\n", cfg.ProxyPort)
|
fmt.Printf("\nListening on http://localhost:%s", cfg.ProxyPort)
|
||||||
fmt.Printf("Dashboard on http://127.0.0.1:%s\n", cfg.DashboardPort)
|
fmt.Printf("\nDashboard on http://localhost:%s", cfg.DashboardPort)
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
||||||
srv := NewCaptureService(cfg.MaxCaptures)
|
srv := NewCaptureService(cfg.MaxCaptures)
|
||||||
hdr := NewRecorderHandler(srv, NewPluginHandler(NewProxyHandler(cfg.TargetURL, cfg.TLSSkipVerify)))
|
hdr := NewRecorderHandler(srv, NewPluginHandler(NewProxyHandler(cfg.TargetURL)))
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
fmt.Println(http.ListenAndServe(":"+cfg.DashboardPort, NewDashboardHandler(hdr, srv, cfg)))
|
fmt.Println(http.ListenAndServe(":"+cfg.DashboardPort, NewDashboardHandler(hdr, srv, cfg)))
|
||||||
|
@ -231,14 +230,9 @@ 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, TLSSkipVerify bool) http.HandlerFunc {
|
func NewProxyHandler(URL string) 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, false))
|
capture := httptest.NewServer(NewProxyHandler(service.URL))
|
||||||
|
|
||||||
// when
|
// when
|
||||||
resp := tc.request(capture.URL)
|
resp := tc.request(capture.URL)
|
||||||
|
|
Loading…
Reference in a new issue