mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-25 03:26:34 +08:00
添加源站时校验端口号
This commit is contained in:
@@ -3,9 +3,11 @@ package servers
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
@@ -37,7 +39,7 @@ func (this *AddOriginPopupAction) RunPost(params struct {
|
||||
Field("addr", params.Addr).
|
||||
Require("请输入源站地址")
|
||||
|
||||
addr := params.Addr
|
||||
var addr = params.Addr
|
||||
|
||||
// 是否是完整的地址
|
||||
if (params.Protocol == "http" || params.Protocol == "https") && regexp.MustCompile(`^(http|https)://`).MatchString(addr) {
|
||||
@@ -59,8 +61,26 @@ func (this *AddOriginPopupAction) RunPost(params struct {
|
||||
}
|
||||
portIndex = strings.LastIndex(addr, ":")
|
||||
}
|
||||
host := addr[:portIndex]
|
||||
port := addr[portIndex+1:]
|
||||
var host = addr[:portIndex]
|
||||
var port = addr[portIndex+1:]
|
||||
|
||||
// 检查端口号
|
||||
if port == "0" {
|
||||
this.Fail("端口号不能为0")
|
||||
}
|
||||
if !configutils.HasVariables(port) {
|
||||
// 必须是整数
|
||||
if !regexp.MustCompile(`^\d+$`).MatchString(port) {
|
||||
this.Fail("端口号只能为整数")
|
||||
}
|
||||
var portInt = types.Int(port)
|
||||
if portInt == 0 {
|
||||
this.Fail("端口号不能为0")
|
||||
}
|
||||
if portInt > 65535 {
|
||||
this.Fail("端口号不能大于65535")
|
||||
}
|
||||
}
|
||||
|
||||
resp, err := this.RPC().OriginRPC().CreateOrigin(this.AdminContext(), &pb.CreateOriginRequest{
|
||||
Name: "",
|
||||
@@ -78,7 +98,7 @@ func (this *AddOriginPopupAction) RunPost(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
origin := &serverconfigs.OriginConfig{
|
||||
var origin = &serverconfigs.OriginConfig{
|
||||
Id: resp.OriginId,
|
||||
IsOn: true,
|
||||
Addr: &serverconfigs.NetworkAddressConfig{
|
||||
|
||||
Reference in New Issue
Block a user