From 20bccc39f5f53f9fa8ac37e0394c526d5af3ee01 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sun, 18 Sep 2022 14:57:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=8A=82=E7=82=B9=E6=97=B6?= =?UTF-8?q?=E5=B0=9D=E8=AF=95=E8=87=AA=E5=8A=A8=E4=BB=8E=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E4=B8=AD=E8=AF=BB=E5=8F=96IP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/clusters/cluster/createNode.go | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/internal/web/actions/default/clusters/cluster/createNode.go b/internal/web/actions/default/clusters/cluster/createNode.go index 8f4fe246..dd300878 100644 --- a/internal/web/actions/default/clusters/cluster/createNode.go +++ b/internal/web/actions/default/clusters/cluster/createNode.go @@ -11,6 +11,8 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/maps" + "net" + "regexp" "strconv" "strings" ) @@ -122,7 +124,7 @@ func (this *CreateNodeAction) RunPost(params struct { } // IP地址 - ipAddresses := []maps.Map{} + var ipAddresses = []maps.Map{} if len(params.IpAddressesJSON) > 0 { err := json.Unmarshal(params.IpAddressesJSON, &ipAddresses) if err != nil { @@ -131,10 +133,29 @@ func (this *CreateNodeAction) RunPost(params struct { } } if len(ipAddresses) == 0 { - this.Fail("请至少输入一个IP地址") + // 检查Name中是否包含IP + var ipv4Reg = regexp.MustCompile(`\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}`) + var ipMatches = ipv4Reg.FindStringSubmatch(params.Name) + if len(ipMatches) > 0 { + var nodeIP = ipMatches[0] + if net.ParseIP(nodeIP) != nil { + ipAddresses = []maps.Map{ + { + "ip": nodeIP, + "canAccess": true, + "isOn": true, + "isUp": true, + }, + } + } + } + + if len(ipAddresses) == 0 { + this.Fail("请至少输入一个IP地址") + } } - dnsRouteCodes := []string{} + var dnsRouteCodes = []string{} if len(params.DnsRoutesJSON) > 0 { err := json.Unmarshal(params.DnsRoutesJSON, &dnsRouteCodes) if err != nil { @@ -144,7 +165,7 @@ func (this *CreateNodeAction) RunPost(params struct { } // TODO 检查登录授权 - loginInfo := &pb.NodeLogin{ + var loginInfo = &pb.NodeLogin{ Id: 0, Name: "SSH", Type: "ssh", @@ -169,7 +190,7 @@ func (this *CreateNodeAction) RunPost(params struct { this.ErrorPage(err) return } - nodeId := createResp.NodeId + var nodeId = createResp.NodeId // IP地址 var resultIPAddresses = []string{}