mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-09 11:40:25 +08:00
服务支持fastcgi
This commit is contained in:
112
internal/rpc/services/service_http_fastcgi.go
Normal file
112
internal/rpc/services/service_http_fastcgi.go
Normal file
@@ -0,0 +1,112 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
// HTTPFastcgiService HTTP Fastcgi服务
|
||||
type HTTPFastcgiService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// CreateHTTPFastcgi 创建Fastcgi
|
||||
func (this *HTTPFastcgiService) CreateHTTPFastcgi(ctx context.Context, req *pb.CreateHTTPFastcgiRequest) (*pb.CreateHTTPFastcgiResponse, error) {
|
||||
adminId, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
fastcgiId, err := models.SharedHTTPFastcgiDAO.CreateFastcgi(tx, adminId, userId, req.IsOn, req.Address, req.ParamsJSON, req.ReadTimeoutJSON, req.ConnTimeoutJSON, req.PoolSize, req.PathInfoPattern)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CreateHTTPFastcgiResponse{HttpFastcgiId: fastcgiId}, nil
|
||||
}
|
||||
|
||||
// UpdateHTTPFastcgi 修改Fastcgi
|
||||
func (this *HTTPFastcgiService) UpdateHTTPFastcgi(ctx context.Context, req *pb.UpdateHTTPFastcgiRequest) (*pb.RPCSuccess, error) {
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
if userId > 0 {
|
||||
err = models.SharedHTTPFastcgiDAO.CheckUserFastcgi(tx, userId, req.HttpFastcgiId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
err = models.SharedHTTPFastcgiDAO.UpdateFastcgi(tx, req.HttpFastcgiId, req.IsOn, req.Address, req.ParamsJSON, req.ReadTimeoutJSON, req.ConnTimeoutJSON, req.PoolSize, req.PathInfoPattern)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// FindEnabledHTTPFastcgi 获取Fastcgi详情
|
||||
func (this *HTTPFastcgiService) FindEnabledHTTPFastcgi(ctx context.Context, req *pb.FindEnabledHTTPFastcgiRequest) (*pb.FindEnabledHTTPFastcgiResponse, error) {
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
if userId > 0 {
|
||||
err = models.SharedHTTPFastcgiDAO.CheckUserFastcgi(tx, userId, req.HttpFastcgiId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
fastcgi, err := models.SharedHTTPFastcgiDAO.FindEnabledHTTPFastcgi(tx, req.HttpFastcgiId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if fastcgi == nil {
|
||||
return &pb.FindEnabledHTTPFastcgiResponse{HttpFastcgi: nil}, nil
|
||||
}
|
||||
return &pb.FindEnabledHTTPFastcgiResponse{HttpFastcgi: &pb.HTTPFastcgi{
|
||||
Id: int64(fastcgi.Id),
|
||||
IsOn: fastcgi.IsOn == 1,
|
||||
Address: fastcgi.Address,
|
||||
ParamsJSON: []byte(fastcgi.Params),
|
||||
ReadTimeoutJSON: []byte(fastcgi.ReadTimeout),
|
||||
ConnTimeoutJSON: []byte(fastcgi.ConnTimeout),
|
||||
PoolSize: types.Int32(fastcgi.PoolSize),
|
||||
PathInfoPattern: fastcgi.PathInfoPattern,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
// FindEnabledHTTPFastcgiConfig 获取Fastcgi配置
|
||||
func (this *HTTPFastcgiService) FindEnabledHTTPFastcgiConfig(ctx context.Context, req *pb.FindEnabledHTTPFastcgiConfigRequest) (*pb.FindEnabledHTTPFastcgiConfigResponse, error) {
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
if userId > 0 {
|
||||
err = models.SharedHTTPFastcgiDAO.CheckUserFastcgi(tx, userId, req.HttpFastcgiId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
config, err := models.SharedHTTPFastcgiDAO.ComposeFastcgiConfig(tx, req.HttpFastcgiId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
configJSON, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.FindEnabledHTTPFastcgiConfigResponse{HttpFastcgiJSON: configJSON}, nil
|
||||
}
|
||||
@@ -14,7 +14,7 @@ type HTTPWebService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// 创建Web配置
|
||||
// CreateHTTPWeb 创建Web配置
|
||||
func (this *HTTPWebService) CreateHTTPWeb(ctx context.Context, req *pb.CreateHTTPWebRequest) (*pb.CreateHTTPWebResponse, error) {
|
||||
// 校验请求
|
||||
adminId, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -32,7 +32,7 @@ func (this *HTTPWebService) CreateHTTPWeb(ctx context.Context, req *pb.CreateHTT
|
||||
return &pb.CreateHTTPWebResponse{WebId: webId}, nil
|
||||
}
|
||||
|
||||
// 查找Web配置
|
||||
// FindEnabledHTTPWeb 查找Web配置
|
||||
func (this *HTTPWebService) FindEnabledHTTPWeb(ctx context.Context, req *pb.FindEnabledHTTPWebRequest) (*pb.FindEnabledHTTPWebResponse, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -65,7 +65,7 @@ func (this *HTTPWebService) FindEnabledHTTPWeb(ctx context.Context, req *pb.Find
|
||||
return &pb.FindEnabledHTTPWebResponse{Web: result}, nil
|
||||
}
|
||||
|
||||
// 查找Web配置
|
||||
// FindEnabledHTTPWebConfig 查找Web配置
|
||||
func (this *HTTPWebService) FindEnabledHTTPWebConfig(ctx context.Context, req *pb.FindEnabledHTTPWebConfigRequest) (*pb.FindEnabledHTTPWebConfigResponse, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -95,7 +95,7 @@ func (this *HTTPWebService) FindEnabledHTTPWebConfig(ctx context.Context, req *p
|
||||
return &pb.FindEnabledHTTPWebConfigResponse{WebJSON: configJSON}, nil
|
||||
}
|
||||
|
||||
// 修改Web配置
|
||||
// UpdateHTTPWeb 修改Web配置
|
||||
func (this *HTTPWebService) UpdateHTTPWeb(ctx context.Context, req *pb.UpdateHTTPWebRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -121,7 +121,7 @@ func (this *HTTPWebService) UpdateHTTPWeb(ctx context.Context, req *pb.UpdateHTT
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改Gzip配置
|
||||
// UpdateHTTPWebGzip 修改Gzip配置
|
||||
func (this *HTTPWebService) UpdateHTTPWebGzip(ctx context.Context, req *pb.UpdateHTTPWebGzipRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -147,7 +147,7 @@ func (this *HTTPWebService) UpdateHTTPWebGzip(ctx context.Context, req *pb.Updat
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改字符集配置
|
||||
// UpdateHTTPWebCharset 修改字符集配置
|
||||
func (this *HTTPWebService) UpdateHTTPWebCharset(ctx context.Context, req *pb.UpdateHTTPWebCharsetRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -172,7 +172,7 @@ func (this *HTTPWebService) UpdateHTTPWebCharset(ctx context.Context, req *pb.Up
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 更改请求Header策略
|
||||
// UpdateHTTPWebRequestHeader 更改请求Header策略
|
||||
func (this *HTTPWebService) UpdateHTTPWebRequestHeader(ctx context.Context, req *pb.UpdateHTTPWebRequestHeaderRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -198,7 +198,7 @@ func (this *HTTPWebService) UpdateHTTPWebRequestHeader(ctx context.Context, req
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 更改响应Header策略
|
||||
// UpdateHTTPWebResponseHeader 更改响应Header策略
|
||||
func (this *HTTPWebService) UpdateHTTPWebResponseHeader(ctx context.Context, req *pb.UpdateHTTPWebResponseHeaderRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -224,7 +224,7 @@ func (this *HTTPWebService) UpdateHTTPWebResponseHeader(ctx context.Context, req
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 更改Shutdown
|
||||
// UpdateHTTPWebShutdown 更改Shutdown
|
||||
func (this *HTTPWebService) UpdateHTTPWebShutdown(ctx context.Context, req *pb.UpdateHTTPWebShutdownRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -249,7 +249,7 @@ func (this *HTTPWebService) UpdateHTTPWebShutdown(ctx context.Context, req *pb.U
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 更改Pages
|
||||
// UpdateHTTPWebPages 更改Pages
|
||||
func (this *HTTPWebService) UpdateHTTPWebPages(ctx context.Context, req *pb.UpdateHTTPWebPagesRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -274,7 +274,7 @@ func (this *HTTPWebService) UpdateHTTPWebPages(ctx context.Context, req *pb.Upda
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 更改访问日志配置
|
||||
// UpdateHTTPWebAccessLog 更改访问日志配置
|
||||
func (this *HTTPWebService) UpdateHTTPWebAccessLog(ctx context.Context, req *pb.UpdateHTTPWebAccessLogRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -299,7 +299,7 @@ func (this *HTTPWebService) UpdateHTTPWebAccessLog(ctx context.Context, req *pb.
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 更改统计配置
|
||||
// UpdateHTTPWebStat 更改统计配置
|
||||
func (this *HTTPWebService) UpdateHTTPWebStat(ctx context.Context, req *pb.UpdateHTTPWebStatRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -324,7 +324,7 @@ func (this *HTTPWebService) UpdateHTTPWebStat(ctx context.Context, req *pb.Updat
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 更改缓存配置
|
||||
// UpdateHTTPWebCache 更改缓存配置
|
||||
func (this *HTTPWebService) UpdateHTTPWebCache(ctx context.Context, req *pb.UpdateHTTPWebCacheRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -350,7 +350,7 @@ func (this *HTTPWebService) UpdateHTTPWebCache(ctx context.Context, req *pb.Upda
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 更改防火墙设置
|
||||
// UpdateHTTPWebFirewall 更改防火墙设置
|
||||
func (this *HTTPWebService) UpdateHTTPWebFirewall(ctx context.Context, req *pb.UpdateHTTPWebFirewallRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -376,7 +376,7 @@ func (this *HTTPWebService) UpdateHTTPWebFirewall(ctx context.Context, req *pb.U
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 更改路径规则设置
|
||||
// UpdateHTTPWebLocations 更改路径规则设置
|
||||
func (this *HTTPWebService) UpdateHTTPWebLocations(ctx context.Context, req *pb.UpdateHTTPWebLocationsRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -402,7 +402,7 @@ func (this *HTTPWebService) UpdateHTTPWebLocations(ctx context.Context, req *pb.
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 更改跳转到HTTPS设置
|
||||
// UpdateHTTPWebRedirectToHTTPS 更改跳转到HTTPS设置
|
||||
func (this *HTTPWebService) UpdateHTTPWebRedirectToHTTPS(ctx context.Context, req *pb.UpdateHTTPWebRedirectToHTTPSRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -427,7 +427,7 @@ func (this *HTTPWebService) UpdateHTTPWebRedirectToHTTPS(ctx context.Context, re
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 更改Websocket设置
|
||||
// UpdateHTTPWebWebsocket 更改Websocket设置
|
||||
func (this *HTTPWebService) UpdateHTTPWebWebsocket(ctx context.Context, req *pb.UpdateHTTPWebWebsocketRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -451,7 +451,31 @@ func (this *HTTPWebService) UpdateHTTPWebWebsocket(ctx context.Context, req *pb.
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 更改重写规则设置
|
||||
// UpdateHTTPWebFastcgi 更改Fastcgi设置
|
||||
func (this *HTTPWebService) UpdateHTTPWebFastcgi(ctx context.Context, req *pb.UpdateHTTPWebFastcgiRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if userId > 0 {
|
||||
err = models.SharedHTTPWebDAO.CheckUserWeb(nil, userId, req.WebId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
err = models.SharedHTTPWebDAO.UpdateWebFastcgi(tx, req.WebId, req.FastcgiJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// UpdateHTTPWebRewriteRules 更改重写规则设置
|
||||
func (this *HTTPWebService) UpdateHTTPWebRewriteRules(ctx context.Context, req *pb.UpdateHTTPWebRewriteRulesRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -475,7 +499,7 @@ func (this *HTTPWebService) UpdateHTTPWebRewriteRules(ctx context.Context, req *
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 更改主机跳转设置
|
||||
// UpdateHTTPWebHostRedirects 更改主机跳转设置
|
||||
func (this *HTTPWebService) UpdateHTTPWebHostRedirects(ctx context.Context, req *pb.UpdateHTTPWebHostRedirectsRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -515,7 +539,7 @@ func (this *HTTPWebService) UpdateHTTPWebHostRedirects(ctx context.Context, req
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 查找主机跳转设置
|
||||
// FindHTTPWebHostRedirects 查找主机跳转设置
|
||||
func (this *HTTPWebService) FindHTTPWebHostRedirects(ctx context.Context, req *pb.FindHTTPWebHostRedirectsRequest) (*pb.FindHTTPWebHostRedirectsResponse, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
|
||||
@@ -13,7 +13,7 @@ type HTTPGzipService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// 创建Gzip配置
|
||||
// CreateHTTPGzip 创建Gzip配置
|
||||
func (this *HTTPGzipService) CreateHTTPGzip(ctx context.Context, req *pb.CreateHTTPGzipRequest) (*pb.CreateHTTPGzipResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
@@ -50,10 +50,10 @@ func (this *HTTPGzipService) CreateHTTPGzip(ctx context.Context, req *pb.CreateH
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.CreateHTTPGzipResponse{GzipId: gzipId}, nil
|
||||
return &pb.CreateHTTPGzipResponse{HttpGzipId: gzipId}, nil
|
||||
}
|
||||
|
||||
// 查找Gzip
|
||||
// FindEnabledHTTPGzipConfig 查找Gzip
|
||||
func (this *HTTPGzipService) FindEnabledHTTPGzipConfig(ctx context.Context, req *pb.FindEnabledGzipConfigRequest) (*pb.FindEnabledGzipConfigResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
@@ -63,7 +63,7 @@ func (this *HTTPGzipService) FindEnabledHTTPGzipConfig(ctx context.Context, req
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
config, err := models.SharedHTTPGzipDAO.ComposeGzipConfig(tx, req.GzipId)
|
||||
config, err := models.SharedHTTPGzipDAO.ComposeGzipConfig(tx, req.HttpGzipId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -72,10 +72,10 @@ func (this *HTTPGzipService) FindEnabledHTTPGzipConfig(ctx context.Context, req
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.FindEnabledGzipConfigResponse{GzipJSON: configData}, nil
|
||||
return &pb.FindEnabledGzipConfigResponse{HttpGzipJSON: configData}, nil
|
||||
}
|
||||
|
||||
// 修改Gzip配置
|
||||
// UpdateHTTPGzip 修改Gzip配置
|
||||
func (this *HTTPGzipService) UpdateHTTPGzip(ctx context.Context, req *pb.UpdateHTTPGzipRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
@@ -107,7 +107,7 @@ func (this *HTTPGzipService) UpdateHTTPGzip(ctx context.Context, req *pb.UpdateH
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
err = models.SharedHTTPGzipDAO.UpdateGzip(tx, req.GzipId, int(req.Level), minLengthJSON, maxLengthJSON, req.CondsJSON)
|
||||
err = models.SharedHTTPGzipDAO.UpdateGzip(tx, req.HttpGzipId, int(req.Level), minLengthJSON, maxLengthJSON, req.CondsJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user