-
Notifications
You must be signed in to change notification settings - Fork 34
/
security.go
61 lines (51 loc) · 1.19 KB
/
security.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
55
56
57
58
59
60
61
package server
import (
"github.com/TeaWeb/code/teaweb/configs"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/lists"
)
type SecurityAction actions.Action
// 安全设置
func (this *SecurityAction) Run(params struct{}) {
admin := configs.SharedAdminConfig()
this.Data["security"] = admin.Security
this.Data["allowAll"] = lists.ContainsString(admin.Security.Allow, "all")
this.Data["userIP"] = this.RequestRemoteIP()
this.Show()
}
func (this *SecurityAction) RunPost(params struct {
AllowIPs []string
DenyIPs []string
AllowAll bool
}) {
admin := configs.SharedAdminConfig()
if params.AllowAll {
admin.Security.Allow = []string{"all"}
} else {
ips := []string{}
for _, ip := range params.AllowIPs {
if len(ip) > 0 {
ips = append(ips, ip)
}
}
if len(ips) == 0 {
this.Fail("至少要有一个允许访问的IP")
}
admin.Security.Allow = ips
}
{
ips := []string{}
for _, ip := range params.DenyIPs {
if len(ip) > 0 {
ips = append(ips, ip)
}
}
admin.Security.Deny = ips
}
err := admin.Save()
if err != nil {
this.Fail("保存失败:" + err.Error())
}
this.Next("/settings", map[string]interface{}{})
this.Success("保存成功")
}