mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-07 13:03:45 +02:00
Documentation in CLI, indicate what commands require a running node.
This commit is contained in:
parent
f97e9e1f5d
commit
cb147a3e8a
7 changed files with 120 additions and 142 deletions
|
@ -28,6 +28,8 @@ func Cert(basePath string, authTokenGenerator func() string, args []string, json
|
||||||
|
|
||||||
switch args[0] {
|
switch args[0] {
|
||||||
|
|
||||||
|
case "list":
|
||||||
|
|
||||||
case "newsid":
|
case "newsid":
|
||||||
if len(args) > 2 {
|
if len(args) > 2 {
|
||||||
Help()
|
Help()
|
||||||
|
|
|
@ -39,20 +39,20 @@ Common Operations:
|
||||||
|
|
||||||
status Show node status and configuration
|
status Show node status and configuration
|
||||||
|
|
||||||
set [option] [value] - Get or set node configuration
|
· set [option] [value] - Get or set node configuration
|
||||||
port <port> Primary P2P port
|
port <port> Primary P2P port
|
||||||
secondaryport <port/0> Secondary P2P port (0 to disable)
|
secondaryport <port/0> Secondary P2P port (0 to disable)
|
||||||
blacklist cidr <IP/bits> <boolean> Toggle physical path blacklisting
|
blacklist cidr <IP/bits> <boolean> Toggle physical path blacklisting
|
||||||
blacklist if <prefix> <boolean> Toggle interface prefix blacklisting
|
blacklist if <prefix> <boolean> Toggle interface prefix blacklisting
|
||||||
portmap <boolean> Toggle use of uPnP or NAT-PMP
|
portmap <boolean> Toggle use of uPnP or NAT-PMP
|
||||||
|
|
||||||
peer list List VL1 peers
|
· peer list List VL1 peers
|
||||||
peer <address> [command] [option] - Peer management commands
|
· peer <address> [command] [option] - Peer management commands
|
||||||
show Show peer details (default)
|
show Show peer details (default)
|
||||||
try <endpoint> [...] Try peer at explicit endpoint
|
try <endpoint> [...] Try peer at explicit endpoint
|
||||||
|
|
||||||
network list List VL2 networks
|
· network list List VL2 networks
|
||||||
network <network> [command] [option] - Network management commands
|
· network <network> [command] [option] - Network management commands
|
||||||
show Show network details (default)
|
show Show network details (default)
|
||||||
set [option] [value] - Get or set network options
|
set [option] [value] - Get or set network options
|
||||||
manageips <boolean> Is IP management allowed?
|
manageips <boolean> Is IP management allowed?
|
||||||
|
@ -61,23 +61,23 @@ Common Operations:
|
||||||
globalroutes <boolean> Can global IP space routes be set?
|
globalroutes <boolean> Can global IP space routes be set?
|
||||||
defaultroute <boolean> Can default route be overridden?
|
defaultroute <boolean> Can default route be overridden?
|
||||||
|
|
||||||
join [-options] <network> Join a virtual network
|
· join [-options] <network> Join a virtual network
|
||||||
-a <token> Token to submit to controller
|
-a <token> Token to submit to controller
|
||||||
-c <identity | fingerprint> Controller identity or fingerprint
|
-c <identity | fingerprint> Controller identity or fingerprint
|
||||||
leave <network> Leave a virtual network
|
· leave <network> Leave a virtual network
|
||||||
|
|
||||||
Advanced Operations:
|
Advanced Operations:
|
||||||
|
|
||||||
service Start node (seldom used from CLI)
|
service Start node (seldom used from CLI)
|
||||||
|
|
||||||
controller <command> [option] - Local controller management commands
|
· controller <command> [option] - Local controller management commands
|
||||||
list List networks run by local controller
|
· list List networks run by local controller
|
||||||
new Create a new network
|
· new Create a new network
|
||||||
set <network> [setting] [value] Show or modify network settings
|
· set <network> [setting] [value] Show or modify network settings
|
||||||
members <network> List members of a network
|
· members <network> List members of a network
|
||||||
member <network> [setting] [value] Show or modify member level settings
|
· member <network> [setting] [value] Show or modify member level settings
|
||||||
auth <address> Authorize a peer
|
· auth <address> Authorize a peer
|
||||||
deauth <address> Deauthorize a peer
|
· deauth <address> Deauthorize a peer
|
||||||
|
|
||||||
identity <command> [args] - Identity management
|
identity <command> [args] - Identity management
|
||||||
new [c25519 | p384] Create identity (default: c25519)
|
new [c25519 | p384] Create identity (default: c25519)
|
||||||
|
@ -93,18 +93,20 @@ Advanced Operations:
|
||||||
show <locator> Show contents of a locator
|
show <locator> Show contents of a locator
|
||||||
|
|
||||||
cert <command> [args] - Certificate management
|
cert <command> [args] - Certificate management
|
||||||
list List certificates in local node store
|
· list List certificates in local node store
|
||||||
show [serial] List or show details of a certificate
|
· show [serial] List or show details of a certificate
|
||||||
newsid <secret out> Create a new subject unique ID
|
newsid <secret out> Create a new subject unique ID
|
||||||
newcsr <subject> <secret> <csr out> Create a subject CSR
|
newcsr <subject> <secret> <csr out> Create a subject CSR
|
||||||
sign <csr> <identity> <cert out> Sign a CSR to create a certificate
|
sign <csr> <identity> <cert out> Sign a CSR to create a certificate
|
||||||
verify <cert> Verify a certificate
|
· verify <cert> Verify a certificate
|
||||||
import <cert> [trust,[trust]] Import certificate into this node
|
· import <cert> [trust,[trust]] Import certificate into this node
|
||||||
rootca Certificate is a root CA (trust flag)
|
rootca Certificate is a root CA (trust flag)
|
||||||
ztrootset ZeroTier root node set (trust flag)
|
ztrootset ZeroTier root node set (trust flag)
|
||||||
restore Re-import default certificates
|
· restore Re-import default certificates
|
||||||
export <serial> [path] Export a certificate from this node
|
· export <serial> [path] Export a certificate from this node
|
||||||
delete <serial|ALL> Delete certificate from this node
|
· delete <serial|ALL> Delete certificate from this node
|
||||||
|
|
||||||
|
· Command requires a running node and access to a local API token.
|
||||||
|
|
||||||
An <address> may be specified as a 10-digit short ZeroTier address, a
|
An <address> may be specified as a 10-digit short ZeroTier address, a
|
||||||
fingerprint containing both an address and a SHA384 hash, or an identity.
|
fingerprint containing both an address and a SHA384 hash, or an identity.
|
||||||
|
|
|
@ -21,6 +21,33 @@ import (
|
||||||
"zerotier/pkg/zerotier"
|
"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 <type> <device> <managed IP(s)>\n", "<id>", "<name>", "<mac>", "<status>")
|
||||||
|
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) {
|
func showNetwork(nwids string, network *zerotier.APINetwork, jsonOutput bool) {
|
||||||
if jsonOutput {
|
if jsonOutput {
|
||||||
fmt.Println(jsonDump(&network))
|
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 {
|
func Network(basePath string, authTokenGenerator func() string, args []string, jsonOutput bool) int {
|
||||||
authToken := authTokenGenerator()
|
|
||||||
|
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
Help()
|
Help()
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
authToken := authTokenGenerator()
|
||||||
|
|
||||||
|
if len(args) == 1 && args[0] == "list" {
|
||||||
|
return listNetworks(basePath, authToken, jsonOutput)
|
||||||
|
}
|
||||||
|
|
||||||
if len(args[0]) != zerotier.NetworkIDStringLength {
|
if len(args[0]) != zerotier.NetworkIDStringLength {
|
||||||
fmt.Printf("ERROR: invalid network ID: %s\n", args[0])
|
fmt.Printf("ERROR: invalid network ID: %s\n", args[0])
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -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 <type> <device> <managed IP(s)>\n", "<id>", "<name>", "<mac>", "<status>")
|
|
||||||
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
|
|
||||||
}
|
|
|
@ -13,12 +13,70 @@
|
||||||
|
|
||||||
package cli
|
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("<address> <ver> <root> <lat(ms)> <path(s)>\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 {
|
func Peer(basePath string, authTokenGenerator func() string, args []string, jsonOutput bool) int {
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
Help()
|
Help()
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
authToken := authTokenGenerator()
|
||||||
|
|
||||||
|
if len(args) == 1 && args[0] == "list" {
|
||||||
|
return listPeers(basePath, authToken, jsonOutput, false)
|
||||||
|
}
|
||||||
|
|
||||||
switch args[0] {
|
switch args[0] {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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("<address> <ver> <root> <lat(ms)> <path(s)>\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
|
|
||||||
}
|
|
|
@ -142,15 +142,13 @@ func main() {
|
||||||
case "leave":
|
case "leave":
|
||||||
exitCode = cli.Leave(basePath, authToken(basePath, *tflag, *tTflag), cmdArgs)
|
exitCode = cli.Leave(basePath, authToken(basePath, *tflag, *tTflag), cmdArgs)
|
||||||
case "networks", "listnetworks":
|
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":
|
case "network":
|
||||||
exitCode = cli.Network(basePath, authToken(basePath, *tflag, *tTflag), cmdArgs, *jflag)
|
exitCode = cli.Network(basePath, authToken(basePath, *tflag, *tTflag), cmdArgs, *jflag)
|
||||||
case "peers", "listpeers", "lspeers":
|
case "peers", "listpeers":
|
||||||
exitCode = cli.Peers(basePath, authToken(basePath, *tflag, *tTflag), cmdArgs, *jflag, false)
|
exitCode = cli.Peer(basePath, authToken(basePath, *tflag, *tTflag), []string{"list"}, *jflag)
|
||||||
case "peer":
|
case "peer":
|
||||||
exitCode = cli.Peer(basePath, authToken(basePath, *tflag, *tTflag), cmdArgs, *jflag)
|
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":
|
case "controller":
|
||||||
exitCode = cli.Controller(basePath, authToken(basePath, *tflag, *tTflag), cmdArgs, *jflag)
|
exitCode = cli.Controller(basePath, authToken(basePath, *tflag, *tTflag), cmdArgs, *jflag)
|
||||||
case "set":
|
case "set":
|
||||||
|
|
Loading…
Add table
Reference in a new issue