This commit is contained in:
robin
2026-03-13 14:25:13 +08:00
parent a25a474d6a
commit afbaaa869c
95 changed files with 4591 additions and 2578 deletions

View File

@@ -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, &paramsMap)
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,

View File

@@ -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,