mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-25 07:15:01 +03:00
feat(amneziawg): support persistent keepalive ranges (#6881)
AmneziaWG clients accept a randomised PersistentKeepalive range such as 15-25, which makes keepalive timing harder to fingerprint; the panel only stored a single number. A client's keepalive may now be a range, validated the way AmneziaWG parses it. The downloadable .conf and vpn:// profile carry the range, Clash/Mihomo output gets its lower bound, and plain WireGuard stays scalar-only. The range lives in an additive wg_keep_alive_range column, so the integer column and an older panel binary keep working after a rollback.
This commit is contained in:
@@ -1338,6 +1338,9 @@ func (s *InboundService) AddInbound(inbound *model.Inbound) (*model.Inbound, boo
|
||||
if err := validateClientsRenewal(clients); err != nil {
|
||||
return inbound, false, err
|
||||
}
|
||||
if err := validateClientsKeepAlive(inbound.Protocol, clients); err != nil {
|
||||
return inbound, false, err
|
||||
}
|
||||
for _, traffic := range inbound.ClientStats {
|
||||
if err := validateClientRenewal(model.Client{Reset: traffic.Reset, ResetDay: traffic.ResetDay, ResetWeekday: traffic.ResetWeekday}); err != nil {
|
||||
return inbound, false, err
|
||||
@@ -1912,7 +1915,7 @@ func (s *InboundService) SetInboundEnable(id int, enable bool) (bool, error) {
|
||||
return needRestart, nil
|
||||
}
|
||||
|
||||
func (s *InboundService) validateUpdatedInboundClients(inbound *model.Inbound) error {
|
||||
func (s *InboundService) validateUpdatedInboundClients(inbound, existing *model.Inbound) error {
|
||||
clients, err := s.GetClients(inbound)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1920,6 +1923,16 @@ func (s *InboundService) validateUpdatedInboundClients(inbound *model.Inbound) e
|
||||
if err := validateClientsRenewal(clients); err != nil {
|
||||
return err
|
||||
}
|
||||
var existingClients []model.Client
|
||||
if inbound.Protocol == existing.Protocol {
|
||||
existingClients, err = s.GetClients(existing)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := validateClientsKeepAliveAgainstExisting(inbound.Protocol, clients, existingClients); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, client := range clients {
|
||||
switch inbound.Protocol {
|
||||
case model.Hysteria:
|
||||
@@ -2038,7 +2051,7 @@ func (s *InboundService) UpdateInbound(inbound *model.Inbound) (*model.Inbound,
|
||||
inbound.Enable = stored.Enable
|
||||
}
|
||||
// On the clients actually saved: a protocol switch keeps the stored ones.
|
||||
if err := s.validateUpdatedInboundClients(inbound); err != nil {
|
||||
if err := s.validateUpdatedInboundClients(inbound, stored); err != nil {
|
||||
return err
|
||||
}
|
||||
conflict, cErr := checkPortConflictTx(tx, inbound, inbound.Id)
|
||||
|
||||
Reference in New Issue
Block a user