host.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. LocalRange net.IPNet `json:"localrange" yaml:"localrange"`
  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. Interfaces []Iface `json:"interfaces" yaml:"interfaces"`
  33. EndpointIP net.IP `json:"endpointip" yaml:"endpointip"`
  34. ProxyEnabled bool `json:"proxy_enabled" yaml:"proxy_enabled"`
  35. IsDocker bool `json:"isdocker" yaml:"isdocker"`
  36. IsK8S bool `json:"isk8s" yaml:"isk8s"`
  37. IsStatic bool `json:"isstatic" yaml:"isstatic"`
  38. IsDefault bool `json:"isdefault" yaml:"isdefault"`
  39. }
  40. // FormatBool converts a boolean to a [yes|no] string
  41. func FormatBool(b bool) string {
  42. s := "no"
  43. if b {
  44. s = "yes"
  45. }
  46. return s
  47. }
  48. // ParseBool parses a [yes|no] string to boolean value
  49. func ParseBool(s string) bool {
  50. b := false
  51. if s == "yes" {
  52. b = true
  53. }
  54. return b
  55. }