mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-02 01:40:25 +08:00
服务支持fastcgi;路径规则支持匹配后缀
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package fastcgi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"net"
|
||||
)
|
||||
|
||||
type CreatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct{}) {
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
Address string
|
||||
ParamsJSON []byte
|
||||
ReadTimeout int64
|
||||
PoolSize int32
|
||||
PathInfoPattern string
|
||||
IsOn bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
var fastcgiId = int64(0)
|
||||
defer func() {
|
||||
if fastcgiId > 0 {
|
||||
this.CreateLogInfo("创建Fastcgi %d", fastcgiId)
|
||||
} else {
|
||||
this.CreateLogInfo("创建Fastcgi")
|
||||
}
|
||||
}()
|
||||
|
||||
params.Must.
|
||||
Field("address", params.Address).
|
||||
Require("请输入Fastcgi地址")
|
||||
|
||||
_, _, err := net.SplitHostPort(params.Address)
|
||||
if err != nil {
|
||||
this.FailField("address", "请输入正确的Fastcgi地址")
|
||||
}
|
||||
|
||||
readTimeoutJSON, err := json.Marshal(&shared.TimeDuration{
|
||||
Count: params.ReadTimeout,
|
||||
Unit: "second",
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
createResp, err := this.RPC().HTTPFastcgiRPC().CreateHTTPFastcgi(this.AdminContext(), &pb.CreateHTTPFastcgiRequest{
|
||||
IsOn: params.IsOn,
|
||||
Address: params.Address,
|
||||
ParamsJSON: params.ParamsJSON,
|
||||
ReadTimeoutJSON: readTimeoutJSON,
|
||||
ConnTimeoutJSON: nil, // TODO 将来支持
|
||||
PoolSize: params.PoolSize,
|
||||
PathInfoPattern: params.PathInfoPattern,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
fastcgiId = createResp.HttpFastcgiId
|
||||
|
||||
configResp, err := this.RPC().HTTPFastcgiRPC().FindEnabledHTTPFastcgiConfig(this.AdminContext(), &pb.FindEnabledHTTPFastcgiConfigRequest{HttpFastcgiId: fastcgiId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
configJSON := configResp.HttpFastcgiJSON
|
||||
config := &serverconfigs.HTTPFastcgiConfig{}
|
||||
err = json.Unmarshal(configJSON, config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["fastcgi"] = config
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package fastcgi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"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("fastcgi")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
ServerId int64
|
||||
}) {
|
||||
webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["webId"] = webConfig.Id
|
||||
this.Data["fastcgiRef"] = webConfig.FastcgiRef
|
||||
this.Data["fastcgiConfigs"] = webConfig.FastcgiList
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunPost(params struct {
|
||||
WebId int64
|
||||
FastcgiRefJSON []byte
|
||||
FastcgiJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
defer this.CreateLogInfo("修改Web %d 的Fastcgi设置", params.WebId)
|
||||
|
||||
// TODO 检查配置
|
||||
|
||||
fastcgiRef := &serverconfigs.HTTPFastcgiRef{}
|
||||
err := json.Unmarshal(params.FastcgiRefJSON, fastcgiRef)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
fastcgiRefJSON, err := json.Marshal(fastcgiRef)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebFastcgi(this.AdminContext(), &pb.UpdateHTTPWebFastcgiRequest{
|
||||
WebId: params.WebId,
|
||||
FastcgiJSON: fastcgiRefJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package fastcgi
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/serverutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)).
|
||||
Helper(serverutils.NewServerHelper()).
|
||||
Prefix("/servers/server/settings/fastcgi").
|
||||
GetPost("", new(IndexAction)).
|
||||
GetPost("/createPopup", new(CreatePopupAction)).
|
||||
GetPost("/updatePopup", new(UpdatePopupAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package fastcgi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"net"
|
||||
)
|
||||
|
||||
type UpdatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunGet(params struct {
|
||||
FastcgiId int64
|
||||
}) {
|
||||
configResp, err := this.RPC().HTTPFastcgiRPC().FindEnabledHTTPFastcgiConfig(this.AdminContext(), &pb.FindEnabledHTTPFastcgiConfigRequest{HttpFastcgiId: params.FastcgiId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
configJSON := configResp.HttpFastcgiJSON
|
||||
config := &serverconfigs.HTTPFastcgiConfig{}
|
||||
err = json.Unmarshal(configJSON, config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["fastcgi"] = config
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunPost(params struct {
|
||||
FastcgiId int64
|
||||
Address string
|
||||
ParamsJSON []byte
|
||||
ReadTimeout int64
|
||||
PoolSize int32
|
||||
PathInfoPattern string
|
||||
IsOn bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo("修改Fastcgi %d", params.FastcgiId)
|
||||
|
||||
params.Must.
|
||||
Field("address", params.Address).
|
||||
Require("请输入Fastcgi地址")
|
||||
|
||||
_, _, err := net.SplitHostPort(params.Address)
|
||||
if err != nil {
|
||||
this.FailField("address", "请输入正确的Fastcgi地址")
|
||||
}
|
||||
|
||||
readTimeoutJSON, err := json.Marshal(&shared.TimeDuration{
|
||||
Count: params.ReadTimeout,
|
||||
Unit: "second",
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = this.RPC().HTTPFastcgiRPC().UpdateHTTPFastcgi(this.AdminContext(), &pb.UpdateHTTPFastcgiRequest{
|
||||
HttpFastcgiId: params.FastcgiId,
|
||||
IsOn: params.IsOn,
|
||||
Address: params.Address,
|
||||
ParamsJSON: params.ParamsJSON,
|
||||
ReadTimeoutJSON: readTimeoutJSON,
|
||||
ConnTimeoutJSON: nil, // TODO 将来支持
|
||||
PoolSize: params.PoolSize,
|
||||
PathInfoPattern: params.PathInfoPattern,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
configResp, err := this.RPC().HTTPFastcgiRPC().FindEnabledHTTPFastcgiConfig(this.AdminContext(), &pb.FindEnabledHTTPFastcgiConfigRequest{HttpFastcgiId: params.FastcgiId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
configJSON := configResp.HttpFastcgiJSON
|
||||
config := &serverconfigs.HTTPFastcgiConfig{}
|
||||
err = json.Unmarshal(configJSON, config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["fastcgi"] = config
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user