mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-04 05:00:25 +08:00
实现节点自动切换到备用IP
This commit is contained in:
@@ -30,6 +30,7 @@ func init() {
|
||||
Post("/showTip", new(ShowTipAction)).
|
||||
Post("/hideTip", new(HideTipAction)).
|
||||
Post("/theme", new(ThemeAction)).
|
||||
Post("/validateIPs", new(ValidateIPsAction)).
|
||||
|
||||
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()
|
||||
}
|
||||
Reference in New Issue
Block a user