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