status.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (c)2013-2020 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2025-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. package cli
  14. import (
  15. "fmt"
  16. "zerotier/pkg/zerotier"
  17. )
  18. func Status(basePath string, authTokenGenerator func() string, args []string, jsonOutput bool) int {
  19. var status zerotier.APIStatus
  20. apiGet(basePath, authTokenGenerator(), "/status", &status)
  21. if jsonOutput {
  22. fmt.Println(jsonDump(&status))
  23. } else {
  24. online := "ONLINE"
  25. if !status.Online {
  26. online = "OFFLINE"
  27. }
  28. fmt.Printf("%.10x: %s %s\n", uint64(status.Address), online, status.Version)
  29. fmt.Printf("\tidentity:\t%s\n", status.Identity.String())
  30. if status.Config.Settings.SecondaryPort > 0 && status.Config.Settings.SecondaryPort < 65536 {
  31. fmt.Printf("\tports:\t%d %d\n", status.Config.Settings.PrimaryPort, status.Config.Settings.SecondaryPort)
  32. } else {
  33. fmt.Printf("\tports:\t%d\n", status.Config.Settings.PrimaryPort)
  34. }
  35. fmt.Printf("\tport mapping (uPnP/NAT-PMP):\t%s\n", enabledDisabled(status.Config.Settings.PortMapping))
  36. fmt.Printf("\tblacklisted interface prefixes:\t")
  37. for i, bl := range status.Config.Settings.InterfacePrefixBlacklist {
  38. if i > 0 {
  39. fmt.Print(" ")
  40. }
  41. fmt.Print(bl)
  42. }
  43. fmt.Printf("\n\texplicit external addresses: ")
  44. for i, ea := range status.Config.Settings.ExplicitAddresses {
  45. if i > 0 {
  46. fmt.Print(" ")
  47. }
  48. fmt.Print(ea.String())
  49. }
  50. fmt.Printf("\n\tsystem interface addresses: ")
  51. for i, a := range status.InterfaceAddresses {
  52. if i > 0 {
  53. fmt.Print(" ")
  54. }
  55. fmt.Print(a.String())
  56. }
  57. fmt.Printf("\n\tmapped external addresses: ")
  58. for i, a := range status.MappedExternalAddresses {
  59. if i > 0 {
  60. fmt.Print(" ")
  61. }
  62. fmt.Print(a.String())
  63. }
  64. fmt.Printf("\n")
  65. }
  66. return 0
  67. }