mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-06 06:40:27 +08:00
服务支持自定义访客IP地址获取方式
This commit is contained in:
@@ -52,9 +52,7 @@ func (this *LocationHelper) BeforeAction(actionPtr actions.ActionWrapper) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *LocationHelper) createMenus(serverIdString string, locationIdString string, secondMenuItem string, locationConfig *serverconfigs.HTTPLocationConfig) []maps.Map {
|
func (this *LocationHelper) createMenus(serverIdString string, locationIdString string, secondMenuItem string, locationConfig *serverconfigs.HTTPLocationConfig) []maps.Map {
|
||||||
menuItems := []maps.Map{
|
menuItems := []maps.Map{}
|
||||||
|
|
||||||
}
|
|
||||||
menuItems = append(menuItems, maps.Map{
|
menuItems = append(menuItems, maps.Map{
|
||||||
"name": "基本信息",
|
"name": "基本信息",
|
||||||
"url": "/servers/server/settings/locations/location?serverId=" + serverIdString + "&locationId=" + locationIdString,
|
"url": "/servers/server/settings/locations/location?serverId=" + serverIdString + "&locationId=" + locationIdString,
|
||||||
@@ -163,6 +161,19 @@ func (this *LocationHelper) createMenus(serverIdString string, locationIdString
|
|||||||
"isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.FastcgiRef != nil && locationConfig.Web.FastcgiRef.IsPrior,
|
"isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.FastcgiRef != nil && locationConfig.Web.FastcgiRef.IsPrior,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
menuItems = append(menuItems, maps.Map{
|
||||||
|
"name": "-",
|
||||||
|
"url": "",
|
||||||
|
"isActive": false,
|
||||||
|
})
|
||||||
|
|
||||||
|
menuItems = append(menuItems, maps.Map{
|
||||||
|
"name": "访客IP地址",
|
||||||
|
"url": "/servers/server/settings/locations/remoteAddr?serverId=" + serverIdString + "&locationId=" + locationIdString,
|
||||||
|
"isActive": secondMenuItem == "remoteAddr",
|
||||||
|
"isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.RemoteAddr != nil && locationConfig.Web.RemoteAddr.IsOn,
|
||||||
|
})
|
||||||
|
|
||||||
return menuItems
|
return menuItems
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package remoteAddr
|
||||||
|
|
||||||
|
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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunGet(params struct {
|
||||||
|
LocationId int64
|
||||||
|
}) {
|
||||||
|
webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithLocationId(this.AdminContext(), params.LocationId)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["webId"] = webConfig.Id
|
||||||
|
this.Data["remoteAddrConfig"] = webConfig.RemoteAddr
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunPost(params struct {
|
||||||
|
WebId int64
|
||||||
|
RemoteAddrJSON []byte
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
CSRF *actionutils.CSRF
|
||||||
|
}) {
|
||||||
|
var remoteAddrConfig = &serverconfigs.HTTPRemoteAddrConfig{}
|
||||||
|
err := json.Unmarshal(params.RemoteAddrJSON, remoteAddrConfig)
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("参数校验失败:" + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRemoteAddr(this.AdminContext(), &pb.UpdateHTTPWebRemoteAddrRequest{
|
||||||
|
WebId: params.WebId,
|
||||||
|
RemoteAddrJSON: params.RemoteAddrJSON,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package remoteAddr
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/locationutils"
|
||||||
|
"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(locationutils.NewLocationHelper()).
|
||||||
|
Helper(serverutils.NewServerHelper()).
|
||||||
|
Data("tinyMenuItem", "remoteAddr").
|
||||||
|
Prefix("/servers/server/settings/locations/remoteAddr").
|
||||||
|
GetPost("", new(IndexAction)).
|
||||||
|
EndAll()
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package remoteAddr
|
||||||
|
|
||||||
|
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("remoteAddr")
|
||||||
|
}
|
||||||
|
|
||||||
|
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["remoteAddrConfig"] = webConfig.RemoteAddr
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunPost(params struct {
|
||||||
|
WebId int64
|
||||||
|
RemoteAddrJSON []byte
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
CSRF *actionutils.CSRF
|
||||||
|
}) {
|
||||||
|
var remoteAddrConfig = &serverconfigs.HTTPRemoteAddrConfig{}
|
||||||
|
err := json.Unmarshal(params.RemoteAddrJSON, remoteAddrConfig)
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("参数校验失败:" + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRemoteAddr(this.AdminContext(), &pb.UpdateHTTPWebRemoteAddrRequest{
|
||||||
|
WebId: params.WebId,
|
||||||
|
RemoteAddrJSON: params.RemoteAddrJSON,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package remoteAddr
|
||||||
|
|
||||||
|
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/remoteAddr").
|
||||||
|
GetPost("", new(IndexAction)).
|
||||||
|
EndAll()
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -328,12 +328,26 @@ func (this *ServerHelper) createSettingsMenu(secondMenuItem string, serverIdStri
|
|||||||
"isActive": secondMenuItem == "webp",
|
"isActive": secondMenuItem == "webp",
|
||||||
"isOn": serverConfig.Web != nil && serverConfig.Web.WebP != nil && serverConfig.Web.WebP.IsOn,
|
"isOn": serverConfig.Web != nil && serverConfig.Web.WebP != nil && serverConfig.Web.WebP.IsOn,
|
||||||
})
|
})
|
||||||
|
|
||||||
menuItems = append(menuItems, maps.Map{
|
menuItems = append(menuItems, maps.Map{
|
||||||
"name": "Fastcgi",
|
"name": "Fastcgi",
|
||||||
"url": "/servers/server/settings/fastcgi?serverId=" + serverIdString,
|
"url": "/servers/server/settings/fastcgi?serverId=" + serverIdString,
|
||||||
"isActive": secondMenuItem == "fastcgi",
|
"isActive": secondMenuItem == "fastcgi",
|
||||||
"isOn": serverConfig.Web != nil && serverConfig.Web.FastcgiRef != nil && serverConfig.Web.FastcgiRef.IsOn,
|
"isOn": serverConfig.Web != nil && serverConfig.Web.FastcgiRef != nil && serverConfig.Web.FastcgiRef.IsOn,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
menuItems = append(menuItems, maps.Map{
|
||||||
|
"name": "-",
|
||||||
|
"url": "",
|
||||||
|
"isActive": false,
|
||||||
|
})
|
||||||
|
|
||||||
|
menuItems = append(menuItems, maps.Map{
|
||||||
|
"name": "访客IP地址",
|
||||||
|
"url": "/servers/server/settings/remoteAddr?serverId=" + serverIdString,
|
||||||
|
"isActive": secondMenuItem == "remoteAddr",
|
||||||
|
"isOn": serverConfig.Web != nil && serverConfig.Web.RemoteAddr != nil && serverConfig.Web.RemoteAddr.IsOn,
|
||||||
|
})
|
||||||
} else if serverConfig.IsTCPFamily() {
|
} else if serverConfig.IsTCPFamily() {
|
||||||
menuItems = append(menuItems, maps.Map{
|
menuItems = append(menuItems, maps.Map{
|
||||||
"name": "TCP",
|
"name": "TCP",
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ import (
|
|||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/http"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/http"
|
||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/location"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/location"
|
||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/pages"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/pages"
|
||||||
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/remoteAddr"
|
||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/reverseProxy"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/reverseProxy"
|
||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/rewrite"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/rewrite"
|
||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/stat"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/stat"
|
||||||
@@ -87,6 +88,7 @@ import (
|
|||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/origins"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/origins"
|
||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/pages"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/pages"
|
||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/redirects"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/redirects"
|
||||||
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/remoteAddr"
|
||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/reverseProxy"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/reverseProxy"
|
||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/rewrite"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/rewrite"
|
||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/serverNames"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/serverNames"
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
Vue.component("http-remote-addr-config-box", {
|
||||||
|
props: ["v-remote-addr-config", "v-is-location"],
|
||||||
|
data: function () {
|
||||||
|
let config = this.vRemoteAddrConfig
|
||||||
|
if (config == null) {
|
||||||
|
config = {
|
||||||
|
isPrior: false,
|
||||||
|
isOn: false,
|
||||||
|
value: "${remoteAddr}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
config: config
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
isOn: function () {
|
||||||
|
return (!this.vIsLocation || this.config.isPrior) && this.config.isOn
|
||||||
|
}
|
||||||
|
},
|
||||||
|
template: `<div>
|
||||||
|
<input type="hidden" name="remoteAddrJSON" :value="JSON.stringify(config)"/>
|
||||||
|
<table class="ui table definition selectable">
|
||||||
|
<prior-checkbox :v-config="config" v-if="vIsLocation"></prior-checkbox>
|
||||||
|
<tbody v-show="!vIsLocation || config.isPrior">
|
||||||
|
<tr>
|
||||||
|
<td class="title">是否启用</td>
|
||||||
|
<td>
|
||||||
|
<div class="ui checkbox">
|
||||||
|
<input type="checkbox" value="1" v-model="config.isOn"/>
|
||||||
|
<label></label>
|
||||||
|
</div>
|
||||||
|
<p class="comment">选中后表示使用自定义的请求变量获取客户端IP。</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
<tbody v-show="isOn()">
|
||||||
|
<tr>
|
||||||
|
<td>请求变量</td>
|
||||||
|
<td>
|
||||||
|
<input type="text" v-model="config.value" maxlength="100"/>
|
||||||
|
<p class="comment">通过此变量获取用户的IP地址。具体可用的请求变量列表可参考官方网站文档。</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<div class="margin"></div>
|
||||||
|
</div>`
|
||||||
|
})
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
{$layout}
|
||||||
|
{$template "/left_menu"}
|
||||||
|
|
||||||
|
<div class="right-box">
|
||||||
|
{$template "../location_menu"}
|
||||||
|
{$template "../left_menu"}
|
||||||
|
|
||||||
|
<div class="right-box tiny">
|
||||||
|
<form class="ui form" data-tea-action="$" data-tea-success="success">
|
||||||
|
<csrf-token></csrf-token>
|
||||||
|
<input type="hidden" name="webId" :value="webId"/>
|
||||||
|
|
||||||
|
<http-remote-addr-config-box :v-remote-addr-config="remoteAddrConfig" :v-is-location="true"></http-remote-addr-config-box>
|
||||||
|
|
||||||
|
<submit-btn></submit-btn>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
Tea.context(function () {
|
||||||
|
this.success = NotifyReloadSuccess("保存成功")
|
||||||
|
})
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
{$layout}
|
||||||
|
{$template "/left_menu"}
|
||||||
|
|
||||||
|
<div class="right-box">
|
||||||
|
<form class="ui form" data-tea-action="$" data-tea-success="success">
|
||||||
|
<csrf-token></csrf-token>
|
||||||
|
<input type="hidden" name="webId" :value="webId"/>
|
||||||
|
|
||||||
|
<http-remote-addr-config-box :v-remote-addr-config="remoteAddrConfig"></http-remote-addr-config-box>
|
||||||
|
|
||||||
|
<submit-btn></submit-btn>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
Tea.context(function () {
|
||||||
|
this.success = NotifyReloadSuccess("保存成功")
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user