添加端口时校验端口范围

This commit is contained in:
刘祥超
2021-05-23 20:03:14 +08:00
parent d5659e627d
commit fbedf3b605
2 changed files with 38 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ import (
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
"regexp"
)
type IndexAction struct {
@@ -87,7 +88,23 @@ func (this *IndexAction) RunPost(params struct {
this.Fail("端口地址解析失败:" + err.Error())
}
// TODO 校验addresses
// 检查端口地址是否正确
for _, addr := range addresses {
err = addr.Init()
if err != nil {
this.Fail("绑定端口校验失败:" + err.Error())
}
if regexp.MustCompile(`^\d+$`).MatchString(addr.PortRange) {
port := types.Int(addr.PortRange)
if port > 65535 {
this.Fail("绑定的端口地址不能大于65535")
}
if port == 80 {
this.Fail("端口80通常是HTTP的端口不能用在HTTPS上")
}
}
}
// 校验SSL
var sslPolicyId = int64(0)