Skip to content

Commit

Permalink
brook link socks5
Browse files Browse the repository at this point in the history
  • Loading branch information
txthinking committed Aug 31, 2020
1 parent 0772328 commit f52761b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
20 changes: 15 additions & 5 deletions cli/brook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
},
Expand All @@ -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
},
},
Expand Down
20 changes: 16 additions & 4 deletions link.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit f52761b

Please sign in to comment.