1.5.0
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
||||
nodethresholds "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/node/settings/thresholds"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/cc"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/http3"
|
||||
networksecurity "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/network-security"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/pages"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/thresholds"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/uam"
|
||||
@@ -53,7 +52,6 @@ func init() {
|
||||
GetPost("/thresholds", new(thresholds.IndexAction)).
|
||||
|
||||
//
|
||||
GetPost("/network-security", new(networksecurity.IndexAction)).
|
||||
|
||||
// 节点设置相关
|
||||
Prefix("/clusters/cluster/node/settings").
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package networksecurity
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "setting", "index")
|
||||
this.SecondMenu("networkSecurity")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
ClusterId int64
|
||||
}) {
|
||||
policyResp, err := this.RPC().NodeClusterRPC().FindNodeClusterNetworkSecurityPolicy(this.AdminContext(), &pb.FindNodeClusterNetworkSecurityPolicyRequest{
|
||||
NodeClusterId: params.ClusterId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var policy = nodeconfigs.NewNetworkSecurityPolicy()
|
||||
if len(policyResp.NetworkSecurityPolicyJSON) > 0 {
|
||||
err = json.Unmarshal(policyResp.NetworkSecurityPolicyJSON, policy)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
this.Data["policy"] = policy
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunPost(params struct {
|
||||
ClusterId int64
|
||||
Status string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
policyResp, err := this.RPC().NodeClusterRPC().FindNodeClusterNetworkSecurityPolicy(this.AdminContext(), &pb.FindNodeClusterNetworkSecurityPolicyRequest{
|
||||
NodeClusterId: params.ClusterId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var policy = nodeconfigs.NewNetworkSecurityPolicy()
|
||||
if len(policyResp.NetworkSecurityPolicyJSON) > 0 {
|
||||
err = json.Unmarshal(policyResp.NetworkSecurityPolicyJSON, policy)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
policy.Status = params.Status
|
||||
|
||||
err = policy.Init()
|
||||
if err != nil {
|
||||
this.Fail("配置校验失败:" + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
policyJSON, err := json.Marshal(policy)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = this.RPC().NodeClusterRPC().UpdateNodeClusterNetworkSecurityPolicy(this.AdminContext(), &pb.UpdateNodeClusterNetworkSecurityPolicyRequest{
|
||||
NodeClusterId: params.ClusterId,
|
||||
NetworkSecurityPolicyJSON: policyJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -44,17 +44,10 @@ func (this *ClusterHelper) filterMenuItems1(items []maps.Map, info *pb.FindEnabl
|
||||
|
||||
func (this *ClusterHelper) filterMenuItems2(items []maps.Map, info *pb.FindEnabledNodeClusterConfigInfoResponse, clusterIdString string, selectedItem string, actionPtr actions.ActionWrapper) []maps.Map {
|
||||
if teaconst.IsPlus {
|
||||
items = append(items, maps.Map{
|
||||
"name": this.Lang(actionPtr, codes.NodeClusterMenu_SettingSecurityPolicy),
|
||||
"url": "/clusters/cluster/settings/network-security?clusterId=" + clusterIdString,
|
||||
"isActive": selectedItem == "networkSecurity",
|
||||
"isOn": info != nil && info.HasNetworkSecurityPolicy, // TODO 将来 加入 info.HasDDoSProtection
|
||||
})
|
||||
|
||||
items = append(items, maps.Map{
|
||||
"name": "-",
|
||||
})
|
||||
if plusutils.CheckComponent(plusutils.ComponentCodeScheduling) {
|
||||
items = append(items, maps.Map{
|
||||
"name": "-",
|
||||
})
|
||||
items = append(items, maps.Map{
|
||||
"name": this.Lang(actionPtr, codes.NodeClusterMenu_SettingSchedule),
|
||||
"url": "/clusters/cluster/settings/schedule?clusterId=" + clusterIdString,
|
||||
@@ -89,14 +82,12 @@ func (this *ClusterHelper) filterMenuItems2(items []maps.Map, info *pb.FindEnabl
|
||||
"isOn": info != nil && info.HasSystemServices,
|
||||
})
|
||||
|
||||
{
|
||||
items = append(items, maps.Map{
|
||||
"name": this.Lang(actionPtr, codes.NodeClusterMenu_SettingTOA),
|
||||
"url": "/clusters/cluster/settings/toa?clusterId=" + clusterIdString,
|
||||
"isActive": selectedItem == "toa",
|
||||
"isOn": info != nil && info.IsTOAEnabled,
|
||||
})
|
||||
}
|
||||
items = append(items, maps.Map{
|
||||
"name": this.Lang(actionPtr, codes.NodeClusterMenu_SettingTOA),
|
||||
"url": "/clusters/cluster/settings/toa?clusterId=" + clusterIdString,
|
||||
"isActive": selectedItem == "toa",
|
||||
"isOn": info != nil && info.IsTOAEnabled,
|
||||
})
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build plus
|
||||
|
||||
package boards
|
||||
|
||||
import (
|
||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dashboard/boards/boardutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type HTTPDNSAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAction) Init() {
|
||||
this.Nav("", "", "httpdns")
|
||||
this.ViewDir("@default")
|
||||
this.View("dashboard/boards/httpdns")
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAction) RunGet(params struct{}) {
|
||||
if !teaconst.IsPlus {
|
||||
this.RedirectURL("/dashboard")
|
||||
return
|
||||
}
|
||||
|
||||
err := boardutils.InitBoard(this.Parent())
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["board"] = maps.Map{
|
||||
"countApps": 0,
|
||||
"countDomains": 0,
|
||||
"countClusters": 0,
|
||||
"countNodes": 0,
|
||||
"countOfflineNodes": 0,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAction) RunPost(params struct{}) {
|
||||
resp, err := this.RPC().HTTPDNSBoardRPC().ComposeHTTPDNSBoard(this.AdminContext(), &pb.ComposeHTTPDNSBoardRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["board"] = maps.Map{
|
||||
"countApps": resp.CountApps,
|
||||
"countDomains": resp.CountDomains,
|
||||
"countClusters": resp.CountClusters,
|
||||
"countNodes": resp.CountNodes,
|
||||
"countOfflineNodes": resp.CountOfflineNodes,
|
||||
}
|
||||
|
||||
{
|
||||
var statMaps = []maps.Map{}
|
||||
for _, stat := range resp.HourlyTrafficStats {
|
||||
statMaps = append(statMaps, maps.Map{
|
||||
"day": stat.Hour[4:6] + "月" + stat.Hour[6:8] + "日",
|
||||
"hour": stat.Hour[8:],
|
||||
"countRequests": stat.CountRequests,
|
||||
"bytes": stat.Bytes,
|
||||
})
|
||||
}
|
||||
this.Data["hourlyStats"] = statMaps
|
||||
}
|
||||
|
||||
{
|
||||
var statMaps = []maps.Map{}
|
||||
for _, stat := range resp.DailyTrafficStats {
|
||||
statMaps = append(statMaps, maps.Map{
|
||||
"day": stat.Day[4:6] + "月" + stat.Day[6:] + "日",
|
||||
"countRequests": stat.CountRequests,
|
||||
"bytes": stat.Bytes,
|
||||
})
|
||||
}
|
||||
this.Data["dailyStats"] = statMaps
|
||||
}
|
||||
|
||||
{
|
||||
var statMaps = []maps.Map{}
|
||||
for _, stat := range resp.TopAppStats {
|
||||
statMaps = append(statMaps, maps.Map{
|
||||
"appId": stat.AppId,
|
||||
"appName": stat.AppName,
|
||||
"countRequests": stat.CountRequests,
|
||||
"bytes": stat.Bytes,
|
||||
})
|
||||
}
|
||||
this.Data["topAppStats"] = statMaps
|
||||
}
|
||||
|
||||
{
|
||||
var statMaps = []maps.Map{}
|
||||
for _, stat := range resp.TopDomainStats {
|
||||
statMaps = append(statMaps, maps.Map{
|
||||
"domainId": stat.DomainId,
|
||||
"domainName": stat.DomainName,
|
||||
"countRequests": stat.CountRequests,
|
||||
"bytes": stat.Bytes,
|
||||
})
|
||||
}
|
||||
this.Data["topDomainStats"] = statMaps
|
||||
}
|
||||
|
||||
{
|
||||
var statMaps = []maps.Map{}
|
||||
for _, stat := range resp.TopNodeStats {
|
||||
statMaps = append(statMaps, maps.Map{
|
||||
"clusterId": stat.ClusterId,
|
||||
"nodeId": stat.NodeId,
|
||||
"nodeName": stat.NodeName,
|
||||
"countRequests": stat.CountRequests,
|
||||
"bytes": stat.Bytes,
|
||||
})
|
||||
}
|
||||
this.Data["topNodeStats"] = statMaps
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
stringutil "github.com/iwind/TeaGo/utils/string"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
"regexp"
|
||||
"time"
|
||||
@@ -409,5 +410,55 @@ func (this *IndexAction) RunPost(params struct {
|
||||
}
|
||||
this.Data["countWeakAdmins"] = countWeakAdminsResp.Count
|
||||
|
||||
upgradeConfig, err := configloaders.LoadUpgradeConfig()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["autoUpgrade"] = upgradeConfig.AutoUpgrade
|
||||
|
||||
httpdnsNodeUpgradeInfo, err := this.composeHTTPDNSNodeUpgradeInfo()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["httpdnsNodeUpgradeInfo"] = httpdnsNodeUpgradeInfo
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
func (this *IndexAction) composeHTTPDNSNodeUpgradeInfo() (maps.Map, error) {
|
||||
clustersResp, err := this.RPC().HTTPDNSClusterRPC().ListHTTPDNSClusters(this.AdminContext(), &pb.ListHTTPDNSClustersRequest{
|
||||
Offset: 0,
|
||||
Size: 10000,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
count := 0
|
||||
version := ""
|
||||
for _, cluster := range clustersResp.Clusters {
|
||||
resp, err := this.RPC().HTTPDNSNodeRPC().FindAllUpgradeHTTPDNSNodesWithClusterId(this.AdminContext(), &pb.FindAllUpgradeHTTPDNSNodesWithClusterIdRequest{
|
||||
ClusterId: cluster.Id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
count += len(resp.Nodes)
|
||||
for _, nodeUpgrade := range resp.Nodes {
|
||||
if len(nodeUpgrade.NewVersion) == 0 {
|
||||
continue
|
||||
}
|
||||
if len(version) == 0 || stringutil.VersionCompare(version, nodeUpgrade.NewVersion) < 0 {
|
||||
version = nodeUpgrade.NewVersion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return maps.Map{
|
||||
"count": count,
|
||||
"version": version,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -245,5 +245,12 @@ func (this *IndexAction) RunPost(params struct{}) {
|
||||
}
|
||||
this.Data["countWeakAdmins"] = countWeakAdminsResp.Count
|
||||
|
||||
upgradeConfig, err := configloaders.LoadUpgradeConfig()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["autoUpgrade"] = upgradeConfig.AutoUpgrade
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ func init() {
|
||||
Get("/waf", new(boards.WafAction)).
|
||||
Post("/wafLogs", new(boards.WafLogsAction)).
|
||||
GetPost("/dns", new(boards.DnsAction)).
|
||||
GetPost("/httpdns", new(boards.HTTPDNSAction)).
|
||||
Get("/user", new(boards.UserAction)).
|
||||
Get("/events", new(boards.EventsAction)).
|
||||
Post("/readLogs", new(boards.ReadLogsAction)).
|
||||
|
||||
@@ -1,11 +1,110 @@
|
||||
package httpdns
|
||||
|
||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
this.RedirectURL("/httpdns/clusters")
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "httpdns")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
this.Data["board"] = maps.Map{
|
||||
"countApps": 0,
|
||||
"countDomains": 0,
|
||||
"countClusters": 0,
|
||||
"countNodes": 0,
|
||||
"countOfflineNodes": 0,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunPost(params struct{}) {
|
||||
resp, err := this.RPC().HTTPDNSBoardRPC().ComposeHTTPDNSBoard(this.AdminContext(), &pb.ComposeHTTPDNSBoardRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["board"] = maps.Map{
|
||||
"countApps": resp.CountApps,
|
||||
"countDomains": resp.CountDomains,
|
||||
"countClusters": resp.CountClusters,
|
||||
"countNodes": resp.CountNodes,
|
||||
"countOfflineNodes": resp.CountOfflineNodes,
|
||||
}
|
||||
|
||||
{
|
||||
statMaps := []maps.Map{}
|
||||
for _, stat := range resp.HourlyTrafficStats {
|
||||
statMaps = append(statMaps, maps.Map{
|
||||
"day": stat.Hour[4:6] + "月" + stat.Hour[6:8] + "日",
|
||||
"hour": stat.Hour[8:],
|
||||
"countRequests": stat.CountRequests,
|
||||
"bytes": stat.Bytes,
|
||||
})
|
||||
}
|
||||
this.Data["hourlyStats"] = statMaps
|
||||
}
|
||||
|
||||
{
|
||||
statMaps := []maps.Map{}
|
||||
for _, stat := range resp.DailyTrafficStats {
|
||||
statMaps = append(statMaps, maps.Map{
|
||||
"day": stat.Day[4:6] + "月" + stat.Day[6:] + "日",
|
||||
"countRequests": stat.CountRequests,
|
||||
"bytes": stat.Bytes,
|
||||
})
|
||||
}
|
||||
this.Data["dailyStats"] = statMaps
|
||||
}
|
||||
|
||||
{
|
||||
statMaps := []maps.Map{}
|
||||
for _, stat := range resp.TopAppStats {
|
||||
statMaps = append(statMaps, maps.Map{
|
||||
"appId": stat.AppId,
|
||||
"appName": stat.AppName,
|
||||
"countRequests": stat.CountRequests,
|
||||
"bytes": stat.Bytes,
|
||||
})
|
||||
}
|
||||
this.Data["topAppStats"] = statMaps
|
||||
}
|
||||
|
||||
{
|
||||
statMaps := []maps.Map{}
|
||||
for _, stat := range resp.TopDomainStats {
|
||||
statMaps = append(statMaps, maps.Map{
|
||||
"domainId": stat.DomainId,
|
||||
"domainName": stat.DomainName,
|
||||
"countRequests": stat.CountRequests,
|
||||
"bytes": stat.Bytes,
|
||||
})
|
||||
}
|
||||
this.Data["topDomainStats"] = statMaps
|
||||
}
|
||||
|
||||
{
|
||||
statMaps := []maps.Map{}
|
||||
for _, stat := range resp.TopNodeStats {
|
||||
statMaps = append(statMaps, maps.Map{
|
||||
"clusterId": stat.ClusterId,
|
||||
"nodeId": stat.NodeId,
|
||||
"nodeName": stat.NodeName,
|
||||
"countRequests": stat.CountRequests,
|
||||
"bytes": stat.Bytes,
|
||||
})
|
||||
}
|
||||
this.Data["topNodeStats"] = statMaps
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ func init() {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeHttpDNS)).
|
||||
Data("teaMenu", "httpdns").
|
||||
Data("teaSubMenu", "cluster").
|
||||
Data("teaSubMenu", "board").
|
||||
Prefix("/httpdns").
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("", new(IndexAction)).
|
||||
GetPost("/addPortPopup", new(AddPortPopupAction)).
|
||||
EndAll()
|
||||
})
|
||||
|
||||
@@ -25,7 +25,7 @@ func (this *CreatePopupAction) Init() {
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct{}) {
|
||||
var authMethods = []*serverconfigs.HTTPAuthTypeDefinition{}
|
||||
authMethods := []*serverconfigs.HTTPAuthTypeDefinition{}
|
||||
for _, method := range serverconfigs.FindAllHTTPAuthTypes(teaconst.Role) {
|
||||
if !method.IsPlus || (method.IsPlus && teaconst.IsPlus) {
|
||||
authMethods = append(authMethods, method)
|
||||
@@ -59,6 +59,10 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
TypeDTimestampParamName string
|
||||
TypeDLife int
|
||||
|
||||
// TypeE
|
||||
TypeESecret string
|
||||
TypeELife int
|
||||
|
||||
// BasicAuth
|
||||
HttpAuthBasicAuthUsersJSON []byte
|
||||
BasicAuthRealm string
|
||||
@@ -81,29 +85,25 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
Field("type", params.Type).
|
||||
Require("请输入鉴权类型")
|
||||
|
||||
var ref = &serverconfigs.HTTPAuthPolicyRef{IsOn: true}
|
||||
ref := &serverconfigs.HTTPAuthPolicyRef{IsOn: true}
|
||||
var method serverconfigs.HTTPAuthMethodInterface
|
||||
|
||||
// 扩展名
|
||||
var exts = utils.NewStringsStream(params.Exts).
|
||||
exts := utils.NewStringsStream(params.Exts).
|
||||
Map(strings.TrimSpace, strings.ToLower).
|
||||
Filter(utils.FilterNotEmpty).
|
||||
Map(utils.MapAddPrefixFunc(".")).
|
||||
Unique().
|
||||
Result()
|
||||
|
||||
// 域名
|
||||
var domains = []string{}
|
||||
domains := []string{}
|
||||
if len(params.DomainsJSON) > 0 {
|
||||
var rawDomains = []string{}
|
||||
rawDomains := []string{}
|
||||
err := json.Unmarshal(params.DomainsJSON, &rawDomains)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO 如果用户填写了一个网址,应该分析域名并填入
|
||||
|
||||
domains = utils.NewStringsStream(rawDomains).
|
||||
Map(strings.TrimSpace, strings.ToLower).
|
||||
Filter(utils.FilterNotEmpty).
|
||||
@@ -116,11 +116,11 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
params.Must.
|
||||
Field("typeASecret", params.TypeASecret).
|
||||
Require("请输入鉴权密钥").
|
||||
MaxLength(40, "鉴权密钥不能超过40个字符").
|
||||
Match(`^[a-zA-Z0-9]{1,40}$`, "鉴权密钥中只能包含字母、数字").
|
||||
MaxLength(40, "鉴权密钥长度不能超过40个字符").
|
||||
Match(`^[a-zA-Z0-9]{1,40}$`, "鉴权密钥中只能包含字母和数字").
|
||||
Field("typeASignParamName", params.TypeASignParamName).
|
||||
Require("请输入签名参数").
|
||||
Match(`^[a-zA-Z0-9_]{1,40}$`, "签名参数中只能包含字母、数字、下划线")
|
||||
Match(`^[a-zA-Z0-9_]{1,40}$`, "签名参数中只能包含字母、数字和下划线")
|
||||
|
||||
if params.TypeALife < 0 {
|
||||
params.TypeALife = 0
|
||||
@@ -135,8 +135,8 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
params.Must.
|
||||
Field("typeBSecret", params.TypeBSecret).
|
||||
Require("请输入鉴权密钥").
|
||||
MaxLength(40, "鉴权密钥不能超过40个字符").
|
||||
Match(`^[a-zA-Z0-9]{1,40}$`, "鉴权密钥中只能包含字母、数字")
|
||||
MaxLength(40, "鉴权密钥长度不能超过40个字符").
|
||||
Match(`^[a-zA-Z0-9]{1,40}$`, "鉴权密钥中只能包含字母和数字")
|
||||
|
||||
method = &serverconfigs.HTTPAuthTypeBMethod{
|
||||
Secret: params.TypeBSecret,
|
||||
@@ -146,8 +146,8 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
params.Must.
|
||||
Field("typeCSecret", params.TypeCSecret).
|
||||
Require("请输入鉴权密钥").
|
||||
MaxLength(40, "鉴权密钥不能超过40个字符").
|
||||
Match(`^[a-zA-Z0-9]{1,40}$`, "鉴权密钥中只能包含字母、数字")
|
||||
MaxLength(40, "鉴权密钥长度不能超过40个字符").
|
||||
Match(`^[a-zA-Z0-9]{1,40}$`, "鉴权密钥中只能包含字母和数字")
|
||||
|
||||
method = &serverconfigs.HTTPAuthTypeCMethod{
|
||||
Secret: params.TypeCSecret,
|
||||
@@ -157,14 +157,14 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
params.Must.
|
||||
Field("typeDSecret", params.TypeDSecret).
|
||||
Require("请输入鉴权密钥").
|
||||
MaxLength(40, "鉴权密钥不能超过40个字符").
|
||||
Match(`^[a-zA-Z0-9]{1,40}$`, "鉴权密钥中只能包含字母、数字").
|
||||
MaxLength(40, "鉴权密钥长度不能超过40个字符").
|
||||
Match(`^[a-zA-Z0-9]{1,40}$`, "鉴权密钥中只能包含字母和数字").
|
||||
Field("typeDSignParamName", params.TypeDSignParamName).
|
||||
Require("请输入签名参数").
|
||||
Match(`^[a-zA-Z0-9_]{1,40}$`, "签名参数中只能包含字母、数字、下划线").
|
||||
Match(`^[a-zA-Z0-9_]{1,40}$`, "签名参数中只能包含字母、数字和下划线").
|
||||
Field("typeDTimestampParamName", params.TypeDTimestampParamName).
|
||||
Require("请输入时间戳参数").
|
||||
Match(`^[a-zA-Z0-9_]{1,40}$`, "时间戳参数中只能包含字母、数字、下划线")
|
||||
Require("请输入时间参数").
|
||||
Match(`^[a-zA-Z0-9_]{1,40}$`, "时间参数中只能包含字母、数字和下划线")
|
||||
|
||||
method = &serverconfigs.HTTPAuthTypeDMethod{
|
||||
Secret: params.TypeDSecret,
|
||||
@@ -172,15 +172,26 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
TimestampParamName: params.TypeDTimestampParamName,
|
||||
Life: params.TypeDLife,
|
||||
}
|
||||
case serverconfigs.HTTPAuthTypeTypeE:
|
||||
params.Must.
|
||||
Field("typeESecret", params.TypeESecret).
|
||||
Require("请输入鉴权密钥").
|
||||
MaxLength(40, "鉴权密钥长度不能超过40个字符").
|
||||
Match(`^[a-zA-Z0-9]{1,40}$`, "鉴权密钥中只能包含字母和数字")
|
||||
|
||||
method = &serverconfigs.HTTPAuthTypeEMethod{
|
||||
Secret: params.TypeESecret,
|
||||
Life: params.TypeELife,
|
||||
}
|
||||
case serverconfigs.HTTPAuthTypeBasicAuth:
|
||||
var users = []*serverconfigs.HTTPAuthBasicMethodUser{}
|
||||
users := []*serverconfigs.HTTPAuthBasicMethodUser{}
|
||||
err := json.Unmarshal(params.HttpAuthBasicAuthUsersJSON, &users)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if len(users) == 0 {
|
||||
this.Fail("请添加至少一个用户")
|
||||
this.Fail("请至少添加一个用户")
|
||||
}
|
||||
method = &serverconfigs.HTTPAuthBasicMethod{
|
||||
Users: users,
|
||||
@@ -188,8 +199,9 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
Charset: params.BasicAuthCharset,
|
||||
}
|
||||
case serverconfigs.HTTPAuthTypeSubRequest:
|
||||
params.Must.Field("subRequestURL", params.SubRequestURL).
|
||||
Require("请输入子请求URL")
|
||||
params.Must.
|
||||
Field("subRequestURL", params.SubRequestURL).
|
||||
Require("请输入子请求 URL")
|
||||
if params.SubRequestFollowRequest {
|
||||
params.SubRequestMethod = ""
|
||||
}
|
||||
@@ -198,7 +210,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
Method: params.SubRequestMethod,
|
||||
}
|
||||
default:
|
||||
this.Fail("不支持的鉴权类型'" + params.Type + "'")
|
||||
this.Fail("不支持的鉴权类型 '" + params.Type + "'")
|
||||
}
|
||||
|
||||
if method == nil {
|
||||
@@ -214,7 +226,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
var paramsMap = maps.Map{}
|
||||
paramsMap := maps.Map{}
|
||||
err = json.Unmarshal(methodJSON, ¶msMap)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
@@ -231,6 +243,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
return
|
||||
}
|
||||
defer this.CreateLogInfo(codes.HTTPAuthPolicy_LogCreateHTTPAuthPolicy, createResp.HttpAuthPolicyId)
|
||||
|
||||
ref.AuthPolicyId = createResp.HttpAuthPolicyId
|
||||
ref.AuthPolicy = &serverconfigs.HTTPAuthPolicy{
|
||||
Id: createResp.HttpAuthPolicyId,
|
||||
|
||||
@@ -27,7 +27,7 @@ func (this *UpdatePopupAction) Init() {
|
||||
func (this *UpdatePopupAction) RunGet(params struct {
|
||||
PolicyId int64
|
||||
}) {
|
||||
var authMethods = []*serverconfigs.HTTPAuthTypeDefinition{}
|
||||
authMethods := []*serverconfigs.HTTPAuthTypeDefinition{}
|
||||
for _, method := range serverconfigs.FindAllHTTPAuthTypes(teaconst.Role) {
|
||||
if !method.IsPlus || (method.IsPlus && teaconst.IsPlus) {
|
||||
authMethods = append(authMethods, method)
|
||||
@@ -47,7 +47,7 @@ func (this *UpdatePopupAction) RunGet(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
var authParams = map[string]interface{}{}
|
||||
authParams := map[string]interface{}{}
|
||||
if len(policy.ParamsJSON) > 0 {
|
||||
err = json.Unmarshal(policy.ParamsJSON, &authParams)
|
||||
if err != nil {
|
||||
@@ -91,6 +91,10 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
TypeDTimestampParamName string
|
||||
TypeDLife int
|
||||
|
||||
// TypeE
|
||||
TypeESecret string
|
||||
TypeELife int
|
||||
|
||||
// BasicAuth
|
||||
HttpAuthBasicAuthUsersJSON []byte
|
||||
BasicAuthRealm string
|
||||
@@ -125,29 +129,25 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
Field("name", params.Name).
|
||||
Require("请输入名称")
|
||||
|
||||
var ref = &serverconfigs.HTTPAuthPolicyRef{IsOn: true}
|
||||
ref := &serverconfigs.HTTPAuthPolicyRef{IsOn: true}
|
||||
var method serverconfigs.HTTPAuthMethodInterface
|
||||
|
||||
// 扩展名
|
||||
var exts = utils.NewStringsStream(params.Exts).
|
||||
exts := utils.NewStringsStream(params.Exts).
|
||||
Map(strings.TrimSpace, strings.ToLower).
|
||||
Filter(utils.FilterNotEmpty).
|
||||
Map(utils.MapAddPrefixFunc(".")).
|
||||
Unique().
|
||||
Result()
|
||||
|
||||
// 域名
|
||||
var domains = []string{}
|
||||
domains := []string{}
|
||||
if len(params.DomainsJSON) > 0 {
|
||||
var rawDomains = []string{}
|
||||
rawDomains := []string{}
|
||||
err := json.Unmarshal(params.DomainsJSON, &rawDomains)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO 如果用户填写了一个网址,应该分析域名并填入
|
||||
|
||||
domains = utils.NewStringsStream(rawDomains).
|
||||
Map(strings.TrimSpace, strings.ToLower).
|
||||
Filter(utils.FilterNotEmpty).
|
||||
@@ -160,11 +160,11 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
params.Must.
|
||||
Field("typeASecret", params.TypeASecret).
|
||||
Require("请输入鉴权密钥").
|
||||
MaxLength(40, "鉴权密钥不能超过40个字符").
|
||||
Match(`^[a-zA-Z0-9]{1,40}$`, "鉴权密钥中只能包含字母、数字").
|
||||
MaxLength(40, "鉴权密钥长度不能超过40个字符").
|
||||
Match(`^[a-zA-Z0-9]{1,40}$`, "鉴权密钥中只能包含字母和数字").
|
||||
Field("typeASignParamName", params.TypeASignParamName).
|
||||
Require("请输入签名参数").
|
||||
Match(`^[a-zA-Z0-9_]{1,40}$`, "签名参数中只能包含字母、数字、下划线")
|
||||
Match(`^[a-zA-Z0-9_]{1,40}$`, "签名参数中只能包含字母、数字和下划线")
|
||||
|
||||
if params.TypeALife < 0 {
|
||||
params.TypeALife = 0
|
||||
@@ -179,8 +179,8 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
params.Must.
|
||||
Field("typeBSecret", params.TypeBSecret).
|
||||
Require("请输入鉴权密钥").
|
||||
MaxLength(40, "鉴权密钥不能超过40个字符").
|
||||
Match(`^[a-zA-Z0-9]{1,40}$`, "鉴权密钥中只能包含字母、数字")
|
||||
MaxLength(40, "鉴权密钥长度不能超过40个字符").
|
||||
Match(`^[a-zA-Z0-9]{1,40}$`, "鉴权密钥中只能包含字母和数字")
|
||||
|
||||
method = &serverconfigs.HTTPAuthTypeBMethod{
|
||||
Secret: params.TypeBSecret,
|
||||
@@ -190,8 +190,8 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
params.Must.
|
||||
Field("typeCSecret", params.TypeCSecret).
|
||||
Require("请输入鉴权密钥").
|
||||
MaxLength(40, "鉴权密钥不能超过40个字符").
|
||||
Match(`^[a-zA-Z0-9]{1,40}$`, "鉴权密钥中只能包含字母、数字")
|
||||
MaxLength(40, "鉴权密钥长度不能超过40个字符").
|
||||
Match(`^[a-zA-Z0-9]{1,40}$`, "鉴权密钥中只能包含字母和数字")
|
||||
|
||||
method = &serverconfigs.HTTPAuthTypeCMethod{
|
||||
Secret: params.TypeCSecret,
|
||||
@@ -201,14 +201,14 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
params.Must.
|
||||
Field("typeDSecret", params.TypeDSecret).
|
||||
Require("请输入鉴权密钥").
|
||||
MaxLength(40, "鉴权密钥不能超过40个字符").
|
||||
Match(`^[a-zA-Z0-9]{1,40}$`, "鉴权密钥中只能包含字母、数字").
|
||||
MaxLength(40, "鉴权密钥长度不能超过40个字符").
|
||||
Match(`^[a-zA-Z0-9]{1,40}$`, "鉴权密钥中只能包含字母和数字").
|
||||
Field("typeDSignParamName", params.TypeDSignParamName).
|
||||
Require("请输入签名参数").
|
||||
Match(`^[a-zA-Z0-9_]{1,40}$`, "签名参数中只能包含字母、数字、下划线").
|
||||
Match(`^[a-zA-Z0-9_]{1,40}$`, "签名参数中只能包含字母、数字和下划线").
|
||||
Field("typeDTimestampParamName", params.TypeDTimestampParamName).
|
||||
Require("请输入时间戳参数").
|
||||
Match(`^[a-zA-Z0-9_]{1,40}$`, "时间戳参数中只能包含字母、数字、下划线")
|
||||
Require("请输入时间参数").
|
||||
Match(`^[a-zA-Z0-9_]{1,40}$`, "时间参数中只能包含字母、数字和下划线")
|
||||
|
||||
method = &serverconfigs.HTTPAuthTypeDMethod{
|
||||
Secret: params.TypeDSecret,
|
||||
@@ -216,6 +216,17 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
TimestampParamName: params.TypeDTimestampParamName,
|
||||
Life: params.TypeDLife,
|
||||
}
|
||||
case serverconfigs.HTTPAuthTypeTypeE:
|
||||
params.Must.
|
||||
Field("typeESecret", params.TypeESecret).
|
||||
Require("请输入鉴权密钥").
|
||||
MaxLength(40, "鉴权密钥长度不能超过40个字符").
|
||||
Match(`^[a-zA-Z0-9]{1,40}$`, "鉴权密钥中只能包含字母和数字")
|
||||
|
||||
method = &serverconfigs.HTTPAuthTypeEMethod{
|
||||
Secret: params.TypeESecret,
|
||||
Life: params.TypeELife,
|
||||
}
|
||||
case serverconfigs.HTTPAuthTypeBasicAuth:
|
||||
users := []*serverconfigs.HTTPAuthBasicMethodUser{}
|
||||
err := json.Unmarshal(params.HttpAuthBasicAuthUsersJSON, &users)
|
||||
@@ -224,7 +235,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
return
|
||||
}
|
||||
if len(users) == 0 {
|
||||
this.Fail("请添加至少一个用户")
|
||||
this.Fail("请至少添加一个用户")
|
||||
}
|
||||
method = &serverconfigs.HTTPAuthBasicMethod{
|
||||
Users: users,
|
||||
@@ -232,8 +243,9 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
Charset: params.BasicAuthCharset,
|
||||
}
|
||||
case serverconfigs.HTTPAuthTypeSubRequest:
|
||||
params.Must.Field("subRequestURL", params.SubRequestURL).
|
||||
Require("请输入子请求URL")
|
||||
params.Must.
|
||||
Field("subRequestURL", params.SubRequestURL).
|
||||
Require("请输入子请求 URL")
|
||||
if params.SubRequestFollowRequest {
|
||||
params.SubRequestMethod = ""
|
||||
}
|
||||
@@ -242,7 +254,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
Method: params.SubRequestMethod,
|
||||
}
|
||||
default:
|
||||
this.Fail("不支持的鉴权类型'" + policyType + "'")
|
||||
this.Fail("不支持的鉴权类型 '" + policyType + "'")
|
||||
}
|
||||
|
||||
if method == nil {
|
||||
@@ -275,6 +287,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
ref.AuthPolicy = &serverconfigs.HTTPAuthPolicy{
|
||||
Id: params.PolicyId,
|
||||
Name: params.Name,
|
||||
|
||||
@@ -16,6 +16,8 @@ import (
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type ComponentsAction actions.Action
|
||||
@@ -41,12 +43,7 @@ func (this *ComponentsAction) RunGet(params struct{}) {
|
||||
|
||||
var buffer = bytes.NewBuffer([]byte{})
|
||||
|
||||
var webRoot string
|
||||
if Tea.IsTesting() {
|
||||
webRoot = Tea.Root + "/../web/public/js/components/"
|
||||
} else {
|
||||
webRoot = Tea.Root + "/web/public/js/components/"
|
||||
}
|
||||
webRoot := findComponentsRoot()
|
||||
f := files.NewFile(webRoot)
|
||||
|
||||
f.Range(func(file *files.File) {
|
||||
@@ -173,3 +170,27 @@ func (this *ComponentsAction) RunGet(params struct{}) {
|
||||
|
||||
_, _ = this.Write(componentsData)
|
||||
}
|
||||
|
||||
func findComponentsRoot() string {
|
||||
candidates := []string{
|
||||
filepath.Join(Tea.Root, "web", "public", "js", "components"),
|
||||
filepath.Join(Tea.Root, "..", "web", "public", "js", "components"),
|
||||
filepath.Join(Tea.Root, "..", "..", "web", "public", "js", "components"),
|
||||
}
|
||||
|
||||
if cwd, err := os.Getwd(); err == nil && len(cwd) > 0 {
|
||||
candidates = append(candidates,
|
||||
filepath.Join(cwd, "web", "public", "js", "components"),
|
||||
filepath.Join(cwd, "EdgeAdmin", "web", "public", "js", "components"),
|
||||
)
|
||||
}
|
||||
|
||||
for _, candidate := range candidates {
|
||||
info, err := os.Stat(candidate)
|
||||
if err == nil && info.IsDir() {
|
||||
return candidate + string(filepath.Separator)
|
||||
}
|
||||
}
|
||||
|
||||
return filepath.Join(Tea.Root, "web", "public", "js", "components") + string(filepath.Separator)
|
||||
}
|
||||
|
||||
@@ -141,7 +141,6 @@ import (
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/httpdns"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/httpdns/apps"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/httpdns/clusters"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/httpdns/clusters"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/httpdns/resolveLogs"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/httpdns/runtimeLogs"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/httpdns/sandbox"
|
||||
|
||||
Reference in New Issue
Block a user