2022-12-30 20:48:38 +08:00
|
|
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
|
|
|
|
2023-01-02 18:20:42 +08:00
|
|
|
package userAgent
|
2022-12-30 20:48:38 +08:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
2023-06-30 18:08:30 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
2022-12-30 20:48:38 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
|
|
|
|
"github.com/iwind/TeaGo/actions"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type IndexAction struct {
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) Init() {
|
|
|
|
|
this.Nav("", "setting", "index")
|
|
|
|
|
this.SecondMenu("userAgent")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) RunGet(params struct {
|
|
|
|
|
ServerId int64
|
|
|
|
|
}) {
|
2024-04-14 16:45:17 +08:00
|
|
|
// 只有HTTP服务才支持
|
|
|
|
|
if this.FilterHTTPFamily() {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-30 20:48:38 +08:00
|
|
|
this.Data["serverId"] = params.ServerId
|
|
|
|
|
|
|
|
|
|
webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Data["webId"] = webConfig.Id
|
|
|
|
|
|
|
|
|
|
var userAgentConfig = webConfig.UserAgent
|
|
|
|
|
if userAgentConfig == nil {
|
|
|
|
|
userAgentConfig = serverconfigs.NewUserAgentConfig()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Data["userAgentConfig"] = userAgentConfig
|
|
|
|
|
|
|
|
|
|
this.Show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) RunPost(params struct {
|
|
|
|
|
WebId int64
|
|
|
|
|
UserAgentJSON []byte
|
|
|
|
|
|
|
|
|
|
Must *actions.Must
|
|
|
|
|
CSRF *actionutils.CSRF
|
|
|
|
|
}) {
|
2023-06-30 18:08:30 +08:00
|
|
|
defer this.CreateLogInfo(codes.ServerUserAgent_LogUpdateUserAgents, params.WebId)
|
2022-12-30 20:48:38 +08:00
|
|
|
|
|
|
|
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebUserAgent(this.AdminContext(), &pb.UpdateHTTPWebUserAgentRequest{
|
|
|
|
|
HttpWebId: params.WebId,
|
|
|
|
|
UserAgentJSON: params.UserAgentJSON,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Success()
|
|
|
|
|
}
|