mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-22 20:38:23 +00:00
.
This commit is contained in:
parent
c3e0f262d1
commit
57ade250af
@ -1,2 +1,2 @@
|
||||
all:
|
||||
go build -o zerotier cmd/zerotier/zerotier.go
|
||||
go build -trimpath -ldflags -s -o ../build/zerotier cmd/zerotier/zerotier.go
|
||||
|
@ -14,6 +14,7 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
@ -32,12 +33,15 @@ func AddRoot(basePath, authToken string, args []string) {
|
||||
|
||||
locData, err := ioutil.ReadFile(args[0])
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: unable to read locator: %s\n", err.Error())
|
||||
os.Exit(1)
|
||||
locData, err2 := base64.StdEncoding.DecodeString(strings.TrimSpace(args[0]))
|
||||
if err2 != nil || len(locData) == 0 {
|
||||
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())
|
||||
fmt.Printf("ERROR: invalid locator '%s' (tried as file and base64 literal): %s\n", args[0], err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ func readIdentity(s string) *zerotier.Identity {
|
||||
return id
|
||||
}
|
||||
|
||||
func networkStatusStr(int status) string {
|
||||
func networkStatusStr(status int) string {
|
||||
switch status {
|
||||
case zerotier.NetworkStatusNotFound:
|
||||
return "NOTFOUND"
|
||||
|
@ -63,14 +63,14 @@ func Network(basePath, authToken string, args []string, jsonOutput bool) {
|
||||
fmt.Printf("\tmanaged addresses:\t")
|
||||
for i, a := range network.Config.AssignedAddresses {
|
||||
if i > 0 {
|
||||
fmt.Print(' ')
|
||||
fmt.Print(" ")
|
||||
}
|
||||
fmt.Print(a.String())
|
||||
}
|
||||
fmt.Printf("\n\tmanaged routes:\t")
|
||||
for i, r := range network.Config.Routes {
|
||||
if i > 0 {
|
||||
fmt.Print(' ')
|
||||
fmt.Print(" ")
|
||||
}
|
||||
fmt.Print(r.Target.String())
|
||||
if r.Via == nil {
|
||||
|
@ -37,7 +37,7 @@ func Networks(basePath, authToken string, args []string, jsonOutput bool) {
|
||||
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(",")
|
||||
}
|
||||
fmt.Print(ip.String())
|
||||
}
|
||||
|
@ -41,13 +41,13 @@ func Roots(basePath, authToken string, args []string, jsonOutput bool) {
|
||||
fmt.Printf("%32s %.10x ", rn, uint64(r.Locator.Identity.Address()))
|
||||
for i, a := range r.Locator.Physical {
|
||||
if i > 0 {
|
||||
fmt.Print(',')
|
||||
fmt.Print(",")
|
||||
}
|
||||
fmt.Print(a.String())
|
||||
}
|
||||
for i, a := range r.Locator.Virtual {
|
||||
if i > 0 || len(r.Locator.Physical) > 0 {
|
||||
fmt.Print(',')
|
||||
fmt.Print(",")
|
||||
}
|
||||
fmt.Print(a.String())
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ func Status(basePath, authToken string, args []string, jsonOutput bool) {
|
||||
online = "OFFLINE"
|
||||
}
|
||||
fmt.Printf("%.10x: %s %s\n", uint64(status.Address), online, status.Version)
|
||||
fmt.Printf("\tidentity:\t%s\n", status.Identity.String())
|
||||
fmt.Printf("\tports:\t%d %d %d\n", status.Config.Settings.PrimaryPort, status.Config.Settings.SecondaryPort, status.Config.Settings.TertiaryPort)
|
||||
fmt.Printf("\tport search:\t%s\n", enabledDisabled(status.Config.Settings.PortSearch))
|
||||
fmt.Printf("\tport mapping (uPnP/NAT-PMP):\t%s\n", enabledDisabled(status.Config.Settings.PortMapping))
|
||||
@ -40,32 +41,32 @@ func Status(basePath, authToken string, args []string, jsonOutput bool) {
|
||||
fmt.Printf("\tblacklisted interface prefixes:\t")
|
||||
for i, bl := range status.Config.Settings.InterfacePrefixBlacklist {
|
||||
if i > 0 {
|
||||
fmt.Print(' ')
|
||||
fmt.Print(" ")
|
||||
}
|
||||
fmt.Print(bl)
|
||||
}
|
||||
fmt.Printf("\n\texplicit external addresses: ")
|
||||
for i, ea := range status.Config.Settings.ExplicitAddresses {
|
||||
if i > 0 {
|
||||
fmt.Print(' ')
|
||||
fmt.Print(" ")
|
||||
}
|
||||
fmt.Print(ea.String())
|
||||
}
|
||||
fmt.Printf("\n\tsystem interface addresses: ")
|
||||
for i, a := range status.InterfaceAddresses {
|
||||
if i > 0 {
|
||||
fmt.Print(' ')
|
||||
fmt.Print(" ")
|
||||
}
|
||||
fmt.Print(a.String())
|
||||
}
|
||||
fmt.Printf("\n\tmapped external addresses: ")
|
||||
for i, a := range status.MappedExternalAddresses {
|
||||
if i > 0 {
|
||||
fmt.Print(' ')
|
||||
fmt.Print(" ")
|
||||
}
|
||||
fmt.Print(a.String())
|
||||
}
|
||||
fmt.Printf("\n\tidentity:\t%s\n", status.Identity.String())
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
|
@ -126,7 +126,7 @@ type APIStatus struct {
|
||||
VersionBuild int `json:"versionBuild"`
|
||||
OS string `json:"os"`
|
||||
Architecture string `json:"architecture"`
|
||||
Concurrency int `json:"cpus"`
|
||||
Concurrency int `json:"concurrency"`
|
||||
Runtime string `json:"runtimeVersion"`
|
||||
}
|
||||
|
||||
|
@ -204,7 +204,6 @@ func (id *Identity) UnmarshalJSON(j []byte) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(s)
|
||||
nid, err := NewIdentityFromString(s)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -327,12 +327,10 @@ func NewNode(basePath string) (*Node, error) {
|
||||
m, _ := NewMACFromBytes(i.HardwareAddr)
|
||||
if _, isZeroTier := n.networksByMAC[m]; !isZeroTier {
|
||||
addrs, _ := i.Addrs()
|
||||
if len(addrs) > 0 {
|
||||
for _, a := range addrs {
|
||||
ipn, _ := a.(*net.IPNet)
|
||||
if ipn != nil {
|
||||
interfaceAddresses[ipn.IP.String()] = ipn.IP
|
||||
}
|
||||
for _, a := range addrs {
|
||||
ipn, _ := a.(*net.IPNet)
|
||||
if ipn != nil && len(ipn.IP) > 0 && !ipn.IP.IsLinkLocalUnicast() && !ipn.IP.IsMulticast() {
|
||||
interfaceAddresses[ipn.IP.String()] = ipn.IP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user