host.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. AutoUpdate bool `json:"autoupdate" yaml:"autoupdate"`
  32. HostPass string `json:"hostpass" yaml:"hostpass"`
  33. Name string `json:"name" yaml:"name"`
  34. OS string `json:"os" yaml:"os"`
  35. Interface string `json:"interface" yaml:"interface"`
  36. Debug bool `json:"debug" yaml:"debug"`
  37. ListenPort int `json:"listenport" yaml:"listenport"`
  38. PublicListenPort int `json:"public_listen_port" yaml:"public_listen_port"`
  39. ProxyListenPort int `json:"proxy_listen_port" yaml:"proxy_listen_port"`
  40. MTU int `json:"mtu" yaml:"mtu"`
  41. PublicKey wgtypes.Key `json:"publickey" yaml:"publickey"`
  42. MacAddress net.HardwareAddr `json:"macaddress" yaml:"macaddress"`
  43. TrafficKeyPublic []byte `json:"traffickeypublic" yaml:"traffickeypublic"`
  44. InternetGateway net.UDPAddr `json:"internetgateway" yaml:"internetgateway"`
  45. Nodes []string `json:"nodes" yaml:"nodes"`
  46. IsRelayed bool `json:"isrelayed" yaml:"isrelayed"`
  47. RelayedBy string `json:"relayed_by" yaml:"relayed_by"`
  48. IsRelay bool `json:"isrelay" yaml:"isrelay"`
  49. RelayedHosts []string `json:"relay_hosts" yaml:"relay_hosts"`
  50. Interfaces []Iface `json:"interfaces" yaml:"interfaces"`
  51. DefaultInterface string `json:"defaultinterface" yaml:"defaultinterface"`
  52. EndpointIP net.IP `json:"endpointip" yaml:"endpointip"`
  53. ProxyEnabled bool `json:"proxy_enabled" yaml:"proxy_enabled"`
  54. ProxyEnabledSet bool `json:"proxy_enabled_updated" yaml:"proxy_enabled_updated"`
  55. IsDocker bool `json:"isdocker" yaml:"isdocker"`
  56. IsK8S bool `json:"isk8s" yaml:"isk8s"`
  57. IsStatic bool `json:"isstatic" yaml:"isstatic"`
  58. IsDefault bool `json:"isdefault" yaml:"isdefault"`
  59. }
  60. // FormatBool converts a boolean to a [yes|no] string
  61. func FormatBool(b bool) string {
  62. s := "no"
  63. if b {
  64. s = "yes"
  65. }
  66. return s
  67. }
  68. // ParseBool parses a [yes|no] string to boolean value
  69. func ParseBool(s string) bool {
  70. b := false
  71. if s == "yes" {
  72. b = true
  73. }
  74. return b
  75. }
  76. // HostMqAction - type for host update action
  77. type HostMqAction string
  78. const (
  79. // UpdateHost - constant for host update action
  80. UpdateHost = "UPDATE_HOST"
  81. // DeleteHost - constant for host delete action
  82. DeleteHost = "DELETE_HOST"
  83. // JoinHostToNetwork - constant for host network join action
  84. JoinHostToNetwork = "JOIN_HOST_TO_NETWORK"
  85. // Acknowledgement - ACK response for hosts
  86. Acknowledgement = "ACK"
  87. // RequestAck - request an ACK
  88. RequestAck = "REQ_ACK"
  89. )
  90. // HostUpdate - struct for host update
  91. type HostUpdate struct {
  92. Action HostMqAction
  93. Host Host
  94. Node Node
  95. }