diff --git a/go.mod b/go.mod index 76160f739..502621cb4 100644 --- a/go.mod +++ b/go.mod @@ -20,6 +20,8 @@ require ( golang.org/x/time v0.3.0 ) +require github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect + require ( github.com/OneOfOne/xxhash v1.2.8 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect diff --git a/go.sum b/go.sum index 81efadc46..c2b118d6e 100644 --- a/go.sum +++ b/go.sum @@ -56,6 +56,8 @@ github.com/schollz/peerdiscovery v1.7.0/go.mod h1:BouGdURKIFl7OGez+2lyZJKD+2tBQ2 github.com/schollz/progressbar/v3 v3.13.1 h1:o8rySDYiQ59Mwzy2FELeHY5ZARXZTVJC7iHD6PEFUiE= github.com/schollz/progressbar/v3 v3.13.1/go.mod h1:xvrbki8kfT1fzWzBT/UZd9L6GA+jdL7HAgq2RFnO6fQ= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0= +github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= diff --git a/src/cli/cli.go b/src/cli/cli.go index 70f56d690..50032594e 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -66,6 +66,7 @@ func Run() (err error) { ArgsUsage: "[filename(s) or folder]", Flags: []cli.Flag{ &cli.BoolFlag{Name: "zip", Usage: "zip folder before sending"}, + &cli.BoolFlag{Name: "qrcode",Aliases: []string{"qr"}, Usage: "show receive code as a qrcode"}, &cli.StringFlag{Name: "code", Aliases: []string{"c"}, Usage: "codephrase used to connect to relay"}, &cli.StringFlag{Name: "hash", Value: "xxhash", Usage: "hash algorithm (xxhash, imohash, md5)"}, &cli.StringFlag{Name: "text", Aliases: []string{"t"}, Usage: "send some text"}, @@ -201,6 +202,7 @@ func send(c *cli.Context) (err error) { ThrottleUpload: c.String("throttleUpload"), ZipFolder: c.Bool("zip"), GitIgnore: c.Bool("git"), + ShowQrCode: c.Bool("qrcode"), } if crocOptions.RelayAddress != models.DEFAULT_RELAY { crocOptions.RelayAddress6 = "" diff --git a/src/croc/croc.go b/src/croc/croc.go index a4e23a195..996550eb7 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -33,8 +33,8 @@ import ( "github.com/schollz/croc/v9/src/models" "github.com/schollz/croc/v9/src/tcp" "github.com/schollz/croc/v9/src/utils" + qrcode "github.com/skip2/go-qrcode" ) - var ( ipRequest = []byte("ips?") handshakeRequest = []byte("handshake") @@ -79,6 +79,7 @@ type Options struct { ZipFolder bool TestFlag bool GitIgnore bool + ShowQrCode bool } // Client holds the state of the croc transfer @@ -630,6 +631,9 @@ func (c *Client) Send(filesInfo []FileInfo, emptyFoldersToTransfer []FileInfo, t flags.WriteString("--pass " + c.Options.RelayPassword + " ") } fmt.Fprintf(os.Stderr, "Code is: %[1]s\nOn the other computer run\n\ncroc %[2]s%[1]s\n", c.Options.SharedSecret, flags.String()) + if c.Options.ShowQrCode { + showReceiveCommandQrCode(fmt.Sprintf("%[1]s", c.Options.SharedSecret)) + } if c.Options.Ask { machid, _ := machineid.ID() fmt.Fprintf(os.Stderr, "\rYour machine ID is '%s'\n", machid) @@ -754,7 +758,12 @@ func (c *Client) Send(filesInfo []FileInfo, emptyFoldersToTransfer []FileInfo, t } return err } - +func showReceiveCommandQrCode(command string){ + qrCode, err := qrcode.New(command, qrcode.Medium) + if err == nil { + fmt.Println(qrCode.ToSmallString(false)) + } +} // Receive will receive a file func (c *Client) Receive() (err error) { fmt.Fprintf(os.Stderr, "connecting...")