host.go 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package models
  2. import (
  3. "net"
  4. "github.com/google/uuid"
  5. "golang.zx2c4.com/wireguard/wgctrl/wgtypes"
  6. )
  7. // WIREGUARD_INTERFACE name of wireguard interface
  8. const WIREGUARD_INTERFACE = "netmaker"
  9. // Host - represents a host on the network
  10. type Host struct {
  11. ID uuid.UUID `json:"id" yaml:"id"`
  12. Verbosity int `json:"verbosity" yaml:"verbosity"`
  13. FirewallInUse string `json:"firewallinuse" yaml:"firewallinuse"`
  14. Version string `json:"version" yaml:"version"`
  15. IPForwarding bool `json:"ipforwarding" yaml:"ipforwarding"`
  16. DaemonInstalled bool `json:"daemoninstalled" yaml:"daemoninstalled"`
  17. HostPass string `json:"hostpass" yaml:"hostpass"`
  18. Name string `json:"name" yaml:"name"`
  19. OS string `json:"os" yaml:"os"`
  20. Interface string `json:"interface" yaml:"interface"`
  21. Debug bool `json:"debug" yaml:"debug"`
  22. ListenPort int `json:"listenport" yaml:"listenport"`
  23. PublicListenPort int `json:"public_listen_port" yaml:"public_listen_port"`
  24. LocalListenPort int `json:"locallistenport" yaml:"locallistenport"`
  25. ProxyListenPort int `json:"proxy_listen_port" yaml:"proxy_listen_port"`
  26. MTU int `json:"mtu" yaml:"mtu"`
  27. PublicKey wgtypes.Key `json:"publickey" yaml:"publickey"`
  28. MacAddress net.HardwareAddr `json:"macaddress" yaml:"macaddress"`
  29. TrafficKeyPublic []byte `json:"traffickeypublic" yaml:"trafficekeypublic"`
  30. InternetGateway net.UDPAddr `json:"internetgateway" yaml:"internetgateway"`
  31. Nodes []string `json:"nodes" yaml:"nodes"`
  32. IsRelayed bool `json:"isrelayed" yaml:"isrelayed"`
  33. RelayedBy string `json:"relayed_by" yaml:"relayed_by"`
  34. IsRelay bool `json:"isrelay" yaml:"isrelay"`
  35. RelayedHosts []string `json:"relay_hosts" yaml:"relay_hosts"`
  36. Interfaces []Iface `json:"interfaces" yaml:"interfaces"`
  37. DefaultInterface string `json:"defaultinterface" yaml:"defautlinterface"`
  38. EndpointIP net.IP `json:"endpointip" yaml:"endpointip"`
  39. ProxyEnabled bool `json:"proxy_enabled" yaml:"proxy_enabled"`
  40. IsDocker bool `json:"isdocker" yaml:"isdocker"`
  41. IsK8S bool `json:"isk8s" yaml:"isk8s"`
  42. IsStatic bool `json:"isstatic" yaml:"isstatic"`
  43. IsDefault bool `json:"isdefault" yaml:"isdefault"`
  44. }
  45. // FormatBool converts a boolean to a [yes|no] string
  46. func FormatBool(b bool) string {
  47. s := "no"
  48. if b {
  49. s = "yes"
  50. }
  51. return s
  52. }
  53. // ParseBool parses a [yes|no] string to boolean value
  54. func ParseBool(s string) bool {
  55. b := false
  56. if s == "yes" {
  57. b = true
  58. }
  59. return b
  60. }
  61. // HostMqAction - type for host update action
  62. type HostMqAction string
  63. const (
  64. // UpdateHost - constant for host update action
  65. UpdateHost = "UPDATE_HOST"
  66. // DeleteHost - constant for host delete action
  67. DeleteHost = "DELETE_HOST"
  68. // JoinHostToNetwork - constant for host network join action
  69. JoinHostToNetwork = "JOIN_HOST_TO_NETWORK"
  70. )
  71. // HostUpdate - struct for host update
  72. type HostUpdate struct {
  73. Action HostMqAction
  74. Host Host
  75. Node Node
  76. }