fix(web): unify asset versions and remove SES

go
codex 1 month ago
parent 2e66371a1d
commit 873acf0fd8

@ -9,7 +9,6 @@ namespace App\Services;
use App\Models\Configurations;
use App\Models\EmailLog;
use App\Services\Mail\Mailgun;
use App\Services\Mail\Ses;
use App\Services\Mail\Smtp;
use App\Services\Mail\NullMail;
use Smarty;
@ -20,7 +19,7 @@ class Mail
private const EMAIL_BLACKLIST_CACHE_KEY = 'email_blacklist';
/**
* @return Mailgun|Ses|Smtp|NullMail
* @return Mailgun|Smtp|NullMail
*/
public static function getClient()
{
@ -28,14 +27,11 @@ class Mail
switch ($driver) {
case "mailgun":
return new Mailgun();
case "ses":
return new Ses();
case "smtp":
return new Smtp();
default:
return new NullMail();
}
return null;
}
/**

@ -1,43 +0,0 @@
<?php
namespace App\Services\Mail;
use App\Services\Config;
class Ses extends Base
{
protected $client;
public function __construct()
{
$this->client = Factory::createSes();
}
public function send($to, $subject, $text, $file)
{
if (!empty($file)) {
return false;
}
return $this->client->sendEmail([
'Destination' => [ // REQUIRED
'ToAddresses' => [$to],
],
'Message' => [ // REQUIRED
'Body' => [ // REQUIRED
'Html' => [
'Data' => $text, // REQUIRED
],
'Text' => [
'Data' => $text, // REQUIRED
],
],
'Subject' => [ // REQUIRED
'Data' => $subject, // REQUIRED
],
],
'Source' => $this->getSender(), // REQUIRED
]) !== false;
}
}

@ -1,6 +1,6 @@
<?php
#----------------------------------------邮件-------------------------------------------
$System_Config['mailDriver'] = 'smtp'; // mailgun or smtp or sendgrid
$System_Config['mailDriver'] = 'smtp'; // mailgun or smtp
# mailgun
$System_Config['mailgun_key'] = '';
$System_Config['mailgun_domain'] = '';

@ -1,7 +1,16 @@
import {
const assetVersion = new URL(import.meta.url).searchParams.get('v');
function versionedModuleUrl(path) {
const url = new URL(path, import.meta.url);
url.search = '';
if (assetVersion) url.searchParams.set('v', assetVersion);
return url.href;
}
const {
announceTaskAccepted, observeTask, recoveryTaskFailureNotice, taskUrl,
taskSucceededWithoutRecovery,
} from './task-observer.js?v=2026102102';
} = await import(versionedModuleUrl('./task-observer.js'));
const root = document.querySelector('[data-admin-instances]');
const byId = id => document.getElementById(id);

@ -1,7 +1,16 @@
import {
const assetVersion = new URL(import.meta.url).searchParams.get('v');
function versionedModuleUrl(path) {
const url = new URL(path, import.meta.url);
url.search = '';
if (assetVersion) url.searchParams.set('v', assetVersion);
return url.href;
}
const {
announceTaskAccepted, observeTask, recoveryTaskFailureNotice, taskUrl,
taskSucceededWithoutRecovery,
} from './task-observer.js?v=2026102102';
} = await import(versionedModuleUrl('./task-observer.js'));
const root = document.querySelector('[data-admin-operations]');
const byId = id => document.getElementById(id);

@ -1,4 +1,16 @@
import { announceTaskAccepted, observeTask, recoveryTaskFailureNotice, taskSucceededWithoutRecovery, taskUrl } from './task-observer.js?v=2026102102';
const assetVersion = new URL(import.meta.url).searchParams.get('v');
function versionedModuleUrl(path) {
const url = new URL(path, import.meta.url);
url.search = '';
if (assetVersion) url.searchParams.set('v', assetVersion);
return url.href;
}
const {
announceTaskAccepted, observeTask, recoveryTaskFailureNotice,
taskSucceededWithoutRecovery, taskUrl,
} = await import(versionedModuleUrl('./task-observer.js'));
const root = document.querySelector('[data-cloud-admin]');
const byId = id => document.getElementById(id);

@ -1,5 +1,3 @@
import { initializeTaskCenter } from './task-center.js?v=2026102408';
const pageModules = Object.freeze({
instances: '/cloud/instances.js',
detail: '/cloud/detail.js',
@ -12,23 +10,37 @@ const pageModules = Object.freeze({
});
const page = document.body.dataset.cloudPage || '';
initializeTaskCenter();
const modulePath = pageModules[page];
if (modulePath) {
const moduleUrl = new URL(modulePath, location.origin);
const assetVersion = new URL(import.meta.url).searchParams.get('v');
if (assetVersion) moduleUrl.searchParams.set('v', assetVersion);
import(moduleUrl.href).then(module => module.initialize()).catch(error => {
const target = document.getElementById('cloud-page-error');
if (target) {
target.textContent = error?.message || '页面加载失败,请刷新后重试。';
target.hidden = false;
}
});
} else {
const assetVersion = new URL(import.meta.url).searchParams.get('v');
function versionedModuleUrl(path) {
const url = new URL(path, import.meta.url);
url.search = '';
if (assetVersion) url.searchParams.set('v', assetVersion);
return url.href;
}
function showPageError(message) {
const target = document.getElementById('cloud-page-error');
if (target) {
target.textContent = '页面类型无效,请返回实例列表。';
target.textContent = message;
target.hidden = false;
}
}
async function initializeCloudApp() {
const { initializeTaskCenter } = await import(versionedModuleUrl('./task-center.js'));
initializeTaskCenter();
const modulePath = pageModules[page];
if (!modulePath) {
showPageError('页面类型无效,请返回实例列表。');
return;
}
const module = await import(versionedModuleUrl(modulePath));
module.initialize();
}
initializeCloudApp().catch(error => {
showPageError(error?.message || '页面加载失败,请刷新后重试。');
});

@ -1,12 +1,21 @@
import {
const assetVersion = new URL(import.meta.url).searchParams.get('v');
function versionedModuleUrl(path) {
const url = new URL(path, import.meta.url);
url.search = '';
if (assetVersion) url.searchParams.set('v', assetVersion);
return url.href;
}
const [taskObserver, runtime] = await Promise.all([
import(versionedModuleUrl('./task-observer.js')),
import(versionedModuleUrl('/cloud/runtime.js')),
]);
const {
announceTaskAccepted, normalizeTask, observeTask,
recoveryTaskFailureNotice, resolvedTaskFailureNotice,
taskSucceededWithoutRecovery,
} from './task-observer.js?v=2026102102';
const runtimeUrl = new URL('/cloud/runtime.js', location.origin);
const assetVersion = new URL(import.meta.url).searchParams.get('v');
if (assetVersion) runtimeUrl.searchParams.set('v', assetVersion);
} = taskObserver;
const {
VM_DETAIL_TABS, api, bindPageCleanup, byId, clearCredential,
clearVmMetrics, clearVmTrafficDaily, closeConsole, copyText, credential,
@ -14,7 +23,7 @@ const {
loadVmTrafficDaily, renderVmDetail, renderVmMetrics,
selectedVm, setVmDetailTab, showError, state, stopVmMetrics,
stopVmTrafficDaily, toast, trafficDailyViewVisible, vmIp,
} = await import(runtimeUrl.href);
} = runtime;
const requestUserConfirmation = options => window.VenixDialog?.confirm?.(options) ?? Promise.resolve(false);
const VM_METADATA_FIELDS = Object.freeze([

@ -1,4 +1,13 @@
import { toast } from './toast.js?v=2026100206';
const assetVersion = new URL(import.meta.url).searchParams.get('v');
function versionedModuleUrl(path) {
const url = new URL(path, import.meta.url);
url.search = '';
if (assetVersion) url.searchParams.set('v', assetVersion);
return url.href;
}
const { toast } = await import(versionedModuleUrl('./toast.js'));
// The first twenty instances are rendered by PHP. This lightweight module only
// handles local filtering, pagination and batched live-state refreshes.

@ -1,8 +1,21 @@
import { toast } from './toast.js?v=2026100102';
import {
const assetVersion = new URL(import.meta.url).searchParams.get('v');
function versionedModuleUrl(path) {
const url = new URL(path, import.meta.url);
url.search = '';
if (assetVersion) url.searchParams.set('v', assetVersion);
return url.href;
}
const [toastModule, taskObserver] = await Promise.all([
import(versionedModuleUrl('./toast.js')),
import(versionedModuleUrl('./task-observer.js')),
]);
const { toast } = toastModule;
const {
announceTaskAccepted, observeTask, recoveryTaskFailureNotice,
taskSucceededWithoutRecovery, taskUrl,
} from './task-observer.js?v=2026102102';
} = taskObserver;
// Lightweight invoice-detail runtime. This module deliberately contains no VM,
// deployment, metrics or console code so the bill is interactive without

@ -1,14 +1,23 @@
import {
const assetVersion = new URL(import.meta.url).searchParams.get('v');
function versionedModuleUrl(path) {
const url = new URL(path, import.meta.url);
url.search = '';
if (assetVersion) url.searchParams.set('v', assetVersion);
return url.href;
}
const [taskObserver, runtime] = await Promise.all([
import(versionedModuleUrl('./task-observer.js')),
import(versionedModuleUrl('/cloud/runtime.js')),
]);
const {
announceTaskAccepted, observeTask, recoveryTaskFailureNotice, taskUrl,
taskSucceededWithoutRecovery,
} from './task-observer.js?v=2026102102';
const runtimeUrl = new URL('/cloud/runtime.js', location.origin);
const assetVersion = new URL(import.meta.url).searchParams.get('v');
if (assetVersion) runtimeUrl.searchParams.set('v', assetVersion);
} = taskObserver;
const {
api, bindPageCleanup, byId, initializeSession, showError, state, toast,
} = await import(runtimeUrl.href);
} = runtime;
const requestUserConfirmation = options => window.VenixDialog?.confirm?.(options) ?? Promise.resolve(false);
const pageState = {

@ -1,8 +1,21 @@
import { toast } from './toast.js?v=2026100102';
import {
const assetVersion = new URL(import.meta.url).searchParams.get('v');
function versionedModuleUrl(path) {
const url = new URL(path, import.meta.url);
url.search = '';
if (assetVersion) url.searchParams.set('v', assetVersion);
return url.href;
}
const [toastModule, taskObserver] = await Promise.all([
import(versionedModuleUrl('./toast.js')),
import(versionedModuleUrl('./task-observer.js')),
]);
const { toast } = toastModule;
const {
announceTaskAccepted, observeTask, recoveryTaskFailureNotice,
resolvedTaskFailureNotice, taskSucceededWithoutRecovery, taskUrl,
} from './task-observer.js?v=2026102102';
} = taskObserver;
// PHP owns authentication, authorisation, ownership and purchasing. No Agent
// address, token, host credential or unrestricted create API exists in this UI.

@ -1,4 +1,13 @@
import { toast } from './toast.js?v=2026100102';
const assetVersion = new URL(import.meta.url).searchParams.get('v');
function versionedModuleUrl(path) {
const url = new URL(path, import.meta.url);
url.search = '';
if (assetVersion) url.searchParams.set('v', assetVersion);
return url.href;
}
const { toast } = await import(versionedModuleUrl('./toast.js'));
// The saved-key list and the user/CSRF bootstrap are rendered into the
// first HTML response. This module owns only the add/delete interactions and

@ -1,6 +1,15 @@
import {
const assetVersion = new URL(import.meta.url).searchParams.get('v');
function versionedModuleUrl(path) {
const url = new URL(path, import.meta.url);
url.search = '';
if (assetVersion) url.searchParams.set('v', assetVersion);
return url.href;
}
const {
normalizeTask, recoveryTaskFailureNotice, resolvedTaskFailureNotice,
} from './task-observer.js?v=2026102102';
} = await import(versionedModuleUrl('./task-observer.js'));
const REFRESH_MS = 10000;
// Covers the longest server-side absolute task deadline (145 minutes) while

@ -1,2 +1,2 @@
{* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *}
{assign var=venix_asset_version value='2026102409' scope='global'}
{assign var=venix_asset_version value='2026102410' scope='global'}

@ -2,8 +2,8 @@ import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import vm from 'node:vm';
const source = (await readFile(new URL('../public/cloud/admin.js', import.meta.url), 'utf8'))
.replace(/^import[^\n]*\n/, '')
const adminSource = await readFile(new URL('../public/cloud/admin.js', import.meta.url), 'utf8');
const source = adminSource.slice(adminSource.indexOf('const root ='))
.replace('void initialize();', '')
+ '\nglobalThis.hostUI = { initialize, fillHost, saveHost, renderHostNetworkPools, state };';
const submit = { preventDefault() {} };

@ -2,8 +2,8 @@ import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import vm from 'node:vm';
const source = (await readFile(new URL('../public/cloud/admin.js', import.meta.url), 'utf8'))
.replace(/^import[^\n]*\n/, '')
const adminSource = await readFile(new URL('../public/cloud/admin.js', import.meta.url), 'utf8');
const source = adminSource.slice(adminSource.indexOf('const root ='))
.replace('void initialize();', '')
+ '\n;globalThis.__scripts = { startupScriptState, openStartupScript, closeStartupScript, saveStartupScript, loadCatalog };\n';

@ -0,0 +1,59 @@
<?php
$root = dirname(__DIR__);
$assets = file_get_contents(
$root . '/resources/views/venix/layout_assets.tpl'
);
$cloudShell = file_get_contents(
$root . '/resources/views/venix/cloud/page.tpl'
);
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$assert(is_string($assets)
&& preg_match("/venix_asset_version value='[0-9]+'/", $assets) === 1
&& is_string($cloudShell)
&& str_contains($cloudShell, '/cloud/app.js?v={$venix_asset_version}'),
'The cloud application entry must use the shared Venix asset version.');
$dependencyFiles = [];
foreach (glob($root . '/public/cloud/*.js') ?: [] as $file) {
$source = file_get_contents($file);
$relative = 'public/cloud/' . basename($file);
$assert(is_string($source), 'Unable to read ' . $relative . '.');
$assert(preg_match('/[?&]v=[0-9]{6,}/', $source) !== 1,
$relative . ' contains an independent numeric asset version.');
if (str_contains($source, 'task-observer.js')
|| str_contains($source, 'toast.js')
|| str_contains($source, 'task-center.js')) {
$dependencyFiles[] = $relative;
$assert(str_contains($source,
"const assetVersion = new URL(import.meta.url).searchParams.get('v');")
&& str_contains($source, 'function versionedModuleUrl(path)')
&& str_contains($source, "url.searchParams.set('v', assetVersion)")
&& str_contains($source, 'import(versionedModuleUrl('),
$relative . ' must pass the entry version to nested modules.');
}
}
sort($dependencyFiles);
$assert($dependencyFiles === [
'public/cloud/admin-instances.js',
'public/cloud/admin-operations.js',
'public/cloud/admin.js',
'public/cloud/app.js',
'public/cloud/detail.js',
'public/cloud/instances.js',
'public/cloud/invoice-detail-runtime.js',
'public/cloud/iso-images.js',
'public/cloud/runtime.js',
'public/cloud/ssh-keys.js',
'public/cloud/task-center.js',
], 'The nested cloud-module inventory changed without an asset-version review.');
echo "Cloud asset version inheritance checks passed.\n";

@ -460,7 +460,11 @@ const protocolFailure = task => {
const layoutAssets = await readFile(layoutAssetsUrl, 'utf8');
const assetVersion = layoutAssets.match(/venix_asset_version value='([0-9]+)'/)?.[1];
assert.ok(assetVersion, 'The shared cloud asset version is missing.');
assert.match(appSource, new RegExp(`task-center\\.js\\?v=${assetVersion}`));
assert.match(appSource, /const assetVersion = new URL\(import\.meta\.url\)\.searchParams\.get\('v'\);/);
assert.match(appSource, /function versionedModuleUrl\(path\)/);
assert.match(appSource, /url\.searchParams\.set\('v', assetVersion\)/);
assert.match(appSource, /await import\(versionedModuleUrl\('\.\/task-center\.js'\)\)/);
assert.doesNotMatch(appSource, /task-center\.js\?v=[0-9]+/);
assert.match(clientCss,
/\.panel-announcements-close\.button:focus,\s*\.panel-task-close\.button:focus,\s*\.panel-account-drawer-close\.button:focus\s*\{/,
'Touch-opened task drawers must match announcements without retaining a close-button frame.');

@ -0,0 +1,40 @@
<?php
$root = dirname(__DIR__);
$mailDirectory = $root . '/app/Services/Mail';
$mailService = file_get_contents($root . '/app/Services/Mail.php');
$configExample = file_get_contents($root . '/config/.config.php.example');
function expectMailDriverRegistry($condition, string $message): void
{
if (!$condition) {
fwrite(STDERR, $message . PHP_EOL);
exit(1);
}
}
$driverFiles = array_map('basename', glob($mailDirectory . '/*.php') ?: []);
sort($driverFiles);
$expectedDriverFiles = ['Base.php', 'Mailgun.php', 'NullMail.php', 'Smtp.php'];
expectMailDriverRegistry(
$driverFiles === $expectedDriverFiles,
'The mail transport directory must contain only the supported drivers.'
);
expectMailDriverRegistry(is_string($mailService), 'Unable to read the mail service.');
preg_match_all('/case\s+["\']([^"\']+)["\']\s*:/', $mailService, $driverCases);
expectMailDriverRegistry(
($driverCases[1] ?? []) === ['mailgun', 'smtp'],
'The mail service must register only Mailgun and SMTP transports.'
);
expectMailDriverRegistry(
str_contains($mailService, 'return new NullMail();'),
'Unknown or disabled mail transports must retain the null fallback.'
);
expectMailDriverRegistry(
is_string($configExample)
&& str_contains($configExample, "'smtp'; // mailgun or smtp"),
'The example configuration must document the complete supported transport list.'
);
echo "Mail driver registry checks passed.\n";

@ -98,9 +98,13 @@ $assert(str_contains($styles, '.panel-user-dialog::backdrop')
&& 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, $assetMatch) === 1
&& preg_match('/task-center\\.js\\?v=([0-9]+)/', $entry, $entryMatch) === 1
&& $assetMatch[1] === $entryMatch[1],
'The shared asset version and application module cache key must stay synchronized.');
$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";

@ -178,7 +178,7 @@ $assert(str_contains($routes, "'/cloud/instances'")
$assert(str_contains($cloudPageController, "'/user/cloud/instances'")
&& str_contains($cloudShell, 'data-cloud-page=')
&& str_contains($clientEntry, "instances: '/cloud/instances.js'")
&& str_contains($clientEntry, "import(moduleUrl.href)"),
&& str_contains($clientEntry, 'import(versionedModuleUrl(modulePath))'),
'Cloud route controller and page-module bootstrap contract is incomplete');
$assert(!str_contains($clientScript, 'location.hash')
&& !str_contains($clientScript, 'hashchange')
@ -186,7 +186,9 @@ $assert(!str_contains($clientScript, 'location.hash')
&& !str_contains($sharedSidebar, '/user/cloud#'),
'Retired hash routing must not remain in the user cloud UI');
$assert(str_contains($clientEntry, "new URL(import.meta.url).searchParams.get('v')")
&& str_contains($clientScript, "new URL('/cloud/runtime.js', location.origin)"),
&& str_contains($clientEntry, 'function versionedModuleUrl(path)')
&& str_contains($clientScript, "versionedModuleUrl('/cloud/runtime.js')")
&& !preg_match('/[?&]v=[0-9]{6,}/', $clientScript),
'Page modules must propagate the asset version to avoid year-long stale module caching');
$assert(substr_count($clientScript, "window.addEventListener('pageshow'") >= 3
&& substr_count($clientScript, 'if (!event.persisted) return;') >= 3

Loading…
Cancel
Save