mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 13:10:26 +08:00 
			
		
		
		
	可以配置是否在反向代理中添加X-Real-IP和X-Forwarded-*
This commit is contained in:
		@@ -1,50 +1,86 @@
 | 
			
		||||
Vue.component("reverse-proxy-box", {
 | 
			
		||||
	props: ["v-reverse-proxy-ref", "v-reverse-proxy-config", "v-is-location", "v-family"],
 | 
			
		||||
	data: function () {
 | 
			
		||||
		let reverseProxyRef = this.vReverseProxyRef
 | 
			
		||||
		if (reverseProxyRef == null) {
 | 
			
		||||
			reverseProxyRef = {
 | 
			
		||||
				isPrior: false,
 | 
			
		||||
				isOn: false,
 | 
			
		||||
				reverseProxyId: 0
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
    props: ["v-reverse-proxy-ref", "v-reverse-proxy-config", "v-is-location", "v-family"],
 | 
			
		||||
    data: function () {
 | 
			
		||||
        let reverseProxyRef = this.vReverseProxyRef
 | 
			
		||||
        if (reverseProxyRef == null) {
 | 
			
		||||
            reverseProxyRef = {
 | 
			
		||||
                isPrior: false,
 | 
			
		||||
                isOn: false,
 | 
			
		||||
                reverseProxyId: 0
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		let reverseProxyConfig = this.vReverseProxyConfig
 | 
			
		||||
		if (reverseProxyConfig == null) {
 | 
			
		||||
			reverseProxyConfig = {
 | 
			
		||||
				requestPath: "",
 | 
			
		||||
				stripPrefix: "",
 | 
			
		||||
				requestURI: "",
 | 
			
		||||
				requestHost: "",
 | 
			
		||||
				requestHostType: 0
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		return {
 | 
			
		||||
			reverseProxyRef: reverseProxyRef,
 | 
			
		||||
			reverseProxyConfig: reverseProxyConfig,
 | 
			
		||||
			advancedVisible: false,
 | 
			
		||||
            family: this.vFamily
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
	watch: {
 | 
			
		||||
		"reverseProxyConfig.requestHostType": function (v) {
 | 
			
		||||
			let requestHostType = parseInt(v)
 | 
			
		||||
			if (isNaN(requestHostType)) {
 | 
			
		||||
				requestHostType = 0
 | 
			
		||||
			}
 | 
			
		||||
			this.reverseProxyConfig.requestHostType = requestHostType
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
	methods: {
 | 
			
		||||
		isOn: function () {
 | 
			
		||||
			return (!this.vIsLocation || this.reverseProxyRef.isPrior) && this.reverseProxyRef.isOn
 | 
			
		||||
		},
 | 
			
		||||
		changeAdvancedVisible: function (v) {
 | 
			
		||||
			this.advancedVisible = v
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
	template: `<div>
 | 
			
		||||
        let reverseProxyConfig = this.vReverseProxyConfig
 | 
			
		||||
        if (reverseProxyConfig == null) {
 | 
			
		||||
            reverseProxyConfig = {
 | 
			
		||||
                requestPath: "",
 | 
			
		||||
                stripPrefix: "",
 | 
			
		||||
                requestURI: "",
 | 
			
		||||
                requestHost: "",
 | 
			
		||||
                requestHostType: 0,
 | 
			
		||||
                addHeaders: []
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        let forwardHeaders = [
 | 
			
		||||
            {
 | 
			
		||||
                name: "X-Real-IP",
 | 
			
		||||
                isChecked: false
 | 
			
		||||
            },
 | 
			
		||||
            {
 | 
			
		||||
                name: "X-Forwarded-For",
 | 
			
		||||
                isChecked: false
 | 
			
		||||
            },
 | 
			
		||||
            {
 | 
			
		||||
                name: "X-Forwarded-By",
 | 
			
		||||
                isChecked: false
 | 
			
		||||
            },
 | 
			
		||||
            {
 | 
			
		||||
                name: "X-Forwarded-Host",
 | 
			
		||||
                isChecked: false
 | 
			
		||||
            },
 | 
			
		||||
            {
 | 
			
		||||
                name: "X-Forwarded-Proto",
 | 
			
		||||
                isChecked: false
 | 
			
		||||
            }
 | 
			
		||||
        ]
 | 
			
		||||
        forwardHeaders.forEach(function (v) {
 | 
			
		||||
            v.isChecked = reverseProxyConfig.addHeaders.$contains(v.name)
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        return {
 | 
			
		||||
            reverseProxyRef: reverseProxyRef,
 | 
			
		||||
            reverseProxyConfig: reverseProxyConfig,
 | 
			
		||||
            advancedVisible: false,
 | 
			
		||||
            family: this.vFamily,
 | 
			
		||||
            forwardHeaders: forwardHeaders
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
    watch: {
 | 
			
		||||
        "reverseProxyConfig.requestHostType": function (v) {
 | 
			
		||||
            let requestHostType = parseInt(v)
 | 
			
		||||
            if (isNaN(requestHostType)) {
 | 
			
		||||
                requestHostType = 0
 | 
			
		||||
            }
 | 
			
		||||
            this.reverseProxyConfig.requestHostType = requestHostType
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
    methods: {
 | 
			
		||||
        isOn: function () {
 | 
			
		||||
            return (!this.vIsLocation || this.reverseProxyRef.isPrior) && this.reverseProxyRef.isOn
 | 
			
		||||
        },
 | 
			
		||||
        changeAdvancedVisible: function (v) {
 | 
			
		||||
            this.advancedVisible = v
 | 
			
		||||
        },
 | 
			
		||||
        changeAddHeader: function () {
 | 
			
		||||
            this.reverseProxyConfig.addHeaders = this.forwardHeaders.filter(function (v) {
 | 
			
		||||
                return v.isChecked
 | 
			
		||||
            }).map(function (v) {
 | 
			
		||||
                return v.name
 | 
			
		||||
            })
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
    template: `<div>
 | 
			
		||||
	<input type="hidden" name="reverseProxyRefJSON" :value="JSON.stringify(reverseProxyRef)"/>
 | 
			
		||||
	<input type="hidden" name="reverseProxyJSON" :value="JSON.stringify(reverseProxyConfig)"/>
 | 
			
		||||
	<table class="ui table selectable definition">
 | 
			
		||||
@@ -77,6 +113,16 @@ Vue.component("reverse-proxy-box", {
 | 
			
		||||
		</tbody>
 | 
			
		||||
		<more-options-tbody @change="changeAdvancedVisible" v-if="isOn()"></more-options-tbody>
 | 
			
		||||
		<tbody v-show="isOn() && advancedVisible">
 | 
			
		||||
		    <tr v-show="family == null || family == 'http'">
 | 
			
		||||
		        <td>自动添加的Header</td>
 | 
			
		||||
		        <td>
 | 
			
		||||
		            <div>
 | 
			
		||||
		                <div style="width: 20em; float: left; margin-bottom: 1em" v-for="header in forwardHeaders" :key="header.name">
 | 
			
		||||
		                    <checkbox v-model="header.isChecked" @input="changeAddHeader">{{header.name}}</checkbox>
 | 
			
		||||
                        </div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                </td> 
 | 
			
		||||
            </tr>
 | 
			
		||||
			<tr v-show="family == null || family == 'http'">
 | 
			
		||||
				<td>请求URI<em>(RequestURI)</em></td>
 | 
			
		||||
				<td>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user