mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-09-16 23:27:14 +00:00
fix(clients): let an explicit 0 actually disable PersistentKeepalive
Addresses review feedback on the previous commit. UpdateInboundClient carries a stored keepalive forward whenever the incoming one is zero, so the settings JSON and the running peer survive a metadata-only edit that omits the field. That was a 0 -> 0 no-op while no UI could set a nonzero value. Now that the client form can, the carry-forward became reachable in the other direction: a client created at the form's default of 25 could never be returned to 0, and the hint text shipped to all 13 locales -- "0 disables it" -- described something the backend silently refused. The save even reported success, because a settings blob that came back byte-identical skips the transaction entirely. The zero value cannot carry that distinction, so model.Client.KeepAlive becomes *int: nil means the field was never sent, &0 means "send no keepalives". The pointer survives the internal marshal in ClientService.Update, which is where an explicit 0 was being erased by omitempty before UpdateInboundClient ever saw it. ClientRecord.KeepAlive stays a plain int -- it is the stored column, where "unset" has no meaning -- and the conversions bridge the two. Two tests, both red before this change in the direction they cover: an explicit 0 must reach wg_keep_alive, and an update that omits the field must still leave a stored 25 alone. Also adds the output transform every other numeric field in the client form already has, so a cleared box sends 0 rather than null.
This commit is contained in:
@@ -1147,6 +1147,8 @@
|
||||
"type": "string"
|
||||
},
|
||||
"keepAlive": {
|
||||
"description": "Seconds between PersistentKeepalive packets; 0 sends none, omit to keep the stored value",
|
||||
"nullable": true,
|
||||
"type": "integer"
|
||||
},
|
||||
"limitIp": {
|
||||
|
||||
@@ -275,7 +275,7 @@ export const EXAMPLES: Record<string, unknown> = {
|
||||
"forwardedPorts": "",
|
||||
"group": "",
|
||||
"id": "",
|
||||
"keepAlive": 0,
|
||||
"keepAlive": null,
|
||||
"limitIp": 0,
|
||||
"password": "",
|
||||
"preSharedKey": "",
|
||||
|
||||
@@ -1121,6 +1121,8 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
"type": "string"
|
||||
},
|
||||
"keepAlive": {
|
||||
"description": "Seconds between PersistentKeepalive packets; 0 sends none, omit to keep the stored value",
|
||||
"nullable": true,
|
||||
"type": "integer"
|
||||
},
|
||||
"limitIp": {
|
||||
|
||||
@@ -271,7 +271,7 @@ export interface Client {
|
||||
forwardedPorts?: string;
|
||||
group?: string;
|
||||
id?: string;
|
||||
keepAlive?: number;
|
||||
keepAlive?: number | null;
|
||||
limitIp: number;
|
||||
password?: string;
|
||||
preSharedKey?: string;
|
||||
|
||||
@@ -292,7 +292,7 @@ export const ClientSchema = z.object({
|
||||
forwardedPorts: z.string().optional(),
|
||||
group: z.string().optional(),
|
||||
id: z.string().optional(),
|
||||
keepAlive: z.number().int().optional(),
|
||||
keepAlive: z.number().int().nullable().optional(),
|
||||
limitIp: z.number().int(),
|
||||
password: z.string().optional(),
|
||||
preSharedKey: z.string().optional(),
|
||||
|
||||
@@ -1279,6 +1279,7 @@ export default function ClientFormModal({
|
||||
name="wgKeepAlive"
|
||||
label={t('pages.clients.tunnelKeepAlive')}
|
||||
extra={t('pages.clients.tunnelKeepAliveHint')}
|
||||
transform={{ output: (v) => Number(v) || 0 }}
|
||||
>
|
||||
<InputNumber min={0} max={65535} style={{ width: '100%' }} />
|
||||
</FormField>
|
||||
|
||||
Reference in New Issue
Block a user