mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-06-05 12:44:22 +00:00
refactor(api): emit JSON-text columns as nested objects
Inbound, ClientRecord, and InboundClientIps store settings / streamSettings / sniffing / reverse / ips as JSON-text in the DB. The API was passing that text through verbatim, so every consumer had to JSON.parse a string inside a string. Add MarshalJSON / UnmarshalJSON so the wire format is a real nested object, while still accepting the legacy escaped-string shape on write. Frontend dbinbound.js gets a matching coerceInboundJsonField helper for the same dual-shape read path, and inbound.js toJson stops emitting empty/placeholder fields (externalProxy [], sniffing destOverride when disabled, etc.) so the new normalised JSON stays terse. api-docs and the inbound-clone path are updated to the new shape. Controller route lists are regrouped so all GETs sit above POSTs. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
e500c04877
commit
1f2769cebf
8 changed files with 382 additions and 47 deletions
|
|
@ -2,8 +2,10 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/mhsanaei/3x-ui/v3/util/json_util"
|
||||
"github.com/mhsanaei/3x-ui/v3/xray"
|
||||
|
|
@ -83,6 +85,38 @@ type InboundClientIps struct {
|
|||
Ips string `json:"ips" form:"ips"`
|
||||
}
|
||||
|
||||
// MarshalJSON emits the Ips column as a real JSON array instead of an escaped
|
||||
// JSON-text string. Empty or unparseable storage renders as null so API
|
||||
// consumers don't have to special-case the legacy double-encoded shape.
|
||||
func (ic InboundClientIps) MarshalJSON() ([]byte, error) {
|
||||
type alias InboundClientIps
|
||||
return json.Marshal(struct {
|
||||
alias
|
||||
Ips json.RawMessage `json:"ips"`
|
||||
}{
|
||||
alias: alias(ic),
|
||||
Ips: jsonStringFieldToRaw(ic.Ips),
|
||||
})
|
||||
}
|
||||
|
||||
// UnmarshalJSON accepts ips as either a JSON array (modern shape) or a
|
||||
// JSON-encoded string (legacy shape), normalising back to the JSON-text the
|
||||
// column stores.
|
||||
func (ic *InboundClientIps) UnmarshalJSON(data []byte) error {
|
||||
type alias InboundClientIps
|
||||
aux := struct {
|
||||
*alias
|
||||
Ips json.RawMessage `json:"ips"`
|
||||
}{
|
||||
alias: (*alias)(ic),
|
||||
}
|
||||
if err := json.Unmarshal(data, &aux); err != nil {
|
||||
return err
|
||||
}
|
||||
ic.Ips = jsonStringFieldFromRaw(aux.Ips)
|
||||
return nil
|
||||
}
|
||||
|
||||
// HistoryOfSeeders tracks which database seeders have been executed to prevent re-running.
|
||||
type HistoryOfSeeders struct {
|
||||
Id int `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
|
|
@ -97,6 +131,74 @@ type ApiToken struct {
|
|||
CreatedAt int64 `json:"createdAt" gorm:"autoCreateTime"`
|
||||
}
|
||||
|
||||
// MarshalJSON emits settings, streamSettings, and sniffing as nested JSON
|
||||
// objects rather than escaped strings, so API consumers don't need to JSON.parse
|
||||
// a string inside a string. Empty fields render as null; fields whose stored
|
||||
// text isn't valid JSON fall back to a JSON-encoded string so no data is lost.
|
||||
func (i Inbound) MarshalJSON() ([]byte, error) {
|
||||
type alias Inbound
|
||||
return json.Marshal(struct {
|
||||
alias
|
||||
Settings json.RawMessage `json:"settings"`
|
||||
StreamSettings json.RawMessage `json:"streamSettings"`
|
||||
Sniffing json.RawMessage `json:"sniffing"`
|
||||
}{
|
||||
alias: alias(i),
|
||||
Settings: jsonStringFieldToRaw(i.Settings),
|
||||
StreamSettings: jsonStringFieldToRaw(i.StreamSettings),
|
||||
Sniffing: jsonStringFieldToRaw(i.Sniffing),
|
||||
})
|
||||
}
|
||||
|
||||
// UnmarshalJSON accepts settings, streamSettings, and sniffing as either a raw
|
||||
// JSON object/array (the modern shape MarshalJSON emits) or a JSON-encoded
|
||||
// string (the legacy shape). Either form is normalised back to the JSON-text
|
||||
// string the DB column stores.
|
||||
func (i *Inbound) UnmarshalJSON(data []byte) error {
|
||||
type alias Inbound
|
||||
aux := struct {
|
||||
*alias
|
||||
Settings json.RawMessage `json:"settings"`
|
||||
StreamSettings json.RawMessage `json:"streamSettings"`
|
||||
Sniffing json.RawMessage `json:"sniffing"`
|
||||
}{
|
||||
alias: (*alias)(i),
|
||||
}
|
||||
if err := json.Unmarshal(data, &aux); err != nil {
|
||||
return err
|
||||
}
|
||||
i.Settings = jsonStringFieldFromRaw(aux.Settings)
|
||||
i.StreamSettings = jsonStringFieldFromRaw(aux.StreamSettings)
|
||||
i.Sniffing = jsonStringFieldFromRaw(aux.Sniffing)
|
||||
return nil
|
||||
}
|
||||
|
||||
func jsonStringFieldToRaw(s string) json.RawMessage {
|
||||
trimmed := strings.TrimSpace(s)
|
||||
if trimmed == "" {
|
||||
return json.RawMessage("null")
|
||||
}
|
||||
if json.Valid([]byte(trimmed)) {
|
||||
return json.RawMessage(trimmed)
|
||||
}
|
||||
b, _ := json.Marshal(s)
|
||||
return b
|
||||
}
|
||||
|
||||
func jsonStringFieldFromRaw(r json.RawMessage) string {
|
||||
trimmed := bytes.TrimSpace(r)
|
||||
if len(trimmed) == 0 || bytes.Equal(trimmed, []byte("null")) {
|
||||
return ""
|
||||
}
|
||||
if trimmed[0] == '"' {
|
||||
var s string
|
||||
if err := json.Unmarshal(trimmed, &s); err == nil {
|
||||
return s
|
||||
}
|
||||
}
|
||||
return string(trimmed)
|
||||
}
|
||||
|
||||
// GenXrayInboundConfig generates an Xray inbound configuration from the Inbound model.
|
||||
func (i *Inbound) GenXrayInboundConfig() *xray.InboundConfig {
|
||||
listen := i.Listen
|
||||
|
|
@ -224,6 +326,37 @@ type ClientRecord struct {
|
|||
|
||||
func (ClientRecord) TableName() string { return "clients" }
|
||||
|
||||
// MarshalJSON emits the reverse column as a nested JSON object rather than an
|
||||
// escaped JSON-text string, matching the same convention Inbound uses for its
|
||||
// JSON-text columns. Empty storage renders as null.
|
||||
func (r ClientRecord) MarshalJSON() ([]byte, error) {
|
||||
type alias ClientRecord
|
||||
return json.Marshal(struct {
|
||||
alias
|
||||
Reverse json.RawMessage `json:"reverse"`
|
||||
}{
|
||||
alias: alias(r),
|
||||
Reverse: jsonStringFieldToRaw(r.Reverse),
|
||||
})
|
||||
}
|
||||
|
||||
// UnmarshalJSON accepts reverse as either a JSON object (modern shape) or a
|
||||
// JSON-encoded string (legacy shape).
|
||||
func (r *ClientRecord) UnmarshalJSON(data []byte) error {
|
||||
type alias ClientRecord
|
||||
aux := struct {
|
||||
*alias
|
||||
Reverse json.RawMessage `json:"reverse"`
|
||||
}{
|
||||
alias: (*alias)(r),
|
||||
}
|
||||
if err := json.Unmarshal(data, &aux); err != nil {
|
||||
return err
|
||||
}
|
||||
r.Reverse = jsonStringFieldFromRaw(aux.Reverse)
|
||||
return nil
|
||||
}
|
||||
|
||||
type ClientInbound struct {
|
||||
ClientId int `json:"clientId" gorm:"primaryKey;column:client_id;index"`
|
||||
InboundId int `json:"inboundId" gorm:"primaryKey;column:inbound_id;index"`
|
||||
|
|
|
|||
|
|
@ -1,6 +1,193 @@
|
|||
package model
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestInboundMarshalJSONNestsObjectFields(t *testing.T) {
|
||||
in := Inbound{
|
||||
Id: 7,
|
||||
Protocol: VLESS,
|
||||
Port: 443,
|
||||
Settings: `{"clients":[],"decryption":"none"}`,
|
||||
StreamSettings: `{"network":"tcp"}`,
|
||||
Sniffing: `{"enabled":true}`,
|
||||
}
|
||||
out, err := json.Marshal(in)
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal failed: %v", err)
|
||||
}
|
||||
var parsed map[string]any
|
||||
if err := json.Unmarshal(out, &parsed); err != nil {
|
||||
t.Fatalf("output is not valid JSON: %v", err)
|
||||
}
|
||||
for _, field := range []string{"settings", "streamSettings", "sniffing"} {
|
||||
if _, ok := parsed[field].(map[string]any); !ok {
|
||||
t.Errorf("expected %s to marshal as a JSON object, got %T", field, parsed[field])
|
||||
}
|
||||
}
|
||||
if strings.Contains(string(out), `"settings":"`) {
|
||||
t.Errorf("settings should not be emitted as a JSON string: %s", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInboundMarshalJSONEmptyFieldsBecomeNull(t *testing.T) {
|
||||
in := Inbound{Id: 1, Protocol: VLESS}
|
||||
out, err := json.Marshal(in)
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal failed: %v", err)
|
||||
}
|
||||
var parsed map[string]any
|
||||
if err := json.Unmarshal(out, &parsed); err != nil {
|
||||
t.Fatalf("output is not valid JSON: %v", err)
|
||||
}
|
||||
for _, field := range []string{"settings", "streamSettings", "sniffing"} {
|
||||
if parsed[field] != nil {
|
||||
t.Errorf("expected %s to be null, got %v", field, parsed[field])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestInboundUnmarshalJSONAcceptsBothShapes(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
body string
|
||||
}{
|
||||
{
|
||||
name: "nested objects (modern)",
|
||||
body: `{"id":1,"settings":{"clients":[],"decryption":"none"},"streamSettings":{"network":"tcp"},"sniffing":{"enabled":true}}`,
|
||||
},
|
||||
{
|
||||
name: "JSON-encoded strings (legacy)",
|
||||
body: `{"id":1,"settings":"{\"clients\":[],\"decryption\":\"none\"}","streamSettings":"{\"network\":\"tcp\"}","sniffing":"{\"enabled\":true}"}`,
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
var in Inbound
|
||||
if err := json.Unmarshal([]byte(tc.body), &in); err != nil {
|
||||
t.Fatalf("Unmarshal failed: %v", err)
|
||||
}
|
||||
if !strings.Contains(in.Settings, `"decryption":"none"`) {
|
||||
t.Errorf("Settings not normalised: %q", in.Settings)
|
||||
}
|
||||
if !strings.Contains(in.StreamSettings, `"network":"tcp"`) {
|
||||
t.Errorf("StreamSettings not normalised: %q", in.StreamSettings)
|
||||
}
|
||||
if !strings.Contains(in.Sniffing, `"enabled":true`) {
|
||||
t.Errorf("Sniffing not normalised: %q", in.Sniffing)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInboundMarshalJSONInvalidTextFallsBackToString(t *testing.T) {
|
||||
in := Inbound{Id: 1, Settings: "not json at all"}
|
||||
out, err := json.Marshal(in)
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal failed: %v", err)
|
||||
}
|
||||
if !strings.Contains(string(out), `"settings":"not json at all"`) {
|
||||
t.Errorf("expected invalid settings text to be wrapped as a JSON string, got %s", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientRecordMarshalJSONNestsReverse(t *testing.T) {
|
||||
rec := ClientRecord{Id: 1, Email: "alice@example.com", Reverse: `{"tag":"vless-in"}`}
|
||||
out, err := json.Marshal(rec)
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal failed: %v", err)
|
||||
}
|
||||
var parsed map[string]any
|
||||
if err := json.Unmarshal(out, &parsed); err != nil {
|
||||
t.Fatalf("output is not valid JSON: %v", err)
|
||||
}
|
||||
obj, ok := parsed["reverse"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("expected reverse to marshal as a JSON object, got %T", parsed["reverse"])
|
||||
}
|
||||
if obj["tag"] != "vless-in" {
|
||||
t.Errorf("expected tag to be preserved, got %v", obj["tag"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientRecordMarshalJSONEmptyReverseIsNull(t *testing.T) {
|
||||
rec := ClientRecord{Id: 1, Email: "alice@example.com"}
|
||||
out, err := json.Marshal(rec)
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal failed: %v", err)
|
||||
}
|
||||
var parsed map[string]any
|
||||
if err := json.Unmarshal(out, &parsed); err != nil {
|
||||
t.Fatalf("output is not valid JSON: %v", err)
|
||||
}
|
||||
if parsed["reverse"] != nil {
|
||||
t.Errorf("expected reverse to be null, got %v", parsed["reverse"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientRecordUnmarshalJSONAcceptsBothShapes(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
body string
|
||||
}{
|
||||
{name: "nested object", body: `{"id":1,"reverse":{"tag":"vless-in"}}`},
|
||||
{name: "legacy string", body: `{"id":1,"reverse":"{\"tag\":\"vless-in\"}"}`},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
var rec ClientRecord
|
||||
if err := json.Unmarshal([]byte(tc.body), &rec); err != nil {
|
||||
t.Fatalf("Unmarshal failed: %v", err)
|
||||
}
|
||||
if !strings.Contains(rec.Reverse, `"tag":"vless-in"`) {
|
||||
t.Errorf("Reverse not normalised: %q", rec.Reverse)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInboundClientIpsMarshalJSONNestsArray(t *testing.T) {
|
||||
row := InboundClientIps{Id: 1, ClientEmail: "alice@example.com", Ips: `[{"ip":"1.2.3.4","timestamp":1700000000}]`}
|
||||
out, err := json.Marshal(row)
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal failed: %v", err)
|
||||
}
|
||||
var parsed map[string]any
|
||||
if err := json.Unmarshal(out, &parsed); err != nil {
|
||||
t.Fatalf("output is not valid JSON: %v", err)
|
||||
}
|
||||
arr, ok := parsed["ips"].([]any)
|
||||
if !ok {
|
||||
t.Fatalf("expected ips to marshal as a JSON array, got %T", parsed["ips"])
|
||||
}
|
||||
if len(arr) != 1 {
|
||||
t.Errorf("expected 1 entry, got %d", len(arr))
|
||||
}
|
||||
}
|
||||
|
||||
func TestInboundClientIpsUnmarshalJSONAcceptsBothShapes(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
body string
|
||||
}{
|
||||
{name: "nested array", body: `{"id":1,"ips":[{"ip":"1.2.3.4","timestamp":1}]}`},
|
||||
{name: "legacy string", body: `{"id":1,"ips":"[{\"ip\":\"1.2.3.4\",\"timestamp\":1}]"}`},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
var row InboundClientIps
|
||||
if err := json.Unmarshal([]byte(tc.body), &row); err != nil {
|
||||
t.Fatalf("Unmarshal failed: %v", err)
|
||||
}
|
||||
if !strings.Contains(row.Ips, `"ip":"1.2.3.4"`) {
|
||||
t.Errorf("Ips not normalised: %q", row.Ips)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsHysteria(t *testing.T) {
|
||||
cases := []struct {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,19 @@ import dayjs from 'dayjs';
|
|||
import { ObjectUtil, NumberFormatter, SizeFormatter } from '@/utils';
|
||||
import { Inbound, Protocols } from './inbound.js';
|
||||
|
||||
export function coerceInboundJsonField(value) {
|
||||
if (value == null) return {};
|
||||
if (typeof value === 'object') return value;
|
||||
if (typeof value !== 'string') return {};
|
||||
const trimmed = value.trim();
|
||||
if (trimmed === '') return {};
|
||||
try {
|
||||
return JSON.parse(trimmed);
|
||||
} catch (_e) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
export class DBInbound {
|
||||
|
||||
constructor(data) {
|
||||
|
|
@ -110,20 +123,9 @@ export class DBInbound {
|
|||
return this._cachedInbound;
|
||||
}
|
||||
|
||||
let settings = {};
|
||||
if (!ObjectUtil.isEmpty(this.settings)) {
|
||||
settings = JSON.parse(this.settings);
|
||||
}
|
||||
|
||||
let streamSettings = {};
|
||||
if (!ObjectUtil.isEmpty(this.streamSettings)) {
|
||||
streamSettings = JSON.parse(this.streamSettings);
|
||||
}
|
||||
|
||||
let sniffing = {};
|
||||
if (!ObjectUtil.isEmpty(this.sniffing)) {
|
||||
sniffing = JSON.parse(this.sniffing);
|
||||
}
|
||||
const settings = coerceInboundJsonField(this.settings);
|
||||
const streamSettings = coerceInboundJsonField(this.streamSettings);
|
||||
const sniffing = coerceInboundJsonField(this.sniffing);
|
||||
|
||||
const config = {
|
||||
port: this.port,
|
||||
|
|
|
|||
|
|
@ -233,14 +233,20 @@ export class TcpStreamSettings extends XrayCommonClass {
|
|||
}
|
||||
|
||||
toJson() {
|
||||
return {
|
||||
acceptProxyProtocol: this.acceptProxyProtocol,
|
||||
header: {
|
||||
type: this.type,
|
||||
request: this.type === 'http' ? this.request.toJson() : undefined,
|
||||
response: this.type === 'http' ? this.response.toJson() : undefined,
|
||||
},
|
||||
};
|
||||
const json = {};
|
||||
if (this.acceptProxyProtocol) {
|
||||
json.acceptProxyProtocol = true;
|
||||
}
|
||||
if (this.type === 'http') {
|
||||
json.header = {
|
||||
type: 'http',
|
||||
request: this.request.toJson(),
|
||||
response: this.response.toJson(),
|
||||
};
|
||||
} else if (this.type && this.type !== 'none') {
|
||||
json.header = { type: this.type };
|
||||
}
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1466,7 +1472,9 @@ export class StreamSettings extends XrayCommonClass {
|
|||
return {
|
||||
network: network,
|
||||
security: this.security,
|
||||
externalProxy: this.externalProxy,
|
||||
externalProxy: Array.isArray(this.externalProxy) && this.externalProxy.length > 0
|
||||
? this.externalProxy
|
||||
: undefined,
|
||||
tlsSettings: this.isTls ? this.tls.toJson() : undefined,
|
||||
realitySettings: this.isReality ? this.reality.toJson() : undefined,
|
||||
tcpSettings: network === 'tcp' ? this.tcp.toJson() : undefined,
|
||||
|
|
@ -1515,11 +1523,14 @@ export class Sniffing extends XrayCommonClass {
|
|||
}
|
||||
|
||||
toJson() {
|
||||
if (!this.enabled) {
|
||||
return { enabled: false };
|
||||
}
|
||||
return {
|
||||
enabled: this.enabled,
|
||||
enabled: true,
|
||||
destOverride: this.destOverride,
|
||||
metadataOnly: this.metadataOnly,
|
||||
routeOnly: this.routeOnly,
|
||||
metadataOnly: this.metadataOnly || undefined,
|
||||
routeOnly: this.routeOnly || undefined,
|
||||
ipsExcluded: this.ipsExcluded.length > 0 ? this.ipsExcluded : undefined,
|
||||
domainsExcluded: this.domainsExcluded.length > 0 ? this.domainsExcluded : undefined,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -76,9 +76,9 @@ export const sections = [
|
|||
{
|
||||
method: 'GET',
|
||||
path: '/panel/api/inbounds/list',
|
||||
summary: 'List every inbound owned by the authenticated user, including each inbound’s clientStats traffic counters.',
|
||||
summary: 'List every inbound owned by the authenticated user, including each inbound’s clientStats traffic counters. settings, streamSettings, and sniffing are returned as nested JSON objects (no escaped strings); legacy callers that send them back as JSON-encoded strings are still accepted on write.',
|
||||
response:
|
||||
'{\n "success": true,\n "obj": [\n {\n "id": 1,\n "userId": 1,\n "up": 0,\n "down": 0,\n "total": 0,\n "remark": "VLESS-443",\n "enable": true,\n "expiryTime": 0,\n "listen": "",\n "port": 443,\n "protocol": "vless",\n "settings": "{\\"clients\\":[...]}",\n "streamSettings": "{...}",\n "tag": "inbound-443",\n "sniffing": "{...}",\n "clientStats": [...]\n }\n ]\n}',
|
||||
'{\n "success": true,\n "obj": [\n {\n "id": 1,\n "userId": 1,\n "up": 0,\n "down": 0,\n "total": 0,\n "remark": "VLESS-443",\n "enable": true,\n "expiryTime": 0,\n "listen": "",\n "port": 443,\n "protocol": "vless",\n "settings": {\n "clients": [],\n "decryption": "none"\n },\n "streamSettings": {\n "network": "tcp",\n "security": "reality",\n "realitySettings": { "show": false, "dest": "..." }\n },\n "tag": "inbound-443",\n "sniffing": {\n "enabled": true,\n "destOverride": ["http", "tls"]\n },\n "clientStats": []\n }\n ]\n}',
|
||||
},
|
||||
{
|
||||
method: 'GET',
|
||||
|
|
@ -91,9 +91,9 @@ export const sections = [
|
|||
{
|
||||
method: 'POST',
|
||||
path: '/panel/api/inbounds/add',
|
||||
summary: 'Create a new inbound. Send the full inbound payload (protocol, port, settings JSON, streamSettings JSON, sniffing JSON, remark, expiryTime, total, enable).',
|
||||
summary: 'Create a new inbound. Send the full inbound payload (protocol, port, settings, streamSettings, sniffing, remark, expiryTime, total, enable). settings, streamSettings, and sniffing may be sent as nested JSON objects (preferred) or as JSON-encoded strings (legacy).',
|
||||
body:
|
||||
'{\n "enable": true,\n "remark": "VLESS-443",\n "listen": "",\n "port": 443,\n "protocol": "vless",\n "expiryTime": 0,\n "total": 0,\n "settings": "{\\"clients\\":[{\\"id\\":\\"...\\",\\"email\\":\\"user1\\"}],\\"decryption\\":\\"none\\",\\"fallbacks\\":[]}",\n "streamSettings": "{\\"network\\":\\"tcp\\",\\"security\\":\\"reality\\",\\"realitySettings\\":{...}}",\n "sniffing": "{\\"enabled\\":true,\\"destOverride\\":[\\"http\\",\\"tls\\"]}"\n}',
|
||||
'{\n "enable": true,\n "remark": "VLESS-443",\n "listen": "",\n "port": 443,\n "protocol": "vless",\n "expiryTime": 0,\n "total": 0,\n "settings": {\n "clients": [{ "id": "...", "email": "user1" }],\n "decryption": "none",\n "fallbacks": []\n },\n "streamSettings": {\n "network": "tcp",\n "security": "reality",\n "realitySettings": { "show": false, "dest": "..." }\n },\n "sniffing": {\n "enabled": true,\n "destOverride": ["http", "tls"]\n }\n}',
|
||||
errorResponse:
|
||||
'{\n "success": false,\n "msg": "Port 443 is already in use"\n}',
|
||||
},
|
||||
|
|
@ -375,9 +375,9 @@ export const sections = [
|
|||
{
|
||||
method: 'GET',
|
||||
path: '/panel/api/clients/list',
|
||||
summary: 'List every client with its attached inbound IDs and traffic record.',
|
||||
summary: 'List every client with its attached inbound IDs and traffic record. The reverse field, if set, is returned as a nested JSON object (legacy JSON-encoded-string form is still accepted on write).',
|
||||
response:
|
||||
'{\n "success": true,\n "obj": [\n {\n "id": 1,\n "email": "alice@example.com",\n "subId": "abcd1234",\n "uuid": "...",\n "totalGB": 53687091200,\n "expiryTime": 1735689600000,\n "enable": true,\n "inboundIds": [3, 5],\n "traffic": { "up": 1024, "down": 4096, "enable": true }\n }\n ]\n}',
|
||||
'{\n "success": true,\n "obj": [\n {\n "id": 1,\n "email": "alice@example.com",\n "subId": "abcd1234",\n "uuid": "...",\n "totalGB": 53687091200,\n "expiryTime": 1735689600000,\n "enable": true,\n "reverse": null,\n "inboundIds": [3, 5],\n "traffic": { "up": 1024, "down": 4096, "enable": true }\n }\n ]\n}',
|
||||
},
|
||||
{
|
||||
method: 'GET',
|
||||
|
|
@ -543,7 +543,7 @@ export const sections = [
|
|||
method: 'GET',
|
||||
path: '/panel/api/nodes/list',
|
||||
summary: 'List every configured node with its connection details, health, and last heartbeat patch.',
|
||||
response: '{\n "success": true,\n "obj": [\n {\n "id": 1,\n "name": "de-fra-1",\n "scheme": "https",\n "host": "node1.example.com",\n "port": 2053,\n "status": "online",\n "cpu": 23.5,\n "mem": 45.1\n }\n ]\n}',
|
||||
response: '{\n "success": true,\n "obj": [\n {\n "id": 1,\n "name": "de-fra-1",\n "remark": "",\n "scheme": "https",\n "address": "node1.example.com",\n "port": 2053,\n "basePath": "/",\n "apiToken": "abcdef...",\n "enable": true,\n "allowPrivateAddress": false,\n "status": "online",\n "lastHeartbeat": 1700000000,\n "latencyMs": 42,\n "xrayVersion": "25.x.x",\n "panelVersion": "v3.x.x",\n "cpuPct": 23.5,\n "memPct": 45.1,\n "uptimeSecs": 86400,\n "lastError": "",\n "inboundCount": 5,\n "clientCount": 27,\n "onlineCount": 3,\n "depletedCount": 1,\n "createdAt": 1700000000,\n "updatedAt": 1700000000\n }\n ]\n}',
|
||||
},
|
||||
{
|
||||
method: 'GET',
|
||||
|
|
@ -556,9 +556,9 @@ export const sections = [
|
|||
{
|
||||
method: 'POST',
|
||||
path: '/panel/api/nodes/add',
|
||||
summary: 'Register a new remote node. Provide its URL, apiToken, and optional label/notes.',
|
||||
summary: 'Register a new remote node. Provide its URL, apiToken, and optional remark / allowPrivateAddress flag.',
|
||||
body:
|
||||
'{\n "name": "de-fra-1",\n "scheme": "https",\n "host": "node1.example.com",\n "port": 2053,\n "basePath": "/",\n "apiToken": "abcdef..."\n}',
|
||||
'{\n "name": "de-fra-1",\n "remark": "",\n "scheme": "https",\n "address": "node1.example.com",\n "port": 2053,\n "basePath": "/",\n "apiToken": "abcdef...",\n "enable": true,\n "allowPrivateAddress": false\n}',
|
||||
},
|
||||
{
|
||||
method: 'POST',
|
||||
|
|
@ -567,7 +567,7 @@ export const sections = [
|
|||
params: [
|
||||
{ name: 'id', in: 'path', type: 'number', desc: 'Node ID.' },
|
||||
],
|
||||
body: '{\n "name": "de-fra-1",\n "scheme": "https",\n "host": "node1.example.com",\n "port": 2053,\n "basePath": "/",\n "apiToken": "abcdef..."\n}',
|
||||
body: '{\n "name": "de-fra-1",\n "remark": "",\n "scheme": "https",\n "address": "node1.example.com",\n "port": 2053,\n "basePath": "/",\n "apiToken": "abcdef...",\n "enable": true,\n "allowPrivateAddress": false\n}',
|
||||
},
|
||||
{
|
||||
method: 'POST',
|
||||
|
|
@ -589,9 +589,9 @@ export const sections = [
|
|||
{
|
||||
method: 'POST',
|
||||
path: '/panel/api/nodes/test',
|
||||
summary: 'Probe a node without saving it. Uses the body as connection details and returns whether the handshake succeeds.',
|
||||
body: '{\n "scheme": "https",\n "host": "node1.example.com",\n "port": 2053,\n "basePath": "/",\n "apiToken": "abcdef..."\n}',
|
||||
response: '{\n "success": true,\n "obj": {\n "status": "online",\n "cpu": 12.5,\n "mem": 45.2\n }\n}',
|
||||
summary: 'Probe a node without saving it. Uses the body as connection details and returns the same heartbeat snapshot a registered node would have.',
|
||||
body: '{\n "scheme": "https",\n "address": "node1.example.com",\n "port": 2053,\n "basePath": "/",\n "apiToken": "abcdef..."\n}',
|
||||
response: '{\n "success": true,\n "obj": {\n "status": "online",\n "latencyMs": 42,\n "xrayVersion": "25.x.x",\n "panelVersion": "v3.x.x",\n "cpuPct": 12.5,\n "memPct": 45.2,\n "uptimeSecs": 86400,\n "error": ""\n }\n}',
|
||||
},
|
||||
{
|
||||
method: 'POST',
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import {
|
|||
|
||||
import { HttpUtil, SizeFormatter, RandomUtil } from '@/utils';
|
||||
import { Inbound } from '@/models/inbound.js';
|
||||
import { coerceInboundJsonField } from '@/models/dbinbound.js';
|
||||
import { theme as themeState, antdThemeConfig } from '@/composables/useTheme.js';
|
||||
import { useMediaQuery } from '@/composables/useMediaQuery.js';
|
||||
import AppSidebar from '@/components/AppSidebar.vue';
|
||||
|
|
@ -318,11 +319,11 @@ function confirmClone(dbInbound) {
|
|||
cancelText: 'Cancel',
|
||||
onOk: async () => {
|
||||
const baseInbound = dbInbound.toInbound();
|
||||
let clonedSettings = '';
|
||||
let clonedSettings;
|
||||
try {
|
||||
const raw = JSON.parse(dbInbound.settings || '{}');
|
||||
const raw = coerceInboundJsonField(dbInbound.settings);
|
||||
raw.clients = [];
|
||||
clonedSettings = JSON.stringify(raw, null, 2);
|
||||
clonedSettings = JSON.stringify(raw);
|
||||
} catch (_e) {
|
||||
clonedSettings = Inbound.Settings.getSettings(baseInbound.protocol).toString();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ func NewClientController(g *gin.RouterGroup) *ClientController {
|
|||
func (a *ClientController) initRouter(g *gin.RouterGroup) {
|
||||
g.GET("/list", a.list)
|
||||
g.GET("/get/:email", a.get)
|
||||
g.GET("/traffic/:email", a.getTrafficByEmail)
|
||||
g.GET("/subLinks/:subId", a.getSubLinks)
|
||||
g.GET("/links/:email", a.getClientLinks)
|
||||
|
||||
g.POST("/add", a.create)
|
||||
g.POST("/update/:email", a.update)
|
||||
g.POST("/del/:email", a.delete)
|
||||
|
|
@ -39,9 +43,6 @@ func (a *ClientController) initRouter(g *gin.RouterGroup) {
|
|||
g.POST("/clearIps/:email", a.clearIps)
|
||||
g.POST("/onlines", a.onlines)
|
||||
g.POST("/lastOnline", a.lastOnline)
|
||||
g.GET("/traffic/:email", a.getTrafficByEmail)
|
||||
g.GET("/subLinks/:subId", a.getSubLinks)
|
||||
g.GET("/links/:email", a.getClientLinks)
|
||||
}
|
||||
|
||||
func (a *ClientController) list(c *gin.Context) {
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ func (a *InboundController) initRouter(g *gin.RouterGroup) {
|
|||
|
||||
g.GET("/list", a.getInbounds)
|
||||
g.GET("/get/:id", a.getInbound)
|
||||
g.GET("/:id/fallbackChildren", a.getFallbackChildren)
|
||||
|
||||
g.POST("/add", a.addInbound)
|
||||
g.POST("/del/:id", a.delInbound)
|
||||
|
|
@ -70,7 +71,6 @@ func (a *InboundController) initRouter(g *gin.RouterGroup) {
|
|||
g.POST("/:id/resetTraffic", a.resetInboundTraffic)
|
||||
g.POST("/resetAllTraffics", a.resetAllTraffics)
|
||||
g.POST("/import", a.importInbound)
|
||||
g.GET("/:id/fallbackChildren", a.getFallbackChildren)
|
||||
g.POST("/:id/fallbackChildren", a.setFallbackChildren)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue