|
|
|
|
@ -10,8 +10,6 @@ const state = {
|
|
|
|
|
opener: null, scroll: null, networkRequest: null,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const canManage = window.ADMIN_CAN_MANAGE === true;
|
|
|
|
|
|
|
|
|
|
function el(tag, className = '', text) {
|
|
|
|
|
const node = document.createElement(tag);
|
|
|
|
|
node.className = className;
|
|
|
|
|
@ -85,7 +83,6 @@ async function api(path, controller) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function mutate(path, body, controller) {
|
|
|
|
|
if (!canManage) throw new Error('当前管理员仅可查看,不能修改实例配置。');
|
|
|
|
|
if (location.protocol !== 'https:' && !['localhost', '127.0.0.1', '[::1]'].includes(location.hostname)) {
|
|
|
|
|
throw new Error('请通过 HTTPS 修改实例网络配置。');
|
|
|
|
|
}
|
|
|
|
|
@ -370,43 +367,25 @@ function networkEditor(vm) {
|
|
|
|
|
const copy = el('div');
|
|
|
|
|
copy.append(el('h3', 'h6 fw-semibold mb-1', '网络配置'), el('p', 'text-muted fs-13 mb-0', '更换公网 IP 会触发一次受控重启,网关和 DNS 由宿主机地址池自动校验。'));
|
|
|
|
|
heading.append(copy);
|
|
|
|
|
if (canManage) {
|
|
|
|
|
const edit = el('button', 'btn btn-light btn-sm', '更换公网 IP');
|
|
|
|
|
edit.type = 'button'; edit.dataset.networkEdit = 'open';
|
|
|
|
|
edit.setAttribute('aria-expanded', 'false');
|
|
|
|
|
heading.append(edit);
|
|
|
|
|
}
|
|
|
|
|
const template = byId('admin-instance-network-controls');
|
|
|
|
|
const controls = template?.content?.cloneNode(true);
|
|
|
|
|
const edit = controls?.querySelector('[data-network-edit="open"]');
|
|
|
|
|
if (edit) heading.append(edit);
|
|
|
|
|
section.append(heading);
|
|
|
|
|
const current = el('div', 'admin-instance-network-current mt-3');
|
|
|
|
|
current.append(el('span', 'text-muted fs-13', '当前公网地址'), el('strong', 'admin-mono', text(vm.public_ip_cidr, vm.public_ip, '未记录')));
|
|
|
|
|
section.append(current);
|
|
|
|
|
const form = el('form', 'admin-instance-network-form mt-3');
|
|
|
|
|
form.hidden = true;
|
|
|
|
|
form.noValidate = true;
|
|
|
|
|
const label = el('label', 'form-label', '新的公网 IP / CIDR');
|
|
|
|
|
const input = el('input', 'form-control', '');
|
|
|
|
|
input.type = 'text'; input.name = 'public_ip_cidr'; input.required = true; input.maxLength = 64;
|
|
|
|
|
input.autocomplete = 'off'; input.spellcheck = false; input.placeholder = '例如 216.236.1.20/24';
|
|
|
|
|
if (controls) section.append(controls);
|
|
|
|
|
const form = section.querySelector('.admin-instance-network-form');
|
|
|
|
|
if (!form) return section;
|
|
|
|
|
const input = form.elements.namedItem('public_ip_cidr');
|
|
|
|
|
const feedback = section.querySelector('.admin-instance-network-feedback');
|
|
|
|
|
const submit = form.querySelector('button[type="submit"]');
|
|
|
|
|
const cancel = form.querySelector('[data-network-edit="cancel"]');
|
|
|
|
|
input.value = String(vm.public_ip_cidr || vm.public_ip || '');
|
|
|
|
|
label.append(input);
|
|
|
|
|
form.append(label, el('p', 'form-text mb-2', '仅允许该宿主机地址池中的可用 IPv4;本操作不会移动实例到其他宿主机。'));
|
|
|
|
|
const feedback = el('p', 'admin-instance-network-feedback text-muted fs-13 mb-2');
|
|
|
|
|
feedback.hidden = true; feedback.setAttribute('role', 'status');
|
|
|
|
|
const actions = el('div', 'd-flex justify-content-end gap-2 flex-wrap');
|
|
|
|
|
const cancel = el('button', 'btn btn-light btn-sm', '取消');
|
|
|
|
|
cancel.type = 'button'; cancel.dataset.networkEdit = 'cancel';
|
|
|
|
|
const submit = el('button', 'btn btn-primary btn-sm', '提交更换');
|
|
|
|
|
submit.type = 'submit';
|
|
|
|
|
actions.append(cancel, submit);
|
|
|
|
|
form.append(feedback, actions);
|
|
|
|
|
section.append(form);
|
|
|
|
|
|
|
|
|
|
if (!canManage) {
|
|
|
|
|
section.append(el('p', 'text-muted fs-12 mt-3 mb-0', '当前管理员仅可查看,超级管理员才可以修改实例网络。'));
|
|
|
|
|
}
|
|
|
|
|
form.addEventListener('submit', async event => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
if (state.networkRequest || !canManage) return;
|
|
|
|
|
if (state.networkRequest) return;
|
|
|
|
|
const value = input.value.trim();
|
|
|
|
|
if (!/^\d{1,3}(?:\.\d{1,3}){3}\/\d{1,2}$/.test(value)) {
|
|
|
|
|
feedback.hidden = false; feedback.className = 'admin-instance-network-feedback text-danger fs-13 mb-2';
|
|
|
|
|
@ -502,12 +481,13 @@ function renderDetail(payload) {
|
|
|
|
|
if (!payload.invoices?.length) invoices.append(el('p', 'text-muted py-3', '暂无关联账单;导入或免计费实例可能没有开通账单。'));
|
|
|
|
|
if (payload.invoices_truncated) invoices.append(el('p', 'text-muted fs-12', '仅展示最近的关联账单。'));
|
|
|
|
|
const control = byId('instance-control-link');
|
|
|
|
|
const link = vm.can_manage && vm.detail_url ? safeLink(vm.detail_url, '') : null;
|
|
|
|
|
control.hidden = !(link instanceof HTMLAnchorElement);
|
|
|
|
|
if (link instanceof HTMLAnchorElement) control.href = link.href;
|
|
|
|
|
byId('instance-detail-permission').textContent = vm.can_manage
|
|
|
|
|
? '电源、VNC、重装等操作在实例控制台进行,继续使用原权限校验与确认步骤。'
|
|
|
|
|
: '当前管理员仅可查看;全局实例操作需超级管理员权限。';
|
|
|
|
|
if (control instanceof HTMLAnchorElement && vm.detail_url) {
|
|
|
|
|
const link = safeLink(vm.detail_url, '');
|
|
|
|
|
if (link instanceof HTMLAnchorElement) {
|
|
|
|
|
control.href = link.href;
|
|
|
|
|
control.hidden = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function lockDetailScroll() {
|
|
|
|
|
@ -542,8 +522,8 @@ async function openDetail(id, opener) {
|
|
|
|
|
const controller = new AbortController();
|
|
|
|
|
state.detailRequest = controller;
|
|
|
|
|
byId('instance-detail-title').textContent = `实例 #${id}`;
|
|
|
|
|
byId('instance-control-link').hidden = true;
|
|
|
|
|
byId('instance-detail-permission').textContent = '当前详情为只读信息。';
|
|
|
|
|
const control = byId('instance-control-link');
|
|
|
|
|
if (control) control.hidden = true;
|
|
|
|
|
tabs.forEach(tab => byId(`instance-panel-${tab}`).replaceChildren());
|
|
|
|
|
chooseTab('basic');
|
|
|
|
|
detailNotice('正在读取详情…');
|
|
|
|
|
|