diff --git a/internal/web/actions/default/ui/init.go b/internal/web/actions/default/ui/init.go index dff32542..fc0543f6 100644 --- a/internal/web/actions/default/ui/init.go +++ b/internal/web/actions/default/ui/init.go @@ -30,6 +30,7 @@ func init() { Post("/showTip", new(ShowTipAction)). Post("/hideTip", new(HideTipAction)). Post("/theme", new(ThemeAction)). + Post("/validateIPs", new(ValidateIPsAction)). EndAll() }) diff --git a/internal/web/actions/default/ui/validateIPs.go b/internal/web/actions/default/ui/validateIPs.go new file mode 100644 index 00000000..484cf06c --- /dev/null +++ b/internal/web/actions/default/ui/validateIPs.go @@ -0,0 +1,41 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package ui + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "net" + "strings" +) + +type ValidateIPsAction struct { + actionutils.ParentAction +} + +func (this *ValidateIPsAction) RunPost(params struct { + Ips string +}) { + var ips = params.Ips + if len(ips) == 0 { + this.Data["ips"] = []string{} + this.Success() + } + + var ipSlice = strings.Split(ips, "\n") + var result = []string{} + for _, ip := range ipSlice { + ip = strings.TrimSpace(ip) + if len(ip) == 0 { + continue + } + data := net.ParseIP(ip) + if len(data) == 0 { + this.Data["failIP"] = ip + this.Fail() + } + result = append(result, ip) + } + + this.Data["ips"] = result + this.Success() +} diff --git a/web/public/js/components/node/node-ip-address-thresholds-box.js b/web/public/js/components/node/node-ip-address-thresholds-box.js index 6152bb74..088161b9 100644 --- a/web/public/js/components/node/node-ip-address-thresholds-box.js +++ b/web/public/js/components/node/node-ip-address-thresholds-box.js @@ -95,10 +95,16 @@ Vue.component("node-ip-address-thresholds-box", { "name": "通知", "code": "notify", "description": "发送已达到阈值通知。" - } + }, + { + "name": "切换", + "code": "switch", + "description": "在DNS中记录中将IP切换到指定的备用IP。" + }, ], - actionCode: "up" + actionCode: "up", + actionBackupIPs: "" } }, methods: { @@ -280,8 +286,12 @@ Vue.component("node-ip-address-thresholds-box", { cancelAction: function () { this.isAddingAction = false this.actionCode = "up" + this.actionBackupIPs = "" }, confirmAction: function () { + this.doConfirmAction(false) + }, + doConfirmAction: function (validated, options) { // 是否已存在 let exists = false let that = this @@ -295,9 +305,41 @@ Vue.component("node-ip-address-thresholds-box", { return } + if (options == null) { + options = {} + } + + switch (this.actionCode) { + case "switch": + if (!validated) { + Tea.action("/ui/validateIPs") + .params({ + "ips": this.actionBackupIPs + }) + .success(function (resp) { + if (resp.data.ips.length == 0) { + teaweb.warn("请输入备用IP", function () { + that.$refs.actionBackupIPs.focus() + }) + return + } + options["ips"] = resp.data.ips + that.doConfirmAction(true, options) + }) + .fail(function (resp) { + teaweb.warn("输入的IP '" + resp.data.failIP + "' 格式不正确,请改正后提交", function () { + that.$refs.actionBackupIPs.focus() + }) + }) + .post() + return + } + break + } + this.addingThreshold.actions.push({ action: this.actionCode, - options: {} + options: options }) // 还原 @@ -322,14 +364,16 @@ Vue.component("node-ip-address-thresholds-box", {
-
+
[{{item.duration}}{{itemDurationUnitName(item.durationUnit)}}] {{itemName(item.item)}} [{{group.name}}   ] [{{itemOperatorName(item.operator)}}]  {{item.value}}{{itemUnitName(item.item)}}  AND   -> - {{actionName(action.action)}}  AND   + {{actionName(action.action)}} + 到{{action.options.ips.join(", ")}} +  AND     @@ -419,6 +463,7 @@ Vue.component("node-ip-address-thresholds-box", {
{{actionName(action.action)}}   + 到{{action.options.ips.join(", ")}}
@@ -435,6 +480,13 @@ Vue.component("node-ip-address-thresholds-box", {

{{action.description}}

+ + 备用IP * + + +

每行一个备用IP。

+ +
  diff --git a/web/public/js/components/node/node-ip-address-thresholds-view.js b/web/public/js/components/node/node-ip-address-thresholds-view.js index 0faa04b8..b12f1e00 100644 --- a/web/public/js/components/node/node-ip-address-thresholds-view.js +++ b/web/public/js/components/node/node-ip-address-thresholds-view.js @@ -139,14 +139,16 @@ Vue.component("node-ip-address-thresholds-view", { template: `
-
+
[{{item.duration}}{{itemDurationUnitName(item.durationUnit)}}] {{itemName(item.item)}} [{{group.name}}   ] [{{itemOperatorName(item.operator)}}] {{item.value}}{{itemUnitName(item.item)}}  AND   -> - {{actionName(action.action)}}  AND   + {{actionName(action.action)}} + 到{{action.options.ips.join(", ")}} +  AND  
` diff --git a/web/views/@default/clusters/ip-addrs/addr/index.html b/web/views/@default/clusters/ip-addrs/addr/index.html index 9de5a80b..f9180ca8 100644 --- a/web/views/@default/clusters/ip-addrs/addr/index.html +++ b/web/views/@default/clusters/ip-addrs/addr/index.html @@ -13,6 +13,9 @@ 不可访问 禁用 + 备用 +
{{addr.backupIP}} +
在线 离线 diff --git a/web/views/@default/clusters/ip-addrs/addr/logs.html b/web/views/@default/clusters/ip-addrs/addr/logs.html index 552283e0..679cbb0b 100644 --- a/web/views/@default/clusters/ip-addrs/addr/logs.html +++ b/web/views/@default/clusters/ip-addrs/addr/logs.html @@ -22,6 +22,9 @@ 停用 不可访问 + 备用 +
{{log.backupIP}} +
上线 离线 diff --git a/web/views/@default/clusters/ip-addrs/index.html b/web/views/@default/clusters/ip-addrs/index.html index 02e73605..93e41595 100644 --- a/web/views/@default/clusters/ip-addrs/index.html +++ b/web/views/@default/clusters/ip-addrs/index.html @@ -68,6 +68,9 @@ 禁用 不可访问 + 备用 +
{{addr.backupIP}} +
在线 离线 diff --git a/web/views/@default/clusters/ip-addrs/logs.html b/web/views/@default/clusters/ip-addrs/logs.html index 4a2f7f94..d3851565 100644 --- a/web/views/@default/clusters/ip-addrs/logs.html +++ b/web/views/@default/clusters/ip-addrs/logs.html @@ -27,6 +27,9 @@ 停用 不可访问 + 备用 +
{{log.backupIP}} +
上线 离线