Vue.component("http-remote-addr-config-box", { props: ["v-remote-addr-config", "v-is-location", "v-is-group"], data: function () { let config = this.vRemoteAddrConfig if (config == null) { config = { isPrior: false, isOn: false, value: "${rawRemoteAddr}", type: "default", requestHeaderName: "" } } // type if (config.type == null || config.type.length == 0) { config.type = "default" switch (config.value) { case "${rawRemoteAddr}": config.type = "default" break case "${remoteAddrValue}": config.type = "default" break case "${remoteAddr}": config.type = "proxy" break default: if (config.value != null && config.value.length > 0) { config.type = "variable" } } } // value if (config.value == null || config.value.length == 0) { config.value = "${rawRemoteAddr}" } return { config: config, options: [ { name: "直接获取", description: "用户直接访问边缘节点,即 \"用户 --> 边缘节点\" 模式,这时候系统会试图从直接的连接中读取到客户端IP地址。", value: "${rawRemoteAddr}", type: "default" }, { name: "从上级代理中获取", description: "用户和边缘节点之间有别的代理服务转发,即 \"用户 --> [第三方代理服务] --> 边缘节点\",这时候只能从上级代理中获取传递的IP地址;上级代理传递的请求报头中必须包含 X-Forwarded-For 或 X-Real-IP 信息。", value: "${remoteAddr}", type: "proxy" }, { name: "从请求报头中读取", description: "从自定义请求报头读取客户端IP。", value: "", type: "requestHeader" }, { name: "[自定义变量]", description: "通过自定义变量来获取客户端真实的IP地址。", value: "", type: "variable" } ] } }, watch: { "config.requestHeaderName": function (value) { if (this.config.type == "requestHeader"){ this.config.value = "${header." + value.trim() + "}" } } }, methods: { isOn: function () { return ((!this.vIsLocation && !this.vIsGroup) || this.config.isPrior) && this.config.isOn }, changeOptionType: function () { let that = this switch(this.config.type) { case "default": this.config.value = "${rawRemoteAddr}" break case "proxy": this.config.value = "${remoteAddr}" break case "requestHeader": this.config.value = "" if (this.requestHeaderName != null && this.requestHeaderName.length > 0) { this.config.value = "${header." + this.requestHeaderName + "}" } setTimeout(function () { that.$refs.requestHeaderInput.focus() }) break case "variable": this.config.value = "${rawRemoteAddr}" setTimeout(function () { that.$refs.variableInput.focus() }) break } } }, template: `
| 启用访客IP设置 |
选中后,表示使用自定义的请求变量获取客户端IP。 |
| 获取IP方式 * |
{{option.description}} |
| 请求报头 * |
请输入包含有客户端IP的请求报头,需要注意大小写,常见的有 |
| 读取IP变量值 * |
通过此变量获取用户的IP地址。具体可用的请求变量列表可参考官方网站文档;比如通过报头传递IP的情形,可以使用 |