manager.go 2.4 KB

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