manager.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package vpn
  2. type Manager struct {
  3. PPPoE *PPPoEManager
  4. WireGuard *WireGuardManager
  5. PPTP *PPTPManager
  6. L2TP *L2TPManager
  7. IPSec *IPSecManager
  8. }
  9. func NewManager() *Manager {
  10. return &Manager{
  11. PPPoE: NewPPPoEManager(),
  12. WireGuard: NewWireGuardManager(),
  13. PPTP: NewPPTPManager(),
  14. L2TP: NewL2TPManager(),
  15. IPSec: NewIPSecManager(),
  16. }
  17. }
  18. // GetOverallStatus returns a summary of all active instances across all protocols.
  19. func (m *Manager) GetOverallStatus() OverallVPNStatus {
  20. pppoeList := m.PPPoE.List()
  21. wgIfaces := m.WireGuard.ListInterfaces()
  22. wgPeers := m.WireGuard.ListPeers("")
  23. pptpList := m.PPTP.List()
  24. l2tpList := m.L2TP.List()
  25. ipsecList := m.IPSec.List()
  26. activePPPoE := 0
  27. for _, p := range pppoeList {
  28. if p.Running {
  29. activePPPoE++
  30. }
  31. }
  32. activeWG := 0
  33. for _, w := range wgIfaces {
  34. if w.Running {
  35. activeWG++
  36. }
  37. }
  38. activePPTP := 0
  39. for _, p := range pptpList {
  40. if p.Running {
  41. activePPTP++
  42. }
  43. }
  44. activeL2TP := 0
  45. for _, l := range l2tpList {
  46. if l.Running {
  47. activeL2TP++
  48. }
  49. }
  50. activeIPSec := 0
  51. for _, i := range ipsecList {
  52. if i.Running {
  53. activeIPSec++
  54. }
  55. }
  56. totalActive := activePPPoE + activeWG + activePPTP + activeL2TP + activeIPSec
  57. return OverallVPNStatus{
  58. TotalPPPoE: len(pppoeList),
  59. ActivePPPoE: activePPPoE,
  60. TotalWireGuard: len(wgIfaces),
  61. ActiveWireGuard: activeWG,
  62. TotalWireGuardPeers: len(wgPeers),
  63. TotalPPTP: len(pptpList),
  64. ActivePPTP: activePPTP,
  65. TotalL2TP: len(l2tpList),
  66. ActiveL2TP: activeL2TP,
  67. TotalIPSec: len(ipsecList),
  68. ActiveIPSec: activeIPSec,
  69. TotalActiveTunnels: totalActive,
  70. }
  71. }