-
Notifications
You must be signed in to change notification settings - Fork 4
/
addIP.go
54 lines (44 loc) · 1.09 KB
/
addIP.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2021 GoEdge CDN goedge.cdn@gmail.com. All rights reserved.
package ipbox
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"strings"
"time"
)
type AddIPAction struct {
actionutils.ParentAction
}
func (this *AddIPAction) RunPost(params struct {
ListId int64
Ip string
ExpiredAt int64
}) {
var itemId int64 = 0
defer func() {
this.CreateLogInfo(codes.IPItem_LogCreateIPItem, params.ListId, itemId)
}()
var ipType = "ipv4"
if strings.Contains(params.Ip, ":") {
ipType = "ipv6"
}
if params.ExpiredAt <= 0 {
params.ExpiredAt = time.Now().Unix() + 86400
}
createResp, err := this.RPC().IPItemRPC().CreateIPItem(this.AdminContext(), &pb.CreateIPItemRequest{
IpListId: params.ListId,
IpFrom: params.Ip,
IpTo: "",
ExpiredAt: params.ExpiredAt,
Reason: "从IPBox中加入名单",
Type: ipType,
EventLevel: "critical",
})
if err != nil {
this.ErrorPage(err)
return
}
itemId = createResp.IpItemId
this.Success()
}