Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78bf5ddc2b |
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -59,7 +59,7 @@ jobs:
|
|||||||
- name: Run tests in test container
|
- name: Run tests in test container
|
||||||
run: |
|
run: |
|
||||||
touch coverage.txt
|
touch coverage.txt
|
||||||
docker run --rm --device /dev/net/tun \
|
docker run --rm \
|
||||||
-v "$(pwd)/coverage.txt:/tmp/gobuild/coverage.txt" \
|
-v "$(pwd)/coverage.txt:/tmp/gobuild/coverage.txt" \
|
||||||
test-container
|
test-container
|
||||||
|
|
||||||
|
|||||||
2
.github/workflows/markdown.yml
vendored
2
.github/workflows/markdown.yml
vendored
@@ -20,7 +20,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: DavidAnson/markdownlint-cli2-action@v18
|
- uses: DavidAnson/markdownlint-cli2-action@v16
|
||||||
with:
|
with:
|
||||||
globs: "**.md"
|
globs: "**.md"
|
||||||
config: .markdownlint.json
|
config: .markdownlint.json
|
||||||
|
|||||||
@@ -125,8 +125,6 @@ ENV VPN_SERVICE_PROVIDER=pia \
|
|||||||
VPN_PORT_FORWARDING_STATUS_FILE="/tmp/gluetun/forwarded_port" \
|
VPN_PORT_FORWARDING_STATUS_FILE="/tmp/gluetun/forwarded_port" \
|
||||||
VPN_PORT_FORWARDING_USERNAME= \
|
VPN_PORT_FORWARDING_USERNAME= \
|
||||||
VPN_PORT_FORWARDING_PASSWORD= \
|
VPN_PORT_FORWARDING_PASSWORD= \
|
||||||
VPN_PORT_FORWARDING_UP_COMMAND= \
|
|
||||||
VPN_PORT_FORWARDING_DOWN_COMMAND= \
|
|
||||||
# # Cyberghost only:
|
# # Cyberghost only:
|
||||||
OPENVPN_CERT= \
|
OPENVPN_CERT= \
|
||||||
OPENVPN_KEY= \
|
OPENVPN_KEY= \
|
||||||
|
|||||||
@@ -380,7 +380,7 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
|||||||
|
|
||||||
portForwardLogger := logger.New(log.SetComponent("port forwarding"))
|
portForwardLogger := logger.New(log.SetComponent("port forwarding"))
|
||||||
portForwardLooper := portforward.NewLoop(allSettings.VPN.Provider.PortForwarding,
|
portForwardLooper := portforward.NewLoop(allSettings.VPN.Provider.PortForwarding,
|
||||||
routingConf, httpClient, firewallConf, portForwardLogger, cmder, puid, pgid)
|
routingConf, httpClient, firewallConf, portForwardLogger, puid, pgid)
|
||||||
portForwardRunError, err := portForwardLooper.Start(ctx)
|
portForwardRunError, err := portForwardLooper.Start(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("starting port forwarding loop: %w", err)
|
return fmt.Errorf("starting port forwarding loop: %w", err)
|
||||||
|
|||||||
18
go.mod
18
go.mod
@@ -3,27 +3,27 @@ module github.com/qdm12/gluetun
|
|||||||
go 1.23
|
go 1.23
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/breml/rootcerts v0.2.19
|
github.com/breml/rootcerts v0.2.18
|
||||||
github.com/fatih/color v1.18.0
|
github.com/fatih/color v1.18.0
|
||||||
github.com/golang/mock v1.6.0
|
github.com/golang/mock v1.6.0
|
||||||
github.com/klauspost/compress v1.17.11
|
github.com/klauspost/compress v1.17.11
|
||||||
github.com/klauspost/pgzip v1.2.6
|
github.com/klauspost/pgzip v1.2.6
|
||||||
github.com/pelletier/go-toml/v2 v2.2.3
|
github.com/pelletier/go-toml/v2 v2.2.2
|
||||||
github.com/qdm12/dns/v2 v2.0.0-rc8
|
github.com/qdm12/dns/v2 v2.0.0-rc8
|
||||||
github.com/qdm12/gosettings v0.4.4
|
github.com/qdm12/gosettings v0.4.3
|
||||||
github.com/qdm12/goshutdown v0.3.0
|
github.com/qdm12/goshutdown v0.3.0
|
||||||
github.com/qdm12/gosplash v0.2.0
|
github.com/qdm12/gosplash v0.2.0
|
||||||
github.com/qdm12/gotree v0.3.0
|
github.com/qdm12/gotree v0.3.0
|
||||||
github.com/qdm12/log v0.1.0
|
github.com/qdm12/log v0.1.0
|
||||||
github.com/qdm12/ss-server v0.6.0
|
github.com/qdm12/ss-server v0.6.0
|
||||||
github.com/stretchr/testify v1.10.0
|
github.com/stretchr/testify v1.9.0
|
||||||
github.com/ulikunitz/xz v0.5.11
|
github.com/ulikunitz/xz v0.5.11
|
||||||
github.com/vishvananda/netlink v1.2.1
|
github.com/vishvananda/netlink v1.2.1
|
||||||
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a
|
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a
|
||||||
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c
|
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c
|
||||||
golang.org/x/net v0.31.0
|
golang.org/x/net v0.30.0
|
||||||
golang.org/x/sys v0.27.0
|
golang.org/x/sys v0.26.0
|
||||||
golang.org/x/text v0.20.0
|
golang.org/x/text v0.19.0
|
||||||
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173
|
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173
|
||||||
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230429144221-925a1e7659e6
|
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230429144221-925a1e7659e6
|
||||||
gopkg.in/ini.v1 v1.67.0
|
gopkg.in/ini.v1 v1.67.0
|
||||||
@@ -50,9 +50,9 @@ require (
|
|||||||
github.com/qdm12/goservices v0.1.0 // indirect
|
github.com/qdm12/goservices v0.1.0 // indirect
|
||||||
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 // indirect
|
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 // indirect
|
||||||
github.com/vishvananda/netns v0.0.4 // indirect
|
github.com/vishvananda/netns v0.0.4 // indirect
|
||||||
golang.org/x/crypto v0.29.0 // indirect
|
golang.org/x/crypto v0.28.0 // indirect
|
||||||
golang.org/x/mod v0.21.0 // indirect
|
golang.org/x/mod v0.21.0 // indirect
|
||||||
golang.org/x/sync v0.9.0 // indirect
|
golang.org/x/sync v0.8.0 // indirect
|
||||||
golang.org/x/tools v0.26.0 // indirect
|
golang.org/x/tools v0.26.0 // indirect
|
||||||
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
|
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
|
||||||
google.golang.org/protobuf v1.35.1 // indirect
|
google.golang.org/protobuf v1.35.1 // indirect
|
||||||
|
|||||||
45
go.sum
45
go.sum
@@ -1,9 +1,10 @@
|
|||||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
github.com/breml/rootcerts v0.2.19 h1:3D/qwAC1xoh82GmZ21mYzQ1NaLOICUVntIo+MRZYr4U=
|
github.com/breml/rootcerts v0.2.18 h1:KjZaNT7AX/akUjzpStuwTMQs42YHlPyc6NmdwShVba0=
|
||||||
github.com/breml/rootcerts v0.2.19/go.mod h1:S/PKh+4d1HUn4HQovEB8hPJZO6pUZYrIhmXBhsegfXw=
|
github.com/breml/rootcerts v0.2.18/go.mod h1:S/PKh+4d1HUn4HQovEB8hPJZO6pUZYrIhmXBhsegfXw=
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
|
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
|
||||||
@@ -41,8 +42,8 @@ github.com/mikioh/ipaddr v0.0.0-20190404000644-d465c8ab6721 h1:RlZweED6sbSArvlE9
|
|||||||
github.com/mikioh/ipaddr v0.0.0-20190404000644-d465c8ab6721/go.mod h1:Ickgr2WtCLZ2MDGd4Gr0geeCH5HybhRJbonOgQpvSxc=
|
github.com/mikioh/ipaddr v0.0.0-20190404000644-d465c8ab6721/go.mod h1:Ickgr2WtCLZ2MDGd4Gr0geeCH5HybhRJbonOgQpvSxc=
|
||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
||||||
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
|
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
||||||
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
|
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
|
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
|
||||||
@@ -57,8 +58,8 @@ github.com/qdm12/dns/v2 v2.0.0-rc8 h1:kbgKPkbT+79nScfuZ0ZcVhksTGo8IUqQ8TTQGnQlZ1
|
|||||||
github.com/qdm12/dns/v2 v2.0.0-rc8/go.mod h1:VaF02KWEL7xNV4oKfG4N9nEv/kR6bqyIcBReCV5NJhw=
|
github.com/qdm12/dns/v2 v2.0.0-rc8/go.mod h1:VaF02KWEL7xNV4oKfG4N9nEv/kR6bqyIcBReCV5NJhw=
|
||||||
github.com/qdm12/goservices v0.1.0 h1:9sODefm/yuIGS7ynCkEnNlMTAYn9GzPhtcK4F69JWvc=
|
github.com/qdm12/goservices v0.1.0 h1:9sODefm/yuIGS7ynCkEnNlMTAYn9GzPhtcK4F69JWvc=
|
||||||
github.com/qdm12/goservices v0.1.0/go.mod h1:/JOFsAnHFiSjyoXxa5FlfX903h20K5u/3rLzCjYVMck=
|
github.com/qdm12/goservices v0.1.0/go.mod h1:/JOFsAnHFiSjyoXxa5FlfX903h20K5u/3rLzCjYVMck=
|
||||||
github.com/qdm12/gosettings v0.4.4 h1:SM6tOZDf6k8qbjWU8KWyBF4mWIixfsKCfh9DGRLHlj4=
|
github.com/qdm12/gosettings v0.4.3 h1:oGAjiKVtml9oHVlPQo6H3yk6TmtWpVYicNeGFcM7AP8=
|
||||||
github.com/qdm12/gosettings v0.4.4/go.mod h1:CPrt2YC4UsURTrslmhxocVhMCW03lIrqdH2hzIf5prg=
|
github.com/qdm12/gosettings v0.4.3/go.mod h1:CPrt2YC4UsURTrslmhxocVhMCW03lIrqdH2hzIf5prg=
|
||||||
github.com/qdm12/goshutdown v0.3.0 h1:pqBpJkdwlZlfTEx4QHtS8u8CXx6pG0fVo6S1N0MpSEM=
|
github.com/qdm12/goshutdown v0.3.0 h1:pqBpJkdwlZlfTEx4QHtS8u8CXx6pG0fVo6S1N0MpSEM=
|
||||||
github.com/qdm12/goshutdown v0.3.0/go.mod h1:EqZ46No00kCTZ5qzdd3qIzY6ayhMt24QI8Mh8LVQYmM=
|
github.com/qdm12/goshutdown v0.3.0/go.mod h1:EqZ46No00kCTZ5qzdd3qIzY6ayhMt24QI8Mh8LVQYmM=
|
||||||
github.com/qdm12/gosplash v0.2.0 h1:DOxCEizbW6ZG+FgpH2oK1atT6bM8MHL9GZ2ywSS4zZY=
|
github.com/qdm12/gosplash v0.2.0 h1:DOxCEizbW6ZG+FgpH2oK1atT6bM8MHL9GZ2ywSS4zZY=
|
||||||
@@ -73,8 +74,15 @@ github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 h1:f/FNXud6gA3MNr
|
|||||||
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3/go.mod h1:HgjTstvQsPGkxUsCd2KWxErBblirPizecHcpD3ffK+s=
|
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3/go.mod h1:HgjTstvQsPGkxUsCd2KWxErBblirPizecHcpD3ffK+s=
|
||||||
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||||
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
|
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||||
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
|
github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
|
||||||
github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
|
github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
|
||||||
github.com/vishvananda/netlink v1.2.1 h1:pfLv/qlJUwOTPvtWREA7c3PI4u81YkqZw1DYhI2HmLA=
|
github.com/vishvananda/netlink v1.2.1 h1:pfLv/qlJUwOTPvtWREA7c3PI4u81YkqZw1DYhI2HmLA=
|
||||||
@@ -87,8 +95,8 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
|
|||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
|
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
|
||||||
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
|
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
|
||||||
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY=
|
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY=
|
||||||
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8=
|
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8=
|
||||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
@@ -97,12 +105,12 @@ golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
|||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||||
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
|
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
|
||||||
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
|
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
|
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||||
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
@@ -112,13 +120,13 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||||||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
|
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
||||||
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
|
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
|
||||||
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
|
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||||
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 h1:vVKdlvoWBphwdxWKrFZEuM0kGgGLxUOYcY4U/2Vjg44=
|
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 h1:vVKdlvoWBphwdxWKrFZEuM0kGgGLxUOYcY4U/2Vjg44=
|
||||||
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
@@ -142,6 +150,7 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
|
|||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
|
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
|
||||||
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gvisor.dev/gvisor v0.0.0-20230927004350-cbd86285d259 h1:TbRPT0HtzFP3Cno1zZo7yPzEEnfu8EjLfl6IU9VfqkQ=
|
gvisor.dev/gvisor v0.0.0-20230927004350-cbd86285d259 h1:TbRPT0HtzFP3Cno1zZo7yPzEEnfu8EjLfl6IU9VfqkQ=
|
||||||
|
|||||||
@@ -1,150 +0,0 @@
|
|||||||
package command
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
"unicode/utf8"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
ErrCommandEmpty = errors.New("command is empty")
|
|
||||||
ErrSingleQuoteUnterminated = errors.New("unterminated single-quoted string")
|
|
||||||
ErrDoubleQuoteUnterminated = errors.New("unterminated double-quoted string")
|
|
||||||
ErrEscapeUnterminated = errors.New("unterminated backslash-escape")
|
|
||||||
)
|
|
||||||
|
|
||||||
// Split splits a command string into a slice of arguments.
|
|
||||||
// This is especially important for commands such as:
|
|
||||||
// /bin/sh -c "echo hello"
|
|
||||||
// which should be split into: ["/bin/sh", "-c", "echo hello"]
|
|
||||||
// It supports backslash-escapes, single-quotes and double-quotes.
|
|
||||||
// It does not support:
|
|
||||||
// - the $" quoting style.
|
|
||||||
// - expansion (brace, shell or pathname).
|
|
||||||
func Split(command string) (words []string, err error) {
|
|
||||||
if command == "" {
|
|
||||||
return nil, fmt.Errorf("%w", ErrCommandEmpty)
|
|
||||||
}
|
|
||||||
|
|
||||||
const bufferSize = 1024
|
|
||||||
buffer := bytes.NewBuffer(make([]byte, bufferSize))
|
|
||||||
|
|
||||||
startIndex := 0
|
|
||||||
|
|
||||||
for startIndex < len(command) {
|
|
||||||
// skip any split characters at the start
|
|
||||||
character, runeSize := utf8.DecodeRuneInString(command[startIndex:])
|
|
||||||
switch {
|
|
||||||
case strings.ContainsRune(" \n\t", character):
|
|
||||||
startIndex += runeSize
|
|
||||||
case character == '\\':
|
|
||||||
// Look ahead to eventually skip an escaped newline
|
|
||||||
if command[startIndex+runeSize:] == "" {
|
|
||||||
return nil, fmt.Errorf("%w: %q", ErrEscapeUnterminated, command)
|
|
||||||
}
|
|
||||||
character, runeSize := utf8.DecodeRuneInString(command[startIndex+runeSize:])
|
|
||||||
if character == '\n' {
|
|
||||||
startIndex += runeSize + runeSize // backslash and newline
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
var word string
|
|
||||||
buffer.Reset()
|
|
||||||
word, startIndex, err = splitWord(command, startIndex, buffer)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("splitting word in %q: %w", command, err)
|
|
||||||
}
|
|
||||||
words = append(words, word)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return words, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// WARNING: buffer must be cleared before calling this function.
|
|
||||||
func splitWord(input string, startIndex int, buffer *bytes.Buffer) (
|
|
||||||
word string, newStartIndex int, err error,
|
|
||||||
) {
|
|
||||||
cursor := startIndex
|
|
||||||
for cursor < len(input) {
|
|
||||||
character, runeLength := utf8.DecodeRuneInString(input[cursor:])
|
|
||||||
cursor += runeLength
|
|
||||||
if character == '"' ||
|
|
||||||
character == '\'' ||
|
|
||||||
character == '\\' ||
|
|
||||||
character == ' ' ||
|
|
||||||
character == '\n' ||
|
|
||||||
character == '\t' {
|
|
||||||
buffer.WriteString(input[startIndex : cursor-runeLength])
|
|
||||||
}
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case strings.ContainsRune(" \n\t", character): // spacing character
|
|
||||||
return buffer.String(), cursor, nil
|
|
||||||
case character == '"':
|
|
||||||
return handleDoubleQuoted(input, cursor, buffer)
|
|
||||||
case character == '\'':
|
|
||||||
return handleSingleQuoted(input, cursor, buffer)
|
|
||||||
case character == '\\':
|
|
||||||
return handleEscaped(input, cursor, buffer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer.WriteString(input[startIndex:])
|
|
||||||
return buffer.String(), len(input), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleDoubleQuoted(input string, startIndex int, buffer *bytes.Buffer) (
|
|
||||||
word string, newStartIndex int, err error,
|
|
||||||
) {
|
|
||||||
cursor := startIndex
|
|
||||||
for cursor < len(input) {
|
|
||||||
nextCharacter, nextRuneLength := utf8.DecodeRuneInString(input[cursor:])
|
|
||||||
cursor += nextRuneLength
|
|
||||||
switch nextCharacter {
|
|
||||||
case '"': // end of the double quoted string
|
|
||||||
buffer.WriteString(input[startIndex : cursor-nextRuneLength])
|
|
||||||
return splitWord(input, cursor, buffer)
|
|
||||||
case '\\': // escaped character
|
|
||||||
escapedCharacter, escapedRuneLength := utf8.DecodeRuneInString(input[cursor:])
|
|
||||||
cursor += escapedRuneLength
|
|
||||||
if !strings.ContainsRune("$`\"\n\\", escapedCharacter) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
buffer.WriteString(input[startIndex : cursor-nextRuneLength-escapedRuneLength])
|
|
||||||
if escapedCharacter != '\n' {
|
|
||||||
// skip backslash entirely for the newline character
|
|
||||||
buffer.WriteRune(escapedCharacter)
|
|
||||||
}
|
|
||||||
startIndex = cursor
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "", 0, fmt.Errorf("%w", ErrDoubleQuoteUnterminated)
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleSingleQuoted(input string, startIndex int, buffer *bytes.Buffer) (
|
|
||||||
word string, newStartIndex int, err error,
|
|
||||||
) {
|
|
||||||
closingQuoteIndex := strings.IndexRune(input[startIndex:], '\'')
|
|
||||||
if closingQuoteIndex == -1 {
|
|
||||||
return "", 0, fmt.Errorf("%w", ErrSingleQuoteUnterminated)
|
|
||||||
}
|
|
||||||
buffer.WriteString(input[startIndex : startIndex+closingQuoteIndex])
|
|
||||||
const singleQuoteRuneLength = 1
|
|
||||||
startIndex += closingQuoteIndex + singleQuoteRuneLength
|
|
||||||
return splitWord(input, startIndex, buffer)
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleEscaped(input string, startIndex int, buffer *bytes.Buffer) (
|
|
||||||
word string, newStartIndex int, err error,
|
|
||||||
) {
|
|
||||||
if input[startIndex:] == "" {
|
|
||||||
return "", 0, fmt.Errorf("%w", ErrEscapeUnterminated)
|
|
||||||
}
|
|
||||||
character, runeLength := utf8.DecodeRuneInString(input[startIndex:])
|
|
||||||
if character != '\n' { // backslash-escaped newline is ignored
|
|
||||||
buffer.WriteString(input[startIndex : startIndex+runeLength])
|
|
||||||
}
|
|
||||||
startIndex += runeLength
|
|
||||||
return splitWord(input, startIndex, buffer)
|
|
||||||
}
|
|
||||||
@@ -1,110 +0,0 @@
|
|||||||
package command
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Test_Split(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
testCases := map[string]struct {
|
|
||||||
command string
|
|
||||||
words []string
|
|
||||||
errWrapped error
|
|
||||||
errMessage string
|
|
||||||
}{
|
|
||||||
"empty": {
|
|
||||||
command: "",
|
|
||||||
errWrapped: ErrCommandEmpty,
|
|
||||||
errMessage: "command is empty",
|
|
||||||
},
|
|
||||||
"concrete_sh_command": {
|
|
||||||
command: `/bin/sh -c "echo 123"`,
|
|
||||||
words: []string{"/bin/sh", "-c", "echo 123"},
|
|
||||||
},
|
|
||||||
"single_word": {
|
|
||||||
command: "word1",
|
|
||||||
words: []string{"word1"},
|
|
||||||
},
|
|
||||||
"two_words_single_space": {
|
|
||||||
command: "word1 word2",
|
|
||||||
words: []string{"word1", "word2"},
|
|
||||||
},
|
|
||||||
"two_words_multiple_space": {
|
|
||||||
command: "word1 word2",
|
|
||||||
words: []string{"word1", "word2"},
|
|
||||||
},
|
|
||||||
"two_words_no_expansion": {
|
|
||||||
command: "word1* word2?",
|
|
||||||
words: []string{"word1*", "word2?"},
|
|
||||||
},
|
|
||||||
"escaped_single quote": {
|
|
||||||
command: "ain\\'t good",
|
|
||||||
words: []string{"ain't", "good"},
|
|
||||||
},
|
|
||||||
"escaped_single_quote_all_single_quoted": {
|
|
||||||
command: "'ain'\\''t good'",
|
|
||||||
words: []string{"ain't good"},
|
|
||||||
},
|
|
||||||
"empty_single_quoted": {
|
|
||||||
command: "word1 '' word2",
|
|
||||||
words: []string{"word1", "", "word2"},
|
|
||||||
},
|
|
||||||
"escaped_newline": {
|
|
||||||
command: "word1\\\nword2",
|
|
||||||
words: []string{"word1word2"},
|
|
||||||
},
|
|
||||||
"quoted_newline": {
|
|
||||||
command: "text \"with\na\" quoted newline",
|
|
||||||
words: []string{"text", "with\na", "quoted", "newline"},
|
|
||||||
},
|
|
||||||
"quoted_escaped_newline": {
|
|
||||||
command: "\"word1\\d\\\\\\\" word2\\\nword3 word4\"",
|
|
||||||
words: []string{"word1\\d\\\" word2word3 word4"},
|
|
||||||
},
|
|
||||||
"escaped_separated_newline": {
|
|
||||||
command: "word1 \\\n word2",
|
|
||||||
words: []string{"word1", "word2"},
|
|
||||||
},
|
|
||||||
"double_quotes_no_spacing": {
|
|
||||||
command: "word1\"word2\"word3",
|
|
||||||
words: []string{"word1word2word3"},
|
|
||||||
},
|
|
||||||
"unterminated_single_quote": {
|
|
||||||
command: "'abc'\\''def",
|
|
||||||
errWrapped: ErrSingleQuoteUnterminated,
|
|
||||||
errMessage: `splitting word in "'abc'\\''def": unterminated single-quoted string`,
|
|
||||||
},
|
|
||||||
"unterminated_double_quote": {
|
|
||||||
command: "\"abc'def",
|
|
||||||
errWrapped: ErrDoubleQuoteUnterminated,
|
|
||||||
errMessage: `splitting word in "\"abc'def": unterminated double-quoted string`,
|
|
||||||
},
|
|
||||||
"unterminated_escape": {
|
|
||||||
command: "abc\\",
|
|
||||||
errWrapped: ErrEscapeUnterminated,
|
|
||||||
errMessage: `splitting word in "abc\\": unterminated backslash-escape`,
|
|
||||||
},
|
|
||||||
"unterminated_escape_only": {
|
|
||||||
command: " \\",
|
|
||||||
errWrapped: ErrEscapeUnterminated,
|
|
||||||
errMessage: `unterminated backslash-escape: " \\"`,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for name, testCase := range testCases {
|
|
||||||
t.Run(name, func(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
words, err := Split(testCase.command)
|
|
||||||
|
|
||||||
assert.Equal(t, testCase.words, words)
|
|
||||||
assert.ErrorIs(t, err, testCase.errWrapped)
|
|
||||||
if testCase.errWrapped != nil {
|
|
||||||
assert.EqualError(t, err, testCase.errMessage)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -29,14 +29,6 @@ type PortForwarding struct {
|
|||||||
// to write to a file. It cannot be nil for the
|
// to write to a file. It cannot be nil for the
|
||||||
// internal state
|
// internal state
|
||||||
Filepath *string `json:"status_file_path"`
|
Filepath *string `json:"status_file_path"`
|
||||||
// UpCommand is the command to use when the port forwarding is up.
|
|
||||||
// It can be the empty string to indicate not to run a command.
|
|
||||||
// It cannot be nil in the internal state.
|
|
||||||
UpCommand *string `json:"up_command"`
|
|
||||||
// DownCommand is the command to use after the port forwarding goes down.
|
|
||||||
// It can be the empty string to indicate to NOT run a command.
|
|
||||||
// It cannot be nil in the internal state.
|
|
||||||
DownCommand *string `json:"down_command"`
|
|
||||||
// ListeningPort is the port traffic would be redirected to from the
|
// ListeningPort is the port traffic would be redirected to from the
|
||||||
// forwarded port. The redirection is disabled if it is set to 0, which
|
// forwarded port. The redirection is disabled if it is set to 0, which
|
||||||
// is its default as well.
|
// is its default as well.
|
||||||
@@ -92,8 +84,6 @@ func (p *PortForwarding) Copy() (copied PortForwarding) {
|
|||||||
Enabled: gosettings.CopyPointer(p.Enabled),
|
Enabled: gosettings.CopyPointer(p.Enabled),
|
||||||
Provider: gosettings.CopyPointer(p.Provider),
|
Provider: gosettings.CopyPointer(p.Provider),
|
||||||
Filepath: gosettings.CopyPointer(p.Filepath),
|
Filepath: gosettings.CopyPointer(p.Filepath),
|
||||||
UpCommand: gosettings.CopyPointer(p.UpCommand),
|
|
||||||
DownCommand: gosettings.CopyPointer(p.DownCommand),
|
|
||||||
ListeningPort: gosettings.CopyPointer(p.ListeningPort),
|
ListeningPort: gosettings.CopyPointer(p.ListeningPort),
|
||||||
Username: p.Username,
|
Username: p.Username,
|
||||||
Password: p.Password,
|
Password: p.Password,
|
||||||
@@ -104,8 +94,6 @@ func (p *PortForwarding) OverrideWith(other PortForwarding) {
|
|||||||
p.Enabled = gosettings.OverrideWithPointer(p.Enabled, other.Enabled)
|
p.Enabled = gosettings.OverrideWithPointer(p.Enabled, other.Enabled)
|
||||||
p.Provider = gosettings.OverrideWithPointer(p.Provider, other.Provider)
|
p.Provider = gosettings.OverrideWithPointer(p.Provider, other.Provider)
|
||||||
p.Filepath = gosettings.OverrideWithPointer(p.Filepath, other.Filepath)
|
p.Filepath = gosettings.OverrideWithPointer(p.Filepath, other.Filepath)
|
||||||
p.UpCommand = gosettings.OverrideWithPointer(p.UpCommand, other.UpCommand)
|
|
||||||
p.DownCommand = gosettings.OverrideWithPointer(p.DownCommand, other.DownCommand)
|
|
||||||
p.ListeningPort = gosettings.OverrideWithPointer(p.ListeningPort, other.ListeningPort)
|
p.ListeningPort = gosettings.OverrideWithPointer(p.ListeningPort, other.ListeningPort)
|
||||||
p.Username = gosettings.OverrideWithComparable(p.Username, other.Username)
|
p.Username = gosettings.OverrideWithComparable(p.Username, other.Username)
|
||||||
p.Password = gosettings.OverrideWithComparable(p.Password, other.Password)
|
p.Password = gosettings.OverrideWithComparable(p.Password, other.Password)
|
||||||
@@ -115,8 +103,6 @@ func (p *PortForwarding) setDefaults() {
|
|||||||
p.Enabled = gosettings.DefaultPointer(p.Enabled, false)
|
p.Enabled = gosettings.DefaultPointer(p.Enabled, false)
|
||||||
p.Provider = gosettings.DefaultPointer(p.Provider, "")
|
p.Provider = gosettings.DefaultPointer(p.Provider, "")
|
||||||
p.Filepath = gosettings.DefaultPointer(p.Filepath, "/tmp/gluetun/forwarded_port")
|
p.Filepath = gosettings.DefaultPointer(p.Filepath, "/tmp/gluetun/forwarded_port")
|
||||||
p.UpCommand = gosettings.DefaultPointer(p.UpCommand, "")
|
|
||||||
p.DownCommand = gosettings.DefaultPointer(p.DownCommand, "")
|
|
||||||
p.ListeningPort = gosettings.DefaultPointer(p.ListeningPort, 0)
|
p.ListeningPort = gosettings.DefaultPointer(p.ListeningPort, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,13 +135,6 @@ func (p PortForwarding) toLinesNode() (node *gotree.Node) {
|
|||||||
}
|
}
|
||||||
node.Appendf("Forwarded port file path: %s", filepath)
|
node.Appendf("Forwarded port file path: %s", filepath)
|
||||||
|
|
||||||
if *p.UpCommand != "" {
|
|
||||||
node.Appendf("Forwarded port up command: %s", *p.UpCommand)
|
|
||||||
}
|
|
||||||
if *p.DownCommand != "" {
|
|
||||||
node.Appendf("Forwarded port down command: %s", *p.DownCommand)
|
|
||||||
}
|
|
||||||
|
|
||||||
if p.Username != "" {
|
if p.Username != "" {
|
||||||
credentialsNode := node.Appendf("Credentials:")
|
credentialsNode := node.Appendf("Credentials:")
|
||||||
credentialsNode.Appendf("Username: %s", p.Username)
|
credentialsNode.Appendf("Username: %s", p.Username)
|
||||||
@@ -184,12 +163,6 @@ func (p *PortForwarding) read(r *reader.Reader) (err error) {
|
|||||||
"PRIVATE_INTERNET_ACCESS_VPN_PORT_FORWARDING_STATUS_FILE",
|
"PRIVATE_INTERNET_ACCESS_VPN_PORT_FORWARDING_STATUS_FILE",
|
||||||
))
|
))
|
||||||
|
|
||||||
p.UpCommand = r.Get("VPN_PORT_FORWARDING_UP_COMMAND",
|
|
||||||
reader.ForceLowercase(false))
|
|
||||||
|
|
||||||
p.DownCommand = r.Get("VPN_PORT_FORWARDING_DOWN_COMMAND",
|
|
||||||
reader.ForceLowercase(false))
|
|
||||||
|
|
||||||
p.ListeningPort, err = r.Uint16Ptr("VPN_PORT_FORWARDING_LISTENING_PORT")
|
p.ListeningPort, err = r.Uint16Ptr("VPN_PORT_FORWARDING_LISTENING_PORT")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -22,14 +22,15 @@ func (l *Loop) SetSettings(ctx context.Context, settings settings.DNS) (
|
|||||||
return l.state.SetSettings(ctx, settings)
|
return l.state.SetSettings(ctx, settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildDoTSettings(settings settings.DNS,
|
func buildServerSettings(settings settings.DNS,
|
||||||
filter *mapfilter.Filter, logger Logger) (
|
filter *mapfilter.Filter, logger Logger) (
|
||||||
serverSettings server.Settings, err error,
|
serverSettings server.Settings, err error,
|
||||||
) {
|
) {
|
||||||
serverSettings.Logger = logger
|
serverSettings.Logger = logger
|
||||||
|
providersData := provider.NewProviders()
|
||||||
|
|
||||||
var dotSettings dot.Settings
|
var dotSettings dot.Settings
|
||||||
providersData := provider.NewProviders()
|
dotSettings.Warner = logger
|
||||||
dotSettings.UpstreamResolvers = make([]provider.Provider, len(settings.DoT.Providers))
|
dotSettings.UpstreamResolvers = make([]provider.Provider, len(settings.DoT.Providers))
|
||||||
for i := range settings.DoT.Providers {
|
for i := range settings.DoT.Providers {
|
||||||
var err error
|
var err error
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func (l *Loop) setupServer(ctx context.Context) (runError <-chan error, err erro
|
|||||||
|
|
||||||
settings := l.GetSettings()
|
settings := l.GetSettings()
|
||||||
|
|
||||||
dotSettings, err := buildDoTSettings(settings, l.filter, l.logger)
|
dotSettings, err := buildServerSettings(settings, l.filter, l.logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("building DoT settings: %w", err)
|
return nil, fmt.Errorf("building DoT settings: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ type chainRule struct {
|
|||||||
packets uint64
|
packets uint64
|
||||||
bytes uint64
|
bytes uint64
|
||||||
target string // "ACCEPT", "DROP", "REJECT" or "REDIRECT"
|
target string // "ACCEPT", "DROP", "REJECT" or "REDIRECT"
|
||||||
protocol string // "icmp", "tcp", "udp" or "" for all protocols.
|
protocol string // "tcp", "udp" or "" for all protocols.
|
||||||
inputInterface string // input interface, for example "tun0" or "*""
|
inputInterface string // input interface, for example "tun0" or "*""
|
||||||
outputInterface string // output interface, for example "eth0" or "*""
|
outputInterface string // output interface, for example "eth0" or "*""
|
||||||
source netip.Prefix // source IP CIDR, for example 0.0.0.0/0. Must be valid.
|
source netip.Prefix // source IP CIDR, for example 0.0.0.0/0. Must be valid.
|
||||||
@@ -324,8 +324,6 @@ var ErrProtocolUnknown = errors.New("unknown protocol")
|
|||||||
func parseProtocol(s string) (protocol string, err error) {
|
func parseProtocol(s string) (protocol string, err error) {
|
||||||
switch s {
|
switch s {
|
||||||
case "0":
|
case "0":
|
||||||
case "1":
|
|
||||||
protocol = "icmp"
|
|
||||||
case "6":
|
case "6":
|
||||||
protocol = "tcp"
|
protocol = "tcp"
|
||||||
case "17":
|
case "17":
|
||||||
|
|||||||
@@ -56,8 +56,7 @@ num pkts bytes target prot opt in out source destinati
|
|||||||
num pkts bytes target prot opt in out source destination
|
num pkts bytes target prot opt in out source destination
|
||||||
1 0 0 ACCEPT 17 -- tun0 * 0.0.0.0/0 0.0.0.0/0 udp dpt:55405
|
1 0 0 ACCEPT 17 -- tun0 * 0.0.0.0/0 0.0.0.0/0 udp dpt:55405
|
||||||
2 0 0 ACCEPT 6 -- tun0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:55405
|
2 0 0 ACCEPT 6 -- tun0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:55405
|
||||||
3 0 0 ACCEPT 1 -- tun0 * 0.0.0.0/0 0.0.0.0/0
|
3 0 0 DROP 0 -- tun0 * 1.2.3.4 0.0.0.0/0
|
||||||
4 0 0 DROP 0 -- tun0 * 1.2.3.4 0.0.0.0/0
|
|
||||||
`,
|
`,
|
||||||
table: chain{
|
table: chain{
|
||||||
name: "INPUT",
|
name: "INPUT",
|
||||||
@@ -93,17 +92,6 @@ num pkts bytes target prot opt in out source destinati
|
|||||||
lineNumber: 3,
|
lineNumber: 3,
|
||||||
packets: 0,
|
packets: 0,
|
||||||
bytes: 0,
|
bytes: 0,
|
||||||
target: "ACCEPT",
|
|
||||||
protocol: "icmp",
|
|
||||||
inputInterface: "tun0",
|
|
||||||
outputInterface: "*",
|
|
||||||
source: netip.MustParsePrefix("0.0.0.0/0"),
|
|
||||||
destination: netip.MustParsePrefix("0.0.0.0/0"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lineNumber: 4,
|
|
||||||
packets: 0,
|
|
||||||
bytes: 0,
|
|
||||||
target: "DROP",
|
target: "DROP",
|
||||||
protocol: "",
|
protocol: "",
|
||||||
inputInterface: "tun0",
|
inputInterface: "tun0",
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ func testIptablesPath(ctx context.Context, path string,
|
|||||||
// Set policy as the existing policy so no mutation is done.
|
// Set policy as the existing policy so no mutation is done.
|
||||||
// This is an extra check for some buggy kernels where setting the policy
|
// This is an extra check for some buggy kernels where setting the policy
|
||||||
// does not work.
|
// does not work.
|
||||||
cmd = exec.CommandContext(ctx, path, "-nL", "INPUT")
|
cmd = exec.CommandContext(ctx, path, "-L", "INPUT")
|
||||||
output, err = runner.Run(cmd)
|
output, err = runner.Run(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
unsupportedMessage = fmt.Sprintf("%s (%s)", output, err)
|
unsupportedMessage = fmt.Sprintf("%s (%s)", output, err)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ func newDeleteTestRuleMatcher(path string) *cmdMatcher {
|
|||||||
|
|
||||||
func newListInputRulesMatcher(path string) *cmdMatcher {
|
func newListInputRulesMatcher(path string) *cmdMatcher {
|
||||||
return newCmdMatcher(path,
|
return newCmdMatcher(path,
|
||||||
"^-nL$", "^INPUT$")
|
"^-L$", "^INPUT$")
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSetPolicyMatcher(path, inputPolicy string) *cmdMatcher { //nolint:unparam
|
func newSetPolicyMatcher(path, inputPolicy string) *cmdMatcher { //nolint:unparam
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package natpmp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net"
|
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -24,15 +23,14 @@ func Test_Client_ExternalAddress(t *testing.T) {
|
|||||||
durationSinceStartOfEpoch time.Duration
|
durationSinceStartOfEpoch time.Duration
|
||||||
externalIPv4Address netip.Addr
|
externalIPv4Address netip.Addr
|
||||||
err error
|
err error
|
||||||
errMessageRegex string
|
errMessage string
|
||||||
}{
|
}{
|
||||||
"failure": {
|
"failure": {
|
||||||
ctx: canceledCtx,
|
ctx: canceledCtx,
|
||||||
gateway: netip.AddrFrom4([4]byte{127, 0, 0, 1}),
|
gateway: netip.AddrFrom4([4]byte{127, 0, 0, 1}),
|
||||||
initialConnDuration: initialConnectionDuration,
|
initialConnDuration: initialConnectionDuration,
|
||||||
err: net.ErrClosed,
|
err: context.Canceled,
|
||||||
errMessageRegex: "executing remote procedure call: setting connection deadline: " +
|
errMessage: "executing remote procedure call: reading from udp connection: context canceled",
|
||||||
"set udp 127.0.0.1:[1-9][0-9]{1,4}: use of closed network connection",
|
|
||||||
},
|
},
|
||||||
"success": {
|
"success": {
|
||||||
ctx: context.Background(),
|
ctx: context.Background(),
|
||||||
@@ -62,7 +60,7 @@ func Test_Client_ExternalAddress(t *testing.T) {
|
|||||||
durationSinceStartOfEpoch, externalIPv4Address, err := client.ExternalAddress(testCase.ctx, testCase.gateway)
|
durationSinceStartOfEpoch, externalIPv4Address, err := client.ExternalAddress(testCase.ctx, testCase.gateway)
|
||||||
assert.ErrorIs(t, err, testCase.err)
|
assert.ErrorIs(t, err, testCase.err)
|
||||||
if testCase.err != nil {
|
if testCase.err != nil {
|
||||||
assert.Regexp(t, testCase.errMessageRegex, err.Error())
|
assert.EqualError(t, err, testCase.errMessage)
|
||||||
}
|
}
|
||||||
assert.Equal(t, testCase.durationSinceStartOfEpoch, durationSinceStartOfEpoch)
|
assert.Equal(t, testCase.durationSinceStartOfEpoch, durationSinceStartOfEpoch)
|
||||||
assert.Equal(t, testCase.externalIPv4Address, externalIPv4Address)
|
assert.Equal(t, testCase.externalIPv4Address, externalIPv4Address)
|
||||||
|
|||||||
@@ -45,10 +45,8 @@ func (c *Client) rpc(ctx context.Context, gateway netip.Addr,
|
|||||||
cancel()
|
cancel()
|
||||||
<-endGoroutineDone
|
<-endGoroutineDone
|
||||||
}()
|
}()
|
||||||
ctxListeningReady := make(chan struct{})
|
|
||||||
go func() {
|
go func() {
|
||||||
defer close(endGoroutineDone)
|
defer close(endGoroutineDone)
|
||||||
close(ctxListeningReady)
|
|
||||||
// Context is canceled either by the parent context or
|
// Context is canceled either by the parent context or
|
||||||
// when this function returns.
|
// when this function returns.
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
@@ -62,7 +60,6 @@ func (c *Client) rpc(ctx context.Context, gateway netip.Addr,
|
|||||||
}
|
}
|
||||||
err = fmt.Errorf("%w; closing connection: %w", err, closeErr)
|
err = fmt.Errorf("%w; closing connection: %w", err, closeErr)
|
||||||
}()
|
}()
|
||||||
<-ctxListeningReady // really to make unit testing reliable
|
|
||||||
|
|
||||||
const maxResponseSize = 16
|
const maxResponseSize = 16
|
||||||
response = make([]byte, maxResponseSize)
|
response = make([]byte, maxResponseSize)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package portforward
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"os/exec"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Service interface {
|
type Service interface {
|
||||||
@@ -30,8 +29,3 @@ type Logger interface {
|
|||||||
Warn(s string)
|
Warn(s string)
|
||||||
Error(s string)
|
Error(s string)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Cmder interface {
|
|
||||||
Start(cmd *exec.Cmd) (stdoutLines, stderrLines <-chan string,
|
|
||||||
waitError <-chan error, startErr error)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ type Loop struct {
|
|||||||
client *http.Client
|
client *http.Client
|
||||||
portAllower PortAllower
|
portAllower PortAllower
|
||||||
logger Logger
|
logger Logger
|
||||||
cmder Cmder
|
|
||||||
// Fixed parameters
|
// Fixed parameters
|
||||||
uid, gid int
|
uid, gid int
|
||||||
// Internal channels and locks
|
// Internal channels and locks
|
||||||
@@ -35,7 +34,7 @@ type Loop struct {
|
|||||||
|
|
||||||
func NewLoop(settings settings.PortForwarding, routing Routing,
|
func NewLoop(settings settings.PortForwarding, routing Routing,
|
||||||
client *http.Client, portAllower PortAllower,
|
client *http.Client, portAllower PortAllower,
|
||||||
logger Logger, cmder Cmder, uid, gid int,
|
logger Logger, uid, gid int,
|
||||||
) *Loop {
|
) *Loop {
|
||||||
return &Loop{
|
return &Loop{
|
||||||
settings: Settings{
|
settings: Settings{
|
||||||
@@ -43,8 +42,6 @@ func NewLoop(settings settings.PortForwarding, routing Routing,
|
|||||||
Service: service.Settings{
|
Service: service.Settings{
|
||||||
Enabled: settings.Enabled,
|
Enabled: settings.Enabled,
|
||||||
Filepath: *settings.Filepath,
|
Filepath: *settings.Filepath,
|
||||||
UpCommand: *settings.UpCommand,
|
|
||||||
DownCommand: *settings.DownCommand,
|
|
||||||
ListeningPort: *settings.ListeningPort,
|
ListeningPort: *settings.ListeningPort,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -52,7 +49,6 @@ func NewLoop(settings settings.PortForwarding, routing Routing,
|
|||||||
client: client,
|
client: client,
|
||||||
portAllower: portAllower,
|
portAllower: portAllower,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
cmder: cmder,
|
|
||||||
uid: uid,
|
uid: uid,
|
||||||
gid: gid,
|
gid: gid,
|
||||||
}
|
}
|
||||||
@@ -119,7 +115,7 @@ func (l *Loop) run(runCtx context.Context, runDone chan<- struct{},
|
|||||||
*serviceSettings.Enabled = *serviceSettings.Enabled && *l.settings.VPNIsUp
|
*serviceSettings.Enabled = *serviceSettings.Enabled && *l.settings.VPNIsUp
|
||||||
|
|
||||||
l.service = service.New(serviceSettings, l.routing, l.client,
|
l.service = service.New(serviceSettings, l.routing, l.client,
|
||||||
l.portAllower, l.logger, l.cmder, l.uid, l.gid)
|
l.portAllower, l.logger, l.uid, l.gid)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
serviceRunError, err = l.service.Start(runCtx)
|
serviceRunError, err = l.service.Start(runCtx)
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
package service
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"os/exec"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/command"
|
|
||||||
)
|
|
||||||
|
|
||||||
func runCommand(ctx context.Context, cmder Cmder, logger Logger,
|
|
||||||
commandTemplate string, ports []uint16,
|
|
||||||
) (err error) {
|
|
||||||
portStrings := make([]string, len(ports))
|
|
||||||
for i, port := range ports {
|
|
||||||
portStrings[i] = fmt.Sprint(int(port))
|
|
||||||
}
|
|
||||||
portsString := strings.Join(portStrings, ",")
|
|
||||||
commandString := strings.ReplaceAll(commandTemplate, "{{PORTS}}", portsString)
|
|
||||||
args, err := command.Split(commandString)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("parsing command: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := exec.CommandContext(ctx, args[0], args[1:]...) // #nosec G204
|
|
||||||
stdout, stderr, waitError, err := cmder.Start(cmd)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
streamCtx, streamCancel := context.WithCancel(context.Background())
|
|
||||||
streamDone := make(chan struct{})
|
|
||||||
go streamLines(streamCtx, streamDone, logger, stdout, stderr)
|
|
||||||
|
|
||||||
err = <-waitError
|
|
||||||
streamCancel()
|
|
||||||
<-streamDone
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func streamLines(ctx context.Context, done chan<- struct{},
|
|
||||||
logger Logger, stdout, stderr <-chan string,
|
|
||||||
) {
|
|
||||||
defer close(done)
|
|
||||||
|
|
||||||
var line string
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
return
|
|
||||||
case line = <-stdout:
|
|
||||||
logger.Info(line)
|
|
||||||
case line = <-stderr:
|
|
||||||
logger.Error(line)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
//go:build linux
|
|
||||||
|
|
||||||
package service
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
gomock "github.com/golang/mock/gomock"
|
|
||||||
"github.com/qdm12/gluetun/internal/command"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Test_Service_runCommand(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
ctrl := gomock.NewController(t)
|
|
||||||
|
|
||||||
ctx := context.Background()
|
|
||||||
cmder := command.New()
|
|
||||||
const commandTemplate = `/bin/sh -c "echo {{PORTS}}"`
|
|
||||||
ports := []uint16{1234, 5678}
|
|
||||||
logger := NewMockLogger(ctrl)
|
|
||||||
logger.EXPECT().Info("1234,5678")
|
|
||||||
|
|
||||||
err := runCommand(ctx, cmder, logger, commandTemplate, ports)
|
|
||||||
|
|
||||||
require.NoError(t, err)
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@ package service
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"os/exec"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
)
|
)
|
||||||
@@ -33,8 +32,3 @@ type PortForwarder interface {
|
|||||||
ports []uint16, err error)
|
ports []uint16, err error)
|
||||||
KeepPortForward(ctx context.Context, objects utils.PortForwardObjects) (err error)
|
KeepPortForward(ctx context.Context, objects utils.PortForwardObjects) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Cmder interface {
|
|
||||||
Start(cmd *exec.Cmd) (stdoutLines, stderrLines <-chan string,
|
|
||||||
waitError <-chan error, startErr error)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
package service
|
|
||||||
|
|
||||||
//go:generate mockgen -destination=mocks_test.go -package=$GOPACKAGE . Logger
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
// Code generated by MockGen. DO NOT EDIT.
|
|
||||||
// Source: github.com/qdm12/gluetun/internal/portforward/service (interfaces: Logger)
|
|
||||||
|
|
||||||
// Package service is a generated GoMock package.
|
|
||||||
package service
|
|
||||||
|
|
||||||
import (
|
|
||||||
reflect "reflect"
|
|
||||||
|
|
||||||
gomock "github.com/golang/mock/gomock"
|
|
||||||
)
|
|
||||||
|
|
||||||
// MockLogger is a mock of Logger interface.
|
|
||||||
type MockLogger struct {
|
|
||||||
ctrl *gomock.Controller
|
|
||||||
recorder *MockLoggerMockRecorder
|
|
||||||
}
|
|
||||||
|
|
||||||
// MockLoggerMockRecorder is the mock recorder for MockLogger.
|
|
||||||
type MockLoggerMockRecorder struct {
|
|
||||||
mock *MockLogger
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMockLogger creates a new mock instance.
|
|
||||||
func NewMockLogger(ctrl *gomock.Controller) *MockLogger {
|
|
||||||
mock := &MockLogger{ctrl: ctrl}
|
|
||||||
mock.recorder = &MockLoggerMockRecorder{mock}
|
|
||||||
return mock
|
|
||||||
}
|
|
||||||
|
|
||||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
|
||||||
func (m *MockLogger) EXPECT() *MockLoggerMockRecorder {
|
|
||||||
return m.recorder
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debug mocks base method.
|
|
||||||
func (m *MockLogger) Debug(arg0 string) {
|
|
||||||
m.ctrl.T.Helper()
|
|
||||||
m.ctrl.Call(m, "Debug", arg0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debug indicates an expected call of Debug.
|
|
||||||
func (mr *MockLoggerMockRecorder) Debug(arg0 interface{}) *gomock.Call {
|
|
||||||
mr.mock.ctrl.T.Helper()
|
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Debug", reflect.TypeOf((*MockLogger)(nil).Debug), arg0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error mocks base method.
|
|
||||||
func (m *MockLogger) Error(arg0 string) {
|
|
||||||
m.ctrl.T.Helper()
|
|
||||||
m.ctrl.Call(m, "Error", arg0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error indicates an expected call of Error.
|
|
||||||
func (mr *MockLoggerMockRecorder) Error(arg0 interface{}) *gomock.Call {
|
|
||||||
mr.mock.ctrl.T.Helper()
|
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Error", reflect.TypeOf((*MockLogger)(nil).Error), arg0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Info mocks base method.
|
|
||||||
func (m *MockLogger) Info(arg0 string) {
|
|
||||||
m.ctrl.T.Helper()
|
|
||||||
m.ctrl.Call(m, "Info", arg0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Info indicates an expected call of Info.
|
|
||||||
func (mr *MockLoggerMockRecorder) Info(arg0 interface{}) *gomock.Call {
|
|
||||||
mr.mock.ctrl.T.Helper()
|
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Info", reflect.TypeOf((*MockLogger)(nil).Info), arg0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warn mocks base method.
|
|
||||||
func (m *MockLogger) Warn(arg0 string) {
|
|
||||||
m.ctrl.T.Helper()
|
|
||||||
m.ctrl.Call(m, "Warn", arg0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warn indicates an expected call of Warn.
|
|
||||||
func (mr *MockLoggerMockRecorder) Warn(arg0 interface{}) *gomock.Call {
|
|
||||||
mr.mock.ctrl.T.Helper()
|
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Warn", reflect.TypeOf((*MockLogger)(nil).Warn), arg0)
|
|
||||||
}
|
|
||||||
@@ -19,7 +19,6 @@ type Service struct {
|
|||||||
client *http.Client
|
client *http.Client
|
||||||
portAllower PortAllower
|
portAllower PortAllower
|
||||||
logger Logger
|
logger Logger
|
||||||
cmder Cmder
|
|
||||||
// Internal channels and locks
|
// Internal channels and locks
|
||||||
startStopMutex sync.Mutex
|
startStopMutex sync.Mutex
|
||||||
keepPortCancel context.CancelFunc
|
keepPortCancel context.CancelFunc
|
||||||
@@ -27,7 +26,7 @@ type Service struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(settings Settings, routing Routing, client *http.Client,
|
func New(settings Settings, routing Routing, client *http.Client,
|
||||||
portAllower PortAllower, logger Logger, cmder Cmder, puid, pgid int,
|
portAllower PortAllower, logger Logger, puid, pgid int,
|
||||||
) *Service {
|
) *Service {
|
||||||
return &Service{
|
return &Service{
|
||||||
// Fixed parameters
|
// Fixed parameters
|
||||||
@@ -39,7 +38,6 @@ func New(settings Settings, routing Routing, client *http.Client,
|
|||||||
client: client,
|
client: client,
|
||||||
portAllower: portAllower,
|
portAllower: portAllower,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
cmder: cmder,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ type Settings struct {
|
|||||||
Enabled *bool
|
Enabled *bool
|
||||||
PortForwarder PortForwarder
|
PortForwarder PortForwarder
|
||||||
Filepath string
|
Filepath string
|
||||||
UpCommand string
|
|
||||||
DownCommand string
|
|
||||||
Interface string // needed for PIA, PrivateVPN and ProtonVPN, tun0 for example
|
Interface string // needed for PIA, PrivateVPN and ProtonVPN, tun0 for example
|
||||||
ServerName string // needed for PIA
|
ServerName string // needed for PIA
|
||||||
CanPortForward bool // needed for PIA
|
CanPortForward bool // needed for PIA
|
||||||
@@ -26,8 +24,6 @@ func (s Settings) Copy() (copied Settings) {
|
|||||||
copied.Enabled = gosettings.CopyPointer(s.Enabled)
|
copied.Enabled = gosettings.CopyPointer(s.Enabled)
|
||||||
copied.PortForwarder = s.PortForwarder
|
copied.PortForwarder = s.PortForwarder
|
||||||
copied.Filepath = s.Filepath
|
copied.Filepath = s.Filepath
|
||||||
copied.UpCommand = s.UpCommand
|
|
||||||
copied.DownCommand = s.DownCommand
|
|
||||||
copied.Interface = s.Interface
|
copied.Interface = s.Interface
|
||||||
copied.ServerName = s.ServerName
|
copied.ServerName = s.ServerName
|
||||||
copied.CanPortForward = s.CanPortForward
|
copied.CanPortForward = s.CanPortForward
|
||||||
@@ -41,8 +37,6 @@ func (s *Settings) OverrideWith(update Settings) {
|
|||||||
s.Enabled = gosettings.OverrideWithPointer(s.Enabled, update.Enabled)
|
s.Enabled = gosettings.OverrideWithPointer(s.Enabled, update.Enabled)
|
||||||
s.PortForwarder = gosettings.OverrideWithComparable(s.PortForwarder, update.PortForwarder)
|
s.PortForwarder = gosettings.OverrideWithComparable(s.PortForwarder, update.PortForwarder)
|
||||||
s.Filepath = gosettings.OverrideWithComparable(s.Filepath, update.Filepath)
|
s.Filepath = gosettings.OverrideWithComparable(s.Filepath, update.Filepath)
|
||||||
s.UpCommand = gosettings.OverrideWithComparable(s.UpCommand, update.UpCommand)
|
|
||||||
s.DownCommand = gosettings.OverrideWithComparable(s.DownCommand, update.DownCommand)
|
|
||||||
s.Interface = gosettings.OverrideWithComparable(s.Interface, update.Interface)
|
s.Interface = gosettings.OverrideWithComparable(s.Interface, update.Interface)
|
||||||
s.ServerName = gosettings.OverrideWithComparable(s.ServerName, update.ServerName)
|
s.ServerName = gosettings.OverrideWithComparable(s.ServerName, update.ServerName)
|
||||||
s.CanPortForward = gosettings.OverrideWithComparable(s.CanPortForward, update.CanPortForward)
|
s.CanPortForward = gosettings.OverrideWithComparable(s.CanPortForward, update.CanPortForward)
|
||||||
|
|||||||
@@ -73,14 +73,6 @@ func (s *Service) Start(ctx context.Context) (runError <-chan error, err error)
|
|||||||
s.ports = ports
|
s.ports = ports
|
||||||
s.portMutex.Unlock()
|
s.portMutex.Unlock()
|
||||||
|
|
||||||
if s.settings.UpCommand != "" {
|
|
||||||
err = runCommand(ctx, s.cmder, s.logger, s.settings.UpCommand, ports)
|
|
||||||
if err != nil {
|
|
||||||
err = fmt.Errorf("running up command: %w", err)
|
|
||||||
s.logger.Error(err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
keepPortCtx, keepPortCancel := context.WithCancel(context.Background())
|
keepPortCtx, keepPortCancel := context.WithCancel(context.Background())
|
||||||
s.keepPortCancel = keepPortCancel
|
s.keepPortCancel = keepPortCancel
|
||||||
runErrorCh := make(chan error)
|
runErrorCh := make(chan error)
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Service) Stop() (err error) {
|
func (s *Service) Stop() (err error) {
|
||||||
@@ -31,17 +30,6 @@ func (s *Service) cleanup() (err error) {
|
|||||||
s.portMutex.Lock()
|
s.portMutex.Lock()
|
||||||
defer s.portMutex.Unlock()
|
defer s.portMutex.Unlock()
|
||||||
|
|
||||||
if s.settings.DownCommand != "" {
|
|
||||||
const downTimeout = 60 * time.Second
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), downTimeout)
|
|
||||||
defer cancel()
|
|
||||||
err = runCommand(ctx, s.cmder, s.logger, s.settings.DownCommand, s.ports)
|
|
||||||
if err != nil {
|
|
||||||
err = fmt.Errorf("running down command: %w", err)
|
|
||||||
s.logger.Error(err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, port := range s.ports {
|
for _, port := range s.ports {
|
||||||
err = s.portAllower.RemoveAllowedPort(context.Background(), port)
|
err = s.portAllower.RemoveAllowedPort(context.Background(), port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ func hardcodedServers() (servers []models.Server) {
|
|||||||
{Country: "Canada", City: "Montreal", Hostname: "canada-montreal-ca-version-2.expressnetw.com"},
|
{Country: "Canada", City: "Montreal", Hostname: "canada-montreal-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Canada", City: "Toronto", Hostname: "canada-toronto-2-ca-version-2.expressnetw.com"},
|
{Country: "Canada", City: "Toronto", Hostname: "canada-toronto-2-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Canada", City: "Toronto", Hostname: "canada-toronto-ca-version-2.expressnetw.com"},
|
{Country: "Canada", City: "Toronto", Hostname: "canada-toronto-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Canada", City: "Vancouver", Hostname: "canada-vancouver-ca-version-2.expressnetw.com"},
|
|
||||||
{Country: "Chile", Hostname: "chile-ca-version-2.expressnetw.com"},
|
{Country: "Chile", Hostname: "chile-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Colombia", Hostname: "colombia-ca-version-2.expressnetw.com"},
|
{Country: "Colombia", Hostname: "colombia-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Costa Rica", City: "Costa Rica", Hostname: "costarica-ca-version-2.expressnetw.com"},
|
{Country: "Costa Rica", City: "Costa Rica", Hostname: "costarica-ca-version-2.expressnetw.com"},
|
||||||
@@ -49,17 +48,13 @@ func hardcodedServers() (servers []models.Server) {
|
|||||||
{Country: "France", City: "Strasbourg", Hostname: "france-strasbourg-ca-version-2.expressnetw.com"},
|
{Country: "France", City: "Strasbourg", Hostname: "france-strasbourg-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Georgia", Hostname: "georgia-ca-version-2.expressnetw.com"},
|
{Country: "Georgia", Hostname: "georgia-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Germany", City: "Frankfurt", Hostname: "germany-frankfurt-1-ca-version-2.expressnetw.com"},
|
{Country: "Germany", City: "Frankfurt", Hostname: "germany-frankfurt-1-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Germany", City: "Frankfurt", Hostname: "germany-frankfurt-2-ca-version-2.expressnetw.com"},
|
|
||||||
{Country: "Germany", City: "Frankfurt", Hostname: "germany-darmstadt-ca-version-2.expressnetw.com"},
|
{Country: "Germany", City: "Frankfurt", Hostname: "germany-darmstadt-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Germany", City: "Nuremberg", Hostname: "germany-nuremberg-ca-version-2.expressnetw.com"},
|
{Country: "Germany", City: "Nuremberg", Hostname: "germany-nuremberg-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Greece", Hostname: "greece-ca-version-2.expressnetw.com"},
|
{Country: "Greece", Hostname: "greece-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Guatemala", Hostname: "guatemala-ca-version-2.expressnetw.com"},
|
{Country: "Guatemala", Hostname: "guatemala-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Hong Kong", City: "Hong Kong", Hostname: "hongkong-2-ca-version-2.expressnetw.com"},
|
{Country: "Hong Kong", City: "Hong Kong", Hostname: "hongkong-2-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Hong Kong", City: "Hong Kong", Hostname: "hongkong4-ca-version-2.expressnetw.com"},
|
|
||||||
{Country: "Hungary", Hostname: "hungary-ca-version-2.expressnetw.com"},
|
{Country: "Hungary", Hostname: "hungary-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Iceland", Hostname: "iceland-ca-version-2.expressnetw.com"},
|
{Country: "Iceland", Hostname: "iceland-ca-version-2.expressnetw.com"},
|
||||||
{Country: "India", City: "Chennai", Hostname: "india-chennai-ca-version-2.expressnetw.com"},
|
|
||||||
{Country: "India", City: "Mumbai", Hostname: "india-mumbai-1-ca-version-2.expressnetw.com"},
|
|
||||||
{Country: "Indonesia", Hostname: "indonesia-ca-version-2.expressnetw.com"},
|
{Country: "Indonesia", Hostname: "indonesia-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Ireland", Hostname: "ireland-ca-version-2.expressnetw.com"},
|
{Country: "Ireland", Hostname: "ireland-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Isle Of Man", City: "Isle Of Man", Hostname: "isleofman-ca-version-2.expressnetw.com"},
|
{Country: "Isle Of Man", City: "Isle Of Man", Hostname: "isleofman-ca-version-2.expressnetw.com"},
|
||||||
@@ -72,7 +67,6 @@ func hardcodedServers() (servers []models.Server) {
|
|||||||
{Country: "Jersey", Hostname: "jersey-ca-version-2.expressnetw.com"},
|
{Country: "Jersey", Hostname: "jersey-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Kazakhstan", Hostname: "kazakhstan-ca-version-2.expressnetw.com"},
|
{Country: "Kazakhstan", Hostname: "kazakhstan-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Kenya", Hostname: "kenya-ca-version-2.expressnetw.com"},
|
{Country: "Kenya", Hostname: "kenya-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Kyrgyzstan", Hostname: "kyrgyzstan-ca-version-2.expressnetw.com"},
|
|
||||||
{Country: "Laos", Hostname: "laos-ca-version-2.expressnetw.com"},
|
{Country: "Laos", Hostname: "laos-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Latvia", Hostname: "latvia-ca-version-2.expressnetw.com"},
|
{Country: "Latvia", Hostname: "latvia-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Liechtenstein", Hostname: "liechtenstein-ca-version-2.expressnetw.com"},
|
{Country: "Liechtenstein", Hostname: "liechtenstein-ca-version-2.expressnetw.com"},
|
||||||
@@ -88,7 +82,6 @@ func hardcodedServers() (servers []models.Server) {
|
|||||||
{Country: "Montenegro", Hostname: "montenegro-ca-version-2.expressnetw.com"},
|
{Country: "Montenegro", Hostname: "montenegro-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Myanmar", Hostname: "myanmar-ca-version-2.expressnetw.com"},
|
{Country: "Myanmar", Hostname: "myanmar-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Nepal", Hostname: "nepal-ca-version-2.expressnetw.com"},
|
{Country: "Nepal", Hostname: "nepal-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Netherlands", City: "Amsterdam", Hostname: "netherlands-amsterdam-2-ca-version-2.expressnetw.com"},
|
|
||||||
{Country: "Netherlands", City: "Amsterdam", Hostname: "netherlands-amsterdam-ca-version-2.expressnetw.com"},
|
{Country: "Netherlands", City: "Amsterdam", Hostname: "netherlands-amsterdam-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Netherlands", City: "Rotterdam", Hostname: "netherlands-rotterdam-ca-version-2.expressnetw.com"},
|
{Country: "Netherlands", City: "Rotterdam", Hostname: "netherlands-rotterdam-ca-version-2.expressnetw.com"},
|
||||||
{Country: "Netherlands", City: "The Hague", Hostname: "netherlands-thehague-ca-version-2.expressnetw.com"},
|
{Country: "Netherlands", City: "The Hague", Hostname: "netherlands-thehague-ca-version-2.expressnetw.com"},
|
||||||
@@ -129,7 +122,6 @@ func hardcodedServers() (servers []models.Server) {
|
|||||||
{Country: "USA", City: "Dallas", Hostname: "usa-dallas-2-ca-version-2.expressnetw.com"},
|
{Country: "USA", City: "Dallas", Hostname: "usa-dallas-2-ca-version-2.expressnetw.com"},
|
||||||
{Country: "USA", City: "Dallas", Hostname: "usa-dallas-ca-version-2.expressnetw.com"},
|
{Country: "USA", City: "Dallas", Hostname: "usa-dallas-ca-version-2.expressnetw.com"},
|
||||||
{Country: "USA", City: "Denver", Hostname: "usa-denver-ca-version-2.expressnetw.com"},
|
{Country: "USA", City: "Denver", Hostname: "usa-denver-ca-version-2.expressnetw.com"},
|
||||||
{Country: "USA", City: "Los Angeles", Hostname: "usa-losangeles-1-ca-version-2.expressnetw.com"},
|
|
||||||
{Country: "USA", City: "Los Angeles", Hostname: "usa-losangeles-2-ca-version-2.expressnetw.com"},
|
{Country: "USA", City: "Los Angeles", Hostname: "usa-losangeles-2-ca-version-2.expressnetw.com"},
|
||||||
{Country: "USA", City: "Los Angeles", Hostname: "usa-losangeles-3-ca-version-2.expressnetw.com"},
|
{Country: "USA", City: "Los Angeles", Hostname: "usa-losangeles-3-ca-version-2.expressnetw.com"},
|
||||||
{Country: "USA", City: "Los Angeles", Hostname: "usa-losangeles5-ca-version-2.expressnetw.com"},
|
{Country: "USA", City: "Los Angeles", Hostname: "usa-losangeles5-ca-version-2.expressnetw.com"},
|
||||||
@@ -138,7 +130,6 @@ func hardcodedServers() (servers []models.Server) {
|
|||||||
{Country: "USA", City: "New Jersey", Hostname: "usa-newjersey-1-ca-version-2.expressnetw.com"},
|
{Country: "USA", City: "New Jersey", Hostname: "usa-newjersey-1-ca-version-2.expressnetw.com"},
|
||||||
{Country: "USA", City: "New Jersey", Hostname: "usa-newjersey2-ca-version-2.expressnetw.com"},
|
{Country: "USA", City: "New Jersey", Hostname: "usa-newjersey2-ca-version-2.expressnetw.com"},
|
||||||
{Country: "USA", City: "New Jersey", Hostname: "usa-newjersey-3-ca-version-2.expressnetw.com"},
|
{Country: "USA", City: "New Jersey", Hostname: "usa-newjersey-3-ca-version-2.expressnetw.com"},
|
||||||
{Country: "USA", City: "New York", Hostname: "us-new-york-2-ca-version-2.expressnetw.com"},
|
|
||||||
{Country: "USA", City: "New York", Hostname: "usa-newyork-ca-version-2.expressnetw.com"},
|
{Country: "USA", City: "New York", Hostname: "usa-newyork-ca-version-2.expressnetw.com"},
|
||||||
{Country: "USA", City: "Salt Lake City", Hostname: "usa-saltlakecity-ca-version-2.expressnetw.com"},
|
{Country: "USA", City: "Salt Lake City", Hostname: "usa-saltlakecity-ca-version-2.expressnetw.com"},
|
||||||
{Country: "USA", City: "San Francisco", Hostname: "usa-sanfrancisco-ca-version-2.expressnetw.com"},
|
{Country: "USA", City: "San Francisco", Hostname: "usa-sanfrancisco-ca-version-2.expressnetw.com"},
|
||||||
|
|||||||
@@ -14,17 +14,13 @@ func (p *Provider) OpenVPNConfig(connection models.Connection,
|
|||||||
providerSettings := utils.OpenVPNProviderSettings{
|
providerSettings := utils.OpenVPNProviderSettings{
|
||||||
AuthUserPass: true,
|
AuthUserPass: true,
|
||||||
Ciphers: []string{
|
Ciphers: []string{
|
||||||
openvpn.AES256gcm,
|
|
||||||
openvpn.AES256cbc,
|
openvpn.AES256cbc,
|
||||||
},
|
},
|
||||||
Auth: openvpn.SHA256,
|
Auth: openvpn.SHA256,
|
||||||
VerifyX509Type: "name",
|
VerifyX509Type: "name",
|
||||||
TLSCipher: "TLS-DHE-RSA-WITH-AES-256-CBC-SHA:TLS-DHE-DSS-WITH-AES-256-CBC-SHA:TLS-RSA-WITH-AES-256-CBC-SHA",
|
TLSCipher: "TLS-DHE-RSA-WITH-AES-256-CBC-SHA:TLS-DHE-DSS-WITH-AES-256-CBC-SHA:TLS-RSA-WITH-AES-256-CBC-SHA",
|
||||||
CAs: []string{"MIIErzCCA5egAwIBAgIJAMYKzSS8uPKDMA0GCSqGSIb3DQEBDQUAMIGVMQswCQYDVQQGEwJVUzELMAkGA1UECBMCRkwxFDASBgNVBAcTC1dpbnRlciBQYXJrMREwDwYDVQQKEwhJUFZhbmlzaDEVMBMGA1UECxMMSVBWYW5pc2ggVlBOMRQwEgYDVQQDEwtJUFZhbmlzaCBDQTEjMCEGCSqGSIb3DQEJARYUc3VwcG9ydEBpcHZhbmlzaC5jb20wIBcNMjIwNTA5MjAyMDQ1WhgPMjA4MjA0MjQyMDIwNDVaMIGVMQswCQYDVQQGEwJVUzELMAkGA1UECBMCRkwxFDASBgNVBAcTC1dpbnRlciBQYXJrMREwDwYDVQQKEwhJUFZhbmlzaDEVMBMGA1UECxMMSVBWYW5pc2ggVlBOMRQwEgYDVQQDEwtJUFZhbmlzaCBDQTEjMCEGCSqGSIb3DQEJARYUc3VwcG9ydEBpcHZhbmlzaC5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC30MFY2v8go65jdOYM/nHu9hlHQMbEttdTxPIDMFuNS0UUxuHGUeJdVCtkeaDOKH3jHsGBczu1amYwphVv6A1qox1YTrzRCbec7CaHL926VcOQQcDAPTmL+JPHhlpR21Xa+woHFGDW90LgASLAPtupXgc6LXfFwb3vVpDnkyPUp4J0DRo2+lq3UtbHaONbGx8jyzYu/kWSiLUc7X69OedoSwlmsGACQteki2o/b0uKTf84Ei+QEjGUquGJU+LETmo2IP55I+KuyZE6+zIiiegm25jgPDkrqlw2UrJiLCjUg4VhTdjF9/AUmT5tJbhZUGGx1/l0bGr+44ea7PmB3DELAgMBAAGjgf0wgfowDAYDVR0TBAUwAwEB/zAdBgNVHQ4EFgQUS/0UJYkd58Fwg9f2nxEcJU4Z7q4wgcoGA1UdIwSBwjCBv4AUS/0UJYkd58Fwg9f2nxEcJU4Z7q6hgZukgZgwgZUxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJGTDEUMBIGA1UEBxMLV2ludGVyIFBhcmsxETAPBgNVBAoTCElQVmFuaXNoMRUwEwYDVQQLEwxJUFZhbmlzaCBWUE4xFDASBgNVBAMTC0lQVmFuaXNoIENBMSMwIQYJKoZIhvcNAQkBFhRzdXBwb3J0QGlwdmFuaXNoLmNvbYIJAMYKzSS8uPKDMA0GCSqGSIb3DQEBDQUAA4IBAQCc9JV7IR8BfBrF/BQTXg0SZMZyyMAxR2jfW9qMHKSeJuZVVjfHiqoynEgBCNbn71wZWv3OF/Thu9BJ4GiYJ2Bc9nIa90D1NGYgiOVYLGXfUUqy5FgfrsWh0Go5oYm9l7W9pWfIifwsaZynkY0rTIHn32FF0H3+wZrGrEUzVL6qi+KD8iR3cBbLT+xUzulMTBp4JYaQnxpV4fZNS0ZsNrWKFWz4Iz1SSBcsnvUhfWs1aKx4yOJQx33Pc+KwpUI+meTlMjoh+AoTriooKU2MbOqLQl32y3pR0MP3fX4HDVFRylxdckEc+VryGNHQLUJiIBKBCORih/YiRhtEhpoBxmkw"}, //nolint:lll
|
CAs: []string{"MIIErTCCA5WgAwIBAgIJAMYKzSS8uPKDMA0GCSqGSIb3DQEBDQUAMIGVMQswCQYDVQQGEwJVUzELMAkGA1UECBMCRkwxFDASBgNVBAcTC1dpbnRlciBQYXJrMREwDwYDVQQKEwhJUFZhbmlzaDEVMBMGA1UECxMMSVBWYW5pc2ggVlBOMRQwEgYDVQQDEwtJUFZhbmlzaCBDQTEjMCEGCSqGSIb3DQEJARYUc3VwcG9ydEBpcHZhbmlzaC5jb20wHhcNMTIwMTExMTkzMjIwWhcNMjgxMTAyMTkzMjIwWjCBlTELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkZMMRQwEgYDVQQHEwtXaW50ZXIgUGFyazERMA8GA1UEChMISVBWYW5pc2gxFTATBgNVBAsTDElQVmFuaXNoIFZQTjEUMBIGA1UEAxMLSVBWYW5pc2ggQ0ExIzAhBgkqhkiG9w0BCQEWFHN1cHBvcnRAaXB2YW5pc2guY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt9DBWNr/IKOuY3TmDP5x7vYZR0DGxLbXU8TyAzBbjUtFFMbhxlHiXVQrZHmgzih94x7BgXM7tWpmMKYVb+gNaqMdWE680Qm3nOwmhy/dulXDkEHAwD05i/iTx4ZaUdtV2vsKBxRg1vdC4AEiwD7bqV4HOi13xcG971aQ55Mj1KeCdA0aNvpat1LWx2jjWxsfI8s2Lv5Fkoi1HO1+vTnnaEsJZrBgAkLXpItqP29Lik3/OBIvkBIxlKrhiVPixE5qNiD+eSPirsmROvsyIonoJtuY4Dw5K6pcNlKyYiwo1IOFYU3YxffwFJk+bSW4WVBhsdf5dGxq/uOHmuz5gdwxCwIDAQABo4H9MIH6MAwGA1UdEwQFMAMBAf8wHQYDVR0OBBYEFEv9FCWJHefBcIPX9p8RHCVOGe6uMIHKBgNVHSMEgcIwgb+AFEv9FCWJHefBcIPX9p8RHCVOGe6uoYGbpIGYMIGVMQswCQYDVQQGEwJVUzELMAkGA1UECBMCRkwxFDASBgNVBAcTC1dpbnRlciBQYXJrMREwDwYDVQQKEwhJUFZhbmlzaDEVMBMGA1UECxMMSVBWYW5pc2ggVlBOMRQwEgYDVQQDEwtJUFZhbmlzaCBDQTEjMCEGCSqGSIb3DQEJARYUc3VwcG9ydEBpcHZhbmlzaC5jb22CCQDGCs0kvLjygzANBgkqhkiG9w0BAQ0FAAOCAQEAI2dkh/43ksV2fdYpVGhYaFZPVqCJoToCez0IvOmLeLGzow+EOSrY508oyjYeNP4VJEjApqo0NrMbKl8g/8bpLBcotOCF1c1HZ+y9v7648uumh01SMjsbBeHOuQcLb+7gX6c0pEmxWv8qj5JiW3/1L1bktnjW5Yp5oFkFSMXjOnIoYKHyKLjN2jtwH6XowUNYpg4qVtKU0CXPdOznWcd9/zSfa393HwJPeeVLbKYaFMC4IEbIUmKYtWyoJ9pJ58smU3pWsHZUg9Zc0LZZNjkNlBdQSLmUHAJ33Bd7pJS0JQeiWviC+4UTmzEWRKa7pDGnYRYNu2cUo0/voStphv8EVA=="}, //nolint:lll
|
||||||
MssFix: 1320,
|
MssFix: 1320,
|
||||||
ExtraLines: []string{
|
|
||||||
"comp-lzo", // Explicitly disable compression
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
return utils.OpenVPNConfig(providerSettings, connection, settings, ipv6Supported)
|
return utils.OpenVPNConfig(providerSettings, connection, settings, ipv6Supported)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,7 @@ package api
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"maps"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"regexp"
|
|
||||||
"slices"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,8 +16,6 @@ const (
|
|||||||
IP2Location Provider = "ip2location"
|
IP2Location Provider = "ip2location"
|
||||||
)
|
)
|
||||||
|
|
||||||
const echoipPrefix = "echoip#"
|
|
||||||
|
|
||||||
type NameToken struct {
|
type NameToken struct {
|
||||||
Name string
|
Name string
|
||||||
Token string
|
Token string
|
||||||
@@ -36,19 +30,15 @@ func New(nameTokenPairs []NameToken, client *http.Client) (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("parsing API name: %w", err)
|
return nil, fmt.Errorf("parsing API name: %w", err)
|
||||||
}
|
}
|
||||||
switch {
|
switch provider {
|
||||||
case provider == Cloudflare:
|
case Cloudflare:
|
||||||
fetchers[i] = newCloudflare(client)
|
fetchers[i] = newCloudflare(client)
|
||||||
case provider == IfConfigCo:
|
case IfConfigCo:
|
||||||
const ifConfigCoURL = "https://ifconfig.co"
|
fetchers[i] = newIfConfigCo(client)
|
||||||
fetchers[i] = newEchoip(client, ifConfigCoURL)
|
case IPInfo:
|
||||||
case provider == IPInfo:
|
|
||||||
fetchers[i] = newIPInfo(client, nameTokenPair.Token)
|
fetchers[i] = newIPInfo(client, nameTokenPair.Token)
|
||||||
case provider == IP2Location:
|
case IP2Location:
|
||||||
fetchers[i] = newIP2Location(client, nameTokenPair.Token)
|
fetchers[i] = newIP2Location(client, nameTokenPair.Token)
|
||||||
case strings.HasPrefix(string(provider), echoipPrefix):
|
|
||||||
url := strings.TrimPrefix(string(provider), echoipPrefix)
|
|
||||||
fetchers[i] = newEchoip(client, url)
|
|
||||||
default:
|
default:
|
||||||
panic("provider not valid: " + provider)
|
panic("provider not valid: " + provider)
|
||||||
}
|
}
|
||||||
@@ -56,88 +46,20 @@ func New(nameTokenPairs []NameToken, client *http.Client) (
|
|||||||
return fetchers, nil
|
return fetchers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var regexEchoipURL = regexp.MustCompile(`^http(s|):\/\/.+$`)
|
|
||||||
|
|
||||||
var ErrProviderNotValid = errors.New("API name is not valid")
|
var ErrProviderNotValid = errors.New("API name is not valid")
|
||||||
|
|
||||||
func ParseProvider(s string) (provider Provider, err error) {
|
func ParseProvider(s string) (provider Provider, err error) {
|
||||||
possibleProviders := []Provider{
|
switch strings.ToLower(s) {
|
||||||
Cloudflare,
|
case "cloudflare":
|
||||||
IfConfigCo,
|
return Cloudflare, nil
|
||||||
IP2Location,
|
case string(IfConfigCo):
|
||||||
IPInfo,
|
return IfConfigCo, nil
|
||||||
|
case "ipinfo":
|
||||||
|
return IPInfo, nil
|
||||||
|
case "ip2location":
|
||||||
|
return IP2Location, nil
|
||||||
|
default:
|
||||||
|
return "", fmt.Errorf(`%w: %q can only be "cloudflare", "ifconfigco", "ip2location" or "ipinfo"`,
|
||||||
|
ErrProviderNotValid, s)
|
||||||
}
|
}
|
||||||
stringToProvider := make(map[string]Provider, len(possibleProviders))
|
|
||||||
for _, provider := range possibleProviders {
|
|
||||||
stringToProvider[string(provider)] = provider
|
|
||||||
}
|
|
||||||
provider, ok := stringToProvider[strings.ToLower(s)]
|
|
||||||
if ok {
|
|
||||||
return provider, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
customPrefixToURLRegex := map[string]*regexp.Regexp{
|
|
||||||
echoipPrefix: regexEchoipURL,
|
|
||||||
}
|
|
||||||
for prefix, urlRegex := range customPrefixToURLRegex {
|
|
||||||
match, err := checkCustomURL(s, prefix, urlRegex)
|
|
||||||
if !match {
|
|
||||||
continue
|
|
||||||
} else if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return Provider(s), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
providerStrings := make([]string, 0, len(stringToProvider)+len(customPrefixToURLRegex))
|
|
||||||
for _, providerString := range slices.Sorted(maps.Keys(stringToProvider)) {
|
|
||||||
providerStrings = append(providerStrings, `"`+providerString+`"`)
|
|
||||||
}
|
|
||||||
for _, prefix := range slices.Sorted(maps.Keys(customPrefixToURLRegex)) {
|
|
||||||
providerStrings = append(providerStrings, "a custom "+prefix+" url")
|
|
||||||
}
|
|
||||||
|
|
||||||
return "", fmt.Errorf(`%w: %q can only be %s`,
|
|
||||||
ErrProviderNotValid, s, orStrings(providerStrings))
|
|
||||||
}
|
|
||||||
|
|
||||||
var ErrCustomURLNotValid = errors.New("custom URL is not valid")
|
|
||||||
|
|
||||||
func checkCustomURL(s, prefix string, regex *regexp.Regexp) (match bool, err error) {
|
|
||||||
if !strings.HasPrefix(s, prefix) {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
s = strings.TrimPrefix(s, prefix)
|
|
||||||
_, err = url.Parse(s)
|
|
||||||
if err != nil {
|
|
||||||
return true, fmt.Errorf("%s %w: %w", prefix, ErrCustomURLNotValid, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if regex.MatchString(s) {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return true, fmt.Errorf("%s %w: %q does not match regular expression: %s",
|
|
||||||
prefix, ErrCustomURLNotValid, s, regex)
|
|
||||||
}
|
|
||||||
|
|
||||||
func orStrings(strings []string) (result string) {
|
|
||||||
return joinStrings(strings, "or")
|
|
||||||
}
|
|
||||||
|
|
||||||
func joinStrings(strings []string, lastJoin string) (result string) {
|
|
||||||
if len(strings) == 0 {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
result = strings[0]
|
|
||||||
for i := 1; i < len(strings); i++ {
|
|
||||||
if i < len(strings)-1 {
|
|
||||||
result += ", " + strings[i]
|
|
||||||
} else {
|
|
||||||
result += " " + lastJoin + " " + strings[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
package api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Test_ParseProvider(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
testCases := map[string]struct {
|
|
||||||
s string
|
|
||||||
provider Provider
|
|
||||||
errWrapped error
|
|
||||||
errMessage string
|
|
||||||
}{
|
|
||||||
"empty": {
|
|
||||||
errWrapped: ErrProviderNotValid,
|
|
||||||
errMessage: `API name is not valid: "" can only be ` +
|
|
||||||
`"cloudflare", "ifconfigco", "ip2location", "ipinfo" or a custom echoip# url`,
|
|
||||||
},
|
|
||||||
"invalid": {
|
|
||||||
s: "xyz",
|
|
||||||
errWrapped: ErrProviderNotValid,
|
|
||||||
errMessage: `API name is not valid: "xyz" can only be ` +
|
|
||||||
`"cloudflare", "ifconfigco", "ip2location", "ipinfo" or a custom echoip# url`,
|
|
||||||
},
|
|
||||||
"ipinfo": {
|
|
||||||
s: "ipinfo",
|
|
||||||
provider: IPInfo,
|
|
||||||
},
|
|
||||||
"IpInfo": {
|
|
||||||
s: "IpInfo",
|
|
||||||
provider: IPInfo,
|
|
||||||
},
|
|
||||||
"echoip_url_empty": {
|
|
||||||
s: "echoip#",
|
|
||||||
errWrapped: ErrCustomURLNotValid,
|
|
||||||
errMessage: `echoip# custom URL is not valid: "" ` +
|
|
||||||
`does not match regular expression: ^http(s|):\/\/.+$`,
|
|
||||||
},
|
|
||||||
"echoip_url_invalid": {
|
|
||||||
s: "echoip#postgres://localhost:3451",
|
|
||||||
errWrapped: ErrCustomURLNotValid,
|
|
||||||
errMessage: `echoip# custom URL is not valid: "postgres://localhost:3451" ` +
|
|
||||||
`does not match regular expression: ^http(s|):\/\/.+$`,
|
|
||||||
},
|
|
||||||
"echoip_url_valid": {
|
|
||||||
s: "echoip#http://localhost:3451",
|
|
||||||
provider: Provider("echoip#http://localhost:3451"),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for name, testCase := range testCases {
|
|
||||||
t.Run(name, func(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
provider, err := ParseProvider(testCase.s)
|
|
||||||
|
|
||||||
assert.Equal(t, testCase.provider, provider)
|
|
||||||
assert.ErrorIs(t, err, testCase.errWrapped)
|
|
||||||
if testCase.errWrapped != nil {
|
|
||||||
assert.EqualError(t, err, testCase.errMessage)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,45 +6,39 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type echoip struct {
|
type ifConfigCo struct {
|
||||||
client *http.Client
|
client *http.Client
|
||||||
url string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newEchoip(client *http.Client, url string) *echoip {
|
func newIfConfigCo(client *http.Client) *ifConfigCo {
|
||||||
return &echoip{
|
return &ifConfigCo{
|
||||||
client: client,
|
client: client,
|
||||||
url: url,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *echoip) String() string {
|
func (i *ifConfigCo) String() string {
|
||||||
s := e.url
|
return string(IfConfigCo)
|
||||||
s = strings.TrimPrefix(s, "http://")
|
|
||||||
s = strings.TrimPrefix(s, "https://")
|
|
||||||
return s
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *echoip) CanFetchAnyIP() bool {
|
func (i *ifConfigCo) CanFetchAnyIP() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *echoip) Token() string {
|
func (i *ifConfigCo) Token() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// FetchInfo obtains information on the ip address provided
|
// FetchInfo obtains information on the ip address provided
|
||||||
// using the echoip API at the url given. If the ip is the zero value,
|
// using the ifconfig.co/json API. If the ip is the zero value,
|
||||||
// the public IP address of the machine is used as the IP.
|
// the public IP address of the machine is used as the IP.
|
||||||
func (e *echoip) FetchInfo(ctx context.Context, ip netip.Addr) (
|
func (i *ifConfigCo) FetchInfo(ctx context.Context, ip netip.Addr) (
|
||||||
result models.PublicIP, err error,
|
result models.PublicIP, err error,
|
||||||
) {
|
) {
|
||||||
url := e.url + "/json"
|
url := "https://ifconfig.co/json"
|
||||||
if ip.IsValid() {
|
if ip.IsValid() {
|
||||||
url += "?ip=" + ip.String()
|
url += "?ip=" + ip.String()
|
||||||
}
|
}
|
||||||
@@ -54,7 +48,7 @@ func (e *echoip) FetchInfo(ctx context.Context, ip netip.Addr) (
|
|||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := e.client.Do(request)
|
response, err := i.client.Do(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
@@ -5,10 +5,12 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Parallel struct {
|
type Parallel struct {
|
||||||
repeatResolver *Repeat
|
lastRequestTime time.Time
|
||||||
|
repeatResolver *Repeat
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewParallelResolver(resolverAddress string) *Parallel {
|
func NewParallelResolver(resolverAddress string) *Parallel {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package wireguard
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/netlink"
|
"github.com/qdm12/gluetun/internal/netlink"
|
||||||
)
|
)
|
||||||
@@ -17,10 +16,6 @@ func (w *Wireguard) addRule(rulePriority int, firewallMark uint32,
|
|||||||
rule.Table = int(firewallMark)
|
rule.Table = int(firewallMark)
|
||||||
rule.Family = family
|
rule.Family = family
|
||||||
if err := w.netlink.RuleAdd(rule); err != nil {
|
if err := w.netlink.RuleAdd(rule); err != nil {
|
||||||
if strings.HasSuffix(err.Error(), "file exists") {
|
|
||||||
w.logger.Info("if you are using Kubernetes, this may fix the error below: " +
|
|
||||||
"https://github.com/qdm12/gluetun-wiki/blob/main/setup/advanced/kubernetes.md#adding-ipv6-rule--file-exists")
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("adding %s: %w", rule, err)
|
return nil, fmt.Errorf("adding %s: %w", rule, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
# Maintenance
|
# Maintenance
|
||||||
|
|
||||||
- Rename `UNBLOCK` to `DNS_HOSTNAMES_UNBLOCKED`
|
<https://github.com/macvk/dnsleaktest/blob/master/dnsleaktest.go>
|
||||||
|
|
||||||
|
- Rename `UNBLOCK` to `DNS_ALLOWED_HOSTNAMES`
|
||||||
- Change `Run` methods to `Start`+`Stop`, returning channels rather than injecting them
|
- Change `Run` methods to `Start`+`Stop`, returning channels rather than injecting them
|
||||||
- Go 1.18
|
- Go 1.18
|
||||||
- gofumpt
|
- gofumpt
|
||||||
|
|||||||
Reference in New Issue
Block a user