mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-09 00:20:26 +08:00
实现节点自动切换到备用IP
This commit is contained in:
@@ -30,6 +30,7 @@ func init() {
|
|||||||
Post("/showTip", new(ShowTipAction)).
|
Post("/showTip", new(ShowTipAction)).
|
||||||
Post("/hideTip", new(HideTipAction)).
|
Post("/hideTip", new(HideTipAction)).
|
||||||
Post("/theme", new(ThemeAction)).
|
Post("/theme", new(ThemeAction)).
|
||||||
|
Post("/validateIPs", new(ValidateIPsAction)).
|
||||||
|
|
||||||
EndAll()
|
EndAll()
|
||||||
})
|
})
|
||||||
|
|||||||
41
internal/web/actions/default/ui/validateIPs.go
Normal file
41
internal/web/actions/default/ui/validateIPs.go
Normal file
@@ -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()
|
||||||
|
}
|
||||||
@@ -95,10 +95,16 @@ Vue.component("node-ip-address-thresholds-box", {
|
|||||||
"name": "通知",
|
"name": "通知",
|
||||||
"code": "notify",
|
"code": "notify",
|
||||||
"description": "发送已达到阈值通知。"
|
"description": "发送已达到阈值通知。"
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
"name": "切换",
|
||||||
|
"code": "switch",
|
||||||
|
"description": "在DNS中记录中将IP切换到指定的备用IP。"
|
||||||
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
actionCode: "up"
|
actionCode: "up",
|
||||||
|
actionBackupIPs: ""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@@ -280,8 +286,12 @@ Vue.component("node-ip-address-thresholds-box", {
|
|||||||
cancelAction: function () {
|
cancelAction: function () {
|
||||||
this.isAddingAction = false
|
this.isAddingAction = false
|
||||||
this.actionCode = "up"
|
this.actionCode = "up"
|
||||||
|
this.actionBackupIPs = ""
|
||||||
},
|
},
|
||||||
confirmAction: function () {
|
confirmAction: function () {
|
||||||
|
this.doConfirmAction(false)
|
||||||
|
},
|
||||||
|
doConfirmAction: function (validated, options) {
|
||||||
// 是否已存在
|
// 是否已存在
|
||||||
let exists = false
|
let exists = false
|
||||||
let that = this
|
let that = this
|
||||||
@@ -295,9 +305,41 @@ Vue.component("node-ip-address-thresholds-box", {
|
|||||||
return
|
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({
|
this.addingThreshold.actions.push({
|
||||||
action: this.actionCode,
|
action: this.actionCode,
|
||||||
options: {}
|
options: options
|
||||||
})
|
})
|
||||||
|
|
||||||
// 还原
|
// 还原
|
||||||
@@ -322,14 +364,16 @@ Vue.component("node-ip-address-thresholds-box", {
|
|||||||
|
|
||||||
<!-- 已有条件 -->
|
<!-- 已有条件 -->
|
||||||
<div v-if="thresholds.length > 0">
|
<div v-if="thresholds.length > 0">
|
||||||
<div class="ui label basic small" v-for="(threshold, index) in thresholds" style="margin-bottom: 0.5em; font-weight: normal">
|
<div class="ui label basic small" v-for="(threshold, index) in thresholds">
|
||||||
<span v-for="(item, itemIndex) in threshold.items">[{{item.duration}}{{itemDurationUnitName(item.durationUnit)}}] {{itemName(item.item)}}
|
<span v-for="(item, itemIndex) in threshold.items">[{{item.duration}}{{itemDurationUnitName(item.durationUnit)}}] {{itemName(item.item)}}
|
||||||
<!-- 连通性 -->
|
<!-- 连通性 -->
|
||||||
<span v-if="item.item == 'connectivity' && item.options != null && item.options.groups != null && item.options.groups.length > 0">[<span v-for="(group, groupIndex) in item.options.groups">{{group.name}} <span v-if="groupIndex != item.options.groups.length - 1"> </span></span>]</span>
|
<span v-if="item.item == 'connectivity' && item.options != null && item.options.groups != null && item.options.groups.length > 0">[<span v-for="(group, groupIndex) in item.options.groups">{{group.name}} <span v-if="groupIndex != item.options.groups.length - 1"> </span></span>]</span>
|
||||||
|
|
||||||
<span class="grey">[{{itemOperatorName(item.operator)}}]</span> {{item.value}}{{itemUnitName(item.item)}} <span v-if="itemIndex != threshold.items.length - 1" style="font-style: italic">AND </span></span>
|
<span class="grey">[{{itemOperatorName(item.operator)}}]</span> {{item.value}}{{itemUnitName(item.item)}} <span v-if="itemIndex != threshold.items.length - 1" style="font-style: italic">AND </span></span>
|
||||||
->
|
->
|
||||||
<span v-for="(action, actionIndex) in threshold.actions">{{actionName(action.action)}} <span v-if="actionIndex != threshold.actions.length - 1" style="font-style: italic">AND </span></span>
|
<span v-for="(action, actionIndex) in threshold.actions">{{actionName(action.action)}}
|
||||||
|
<span v-if="action.action == 'switch'">到{{action.options.ips.join(", ")}}</span>
|
||||||
|
<span v-if="actionIndex != threshold.actions.length - 1" style="font-style: italic">AND </span></span>
|
||||||
|
|
||||||
<a href="" title="修改" @click.prevent="update(index)"><i class="icon pencil small"></i></a>
|
<a href="" title="修改" @click.prevent="update(index)"><i class="icon pencil small"></i></a>
|
||||||
<a href="" title="删除" @click.prevent="remove(index)"><i class="icon small remove"></i></a>
|
<a href="" title="删除" @click.prevent="remove(index)"><i class="icon small remove"></i></a>
|
||||||
@@ -419,6 +463,7 @@ Vue.component("node-ip-address-thresholds-box", {
|
|||||||
<div>
|
<div>
|
||||||
<div v-for="(action, index) in addingThreshold.actions" class="ui label basic small" style="margin-bottom: 0.5em">
|
<div v-for="(action, index) in addingThreshold.actions" class="ui label basic small" style="margin-bottom: 0.5em">
|
||||||
{{actionName(action.action)}}
|
{{actionName(action.action)}}
|
||||||
|
<span v-if="action.action == 'switch'">到{{action.options.ips.join(", ")}}</span>
|
||||||
<a href="" title="删除" @click.prevent="removeAction(index)"><i class="icon remove small"></i></a>
|
<a href="" title="删除" @click.prevent="removeAction(index)"><i class="icon remove small"></i></a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -435,6 +480,13 @@ Vue.component("node-ip-address-thresholds-box", {
|
|||||||
<p class="comment" v-for="action in allActions" v-if="action.code == actionCode">{{action.description}}</p>
|
<p class="comment" v-for="action in allActions" v-if="action.code == actionCode">{{action.description}}</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr v-if="actionCode == 'switch'">
|
||||||
|
<td>备用IP *</td>
|
||||||
|
<td>
|
||||||
|
<textarea rows="2" v-model="actionBackupIPs" ref="actionBackupIPs"></textarea>
|
||||||
|
<p class="comment">每行一个备用IP。</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<div style="margin-top: 0.8em">
|
<div style="margin-top: 0.8em">
|
||||||
<button class="ui button tiny" type="button" @click.prevent="confirmAction">确定</button>
|
<button class="ui button tiny" type="button" @click.prevent="confirmAction">确定</button>
|
||||||
|
|||||||
@@ -139,14 +139,16 @@ Vue.component("node-ip-address-thresholds-view", {
|
|||||||
template: `<div>
|
template: `<div>
|
||||||
<!-- 已有条件 -->
|
<!-- 已有条件 -->
|
||||||
<div v-if="thresholds.length > 0">
|
<div v-if="thresholds.length > 0">
|
||||||
<div class="ui label basic small" v-for="(threshold, index) in thresholds" style="margin-bottom: 0.5em; font-weight: normal">
|
<div class="ui label basic small" v-for="(threshold, index) in thresholds" style="margin-bottom: 0.5em">
|
||||||
<span v-for="(item, itemIndex) in threshold.items">[{{item.duration}}{{itemDurationUnitName(item.durationUnit)}}] {{itemName(item.item)}}
|
<span v-for="(item, itemIndex) in threshold.items">[{{item.duration}}{{itemDurationUnitName(item.durationUnit)}}] {{itemName(item.item)}}
|
||||||
<!-- 连通性 -->
|
<!-- 连通性 -->
|
||||||
<span v-if="item.item == 'connectivity' && item.options != null && item.options.groups != null && item.options.groups.length > 0">[<span v-for="(group, groupIndex) in item.options.groups">{{group.name}} <span v-if="groupIndex != item.options.groups.length - 1"> </span></span>]</span>
|
<span v-if="item.item == 'connectivity' && item.options != null && item.options.groups != null && item.options.groups.length > 0">[<span v-for="(group, groupIndex) in item.options.groups">{{group.name}} <span v-if="groupIndex != item.options.groups.length - 1"> </span></span>]</span>
|
||||||
|
|
||||||
<span class="grey">[{{itemOperatorName(item.operator)}}]</span> {{item.value}}{{itemUnitName(item.item)}} <span v-if="itemIndex != threshold.items.length - 1" style="font-style: italic">AND </span></span>
|
<span class="grey">[{{itemOperatorName(item.operator)}}]</span> {{item.value}}{{itemUnitName(item.item)}} <span v-if="itemIndex != threshold.items.length - 1" style="font-style: italic">AND </span></span>
|
||||||
->
|
->
|
||||||
<span v-for="(action, actionIndex) in threshold.actions">{{actionName(action.action)}} <span v-if="actionIndex != threshold.actions.length - 1" style="font-style: italic">AND </span></span>
|
<span v-for="(action, actionIndex) in threshold.actions">{{actionName(action.action)}}
|
||||||
|
<span v-if="action.action == 'switch'">到{{action.options.ips.join(", ")}}</span>
|
||||||
|
<span v-if="actionIndex != threshold.actions.length - 1" style="font-style: italic">AND </span></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>`
|
</div>`
|
||||||
|
|||||||
@@ -13,6 +13,9 @@
|
|||||||
<td>
|
<td>
|
||||||
<span v-if="!addr.canAccess" class="red">不可访问</span>
|
<span v-if="!addr.canAccess" class="red">不可访问</span>
|
||||||
<span v-else-if="!addr.isOn" class="red">禁用</span>
|
<span v-else-if="!addr.isOn" class="red">禁用</span>
|
||||||
|
<span v-else-if="addr.isUp && addr.backupIP.length > 0" class="orange">备用
|
||||||
|
<br/><span class="grey small">{{addr.backupIP}}</span>
|
||||||
|
</span>
|
||||||
<span v-else-if="addr.isUp" class="green">在线</span>
|
<span v-else-if="addr.isUp" class="green">在线</span>
|
||||||
<span v-else class="red">离线</span>
|
<span v-else class="red">离线</span>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -22,6 +22,9 @@
|
|||||||
<td>
|
<td>
|
||||||
<span v-if="!log.isOn" class="red">停用</span>
|
<span v-if="!log.isOn" class="red">停用</span>
|
||||||
<span v-else-if="!log.canAccess" class="red">不可访问</span>
|
<span v-else-if="!log.canAccess" class="red">不可访问</span>
|
||||||
|
<span v-else-if="log.isUp && log.backupIP.length > 0" class="orange">备用
|
||||||
|
<br/><span class="grey small">{{log.backupIP}}</span>
|
||||||
|
</span>
|
||||||
<span v-else-if="log.isUp" class="green">上线</span>
|
<span v-else-if="log.isUp" class="green">上线</span>
|
||||||
<span v-else class="red">离线</span>
|
<span v-else class="red">离线</span>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -68,6 +68,9 @@
|
|||||||
<td>
|
<td>
|
||||||
<span v-if="!addr.isOn" class="red">禁用</span>
|
<span v-if="!addr.isOn" class="red">禁用</span>
|
||||||
<span v-else-if="!addr.canAccess" class="red">不可访问</span>
|
<span v-else-if="!addr.canAccess" class="red">不可访问</span>
|
||||||
|
<span v-else-if="addr.isUp && addr.backupIP.length > 0" class="orange">备用
|
||||||
|
<br/><span class="grey small">{{addr.backupIP}}</span>
|
||||||
|
</span>
|
||||||
<span v-else-if="addr.isUp" class="green">在线</span>
|
<span v-else-if="addr.isUp" class="green">在线</span>
|
||||||
<span v-else class="red">离线</span>
|
<span v-else class="red">离线</span>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -27,6 +27,9 @@
|
|||||||
<td>
|
<td>
|
||||||
<span v-if="!log.isOn" class="red">停用</span>
|
<span v-if="!log.isOn" class="red">停用</span>
|
||||||
<span v-else-if="!log.canAccess" class="red">不可访问</span>
|
<span v-else-if="!log.canAccess" class="red">不可访问</span>
|
||||||
|
<span v-else-if="log.isUp && log.backupIP.length > 0" class="orange">备用
|
||||||
|
<br/><span class="grey small">{{log.backupIP}}</span>
|
||||||
|
</span>
|
||||||
<span v-else-if="log.isUp" class="green">上线</span>
|
<span v-else-if="log.isUp" class="green">上线</span>
|
||||||
<span v-else class="red">离线</span>
|
<span v-else class="red">离线</span>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
Reference in New Issue
Block a user