From 2c50eea4924de8bfb5501d377665ffc2991eeb21 Mon Sep 17 00:00:00 2001 From: codex Date: Wed, 4 Nov 2026 15:10:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=81=E8=AE=B8=E4=BF=9D=E5=AD=98=20I?= =?UTF-8?q?Pv4=20=E5=9C=B0=E5=9D=80=E6=B1=A0=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/public/cloud/admin-hosts.js | 18 +++++++++++++++++- web/resources/views/venix/layout_assets.tpl | 2 +- web/tests/AdminHostNetworkBehaviorTest.mjs | 11 ++++++++++- web/tests/CloudAssetVersionContractTest.php | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/web/public/cloud/admin-hosts.js b/web/public/cloud/admin-hosts.js index 1eee5aec..1f5f02fd 100644 --- a/web/public/cloud/admin-hosts.js +++ b/web/public/cloud/admin-hosts.js @@ -969,7 +969,23 @@ function renderNetworkPoolForm(pool) { const maxAllocations = networkPoolInput('number', 'max_allocations', Number(pool.max_allocations || 0), { min: 1, max: 65535 }); for (const [control, suffix] of [[attachment, 'attachment'], [name, 'name'], [family, 'family'], [cidr, 'cidr'], [gateway, 'gateway'], [gatewayOnLink, 'gateway-on-link'], [prefix, 'prefix'], [status, 'state'], [dns, 'dns'], [reserved, 'reserved'], [allocationStart, 'allocation-start'], [allocationEnd, 'allocation-end'], [maxAllocations, 'max-allocations']]) control.id = `host-network-pool-${pool.pool_key}-${suffix}`; const sparseFields = [networkPoolField('IPv6 分配起始地址', allocationStart), networkPoolField('IPv6 分配结束地址', allocationEnd), networkPoolField('IPv6 最大分配数量', maxAllocations)]; - const syncFamily = () => { const ipv6 = family.value === '6'; prefix.min = ipv6 ? '48' : '24'; prefix.max = ipv6 ? '120' : '30'; for (const field of sparseFields) field.hidden = !ipv6; allocationStart.required = ipv6; allocationEnd.required = ipv6; maxAllocations.required = ipv6; gatewayOnLink.disabled = !canManage || !ipv6; if (!ipv6) { allocationStart.value = ''; allocationEnd.value = ''; maxAllocations.value = '0'; gatewayOnLink.value = '0'; } }; + const syncFamily = () => { + const ipv6 = family.value === '6'; + prefix.min = ipv6 ? '48' : '24'; + prefix.max = ipv6 ? '120' : '30'; + for (const field of sparseFields) field.hidden = !ipv6; + for (const control of [allocationStart, allocationEnd, maxAllocations]) { + control.required = ipv6; + control.disabled = !canManage || !ipv6; + } + gatewayOnLink.disabled = !canManage || !ipv6; + if (!ipv6) { + allocationStart.value = ''; + allocationEnd.value = ''; + maxAllocations.value = '0'; + gatewayOnLink.value = '0'; + } + }; family.addEventListener('change', syncFamily); syncFamily(); grid.append(networkPoolAttachmentField(attachment, attachmentDetail), networkPoolField('地址池名称', name, true), networkPoolField('地址族', family), networkPoolField('网关方式', gatewayOnLink), networkPoolField('实际公网 CIDR', cidr), networkPoolField('公网网关', gateway), networkPoolField('客户机网络前缀', prefix), networkPoolField('运行状态', status), networkPoolField('DNS(逗号或空格分隔)', dns, true), networkPoolField('保留 / 禁用 IP', reserved, true), ...sparseFields); const metadata = element('p', 'form-text mb-0', `面板版本 ${Number(pool.revision || 0)} · 已应用版本 ${pool.live_revision === null ? '未确认' : Number(pool.live_revision)} · 占用 ${Number(pool.occupied_count || 0)} · 可分配 ${Number(pool.available_count || 0)}`); diff --git a/web/resources/views/venix/layout_assets.tpl b/web/resources/views/venix/layout_assets.tpl index 868a8080..5baa4957 100644 --- a/web/resources/views/venix/layout_assets.tpl +++ b/web/resources/views/venix/layout_assets.tpl @@ -1,2 +1,2 @@ {* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *} -{assign var=venix_asset_version value='2026110403' scope='global'} +{assign var=venix_asset_version value='2026110404' scope='global'} diff --git a/web/tests/AdminHostNetworkBehaviorTest.mjs b/web/tests/AdminHostNetworkBehaviorTest.mjs index 581d5b41..a1c8ad0f 100644 --- a/web/tests/AdminHostNetworkBehaviorTest.mjs +++ b/web/tests/AdminHostNetworkBehaviorTest.mjs @@ -284,9 +284,18 @@ for (const [family, enabled] of [[4, false], [6, true]]) { }, 7, 0); const gatewayOnLink = descendants(test.get('host-network-pools-list')) .find(node => node.name === 'gateway_on_link'); + const ipv6OnlyControls = descendants(test.get('host-network-pools-list')) + .filter(node => ['allocation_start', 'allocation_end', 'max_allocations'].includes(node.name)); assert.equal(gatewayOnLink?.disabled, !enabled, `IPv${family} edit mode exposed the wrong on-link state.`); - if (family === 4) assert.equal(gatewayOnLink?.value, '0'); + for (const control of ipv6OnlyControls) { + assert.equal(control.disabled, !enabled, + `IPv${family} edit mode exposed the wrong ${control.name} state.`); + } + if (family === 4) { + assert.equal(gatewayOnLink?.value, '0'); + assert.equal(ipv6OnlyControls.find(node => node.name === 'max_allocations')?.value, '0'); + } } { diff --git a/web/tests/CloudAssetVersionContractTest.php b/web/tests/CloudAssetVersionContractTest.php index 957573ae..d77275b8 100644 --- a/web/tests/CloudAssetVersionContractTest.php +++ b/web/tests/CloudAssetVersionContractTest.php @@ -15,7 +15,7 @@ $assert = static function (bool $condition, string $message): void { }; $assert(is_string($assets) - && str_contains($assets, "venix_asset_version value='2026110403'") + && str_contains($assets, "venix_asset_version value='2026110404'") && is_string($cloudShell) && str_contains($cloudShell, '/cloud/app.js?v={$venix_asset_version}'), 'The cloud application entry must use the shared Venix asset version.');