44 "flag"
55 "fmt"
66 "os"
7- "strconv"
8- "strings"
97
108 gohpts "github.com/shadowy-pycoder/go-http-proxy-to-socks"
119 "golang.org/x/term"
@@ -24,7 +22,7 @@ const usagePrefix string = `
2422 | |__| | (_) | | | | | | | ____) |
2523 \_____|\___/|_| |_|_| |_| |_____/
2624
27- GoHPTS (HTTP Proxy to SOCKS5) by shadowy-pycoder
25+ GoHPTS (HTTP(S) Proxy to SOCKS5 proxy ) by shadowy-pycoder
2826GitHub: https://github.com/shadowy-pycoder/go-http-proxy-to-socks
2927
3028Usage: gohpts [OPTIONS]
@@ -33,48 +31,15 @@ Options:
3331`
3432
3533func root (args []string ) error {
36- conf := gohpts.Config {AddrSOCKS : addrSOCKS , AddrHTTP : addrHTTP }
34+ conf := gohpts.Config {}
3735 flags := flag .NewFlagSet (app , flag .ExitOnError )
38- flags .Func ("s" , "Address of SOCKS5 proxy server (Default: localhost:1080)" , func (flagValue string ) error {
39- var addr string
40- i , err := strconv .Atoi (flagValue )
41- if err == nil {
42- addr = fmt .Sprintf ("127.0.0.1:%d" , i )
43- } else if strings .HasPrefix (flagValue , ":" ) {
44- addr = fmt .Sprintf ("127.0.0.1%s" , flagValue )
45- } else {
46- addr = flagValue
47- }
48- conf .AddrSOCKS = addr
49- return nil
50- })
51- flags .StringVar (& conf .User , "u" , "" , "User for SOCKS5 proxy" )
52- flags .BoolFunc ("p" , "Password for SOCKS5 proxy (not echoed to terminal)" , func (flagValue string ) error {
53- fmt .Print ("SOCKS5 Password: " )
54- bytepw , err := term .ReadPassword (int (os .Stdin .Fd ()))
55- if err != nil {
56- os .Exit (1 )
57- }
58- conf .Pass = string (bytepw )
59- fmt .Print ("\033 [2K\r " )
60- return nil
61- })
62- flags .Func ("l" , "Address of HTTP proxy server (Default: localhost:8080)" , func (flagValue string ) error {
63- var addr string
64- i , err := strconv .Atoi (flagValue )
65- if err == nil {
66- addr = fmt .Sprintf ("127.0.0.1:%d" , i )
67- } else if strings .HasPrefix (flagValue , ":" ) {
68- addr = fmt .Sprintf ("127.0.0.1%s" , flagValue )
69- } else {
70- addr = flagValue
71- }
72- conf .AddrHTTP = addr
73- return nil
74- })
75- flags .StringVar (& conf .CertFile , "c" , "" , "Path to certificate PEM encoded file " )
76- flags .StringVar (& conf .KeyFile , "k" , "" , "Path to private key PEM encoded file " )
77- flags .StringVar (& conf .ProxyChainPath , "f" , "" , "Path to proxychain YAML configuration file" )
36+ flags .StringVar (& conf .AddrSOCKS , "s" , addrSOCKS , "Address of SOCKS5 proxy server" )
37+ flags .StringVar (& conf .User , "u" , "" , "User for SOCKS5 proxy authentication. This flag invokes prompt for password (not echoed to terminal)" )
38+ flags .StringVar (& conf .AddrHTTP , "l" , addrHTTP , "Address of HTTP proxy server" )
39+ flags .StringVar (& conf .ServerUser , "U" , "" , "User for HTTP proxy (basic auth). This flag invokes prompt for password (not echoed to terminal)" )
40+ flags .StringVar (& conf .CertFile , "c" , "" , "Path to certificate PEM encoded file" )
41+ flags .StringVar (& conf .KeyFile , "k" , "" , "Path to private key PEM encoded file" )
42+ flags .StringVar (& conf .ServerConfPath , "f" , "" , "Path to server configuration file in YAML format" )
7843 flags .BoolFunc ("d" , "Show logs in DEBUG mode" , func (flagValue string ) error {
7944 conf .Debug = true
8045 return nil
@@ -100,12 +65,30 @@ func root(args []string) error {
10065 seen := make (map [string ]bool )
10166 flags .Visit (func (f * flag.Flag ) { seen [f .Name ] = true })
10267 if seen ["f" ] {
103- for _ , da := range []string {"s" , "u" , "p " } {
68+ for _ , da := range []string {"s" , "u" , "U" , "c" , "k" , "l " } {
10469 if seen [da ] {
105- return fmt .Errorf ("specify either -f or -s -u -p flags" )
70+ return fmt .Errorf ("-f flag only works with -d and -j flags" )
10671 }
10772 }
10873 }
74+ if seen ["u" ] {
75+ fmt .Print ("SOCKS5 Password: " )
76+ bytepw , err := term .ReadPassword (int (os .Stdin .Fd ()))
77+ if err != nil {
78+ return err
79+ }
80+ conf .Pass = string (bytepw )
81+ fmt .Print ("\033 [2K\r " )
82+ }
83+ if seen ["U" ] {
84+ fmt .Print ("HTTP Password: " )
85+ bytepw , err := term .ReadPassword (int (os .Stdin .Fd ()))
86+ if err != nil {
87+ return err
88+ }
89+ conf .ServerPass = string (bytepw )
90+ fmt .Print ("\033 [2K\r " )
91+ }
10992 p := gohpts .New (& conf )
11093 p .Run ()
11194 return nil
0 commit comments