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
0 commit comments