mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-08 07:50:28 +08:00
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
|
|
package servers
|
||
|
|
|
||
|
|
import (
|
||
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/serverutils"
|
||
|
|
"github.com/iwind/TeaGo/actions"
|
||
|
|
"github.com/iwind/TeaGo/maps"
|
||
|
|
"regexp"
|
||
|
|
"strings"
|
||
|
|
)
|
||
|
|
|
||
|
|
type AddPortPopupAction struct {
|
||
|
|
actionutils.ParentAction
|
||
|
|
}
|
||
|
|
|
||
|
|
func (this *AddPortPopupAction) Init() {
|
||
|
|
this.Nav("", "", "")
|
||
|
|
}
|
||
|
|
|
||
|
|
func (this *AddPortPopupAction) RunGet(params struct {
|
||
|
|
ServerType string
|
||
|
|
}) {
|
||
|
|
this.Data["protocols"] = serverutils.AllServerProtocolsForType(params.ServerType)
|
||
|
|
|
||
|
|
this.Show()
|
||
|
|
}
|
||
|
|
|
||
|
|
func (this *AddPortPopupAction) RunPost(params struct {
|
||
|
|
Protocol string
|
||
|
|
Address string
|
||
|
|
|
||
|
|
Must *actions.Must
|
||
|
|
}) {
|
||
|
|
// 校验地址
|
||
|
|
addr := maps.Map{
|
||
|
|
"protocol": params.Protocol,
|
||
|
|
"host": "",
|
||
|
|
"portRange": "",
|
||
|
|
}
|
||
|
|
|
||
|
|
// TODO 判断端口不能小于1
|
||
|
|
// TODO 判断端口号不能大于65535
|
||
|
|
|
||
|
|
digitRegexp := regexp.MustCompile(`^\d+$`)
|
||
|
|
if digitRegexp.MatchString(params.Address) {
|
||
|
|
addr["portRange"] = params.Address
|
||
|
|
} else if strings.Contains(params.Address, ":") {
|
||
|
|
index := strings.LastIndex(params.Address, ":")
|
||
|
|
addr["host"] = strings.TrimSpace(params.Address[:index])
|
||
|
|
port := strings.TrimSpace(params.Address[index+1:])
|
||
|
|
if !digitRegexp.MatchString(port) {
|
||
|
|
this.Fail("端口只能是一个数字")
|
||
|
|
}
|
||
|
|
addr["portRange"] = port
|
||
|
|
} else {
|
||
|
|
this.Fail("请输入正确的端口或者网络地址")
|
||
|
|
}
|
||
|
|
|
||
|
|
this.Data["address"] = addr
|
||
|
|
this.Success()
|
||
|
|
}
|