mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-25 03:54:47 +03:00
fix(traffic): preserve client usage on scheduled inbound resets (#7136)
A client attached to several inbounds shares one usage counter. When any one of those inbounds reached its scheduled reset, the job zeroed the client's whole usage, across inbounds and nodes, although the client's own cycle resets on another day (#7135). Add a per-inbound "Keep client usage" switch, off by default: with it on, the scheduled reset clears only the inbound's own counters. The setting is pushed to nodes and read back from their snapshots. A node that does not advertise the capability is refused when the switch is saved, not later at push time, so an older node never ends up with a config it cannot apply.
This commit is contained in:
@@ -43,6 +43,12 @@ periodic **traffic reset** schedule: `never` (default), `hourly`, `daily`,
|
||||
|
||||
For `monthly` resets, select a day from 1 to 31. If the selected day does not
|
||||
exist in a shorter month, the reset runs on that month's last day.
|
||||
|
||||
Enable **Keep client usage** to reset only the inbound's counters on its schedule.
|
||||
Clients keep their accumulated usage until their own reset. With the switch off,
|
||||
the schedule also resets the attached clients' usage, including their usage on
|
||||
other inbounds. Upgrade the master and the nodes hosting the inbound before
|
||||
enabling this option on a managed inbound.
|
||||
</Step>
|
||||
|
||||
</Steps>
|
||||
|
||||
@@ -40,6 +40,10 @@ icon: ArrowDownToLine
|
||||
|
||||
选择 `monthly` 时,可以指定每月 1 至 31 日重置。如果当月没有指定日期,
|
||||
则在该月最后一天重置。
|
||||
|
||||
开启**保留客户端用量**后,定时任务仅清零入站计数,客户端继续按自己的周期累计用量。
|
||||
关闭时,定时任务也会清零关联客户端在所有入站上的累计用量。
|
||||
为纳管入站开启此选项前,请先升级主面板及承载该入站的节点。
|
||||
</Step>
|
||||
|
||||
</Steps>
|
||||
|
||||
@@ -3254,6 +3254,11 @@
|
||||
"minimum": 0,
|
||||
"type": "integer"
|
||||
},
|
||||
"preserveClientTraffic": {
|
||||
"description": "Older snapshots omit this field.\nKeep client usage during scheduled inbound resets",
|
||||
"nullable": true,
|
||||
"type": "boolean"
|
||||
},
|
||||
"protocol": {
|
||||
"enum": [
|
||||
"vmess",
|
||||
@@ -5421,6 +5426,7 @@
|
||||
"nodeId": null,
|
||||
"originNodeGuid": "",
|
||||
"port": 443,
|
||||
"preserveClientTraffic": null,
|
||||
"protocol": "vless",
|
||||
"remark": "VLESS-443",
|
||||
"settings": null,
|
||||
@@ -16993,6 +16999,7 @@
|
||||
"nodeId": null,
|
||||
"originNodeGuid": "",
|
||||
"port": 443,
|
||||
"preserveClientTraffic": null,
|
||||
"protocol": "vless",
|
||||
"remark": "VLESS-443",
|
||||
"settings": null,
|
||||
|
||||
@@ -3254,6 +3254,11 @@
|
||||
"minimum": 0,
|
||||
"type": "integer"
|
||||
},
|
||||
"preserveClientTraffic": {
|
||||
"description": "Older snapshots omit this field.\nKeep client usage during scheduled inbound resets",
|
||||
"nullable": true,
|
||||
"type": "boolean"
|
||||
},
|
||||
"protocol": {
|
||||
"enum": [
|
||||
"vmess",
|
||||
@@ -5421,6 +5426,7 @@
|
||||
"nodeId": null,
|
||||
"originNodeGuid": "",
|
||||
"port": 443,
|
||||
"preserveClientTraffic": null,
|
||||
"protocol": "vless",
|
||||
"remark": "VLESS-443",
|
||||
"settings": null,
|
||||
@@ -16993,6 +16999,7 @@
|
||||
"nodeId": null,
|
||||
"originNodeGuid": "",
|
||||
"port": 443,
|
||||
"preserveClientTraffic": null,
|
||||
"protocol": "vless",
|
||||
"remark": "VLESS-443",
|
||||
"settings": null,
|
||||
|
||||
@@ -841,6 +841,7 @@ export const EXAMPLES: Record<string, unknown> = {
|
||||
"nodeId": null,
|
||||
"originNodeGuid": "",
|
||||
"port": 443,
|
||||
"preserveClientTraffic": null,
|
||||
"protocol": "vless",
|
||||
"remark": "VLESS-443",
|
||||
"settings": null,
|
||||
|
||||
@@ -3228,6 +3228,11 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
"minimum": 0,
|
||||
"type": "integer"
|
||||
},
|
||||
"preserveClientTraffic": {
|
||||
"description": "Older snapshots omit this field.\nKeep client usage during scheduled inbound resets",
|
||||
"nullable": true,
|
||||
"type": "boolean"
|
||||
},
|
||||
"protocol": {
|
||||
"enum": [
|
||||
"vmess",
|
||||
|
||||
@@ -742,6 +742,7 @@ export interface Inbound {
|
||||
nodeId?: number | null;
|
||||
originNodeGuid?: string;
|
||||
port: number;
|
||||
preserveClientTraffic?: boolean | null;
|
||||
protocol: Protocol;
|
||||
remark: string;
|
||||
settings: unknown;
|
||||
|
||||
@@ -788,6 +788,7 @@ export const InboundSchema = z.object({
|
||||
nodeId: z.number().int().nullable().optional(),
|
||||
originNodeGuid: z.string().optional(),
|
||||
port: z.number().int().min(0).max(65535),
|
||||
preserveClientTraffic: z.boolean().nullable().optional(),
|
||||
protocol: z.enum(['vmess', 'vless', 'trojan', 'shadowsocks', 'wireguard', 'hysteria', 'http', 'mixed', 'tunnel', 'tun', 'mtproto', 'amneziawg', 'tuic', 'masque']),
|
||||
remark: z.string(),
|
||||
settings: z.unknown(),
|
||||
|
||||
@@ -55,6 +55,7 @@ export interface RawInboundRow {
|
||||
expiryTime?: number;
|
||||
trafficReset?: string;
|
||||
trafficResetDay?: number;
|
||||
preserveClientTraffic?: boolean;
|
||||
lastTrafficResetTime?: number;
|
||||
nodeId?: number | null;
|
||||
shareAddrStrategy?: string;
|
||||
@@ -77,6 +78,7 @@ export interface WireInboundPayload {
|
||||
expiryTime: number;
|
||||
trafficReset: TrafficReset;
|
||||
trafficResetDay: number;
|
||||
preserveClientTraffic: boolean;
|
||||
lastTrafficResetTime: number;
|
||||
listen: string;
|
||||
port: number;
|
||||
@@ -230,6 +232,7 @@ export function rawInboundToFormValues(row: RawInboundRow): InboundFormValues {
|
||||
total: row.total ?? 0,
|
||||
trafficReset: coerceTrafficReset(row.trafficReset),
|
||||
trafficResetDay: Math.min(31, Math.max(1, row.trafficResetDay ?? 1)),
|
||||
preserveClientTraffic: row.preserveClientTraffic ?? false,
|
||||
lastTrafficResetTime: row.lastTrafficResetTime ?? 0,
|
||||
nodeId: row.nodeId ?? null,
|
||||
shareAddrStrategy: coerceShareAddrStrategy(row.shareAddrStrategy),
|
||||
@@ -386,6 +389,7 @@ export function formValuesToWirePayload(
|
||||
expiryTime: values.expiryTime,
|
||||
trafficReset: values.trafficReset,
|
||||
trafficResetDay: values.trafficResetDay,
|
||||
preserveClientTraffic: values.preserveClientTraffic,
|
||||
lastTrafficResetTime: values.lastTrafficResetTime,
|
||||
listen: values.listen,
|
||||
port: values.port,
|
||||
|
||||
@@ -31,6 +31,7 @@ export type DBInboundInit = Partial<{
|
||||
expiryTime: number;
|
||||
trafficReset: string;
|
||||
trafficResetDay: number;
|
||||
preserveClientTraffic: boolean;
|
||||
lastTrafficResetTime: number;
|
||||
listen: string;
|
||||
port: number;
|
||||
@@ -80,6 +81,7 @@ export class DBInbound {
|
||||
expiryTime: number;
|
||||
trafficReset: string;
|
||||
trafficResetDay: number;
|
||||
preserveClientTraffic: boolean;
|
||||
lastTrafficResetTime: number;
|
||||
|
||||
listen: string;
|
||||
@@ -112,6 +114,7 @@ export class DBInbound {
|
||||
this.expiryTime = 0;
|
||||
this.trafficReset = 'never';
|
||||
this.trafficResetDay = 1;
|
||||
this.preserveClientTraffic = false;
|
||||
this.lastTrafficResetTime = 0;
|
||||
|
||||
this.listen = '';
|
||||
|
||||
@@ -834,6 +834,21 @@ export default function InboundFormModal({
|
||||
</FormField>
|
||||
)}
|
||||
|
||||
{trafficReset !== 'never' && (
|
||||
<FormField
|
||||
name="preserveClientTraffic"
|
||||
valueProp="checked"
|
||||
label={t('pages.inbounds.preserveClientTraffic')}
|
||||
tooltip={
|
||||
<span style={{ whiteSpace: 'pre-line' }}>
|
||||
{t('pages.inbounds.preserveClientTrafficHelp')}
|
||||
</span>
|
||||
}
|
||||
>
|
||||
<Switch />
|
||||
</FormField>
|
||||
)}
|
||||
|
||||
<Form.Item
|
||||
htmlFor={`${uid}-expiryTime`}
|
||||
label={t('pages.inbounds.expireDate')}
|
||||
|
||||
@@ -76,6 +76,7 @@ export const InboundDbFieldsSchema = z.object({
|
||||
total: z.number().int().min(0).default(0),
|
||||
trafficReset: TrafficResetSchema.default('never'),
|
||||
trafficResetDay: z.number().int().min(1).max(31).default(1),
|
||||
preserveClientTraffic: z.boolean().default(false),
|
||||
lastTrafficResetTime: z.number().int().default(0),
|
||||
nodeId: z.number().int().nullable().optional(),
|
||||
shareAddrStrategy: ShareAddrStrategySchema.default('node'),
|
||||
|
||||
@@ -271,7 +271,7 @@ describe('formValuesToWirePayload', () => {
|
||||
// the wire payload prunes empty arrays and collapses disabled sniffing
|
||||
// to `{ enabled: false }`. Top-level scalars and the protocol picker
|
||||
// must still survive the round trip without loss.
|
||||
const original = rawInboundToFormValues(vlessRow);
|
||||
const original = rawInboundToFormValues({ ...vlessRow, preserveClientTraffic: true });
|
||||
const payload = formValuesToWirePayload(original);
|
||||
const replay = rawInboundToFormValues({
|
||||
port: payload.port,
|
||||
@@ -289,6 +289,7 @@ describe('formValuesToWirePayload', () => {
|
||||
expiryTime: payload.expiryTime,
|
||||
trafficReset: payload.trafficReset,
|
||||
trafficResetDay: payload.trafficResetDay,
|
||||
preserveClientTraffic: payload.preserveClientTraffic,
|
||||
lastTrafficResetTime: payload.lastTrafficResetTime,
|
||||
nodeId: payload.nodeId ?? null,
|
||||
});
|
||||
@@ -299,6 +300,7 @@ describe('formValuesToWirePayload', () => {
|
||||
expect(replay.up).toBe(original.up);
|
||||
expect(replay.down).toBe(original.down);
|
||||
expect(replay.trafficResetDay).toBe(original.trafficResetDay);
|
||||
expect(replay.preserveClientTraffic).toBe(true);
|
||||
expect(replay.streamSettings).toEqual(original.streamSettings);
|
||||
});
|
||||
|
||||
@@ -307,6 +309,12 @@ describe('formValuesToWirePayload', () => {
|
||||
rawInboundToFormValues({ ...vlessRow, trafficResetDay: undefined }).trafficResetDay,
|
||||
).toBe(1);
|
||||
});
|
||||
|
||||
it('keeps the existing reset behavior for older inbounds', () => {
|
||||
const values = rawInboundToFormValues(vlessRow);
|
||||
expect(values.preserveClientTraffic).toBe(false);
|
||||
expect(formValuesToWirePayload(values).preserveClientTraffic).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('excludeFromSub', () => {
|
||||
|
||||
@@ -114,6 +114,14 @@ func migrateInboundExcludeFromSubColumn() error {
|
||||
return migrator.AddColumn(&model.Inbound{}, "ExcludeFromSub")
|
||||
}
|
||||
|
||||
func migrateInboundPreserveClientTrafficColumn(tx *gorm.DB) error {
|
||||
migrator := tx.Migrator()
|
||||
if !migrator.HasTable(&model.Inbound{}) || migrator.HasColumn(&model.Inbound{}, "preserve_client_traffic") {
|
||||
return nil
|
||||
}
|
||||
return migrator.AddColumn(&model.Inbound{}, "PreserveClientTraffic")
|
||||
}
|
||||
|
||||
func migrateClientKeepAliveRangeColumn() error {
|
||||
migrator := db.Migrator()
|
||||
if !migrator.HasTable(&model.ClientRecord{}) || migrator.HasColumn(&model.ClientRecord{}, "wg_keep_alive_range") {
|
||||
@@ -135,6 +143,9 @@ func initModels() error {
|
||||
if err := migrateInboundExcludeFromSubColumn(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := migrateInboundPreserveClientTrafficColumn(db); err != nil {
|
||||
return err
|
||||
}
|
||||
models := allModels()
|
||||
for _, mdl := range models {
|
||||
if IsPostgres() && postgresModelSettled(mdl) {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
|
||||
)
|
||||
|
||||
func TestMigrateInboundPreserveClientTrafficColumn(t *testing.T) {
|
||||
initMigrateDB(t)
|
||||
tx := GetDB().Begin()
|
||||
if tx.Error != nil {
|
||||
t.Fatal(tx.Error)
|
||||
}
|
||||
t.Cleanup(func() { tx.Rollback() })
|
||||
|
||||
// Recreate the previous schema in this transaction on SQLite or PostgreSQL.
|
||||
if err := tx.Exec("ALTER TABLE inbounds DROP COLUMN preserve_client_traffic").Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
const tag = "legacy-preserve-client-traffic"
|
||||
if err := tx.Exec("INSERT INTO inbounds (tag, up, down, traffic_reset, traffic_reset_day) VALUES (?, 30, 50, 'monthly', 20)", tag).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := migrateInboundPreserveClientTrafficColumn(tx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var stored model.Inbound
|
||||
if err := tx.Where("tag = ?", tag).First(&stored).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if stored.PreserveClientTraffic == nil || *stored.PreserveClientTraffic {
|
||||
t.Fatal("legacy inbound must have a non-null, false preserve_client_traffic")
|
||||
}
|
||||
if stored.Up != 30 || stored.Down != 50 || stored.TrafficReset != "monthly" || stored.TrafficResetDay != 20 {
|
||||
t.Fatalf("legacy inbound after migration: up=%d down=%d schedule=%s day=%d", stored.Up, stored.Down, stored.TrafficReset, stored.TrafficResetDay)
|
||||
}
|
||||
if err := tx.Model(&stored).Update("preserve_client_traffic", true).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := migrateInboundPreserveClientTrafficColumn(tx); err != nil {
|
||||
t.Fatalf("repeat migration: %v", err)
|
||||
}
|
||||
if err := tx.First(&stored, stored.Id).Error; err != nil || !stored.PreservesClientTraffic() {
|
||||
t.Fatalf("repeat migration lost the opt-in: preserve=%t, err=%v", stored.PreservesClientTraffic(), err)
|
||||
}
|
||||
}
|
||||
@@ -66,6 +66,9 @@ type Inbound struct {
|
||||
LastTrafficResetTime int64 `json:"lastTrafficResetTime" form:"lastTrafficResetTime" gorm:"default:0"` // Last traffic reset timestamp
|
||||
ClientStats []xray.ClientTraffic `gorm:"foreignKey:InboundId;references:Id" json:"clientStats" form:"clientStats"` // Client traffic statistics
|
||||
|
||||
// Older snapshots omit this field.
|
||||
PreserveClientTraffic *bool `json:"preserveClientTraffic,omitempty" form:"preserveClientTraffic" gorm:"not null;default:false"` // Keep client usage during scheduled inbound resets
|
||||
|
||||
// Xray configuration fields
|
||||
Listen string `json:"listen" form:"listen"`
|
||||
Port int `json:"port" form:"port" validate:"gte=0,lte=65535" example:"443"`
|
||||
@@ -189,6 +192,16 @@ type ApiToken struct {
|
||||
ExpiresAt int64 `json:"expiresAt" gorm:"not null;default:0"`
|
||||
}
|
||||
|
||||
// PreservesClientTraffic reports whether a scheduled inbound reset keeps client usage.
|
||||
func (i Inbound) PreservesClientTraffic() bool {
|
||||
return i.PreserveClientTraffic != nil && *i.PreserveClientTraffic
|
||||
}
|
||||
|
||||
// HasTrafficResetSchedule reports whether the inbound has periodic resets enabled.
|
||||
func (i *Inbound) HasTrafficResetSchedule() bool {
|
||||
return i.TrafficReset != "" && i.TrafficReset != "never"
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
@@ -26,8 +26,10 @@ const (
|
||||
// CapAmneziaWGKernel marks a node that honours an AmneziaWG inbound's
|
||||
// kernelMode; an older node drops the flag and serves it embedded.
|
||||
CapAmneziaWGKernel = "awg-kernel"
|
||||
// CapPreserveClientTraffic marks a node that supports inbound-only scheduled resets.
|
||||
CapPreserveClientTraffic = "preserve-client-traffic"
|
||||
// NodeCaps is the full CapsHeader value this build advertises.
|
||||
NodeCaps = CapZstd + "," + CapAmneziaWGKernel
|
||||
NodeCaps = CapZstd + "," + CapAmneziaWGKernel + "," + CapPreserveClientTraffic
|
||||
|
||||
// maxDecodeBytes bounds in-memory decompression to defuse a zstd bomb from
|
||||
// an (authenticated) node-API caller.
|
||||
|
||||
@@ -102,6 +102,56 @@ func recordFor(t *testing.T, email string) model.ClientRecord {
|
||||
return rec
|
||||
}
|
||||
|
||||
func TestPeriodicInboundResetPreservesSharedClientTraffic(t *testing.T) {
|
||||
initResetJobDB(t)
|
||||
const email = "shared@example.com"
|
||||
now := time.Now().UTC()
|
||||
seedClientOnCycle(t, 41120, seededClient{
|
||||
email: email, cycle: "monthly", day: now.Day()%28 + 1,
|
||||
recordEnable: true, quotaEnable: true, inboundCycle: "monthly",
|
||||
})
|
||||
|
||||
db := database.GetDB()
|
||||
rec := recordFor(t, email)
|
||||
inboundID := trafficFor(t, email).InboundId
|
||||
if err := db.Model(&model.Inbound{}).Where("id = ?", inboundID).Updates(map[string]any{
|
||||
"traffic_reset_day": now.Day(), "preserve_client_traffic": true, "up": 100, "down": 300,
|
||||
}).Error; err != nil {
|
||||
t.Fatalf("configure inbound reset: %v", err)
|
||||
}
|
||||
sibling := model.Inbound{
|
||||
UserId: 1, Enable: true, Port: 41121, Protocol: model.VLESS, Tag: "shared-sibling",
|
||||
TrafficReset: "never", Up: 400, Down: 400, Settings: `{"clients":[]}`,
|
||||
}
|
||||
if err := db.Create(&sibling).Error; err != nil {
|
||||
t.Fatalf("create sibling inbound: %v", err)
|
||||
}
|
||||
if err := db.Create(&model.ClientInbound{ClientId: rec.Id, InboundId: sibling.Id}).Error; err != nil {
|
||||
t.Fatalf("attach client to sibling inbound: %v", err)
|
||||
}
|
||||
|
||||
job := NewPeriodicTrafficResetJob("monthly", time.UTC)
|
||||
job.Run()
|
||||
var reset model.Inbound
|
||||
if err := db.First(&reset, inboundID).Error; err != nil {
|
||||
t.Fatalf("read scheduled inbound: %v", err)
|
||||
}
|
||||
if reset.Up != 0 || reset.Down != 0 {
|
||||
t.Fatalf("scheduled inbound usage = %d/%d, want 0/0", reset.Up, reset.Down)
|
||||
}
|
||||
if row := trafficFor(t, email); row.Up != 500 || row.Down != 700 {
|
||||
t.Fatalf("shared client usage = %d/%d, want 500/700", row.Up, row.Down)
|
||||
}
|
||||
|
||||
if err := db.Model(&rec).Update("traffic_reset_day", now.Day()).Error; err != nil {
|
||||
t.Fatalf("make client reset due: %v", err)
|
||||
}
|
||||
job.Run()
|
||||
if row := trafficFor(t, email); row.Up != 0 || row.Down != 0 {
|
||||
t.Fatalf("client usage after its own reset = %d/%d, want 0/0", row.Up, row.Down)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPeriodicTrafficResetClients(t *testing.T) {
|
||||
t.Run("resets a client on its own cycle inside a never-reset inbound", func(t *testing.T) {
|
||||
initResetJobDB(t)
|
||||
|
||||
@@ -97,12 +97,15 @@ func (j *PeriodicTrafficResetJob) resetInboundsOnSchedule() {
|
||||
needRestart.Store(true)
|
||||
}
|
||||
|
||||
nr, resetClientErr := j.clientService.ResetAllClientTraffics(&j.inboundService, inbound.Id)
|
||||
if resetClientErr != nil {
|
||||
logger.Warning("Failed to reset traffic for all users of inbound", inbound.Id, ":", resetClientErr)
|
||||
}
|
||||
if nr {
|
||||
needRestart.Store(true)
|
||||
var resetClientErr error
|
||||
if !inbound.PreservesClientTraffic() {
|
||||
nr, resetClientErr = j.clientService.ResetAllClientTraffics(&j.inboundService, inbound.Id)
|
||||
if resetClientErr != nil {
|
||||
logger.Warning("Failed to reset traffic for all users of inbound", inbound.Id, ":", resetClientErr)
|
||||
}
|
||||
if nr {
|
||||
needRestart.Store(true)
|
||||
}
|
||||
}
|
||||
|
||||
if resetInboundErr == nil && resetClientErr == nil {
|
||||
|
||||
@@ -180,6 +180,9 @@ func TestMasterNodeContract(t *testing.T) {
|
||||
run func() error
|
||||
check func(t *testing.T)
|
||||
}{
|
||||
{"CheckPreserveClientTraffic reads the node's reset capability", []string{"CheckPreserveClientTraffic"}, func() error {
|
||||
return master.CheckPreserveClientTraffic(ctx)
|
||||
}, nil},
|
||||
{"AddInbound creates the inbound with its clients", []string{"AddInbound"}, func() error {
|
||||
return master.AddInbound(ctx, masterInbound("added", true, "c0", "c1"))
|
||||
}, func(t *testing.T) {
|
||||
|
||||
@@ -93,10 +93,8 @@ type Remote struct {
|
||||
// seen, config pushes to this node are zstd-compressed. Old nodes never set
|
||||
// it, so they keep receiving plain bodies (mixed-version safe).
|
||||
supportsZstd bool
|
||||
// capsSeen tells a node that advertised no AmneziaWG kernel support apart
|
||||
// from one this Remote has not heard from yet.
|
||||
capsSeen bool
|
||||
supportsAWGKernel bool
|
||||
// nodeCaps is nil until the first response, even if that response advertises no capabilities.
|
||||
nodeCaps []string
|
||||
|
||||
// Per-node client honoring the TLS verify mode, built once and reused; a
|
||||
// node config change drops the cached Remote so the next one rebuilds it.
|
||||
@@ -140,8 +138,7 @@ func (r *Remote) recordCaps(h http.Header) {
|
||||
caps := strings.Split(h.Get(wirecodec.CapsHeader), ",")
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
r.capsSeen = true
|
||||
r.supportsAWGKernel = slices.Contains(caps, wirecodec.CapAmneziaWGKernel)
|
||||
r.nodeCaps = caps
|
||||
if slices.Contains(caps, wirecodec.CapZstd) {
|
||||
r.supportsZstd = true
|
||||
}
|
||||
@@ -157,23 +154,61 @@ func (r *Remote) requireAmneziaWGKernel(ctx context.Context, ib *model.Inbound)
|
||||
if err := json.Unmarshal([]byte(ib.Settings), &settings); err != nil || settings.Server == nil || !settings.Server.KernelMode {
|
||||
return nil
|
||||
}
|
||||
r.mu.RLock()
|
||||
seen := r.capsSeen
|
||||
r.mu.RUnlock()
|
||||
if !seen {
|
||||
if err := r.refreshRemoteIDs(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
supported, err := r.nodeSupports(ctx, wirecodec.CapAmneziaWGKernel)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
r.mu.RLock()
|
||||
supported := r.supportsAWGKernel
|
||||
r.mu.RUnlock()
|
||||
if !supported {
|
||||
return fmt.Errorf("node %s does not support AmneziaWG kernel mode; upgrade its panel or switch the inbound to the embedded datapath", r.node.Name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Remote) nodeSupports(ctx context.Context, capability string) (bool, error) {
|
||||
r.mu.RLock()
|
||||
caps := r.nodeCaps
|
||||
r.mu.RUnlock()
|
||||
if caps == nil {
|
||||
if err := r.refreshRemoteIDs(ctx); err != nil {
|
||||
return false, err
|
||||
}
|
||||
r.mu.RLock()
|
||||
caps = r.nodeCaps
|
||||
r.mu.RUnlock()
|
||||
}
|
||||
return slices.Contains(caps, capability), nil
|
||||
}
|
||||
|
||||
func (r *Remote) checkInboundCapabilities(ctx context.Context, ib *model.Inbound) error {
|
||||
if err := r.requireAmneziaWGKernel(ctx, ib); err != nil {
|
||||
return err
|
||||
}
|
||||
if !ib.PreservesClientTraffic() || !ib.HasTrafficResetSchedule() {
|
||||
return nil
|
||||
}
|
||||
return r.requirePreserveClientTraffic(ctx)
|
||||
}
|
||||
|
||||
// CheckPreserveClientTraffic probes the current node build before the master
|
||||
// commits an opt-in. An upgrade or rollback can make previously learned caps stale.
|
||||
func (r *Remote) CheckPreserveClientTraffic(ctx context.Context) error {
|
||||
if _, err := r.do(ctx, http.MethodGet, "panel/api/server/status", nil); err != nil {
|
||||
return fmt.Errorf("cannot verify support for keeping client usage on node %s: %w", r.node.Name, err)
|
||||
}
|
||||
return r.requirePreserveClientTraffic(ctx)
|
||||
}
|
||||
|
||||
func (r *Remote) requirePreserveClientTraffic(ctx context.Context) error {
|
||||
supported, err := r.nodeSupports(ctx, wirecodec.CapPreserveClientTraffic)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !supported {
|
||||
return fmt.Errorf("node %s does not support inbound-only scheduled traffic resets; upgrade its panel before enabling this option", r.node.Name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// httpClient lazily builds and caches the per-node client honoring the TLS
|
||||
// verify mode, so Remote ops don't fall back to system CA on skip/pin (#5264).
|
||||
func (r *Remote) httpClient() (*http.Client, error) {
|
||||
@@ -469,7 +504,7 @@ func (r *Remote) refreshRemoteIDs(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (r *Remote) AddInbound(ctx context.Context, ib *model.Inbound) error {
|
||||
if err := r.requireAmneziaWGKernel(ctx, ib); err != nil {
|
||||
if err := r.checkInboundCapabilities(ctx, ib); err != nil {
|
||||
return err
|
||||
}
|
||||
payload := wireInbound(ib, r.node.Id)
|
||||
@@ -508,7 +543,7 @@ func (r *Remote) UpdateInbound(ctx context.Context, oldIb, newIb *model.Inbound)
|
||||
if err != nil {
|
||||
return r.AddInbound(ctx, newIb)
|
||||
}
|
||||
if err := r.requireAmneziaWGKernel(ctx, newIb); err != nil {
|
||||
if err := r.checkInboundCapabilities(ctx, newIb); err != nil {
|
||||
return err
|
||||
}
|
||||
payload := wireInbound(newIb, r.node.Id)
|
||||
@@ -928,6 +963,7 @@ func wireInbound(ib *model.Inbound, remoteNodeID int) url.Values {
|
||||
if ib.TrafficResetDay > 0 {
|
||||
v.Set("trafficResetDay", strconv.Itoa(ib.TrafficResetDay))
|
||||
}
|
||||
v.Set("preserveClientTraffic", strconv.FormatBool(ib.PreservesClientTraffic()))
|
||||
return v
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/util/wirecodec"
|
||||
)
|
||||
|
||||
@@ -91,6 +92,34 @@ func TestRemoteSendsPlainWhenNoCap(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteRequiresSupportForInboundOnlyScheduledReset(t *testing.T) {
|
||||
for _, caps := range []string{wirecodec.CapZstd, wirecodec.NodeCaps} {
|
||||
t.Run(caps, func(t *testing.T) {
|
||||
var pushed bool
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set(wirecodec.CapsHeader, caps)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if r.Method == http.MethodPost {
|
||||
pushed = true
|
||||
}
|
||||
_, _ = w.Write([]byte(`{"success":true,"obj":[]}`))
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
r := NewRemote(nodeForPlainServer(t, srv, "verify", "tok"), nil)
|
||||
ib := &model.Inbound{TrafficReset: "monthly", PreserveClientTraffic: new(true)}
|
||||
err := r.AddInbound(context.Background(), ib)
|
||||
if caps == wirecodec.NodeCaps {
|
||||
if err != nil || !pushed {
|
||||
t.Fatalf("capable node: pushed = %v, error = %v", pushed, err)
|
||||
}
|
||||
} else if pushed || err == nil || !strings.Contains(err.Error(), "does not support inbound-only scheduled traffic resets") {
|
||||
t.Fatalf("older node: pushed = %v, error = %v", pushed, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestRemoteRefusesKernelAmneziaWGOnNodeWithoutCap: an older node drops the
|
||||
// kernelMode flag and silently runs the inbound on the embedded datapath.
|
||||
func TestRemoteRefusesKernelAmneziaWGOnNodeWithoutCap(t *testing.T) {
|
||||
|
||||
@@ -303,18 +303,24 @@ func TestIsNonEmptySlice(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWireInboundTrafficReset(t *testing.T) {
|
||||
with := wireInbound(&model.Inbound{TrafficReset: "monthly", TrafficResetDay: 15}, 0)
|
||||
with := wireInbound(&model.Inbound{TrafficReset: "monthly", TrafficResetDay: 15, PreserveClientTraffic: new(true)}, 0)
|
||||
if got := with.Get("trafficReset"); got != "monthly" {
|
||||
t.Fatalf("trafficReset = %q, want monthly", got)
|
||||
}
|
||||
if got := with.Get("trafficResetDay"); got != "15" {
|
||||
t.Fatalf("trafficResetDay = %q, want 15", got)
|
||||
}
|
||||
if got := with.Get("preserveClientTraffic"); got != "true" {
|
||||
t.Fatalf("preserveClientTraffic = %q, want true", got)
|
||||
}
|
||||
// Empty TrafficReset must be omitted entirely, not sent as an empty field.
|
||||
without := wireInbound(&model.Inbound{}, 0)
|
||||
if without.Has("trafficReset") {
|
||||
t.Fatalf("trafficReset must be omitted when empty, got %q", without.Get("trafficReset"))
|
||||
}
|
||||
if got := without.Get("preserveClientTraffic"); got != "false" {
|
||||
t.Fatalf("preserveClientTraffic = %q, want false", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWireInboundDefaultsShareAddressStrategy(t *testing.T) {
|
||||
|
||||
@@ -1353,6 +1353,9 @@ func (s *InboundService) AddInbound(inbound *model.Inbound) (*model.Inbound, boo
|
||||
return inbound, false, err
|
||||
}
|
||||
}
|
||||
if err := s.validateNodeTrafficReset(inbound, nil); err != nil {
|
||||
return inbound, false, err
|
||||
}
|
||||
inbound.SubSortIndex = normalizeSubSortIndex(inbound.SubSortIndex)
|
||||
if err := normalizeInboundShareAddressStrict(inbound); err != nil {
|
||||
return inbound, false, err
|
||||
@@ -2064,6 +2067,9 @@ func (s *InboundService) UpdateInbound(inbound *model.Inbound) (*model.Inbound,
|
||||
// Restore the stored NodeID before any host-scoped check so a node inbound
|
||||
// stays scoped to its own node (the payload's nodeId is unreliable, often absent).
|
||||
inbound.NodeID = oldInbound.NodeID
|
||||
if err := s.validateNodeTrafficReset(inbound, oldInbound); err != nil {
|
||||
return inbound, false, err
|
||||
}
|
||||
if err := normalizeVlessFallbacks(inbound); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
@@ -2244,6 +2250,10 @@ func (s *InboundService) UpdateInbound(inbound *model.Inbound) (*model.Inbound,
|
||||
oldInbound.ExpiryTime = inbound.ExpiryTime
|
||||
oldInbound.TrafficReset = inbound.TrafficReset
|
||||
oldInbound.TrafficResetDay = inbound.TrafficResetDay
|
||||
if inbound.PreserveClientTraffic != nil {
|
||||
oldInbound.PreserveClientTraffic = inbound.PreserveClientTraffic
|
||||
}
|
||||
inbound.PreserveClientTraffic = oldInbound.PreserveClientTraffic
|
||||
oldInbound.Listen = inbound.Listen
|
||||
oldInbound.Port = inbound.Port
|
||||
oldInbound.Protocol = inbound.Protocol
|
||||
|
||||
@@ -50,6 +50,36 @@ func (s *InboundService) runtimeFor(ib *model.Inbound) (runtime.Runtime, error)
|
||||
return mgr.RuntimeFor(ib.NodeID)
|
||||
}
|
||||
|
||||
// Check before the write transaction: a setting an older node cannot apply
|
||||
// would otherwise leave the whole node pending reconciliation.
|
||||
func (s *InboundService) validateNodeTrafficReset(ib, stored *model.Inbound) error {
|
||||
if ib.NodeID == nil {
|
||||
return nil
|
||||
}
|
||||
preserve := ib.PreserveClientTraffic
|
||||
if preserve == nil && stored != nil {
|
||||
preserve = stored.PreserveClientTraffic
|
||||
}
|
||||
if preserve == nil || !*preserve {
|
||||
return nil
|
||||
}
|
||||
// Only opting in or reactivating a dormant schedule needs a live node.
|
||||
if stored != nil && stored.PreservesClientTraffic() && (stored.HasTrafficResetSchedule() || !ib.HasTrafficResetSchedule()) {
|
||||
return nil
|
||||
}
|
||||
rt, err := s.runtimeFor(ib)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
remote, ok := rt.(*runtime.Remote)
|
||||
if !ok {
|
||||
return fmt.Errorf("cannot verify support for keeping client usage on node %d", *ib.NodeID)
|
||||
}
|
||||
ctx, cancel := nodePushContext()
|
||||
defer cancel()
|
||||
return remote.CheckPreserveClientTraffic(ctx)
|
||||
}
|
||||
|
||||
func (s *InboundService) nodePushPlan(ib *model.Inbound) (runtime.Runtime, bool, bool, error) {
|
||||
if ib.NodeID == nil {
|
||||
rt, err := s.runtimeFor(ib)
|
||||
@@ -440,7 +470,8 @@ func adoptedWireChanged(c, snapIb *model.Inbound, adoptedSettings string) bool {
|
||||
c.StreamSettings != snapIb.StreamSettings ||
|
||||
c.Sniffing != snapIb.Sniffing ||
|
||||
c.TrafficReset != snapIb.TrafficReset ||
|
||||
c.TrafficResetDay != normalizeTrafficResetDay(snapIb.TrafficResetDay)
|
||||
c.TrafficResetDay != normalizeTrafficResetDay(snapIb.TrafficResetDay) ||
|
||||
(snapIb.PreserveClientTraffic != nil && c.PreservesClientTraffic() != snapIb.PreservesClientTraffic())
|
||||
}
|
||||
|
||||
// adoptedWireInbound is the central inbound as it reads after adopting the
|
||||
@@ -462,6 +493,9 @@ func adoptedWireInbound(c, snapIb *model.Inbound, adoptedSettings string) *model
|
||||
a.Sniffing = snapIb.Sniffing
|
||||
a.TrafficReset = snapIb.TrafficReset
|
||||
a.TrafficResetDay = normalizeTrafficResetDay(snapIb.TrafficResetDay)
|
||||
if snapIb.PreserveClientTraffic != nil {
|
||||
a.PreserveClientTraffic = snapIb.PreserveClientTraffic
|
||||
}
|
||||
return &a
|
||||
}
|
||||
|
||||
@@ -836,6 +870,8 @@ func (s *InboundService) setRemoteTrafficLocked(nodeID int, snap *runtime.Traffi
|
||||
Down: snapIb.Down,
|
||||
ShareAddrStrategy: "node",
|
||||
DisableFlow: snapIb.DisableFlow,
|
||||
|
||||
PreserveClientTraffic: snapIb.PreserveClientTraffic,
|
||||
}
|
||||
if err := tx.Create(&newIb).Error; err != nil {
|
||||
logger.Warningf("setRemoteTraffic: create central inbound for tag %q failed: %v", snapIb.Tag, err)
|
||||
@@ -893,6 +929,10 @@ func (s *InboundService) setRemoteTrafficLocked(nodeID int, snap *runtime.Traffi
|
||||
updates["sniffing"] = snapIb.Sniffing
|
||||
updates["traffic_reset"] = snapIb.TrafficReset
|
||||
updates["traffic_reset_day"] = normalizeTrafficResetDay(snapIb.TrafficResetDay)
|
||||
if snapIb.PreserveClientTraffic != nil && c.PreservesClientTraffic() != snapIb.PreservesClientTraffic() {
|
||||
updates["preserve_client_traffic"] = snapIb.PreservesClientTraffic()
|
||||
structuralChange = true
|
||||
}
|
||||
updates["last_traffic_reset_time"] = snapIb.LastTrafficResetTime
|
||||
}
|
||||
if !inGrace || (snapIb.Up+snapIb.Down) <= (c.Up+c.Down) {
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
package service
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/database"
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/util/wirecodec"
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/web/runtime"
|
||||
)
|
||||
|
||||
func TestNormalizeTrafficResetDay(t *testing.T) {
|
||||
tests := map[int]int{
|
||||
@@ -16,3 +24,124 @@ func TestNormalizeTrafficResetDay(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateInboundPreserveClientTraffic(t *testing.T) {
|
||||
setupConflictDB(t)
|
||||
ib := makeInboundWithSubSortIndex("in-7006-tcp", 7006, 1)
|
||||
svc := &InboundService{}
|
||||
ib.PreserveClientTraffic = new(true)
|
||||
if _, _, err := svc.AddInbound(ib); err != nil {
|
||||
t.Fatalf("add inbound: %v", err)
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
value *bool
|
||||
want bool
|
||||
}{{nil, true}, {new(false), false}} {
|
||||
updated := *ib
|
||||
updated.PreserveClientTraffic = tc.value
|
||||
got, _, err := svc.UpdateInbound(&updated)
|
||||
if err != nil {
|
||||
t.Fatalf("update inbound: %v", err)
|
||||
}
|
||||
stored, err := svc.GetInbound(ib.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("read inbound: %v", err)
|
||||
}
|
||||
if got.PreservesClientTraffic() != tc.want || stored.PreservesClientTraffic() != tc.want {
|
||||
t.Fatalf("preserve client traffic: returned %t, stored %t, want %t", got.PreservesClientTraffic(), stored.PreservesClientTraffic(), tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetRemoteTrafficPreserveClientTraffic(t *testing.T) {
|
||||
setupConflictDB(t)
|
||||
const nodeID = 1
|
||||
svc := &InboundService{}
|
||||
for _, tc := range []struct {
|
||||
value *bool
|
||||
want bool
|
||||
}{{new(true), true}, {nil, true}, {new(false), false}} {
|
||||
snapshot := &runtime.TrafficSnapshot{Inbounds: []*model.Inbound{{
|
||||
Tag: "in-7007-tcp", Port: 7007, Protocol: model.VLESS, Enable: true,
|
||||
Settings: `{"clients":[]}`, TrafficReset: "monthly", PreserveClientTraffic: tc.value,
|
||||
}}}
|
||||
if _, err := svc.setRemoteTrafficLocked(nodeID, snapshot, false, false); err != nil {
|
||||
t.Fatalf("merge snapshot: %v", err)
|
||||
}
|
||||
var stored model.Inbound
|
||||
if err := database.GetDB().Where("node_id = ?", nodeID).First(&stored).Error; err != nil {
|
||||
t.Fatalf("read adopted inbound: %v", err)
|
||||
}
|
||||
if stored.PreservesClientTraffic() != tc.want {
|
||||
t.Fatalf("preserve client traffic = %t, want %t", stored.PreservesClientTraffic(), tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestManagedInboundChecksResetSupportBeforeSave(t *testing.T) {
|
||||
setupConflictDB(t)
|
||||
useTestRuntimeManager(t)
|
||||
node := newFakeNodeHTTP(t)
|
||||
existing := realNodeInbound(t, node, 7008, nil)
|
||||
db := database.GetDB()
|
||||
svc := &InboundService{}
|
||||
checkUnsupported := func(err error) {
|
||||
t.Helper()
|
||||
if err == nil || !strings.Contains(err.Error(), "does not support inbound-only scheduled traffic resets") {
|
||||
t.Fatalf("want node upgrade error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
add := makeInboundWithSubSortIndex("in-7009-tcp", 7009, 1)
|
||||
add.NodeID, add.TrafficReset, add.PreserveClientTraffic = existing.NodeID, "monthly", new(true)
|
||||
_, _, err := svc.AddInbound(add)
|
||||
checkUnsupported(err)
|
||||
var count int64
|
||||
if err := db.Model(&model.Inbound{}).Where("node_id = ?", *existing.NodeID).Count(&count).Error; err != nil || count != 1 {
|
||||
t.Fatalf("after refused add: inbound count=%d, err=%v", count, err)
|
||||
}
|
||||
|
||||
update := *existing
|
||||
update.NodeID = nil // the edit form may omit nodeId
|
||||
update.TrafficReset, update.PreserveClientTraffic = "monthly", new(true)
|
||||
_, _, err = svc.UpdateInbound(&update)
|
||||
checkUnsupported(err)
|
||||
stored, err := svc.GetInbound(existing.Id)
|
||||
if err != nil || stored.PreservesClientTraffic() || stored.TrafficReset != "never" {
|
||||
t.Fatalf("refused edit changed the inbound: %+v, err=%v", stored, err)
|
||||
}
|
||||
_, _, dirty, _, err := (&NodeService{}).NodeSyncState(*existing.NodeID)
|
||||
if err != nil || dirty {
|
||||
t.Fatalf("after refused saves: dirty=%t, err=%v", dirty, err)
|
||||
}
|
||||
|
||||
// A legacy edit can reactivate a dormant preference while omitting the flag.
|
||||
if err := db.Model(existing).Update("preserve_client_traffic", true).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
update.PreserveClientTraffic = nil
|
||||
_, _, err = svc.UpdateInbound(&update)
|
||||
checkUnsupported(err)
|
||||
|
||||
// A retry after upgrading the node uses its new capability immediately.
|
||||
node.mu.Lock()
|
||||
node.caps = wirecodec.CapPreserveClientTraffic
|
||||
node.mu.Unlock()
|
||||
if _, _, err := svc.UpdateInbound(&update); err != nil {
|
||||
t.Fatalf("edit on upgraded node: %v", err)
|
||||
}
|
||||
if _, _, err := svc.AddInbound(add); err != nil {
|
||||
t.Fatalf("add on upgraded node: %v", err)
|
||||
}
|
||||
stored, err = svc.GetInbound(add.Id)
|
||||
if err != nil || !stored.PreservesClientTraffic() {
|
||||
t.Fatalf("accepted add did not persist the opt-in: %+v, err=%v", stored, err)
|
||||
}
|
||||
|
||||
node.srv.Close()
|
||||
update.PreserveClientTraffic = new(false)
|
||||
if _, _, err := svc.UpdateInbound(&update); err != nil {
|
||||
t.Fatalf("turning the option off while the node is unreachable: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/database"
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/util/wirecodec"
|
||||
)
|
||||
|
||||
// fakeNodeHTTP emulates a node panel over real HTTP, so the master's Remote
|
||||
@@ -22,6 +23,7 @@ type fakeNodeHTTP struct {
|
||||
mu sync.Mutex
|
||||
tags map[string]int
|
||||
hits map[string]int
|
||||
caps string
|
||||
// hold makes every non-list request block until the master gives up.
|
||||
hold bool
|
||||
release chan struct{}
|
||||
@@ -32,6 +34,9 @@ func newFakeNodeHTTP(t *testing.T) *fakeNodeHTTP {
|
||||
f := &fakeNodeHTTP{tags: map[string]int{}, hits: map[string]int{}, release: make(chan struct{})}
|
||||
f.srv = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
f.mu.Lock()
|
||||
w.Header().Set(wirecodec.CapsHeader, f.caps)
|
||||
f.mu.Unlock()
|
||||
if strings.HasSuffix(r.URL.Path, "/inbounds/list") {
|
||||
f.mu.Lock()
|
||||
f.hits["list"]++
|
||||
|
||||
@@ -446,6 +446,8 @@
|
||||
"importInbound": "استيراد إدخال",
|
||||
"periodicTrafficResetTitle": "إعادة تعيين حركة المرور",
|
||||
"periodicTrafficResetDay": "يوم إعادة التعيين الشهري",
|
||||
"preserveClientTraffic": "الاحتفاظ باستهلاك العملاء",
|
||||
"preserveClientTrafficHelp": "عند تفعيل الخيار، تصفّر إعادة الضبط المجدولة عدّادات هذا الاتصال الوارد فقط. يحتفظ كل عميل باستهلاكه المتراكم عبر جميع العقد حتى موعد إعادة الضبط الخاص به.\n\nعند تعطيل الخيار، تصفّر إعادة الضبط المجدولة لهذا الاتصال الوارد أيضًا استهلاك العملاء المرتبطين به عبر جميع العقد.",
|
||||
"periodicTrafficReset": {
|
||||
"never": "أبداً",
|
||||
"daily": "يومياً",
|
||||
|
||||
@@ -447,6 +447,8 @@
|
||||
"importInbound": "Import an Inbound",
|
||||
"periodicTrafficResetTitle": "Traffic Reset",
|
||||
"periodicTrafficResetDay": "Monthly reset day",
|
||||
"preserveClientTraffic": "Keep client usage",
|
||||
"preserveClientTrafficHelp": "When enabled, a scheduled reset clears only this inbound’s traffic counters. Each client keeps its total usage across all nodes until its own scheduled reset.\n\nWhen disabled, this inbound’s scheduled reset also clears the usage its clients have accumulated across all nodes.",
|
||||
"periodicTrafficReset": {
|
||||
"never": "Never",
|
||||
"daily": "Daily",
|
||||
|
||||
@@ -446,6 +446,8 @@
|
||||
"importInbound": "Importar un entrante",
|
||||
"periodicTrafficResetTitle": "Reset de Tráfico",
|
||||
"periodicTrafficResetDay": "Día de reinicio mensual",
|
||||
"preserveClientTraffic": "Conservar el consumo de los clientes",
|
||||
"preserveClientTrafficHelp": "Si se activa, el reinicio programado solo pone a cero los contadores de esta entrada. Cada cliente conserva su consumo acumulado en todos los nodos hasta su propio reinicio programado.\n\nSi se desactiva, el reinicio programado de esta entrada también pone a cero el consumo acumulado de sus clientes en todos los nodos.",
|
||||
"periodicTrafficReset": {
|
||||
"never": "Nunca",
|
||||
"daily": "Diariamente",
|
||||
|
||||
@@ -446,6 +446,8 @@
|
||||
"importInbound": "افزودن یک ورودی",
|
||||
"periodicTrafficResetTitle": "بازنشانی ترافیک",
|
||||
"periodicTrafficResetDay": "روز بازنشانی ماهانه",
|
||||
"preserveClientTraffic": "حفظ مصرف کاربران",
|
||||
"preserveClientTrafficHelp": "اگر این گزینه روشن باشد، بازنشانی زمانبندیشده فقط شمارندههای ترافیک همین ورودی را صفر میکند. مجموع مصرف هر کاربر در همهٔ نودها تا زمان بازنشانی خود آن کاربر حفظ میشود.\n\nاگر این گزینه خاموش باشد، بازنشانی زمانبندیشدهٔ این ورودی مجموع مصرف کاربران متصل به آن را هم در همهٔ نودها صفر میکند.",
|
||||
"periodicTrafficReset": {
|
||||
"never": "هرگز",
|
||||
"daily": "روزانه",
|
||||
|
||||
@@ -446,6 +446,8 @@
|
||||
"importInbound": "Impor Masuk",
|
||||
"periodicTrafficResetTitle": "Reset Trafik Berkala",
|
||||
"periodicTrafficResetDay": "Hari reset bulanan",
|
||||
"preserveClientTraffic": "Pertahankan penggunaan klien",
|
||||
"preserveClientTrafficHelp": "Jika opsi ini aktif, hanya penghitung lalu lintas inbound ini yang direset sesuai jadwal. Total penggunaan setiap klien di semua node tetap tercatat hingga jadwal reset klien tersebut.\n\nJika opsi ini nonaktif, setiap kali inbound ini direset sesuai jadwal, total penggunaan klien yang terkait dengannya di semua node juga kembali ke nol.",
|
||||
"periodicTrafficReset": {
|
||||
"never": "Tidak Pernah",
|
||||
"daily": "Harian",
|
||||
|
||||
@@ -446,6 +446,8 @@
|
||||
"importInbound": "インバウンドルールをインポート",
|
||||
"periodicTrafficResetTitle": "トラフィックリセット",
|
||||
"periodicTrafficResetDay": "毎月のリセット日",
|
||||
"preserveClientTraffic": "クライアントの使用量を保持",
|
||||
"preserveClientTrafficHelp": "オンにすると、定期リセットでこのインバウンドの通信量だけがゼロになります。各クライアントの全ノードでの累計使用量は、そのクライアント自身の定期リセットまで保持されます。\n\nオフにすると、このインバウンドの定期リセット時に、紐付けられたクライアントの全ノードでの累計使用量もゼロになります。",
|
||||
"periodicTrafficReset": {
|
||||
"never": "なし",
|
||||
"daily": "毎日",
|
||||
|
||||
@@ -446,6 +446,8 @@
|
||||
"importInbound": "Importar um Inbound",
|
||||
"periodicTrafficResetTitle": "Reset de Tráfego",
|
||||
"periodicTrafficResetDay": "Dia da redefinição mensal",
|
||||
"preserveClientTraffic": "Manter o consumo dos clientes",
|
||||
"preserveClientTrafficHelp": "Com a opção ativada, a redefinição agendada zera apenas os contadores de tráfego desta entrada. Cada cliente mantém o consumo acumulado em todos os nós até a sua própria redefinição agendada.\n\nCom a opção desativada, a redefinição agendada desta entrada também zera o consumo acumulado em todos os nós pelos clientes vinculados a ela.",
|
||||
"periodicTrafficReset": {
|
||||
"never": "Nunca",
|
||||
"daily": "Diariamente",
|
||||
|
||||
@@ -447,6 +447,8 @@
|
||||
"importInbound": "Импорт подключений",
|
||||
"periodicTrafficResetTitle": "Сброс трафика",
|
||||
"periodicTrafficResetDay": "День ежемесячного сброса",
|
||||
"preserveClientTraffic": "Сохранять трафик клиентов",
|
||||
"preserveClientTrafficHelp": "Если опция включена, сброс по расписанию обнуляет только счётчики этого входящего подключения. Суммарный трафик каждого клиента по всем узлам сохраняется до сброса по расписанию самого клиента.\n\nЕсли опция выключена, при сбросе этого подключения по расписанию также обнуляется трафик, накопленный привязанными к нему клиентами на всех узлах.",
|
||||
"periodicTrafficReset": {
|
||||
"never": "Никогда",
|
||||
"daily": "Ежедневно",
|
||||
|
||||
@@ -447,6 +447,8 @@
|
||||
"importInbound": "Importovať vstup",
|
||||
"periodicTrafficResetTitle": "Nulovanie spotreby",
|
||||
"periodicTrafficResetDay": "Deň mesačného nulovania",
|
||||
"preserveClientTraffic": "Zachovať spotrebu klientov",
|
||||
"preserveClientTrafficHelp": "Keď je táto možnosť zapnutá, podľa plánu sa vynulujú iba počítadlá prenosu tohto vstupu. Celková spotreba každého klienta na všetkých serveroch sa zachová až do vynulovania podľa jeho vlastného plánu.\n\nAk je možnosť vypnutá, pri plánovanom vynulovaní tohto vstupu sa vynuluje aj celková spotreba jeho klientov na všetkých serveroch.",
|
||||
"periodicTrafficReset": {
|
||||
"never": "Nikdy",
|
||||
"daily": "Denne",
|
||||
|
||||
@@ -446,6 +446,8 @@
|
||||
"importInbound": "Gelen Bağlantı İçe Aktar",
|
||||
"periodicTrafficResetTitle": "Trafik Sıfırlama",
|
||||
"periodicTrafficResetDay": "Aylık sıfırlama günü",
|
||||
"preserveClientTraffic": "İstemci kullanımını koru",
|
||||
"preserveClientTrafficHelp": "Seçenek açıkken zamanlanmış sıfırlama yalnızca bu gelen bağlantının trafik sayaçlarını sıfırlar. Her istemcinin tüm düğümlerdeki toplam kullanımı, kendi sıfırlama zamanı gelene kadar korunur.\n\nSeçenek kapalıyken bu gelen bağlantının zamanlanmış sıfırlaması, bağlantıyla ilişkili istemcilerin tüm düğümlerdeki toplam kullanımını da sıfırlar.",
|
||||
"periodicTrafficReset": {
|
||||
"never": "Asla",
|
||||
"daily": "Günlük",
|
||||
|
||||
@@ -446,6 +446,8 @@
|
||||
"importInbound": "Імпортувати вхідний",
|
||||
"periodicTrafficResetTitle": "Скидання трафіку",
|
||||
"periodicTrafficResetDay": "День щомісячного скидання",
|
||||
"preserveClientTraffic": "Зберігати споживання клієнтів",
|
||||
"preserveClientTrafficHelp": "Якщо опцію ввімкнено, скидання за розкладом обнуляє лише лічильники цього вхідного підключення. Сумарний трафік кожного клієнта на всіх вузлах зберігається до скидання за власним розкладом клієнта.\n\nЯкщо опцію вимкнено, під час скидання цього підключення за розкладом також обнуляється трафік, який пов’язані з ним клієнти накопичили на всіх вузлах.",
|
||||
"periodicTrafficReset": {
|
||||
"never": "Ніколи",
|
||||
"daily": "Щодня",
|
||||
|
||||
@@ -446,6 +446,8 @@
|
||||
"importInbound": "Nhập inbound",
|
||||
"periodicTrafficResetTitle": "Đặt lại lưu lượng",
|
||||
"periodicTrafficResetDay": "Ngày đặt lại hàng tháng",
|
||||
"preserveClientTraffic": "Giữ mức sử dụng của máy khách",
|
||||
"preserveClientTrafficHelp": "Khi bật, thao tác đặt lại theo lịch chỉ đưa bộ đếm lưu lượng của inbound này về 0. Tổng lưu lượng của mỗi máy khách trên tất cả các node được giữ lại cho đến lần đặt lại theo lịch riêng của máy khách đó.\n\nKhi tắt, mỗi lần inbound này được đặt lại theo lịch, tổng lưu lượng mà mỗi máy khách liên kết với inbound đã sử dụng trên tất cả các node cũng trở về 0.",
|
||||
"periodicTrafficReset": {
|
||||
"never": "Không bao giờ",
|
||||
"daily": "Hàng ngày",
|
||||
|
||||
@@ -446,6 +446,8 @@
|
||||
"importInbound": "导入入站规则",
|
||||
"periodicTrafficResetTitle": "流量重置",
|
||||
"periodicTrafficResetDay": "每月重置日",
|
||||
"preserveClientTraffic": "保留客户端用量",
|
||||
"preserveClientTrafficHelp": "开启后,入站定时重置只清零本入站的流量。用户在所有节点上的累计用量会保留,按用户自己的周期重置。\n\n关闭后,本入站定时重置时,也会清零关联用户在所有节点上的累计用量。",
|
||||
"periodicTrafficReset": {
|
||||
"never": "从不",
|
||||
"daily": "每日",
|
||||
|
||||
@@ -446,6 +446,8 @@
|
||||
"importInbound": "匯入入站規則",
|
||||
"periodicTrafficResetTitle": "流量重置",
|
||||
"periodicTrafficResetDay": "每月重置日",
|
||||
"preserveClientTraffic": "保留客戶端用量",
|
||||
"preserveClientTrafficHelp": "開啟後,定時重設只會將此入站的流量歸零。每位使用者在所有節點的累計用量都會保留,並依自己的週期重設。\n\n關閉後,此入站定時重設時,也會將關聯使用者在所有節點的累計用量歸零。",
|
||||
"periodicTrafficReset": {
|
||||
"never": "從不",
|
||||
"daily": "每日",
|
||||
|
||||
Reference in New Issue
Block a user