host.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. ProxyListenPort int `json:"proxy_listen_port" yaml:"proxy_listen_port"`
  25. MTU int `json:"mtu" yaml:"mtu"`
  26. PublicKey wgtypes.Key `json:"publickey" yaml:"publickey"`
  27. MacAddress net.HardwareAddr `json:"macaddress" yaml:"macaddress"`
  28. TrafficKeyPublic []byte `json:"traffickeypublic" yaml:"trafficekeypublic"`
  29. InternetGateway net.UDPAddr `json:"internetgateway" yaml:"internetgateway"`
  30. Nodes []string `json:"nodes" yaml:"nodes"`
  31. IsRelayed bool `json:"isrelayed" yaml:"isrelayed"`
  32. RelayedBy string `json:"relayed_by" yaml:"relayed_by"`
  33. IsRelay bool `json:"isrelay" yaml:"isrelay"`
  34. RelayedHosts []string `json:"relay_hosts" yaml:"relay_hosts"`
  35. Interfaces []Iface `json:"interfaces" yaml:"interfaces"`
  36. DefaultInterface string `json:"defaultinterface" yaml:"defautlinterface"`
  37. EndpointIP net.IP `json:"endpointip" yaml:"endpointip"`
  38. ProxyEnabled bool `json:"proxy_enabled" yaml:"proxy_enabled"`
  39. IsDocker bool `json:"isdocker" yaml:"isdocker"`
  40. IsK8S bool `json:"isk8s" yaml:"isk8s"`
  41. IsStatic bool `json:"isstatic" yaml:"isstatic"`
  42. IsDefault bool `json:"isdefault" yaml:"isdefault"`
  43. }
  44. // FormatBool converts a boolean to a [yes|no] string
  45. func FormatBool(b bool) string {
  46. s := "no"
  47. if b {
  48. s = "yes"
  49. }
  50. return s
  51. }
  52. // ParseBool parses a [yes|no] string to boolean value
  53. func ParseBool(s string) bool {
  54. b := false
  55. if s == "yes" {
  56. b = true
  57. }
  58. return b
  59. }
  60. // HostMqAction - type for host update action
  61. type HostMqAction string
  62. const (
  63. // UpdateHost - constant for host update action
  64. UpdateHost = "UPDATE_HOST"
  65. // DeleteHost - constant for host delete action
  66. DeleteHost = "DELETE_HOST"
  67. // JoinHostToNetwork - constant for host network join action
  68. JoinHostToNetwork = "JOIN_HOST_TO_NETWORK"
  69. )
  70. // HostUpdate - struct for host update
  71. type HostUpdate struct {
  72. Action HostMqAction
  73. Host Host
  74. Node Node
  75. }