Skip to content

Commit 72ffcba

Browse files
added basic support for transparent proxy
1 parent 929cc04 commit 72ffcba

File tree

5 files changed

+300
-77
lines changed

5 files changed

+300
-77
lines changed

cmd/gohpts/cli.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"flag"
55
"fmt"
66
"os"
7+
"runtime"
78

89
gohpts "github.com/shadowy-pycoder/go-http-proxy-to-socks"
910
"golang.org/x/term"
@@ -40,6 +41,10 @@ func root(args []string) error {
4041
flags.StringVar(&conf.CertFile, "c", "", "Path to certificate PEM encoded file")
4142
flags.StringVar(&conf.KeyFile, "k", "", "Path to private key PEM encoded file")
4243
flags.StringVar(&conf.ServerConfPath, "f", "", "Path to server configuration file in YAML format")
44+
if runtime.GOOS == "linux" {
45+
flags.StringVar(&conf.TProxy, "t", "", "Address of transparent proxy server (TPROXY) (it starts along with HTTP proxy server)")
46+
flags.StringVar(&conf.TProxyOnly, "T", "", "Address of transparent proxy server (TPROXY) (no HTTP)")
47+
}
4348
flags.BoolFunc("d", "Show logs in DEBUG mode", func(flagValue string) error {
4449
conf.Debug = true
4550
return nil
@@ -64,9 +69,22 @@ func root(args []string) error {
6469
}
6570
seen := make(map[string]bool)
6671
flags.Visit(func(f *flag.Flag) { seen[f.Name] = true })
72+
if seen["t"] && seen["T"] {
73+
return fmt.Errorf("cannot specify both -t and -T flags")
74+
}
75+
if seen["T"] {
76+
for _, da := range []string{"U", "c", "k", "l"} {
77+
if seen[da] {
78+
return fmt.Errorf("-T flag only works with -s, -u, -f, -d and -j flags")
79+
}
80+
}
81+
}
6782
if seen["f"] {
6883
for _, da := range []string{"s", "u", "U", "c", "k", "l"} {
6984
if seen[da] {
85+
if runtime.GOOS == "linux" {
86+
return fmt.Errorf("-f flag only works with -t, -T, -d and -j flags")
87+
}
7088
return fmt.Errorf("-f flag only works with -d and -j flags")
7189
}
7290
}
@@ -89,6 +107,7 @@ func root(args []string) error {
89107
conf.ServerPass = string(bytepw)
90108
fmt.Print("\033[2K\r")
91109
}
110+
92111
p := gohpts.New(&conf)
93112
p.Run()
94113
return nil

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ require (
66
github.com/goccy/go-yaml v1.18.0
77
github.com/rs/zerolog v1.34.0
88
golang.org/x/net v0.40.0
9+
golang.org/x/sys v0.33.0
910
golang.org/x/term v0.32.0
1011
)
1112

1213
require (
1314
github.com/mattn/go-colorable v0.1.13 // indirect
1415
github.com/mattn/go-isatty v0.0.19 // indirect
15-
golang.org/x/sys v0.33.0 // indirect
1616
)

0 commit comments

Comments
 (0)