From f52761bfd408c3e78c764f36f7d37fcc1e3c0dfd Mon Sep 17 00:00:00 2001 From: txthinking Date: Mon, 31 Aug 2020 21:35:33 +0800 Subject: [PATCH] brook link socks5 --- cli/brook/main.go | 20 +++++++++++++++----- link.go | 20 ++++++++++++++++---- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/cli/brook/main.go b/cli/brook/main.go index e3afd41e..1ce67f2a 100644 --- a/cli/brook/main.go +++ b/cli/brook/main.go @@ -549,13 +549,18 @@ func main() { Aliases: []string{"p"}, Usage: "Server password", }, + &cli.StringFlag{ + Name: "username", + Aliases: []string{"u"}, + Usage: "Server username", + }, }, Action: func(c *cli.Context) error { - if c.String("server") == "" || c.String("password") == "" { + if c.String("server") == "" { cli.ShowCommandHelp(c, "link") return nil } - fmt.Println(brook.Link(c.String("server"), c.String("password"))) + fmt.Println(brook.Link(c.String("server"), c.String("password"), c.String("username"))) return nil }, }, @@ -566,20 +571,25 @@ func main() { &cli.StringFlag{ Name: "server", Aliases: []string{"s"}, - Usage: "Support $ brook server and $ brook wsserver address, like: 1.2.3.4:1080, ws://1.2.3.4:1080, wss://google.com:443. Do not omit the port under any circumstances", + Usage: "Support $ brook server, $ brook wsserver and socks5 server, like: 1.2.3.4:1080, ws://1.2.3.4:1080, wss://google.com:443, socks5://1.2.3.4:1080", }, &cli.StringFlag{ Name: "password", Aliases: []string{"p"}, Usage: "Server password", }, + &cli.StringFlag{ + Name: "username", + Aliases: []string{"u"}, + Usage: "Server username", + }, }, Action: func(c *cli.Context) error { - if c.String("server") == "" || c.String("password") == "" { + if c.String("server") == "" { cli.ShowCommandHelp(c, "qr") return nil } - brook.QR(c.String("server"), c.String("password")) + brook.QR(c.String("server"), c.String("password"), c.String("username")) return nil }, }, diff --git a/link.go b/link.go index 268c93a6..9a563f1b 100644 --- a/link.go +++ b/link.go @@ -22,15 +22,27 @@ import ( ) // Link -func Link(server, password string) string { - s := server + " " + password +func Link(server, password, username string) string { + s := server + if username == "" && password != "" { + s += " " + password + } + if username != "" && password != "" { + s += " " + username + " " + password + } s = "brook://" + encrypt.URIEscape(s) return s } // QR generate and print QR code. -func QR(server, password string) { - s := server + " " + password +func QR(server, password, username string) { + s := server + if username == "" && password != "" { + s += " " + password + } + if username != "" && password != "" { + s += " " + username + " " + password + } s = "brook://" + encrypt.URIEscape(s) qrterminal.GenerateHalfBlock(s, qrterminal.L, os.Stdout) }