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.
95 lines
3.8 KiB
PHP
95 lines
3.8 KiB
PHP
<?php
|
|
|
|
$root = dirname(__DIR__);
|
|
$read = static function (string $path) use ($root): string {
|
|
$source = file_get_contents($root . '/' . $path);
|
|
if (!is_string($source)) {
|
|
throw new RuntimeException('Unable to read ' . $path);
|
|
}
|
|
return $source;
|
|
};
|
|
$assert = static function (bool $condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
$pageRoutes = $read('config/routes.php');
|
|
$apiRoutes = $read('config/routes_cloud.php');
|
|
$middleware = $read('app/Middleware/CloudApi.php');
|
|
$pageController = $read('app/Controllers/Admin/CloudPageController.php');
|
|
$apiController = $read('app/Controllers/CloudAdminAbuseMonitoringController.php');
|
|
$service = $read('app/Services/Cloud/CloudAdminAbuseMonitoringService.php');
|
|
$sidebar = $read('resources/views/venix/admin/static_header.tpl');
|
|
|
|
$assert(str_contains(
|
|
$pageRoutes,
|
|
"get('/abuse-monitoring',\n 'App\\Controllers\\Admin\\CloudPageController:abuseMonitoring')"
|
|
) && str_contains($pageController, 'public function abuseMonitoring('),
|
|
'Administrator abuse-monitoring page route is not connected.');
|
|
|
|
$assert(str_contains(
|
|
$apiRoutes,
|
|
"get('/admin/abuse-monitoring',\n 'App\\Controllers\\CloudAdminAbuseMonitoringController:index')"
|
|
) && str_contains(
|
|
$apiRoutes,
|
|
"get('/admin/abuse-monitoring/instances/{id:[1-9][0-9]*}',\n 'App\\Controllers\\CloudAdminAbuseMonitoringController:detail')"
|
|
) && !preg_match(
|
|
"#(?:post|put|patch|delete|map)\\([^\\n]*'/admin/abuse-monitoring#i",
|
|
$apiRoutes
|
|
),
|
|
'Abuse-monitoring API must expose exactly read-only GET surfaces.');
|
|
|
|
$assert(str_contains(
|
|
$middleware,
|
|
"#^/api/v1/admin/abuse-monitoring(?:/|$)#D"
|
|
) && str_contains($middleware, 'CloudAccess::actor(!$databaseOnly)'),
|
|
'Database-only abuse-monitoring reads must not require an Agent session.');
|
|
|
|
$methodStart = strpos(
|
|
$pageController,
|
|
'public function abuseMonitoring('
|
|
);
|
|
$methodEnd = $methodStart === false ? false : strpos(
|
|
$pageController,
|
|
'public function maintenanceNotices(',
|
|
$methodStart
|
|
);
|
|
$method = $methodStart === false || $methodEnd === false
|
|
? '' : substr($pageController, $methodStart, $methodEnd - $methodStart);
|
|
$throwableBlock = '';
|
|
if (preg_match(
|
|
'/catch \(\\\\Throwable \$exception\) \{(?<body>.*?)\n \}/s',
|
|
$method,
|
|
$matches
|
|
) === 1) {
|
|
$throwableBlock = (string) ($matches['body'] ?? '');
|
|
}
|
|
$assert(str_contains($method, 'CloudAccess::actor(false)')
|
|
&& str_contains($method, '!($actor[\'is_admin\'] ?? false)')
|
|
&& str_contains($method, 'CloudAdminAbuseMonitoringService())->page(')
|
|
&& str_contains($method, "'private, no-store'")
|
|
&& str_contains($method, "'abuse_monitoring_timezone' => 'UTC'")
|
|
&& !str_contains($method, 'bootstrap_json')
|
|
&& str_contains($method, "'网络监控数据暂时无法读取,请稍后重试。'")
|
|
&& $throwableBlock !== ''
|
|
&& !str_contains($throwableBlock, '$exception->getMessage()'),
|
|
'Administrator first paint lost its authorization, safe fallback or cache boundary.');
|
|
|
|
$assert(str_contains($apiController, "'Cache-Control', 'private, no-store'")
|
|
&& str_contains($service, "throw new CloudError('需要管理员权限', 403)")
|
|
&& !preg_match(
|
|
'/->(?:insert|update|delete|lockForUpdate)\\s*\\(/',
|
|
$service . $apiController . $method
|
|
),
|
|
'Read-only monitoring gained a mutation or lost API authorization.');
|
|
|
|
$assert(str_contains($sidebar, 'href="/admin/abuse-monitoring"')
|
|
&& str_contains($sidebar,
|
|
"admin_active|default:'' == 'abuse-monitoring'")
|
|
&& strpos($sidebar, 'href="/admin/cloud/instances"')
|
|
< strpos($sidebar, 'href="/admin/abuse-monitoring"'),
|
|
'Network monitoring is missing beside virtual-machine administration.');
|
|
|
|
echo "Administrator abuse-monitoring page contracts passed.\n";
|