From 60e2c73a5f6f61e70b756f3046b0ba9d4d4ff580 Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Fri, 16 Dec 2016 13:57:27 +0800 Subject: [PATCH] change the help message format --- obfssh_client/ssh.go | 120 ++++++++++++++++++++++++++----------------- obfssh_scp/scp.go | 52 ++++++++++++++++--- 2 files changed, 118 insertions(+), 54 deletions(-) diff --git a/obfssh_client/ssh.go b/obfssh_client/ssh.go index bb11bc3..39c9fa5 100644 --- a/obfssh_client/ssh.go +++ b/obfssh_client/ssh.go @@ -106,8 +106,8 @@ func main() { if host == "" { switch len(args) { case 0: - flag.PrintDefaults() - log.Fatal("you must specify the remote host") + fmt.Println("you must specify the remote host") + usage() case 1: host = args[0] cmd = "" @@ -284,54 +284,80 @@ func passwordAuth() (string, error) { func usage() { usageStr := `Usage: obfss_client -N -d -D [bind_address:]port -f configfile - -i identity_file -L [bind_address:]port:host:hostport -l login_name - -pw password -p port + -i identity_file -L [bind_address:]port:host:hostport + -l login_name -pw password -p port -obfs_method method + -obfs_key key -disable_obfs_after_handshake -R [bind_address:]port:host:hostport [user@]hostname [command] Options: - - -d verbose mode - - -D [bind_adress:]port - Specifies a local dynamic application-level port - forwarding. This listen a port on the local side - and act as socks server, when a connection is made - to this port, the connection is forwarded over - the secure channel, the distination is determined - by socks protocol. - This option can be specified multiple times. - - -f configfile - Specifies a config file to load arguments. - The config file is YAML format, - see config_example.yaml for details. - - -i identity_file - Specifies a identity(private key) for public key authentication. - - -L [bind_address:]port:host:hostport - Listen a port on local side, when a connection is made to - this port, the connection is forwared over the secure - channel to host:portport from the remote machine. - This option can be specified multiple times. - - -l login_name - specifies the user to log in as on the remote machine. - - -N Do not execute commannd or start shell on remote machine. - This is useful for just port forwarding. - - -p port - Port to connect to on the remote host - - -pw password - Specifies the password for log in remote machine - - -R [bind_address:]port:host:hostport - Listen a port on remote machine, when a connection is - made to that port, the connection is forwarded over - the secure channel to host:hostport from the local machine. - This option can be specified multiple times. + -d verbose mode + + -D [bind_adress:]port + Specifies a local dynamic application-level port + forwarding. This listen a port on the local side + and act as socks server, when a connection is made + to this port, the connection is forwarded over + the secure channel, the distination is determined + by socks protocol. + This option can be specified multiple times. + + -f configfile + Specifies a config file to load arguments. + The config file is YAML format, + see config_example.yaml for details. + + -i identity_file + Specifies a identity(private key) for public key authentication. + + -L [bind_address:]port:host:hostport + Listen a port on local side, when a connection is made to + this port, the connection is forwared over the secure + channel to host:portport from the remote machine. + This option can be specified multiple times. + + -l login_name + specifies the user to log in as on the remote machine. + + -N Do not execute commannd or start shell on remote machine. + This is useful for just port forwarding. + + -p port + Port to connect to on the remote host + + -pw password + Specifies the password for log in remote machine + + -R [bind_address:]port:host:hostport + Listen a port on remote machine, when a connection is + made to that port, the connection is forwarded over + the secure channel to host:hostport from the local machine. + This option can be specified multiple times. + + -keepalive_interval interval + Specifies the interval of keep alive message, + the interval is integer in seconds. + + -keepalive_max max + Specifies the max error count for keep alive, + when the count reach the max, the connection will + be abort. + +Options for obfuscation: + -obfs_method method + Specifies the encryption method. + when this option is specified, the entire connection + will be encrypted. + when set to none, the encryption is disabled. + Avaliable methods: rc4, aes, none(default) + + -obfs_key key + Specifies the key to encrypt the connection, + if the server enable the obfs, only known the + right key can connect to the server. + + -disable_obfs_after_handshake + when this option is specified, only encrypt the + ssh handshake message. ` fmt.Printf("%s", usageStr) os.Exit(1) diff --git a/obfssh_scp/scp.go b/obfssh_scp/scp.go index 141c00c..fb35bb8 100644 --- a/obfssh_scp/scp.go +++ b/obfssh_scp/scp.go @@ -28,13 +28,8 @@ func main() { var debug bool var hasError bool - flag.Usage = func() { - fmt.Printf("Usage: \n\t%s [options] user@host:path local\n\tor\n\t%s [options] local... user@host:path\n", os.Args[0], os.Args[0]) + flag.Usage = usage - fmt.Printf("Options:\n\n") - - flag.PrintDefaults() - } flag.BoolVar(&debug, "d", false, "verbose mode") flag.StringVar(&port, "p", "22", "port") flag.StringVar(&user, "l", os.Getenv("USER"), "user") @@ -53,7 +48,6 @@ func main() { args := flag.Args() if len(args) < 2 { - //fmt.Printf("Usage: \n\tscp user@host:path local\n\tor\n\tscp local... user@host:path\n") flag.Usage() os.Exit(1) } @@ -506,3 +500,47 @@ func copyFile(w io.Writer, r io.Reader) error { } } } + +func usage() { + usageStr := `Usage: + obfssh_scp -i identity_file -l login_name + -p port -pw password -r -obfs_method method -obfs_key key + -disable_obfs_after_handshake [user@]host1:]file1 ... [user@host2:]file2 + +Options: + -d verbose mode + + -i identity_file + Specifies a identity(private key) for public key authentication. + + -l login_name + specifies the user to log in as on the remote machine. + + -p port + Port to connect to on the remote host + + -pw password + Specifies the password for log in remote machine + + -r recursively copy the directories + +Options for obfuscation: + -obfs_method method + Specifies the encryption method. + when this option is specified, the entire connection + will be encrypted. + when set to none, the encryption is disabled. + Avaliable methods: rc4, aes, none(default) + + -obfs_key key + Specifies the key to encrypt the connection, + if the server enable the obfs, only known the + right key can connect to the server. + + -disable_obfs_after_handshake + when this option is specified, only encrypt the + ssh handshake message. +` + fmt.Printf("%s", usageStr) + os.Exit(1) +}