From cb147a3e8a304597b3084196609045509da3d5c1 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Mon, 10 Aug 2020 16:04:05 -0700 Subject: [PATCH] Documentation in CLI, indicate what commands require a running node. --- cmd/zerotier/cli/cert.go | 2 ++ cmd/zerotier/cli/help.go | 46 +++++++++++++------------ cmd/zerotier/cli/network.go | 35 +++++++++++++++++-- cmd/zerotier/cli/networks.go | 46 ------------------------- cmd/zerotier/cli/peer.go | 58 +++++++++++++++++++++++++++++++ cmd/zerotier/cli/peers.go | 67 ------------------------------------ cmd/zerotier/zerotier.go | 8 ++--- 7 files changed, 120 insertions(+), 142 deletions(-) delete mode 100644 cmd/zerotier/cli/networks.go delete mode 100644 cmd/zerotier/cli/peers.go diff --git a/cmd/zerotier/cli/cert.go b/cmd/zerotier/cli/cert.go index 753aa8187..d9ce87efa 100644 --- a/cmd/zerotier/cli/cert.go +++ b/cmd/zerotier/cli/cert.go @@ -28,6 +28,8 @@ func Cert(basePath string, authTokenGenerator func() string, args []string, json switch args[0] { + case "list": + case "newsid": if len(args) > 2 { Help() diff --git a/cmd/zerotier/cli/help.go b/cmd/zerotier/cli/help.go index a14fd5a68..00d828b72 100644 --- a/cmd/zerotier/cli/help.go +++ b/cmd/zerotier/cli/help.go @@ -39,20 +39,20 @@ Common Operations: status Show node status and configuration - set [option] [value] - Get or set node configuration +· set [option] [value] - Get or set node configuration port Primary P2P port secondaryport Secondary P2P port (0 to disable) blacklist cidr Toggle physical path blacklisting blacklist if Toggle interface prefix blacklisting portmap Toggle use of uPnP or NAT-PMP - peer list List VL1 peers - peer
[command] [option] - Peer management commands +· peer list List VL1 peers +· peer
[command] [option] - Peer management commands show Show peer details (default) try [...] Try peer at explicit endpoint - network list List VL2 networks - network [command] [option] - Network management commands +· network list List VL2 networks +· network [command] [option] - Network management commands show Show network details (default) set [option] [value] - Get or set network options manageips Is IP management allowed? @@ -61,23 +61,23 @@ Common Operations: globalroutes Can global IP space routes be set? defaultroute Can default route be overridden? - join [-options] Join a virtual network +· join [-options] Join a virtual network -a Token to submit to controller -c Controller identity or fingerprint - leave Leave a virtual network +· leave Leave a virtual network Advanced Operations: service Start node (seldom used from CLI) - controller [option] - Local controller management commands - list List networks run by local controller - new Create a new network - set [setting] [value] Show or modify network settings - members List members of a network - member [setting] [value] Show or modify member level settings - auth
Authorize a peer - deauth
Deauthorize a peer +· controller [option] - Local controller management commands +· list List networks run by local controller +· new Create a new network +· set [setting] [value] Show or modify network settings +· members List members of a network +· member [setting] [value] Show or modify member level settings +· auth
Authorize a peer +· deauth
Deauthorize a peer identity [args] - Identity management new [c25519 | p384] Create identity (default: c25519) @@ -93,18 +93,20 @@ Advanced Operations: show Show contents of a locator cert [args] - Certificate management - list List certificates in local node store - show [serial] List or show details of a certificate +· list List certificates in local node store +· show [serial] List or show details of a certificate newsid Create a new subject unique ID newcsr Create a subject CSR sign Sign a CSR to create a certificate - verify Verify a certificate - import [trust,[trust]] Import certificate into this node +· verify Verify a certificate +· import [trust,[trust]] Import certificate into this node rootca Certificate is a root CA (trust flag) ztrootset ZeroTier root node set (trust flag) - restore Re-import default certificates - export [path] Export a certificate from this node - delete Delete certificate from this node +· restore Re-import default certificates +· export [path] Export a certificate from this node +· delete Delete certificate from this node + +· Command requires a running node and access to a local API token. An
may be specified as a 10-digit short ZeroTier address, a fingerprint containing both an address and a SHA384 hash, or an identity. diff --git a/cmd/zerotier/cli/network.go b/cmd/zerotier/cli/network.go index 9f50c2272..e2cb0dceb 100644 --- a/cmd/zerotier/cli/network.go +++ b/cmd/zerotier/cli/network.go @@ -21,6 +21,33 @@ import ( "zerotier/pkg/zerotier" ) +func listNetworks(basePath, authToken string, jsonOutput bool) int { + var networks []zerotier.APINetwork + apiGet(basePath, authToken, "/network", &networks) + + if jsonOutput { + fmt.Println(jsonDump(networks)) + } else { + fmt.Printf("%-16s %-24s %-17s %-8s \n", "", "", "", "") + for _, nw := range networks { + t := "PRIVATE" + if nw.Config.Type == zerotier.NetworkTypePublic { + t = "PUBLIC" + } + fmt.Printf("%.16x %-24s %-17s %-16s %-7s %-16s ", uint64(nw.ID), nw.Config.Name, nw.Config.MAC.String(), networkStatusStr(nw.Config.Status), t, nw.PortName) + for i, ip := range nw.Config.AssignedAddresses { + if i > 0 { + fmt.Print(",") + } + fmt.Print(ip.String()) + } + fmt.Print("\n") + } + } + + return 0 +} + func showNetwork(nwids string, network *zerotier.APINetwork, jsonOutput bool) { if jsonOutput { fmt.Println(jsonDump(&network)) @@ -85,13 +112,17 @@ func showNetwork(nwids string, network *zerotier.APINetwork, jsonOutput bool) { } func Network(basePath string, authTokenGenerator func() string, args []string, jsonOutput bool) int { - authToken := authTokenGenerator() - if len(args) < 1 { Help() return 1 } + authToken := authTokenGenerator() + + if len(args) == 1 && args[0] == "list" { + return listNetworks(basePath, authToken, jsonOutput) + } + if len(args[0]) != zerotier.NetworkIDStringLength { fmt.Printf("ERROR: invalid network ID: %s\n", args[0]) return 1 diff --git a/cmd/zerotier/cli/networks.go b/cmd/zerotier/cli/networks.go deleted file mode 100644 index 82e107584..000000000 --- a/cmd/zerotier/cli/networks.go +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c)2013-2020 ZeroTier, Inc. - * - * Use of this software is governed by the Business Source License included - * in the LICENSE.TXT file in the project's root directory. - * - * Change Date: 2025-01-01 - * - * On the date above, in accordance with the Business Source License, use - * of this software will be governed by version 2.0 of the Apache License. - */ -/****/ - -package cli - -import ( - "fmt" - "zerotier/pkg/zerotier" -) - -func Networks(basePath string, authTokenGenerator func() string, args []string, jsonOutput bool) int { - var networks []zerotier.APINetwork - apiGet(basePath, authTokenGenerator(), "/network", &networks) - - if jsonOutput { - fmt.Println(jsonDump(networks)) - } else { - fmt.Printf("%-16s %-24s %-17s %-8s \n", "", "", "", "") - for _, nw := range networks { - t := "PRIVATE" - if nw.Config.Type == zerotier.NetworkTypePublic { - t = "PUBLIC" - } - fmt.Printf("%.16x %-24s %-17s %-16s %-7s %-16s ", uint64(nw.ID), nw.Config.Name, nw.Config.MAC.String(), networkStatusStr(nw.Config.Status), t, nw.PortName) - for i, ip := range nw.Config.AssignedAddresses { - if i > 0 { - fmt.Print(",") - } - fmt.Print(ip.String()) - } - fmt.Print("\n") - } - } - - return 0 -} diff --git a/cmd/zerotier/cli/peer.go b/cmd/zerotier/cli/peer.go index 391f14ba2..2f1e7f9cc 100644 --- a/cmd/zerotier/cli/peer.go +++ b/cmd/zerotier/cli/peer.go @@ -13,12 +13,70 @@ package cli +import ( + "fmt" + "strings" + "zerotier/pkg/zerotier" +) + +func listPeers(basePath, authToken string, jsonOutput bool, rootsOnly bool) int { + var peers []zerotier.Peer + apiGet(basePath, authToken, "/peer", &peers) + + if rootsOnly { + roots := make([]zerotier.Peer, 0, len(peers)) + for i := range peers { + if peers[i].Root { + roots = append(roots, peers[i]) + } + } + peers = roots + } + + if jsonOutput { + fmt.Println(jsonDump(&peers)) + } else { + fmt.Printf("
\n") + for _, peer := range peers { + root := "" + if peer.Root { + root = " *" + } + + var paths strings.Builder + if len(peer.Paths) > 0 { + if paths.Len() > 0 { + paths.WriteRune(' ') + } + paths.WriteString(peer.Paths[0].Endpoint.String()) + } else { + paths.WriteString("(relayed)") + } + + fmt.Printf("%.10x %-7s %-6s %-9d %s\n", + uint64(peer.Address), + fmt.Sprintf("%d.%d.%d", peer.Version[0], peer.Version[1], peer.Version[2]), + root, + peer.Latency, + paths.String()) + } + } + + return 0 +} + func Peer(basePath string, authTokenGenerator func() string, args []string, jsonOutput bool) int { if len(args) < 1 { Help() return 1 } + authToken := authTokenGenerator() + + if len(args) == 1 && args[0] == "list" { + return listPeers(basePath, authToken, jsonOutput, false) + } + switch args[0] { } diff --git a/cmd/zerotier/cli/peers.go b/cmd/zerotier/cli/peers.go deleted file mode 100644 index 293b0210e..000000000 --- a/cmd/zerotier/cli/peers.go +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c)2013-2020 ZeroTier, Inc. - * - * Use of this software is governed by the Business Source License included - * in the LICENSE.TXT file in the project's root directory. - * - * Change Date: 2025-01-01 - * - * On the date above, in accordance with the Business Source License, use - * of this software will be governed by version 2.0 of the Apache License. - */ -/****/ - -package cli - -import ( - "fmt" - "strings" - - "zerotier/pkg/zerotier" -) - -func Peers(basePath string, authTokenGenerator func() string, args []string, jsonOutput bool, rootsOnly bool) int { - var peers []zerotier.Peer - apiGet(basePath, authTokenGenerator(), "/peer", &peers) - - if rootsOnly { - roots := make([]zerotier.Peer, 0, len(peers)) - for i := range peers { - if peers[i].Root { - roots = append(roots, peers[i]) - } - } - peers = roots - } - - if jsonOutput { - fmt.Println(jsonDump(&peers)) - } else { - fmt.Printf("
\n") - for _, peer := range peers { - root := "" - if peer.Root { - root = " *" - } - - var paths strings.Builder - if len(peer.Paths) > 0 { - if paths.Len() > 0 { - paths.WriteRune(' ') - } - paths.WriteString(peer.Paths[0].Endpoint.String()) - } else { - paths.WriteString("(relayed)") - } - - fmt.Printf("%.10x %-7s %-6s %-9d %s\n", - uint64(peer.Address), - fmt.Sprintf("%d.%d.%d", peer.Version[0], peer.Version[1], peer.Version[2]), - root, - peer.Latency, - paths.String()) - } - } - - return 0 -} diff --git a/cmd/zerotier/zerotier.go b/cmd/zerotier/zerotier.go index f2d0a49d1..41d6bef9c 100644 --- a/cmd/zerotier/zerotier.go +++ b/cmd/zerotier/zerotier.go @@ -142,15 +142,13 @@ func main() { case "leave": exitCode = cli.Leave(basePath, authToken(basePath, *tflag, *tTflag), cmdArgs) case "networks", "listnetworks": - exitCode = cli.Networks(basePath, authToken(basePath, *tflag, *tTflag), cmdArgs, *jflag) + exitCode = cli.Network(basePath, authToken(basePath, *tflag, *tTflag), []string{"list"}, *jflag) case "network": exitCode = cli.Network(basePath, authToken(basePath, *tflag, *tTflag), cmdArgs, *jflag) - case "peers", "listpeers", "lspeers": - exitCode = cli.Peers(basePath, authToken(basePath, *tflag, *tTflag), cmdArgs, *jflag, false) + case "peers", "listpeers": + exitCode = cli.Peer(basePath, authToken(basePath, *tflag, *tTflag), []string{"list"}, *jflag) case "peer": exitCode = cli.Peer(basePath, authToken(basePath, *tflag, *tTflag), cmdArgs, *jflag) - case "roots": - exitCode = cli.Peers(basePath, authToken(basePath, *tflag, *tTflag), cmdArgs, *jflag, true) case "controller": exitCode = cli.Controller(basePath, authToken(basePath, *tflag, *tTflag), cmdArgs, *jflag) case "set":