Files
console-dev/app/components/instance/InstanceNetwork.vue
T

932 lines
33 KiB
Vue

<script>
/** 实例网络与安全面板:合并 IP 展示、模块流量、域名白名单能力及快快云内网 IP 分配。 */
import "~/assets/styles/MfCloudDefence.B2vl5Yip.css";
import "~/assets/styles/MfCloudVpc.CpOEbuWs.css";
import "~/assets/styles/MfCloudIps.jhFnuvcs.css";
import "~/assets/styles/InstanceTraffic.CyyEAXl3.css";
import "~/assets/styles/FlowPacketPanel.-RJSx13z.css";
import "~/assets/styles/InstanceNetwork.CyucZaZp.css";
import { toDisplayString } from "vue";
import { renderList } from "vue";
import { onMounted } from "vue";
import { onBeforeUnmount } from "vue";
import { watch } from "vue";
import { createBlock } from "vue";
import { ref } from "vue";
import { withCtx } from "vue";
import { createCommentVNode } from "vue";
import { computed } from "vue";
import { createElementBlock } from "vue";
import { Fragment } from "vue";
import { createElementVNode } from "vue";
import { createTextVNode } from "vue";
import { unref } from "vue";
import { defineComponent } from "vue";
import { createVNode } from "vue";
import { openBlock } from "vue";
import { NuxtLink } from "#components";
import { useApi } from "~/lib/auth.js";
import button from "primevue/button";
import { t as _plugin_vue_export_helper_t } from "~/lib/_plugin-vue_export-helper.js";
import OperationNotice from "~/components/OperationNotice.vue";
import { n as configuration_display_n } from "~/lib/configuration-display.js";
import { i as cloud_instance_management_i } from "~/lib/cloud-instance-management.js";
import FlowPacketPanel from "~/components/instance/FlowPacketPanel.vue";
import InstanceTraffic from "~/components/instance/InstanceTraffic.vue";
import MfCloudIps from "~/components/mfcloud/MfCloudIps.vue";
import MfCloudVpc from "~/components/mfcloud/MfCloudVpc.vue";
import MfCloudDefence from "~/components/mfcloud/MfCloudDefence.vue";
var ce = {
class: `nw`,
},
le = {
class: `block`,
},
ue = {
class: `block-desc`,
},
de = {
class: `info-table`,
},
fe = {
class: `kv`,
},
pe = {
class: `kv`,
},
me = {
key: 0,
class: `kv`,
},
he = {
class: `kv`,
},
ge = {
class: `kv`,
},
_e = {
key: 0,
class: `block-desc`,
},
ve = {
class: `block`,
},
ye = {
key: 1,
class: `info-table`,
},
be = {
class: `col-mono`,
},
xe = {
key: 0,
class: `kv`,
},
Se = {
class: `col-mono`,
},
Ce = {
key: 1,
class: `kv`,
},
we = {
class: `action-cell`,
},
Te = {
key: 0,
class: `sub`,
},
Ee = {
key: 2,
class: `kv`,
},
De = {
key: 1,
class: `block`,
},
Oe = {
class: `block`,
},
ke = {
class: `info-table`,
},
Ae = {
key: 0,
class: `kv`,
},
S = {
class: `kv`,
},
C = {
class: `action-cell`,
},
je = {
key: 3,
class: `block`,
},
Me = {
class: `info-table`,
},
Ne = {
class: `kv`,
},
Pe = {
key: 0,
},
Fe = {
key: 1,
},
Ie = {
key: 2,
},
Le = {
class: `kv`,
},
w = {
class: `action-cell`,
},
Re = {
key: 4,
class: `block`,
role: `status`,
},
ze = {
class: `block-desc`,
},
T = Object.assign(
_plugin_vue_export_helper_t(
defineComponent({
__name: `InstanceNetwork`,
props: {
info: {},
hostId: {},
productId: {},
module: {},
caps: {},
},
emits: [`pay`, `refresh`],
setup(h, { emit: y }) {
let T = h,
E = y,
D = useApi(),
O = computed(() => configuration_display_n(T.module, T.info.raw)),
k = computed(() => cloud_instance_management_i(T.module)),
A = ref([]),
Be = computed(() => [...new Set([...T.info.ips, ...A.value])]);
watch(
() => [T.hostId, T.module],
() => {
A.value = [];
},
);
let j = ref(!1),
M = ref(``),
N = ref(``),
P = ref(!1),
F = ref(``),
I = computed(() =>
String(T.info.raw.intranet_ip || F.value || ``).trim(),
),
L = computed(
() =>
T.module === `kky_ecs` &&
!I.value &&
T.caps.upgrade !== !1 &&
[`on`, `off`].includes(T.info.powerStatus) &&
!P.value,
),
R = 0,
z = !1;
function B() {
(++R,
(j.value = !1),
(P.value = !1),
(F.value = ``),
(M.value = ``),
(N.value = ``));
}
async function Ve() {
// 仅无内网 IP 且电源状态允许的快快云实例可申请;接口未返回地址时显示处理中而非重复申请。
if (z || j.value || !L.value) return;
let e = T.hostId,
t = ++R,
n = () =>
!z && t === R && T.hostId === e && T.module === `kky_ecs`;
((j.value = !0), (M.value = ``), (N.value = ``));
try {
let t = await D.post(`/kky_ecs/upgrade/${e}/add_intranet_ip`);
if (!n()) return;
((F.value = String(t?.intranet_ip || ``).trim()),
(P.value = !0),
(N.value = F.value
? `内网 IP 已添加`
: `内网 IP 分配请求已提交,请稍后刷新查看`),
F.value && E(`refresh`));
} catch (e) {
n() &&
(M.value =
e instanceof Error
? e.message
: `添加内网 IP 失败,请稍后重试`);
} finally {
n() && (j.value = !1);
}
}
watch(() => [T.hostId, T.module], B, {
flush: `sync`,
});
let V = computed(() =>
[`mf_cloud`, `remf_cloud`, `remf_finance`].includes(T.module),
),
H = ref(null),
U = ref(!1),
W = ref(!1),
G = ref(`loading`),
K = ref(null),
q = ref(``),
J = ref(``);
function He(e) {
return e.status === 1
? `已通过`
: e.status === -1
? `已驳回`
: e.need_review
? `等待人工审核`
: `处理中`;
}
let Y = 0,
X = 0;
function Ue(e) {
return (
typeof e == `object` &&
!!e &&
`status` in e &&
Number(e.status) === 400 &&
`message` in e &&
String(e.message).includes(`该商品暂不支持域名过白`)
);
}
async function Z(e) {
// 先确认白名单能力,再读最新记录;明确“不支持”与网络/协议错误必须分别展示。
let t = ++X,
n = () => t === X && T.hostId === e;
((G.value = `loading`),
(K.value = null),
(q.value = ``),
(J.value = ``));
try {
if (
(await D.get(`/domain_whitelist/form`, {
host_id: e,
}),
!n())
)
return;
G.value = `supported`;
} catch (e) {
if (!n()) return;
if (Ue(e)) {
G.value = `unsupported`;
return;
}
((G.value = `error`),
(q.value =
e instanceof Error
? e.message
: `暂时无法确认域名白名单状态,请重试`));
return;
}
try {
let t = await D.get(`/domain_whitelist/record`, {
host_id: e,
page: 1,
limit: 1,
});
n() && (K.value = t.list?.[0] ?? null);
} catch (e) {
n() &&
(J.value =
e instanceof Error
? e.message
: `读取白名单记录失败,请重试`);
}
}
function Q() {
Z(T.hostId);
}
async function $() {
let e = ++Y,
t = T.hostId;
if (
((H.value = null),
(U.value = !1),
(W.value =
T.caps.traffic !== !1 &&
[`mf_cloud`, `remf_cloud`].includes(T.module)),
T.caps.traffic !== !1 &&
(T.module === `mf_cloud` || T.module === `remf_cloud`))
)
try {
let n = await D.get(`/${T.module}/${t}/flow`);
e === Y && (H.value = n);
} catch {
e === Y && (U.value = !0);
} finally {
e === Y && (W.value = !1);
}
e === Y && (await Z(t));
}
return (
onMounted($),
watch(() => [T.hostId, T.module], $),
onBeforeUnmount(() => {
(Y++, X++, (z = !0), B());
}),
(n, r) => {
let i = MfCloudIps,
o = button,
l = OperationNotice,
v = MfCloudVpc,
y = MfCloudDefence,
b = InstanceTraffic,
x = FlowPacketPanel,
T = NuxtLink;
return (
openBlock(),
createElementBlock(`div`, ce, [
createElementVNode(`section`, le, [
(r[11] ||= createElementVNode(
`h4`,
{
class: `block-title`,
},
`公共网络`,
-1,
)),
createElementVNode(`p`, ue, [
(r[5] ||= createTextVNode(
` 任何人都可以通过公共网络地址访问您的服务器。`,
-1,
)),
h.caps.upgrade === !1
? createCommentVNode(``, !0)
: (openBlock(),
createElementBlock(
Fragment,
{
key: 0,
},
[
createTextVNode(
`若您需要调整带宽上限或流量配额,请前往「计费」进行升降级。`,
),
],
64,
)),
]),
createElementVNode(`div`, de, [
createElementVNode(`div`, fe, [
(r[6] ||= createElementVNode(`span`, null, `区域`, -1)),
createElementVNode(
`b`,
null,
toDisplayString(unref(O).region || `—`),
1,
),
]),
createElementVNode(`div`, pe, [
(r[7] ||= createElementVNode(`span`, null, `线路`, -1)),
createElementVNode(
`b`,
null,
toDisplayString(unref(O).line || `—`),
1,
),
]),
unref(O).networkType
? (openBlock(),
createElementBlock(`div`, me, [
(r[8] ||= createElementVNode(
`span`,
null,
`网络类型`,
-1,
)),
createElementVNode(
`b`,
null,
toDisplayString(unref(O).networkType),
1,
),
]))
: createCommentVNode(``, !0),
createElementVNode(`div`, he, [
(r[9] ||= createElementVNode(
`span`,
null,
`带宽上限`,
-1,
)),
createElementVNode(
`b`,
null,
toDisplayString(
h.info.bw > 0 ? `${h.info.bw} Mbps` : `不限制`,
),
1,
),
]),
createElementVNode(`div`, ge, [
(r[10] ||= createElementVNode(
`span`,
null,
`防护峰值`,
-1,
)),
createElementVNode(
`b`,
null,
toDisplayString(
h.info.protect > 0 ? `${h.info.protect} Gbps` : `—`,
),
1,
),
]),
]),
h.info.protect > 0
? (openBlock(),
createElementBlock(`p`, _e, `在防御峰值内提供保护。`))
: createCommentVNode(``, !0),
]),
createElementVNode(`section`, ve, [
(r[16] ||= createElementVNode(
`h4`,
{
class: `block-title`,
},
`IP 地址`,
-1,
)),
unref(k)
? (openBlock(),
createBlock(
i,
{
key: 0,
"host-id": h.hostId,
module: h.module,
"upgrade-allowed": h.caps.upgrade,
onAddresses: (r[0] ||= (e) => (A.value = e)),
onPay: (r[1] ||= (e) => E(`pay`, e)),
},
null,
8,
[`host-id`, `module`, `upgrade-allowed`],
))
: (openBlock(),
createElementBlock(`div`, ye, [
(openBlock(!0),
createElementBlock(
Fragment,
null,
renderList(
h.info.ips,
(t) => (
openBlock(),
createElementBlock(
`div`,
{
key: t,
class: `kv`,
},
[
(r[12] ||= createElementVNode(
`span`,
null,
`IPv4 地址`,
-1,
)),
createElementVNode(
`b`,
be,
toDisplayString(t),
1,
),
],
)
),
),
128,
)),
unref(I)
? (openBlock(),
createElementBlock(`div`, xe, [
(r[13] ||= createElementVNode(
`span`,
null,
`内网地址`,
-1,
)),
createElementVNode(
`b`,
Se,
toDisplayString(unref(I)),
1,
),
]))
: h.module === `kky_ecs` && h.caps.upgrade !== !1
? (openBlock(),
createElementBlock(`div`, Ce, [
(r[14] ||= createElementVNode(
`span`,
null,
`内网地址`,
-1,
)),
createElementVNode(`div`, we, [
createVNode(
o,
{
label: `添加内网 IP`,
icon: `pi pi-plus`,
size: `small`,
severity: `secondary`,
outlined: ``,
loading: unref(j),
disabled: unref(j) || !unref(L),
onClick: Ve,
},
null,
8,
[`loading`, `disabled`],
),
!unref(L) && !unref(j) && !unref(P)
? (openBlock(),
createElementBlock(
`span`,
Te,
`实例正常开机或关机时可添加`,
))
: createCommentVNode(``, !0),
]),
]))
: createCommentVNode(``, !0),
h.info.ips.length
? createCommentVNode(``, !0)
: (openBlock(),
createElementBlock(`div`, Ee, [
...(r[15] ||= [
createElementVNode(
`span`,
null,
`IPv4 地址`,
-1,
),
createElementVNode(
`b`,
null,
`暂无 IP 地址`,
-1,
),
]),
])),
])),
createVNode(
l,
{
message: unref(M),
severity: `error`,
},
null,
8,
[`message`],
),
createVNode(
l,
{
message: unref(N),
severity: `success`,
},
null,
8,
[`message`],
),
]),
unref(k)
? (openBlock(),
createElementBlock(
Fragment,
{
key: 0,
},
[
createVNode(
v,
{
"host-id": h.hostId,
"product-id": h.productId,
module: h.module,
"network-type": String(
h.info.raw.network_type ?? ``,
),
"data-center-id":
Number(h.info.raw.data_center?.id) || void 0,
active: [`on`, `off`].includes(
h.info.powerStatus,
),
onRefresh: (r[2] ||= (e) => E(`refresh`)),
},
null,
8,
[
`host-id`,
`product-id`,
`module`,
`network-type`,
`data-center-id`,
`active`,
],
),
createVNode(
y,
{
"host-id": h.hostId,
module: h.module,
ips: unref(Be),
active: [`on`, `off`].includes(
h.info.powerStatus,
),
"upgrade-allowed": h.caps.upgrade,
onPay: (r[3] ||= (e) => E(`pay`, e)),
},
null,
8,
[
`host-id`,
`module`,
`ips`,
`active`,
`upgrade-allowed`,
],
),
],
64,
))
: createCommentVNode(``, !0),
h.caps.traffic === !1
? createCommentVNode(``, !0)
: (openBlock(),
createElementBlock(`section`, De, [
(r[17] ||= createElementVNode(
`h4`,
{
class: `block-title`,
},
`网络流量`,
-1,
)),
createVNode(
b,
{
layout: `table`,
module: h.module,
"host-id": h.hostId,
raw: h.info.raw,
flow: unref(H),
loading: unref(W),
failed: unref(U),
},
null,
8,
[
`module`,
`host-id`,
`raw`,
`flow`,
`loading`,
`failed`,
],
),
])),
unref(V)
? (openBlock(),
createBlock(
x,
{
key: 2,
"host-id": h.hostId,
module: h.module,
flow: unref(H),
onPay: (r[4] ||= (e) => E(`pay`, e)),
},
null,
8,
[`host-id`, `module`, `flow`],
))
: createCommentVNode(``, !0),
createElementVNode(`section`, Oe, [
(r[20] ||= createElementVNode(
`h4`,
{
class: `block-title`,
},
`安全组`,
-1,
)),
(r[21] ||= createElementVNode(
`p`,
{
class: `block-desc`,
},
` 安全组是一种虚拟防火墙,用于控制实例级别的入站和出站网络流量。 请确保所选安全组已放通 22 端口(Linux SSH 登录)、3389 端口(Windows 远程登录),否则无法远程登录。 `,
-1,
)),
createElementVNode(`div`, ke, [
unref(V)
? createCommentVNode(``, !0)
: (openBlock(),
createElementBlock(`div`, Ae, [
(r[18] ||= createElementVNode(
`span`,
null,
`当前安全组`,
-1,
)),
createElementVNode(
`b`,
null,
toDisplayString(
h.info.securityGroupName || `未加入安全组`,
),
1,
),
])),
createElementVNode(`div`, S, [
(r[19] ||= createElementVNode(
`span`,
null,
`安全组管理`,
-1,
)),
createElementVNode(`div`, C, [
createVNode(
T,
{
to: `/security/groups`,
},
{
default: withCtx(() => [
createVNode(o, {
as: `span`,
label: `前往安全组管理`,
size: `small`,
severity: `secondary`,
outlined: ``,
icon: `pi pi-shield`,
}),
]),
_: 1,
},
),
]),
]),
]),
]),
unref(G) === `supported`
? (openBlock(),
createElementBlock(`section`, je, [
(r[24] ||= createElementVNode(
`h4`,
{
class: `block-title`,
},
`域名白名单`,
-1,
)),
(r[25] ||= createElementVNode(
`p`,
{
class: `block-desc`,
},
` 使用中国大陆机房提供 HTTP/HTTPS 服务前需要先完成域名过白。白名单仅需提交一级域名,通过后所有子域名均可使用。 `,
-1,
)),
createElementVNode(`div`, Me, [
createElementVNode(`div`, Ne, [
(r[22] ||= createElementVNode(
`span`,
null,
`最近提交`,
-1,
)),
unref(J)
? (openBlock(),
createElementBlock(
`b`,
Pe,
`读取失败:` + toDisplayString(unref(J)),
1,
))
: unref(K)
? (openBlock(),
createElementBlock(
`b`,
Fe,
toDisplayString(
unref(K).domains.join(`、`),
) +
` · ` +
toDisplayString(He(unref(K))),
1,
))
: (openBlock(),
createElementBlock(`b`, Ie, `暂无记录`)),
]),
createElementVNode(`div`, Le, [
(r[23] ||= createElementVNode(
`span`,
null,
`白名单管理`,
-1,
)),
createElementVNode(`div`, w, [
createVNode(
T,
{
to: `/security/domains?host_id=${h.hostId}`,
},
{
default: withCtx(() => [
createVNode(o, {
as: `span`,
label: `前往域名白名单`,
size: `small`,
severity: `secondary`,
outlined: ``,
icon: `pi pi-shield`,
}),
]),
_: 1,
},
8,
[`to`],
),
unref(J)
? (openBlock(),
createBlock(o, {
key: 0,
label: `重试读取`,
size: `small`,
severity: `secondary`,
text: ``,
icon: `pi pi-refresh`,
onClick: Q,
}))
: createCommentVNode(``, !0),
]),
]),
]),
]))
: unref(G) === `error`
? (openBlock(),
createElementBlock(`section`, Re, [
(r[26] ||= createElementVNode(
`h4`,
{
class: `block-title`,
},
`域名白名单`,
-1,
)),
createElementVNode(
`p`,
ze,
toDisplayString(unref(q)),
1,
),
createVNode(o, {
label: `重试`,
size: `small`,
severity: `secondary`,
outlined: ``,
icon: `pi pi-refresh`,
onClick: Q,
}),
]))
: createCommentVNode(``, !0),
])
);
}
);
},
}),
[[`__scopeId`, `data-v-aa906366`]],
),
{
__name: `InstanceNetwork`,
},
);
export {};
export default T;
</script>