types.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. package vpn
  2. // OverallVPNStatus provides quick telemetry for the sidebar badges
  3. type OverallVPNStatus struct {
  4. TotalPPPoE int `json:"total_pppoe"`
  5. ActivePPPoE int `json:"active_pppoe"`
  6. TotalWireGuard int `json:"total_wireguard"`
  7. ActiveWireGuard int `json:"active_wireguard"`
  8. TotalWireGuardPeers int `json:"total_wg_peers"`
  9. TotalPPTP int `json:"total_pptp"`
  10. ActivePPTP int `json:"active_pptp"`
  11. TotalL2TP int `json:"total_l2tp"`
  12. ActiveL2TP int `json:"active_l2tp"`
  13. TotalIPSec int `json:"total_ipsec"`
  14. ActiveIPSec int `json:"active_ipsec"`
  15. TotalEoIP int `json:"total_eoip"`
  16. ActiveEoIP int `json:"active_eoip"`
  17. TotalPPPSessions int `json:"total_ppp_sessions"`
  18. PPPoEServerRunning bool `json:"pppoe_server_running"`
  19. PPTPServerRunning bool `json:"pptp_server_running"`
  20. L2TPServerRunning bool `json:"l2tp_server_running"`
  21. IPSecServerRunning bool `json:"ipsec_server_running"`
  22. TotalActiveTunnels int `json:"total_active_tunnels"`
  23. }
  24. // ======================== PPPoE Client (MikroTik style) ========================
  25. type PPPoEInstance struct {
  26. Name string `json:"name"` // e.g. "pppoe-out1", "pppoe-wan2"
  27. Interface string `json:"interface"` // Physical or VLAN interface, e.g. "eth0", "eth0.100"
  28. Username string `json:"username"`
  29. Password string `json:"password"`
  30. Profile string `json:"profile,omitempty"` // PPP Profile from /ppp profile (default "default")
  31. ServiceName string `json:"service_name,omitempty"`
  32. MTU int `json:"mtu"` // default 1492
  33. DefaultRoute bool `json:"default_route"`
  34. AutoReconnect bool `json:"auto_reconnect"`
  35. Disabled bool `json:"disabled"`
  36. Running bool `json:"running"` // MikroTik 'R' flag
  37. AssignedIP string `json:"assigned_ip,omitempty"`
  38. PPPDevice string `json:"ppp_device,omitempty"` // e.g. "ppp0"
  39. Uptime string `json:"uptime,omitempty"`
  40. LastError string `json:"last_error,omitempty"`
  41. }
  42. // ======================== WireGuard (MikroTik style) ========================
  43. type WireGuardPeer struct {
  44. Interface string `json:"interface"` // Name of parent WG interface (e.g. "wg0")
  45. Name string `json:"name"` // Friendly label (e.g. "Peer-Office", "Laptop")
  46. Comment string `json:"comment,omitempty"`
  47. PublicKey string `json:"public_key"`
  48. AllowedIPs []string `json:"allowed_ips"`
  49. EndpointAddress string `json:"endpoint_address,omitempty"`
  50. EndpointPort int `json:"endpoint_port,omitempty"`
  51. PersistentKeepalive int `json:"persistent_keepalive,omitempty"`
  52. PresharedKey string `json:"preshared_key,omitempty"`
  53. Disabled bool `json:"disabled"`
  54. LatestHandshake string `json:"latest_handshake,omitempty"`
  55. TransferRxBytes uint64 `json:"transfer_rx_bytes,omitempty"`
  56. TransferTxBytes uint64 `json:"transfer_tx_bytes,omitempty"`
  57. TransferRxHuman string `json:"transfer_rx_human,omitempty"`
  58. TransferTxHuman string `json:"transfer_tx_human,omitempty"`
  59. }
  60. type WireGuardInterface struct {
  61. Name string `json:"name"` // e.g. "wg0", "wg-office", "wg-site2site"
  62. ListenPort int `json:"listen_port"` // UDP port e.g. 51820
  63. PrivateKey string `json:"private_key"`
  64. PublicKey string `json:"public_key"`
  65. Address string `json:"address"` // e.g. "10.10.0.1/24"
  66. MTU int `json:"mtu"` // default 1420
  67. Comment string `json:"comment,omitempty"`
  68. Disabled bool `json:"disabled"`
  69. Running bool `json:"running"` // MikroTik 'R' flag
  70. PeersCount int `json:"peers_count"`
  71. Peers []WireGuardPeer `json:"peers"`
  72. LastError string `json:"last_error,omitempty"`
  73. }
  74. type SaveWireGuardInterfaceRequest struct {
  75. WireGuardInterface
  76. OrigName string `json:"orig_name,omitempty"`
  77. }
  78. type SaveWireGuardPeerRequest struct {
  79. WireGuardPeer
  80. OrigInterface string `json:"orig_interface,omitempty"`
  81. OrigPublicKey string `json:"orig_public_key,omitempty"`
  82. }
  83. // ======================== PPTP Client (MikroTik style) ========================
  84. type PPTPInstance struct {
  85. Name string `json:"name"` // e.g. "pptp-out1"
  86. ConnectTo string `json:"connect_to"` // Server IP / hostname
  87. Username string `json:"username"`
  88. Password string `json:"password"`
  89. Profile string `json:"profile,omitempty"` // PPP Profile from /ppp profile (default "default-encryption")
  90. RequireMPPE bool `json:"require_mppe"`
  91. DefaultRoute bool `json:"default_route"`
  92. AutoReconnect bool `json:"auto_reconnect"`
  93. Disabled bool `json:"disabled"`
  94. Running bool `json:"running"`
  95. AssignedIP string `json:"assigned_ip,omitempty"`
  96. PPPDevice string `json:"ppp_device,omitempty"`
  97. LastError string `json:"last_error,omitempty"`
  98. }
  99. // ======================== L2TP Client (MikroTik style) ========================
  100. type L2TPInstance struct {
  101. Name string `json:"name"` // e.g. "l2tp-out1"
  102. ConnectTo string `json:"connect_to"` // Server IP / hostname
  103. Username string `json:"username"`
  104. Password string `json:"password"`
  105. Profile string `json:"profile,omitempty"` // PPP Profile from /ppp profile (default "default-encryption")
  106. IPsecSecret string `json:"ipsec_secret,omitempty"` // For L2TP/IPsec
  107. DefaultRoute bool `json:"default_route"`
  108. Disabled bool `json:"disabled"`
  109. Running bool `json:"running"`
  110. AssignedIP string `json:"assigned_ip,omitempty"`
  111. PPPDevice string `json:"ppp_device,omitempty"`
  112. LastError string `json:"last_error,omitempty"`
  113. }
  114. // ======================== IPSec Connection / Policy (FortiGate Phase 1 & 2 Style) ========================
  115. type IPSecConfig struct {
  116. Connections []IPSecConnection `json:"connections"`
  117. }
  118. type IPSecStatus struct {
  119. Running bool `json:"running"`
  120. ActiveSAs int `json:"active_sas"`
  121. Connections []IPSecConnection `json:"connections"`
  122. RawStatus string `json:"raw_status"`
  123. }
  124. type IPSecConnection struct {
  125. Name string `json:"name"` // Tunnel name, e.g. "VPN_HQ", "to_branch"
  126. Comments string `json:"comments"` // FortiGate Comments
  127. // Network & Phase 1 (IKE Gateway)
  128. Interface string `json:"interface"` // Local interface or %any
  129. LocalAddrs string `json:"local_addrs"` // "%any" or local IP
  130. RemoteAddrs string `json:"remote_addrs"` // Remote Gateway IP or FQDN
  131. IKEVersion string `json:"ike_version"` // "ikev2" (default) or "ikev1"
  132. AuthMethod string `json:"auth_method"` // "psk"
  133. PresharedKey string `json:"preshared_key"`
  134. LocalID string `json:"local_id,omitempty"`
  135. RemoteID string `json:"remote_id,omitempty"`
  136. IKEProposals string `json:"ike_proposals"` // default: aes256-sha256-modp2048,default
  137. IKEKeylife int `json:"ike_keylife"` // seconds, default 86400
  138. DPD string `json:"dpd"` // "on-demand" (default), "periodic", "disabled"
  139. NATTraversal bool `json:"nat_traversal"` // default true
  140. // Phase 2 (IPsec / Selectors)
  141. Phase2Name string `json:"phase2_name"` // e.g. "VPN_HQ_p2"
  142. ESPProposals string `json:"esp_proposals"` // default: aes256-sha256-modp2048,default
  143. PFS bool `json:"pfs"` // Perfect Forward Secrecy, default true
  144. PFSGroup string `json:"pfs_group"` // e.g. "modp2048" (DH 14), "ecp256" (DH 19)
  145. ESPKeylife int `json:"esp_keylife"` // seconds, default 28800
  146. AutoStart bool `json:"auto_start"` // default true
  147. // Traffic Selectors: Multiple Subnets support!
  148. LocalSubnets []string `json:"local_subnets"` // e.g. ["192.168.10.0/24", "10.0.1.0/24", "172.16.0.0/16"]
  149. RemoteSubnets []string `json:"remote_subnets"` // e.g. ["192.168.20.0/24", "10.0.2.0/24", "172.17.0.0/16"]
  150. LocalSubnet string `json:"local_subnet"` // Backward compatibility
  151. RemoteSubnet string `json:"remote_subnet"` // Backward compatibility
  152. Disabled bool `json:"disabled"`
  153. Running bool `json:"running"` // Active SA installed
  154. Status string `json:"status"` // "ESTABLISHED", "INSTALLED", "DISCONNECTED"
  155. }