host.go 3.4 KB

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