diff --git a/ICON-SOURCES.md b/ICON-SOURCES.md new file mode 100644 index 00000000..89c311cc --- /dev/null +++ b/ICON-SOURCES.md @@ -0,0 +1,12 @@ +# 操作系统图标来源 + +这些图标随面板保存在 `static/`,页面运行时不向图标来源站点发起请求。它们仅用于标识实际系统模板,不表示发行版项目或商标持有人认可本面板。 + +| 本地文件 | 官方来源 | 使用说明 | +| --- | --- | --- | +| `static/almalinux-icon.svg` | [AlmaLinux 官方圆形图标](https://almalinux.org/branding/AlmaLinux%20Icon%20Circle.svg) | 保留官方图形及颜色;参阅 [AlmaLinux 品牌规范](https://almalinux.org/branding/brand-book)。 | +| `static/debian-icon.svg` | [Debian Open Use Logo(无文字版)](https://www.debian.org/logos/openlogo-nd.svg) | Copyright © 1999 Software in the Public Interest, Inc.;官方提供 LGPL-3.0-or-later 或 [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/) 双重许可。此本地 SVG 移除了原文件的外部 DTD 与 Illustrator 元数据,图形路径和颜色保持不变。参阅 [Debian 图标说明](https://www.debian.org/logos/)。 | +| `static/centos-icon.svg` | [CentOS 官网图形标识](https://www.centos.org/assets/img/centos-symbol.svg) | 保留官方图形及颜色;参阅 [CentOS 商标指南](https://www.centos.org/legal/trademarks/)。 | +| `static/ubuntu-icon.svg` | [Canonical 官方 Circle of Friends SVG](https://assets.ubuntu.com/v1/ce518a18-CoF-2022_solid+O.svg) | 保留官方图形及颜色;参阅 [Canonical 知识产权政策](https://canonical.com/legal/intellectual-property-policy)。 | + +目前后端仍只允许导入 AlmaLinux 9/10 镜像。预存另外三个图标不等于已开放对应系统的镜像导入、创建或销售。未来正式提供商业套餐前,应核对相应镜像的再分发条件和商标使用要求,尤其是 CentOS 的商业使用限制。 diff --git a/README.md b/README.md index e05b6663..983e8df8 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ SELECT id, username, email FROM users WHERE id = 1; ## 公网云镜像模板创建(无需手动安装) -创建与重装页面的 AlmaLinux 标识使用随项目保存的[官方圆形图标 SVG](https://almalinux.org/branding/AlmaLinux%20Icon%20Circle.svg),页面运行时不会从外网加载图标。该标识仅用于识别系统镜像;本面板并非 AlmaLinux OS Foundation 官方产品。 +面板随项目预存 AlmaLinux、Debian、CentOS 和 Ubuntu 的官方图标,页面运行时不会从外网加载图标;来源与使用说明见 [ICON-SOURCES.md](ICON-SOURCES.md)。图标仅用于识别真实的系统模板,不表示发行版项目认可本面板。当前后端仍只允许导入 AlmaLinux 9/10 镜像,预存其他图标并未开放相应系统的导入或销售。 面板的“创建虚拟机”有独立的“公网云镜像”方式。先在宿主机设置中选择已工作的 Linux 网桥,例如 `bridge:br0`。只有管理员可进入侧栏的“云镜像模板”页面,填写 [AlmaLinux 官方 Generic Cloud qcow2 镜像](https://wiki.almalinux.org/cloud/Generic-cloud)在 `https://repo.almalinux.org/almalinux/9/cloud/x86_64/images/` 或 `https://repo.almalinux.org/almalinux/10/cloud/x86_64/images/` 下的下载地址、发布方 SHA-256 和模板显示名;已保存的显示名也可在该页修改。地址必须是官方 HTTPS 直链,面板不会跟随重定向。面板服务器 A 需要能访问该地址。导入在后台运行,一次只允许一个任务,面板下载、校验 SHA-256 后通过当前 libvirt SSH 连接把模板镜像上传到 B 的磁盘池;无需登录 B 手工复制。模板目录记录加密保存在 MariaDB,绑定当前宿主机身份和磁盘池。改名不会改动镜像文件、模板 ID 或已经创建的虚拟机的系统名称记录,只影响后续创建和重装时的显示。普通用户只能在创建或重装页面从已导入的镜像卡片中选择具体版本,不能导入或改名。不要在导入期间关闭面板进程;若进程异常退出,运行中的导入任务记录不会恢复,可能需要检查项目 `data/` 中的 `.cloud-image-*` 临时文件和 B 磁盘池中 `panel-template-*` 卷,不要未经核对就删除。 diff --git a/static/app.js b/static/app.js index 7b6d2347..a6214167 100644 --- a/static/app.js +++ b/static/app.js @@ -1922,10 +1922,28 @@ async function loadResources() { } } +const TEMPLATE_FAMILY_NAMES = { + almalinux: "AlmaLinux", + debian: "Debian", + centos: "CentOS", + centosstream: "CentOS", + ubuntu: "Ubuntu", +}; + +const TEMPLATE_ICON_PATHS = { + AlmaLinux: "/static/almalinux-icon.svg", + Debian: "/static/debian-icon.svg", + CentOS: "/static/centos-icon.svg", + Ubuntu: "/static/ubuntu-icon.svg", +}; + function templateSystem(item) { const id = String(item?.id || ""); - const family = String(item?.os_family || "").toLowerCase() === "almalinux" || /^alma(?:9|10)-/.test(id) - ? "AlmaLinux" : "其他系统"; + const familyKey = String(item?.os_family || "").trim().toLowerCase().replace(/[\s_-]+/g, ""); + const namedFamily = Object.prototype.hasOwnProperty.call(TEMPLATE_FAMILY_NAMES, familyKey) + ? TEMPLATE_FAMILY_NAMES[familyKey] : ""; + const family = namedFamily + || (/^alma(?:9|10)-/.test(id) ? "AlmaLinux" : "其他系统"); const oldVersion = /^alma(9|10)-/.exec(id)?.[1] || ""; const version = /^[0-9]+$/.test(String(item?.os_version || "")) ? String(item.os_version) : oldVersion; @@ -1933,11 +1951,12 @@ function templateSystem(item) { } function templateIcon(family, className) { - const icon = makeElement("span", `${className}${family === "AlmaLinux" ? " alma" : ""}`); + const logoPath = TEMPLATE_ICON_PATHS[family]; + const icon = makeElement("span", `${className}${logoPath ? " system" : ""}`); icon.setAttribute("aria-hidden", "true"); - if (family === "AlmaLinux") { - const logo = makeElement("img", "template-almalinux-logo"); - logo.src = "/static/almalinux-icon.svg"; + if (logoPath) { + const logo = makeElement("img", "template-system-logo"); + logo.src = logoPath; logo.alt = ""; icon.append(logo); } else { diff --git a/static/centos-icon.svg b/static/centos-icon.svg new file mode 100644 index 00000000..ba433b4e --- /dev/null +++ b/static/centos-icon.svg @@ -0,0 +1 @@ + diff --git a/static/debian-icon.svg b/static/debian-icon.svg new file mode 100644 index 00000000..7fa03875 --- /dev/null +++ b/static/debian-icon.svg @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + diff --git a/static/index.html b/static/index.html index d41d612c..bbe602b8 100644 --- a/static/index.html +++ b/static/index.html @@ -5,8 +5,8 @@ VirtPilot · 虚拟机管理 - - + +
diff --git a/static/styles.css b/static/styles.css index e2cd364b..48143070 100644 --- a/static/styles.css +++ b/static/styles.css @@ -142,8 +142,8 @@ tbody tr:hover{background:#fcfefe} .workspace-form-page{width:min(100%,900px);margin:0 auto 48px}.workspace-form-back{padding-left:0;margin-bottom:15px;min-height:34px}.workspace-form-heading{margin-bottom:22px}.workspace-form-heading h1{margin-top:8px}.workspace-form-card{overflow:hidden}.workspace-form-body{padding:28px clamp(22px,3vw,36px) 32px}.workspace-form-actions{display:flex;justify-content:flex-end;flex-wrap:wrap;gap:10px;padding:18px clamp(22px,3vw,36px);border-top:1px solid #edf1f5;background:#fbfdfe}.workspace-form-actions .button{min-width:120px}.workspace-form-body>.form-error{margin:18px 0 0} .form-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:18px 17px}.field.full{grid-column:1/-1}.field label{display:block}.field label span{color:#dc5965}.field small{display:block;color:#a1adbb;font-size:10px;margin-top:7px;line-height:1.5}.field select{appearance:none;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2393a1ae' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right 12px center;padding-right:35px} .create-source-picker{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px;border:0;padding:0;margin:0 0 23px;min-width:0}.create-source-picker legend{color:#34445a;font-size:13px;font-weight:700;padding:0;margin-bottom:10px}.create-source-picker label{position:relative;display:block;cursor:pointer}.create-source-picker input{position:absolute;opacity:0;width:1px;height:1px}.create-source-picker label span{display:block;border:1px solid #dce4eb;border-radius:9px;padding:12px 14px;min-height:65px;background:#fff}.create-source-picker input:checked+span{border-color:#3bb5bc;background:#effafa;box-shadow:0 0 0 2px rgba(20,166,175,.08)}.create-source-picker input:focus-visible+span{outline:3px solid rgba(18,166,176,.22);outline-offset:2px}.create-source-picker strong{display:block;color:#334a5f;font-size:12px}.create-source-picker small{display:block;color:#8999a8;font-size:10px;margin-top:5px} -.template-field-label{display:block;color:#34445a;font-size:13px;font-weight:700;margin-bottom:10px}.template-field-label span{color:#dc5965}.template-catalog{display:grid;grid-template-columns:repeat(auto-fill,minmax(210px,1fr));gap:14px}.template-catalog-empty{grid-column:1/-1;margin:0;padding:17px;border:1px dashed #cbdbe3;border-radius:10px;background:#f8fbfc;color:#698094;font-size:12px}.template-family-card{min-width:0;border:1px solid #dce7ec;border-radius:12px;background:#fff;overflow:hidden}.template-family-card[open]{border-color:#46b6ba;box-shadow:0 0 0 2px rgba(20,166,175,.07)}.template-family-summary{display:flex;align-items:center;flex-direction:column;gap:9px;min-height:153px;padding:20px 13px 13px;cursor:pointer;text-align:center;list-style:none}.template-family-summary::-webkit-details-marker{display:none}.template-family-summary:focus-visible{outline:3px solid rgba(18,166,176,.22);outline-offset:-3px}.template-family-summary strong{color:#30465a;font-size:13px}.template-family-icon{display:flex;align-items:center;justify-content:center;width:65px;height:65px;border-radius:17px;background:linear-gradient(145deg,#2a6385,#173d58);color:#fff;font-size:31px;font-weight:800;box-shadow:0 6px 16px rgba(24,68,90,.15)}.template-family-icon.alma{background:conic-gradient(from 35deg,#32bac4 0 28%,#5277cb 28% 51%,#e7ad54 51% 72%,#3ea67b 72% 100%);border:5px solid #f5faf9;color:#fff;text-shadow:0 1px 4px rgba(8,45,65,.35)}.template-family-arrow{color:#258f9b;font-size:20px;line-height:1;transition:transform .2s}.template-family-card[open] .template-family-arrow{transform:rotate(180deg)}.template-versions{display:grid;gap:7px;padding:12px;border-top:1px solid #e7edf2;background:#fbfdfd}.template-version-option{width:100%;display:grid;gap:3px;padding:11px 12px;border:1px solid #dee8ed;border-radius:8px;background:#fff;text-align:left;color:#344e60}.template-version-option strong{font-size:12px}.template-version-option small{margin:0;color:#899cac;font-size:10px;overflow-wrap:anywhere}.template-version-option[aria-pressed="true"]{border-color:#35afb7;background:#eaf8f8;box-shadow:0 0 0 2px rgba(20,166,175,.09)}.template-version-option:hover{border-color:#48b6bd}.template-admin-grid{display:grid;grid-template-columns:minmax(0,.9fr) minmax(0,1.1fr);align-items:start;gap:19px}.template-admin-grid .host-card{min-width:0}.template-admin-grid .form-stack .button{align-self:flex-start}.template-field-help{display:block;margin:-16px 0 19px;color:#8b9bab;font-size:11px;line-height:1.55}.template-import-status{margin:0 0 14px;padding:10px 12px;border-radius:8px;background:#edf8f8;color:#317c85;font-size:11px;line-height:1.6}.template-admin-list{display:grid;gap:10px}.template-admin-list>.muted{margin:0}.template-admin-row{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:9px 11px;align-items:end;padding:14px;border:1px solid #e0e9ee;border-radius:10px;background:#fbfdfd}.template-admin-row-heading{grid-column:1/-1;display:flex;align-items:center;gap:9px;margin-bottom:3px;color:#34495c;font-size:12px}.template-admin-icon{display:flex;align-items:center;justify-content:center;width:27px;height:27px;border-radius:7px;background:#e3f6f3;color:#138d8f;font-weight:800}.template-admin-row label{grid-column:1/-1;margin:0;color:#75899b;font-size:11px;font-weight:700}.template-admin-row input{width:100%;min-width:0;height:37px;padding:0 10px;border:1px solid #dce4eb;border-radius:7px;background:#fff;color:#20364a;font-size:12px}.template-admin-row .button{min-height:37px}.template-admin-row .form-error{grid-column:1/-1;margin:0} -.template-family-icon.alma,.template-admin-icon.alma{background:transparent;border:0;box-shadow:none;color:inherit;text-shadow:none}.template-almalinux-logo{display:block;width:100%;height:100%;object-fit:contain}.template-version-option{display:flex;align-items:center;justify-content:center;text-align:center}.template-version-option strong{overflow-wrap:anywhere} +.template-field-label{display:block;color:#34445a;font-size:13px;font-weight:700;margin-bottom:10px}.template-field-label span{color:#dc5965}.template-catalog{display:grid;grid-template-columns:repeat(auto-fill,minmax(210px,1fr));gap:14px}.template-catalog-empty{grid-column:1/-1;margin:0;padding:17px;border:1px dashed #cbdbe3;border-radius:10px;background:#f8fbfc;color:#698094;font-size:12px}.template-family-card{min-width:0;border:1px solid #dce7ec;border-radius:12px;background:#fff;overflow:hidden}.template-family-card[open]{border-color:#46b6ba;box-shadow:0 0 0 2px rgba(20,166,175,.07)}.template-family-summary{display:flex;align-items:center;flex-direction:column;gap:9px;min-height:153px;padding:20px 13px 13px;cursor:pointer;text-align:center;list-style:none}.template-family-summary::-webkit-details-marker{display:none}.template-family-summary:focus-visible{outline:3px solid rgba(18,166,176,.22);outline-offset:-3px}.template-family-summary strong{color:#30465a;font-size:13px}.template-family-icon{display:flex;align-items:center;justify-content:center;width:65px;height:65px;border-radius:17px;background:linear-gradient(145deg,#2a6385,#173d58);color:#fff;font-size:31px;font-weight:800;box-shadow:0 6px 16px rgba(24,68,90,.15)}.template-family-arrow{color:#258f9b;font-size:20px;line-height:1;transition:transform .2s}.template-family-card[open] .template-family-arrow{transform:rotate(180deg)}.template-versions{display:grid;gap:7px;padding:12px;border-top:1px solid #e7edf2;background:#fbfdfd}.template-version-option{width:100%;display:grid;gap:3px;padding:11px 12px;border:1px solid #dee8ed;border-radius:8px;background:#fff;text-align:left;color:#344e60}.template-version-option strong{font-size:12px}.template-version-option[aria-pressed="true"]{border-color:#35afb7;background:#eaf8f8;box-shadow:0 0 0 2px rgba(20,166,175,.09)}.template-version-option:hover{border-color:#48b6bd}.template-admin-grid{display:grid;grid-template-columns:minmax(0,.9fr) minmax(0,1.1fr);align-items:start;gap:19px}.template-admin-grid .host-card{min-width:0}.template-admin-grid .form-stack .button{align-self:flex-start}.template-field-help{display:block;margin:-16px 0 19px;color:#8b9bab;font-size:11px;line-height:1.55}.template-import-status{margin:0 0 14px;padding:10px 12px;border-radius:8px;background:#edf8f8;color:#317c85;font-size:11px;line-height:1.6}.template-admin-list{display:grid;gap:10px}.template-admin-list>.muted{margin:0}.template-admin-row{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:9px 11px;align-items:end;padding:14px;border:1px solid #e0e9ee;border-radius:10px;background:#fbfdfd}.template-admin-row-heading{grid-column:1/-1;display:flex;align-items:center;gap:9px;margin-bottom:3px;color:#34495c;font-size:12px}.template-admin-icon{display:flex;align-items:center;justify-content:center;width:27px;height:27px;border-radius:7px;background:#e3f6f3;color:#138d8f;font-weight:800}.template-admin-row label{grid-column:1/-1;margin:0;color:#75899b;font-size:11px;font-weight:700}.template-admin-row input{width:100%;min-width:0;height:37px;padding:0 10px;border:1px solid #dce4eb;border-radius:7px;background:#fff;color:#20364a;font-size:12px}.template-admin-row .button{min-height:37px}.template-admin-row .form-error{grid-column:1/-1;margin:0} +.template-family-icon.system,.template-admin-icon.system{background:transparent;border:0;box-shadow:none;color:inherit;text-shadow:none}.template-system-logo{display:block;width:100%;height:100%;object-fit:contain}.template-version-option{display:flex;align-items:center;justify-content:center;text-align:center}.template-version-option strong{overflow-wrap:anywhere} .cloud-fields{grid-column:1/-1;border-top:1px solid #e7edf2;padding-top:18px}.cloud-fields-heading{margin-bottom:17px}.cloud-fields-heading strong{display:block;color:#34445a;font-size:13px}.cloud-fields-heading small{display:block;color:#8798a7;font-size:10px;line-height:1.6;margin-top:6px} .vm-auto-public-pool{display:grid;gap:5px;margin:0 0 18px;padding:13px 15px;border:1px solid #cce9e0;border-radius:9px;background:#f0fbf8}.vm-auto-public-pool strong{font-size:12px;color:#217d6e}.vm-auto-public-pool span{font-size:11px;line-height:1.6;color:#5b837a}.vm-cloud-auth-fields{margin-top:18px} .input-suffix{position:relative}.input-suffix input{padding-right:48px}.input-suffix span{position:absolute;right:13px;top:13px;color:#97a4b2;font-size:12px} diff --git a/static/ubuntu-icon.svg b/static/ubuntu-icon.svg new file mode 100644 index 00000000..89b79e94 --- /dev/null +++ b/static/ubuntu-icon.svg @@ -0,0 +1 @@ + diff --git a/tests/test_template_frontend.py b/tests/test_template_frontend.py index e9e4d919..ee086571 100644 --- a/tests/test_template_frontend.py +++ b/tests/test_template_frontend.py @@ -6,6 +6,7 @@ from dataclasses import dataclass from html.parser import HTMLParser from pathlib import Path import re +from xml.etree import ElementTree import pytest @@ -117,20 +118,33 @@ def test_catalog_renders_expandable_family_and_version_cards() -> None: assert 'input.value = id;' in script -def test_almalinux_cards_use_local_vector_logo_instead_of_letter_placeholder() -> None: +@pytest.mark.parametrize( + ("family", "filename"), + [ + ("AlmaLinux", "almalinux-icon.svg"), + ("Debian", "debian-icon.svg"), + ("CentOS", "centos-icon.svg"), + ("Ubuntu", "ubuntu-icon.svg"), + ], +) +def test_system_cards_use_bundled_vector_logos(family: str, filename: str) -> None: script = (STATIC / "app.js").read_text(encoding="utf-8") - logo = STATIC / "almalinux-icon.svg" + logo = STATIC / filename assert logo.is_file() artwork = logo.read_text(encoding="utf-8") - assert " None: + script = (STATIC / "app.js").read_text(encoding="utf-8") + names = script.split("const TEMPLATE_FAMILY_NAMES = {", 1)[1].split("};", 1)[0] + for metadata, family in ( + ("debian", "Debian"), + ("centos", "CentOS"), + ("centosstream", "CentOS"), + ("ubuntu", "Ubuntu"), + ): + assert f'{metadata}: "{family}"' in names + system_code = script.split("function templateSystem(item) {", 1)[1].split( + "function templateIcon(family, className) {", 1 + )[0] + assert "item?.os_family" in system_code + assert "TEMPLATE_FAMILY_NAMES[familyKey]" in system_code def test_version_cards_show_only_centered_template_name() -> None: