Commit Graph
5 Commits
  • feat(sub): add per-client subscription HWID limits (#5802)
    * feat(sub): add per-client subscription HWID limits
    
    * fix(sub): address HWID review on shared subId and bulk create
    
    * fix(sub): store HWID devices by sub_id and drop anchor client workaround
    
    * fix(sub): restore UA auto-detect and HTML page routing in subs()
    
    The cherry-pick of the HWID gate onto main's refactored SUBController
    had dropped main's UA-based format auto-detection and sub-page handling
    from subs(). Restore those branches, slotting enforceHwid after the
    HTML page and before format detection so the gate only applies to
    machine-readable subscription bodies.
    
    Also adapt tests to main's options-struct constructor and to the
    ClientService.Update signature extended with limitHwid.
    
    * fix(frontend): drop axios from HttpUtil.delete
    
    The bulk-delete rework's committed version still referenced axios,
    which this file no longer imports, breaking typecheck in CI. Use the
    httpRequest wrapper like the other verbs.
    
    ---------
    
    Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
  • fix(clients): stop a stale IP row from blocking a client edit
    Saving a client walks every inbound it is attached to and calls
    UpdateInboundClient, which re-keys the client's email in inbound_client_ips
    to the spelling in the edited settings. The email match is EqualFold, so when
    an inbound's settings JSON drifted in case from the client record the panel
    issues a case-only rename of the tracking row.
    
    inbound_client_ips.client_email is unique and case-sensitive, and the
    IP-limit job keys its rows on whatever casing Xray reports, so both spellings
    can already be present. The rename then aborts the whole edit with
    "duplicate key value violates unique constraint
    uni_inbound_client_ips_client_email" — the client could not be saved at all,
    including when only adding an inbound to it.
    
    The caller only renames onto an identity no live client holds, so a row on
    the target email is stale IP tracking: delete it before renaming. The blob is
    rebuilt by the next scan anyway.
  • fix(clients): keep a client editable when its subId is already shared (#6065)
    The subId collision check in Update ran on every save, unlike the email
    check above it. Because Update defaults an omitted subId to the stored
    one, any client already sharing a subId was rejected on every later edit
    -- even a pure totalGB or expiry change that never mentions subId.
    
    Gate the check on an actual change. Pre-existing duplicates are reachable
    because SyncInbound has no such check, and 88a36773 meant to leave them
    untouched. Editing a client onto another subscriber's subId is still
    rejected, so the typo guard is intact.
  • fix(clients): allow case-only email updates without duplicates (#6050)
    Case-only email edits (test → Test) skipped the ClientRecord rename
    because the gate used strings.EqualFold. SyncInbound then failed its
    case-sensitive lookup and inserted a second row; the later fallback
    rename hit UNIQUE constraint failed: clients.email.
    
    Rename on any byte-level email difference so the same client is updated
    in place.
    
    Fixes #5951
  • fix(clients): rename client record atomically with inbound settings
    Update committed an email rename to the clients table with a standalone
    write before the per-inbound loop rewrote each inbound's settings JSON.
    In that window the record held the new email while the JSON still held
    the old one, so any concurrent SyncInbound (traffic poll, another edit)
    found no record for the old email and inserted a duplicate seeded from
    the stale JSON - carrying the same subId, which then failed every later
    edit with "Duplicate subId". The subId collision check also ran after
    that write, so even a rejected update permanently renamed the email.
    
    Move the rename inside UpdateInboundClient's serialized transaction,
    next to the settings save and SyncInbound, so no other writer can see
    one without the other; skip it when a record already owns the target
    email (the merge case). Update now only runs collision checks before
    the loop and falls back to a direct rename solely for records with no
    attached inbound. This covers both the REST API and the web UI editor,
    which share this path.
    
    Closes #5870