manager.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package vpn
  2. import "proxmox-router/internal/aerotun"
  3. type Manager struct {
  4. PPPoE *PPPoEManager
  5. WireGuard *WireGuardManager
  6. PPTP *PPTPManager
  7. L2TP *L2TPManager
  8. IPSec *IPSecManager
  9. EoIP *EoIPManager
  10. PPPServer *PPPServerManager
  11. AeroTUN *aerotun.Manager
  12. }
  13. func NewManager() *Manager {
  14. pppServer := NewPPPServerManager()
  15. l2tpMgr := NewL2TPManager()
  16. l2tpMgr.SetPPPServer(pppServer)
  17. pptpMgr := NewPPTPManager()
  18. pptpMgr.SetPPPServer(pppServer)
  19. return &Manager{
  20. PPPoE: NewPPPoEManager(),
  21. WireGuard: NewWireGuardManager(),
  22. PPTP: pptpMgr,
  23. L2TP: l2tpMgr,
  24. IPSec: NewIPSecManager(),
  25. EoIP: NewEoIPManager(),
  26. PPPServer: pppServer,
  27. AeroTUN: aerotun.NewManager(),
  28. }
  29. }
  30. // GetOverallStatus returns a summary of all active instances across all protocols.
  31. func (m *Manager) GetOverallStatus() OverallVPNStatus {
  32. pppoeList := m.PPPoE.List()
  33. wgIfaces := m.WireGuard.ListInterfaces()
  34. wgPeers := m.WireGuard.ListPeers("")
  35. pptpList := m.PPTP.List()
  36. l2tpList := m.L2TP.List()
  37. ipsecList := m.IPSec.List()
  38. eoipList := m.EoIP.List()
  39. activePPPoE := 0
  40. for _, p := range pppoeList {
  41. if p.Running {
  42. activePPPoE++
  43. }
  44. }
  45. activeWG := 0
  46. for _, w := range wgIfaces {
  47. if w.Running {
  48. activeWG++
  49. }
  50. }
  51. activePPTP := 0
  52. for _, p := range pptpList {
  53. if p.Running {
  54. activePPTP++
  55. }
  56. }
  57. activeL2TP := 0
  58. for _, l := range l2tpList {
  59. if l.Running {
  60. activeL2TP++
  61. }
  62. }
  63. activeIPSec := 0
  64. for _, i := range ipsecList {
  65. if i.Running {
  66. activeIPSec++
  67. }
  68. }
  69. activeEoIP := 0
  70. for _, e := range eoipList {
  71. if e.Running {
  72. activeEoIP++
  73. }
  74. }
  75. aeroStats := m.AeroTUN.GetSummaryStats()
  76. pppoeSrv := m.PPPServer.GetPPPoEServer()
  77. pptpSrv := m.PPPServer.GetPPTPServer()
  78. l2tpSrv := m.PPPServer.GetL2TPServer()
  79. ipsecSrv := m.PPPServer.GetIPSecServer()
  80. pppSessions := len(m.PPPServer.ListActiveSessions())
  81. totalActive := activePPPoE + activeWG + activePPTP + activeL2TP + activeIPSec + activeEoIP + aeroStats.ActiveTunnels + pppSessions
  82. return OverallVPNStatus{
  83. TotalPPPoE: len(pppoeList),
  84. ActivePPPoE: activePPPoE,
  85. TotalWireGuard: len(wgIfaces),
  86. ActiveWireGuard: activeWG,
  87. TotalWireGuardPeers: len(wgPeers),
  88. TotalPPTP: len(pptpList),
  89. ActivePPTP: activePPTP,
  90. TotalL2TP: len(l2tpList),
  91. ActiveL2TP: activeL2TP,
  92. TotalIPSec: len(ipsecList),
  93. ActiveIPSec: activeIPSec,
  94. TotalEoIP: len(eoipList),
  95. ActiveEoIP: activeEoIP,
  96. TotalAeroTUN: aeroStats.TotalTunnels,
  97. ActiveAeroTUN: aeroStats.ActiveTunnels,
  98. AeroTUNSavedBytes: aeroStats.TotalSavedBytes,
  99. AeroTUNRatio: aeroStats.AverageRatio,
  100. TotalPPPSessions: pppSessions,
  101. PPPoEServerRunning: pppoeSrv.Running,
  102. PPTPServerRunning: pptpSrv.Running,
  103. L2TPServerRunning: l2tpSrv.Running,
  104. IPSecServerRunning: ipsecSrv.Running,
  105. TotalActiveTunnels: totalActive,
  106. }
  107. }