|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
|
|
|
|
|
|
use App\Services\UserCopy\UserCopyCoverageScanner;
|
|
|
|
|
|
|
|
|
|
$root = dirname(__DIR__, 2);
|
|
|
|
|
$assert = static function (bool $condition, string $message): void {
|
|
|
|
|
if (!$condition) {
|
|
|
|
|
throw new RuntimeException($message);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This list is intentionally explicit. A new user-facing template or browser
|
|
|
|
|
* entry point must join the copy catalog and this inventory in the same
|
|
|
|
|
* change. Administrator-only assets, vendor libraries and workers are not
|
|
|
|
|
* user-copy surfaces.
|
|
|
|
|
*/
|
|
|
|
|
$templatePaths = [
|
|
|
|
|
'web/resources/views/venix/404.tpl',
|
|
|
|
|
'web/resources/views/venix/405.tpl',
|
|
|
|
|
'web/resources/views/venix/500.tpl',
|
|
|
|
|
'web/resources/views/venix/auth/layout_footer.tpl',
|
|
|
|
|
'web/resources/views/venix/auth/layout_header.tpl',
|
|
|
|
|
'web/resources/views/venix/auth/layout_scripts.tpl',
|
|
|
|
|
'web/resources/views/venix/auth/login.tpl',
|
|
|
|
|
'web/resources/views/venix/auth/register.tpl',
|
|
|
|
|
'web/resources/views/venix/auth/virsh_story.tpl',
|
|
|
|
|
'web/resources/views/venix/cloud/console.tpl',
|
|
|
|
|
'web/resources/views/venix/cloud/page.tpl',
|
|
|
|
|
'web/resources/views/venix/cloud/pages/backups.tpl',
|
|
|
|
|
'web/resources/views/venix/cloud/pages/cloud-snapshots.tpl',
|
|
|
|
|
'web/resources/views/venix/cloud/pages/deploy.tpl',
|
|
|
|
|
'web/resources/views/venix/cloud/pages/detail.tpl',
|
|
|
|
|
'web/resources/views/venix/cloud/pages/instances.tpl',
|
|
|
|
|
'web/resources/views/venix/cloud/pages/invoice-detail.tpl',
|
|
|
|
|
'web/resources/views/venix/cloud/pages/invoices.tpl',
|
|
|
|
|
'web/resources/views/venix/cloud/pages/isos.tpl',
|
|
|
|
|
'web/resources/views/venix/cloud/pages/keys.tpl',
|
|
|
|
|
'web/resources/views/venix/cloud/pages/reinstall.tpl',
|
|
|
|
|
'web/resources/views/venix/cloud/pages/traffic.tpl',
|
|
|
|
|
'web/resources/views/venix/cloud/pages/vpcs.tpl',
|
|
|
|
|
'web/resources/views/venix/components/site_brand_mark.tpl',
|
|
|
|
|
'web/resources/views/venix/home/language_switch.tpl',
|
|
|
|
|
'web/resources/views/venix/home/layout_header.tpl',
|
|
|
|
|
'web/resources/views/venix/home/layout_scripts.tpl',
|
|
|
|
|
'web/resources/views/venix/home/nav_actions.tpl',
|
|
|
|
|
'web/resources/views/venix/home/site_footer.tpl',
|
|
|
|
|
'web/resources/views/venix/home/site_header.tpl',
|
|
|
|
|
'web/resources/views/venix/index.tpl',
|
|
|
|
|
'web/resources/views/venix/layout_assets.tpl',
|
|
|
|
|
'web/resources/views/venix/legal.tpl',
|
|
|
|
|
'web/resources/views/venix/password/reset.tpl',
|
|
|
|
|
'web/resources/views/venix/password/token.tpl',
|
|
|
|
|
'web/resources/views/venix/user/account_drawer.tpl',
|
|
|
|
|
'web/resources/views/venix/user/announcement_drawer.tpl',
|
|
|
|
|
'web/resources/views/venix/user/dialog.tpl',
|
|
|
|
|
'web/resources/views/venix/user/disable.tpl',
|
|
|
|
|
'web/resources/views/venix/user/edit.tpl',
|
|
|
|
|
'web/resources/views/venix/user/invite.tpl',
|
|
|
|
|
'web/resources/views/venix/user/layout_assets.tpl',
|
|
|
|
|
'web/resources/views/venix/user/layout_footer.tpl',
|
|
|
|
|
'web/resources/views/venix/user/layout_header.tpl',
|
|
|
|
|
'web/resources/views/venix/user/layout_plain_header.tpl',
|
|
|
|
|
'web/resources/views/venix/user/layout_scripts.tpl',
|
|
|
|
|
'web/resources/views/venix/user/layout_toast.tpl',
|
|
|
|
|
'web/resources/views/venix/user/panel_sidebar.tpl',
|
|
|
|
|
'web/resources/views/venix/user/panel_topbar.tpl',
|
|
|
|
|
'web/resources/views/venix/user/pay_success.tpl',
|
|
|
|
|
'web/resources/views/venix/user/paytaro.tpl',
|
|
|
|
|
'web/resources/views/venix/user/task_center_drawer.tpl',
|
|
|
|
|
'web/resources/views/venix/user/ticket.tpl',
|
|
|
|
|
'web/resources/views/venix/user/ticket_create.tpl',
|
|
|
|
|
'web/resources/views/venix/user/ticket_view.tpl',
|
|
|
|
|
'web/resources/views/venix/user/user_copy_bootstrap.tpl',
|
|
|
|
|
'web/resources/views/venix/user/user_copy_editor_head.tpl',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$browserPaths = [
|
|
|
|
|
'web/public/cloud/account-drawer.js',
|
|
|
|
|
'web/public/cloud/announcements.js',
|
|
|
|
|
'web/public/cloud/app.js',
|
|
|
|
|
'web/public/cloud/backups.js',
|
|
|
|
|
'web/public/cloud/cloud-snapshots.js',
|
|
|
|
|
'web/public/cloud/deploy.js',
|
|
|
|
|
'web/public/cloud/detail.js',
|
|
|
|
|
'web/public/cloud/drawer-motion.js',
|
|
|
|
|
'web/public/cloud/firewall-input.js',
|
|
|
|
|
'web/public/cloud/instance-service.js',
|
|
|
|
|
'web/public/cloud/instances.js',
|
|
|
|
|
'web/public/cloud/invoice-detail-runtime.js',
|
|
|
|
|
'web/public/cloud/invoice-detail.js',
|
|
|
|
|
'web/public/cloud/invoices.js',
|
|
|
|
|
'web/public/cloud/iso-images.js',
|
|
|
|
|
'web/public/cloud/reinstall.js',
|
|
|
|
|
'web/public/cloud/runtime.js',
|
|
|
|
|
'web/public/cloud/ssh-keys.js',
|
|
|
|
|
'web/public/cloud/task-center.js',
|
|
|
|
|
'web/public/cloud/task-observer.js',
|
|
|
|
|
'web/public/cloud/ticket-upload.js',
|
|
|
|
|
'web/public/cloud/toast.js',
|
|
|
|
|
'web/public/cloud/traffic.js',
|
|
|
|
|
'web/public/cloud/user-copy-runtime.js',
|
|
|
|
|
'web/public/cloud/user-dialog.js',
|
|
|
|
|
'web/public/cloud/vpcs.js',
|
|
|
|
|
'web/public/theme/venix/js/auth.js',
|
|
|
|
|
'web/public/theme/venix/js/recharge.js',
|
|
|
|
|
'web/public/theme/venix/js/ticket-page.js',
|
|
|
|
|
'web/public/theme/venix/js/user-home.js',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$absolute = static fn (string $path): string => $root . '/' . $path;
|
|
|
|
|
foreach (array_merge($templatePaths, $browserPaths) as $path) {
|
|
|
|
|
$assert(is_file($absolute($path)), 'User-copy inventory file is missing: ' . $path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$discover = static function (string $pattern) use ($root): array {
|
|
|
|
|
$files = glob($root . '/' . $pattern);
|
|
|
|
|
if (!is_array($files)) return [];
|
|
|
|
|
return array_map(
|
|
|
|
|
static fn (string $path): string => substr($path, strlen($root) + 1),
|
|
|
|
|
$files
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
$viewRoot = $root . '/web/resources/views/venix';
|
|
|
|
|
$discoveredTemplates = [];
|
|
|
|
|
$iterator = new RecursiveIteratorIterator(
|
|
|
|
|
new RecursiveDirectoryIterator($viewRoot, FilesystemIterator::SKIP_DOTS)
|
|
|
|
|
);
|
|
|
|
|
foreach ($iterator as $file) {
|
|
|
|
|
if (!$file->isFile() || strtolower($file->getExtension()) !== 'tpl') {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$relative = substr($file->getPathname(), strlen($root) + 1);
|
|
|
|
|
if (str_starts_with($relative, 'web/resources/views/venix/admin/')) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$discoveredTemplates[] = $relative;
|
|
|
|
|
}
|
|
|
|
|
sort($discoveredTemplates, SORT_STRING);
|
|
|
|
|
$expectedTemplates = $templatePaths;
|
|
|
|
|
sort($expectedTemplates, SORT_STRING);
|
|
|
|
|
$assert($discoveredTemplates === $expectedTemplates,
|
|
|
|
|
'User-facing template inventory drifted. Add or remove the exact paths in '
|
|
|
|
|
. basename(__FILE__) . '.');
|
|
|
|
|
|
|
|
|
|
$cloudAdminOrInfrastructure = [
|
|
|
|
|
'web/public/cloud/agent-settings.js',
|
|
|
|
|
'web/public/cloud/template-upload-hash-worker.js',
|
|
|
|
|
'web/public/cloud/template-upload-hash.js',
|
|
|
|
|
];
|
|
|
|
|
$allCloudJs = $discover('web/public/cloud/*.js');
|
|
|
|
|
$classifiedCloudJs = array_values(array_filter(
|
|
|
|
|
$allCloudJs,
|
|
|
|
|
static fn (string $path): bool => str_starts_with(
|
|
|
|
|
basename($path), 'admin-'
|
|
|
|
|
) || in_array($path, $browserPaths, true)
|
|
|
|
|
|| in_array($path, $cloudAdminOrInfrastructure, true)
|
|
|
|
|
));
|
|
|
|
|
sort($allCloudJs, SORT_STRING);
|
|
|
|
|
sort($classifiedCloudJs, SORT_STRING);
|
|
|
|
|
$assert($allCloudJs === $classifiedCloudJs,
|
|
|
|
|
'A cloud browser asset has no explicit user/admin/infrastructure ownership.');
|
|
|
|
|
|
|
|
|
|
$themeAdminVendorOrUnused = [
|
|
|
|
|
'web/public/theme/venix/js/admin-announcements.js',
|
|
|
|
|
'web/public/theme/venix/js/admin-csrf.js',
|
|
|
|
|
'web/public/theme/venix/js/admin-home.js',
|
|
|
|
|
'web/public/theme/venix/js/admin-legal.js',
|
|
|
|
|
'web/public/theme/venix/js/fuck.js',
|
|
|
|
|
'web/public/theme/venix/js/jquery.js',
|
|
|
|
|
'web/public/theme/venix/js/qrcode.min.js',
|
|
|
|
|
];
|
|
|
|
|
$allThemeJs = $discover('web/public/theme/venix/js/*.js');
|
|
|
|
|
$classifiedThemeJs = array_values(array_filter(
|
|
|
|
|
$allThemeJs,
|
|
|
|
|
static fn (string $path): bool => in_array($path, $browserPaths, true)
|
|
|
|
|
|| in_array($path, $themeAdminVendorOrUnused, true)
|
|
|
|
|
));
|
|
|
|
|
sort($allThemeJs, SORT_STRING);
|
|
|
|
|
sort($classifiedThemeJs, SORT_STRING);
|
|
|
|
|
$assert($allThemeJs === $classifiedThemeJs,
|
|
|
|
|
'A Venix browser asset has no explicit user/admin/vendor/unused ownership.');
|
|
|
|
|
|
|
|
|
|
$violations = UserCopyCoverageScanner::scanFiles(array_map(
|
|
|
|
|
$absolute,
|
|
|
|
|
array_merge($templatePaths, $browserPaths)
|
|
|
|
|
));
|
|
|
|
|
if ($violations !== []) {
|
|
|
|
|
$lines = array_map(static function (array $violation) use ($root): string {
|
|
|
|
|
$path = (string) ($violation['path'] ?? '');
|
|
|
|
|
if (str_starts_with($path, $root . '/')) {
|
|
|
|
|
$path = substr($path, strlen($root) + 1);
|
|
|
|
|
}
|
|
|
|
|
return sprintf(
|
|
|
|
|
'%s:%d [%s] %s',
|
|
|
|
|
$path,
|
|
|
|
|
(int) ($violation['line'] ?? 0),
|
|
|
|
|
(string) ($violation['rule'] ?? ''),
|
|
|
|
|
(string) ($violation['snippet'] ?? '')
|
|
|
|
|
);
|
|
|
|
|
}, $violations);
|
|
|
|
|
throw new RuntimeException(
|
|
|
|
|
"User-copy coverage gate found unregistered user-visible copy:\n"
|
|
|
|
|
. implode("\n", $lines)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo "All explicit user-facing templates and browser assets use the published copy catalog.\n";
|