|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
// Ordinary user pages must keep confirmations and notices inside the product UI.
|
|
|
|
|
// Administrator scripts and third-party assets are intentionally outside this scope.
|
|
|
|
|
$root = dirname(__DIR__);
|
|
|
|
|
$public = $root . '/public';
|
|
|
|
|
$views = $root . '/resources/views/venix';
|
|
|
|
|
$assert = static function (bool $condition, string $message): void {
|
|
|
|
|
if (!$condition) {
|
|
|
|
|
throw new RuntimeException($message);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$files = glob($public . '/cloud/*.js') ?: [];
|
|
|
|
|
$files = array_values(array_filter(
|
|
|
|
|
$files,
|
|
|
|
|
static fn (string $path): bool => !str_starts_with(basename($path), 'admin')
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
foreach (['auth.js', 'user-home.js', 'ticket-page.js', 'recharge.js', 'fuck.js'] as $script) {
|
|
|
|
|
$files[] = $public . '/theme/venix/js/' . $script;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (['auth', 'cloud', 'home', 'password', 'user'] as $viewDirectory) {
|
|
|
|
|
$directory = $views . '/' . $viewDirectory;
|
|
|
|
|
if (!is_dir($directory)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$iterator = new RecursiveIteratorIterator(
|
|
|
|
|
new RecursiveDirectoryIterator($directory, FilesystemIterator::SKIP_DOTS)
|
|
|
|
|
);
|
|
|
|
|
foreach ($iterator as $file) {
|
|
|
|
|
if ($file->isFile() && $file->getExtension() === 'tpl') {
|
|
|
|
|
$files[] = $file->getPathname();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$violations = [];
|
|
|
|
|
$patterns = [
|
|
|
|
|
'/\b(?:window|globalThis|self|top|parent)\s*\.\s*(?:alert|confirm|prompt)\s*\(/',
|
|
|
|
|
'/(?<![A-Za-z0-9_$.])\b(?:alert|confirm|prompt)\s*\(/',
|
|
|
|
|
'/\bonbeforeunload\b/',
|
|
|
|
|
'/addEventListener\s*\(\s*[\'\"]beforeunload[\'\"]/',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
foreach (array_unique($files) as $path) {
|
|
|
|
|
$source = file_get_contents($path);
|
|
|
|
|
if (!is_string($source)) {
|
|
|
|
|
throw new RuntimeException('Unable to read ' . $path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($patterns as $pattern) {
|
|
|
|
|
if (preg_match_all($pattern, $source, $matches, PREG_OFFSET_CAPTURE) !== false) {
|
|
|
|
|
foreach ($matches[0] as [$match, $offset]) {
|
|
|
|
|
$line = substr_count(substr($source, 0, $offset), "\n") + 1;
|
|
|
|
|
$violations[$path . ':' . $line] = trim($match);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($violations !== []) {
|
|
|
|
|
$details = [];
|
|
|
|
|
foreach ($violations as $location => $call) {
|
|
|
|
|
$details[] = str_replace($root . '/', '', $location) . ' (' . $call . ')';
|
|
|
|
|
}
|
|
|
|
|
throw new RuntimeException(
|
|
|
|
|
"Ordinary user pages still invoke browser-native dialogs:\n- "
|
|
|
|
|
. implode("\n- ", $details)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$topbar = file_get_contents($views . '/user/panel_topbar.tpl');
|
|
|
|
|
$markup = file_get_contents($views . '/user/dialog.tpl');
|
|
|
|
|
$runtime = file_get_contents($public . '/cloud/user-dialog.js');
|
|
|
|
|
$styles = file_get_contents($public . '/cloud/client.css');
|
|
|
|
|
$assets = file_get_contents($views . '/layout_assets.tpl');
|
|
|
|
|
$entry = file_get_contents($public . '/cloud/app.js');
|
|
|
|
|
foreach (compact('topbar', 'markup', 'runtime', 'styles', 'assets', 'entry') as $name => $source) {
|
|
|
|
|
$assert(is_string($source), 'Unable to read user dialog asset: ' . $name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$assert(str_contains($topbar, "{include file='user/dialog.tpl'}")
|
|
|
|
|
&& str_contains($topbar, 'src="/cloud/user-dialog.js?v={$venix_asset_version'),
|
|
|
|
|
'The shared user shell must mount the in-product dialog with the common cache key.');
|
|
|
|
|
$assert(str_contains($markup, 'id="panel-user-dialog"')
|
|
|
|
|
&& str_contains($markup, 'aria-labelledby="panel-user-dialog-title"')
|
|
|
|
|
&& str_contains($markup, 'aria-describedby="panel-user-dialog-message panel-user-dialog-verification-hint"'),
|
|
|
|
|
'The shared user dialog must expose an accessible name and description.');
|
|
|
|
|
$assert(str_contains($runtime, 'window.VenixDialog = Object.freeze')
|
|
|
|
|
&& str_contains($runtime, 'textContent =')
|
|
|
|
|
&& !str_contains($runtime, 'innerHTML'),
|
|
|
|
|
'The dialog API must render dynamic copy as text and expose the shared browser contract.');
|
|
|
|
|
$assert(str_contains($styles, '.panel-user-dialog::backdrop')
|
|
|
|
|
&& str_contains($styles, '.panel-user-dialog.is-dialog-fallback')
|
|
|
|
|
&& str_contains($styles, '@media (prefers-reduced-motion: reduce)'),
|
|
|
|
|
'The user dialog must retain a styled fallback and reduced-motion behavior.');
|
|
|
|
|
|
|
|
|
|
$assert(preg_match("/value='([0-9]+)'/", $assets) === 1
|
|
|
|
|
&& str_contains($entry, "const assetVersion = new URL(import.meta.url).searchParams.get('v');")
|
|
|
|
|
&& str_contains($entry, 'function versionedModuleUrl(path)')
|
|
|
|
|
&& str_contains($entry, 'new URL(path, import.meta.url)')
|
|
|
|
|
&& str_contains($entry, "url.searchParams.set('v', assetVersion)")
|
|
|
|
|
&& str_contains($entry, "await import(versionedModuleUrl('./task-center.js'))")
|
|
|
|
|
&& preg_match('/task-center\\.js\\?v=[0-9]+/', $entry) !== 1,
|
|
|
|
|
'Nested application modules must inherit the single shared asset version at runtime.');
|
|
|
|
|
|
|
|
|
|
echo "Ordinary user native-dialog boundary checks passed.\n";
|