Files
EdgeAdmin/internal/web/actions/default/ui/validateIPs.go

43 lines
744 B
Go
Raw Normal View History

2024-05-17 17:56:37 +08:00
// Copyright 2021 GoEdge CDN goedge.cdn@gmail.com. All rights reserved.
2021-09-13 10:51:16 +08:00
package ui
import (
"net"
"strings"
2024-07-27 15:42:58 +08:00
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
2021-09-13 10:51:16 +08:00
)
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()
}