status.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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: 2024-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. "os"
  17. "zerotier/pkg/zerotier"
  18. )
  19. func Status(basePath, authToken string, args []string, jsonOutput bool) {
  20. var status zerotier.APIStatus
  21. apiGet(basePath, authToken, "/status", &status)
  22. if jsonOutput {
  23. fmt.Println(jsonDump(&status))
  24. } else {
  25. online := "ONLINE"
  26. if !status.Online {
  27. online = "OFFLINE"
  28. }
  29. fmt.Printf("%.10x: %s %s\n", uint64(status.Address), online, status.Version)
  30. fmt.Printf("\tidentity:\t%s\n", status.Identity.String())
  31. if status.Config.Settings.SecondaryPort > 0 && status.Config.Settings.SecondaryPort < 65536 {
  32. fmt.Printf("\tports:\t%d %d\n", status.Config.Settings.PrimaryPort, status.Config.Settings.SecondaryPort)
  33. } else {
  34. fmt.Printf("\tports:\t%d\n", status.Config.Settings.PrimaryPort)
  35. }
  36. fmt.Printf("\tport mapping (uPnP/NAT-PMP):\t%s\n", enabledDisabled(status.Config.Settings.PortMapping))
  37. fmt.Printf("\tblacklisted interface prefixes:\t")
  38. for i, bl := range status.Config.Settings.InterfacePrefixBlacklist {
  39. if i > 0 {
  40. fmt.Print(" ")
  41. }
  42. fmt.Print(bl)
  43. }
  44. fmt.Printf("\n\texplicit external addresses: ")
  45. for i, ea := range status.Config.Settings.ExplicitAddresses {
  46. if i > 0 {
  47. fmt.Print(" ")
  48. }
  49. fmt.Print(ea.String())
  50. }
  51. fmt.Printf("\n\tsystem interface addresses: ")
  52. for i, a := range status.InterfaceAddresses {
  53. if i > 0 {
  54. fmt.Print(" ")
  55. }
  56. fmt.Print(a.String())
  57. }
  58. fmt.Printf("\n\tmapped external addresses: ")
  59. for i, a := range status.MappedExternalAddresses {
  60. if i > 0 {
  61. fmt.Print(" ")
  62. }
  63. fmt.Print(a.String())
  64. }
  65. fmt.Printf("\n")
  66. }
  67. os.Exit(0)
  68. }