Fix quota

This commit is contained in:
2026-07-20 00:00:39 -03:00
parent 5f43698e2b
commit 9bbd950b66
17 changed files with 729 additions and 157 deletions
+11 -5
View File
@@ -106,9 +106,9 @@ func (s *Store) ResetSSHUserTraffic(ctx context.Context, username string) error
return nil
}
_, err := s.db.ExecContext(ctx, `
UPDATE ssh_users
SET total_uplink_bytes = 0, total_downlink_bytes = 0
WHERE username = $1`, username)
UPDATE ssh_users
SET total_uplink_bytes = 0, total_downlink_bytes = 0
WHERE username = $1`, username)
return err
}
@@ -353,9 +353,15 @@ func validateQuotaConfig(quotaBytes int64, action string, throttleMbps int) erro
if quotaBytes < 0 {
return fmt.Errorf("data_quota_bytes must be non-negative")
}
action = normalizeQuotaAction(action)
if quotaBytes > 0 && action == quotaActionThrottle && throttleMbps < 0 {
rawAction := strings.ToLower(strings.TrimSpace(action))
if rawAction != "" && rawAction != quotaActionBlock && rawAction != quotaActionThrottle {
return fmt.Errorf("quota_action must be block or throttle")
}
if throttleMbps < 0 {
return fmt.Errorf("quota_throttle_mbps must be non-negative")
}
if throttleMbps > 1000000 {
return fmt.Errorf("quota_throttle_mbps must not exceed 1000000")
}
return nil
}