mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 05:00:25 +08:00 
			
		
		
		
	创建网站服务时增加缓存、WAF、从上级代理中读取IP等选项
This commit is contained in:
		@@ -8,6 +8,7 @@ import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs"
 | 
			
		||||
	"github.com/iwind/TeaGo/actions"
 | 
			
		||||
	"github.com/iwind/TeaGo/logs"
 | 
			
		||||
@@ -71,8 +72,11 @@ func (this *CreateAction) RunPost(params struct {
 | 
			
		||||
	CertIdsJSON []byte
 | 
			
		||||
	Origins     string
 | 
			
		||||
 | 
			
		||||
	AccessLogIsOn bool
 | 
			
		||||
	WebsocketIsOn bool
 | 
			
		||||
	AccessLogIsOn  bool
 | 
			
		||||
	WebsocketIsOn  bool
 | 
			
		||||
	CacheIsOn      bool
 | 
			
		||||
	WafIsOn        bool
 | 
			
		||||
	RemoteAddrIsOn bool
 | 
			
		||||
 | 
			
		||||
	WebRoot string
 | 
			
		||||
 | 
			
		||||
@@ -483,6 +487,75 @@ func (this *CreateAction) RunPost(params struct {
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			// cache
 | 
			
		||||
			if params.CacheIsOn {
 | 
			
		||||
				var cacheConfig = &serverconfigs.HTTPCacheConfig{
 | 
			
		||||
					IsPrior:         false,
 | 
			
		||||
					IsOn:            true,
 | 
			
		||||
					AddStatusHeader: true,
 | 
			
		||||
					PurgeIsOn:       false,
 | 
			
		||||
					PurgeKey:        "",
 | 
			
		||||
					CacheRefs:       nil,
 | 
			
		||||
				}
 | 
			
		||||
				cacheConfigJSON, err := json.Marshal(cacheConfig)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					this.ErrorPage(err)
 | 
			
		||||
					return
 | 
			
		||||
				}
 | 
			
		||||
				_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCache(this.AdminContext(), &pb.UpdateHTTPWebCacheRequest{
 | 
			
		||||
					WebId:     webConfig.Id,
 | 
			
		||||
					CacheJSON: cacheConfigJSON,
 | 
			
		||||
				})
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					this.ErrorPage(err)
 | 
			
		||||
					return
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			// waf
 | 
			
		||||
			if params.WafIsOn {
 | 
			
		||||
				var firewallRef = &firewallconfigs.HTTPFirewallRef{
 | 
			
		||||
					IsPrior:          false,
 | 
			
		||||
					IsOn:             true,
 | 
			
		||||
					FirewallPolicyId: 0,
 | 
			
		||||
				}
 | 
			
		||||
				firewallRefJSON, err := json.Marshal(firewallRef)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					this.ErrorPage(err)
 | 
			
		||||
					return
 | 
			
		||||
				}
 | 
			
		||||
				_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebFirewall(this.AdminContext(), &pb.UpdateHTTPWebFirewallRequest{
 | 
			
		||||
					WebId:        webConfig.Id,
 | 
			
		||||
					FirewallJSON: firewallRefJSON,
 | 
			
		||||
				})
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					this.ErrorPage(err)
 | 
			
		||||
					return
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			// remoteAddr
 | 
			
		||||
			var remoteAddrConfig = &serverconfigs.HTTPRemoteAddrConfig{
 | 
			
		||||
				IsOn:  true,
 | 
			
		||||
				Value: "${rawRemoteAddr}",
 | 
			
		||||
			}
 | 
			
		||||
			if params.RemoteAddrIsOn {
 | 
			
		||||
				remoteAddrConfig.Value = "${remoteAddr}"
 | 
			
		||||
			}
 | 
			
		||||
			remoteAddrConfigJSON, err := json.Marshal(remoteAddrConfig)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				this.ErrorPage(err)
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
			_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRemoteAddr(this.AdminContext(), &pb.UpdateHTTPWebRemoteAddrRequest{
 | 
			
		||||
				WebId:          webConfig.Id,
 | 
			
		||||
				RemoteAddrJSON: remoteAddrConfigJSON,
 | 
			
		||||
			})
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				this.ErrorPage(err)
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@ Vue.component("http-remote-addr-config-box", {
 | 
			
		||||
			config = {
 | 
			
		||||
				isPrior: false,
 | 
			
		||||
				isOn: false,
 | 
			
		||||
				value: "${remoteAddr}",
 | 
			
		||||
				value: "${rawRemoteAddr}",
 | 
			
		||||
				isCustomized: false
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
@@ -20,18 +20,18 @@ Vue.component("http-remote-addr-config-box", {
 | 
			
		||||
			config: config,
 | 
			
		||||
			options: [
 | 
			
		||||
				{
 | 
			
		||||
					name: "直接访问",
 | 
			
		||||
					description: "用户可以直接访问边缘节点,即 \"用户 --> 边缘节点\" 模式。",
 | 
			
		||||
					name: "直接获取",
 | 
			
		||||
					description: "用户直接访问边缘节点,即 \"用户 --> 边缘节点\" 模式,这时候可以直接从连接中读取到真实的IP地址。",
 | 
			
		||||
					value: "${rawRemoteAddr}"
 | 
			
		||||
				},
 | 
			
		||||
				{
 | 
			
		||||
					name: "代理转发",
 | 
			
		||||
					description: "用户和边缘节点之间有别的代理服务转发,即 \"用户 --> [第三方代理服务] --> 边缘节点\"。",
 | 
			
		||||
					name: "从上级代理中获取",
 | 
			
		||||
					description: "用户和边缘节点之间有别的代理服务转发,即 \"用户 --> [第三方代理服务] --> 边缘节点\",这时候只能从上级代理中获取传递的IP地址。",
 | 
			
		||||
					value: "${remoteAddr}"
 | 
			
		||||
				},
 | 
			
		||||
				{
 | 
			
		||||
					name: "[自定义]",
 | 
			
		||||
					description: "",
 | 
			
		||||
					description: "通过自定义变量来获取客户端真实的IP地址。",
 | 
			
		||||
					value: ""
 | 
			
		||||
				}
 | 
			
		||||
			],
 | 
			
		||||
@@ -69,7 +69,7 @@ Vue.component("http-remote-addr-config-box", {
 | 
			
		||||
		</tbody>
 | 
			
		||||
		<tbody v-show="isOn()">
 | 
			
		||||
			<tr>
 | 
			
		||||
				<td>用户访问节点方式 *</td>
 | 
			
		||||
				<td>获取IP方式 *</td>
 | 
			
		||||
				<td>
 | 
			
		||||
					<select class="ui dropdown auto-width" v-model="optionValue" @change="changeOptionValue">
 | 
			
		||||
						<option v-for="option in options" :value="option.value">{{option.name}}</option>
 | 
			
		||||
 
 | 
			
		||||
@@ -92,6 +92,12 @@
 | 
			
		||||
                <checkbox checked="checked" name="accessLogIsOn">访问日志</checkbox>
 | 
			
		||||
                   
 | 
			
		||||
                <checkbox checked="checked" name="websocketIsOn">Websocket</checkbox>
 | 
			
		||||
                   
 | 
			
		||||
                <checkbox checked="checked" name="cacheIsOn">缓存</checkbox>
 | 
			
		||||
                   
 | 
			
		||||
                <checkbox name="wafIsOn">WAF</checkbox>
 | 
			
		||||
                   
 | 
			
		||||
                <checkbox name="remoteAddrIsOn">从上级代理中读取IP <tip-icon content="此配置非常重要,请不要轻易选中!如果用户需要通过别的代理服务才能访问到这个网站服务,才需要选中。"></tip-icon> </checkbox>
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user