You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
170 lines
8.4 KiB
PHP
170 lines
8.4 KiB
PHP
<?php
|
|
|
|
// Static contract for the revisioned administrator host public-pool boundary.
|
|
$root = dirname(__DIR__);
|
|
$routes = file_get_contents($root . '/config/routes_cloud.php');
|
|
$controller = file_get_contents(
|
|
$root . '/app/Controllers/CloudAdminHostNetworkController.php'
|
|
);
|
|
$service = file_get_contents(
|
|
$root . '/app/Services/Cloud/CloudAdminHostNetworkService.php'
|
|
);
|
|
$usage = file_get_contents(
|
|
$root . '/app/Services/Cloud/CloudPanelUsageService.php'
|
|
);
|
|
$engineClient = file_get_contents(
|
|
$root . '/app/Services/Cloud/CloudEngineClient.php'
|
|
);
|
|
$hostController = file_get_contents(
|
|
$root . '/app/Controllers/CloudAdminController.php'
|
|
);
|
|
$template = file_get_contents(
|
|
$root . '/resources/views/venix/admin/hosts/index.tpl'
|
|
);
|
|
$client = file_get_contents($root . '/public/cloud/admin.js');
|
|
$assets = file_get_contents(
|
|
$root . '/resources/views/venix/layout_assets.tpl'
|
|
);
|
|
|
|
$assert = static function ($condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
$assert(str_contains($routes,
|
|
"map(['GET', 'POST'], '/admin/hosts/{id:[0-9]+}/network-pools'")
|
|
&& str_contains($routes,
|
|
"'/admin/hosts/{id:[0-9]+}/network-pools/{pool_key:[0-9a-f]{32}}'")
|
|
&& str_contains($routes,
|
|
"'App\\Controllers\\CloudAdminHostNetworkController:update'")
|
|
&& !str_contains($routes,
|
|
"delete('/admin/hosts/{id:[0-9]+}/network-pools"),
|
|
'Host public pools require bounded GET/POST/PUT routes and no hard-delete route.');
|
|
|
|
$assert(str_contains($controller, 'CloudAccess::manage($actor);')
|
|
&& str_contains($controller, '$write = $method !== \'GET\';')
|
|
&& substr_count($controller,
|
|
"'name', 'cidr', 'gateway', 'dns_servers', 'reserved_ips'") === 2
|
|
&& str_contains($controller,
|
|
"'guest_prefix_length', 'state', 'request_key'")
|
|
&& str_contains($controller,
|
|
"'guest_prefix_length', 'state', 'expected_revision'")
|
|
&& str_contains($controller,
|
|
"->withHeader('Cache-Control', 'private, no-store')"),
|
|
'Pool writes must be super-admin-only and use a strict request/response boundary.');
|
|
|
|
$assert(str_contains($service, 'private const MAX_POOLS = 32;')
|
|
&& str_contains($service,
|
|
"private const STATES = ['active', 'draining', 'disabled'];")
|
|
&& str_contains($service, "hash_hmac(\n 'sha256'")
|
|
&& str_contains($service, "CloudSecrets::key('payload_key')")
|
|
&& !str_contains($service, 'bin2hex(random_bytes(16))')
|
|
&& !str_contains($service, "'GET', 'host/network-pools'")
|
|
&& str_contains($service,
|
|
"'host/network-pools/' . rawurlencode(\$poolKey)")
|
|
&& str_contains($service, 'CloudHostPoolMembershipService::lockedRows')
|
|
&& str_contains($service, 'CloudHostPoolMembershipService::selected')
|
|
&& str_contains($service, "\$lockedHost->default_network")
|
|
&& str_contains($service, 'CloudHostNetworkAttachment')
|
|
&& str_contains($service, 'CloudPublicIpPool')
|
|
&& str_contains($service, 'desired_revision')
|
|
&& str_contains($service, 'observed_revision')
|
|
&& str_contains($service, 'sync_state')
|
|
&& str_contains($service, 'refreshAttachmentAggregate')
|
|
&& str_contains($service,
|
|
"'uncertain' => 4")
|
|
&& str_contains($service,
|
|
'if ($confirmedRevision > 0)')
|
|
&& str_contains($service,
|
|
'$attachment->observed_revision = $evidenceRevision;'),
|
|
'The service must persist host/line attachment desired state and independent pool revisions.');
|
|
|
|
$assert(str_contains($service,
|
|
"preg_match('/^[0-9a-f]{32}$/D', \$requestKey)")
|
|
&& str_contains($service, 'sameCreateRequest(')
|
|
&& str_contains($service, "'replay' => true")
|
|
&& str_contains($service,
|
|
'存在尚未核对的地址池创建记录,请刷新后编辑该记录,不能继续创建新地址池')
|
|
&& str_contains($service, '$expectedRevision !== $revisionBase')
|
|
&& str_contains($service, '公网地址池版本已变化,请刷新后重试')
|
|
&& str_contains($service, "\$prepared['revision'],\n 'applied'")
|
|
&& str_contains($service, "\$retryExisting = false")
|
|
&& str_contains($service, 'materializeIpLedger')
|
|
&& str_contains($service, "(string) \$pool->sync_state === 'applied'"),
|
|
'Creates must be idempotent, updates CAS-fenced and successful writes must materialize the panel IP ledger.');
|
|
|
|
$assert(str_contains($service, 'assertNoOverlap(')
|
|
&& str_contains($service, 'assertNoGlobalOverlap(')
|
|
&& str_contains($service, 'catalogCount(')
|
|
&& str_contains($service, '一台宿主机最多配置 32 个公网地址池')
|
|
&& str_contains($service, 'OCCUPIED_IP_STATES')
|
|
&& str_contains($service,
|
|
'该地址池仍有实例或任务占用,只能修改名称和运行状态')
|
|
&& str_contains($service, '$originalAttachment')
|
|
&& str_contains($service, '$attachmentChanged')
|
|
&& str_contains($service, '$attachmentLineChanged')
|
|
&& !str_contains($service, '->delete()'),
|
|
'Pool limits, overlap checks, occupied runtime locks and soft lifecycle states are required.');
|
|
$assert(str_contains($service, 'legacyInstanceIpClaims(')
|
|
&& str_contains($service, 'materializeIpLedger(')
|
|
&& str_contains((string) $usage, "CloudInstance::where('host_id', \$hostId)")
|
|
&& str_contains((string) $usage, "'unknown'")
|
|
&& str_contains((string) $usage, 'spec_json')
|
|
&& str_contains((string) $usage, 'managementAddressFromValue'),
|
|
'Legacy panel instances must be counted/imported from panel metadata and block on unknown usage without host discovery.');
|
|
|
|
$assert(str_contains($engineClient,
|
|
'/host/network-pools/[0-9a-f]{32}$#D')
|
|
&& str_contains($engineClient,
|
|
"? '公网地址池配置未通过引擎校验'")
|
|
&& str_contains($service,
|
|
'公网地址池应用状态不确定,请勿重复提交,稍后刷新核对')
|
|
&& !str_contains($service, '$error->getMessage()'),
|
|
'Engine pool failures must retain reviewed status only and never expose raw engine detail.');
|
|
|
|
foreach (['host-public-pool', 'host-gateway', 'host-dns', 'host-reserved',
|
|
'host-vm-prefix'] as $retiredId) {
|
|
$assert(!str_contains($template, 'id="' . $retiredId . '"'),
|
|
'The old single-pool host input remains in the main form: ' . $retiredId);
|
|
}
|
|
$assert(!str_contains($hostController, "'public_pool_cidr', 'public_gateway'")
|
|
&& !str_contains($client, 'function hostPublicNetworkPayload()')
|
|
&& str_contains($hostController,
|
|
"\$engineHost['public_pool_cidr'] ?? ''"),
|
|
'The main host writer must not accept pool input or double-write the pool catalog.');
|
|
|
|
$assert(str_contains($template, 'id="host-network-pools-drawer"')
|
|
&& str_contains($template, 'data-admin-host-network-drawer')
|
|
&& str_contains($template,
|
|
'{if !$admin_can_manage|default:false}disabled{/if}')
|
|
&& str_contains($client, 'window.VenixDrawerMotion.openDrawerWithMotion')
|
|
&& str_contains($client, 'window.VenixDrawerMotion.closeDrawerWithMotion')
|
|
&& str_contains($client, "{ method: 'POST', body }")
|
|
&& str_contains($client, "{ method: 'PUT', body }")
|
|
&& str_contains($client, 'networkPoolEpoch')
|
|
&& str_contains($client, 'networkPoolHostId')
|
|
&& str_contains($client, 'networkPoolContextCurrent(hostId, epoch)')
|
|
&& str_contains($client, 'globalThis.crypto?.getRandomValues')
|
|
&& str_contains($client, 'request_key: requestKey')
|
|
&& str_contains($client, 'expected_revision: expectedRevision')
|
|
&& str_contains($client,
|
|
'const payload = await api(`/api/v1/admin/hosts/${encodeURIComponent(hostId)}/network-pools`);')
|
|
&& str_contains($client, 'save.disabled = !canManage')
|
|
&& str_contains($client, 'for (const control of [cidr, gateway, prefix, dns, reserved]) control.disabled = true;')
|
|
&& !file_exists($root . '/public/cloud/admin-host-network.css'),
|
|
'The responsive pool editor must reuse the shared drawer/CSS and expose disabled write controls.');
|
|
|
|
$assert(str_contains($service, 'legacyRebuildMessage()')
|
|
&& str_contains($service,
|
|
'本项目不执行旧数据迁移,请先清空并按新版结构重建开发数据')
|
|
&& str_contains($service, 'legacyRowDto(')
|
|
&& str_contains($template, '旧行仅供核对且不能编辑'),
|
|
'Legacy development rows must be explicitly blocked and never rendered as native editable pools.');
|
|
|
|
$assert(preg_match("/venix_asset_version value='([0-9]+)'/", $assets, $match) === 1
|
|
&& (int) $match[1] >= 2026100316,
|
|
'The shared browser asset version must cover the host pool drawer release.');
|
|
|
|
echo "Administrator host public-pool contracts passed.\n";
|