mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-14 10:37:33 -07:00
addroot
This commit is contained in:
parent
1711cced3e
commit
d1b780c7be
4 changed files with 99 additions and 9 deletions
|
@ -13,6 +13,49 @@
|
|||
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"zerotier/pkg/zerotier"
|
||||
)
|
||||
|
||||
// AddRoot CLI command
|
||||
func AddRoot(basePath, authToken string, args []string) {
|
||||
if len(args) == 0 {
|
||||
Help()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
locData, err := ioutil.ReadFile(args[0])
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: unable to read locator: %s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
loc, err := zerotier.NewLocatorFromBytes(locData)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: invalid locator in file '%s': %s\n", args[0], err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var name string
|
||||
if len(args) > 1 {
|
||||
if len(args) > 2 {
|
||||
Help()
|
||||
os.Exit(1)
|
||||
}
|
||||
name = strings.TrimSpace(args[1])
|
||||
}
|
||||
|
||||
var result zerotier.Root
|
||||
apiPost(basePath, authToken, "/root/"+url.PathEscape(name), &zerotier.Root{
|
||||
Name: name,
|
||||
Locator: loc,
|
||||
}, &result)
|
||||
|
||||
fmt.Println(jsonDump(&result))
|
||||
os.Exit(0)
|
||||
}
|
||||
|
|
|
@ -40,13 +40,13 @@ Commands:
|
|||
service Start in system service mode
|
||||
status Show ZeroTier service status and config
|
||||
peers Show VL1 peers
|
||||
roots Show VL1 root servers
|
||||
roots Show configured VL1 root servers
|
||||
addroot <locator> [name] Add a VL1 root
|
||||
removeroot <name> Remove a VL1 root
|
||||
locator <command> [args] Locator management commands
|
||||
new <identity> <address> [...] Create and sign a locator
|
||||
newdnskey Create a secure DNS name and secret
|
||||
getdns <key> <locator> Create secure DNS TXT records
|
||||
getdns <dns key> <locator> Create secure DNS TXT records
|
||||
identity <command> [args] Identity management commands
|
||||
new [c25519|p384] Create new identity (including secret)
|
||||
getpublic <identity> Extract only public part of identity
|
||||
|
|
|
@ -38,6 +38,23 @@ func apiGet(basePath, authToken, urlPath string, result interface{}) {
|
|||
}
|
||||
}
|
||||
|
||||
func apiPost(basePath, authToken, urlPath string, post, result interface{}) {
|
||||
statusCode, err := zerotier.APIPost(basePath, zerotier.APISocketName, authToken, urlPath, post, result)
|
||||
if err != nil {
|
||||
fmt.Printf("FATAL: API response code %d: %s\n", statusCode, err.Error())
|
||||
os.Exit(1)
|
||||
return
|
||||
}
|
||||
if statusCode != http.StatusOK {
|
||||
if statusCode == http.StatusUnauthorized {
|
||||
fmt.Printf("FATAL: API response code %d: unauthorized (authorization token incorrect)\n", statusCode)
|
||||
}
|
||||
fmt.Printf("FATAL: API response code %d\n", statusCode)
|
||||
os.Exit(1)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func enabledDisabled(f bool) string {
|
||||
if f {
|
||||
return "ENABLED"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue