Files
EdgeAdmin/internal/web/actions/default/nodes/ipAddresses/createPopup.go

62 lines
1.3 KiB
Go
Raw Normal View History

2020-08-21 21:09:42 +08:00
package ipAddresses
import (
2021-08-18 16:19:07 +08:00
"encoding/json"
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
2020-08-21 21:09:42 +08:00
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
2021-08-18 16:19:07 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
2020-08-21 21:09:42 +08:00
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
"net"
2020-08-21 21:09:42 +08:00
)
type CreatePopupAction struct {
actionutils.ParentAction
}
func (this *CreatePopupAction) Init() {
this.Nav("", "", "")
}
2021-08-31 17:24:30 +08:00
func (this *CreatePopupAction) RunGet(params struct {
SupportThresholds bool
}) {
this.Data["supportThresholds"] = params.SupportThresholds
2021-08-18 16:19:07 +08:00
2020-08-21 21:09:42 +08:00
this.Show()
}
func (this *CreatePopupAction) RunPost(params struct {
2021-08-18 16:19:07 +08:00
IP string `alias:"ip"`
CanAccess bool
Name string
ThresholdsJSON []byte
2020-08-21 21:09:42 +08:00
Must *actions.Must
}) {
ip := net.ParseIP(params.IP)
if len(ip) == 0 {
this.Fail("请输入正确的IP")
}
2020-08-21 21:09:42 +08:00
params.Must.
Field("ip", params.IP).
Require("请输入IP地址")
2021-08-18 16:19:07 +08:00
var thresholds = []*nodeconfigs.NodeValueThresholdConfig{}
if teaconst.IsPlus && len(params.ThresholdsJSON) > 0 {
_ = json.Unmarshal(params.ThresholdsJSON, &thresholds)
}
2020-08-21 21:09:42 +08:00
this.Data["ipAddress"] = maps.Map{
2021-08-18 16:19:07 +08:00
"name": params.Name,
"canAccess": params.CanAccess,
"ip": params.IP,
"id": 0,
"isOn": true,
"isUp": true,
"thresholds": thresholds,
2020-08-21 21:09:42 +08:00
}
this.Success()
}