server_types.go 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package dhcp
  2. import "time"
  3. // DHCPServerInstance represents an interface-bound DHCP server (/ip dhcp-server)
  4. type DHCPServerInstance struct {
  5. ID string `json:"id"`
  6. Name string `json:"name"` // e.g. "dhcp1", "defconf"
  7. Interface string `json:"interface"` // e.g. "bridge1", "eth0"
  8. LeaseTime string `json:"lease_time"` // e.g. "12h", "1d", "30m"
  9. AddressPool string `json:"address_pool"` // e.g. "192.168.88.10-192.168.88.254"
  10. Authoritative bool `json:"authoritative"` // default true
  11. Disabled bool `json:"disabled"` // MikroTik 'X' flag
  12. Comment string `json:"comment,omitempty"`
  13. // Runtime telemetry
  14. Running bool `json:"running"`
  15. ActiveLeases int `json:"active_leases"`
  16. }
  17. // DHCPNetwork defines options and gateway for a specific subnet (/ip dhcp-server network)
  18. type DHCPNetwork struct {
  19. ID string `json:"id"`
  20. Address string `json:"address"` // CIDR e.g. "192.168.88.0/24"
  21. Gateway string `json:"gateway"` // Option 3 (Router IP)
  22. Netmask string `json:"netmask"` // Netmask e.g. "255.255.255.0" or "24"
  23. DNSServers []string `json:"dns_servers"` // Option 6
  24. Domain string `json:"domain"` // Option 15
  25. NTPServers []string `json:"ntp_servers"` // Option 42 (requested by user)
  26. NextServer string `json:"next_server"` // Option 66 / TFTP server IP/hostname (requested by user)
  27. BootFileName string `json:"boot_file_name"`// Option 67 / PXE boot filename
  28. WINSServers []string `json:"wins_servers"` // Option 44
  29. DHCPOptions []string `json:"dhcp_options"` // Linked custom option IDs
  30. Comment string `json:"comment,omitempty"`
  31. }
  32. // DHCPLease represents an active dynamic lease or static reservation (/ip dhcp-server lease)
  33. type DHCPLease struct {
  34. ID string `json:"id"`
  35. Address string `json:"address"` // Assigned IP
  36. MACAddress string `json:"mac_address"` // Format "aa:bb:cc:dd:ee:ff"
  37. ClientID string `json:"client_id,omitempty"`
  38. Server string `json:"server"` // Server name or "all"
  39. HostName string `json:"hostname"`
  40. ExpiresIn string `json:"expires_in"` // e.g. "11h 45m" or "never"
  41. ExpiresAt time.Time `json:"expires_at"`
  42. Dynamic bool `json:"dynamic"` // true=from dnsmasq.leases, false=static reservation
  43. Status string `json:"status"` // "bound", "static", "waiting"
  44. Disabled bool `json:"disabled"`
  45. Comment string `json:"comment,omitempty"`
  46. }
  47. // DHCPOption represents a raw or typed custom DHCP option (/ip dhcp-server option)
  48. type DHCPOption struct {
  49. ID string `json:"id"`
  50. Name string `json:"name"` // e.g. "unifi-controller", "voip-tftp"
  51. Code int `json:"code"` // Option code (1 - 254)
  52. Value string `json:"value"` // Raw IP, text, hex or option string
  53. Comment string `json:"comment,omitempty"`
  54. }
  55. // DHCPServerSummary provides aggregated statistics for KPI cards & sidebar badges
  56. type DHCPServerSummary struct {
  57. TotalServers int `json:"total_servers"`
  58. ActiveServers int `json:"active_servers"`
  59. TotalNetworks int `json:"total_networks"`
  60. ActiveLeases int `json:"active_leases"`
  61. StaticLeases int `json:"static_leases"`
  62. TotalOptions int `json:"total_options"`
  63. }
  64. // DHCPServerConfigStore wraps JSON persistence
  65. type DHCPServerConfigStore struct {
  66. Servers []DHCPServerInstance `json:"servers"`
  67. Networks []DHCPNetwork `json:"networks"`
  68. StaticLeases []DHCPLease `json:"static_leases"`
  69. Options []DHCPOption `json:"options"`
  70. }
  71. // DHCPServerSetupRequest is used by the MikroTik-style 1-click DHCP Setup Wizard
  72. type DHCPServerSetupRequest struct {
  73. Interface string `json:"interface"` // e.g. "bridge1"
  74. AddressSpace string `json:"address_space"` // e.g. "192.168.88.0/24"
  75. Gateway string `json:"gateway"` // e.g. "192.168.88.1"
  76. AddressPool string `json:"address_pool"` // e.g. "192.168.88.10-192.168.88.254"
  77. DNSServers []string `json:"dns_servers"` // e.g. ["192.168.88.1", "1.1.1.1"]
  78. LeaseTime string `json:"lease_time"` // e.g. "12h"
  79. Domain string `json:"domain,omitempty"` // e.g. "lan"
  80. NTPServers []string `json:"ntp_servers,omitempty"` // e.g. ["192.168.88.1"]
  81. NextServer string `json:"next_server,omitempty"` // e.g. "192.168.88.50"
  82. BootFileName string `json:"boot_file_name,omitempty"`// e.g. "pxelinux.0"
  83. }