Compare commits

...

26 commits
v1.3.0 ... main

Author SHA1 Message Date
Simon Vieille 92aa6b341f Merge branch 'develop'
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is pending
2023-09-29 15:56:20 +02:00
Simon Vieille 1f089236dc
fix ci syntax
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is pending
2023-09-29 15:55:59 +02:00
Simon Vieille ee1bc68760
update readme 2023-09-29 15:55:50 +02:00
Simon Vieille 09cd37aa3b
update ci
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/deployment/woodpecker Pipeline was successful
2023-09-01 09:26:55 +02:00
Simon Vieille 8a11deed01
update build
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/deployment/woodpecker Pipeline was successful
2023-09-01 09:14:29 +02:00
Simon Vieille 6c05d9f126 Merge branch 'develop'
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is pending
2023-08-03 18:23:04 +02:00
Simon Vieille 5291903718
add build/ in docker ignored files
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/deployment/woodpecker Pipeline was successful
2023-08-03 18:22:56 +02:00
Simon Vieille c08af75dc5 Merge branch 'develop'
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-08-03 18:21:24 +02:00
Simon Vieille 5fac42f17b
fix tests
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-08-03 15:44:38 +02:00
Simon Vieille 9993d9a8ef
add option to skip TLS verification
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is pending
2023-08-03 15:42:22 +02:00
Simon Vieille d6e0b063e0
rename build binaries 2023-08-03 15:37:42 +02:00
Simon Vieille 0afdce8c5f
update changelog
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is pending
2023-08-03 15:15:08 +02:00
Simon Vieille bcc4a9f4ab
fix ci build
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is pending
2023-08-03 15:14:01 +02:00
Simon Vieille 3e6600113c
fix ci build
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-08-03 15:12:52 +02:00
Simon Vieille bd0781aec7
add makefile
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
update build params
2023-08-03 15:09:12 +02:00
Simon Vieille 174a06e8b5 Merge branch 'develop'
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/deployment/woodpecker Pipeline was successful
2023-06-09 11:32:10 +02:00
Simon Vieille cf97958081
optimze the docker build
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-06-09 11:31:49 +02:00
Simon Vieille 94537e9238 Merge branch 'develop'
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-06-06 22:49:01 +02:00
Simon Vieille 528b3c1da8 Merge branch 'feature/docker' into develop
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-06-06 22:48:41 +02:00
Simon Vieille 989e7689fc
update documentation 2023-06-06 22:48:38 +02:00
Simon Vieille baf19d935c
fix ci
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/deployment/woodpecker Pipeline was successful
2023-06-06 22:15:49 +02:00
Simon Vieille 57654afc2d
fix ci 2023-06-06 22:15:29 +02:00
Simon Vieille c5392885bd
fix ci
Some checks failed
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/deployment/woodpecker Pipeline failed
2023-06-06 22:12:59 +02:00
Simon Vieille 3d9aeaf2d3
fix ci 2023-06-06 22:11:38 +02:00
Simon Vieille be35ef8809
fix ci vy adding volumes
Some checks failed
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/deployment/woodpecker Pipeline failed
2023-06-06 22:09:47 +02:00
Simon Vieille 97c5ce0b7b
use golang builder
Some checks failed
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/deployment/woodpecker Pipeline failed
update ci
2023-06-06 22:07:35 +02:00
10 changed files with 98 additions and 24 deletions

4
.dockerignore Normal file
View file

@ -0,0 +1,4 @@
/build
/.woodpecker.yml
/.git
/.gitignore

6
.gitignore vendored
View file

@ -1,5 +1 @@
.idea
debug
debug.test
*.exe
capture
/build

View file

@ -1,9 +1,9 @@
variables:
- &golang "golang:1.19"
- &volumes
- /var/www/html/artifacts/capture/deblan:/artifacts
- /var/www/html/artifacts/deblan/capture:/artifacts
pipeline:
steps:
test:
image: *golang
commands:
@ -13,9 +13,10 @@ pipeline:
image: *golang
volumes: *volumes
commands:
- go build -o /artifacts/capture
- make
- cp build/* /artifacts
push-release:
push_release:
image: plugins/gitea-release
volumes: *volumes
settings:
@ -23,6 +24,20 @@ pipeline:
from_secret: gitnet_api_key
base_url: https://gitnet.fr
note: ${CI_COMMIT_MESSAGE}
files: /artifacts/capture
files: build/*
when:
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]

View file

@ -1,5 +1,15 @@
## [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

View file

@ -1,9 +1,15 @@
FROM debian:stable-slim
FROM golang:1.21-bullseye as builder
RUN apt-get update && apt-get install ca-certificates -y
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY ./capture /usr/bin/capture
COPY . .
RUN BUILD_DIR=/app make
WORKDIR /app
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 Normal file
View file

@ -0,0 +1,24 @@
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)"

View file

@ -11,15 +11,22 @@ Forked from [ofabricio/capture](https://github.com/ofabricio/capture).
./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
| param | description |
| -------------- | ------------- |
| `-url` | **Required.** Set the url you want to proxy |
| `-port` | Set the proxy port. Default: *9000* |
| `-dashboard` | Set the dashboard port. Default: *9001* |
| `-captures` | Set how many captures to show in the dashboard. Default: *16* |
| `-config` | Set the configuration file. Default: *.capture.ini* |
| param | description |
| -------------- | ------------- |
| `-url` | **Required.** Set the url you want to proxy |
| `-port` | Set the proxy port. Default: *9000* |
| `-dashboard` | Set the dashboard port. Default: *9001* |
| `-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:
@ -28,6 +35,7 @@ url = https://example.com/
port = 9000
dashboard = 9001
captures = 16
tls_skip_verify = false
```
## Using

View file

@ -12,6 +12,7 @@ type Config struct {
TargetURL string
ProxyPort string
DashboardPort string
TLSSkipVerify bool
MaxCaptures int
}
@ -22,12 +23,14 @@ func ReadConfig() Config {
defaultDashboardPort := "9001"
defaultMaxCaptures := 16
defaultConfigFile := ".capture.ini"
defaultTLSSkipVerify := false
targetURL := flag.String("url", defaultTargetURL, "Required. Set the url you want to proxy")
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()
@ -46,6 +49,7 @@ func ReadConfig() Config {
ProxyPort: section.Key("port").MustString(*proxyPort),
MaxCaptures: section.Key("captures").MustInt(*maxCaptures),
DashboardPort: section.Key("dashboard").MustString(*dashboardPort),
TLSSkipVerify: section.Key("tls_skip_verify").MustBool(*TLSSkipVerify),
}
}
@ -54,5 +58,6 @@ func ReadConfig() Config {
ProxyPort: *proxyPort,
MaxCaptures: *maxCaptures,
DashboardPort: *dashboardPort,
TLSSkipVerify: *TLSSkipVerify,
}
}

10
main.go
View file

@ -3,6 +3,7 @@ package main
import (
"bytes"
"compress/gzip"
"crypto/tls"
_ "embed"
"encoding/json"
"fmt"
@ -36,7 +37,7 @@ func main() {
fmt.Println()
srv := NewCaptureService(cfg.MaxCaptures)
hdr := NewRecorderHandler(srv, NewPluginHandler(NewProxyHandler(cfg.TargetURL)))
hdr := NewRecorderHandler(srv, NewPluginHandler(NewProxyHandler(cfg.TargetURL, cfg.TLSSkipVerify)))
go func() {
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.
func NewProxyHandler(URL string) http.HandlerFunc {
func NewProxyHandler(URL string, TLSSkipVerify bool) http.HandlerFunc {
url, _ := url.Parse(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) {
fmt.Printf("Uh oh | %v | %s %s\n", err, req.Method, req.URL)
rw.WriteHeader(StatusInternalProxyError)

View file

@ -22,7 +22,7 @@ func TestProxyHandler(t *testing.T) {
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
service := httptest.NewServer(http.HandlerFunc(tc.service))
capture := httptest.NewServer(NewProxyHandler(service.URL))
capture := httptest.NewServer(NewProxyHandler(service.URL, false))
// when
resp := tc.request(capture.URL)