服务支持自定义访客IP地址获取方式

This commit is contained in:
刘祥超
2021-10-06 11:40:29 +08:00
parent 53c371f8d1
commit 7b1efe65d5
4 changed files with 53 additions and 1 deletions

View File

@@ -408,6 +408,16 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap maps.
config.WebP = webpConfig
}
// RemoteAddr
if IsNotNull(web.RemoteAddr) {
var remoteAddrConfig = &serverconfigs.HTTPRemoteAddrConfig{}
err = json.Unmarshal([]byte(web.RemoteAddr), remoteAddrConfig)
if err != nil {
return nil, err
}
config.RemoteAddr = remoteAddrConfig
}
cacheMap[cacheKey] = config
return config, nil
@@ -477,6 +487,21 @@ func (this *HTTPWebDAO) UpdateWebWebP(tx *dbs.Tx, webId int64, webpConfig []byte
return this.NotifyUpdate(tx, webId)
}
// UpdateWebRemoteAddr 修改RemoteAddr配置
func (this *HTTPWebDAO) UpdateWebRemoteAddr(tx *dbs.Tx, webId int64, remoteAddrConfig []byte) error {
if webId <= 0 {
return errors.New("invalid webId")
}
var op = NewHTTPWebOperator()
op.Id = webId
op.RemoteAddr = remoteAddrConfig
err := this.Save(tx, op)
if err != nil {
return err
}
return this.NotifyUpdate(tx, webId)
}
// UpdateWebCharset 修改字符编码
func (this *HTTPWebDAO) UpdateWebCharset(tx *dbs.Tx, webId int64, charsetJSON []byte) error {
if webId <= 0 {

View File

@@ -31,6 +31,7 @@ type HTTPWeb struct {
Fastcgi string `field:"fastcgi"` // Fastcgi配置
Auth string `field:"auth"` // 认证策略配置
Webp string `field:"webp"` // WebP配置
RemoteAddr string `field:"remoteAddr"` // 客户端IP配置
}
type HTTPWebOperator struct {
@@ -63,6 +64,7 @@ type HTTPWebOperator struct {
Fastcgi interface{} // Fastcgi配置
Auth interface{} // 认证策略配置
Webp interface{} // WebP配置
RemoteAddr interface{} // 客户端IP配置
}
func NewHTTPWebOperator() *HTTPWebOperator {

View File

@@ -173,6 +173,31 @@ func (this *HTTPWebService) UpdateHTTPWebWebP(ctx context.Context, req *pb.Updat
return this.Success()
}
// UpdateHTTPWebRemoteAddr 更改RemoteAddr配置
func (this *HTTPWebService) UpdateHTTPWebRemoteAddr(ctx context.Context, req *pb.UpdateHTTPWebRemoteAddrRequest) (*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
}
}
var tx = this.NullTx()
err = models.SharedHTTPWebDAO.UpdateWebRemoteAddr(tx, req.WebId, req.RemoteAddrJSON)
if err != nil {
return nil, err
}
return this.Success()
}
// UpdateHTTPWebCharset 修改字符集配置
func (this *HTTPWebService) UpdateHTTPWebCharset(ctx context.Context, req *pb.UpdateHTTPWebCharsetRequest) (*pb.RPCSuccess, error) {
// 校验请求

File diff suppressed because one or more lines are too long