Compare commits

...

3 Commits

Author SHA1 Message Date
AJ ONeal 8ba42a09a4 silence more output, fix minor output bugs 2021-06-21 23:22:34 -06:00
AJ ONeal 66f2d41c6b -q => -s (to be curl-like), make staticcheck happy 2021-06-21 23:05:27 -06:00
Kevin Chung ca84ed48de Add -quiet and -q flags 2021-06-17 15:27:21 -04:00
3 changed files with 33 additions and 12 deletions

View File

@ -24,13 +24,15 @@ func ver() string {
} }
func usage() { func usage() {
fmt.Fprintf(os.Stderr, "\nsclient %s\n"+ fmt.Fprintf(os.Stderr, "\n%s\n"+
"\nusage: sclient <remote> <local>\n"+ "\nusage: sclient <remote> <local>\n"+
"\n"+ "\n"+
" ex: sclient example.com 3000\n"+ " ex: sclient example.com 3000\n"+
" (sclient example.com:443 localhost:3000)\n"+ " (sclient example.com:443 localhost:3000)\n"+
"\n"+ "\n"+
" ex: sclient example.com:8443 0.0.0.0:4080\n"+ " ex: sclient example.com:8443 0.0.0.0:4080\n"+
"\n"+
" ex: sclient example.com:443 -\n"+
"\n", ver()) "\n", ver())
flag.PrintDefaults() flag.PrintDefaults()
fmt.Println() fmt.Println()
@ -46,9 +48,11 @@ func main() {
} }
flag.Usage = usage flag.Usage = usage
insecure := flag.Bool("k", false, "ignore bad TLS/SSL/HTTPS certificates") insecure := flag.Bool("k", false, "alias for --insecure")
silent := flag.Bool("s", false, "alias of --silent")
servername := flag.String("servername", "", "specify a servername different from <remote> (to disable SNI use an IP as <remote> and do use this option)") servername := flag.String("servername", "", "specify a servername different from <remote> (to disable SNI use an IP as <remote> and do use this option)")
flag.BoolVar(insecure, "insecure", false, "ignore bad TLS/SSL/HTTPS certificates") flag.BoolVar(insecure, "insecure", false, "ignore bad TLS/SSL/HTTPS certificates")
flag.BoolVar(silent, "silent", false, "less verbose output")
flag.Parse() flag.Parse()
remotestr := flag.Arg(0) remotestr := flag.Arg(0)
localstr := flag.Arg(1) localstr := flag.Arg(1)
@ -69,6 +73,7 @@ func main() {
LocalAddress: "localhost", LocalAddress: "localhost",
InsecureSkipVerify: *insecure, InsecureSkipVerify: *insecure,
ServerName: *servername, ServerName: *servername,
Silent: *silent,
} }
remote := strings.Split(remotestr, ":") remote := strings.Split(remotestr, ":")

View File

@ -18,6 +18,7 @@ type Tunnel struct {
LocalPort int LocalPort int
InsecureSkipVerify bool InsecureSkipVerify bool
ServerName string ServerName string
Silent bool
} }
// DialAndListen will create a test TLS connection to the remote address and then // DialAndListen will create a test TLS connection to the remote address and then
@ -45,7 +46,7 @@ func (t *Tunnel) DialAndListen() error {
} else { } else {
name = "stdin" name = "stdin"
} }
conn := &stdnet{os.Stdin, os.Stdout, &stdaddr{net.UnixAddr{name, network}}} conn := &stdnet{os.Stdin, os.Stdout, &stdaddr{net.UnixAddr{Name: name, Net: network}}}
t.handleConnection(remote, conn) t.handleConnection(remote, conn)
return nil return nil
} }
@ -57,8 +58,10 @@ func (t *Tunnel) DialAndListen() error {
return err return err
} }
fmt.Fprintf(os.Stdout, "[listening] %s:%d <= %s:%d\n", if !t.Silent {
t.RemoteAddress, t.RemotePort, t.LocalAddress, t.LocalPort) fmt.Fprintf(os.Stdout, "[listening] %s:%d <= %s:%d\n",
t.RemoteAddress, t.RemotePort, t.LocalAddress, t.LocalPort)
}
for { for {
conn, err := ln.Accept() conn, err := ln.Accept()
@ -110,7 +113,7 @@ func pipe(r netReadWriteCloser, w netReadWriteCloser, t string) {
if nil != err { if nil != err {
//fmt.Fprintf(os.Stdout, "[debug] (%s:%d) error reading %s\n", t, count, err) //fmt.Fprintf(os.Stdout, "[debug] (%s:%d) error reading %s\n", t, count, err)
if io.EOF != err { if io.EOF != err {
fmt.Fprintf(os.Stderr, "[read error] (%s:%s) %s\n", t, count, err) fmt.Fprintf(os.Stderr, "[read error] (%s:%d) %s\n", t, count, err)
} }
r.Close() r.Close()
//w.Close() //w.Close()
@ -149,12 +152,14 @@ func (t *Tunnel) handleConnection(remote string, conn netReadWriteCloser) {
return return
} }
if "stdio" == conn.RemoteAddr().Network() { if !t.Silent {
fmt.Fprintf(os.Stdout, "(connected to %s:%d and reading from %s)\n", if "stdio" == conn.RemoteAddr().Network() {
t.RemoteAddress, t.RemotePort, conn.RemoteAddr().String()) fmt.Fprintf(os.Stdout, "(connected to %s:%d and reading from %s)\n",
} else { t.RemoteAddress, t.RemotePort, conn.RemoteAddr().String())
fmt.Fprintf(os.Stdout, "[connect] %s => %s:%d\n", } else {
strings.Replace(conn.RemoteAddr().String(), "[::1]:", "localhost:", 1), t.RemoteAddress, t.RemotePort) fmt.Fprintf(os.Stdout, "[connect] %s => %s:%d\n",
strings.Replace(conn.RemoteAddr().String(), "[::1]:", "localhost:", 1), t.RemoteAddress, t.RemotePort)
}
} }
go pipe(conn, sclient, "local") go pipe(conn, sclient, "local")

11
staticcheck.conf Normal file
View File

@ -0,0 +1,11 @@
# I like my yoda conditions ST1017
checks = ["all", "-ST1017", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-ST1023"]
initialisms = ["ACL", "API", "ASCII", "CPU", "CSS", "DNS",
"EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID",
"IP", "JSON", "QPS", "RAM", "RPC", "SLA",
"SMTP", "SQL", "SSH", "TCP", "TLS", "TTL",
"UDP", "UI", "GID", "UID", "UUID", "URI",
"URL", "UTF8", "VM", "XML", "XMPP", "XSRF",
"XSS", "SIP", "RTP", "AMQP", "DB", "TS"]
dot_import_whitelist = []
http_status_code_whitelist = ["200", "400", "404", "500"]