mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
cmd/tailscale: add up --qr to show QR code
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
2501a694cb
commit
2d11503cff
@ -9,6 +9,7 @@
|
|||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -18,6 +19,7 @@
|
|||||||
|
|
||||||
shellquote "github.com/kballard/go-shellquote"
|
shellquote "github.com/kballard/go-shellquote"
|
||||||
"github.com/peterbourgon/ff/v3/ffcli"
|
"github.com/peterbourgon/ff/v3/ffcli"
|
||||||
|
qrcode "github.com/skip2/go-qrcode"
|
||||||
"inet.af/netaddr"
|
"inet.af/netaddr"
|
||||||
"tailscale.com/client/tailscale"
|
"tailscale.com/client/tailscale"
|
||||||
"tailscale.com/ipn"
|
"tailscale.com/ipn"
|
||||||
@ -63,6 +65,7 @@ func effectiveGOOS() string {
|
|||||||
func newUpFlagSet(goos string, upArgs *upArgsT) *flag.FlagSet {
|
func newUpFlagSet(goos string, upArgs *upArgsT) *flag.FlagSet {
|
||||||
upf := flag.NewFlagSet("up", flag.ExitOnError)
|
upf := flag.NewFlagSet("up", flag.ExitOnError)
|
||||||
|
|
||||||
|
upf.BoolVar(&upArgs.qr, "qr", false, "show QR code for login URLs")
|
||||||
upf.BoolVar(&upArgs.forceReauth, "force-reauth", false, "force reauthentication")
|
upf.BoolVar(&upArgs.forceReauth, "force-reauth", false, "force reauthentication")
|
||||||
upf.BoolVar(&upArgs.reset, "reset", false, "reset unspecified settings to their default values")
|
upf.BoolVar(&upArgs.reset, "reset", false, "reset unspecified settings to their default values")
|
||||||
|
|
||||||
@ -99,6 +102,7 @@ func defaultNetfilterMode() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type upArgsT struct {
|
type upArgsT struct {
|
||||||
|
qr bool
|
||||||
reset bool
|
reset bool
|
||||||
server string
|
server string
|
||||||
acceptRoutes bool
|
acceptRoutes bool
|
||||||
@ -445,6 +449,15 @@ func runUp(ctx context.Context, args []string) error {
|
|||||||
if url := n.BrowseToURL; url != nil && printAuthURL(*url) {
|
if url := n.BrowseToURL; url != nil && printAuthURL(*url) {
|
||||||
printed = true
|
printed = true
|
||||||
fmt.Fprintf(os.Stderr, "\nTo authenticate, visit:\n\n\t%s\n\n", *url)
|
fmt.Fprintf(os.Stderr, "\nTo authenticate, visit:\n\n\t%s\n\n", *url)
|
||||||
|
if upArgs.qr {
|
||||||
|
q, err := qrcode.New(*url, qrcode.Medium)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("QR code error: %v", err)
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(os.Stderr, "%s\n", q.ToString(false))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// Wait for backend client to be connected so we know
|
// Wait for backend client to be connected so we know
|
||||||
@ -572,7 +585,7 @@ func addPrefFlagMapping(flagName string, prefNames ...string) {
|
|||||||
// correspond to an ipn.Pref.
|
// correspond to an ipn.Pref.
|
||||||
func preflessFlag(flagName string) bool {
|
func preflessFlag(flagName string) bool {
|
||||||
switch flagName {
|
switch flagName {
|
||||||
case "authkey", "force-reauth", "reset":
|
case "authkey", "force-reauth", "reset", "qr":
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -7,6 +7,9 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep
|
|||||||
💣 github.com/mitchellh/go-ps from tailscale.com/cmd/tailscale/cli+
|
💣 github.com/mitchellh/go-ps from tailscale.com/cmd/tailscale/cli+
|
||||||
github.com/peterbourgon/ff/v3 from github.com/peterbourgon/ff/v3/ffcli
|
github.com/peterbourgon/ff/v3 from github.com/peterbourgon/ff/v3/ffcli
|
||||||
github.com/peterbourgon/ff/v3/ffcli from tailscale.com/cmd/tailscale/cli
|
github.com/peterbourgon/ff/v3/ffcli from tailscale.com/cmd/tailscale/cli
|
||||||
|
github.com/skip2/go-qrcode from tailscale.com/cmd/tailscale/cli
|
||||||
|
github.com/skip2/go-qrcode/bitset from github.com/skip2/go-qrcode+
|
||||||
|
github.com/skip2/go-qrcode/reedsolomon from github.com/skip2/go-qrcode
|
||||||
github.com/tailscale/goupnp from github.com/tailscale/goupnp/dcps/internetgateway2+
|
github.com/tailscale/goupnp from github.com/tailscale/goupnp/dcps/internetgateway2+
|
||||||
github.com/tailscale/goupnp/dcps/internetgateway2 from tailscale.com/net/portmapper
|
github.com/tailscale/goupnp/dcps/internetgateway2 from tailscale.com/net/portmapper
|
||||||
github.com/tailscale/goupnp/httpu from github.com/tailscale/goupnp+
|
github.com/tailscale/goupnp/httpu from github.com/tailscale/goupnp+
|
||||||
@ -102,8 +105,9 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep
|
|||||||
golang.org/x/time/rate from tailscale.com/cmd/tailscale/cli+
|
golang.org/x/time/rate from tailscale.com/cmd/tailscale/cli+
|
||||||
bufio from compress/flate+
|
bufio from compress/flate+
|
||||||
bytes from bufio+
|
bytes from bufio+
|
||||||
compress/flate from compress/gzip
|
compress/flate from compress/gzip+
|
||||||
compress/gzip from net/http
|
compress/gzip from net/http
|
||||||
|
compress/zlib from image/png
|
||||||
container/list from crypto/tls+
|
container/list from crypto/tls+
|
||||||
context from crypto/tls+
|
context from crypto/tls+
|
||||||
crypto from crypto/ecdsa+
|
crypto from crypto/ecdsa+
|
||||||
@ -140,10 +144,14 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep
|
|||||||
flag from github.com/peterbourgon/ff/v3+
|
flag from github.com/peterbourgon/ff/v3+
|
||||||
fmt from compress/flate+
|
fmt from compress/flate+
|
||||||
hash from crypto+
|
hash from crypto+
|
||||||
|
hash/adler32 from compress/zlib
|
||||||
hash/crc32 from compress/gzip+
|
hash/crc32 from compress/gzip+
|
||||||
hash/maphash from go4.org/mem
|
hash/maphash from go4.org/mem
|
||||||
html from tailscale.com/ipn/ipnstate+
|
html from tailscale.com/ipn/ipnstate+
|
||||||
html/template from tailscale.com/cmd/tailscale/cli
|
html/template from tailscale.com/cmd/tailscale/cli
|
||||||
|
image from github.com/skip2/go-qrcode+
|
||||||
|
image/color from github.com/skip2/go-qrcode+
|
||||||
|
image/png from github.com/skip2/go-qrcode
|
||||||
io from bufio+
|
io from bufio+
|
||||||
io/fs from crypto/rand+
|
io/fs from crypto/rand+
|
||||||
io/ioutil from golang.org/x/sys/cpu+
|
io/ioutil from golang.org/x/sys/cpu+
|
||||||
|
1
go.mod
1
go.mod
@ -30,6 +30,7 @@ require (
|
|||||||
github.com/pborman/getopt v1.1.0
|
github.com/pborman/getopt v1.1.0
|
||||||
github.com/peterbourgon/ff/v3 v3.1.0
|
github.com/peterbourgon/ff/v3 v3.1.0
|
||||||
github.com/pkg/sftp v1.13.4
|
github.com/pkg/sftp v1.13.4
|
||||||
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||||
github.com/tailscale/certstore v0.0.0-20210528134328-066c94b793d3
|
github.com/tailscale/certstore v0.0.0-20210528134328-066c94b793d3
|
||||||
github.com/tailscale/depaware v0.0.0-20201214215404-77d1e9757027
|
github.com/tailscale/depaware v0.0.0-20201214215404-77d1e9757027
|
||||||
github.com/tailscale/goexpect v0.0.0-20210902213824-6e8c725cea41
|
github.com/tailscale/goexpect v0.0.0-20210902213824-6e8c725cea41
|
||||||
|
2
go.sum
2
go.sum
@ -536,6 +536,8 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB
|
|||||||
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
||||||
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
|
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
|
||||||
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||||
|
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/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||||
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
|
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
|
||||||
|
Loading…
Reference in New Issue
Block a user