manager.go 2.5 KB

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