status.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c)2019 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: 2023-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. // Status shows service status info
  20. func Status(basePath, authToken string, args []string, jsonOutput bool) {
  21. var status zerotier.APIStatus
  22. apiGet(basePath, authToken, "/status", &status)
  23. if jsonOutput {
  24. fmt.Println(jsonDump(&status))
  25. } else {
  26. online := "ONLINE"
  27. if !status.Online {
  28. online = "OFFLINE"
  29. }
  30. fmt.Printf("%.10x: %s %s\n", uint64(status.Address), online, status.Version)
  31. fmt.Printf("\tidentity:\t%s\n", status.Identity.String())
  32. fmt.Printf("\tports:\t%d %d %d\n", status.Config.Settings.PrimaryPort, status.Config.Settings.SecondaryPort, status.Config.Settings.TertiaryPort)
  33. fmt.Printf("\tport search:\t%s\n", enabledDisabled(status.Config.Settings.PortSearch))
  34. fmt.Printf("\tport mapping (uPnP/NAT-PMP):\t%s\n", enabledDisabled(status.Config.Settings.PortMapping))
  35. fmt.Printf("\tmultipath mode:\t%d\n", status.Config.Settings.MuiltipathMode)
  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. os.Exit(0)
  67. }