Commit Graph
2 Commits
  • xray-setting: pin api routing rule to index 0 on save (#4124)
    when the admin adds a custom outbound (eg vless cascade to a second
    server) and a routing rule sending all inbound traffic to it, that
    catch-all gets evaluated before the existing api->api rule, so the
    panel's internal stats inbound's traffic ends up on the cascade
    outbound. the grpc stats query then can't see anything, GetTraffic
    returns no inbound/user counters, and every client appears offline
    with zero traffic even though the actual proxy path works fine.
    
    before save, find the api rule and move it to the front of
    routing.rules. if it's missing entirely, insert a default. other
    rules keep their relative order.
    
    closes #4113. probably also fixes the long-standing #2818 where the
    documented workaround was "manually move the api rule to the top".
  • Fix blank Xray Settings page from wrapped xrayTemplateConfig (#4059) (#4069)
    `getXraySetting` builds its response as
    
        { "xraySetting": <db value>, "inboundTags": ..., "outboundTestUrl": ... }
    
    and embeds the raw DB value as the `xraySetting` field without
    checking whether the stored value already has that exact shape.
    
    The frontend pulls the textarea content from `result.xraySetting`
    and saves it back verbatim. If the DB ever ends up holding the
    response-shaped wrapper instead of a real xray config (older
    installs where this happened at least once, users who imported a
    copy-pasted response into the textarea, a botched migration, etc.),
    the next save nests another layer, the one after that nests a
    third, and the Vue-side JSON.parse of the resulting blob silently
    fails — the Xray Settings page goes blank.
    
    Fix both ends of the round-trip:
    
    * Add `service.UnwrapXrayTemplateConfig`. It peels off any number of
      `xraySetting`-keyed layers, leaving a real xray config behind.
      The check is conservative: if the outer object already contains
      any top-level xray key (`inbounds`, `outbounds`, `routing`, `api`,
      `dns`, `log`, `policy`, `stats`), it is returned unchanged, and
      there is a depth cap to avoid pathological inputs.
    
    * `SaveXraySetting` unwraps before validation so a round-tripped
      wrapper from an already-corrupted page can no longer re-poison
      the DB on save.
    
    * `getXraySetting` unwraps on read and, when it finds a wrapper,
      rewrites the DB with the corrected value. Existing broken installs
      heal themselves on the next visit to the page.
    
    Includes unit tests for the passthrough, single-wrap, multi-wrap,
    string-encoded-inner, and false-positive cases.
    
    Co-authored-by: pwnnex <eternxles@gmail.com>