host.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package models
  2. import (
  3. "net"
  4. "github.com/google/uuid"
  5. "golang.zx2c4.com/wireguard/wgctrl/wgtypes"
  6. )
  7. // OS_Types - list of OS types Netmaker cares about
  8. var OS_Types = struct {
  9. Linux string
  10. Windows string
  11. Mac string
  12. FreeBSD string
  13. IoT string
  14. }{
  15. Linux: "linux",
  16. Windows: "windows",
  17. Mac: "darwin",
  18. FreeBSD: "freebsd",
  19. IoT: "iot",
  20. }
  21. // WIREGUARD_INTERFACE name of wireguard interface
  22. const WIREGUARD_INTERFACE = "netmaker"
  23. // Host - represents a host on the network
  24. type Host struct {
  25. ID uuid.UUID `json:"id" yaml:"id"`
  26. Verbosity int `json:"verbosity" yaml:"verbosity"`
  27. FirewallInUse string `json:"firewallinuse" yaml:"firewallinuse"`
  28. Version string `json:"version" yaml:"version"`
  29. IPForwarding bool `json:"ipforwarding" yaml:"ipforwarding"`
  30. DaemonInstalled bool `json:"daemoninstalled" yaml:"daemoninstalled"`
  31. HostPass string `json:"hostpass" yaml:"hostpass"`
  32. Name string `json:"name" yaml:"name"`
  33. OS string `json:"os" yaml:"os"`
  34. Interface string `json:"interface" yaml:"interface"`
  35. Debug bool `json:"debug" yaml:"debug"`
  36. ListenPort int `json:"listenport" yaml:"listenport"`
  37. PublicListenPort int `json:"public_listen_port" yaml:"public_listen_port"`
  38. ProxyListenPort int `json:"proxy_listen_port" yaml:"proxy_listen_port"`
  39. MTU int `json:"mtu" yaml:"mtu"`
  40. PublicKey wgtypes.Key `json:"publickey" yaml:"publickey"`
  41. MacAddress net.HardwareAddr `json:"macaddress" yaml:"macaddress"`
  42. TrafficKeyPublic []byte `json:"traffickeypublic" yaml:"traffickeypublic"`
  43. InternetGateway net.UDPAddr `json:"internetgateway" yaml:"internetgateway"`
  44. Nodes []string `json:"nodes" yaml:"nodes"`
  45. IsRelayed bool `json:"isrelayed" yaml:"isrelayed"`
  46. RelayedBy string `json:"relayed_by" yaml:"relayed_by"`
  47. IsRelay bool `json:"isrelay" yaml:"isrelay"`
  48. RelayedHosts []string `json:"relay_hosts" yaml:"relay_hosts"`
  49. Interfaces []Iface `json:"interfaces" yaml:"interfaces"`
  50. DefaultInterface string `json:"defaultinterface" yaml:"defaultinterface"`
  51. EndpointIP net.IP `json:"endpointip" yaml:"endpointip"`
  52. ProxyEnabled bool `json:"proxy_enabled" yaml:"proxy_enabled"`
  53. ProxyEnabledSet bool `json:"proxy_enabled_updated" yaml:"proxy_enabled_updated"`
  54. IsDocker bool `json:"isdocker" yaml:"isdocker"`
  55. IsK8S bool `json:"isk8s" yaml:"isk8s"`
  56. IsStatic bool `json:"isstatic" yaml:"isstatic"`
  57. IsDefault bool `json:"isdefault" yaml:"isdefault"`
  58. }
  59. // FormatBool converts a boolean to a [yes|no] string
  60. func FormatBool(b bool) string {
  61. s := "no"
  62. if b {
  63. s = "yes"
  64. }
  65. return s
  66. }
  67. // ParseBool parses a [yes|no] string to boolean value
  68. func ParseBool(s string) bool {
  69. b := false
  70. if s == "yes" {
  71. b = true
  72. }
  73. return b
  74. }
  75. // HostMqAction - type for host update action
  76. type HostMqAction string
  77. const (
  78. // UpdateHost - constant for host update action
  79. UpdateHost = "UPDATE_HOST"
  80. // DeleteHost - constant for host delete action
  81. DeleteHost = "DELETE_HOST"
  82. // JoinHostToNetwork - constant for host network join action
  83. JoinHostToNetwork = "JOIN_HOST_TO_NETWORK"
  84. // Acknowledgement - ACK response for hosts
  85. Acknowledgement = "ACK"
  86. // RequestAck - request an ACK
  87. RequestAck = "REQ_ACK"
  88. // CheckIn - update last check in times and public address and interfaces
  89. CheckIn = "CHECK_IN"
  90. )
  91. // HostUpdate - struct for host update
  92. type HostUpdate struct {
  93. Action HostMqAction
  94. Host Host
  95. Node Node
  96. }