manager.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package vpn
  2. import "debtik/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. VXLAN *VXLANManager
  11. PPPServer *PPPServerManager
  12. AeroTUN *aerotun.Manager
  13. }
  14. func NewManager() *Manager {
  15. pppServer := NewPPPServerManager()
  16. l2tpMgr := NewL2TPManager()
  17. l2tpMgr.SetPPPServer(pppServer)
  18. pptpMgr := NewPPTPManager()
  19. pptpMgr.SetPPPServer(pppServer)
  20. return &Manager{
  21. PPPoE: NewPPPoEManager(),
  22. WireGuard: NewWireGuardManager(),
  23. PPTP: pptpMgr,
  24. L2TP: l2tpMgr,
  25. IPSec: NewIPSecManager(),
  26. EoIP: NewEoIPManager(),
  27. VXLAN: NewVXLANManager(),
  28. PPPServer: pppServer,
  29. AeroTUN: aerotun.NewManager(),
  30. }
  31. }
  32. // GetOverallStatus returns a summary of all active instances across all protocols.
  33. func (m *Manager) GetOverallStatus() OverallVPNStatus {
  34. pppoeList := m.PPPoE.List()
  35. wgIfaces := m.WireGuard.ListInterfaces()
  36. wgPeers := m.WireGuard.ListPeers("")
  37. pptpList := m.PPTP.List()
  38. l2tpList := m.L2TP.List()
  39. ipsecList := m.IPSec.List()
  40. eoipList := m.EoIP.List()
  41. vxlanList := m.VXLAN.List()
  42. activePPPoE := 0
  43. for _, p := range pppoeList {
  44. if p.Running {
  45. activePPPoE++
  46. }
  47. }
  48. activeWG := 0
  49. for _, w := range wgIfaces {
  50. if w.Running {
  51. activeWG++
  52. }
  53. }
  54. activePPTP := 0
  55. for _, p := range pptpList {
  56. if p.Running {
  57. activePPTP++
  58. }
  59. }
  60. activeL2TP := 0
  61. for _, l := range l2tpList {
  62. if l.Running {
  63. activeL2TP++
  64. }
  65. }
  66. activeIPSec := 0
  67. for _, i := range ipsecList {
  68. if i.Running {
  69. activeIPSec++
  70. }
  71. }
  72. activeEoIP := 0
  73. for _, e := range eoipList {
  74. if e.Running {
  75. activeEoIP++
  76. }
  77. }
  78. activeVXLAN := 0
  79. for _, v := range vxlanList {
  80. if v.Running {
  81. activeVXLAN++
  82. }
  83. }
  84. aeroStats := m.AeroTUN.GetSummaryStats()
  85. pppoeSrv := m.PPPServer.GetPPPoEServer()
  86. pptpSrv := m.PPPServer.GetPPTPServer()
  87. l2tpSrv := m.PPPServer.GetL2TPServer()
  88. ipsecSrv := m.PPPServer.GetIPSecServer()
  89. pppSessions := len(m.PPPServer.ListActiveSessions())
  90. totalActive := activePPPoE + activeWG + activePPTP + activeL2TP + activeIPSec + activeEoIP + activeVXLAN + aeroStats.ActiveTunnels + pppSessions
  91. return OverallVPNStatus{
  92. TotalPPPoE: len(pppoeList),
  93. ActivePPPoE: activePPPoE,
  94. TotalWireGuard: len(wgIfaces),
  95. ActiveWireGuard: activeWG,
  96. TotalWireGuardPeers: len(wgPeers),
  97. TotalPPTP: len(pptpList),
  98. ActivePPTP: activePPTP,
  99. TotalL2TP: len(l2tpList),
  100. ActiveL2TP: activeL2TP,
  101. TotalIPSec: len(ipsecList),
  102. ActiveIPSec: activeIPSec,
  103. TotalEoIP: len(eoipList),
  104. ActiveEoIP: activeEoIP,
  105. TotalVXLAN: len(vxlanList),
  106. ActiveVXLAN: activeVXLAN,
  107. TotalAeroTUN: aeroStats.TotalTunnels,
  108. ActiveAeroTUN: aeroStats.ActiveTunnels,
  109. AeroTUNSavedBytes: aeroStats.TotalSavedBytes,
  110. AeroTUNRatio: aeroStats.AverageRatio,
  111. TotalPPPSessions: pppSessions,
  112. PPPoEServerRunning: pppoeSrv.Running,
  113. PPTPServerRunning: pptpSrv.Running,
  114. L2TPServerRunning: l2tpSrv.Running,
  115. IPSecServerRunning: ipsecSrv.Running,
  116. TotalActiveTunnels: totalActive,
  117. }
  118. }
  119. // RenameInterface updates VPN client interface references when an interface is renamed.
  120. func (m *Manager) RenameInterface(oldName, newName string) {
  121. if m.PPPoE != nil {
  122. m.PPPoE.RenameInterface(oldName, newName)
  123. }
  124. if m.VXLAN != nil {
  125. m.VXLAN.RenameInterface(oldName, newName)
  126. }
  127. }