mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 05:00:25 +08:00 
			
		
		
		
	源站地址填写为HTTP时,自动检测HTTPS是否可用
This commit is contained in:
		@@ -36,9 +36,10 @@
 | 
			
		||||
			<td>
 | 
			
		||||
				<div class="ui input left labeled">
 | 
			
		||||
                    <span class="ui label">{{protocol.toLowerCase()}}://</span>
 | 
			
		||||
                    <input type="text" name="addr" ref="focus" v-model="addr" @input="changeAddr"/>
 | 
			
		||||
                    <input type="text" name="addr" ref="focus" v-model="addr" @input="changeAddr" @change="detectHTTPS"/>
 | 
			
		||||
                </div>
 | 
			
		||||
				<p class="comment"><span class="red" v-if="addrError.length > 0">{{addrError}}</span>源站服务器地址,通常是一个IP(或域名)加端口<span v-if="serverType == 'httpProxy'">,不需要加 http:// 或 https://</span>。</p>
 | 
			
		||||
                <p class="comment" style="padding-bottom: 0; margin-bottom: 0" v-if="addrError.length == 0 && adviceHTTPS && protocol == 'http'"><span class="red">系统检测到当前源站有HTTPS协议可用,是否切换到HTTPS协议?</span> <a href="" @click.prevent="switchToHTTPS">[点此切换]</a></p>
 | 
			
		||||
				<p class="comment"><span class="red" v-if="addrError.length > 0">{{addrError}}</span>源站服务器地址,通常是一个IP(或域名)加端口,80和443端口可以省略<span v-if="serverType == 'httpProxy'">,不需要加 http:// 或 https://</span>。</p>
 | 
			
		||||
			</td>
 | 
			
		||||
		</tr>
 | 
			
		||||
        <tr v-if="(isHTTP || protocol == 'tls') && !isOSS">
 | 
			
		||||
 
 | 
			
		||||
@@ -18,10 +18,18 @@ Tea.context(function () {
 | 
			
		||||
	this.changeProtocol = function () {
 | 
			
		||||
		this.isOSS = this.protocol.startsWith("oss:")
 | 
			
		||||
 | 
			
		||||
		if (this.protocol == "http") {
 | 
			
		||||
			this.detectHTTPS()
 | 
			
		||||
		} else {
 | 
			
		||||
			this.adviceHTTPS = false
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		this.checkPort()
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.changeAddr = function () {
 | 
			
		||||
		this.adviceHTTPS = false
 | 
			
		||||
 | 
			
		||||
		if (this.serverType == "httpProxy") {
 | 
			
		||||
			if (this.addr.startsWith("http://")) {
 | 
			
		||||
				this.protocol = "http"
 | 
			
		||||
@@ -54,4 +62,42 @@ Tea.context(function () {
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.adviceHTTPS = false
 | 
			
		||||
 | 
			
		||||
	var isDetectingHTTPS = false
 | 
			
		||||
	this.detectHTTPS = function () {
 | 
			
		||||
		if (isDetectingHTTPS) {
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		isDetectingHTTPS = true
 | 
			
		||||
 | 
			
		||||
		this.adviceHTTPS = false
 | 
			
		||||
		if (this.protocol == "http") {
 | 
			
		||||
			this.$post("/servers/server/settings/origins/detectHTTPS")
 | 
			
		||||
				.params({
 | 
			
		||||
					addr: this.addr
 | 
			
		||||
				})
 | 
			
		||||
				.success(function (resp) {
 | 
			
		||||
					this.adviceHTTPS = resp.data.isOk
 | 
			
		||||
					if (resp.data.isOk) {
 | 
			
		||||
						this.addr = resp.data.addr
 | 
			
		||||
					}
 | 
			
		||||
				})
 | 
			
		||||
				.done(function () {
 | 
			
		||||
					isDetectingHTTPS = false
 | 
			
		||||
				})
 | 
			
		||||
		} else {
 | 
			
		||||
			isDetectingHTTPS = false
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.switchToHTTPS = function () {
 | 
			
		||||
		this.adviceHTTPS = false
 | 
			
		||||
		this.protocol = "https"
 | 
			
		||||
 | 
			
		||||
		if (this.addr.endsWith(":80")) {
 | 
			
		||||
			this.addr = this.addr.substring(0, this.addr.length - (":80").length)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
@@ -45,6 +45,7 @@ Tea.context(function () {
 | 
			
		||||
 | 
			
		||||
	this.addOrigin = function () {
 | 
			
		||||
		teaweb.popup("/servers/addOriginPopup?serverType=" + this.serverType, {
 | 
			
		||||
			width: "45em",
 | 
			
		||||
			height: "27em",
 | 
			
		||||
			callback: function (resp) {
 | 
			
		||||
				this.origins.push(resp.data.origin);
 | 
			
		||||
 
 | 
			
		||||
@@ -38,10 +38,10 @@
 | 
			
		||||
			<td>
 | 
			
		||||
                <div class="ui input left labeled">
 | 
			
		||||
                    <span class="ui label">{{protocol.toLowerCase()}}://</span>
 | 
			
		||||
				    <input type="text" name="addr" ref="focus" v-model="addr" @input="changeAddr"/>
 | 
			
		||||
				    <input type="text" name="addr" ref="focus" v-model="addr" @input="changeAddr" @change="detectHTTPS"/>
 | 
			
		||||
                </div>
 | 
			
		||||
				<p class="comment"><span class="red" v-if="addrError.length > 0">{{addrError}}</span>
 | 
			
		||||
                    源站服务器地址,通常是一个IP(或域名)加端口<span v-if="serverType == 'httpProxy'">,不需要加 http:// 或 https://</span>。</p>
 | 
			
		||||
                <p class="comment" style="padding-bottom: 0; margin-bottom: 0" v-if="addrError.length == 0 && adviceHTTPS && protocol == 'http'"><span class="red">系统检测到当前源站有HTTPS协议可用,是否切换到HTTPS协议?</span> <a href="" @click.prevent="switchToHTTPS">[点此切换]</a></p>
 | 
			
		||||
				<p class="comment"><span class="red" v-if="addrError.length > 0">{{addrError}}</span>源站服务器地址,通常是一个IP(或域名)加端口,80和443端口可以省略<span v-if="serverType == 'httpProxy'">,不需要加 http:// 或 https://</span>。</p>
 | 
			
		||||
			</td>
 | 
			
		||||
		</tr>
 | 
			
		||||
        <tr v-if="(isHTTP || protocol == 'tls') && !isOSS">
 | 
			
		||||
 
 | 
			
		||||
@@ -16,10 +16,18 @@ Tea.context(function () {
 | 
			
		||||
	this.changeProtocol = function () {
 | 
			
		||||
		this.isOSS = this.protocol.startsWith("oss:")
 | 
			
		||||
 | 
			
		||||
		if (this.protocol == "http") {
 | 
			
		||||
			this.detectHTTPS()
 | 
			
		||||
		} else {
 | 
			
		||||
			this.adviceHTTPS = false
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		this.checkPort()
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.changeAddr = function () {
 | 
			
		||||
		this.adviceHTTPS = false
 | 
			
		||||
 | 
			
		||||
		if (this.serverType == "httpProxy") {
 | 
			
		||||
			if (this.addr.startsWith("http://")) {
 | 
			
		||||
				this.protocol = "http"
 | 
			
		||||
@@ -52,4 +60,41 @@ Tea.context(function () {
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.adviceHTTPS = false
 | 
			
		||||
	var isDetectingHTTPS = false
 | 
			
		||||
	this.detectHTTPS = function () {
 | 
			
		||||
		if (isDetectingHTTPS) {
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		isDetectingHTTPS = true
 | 
			
		||||
 | 
			
		||||
		this.adviceHTTPS = false
 | 
			
		||||
		if (this.protocol == "http") {
 | 
			
		||||
			this.$post(".detectHTTPS")
 | 
			
		||||
				.params({
 | 
			
		||||
					addr: this.addr
 | 
			
		||||
				})
 | 
			
		||||
				.success(function (resp) {
 | 
			
		||||
					this.adviceHTTPS = resp.data.isOk
 | 
			
		||||
					if (resp.data.isOk) {
 | 
			
		||||
						this.addr = resp.data.addr
 | 
			
		||||
					}
 | 
			
		||||
				})
 | 
			
		||||
				.done(function () {
 | 
			
		||||
					isDetectingHTTPS = false
 | 
			
		||||
				})
 | 
			
		||||
		} else {
 | 
			
		||||
			isDetectingHTTPS = false
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.switchToHTTPS = function () {
 | 
			
		||||
		this.adviceHTTPS = false
 | 
			
		||||
		this.protocol = "https"
 | 
			
		||||
 | 
			
		||||
		if (this.addr.endsWith(":80")) {
 | 
			
		||||
			this.addr = this.addr.substring(0, this.addr.length - (":80").length)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
@@ -42,7 +42,7 @@
 | 
			
		||||
                    <span class="ui label">{{origin.protocol.toLowerCase()}}://</span>
 | 
			
		||||
				    <input type="text" name="addr" ref="focus" v-model="origin.addr" @input="changeAddr"/>
 | 
			
		||||
                </div>
 | 
			
		||||
				<p class="comment"><span class="red" v-if="addrError.length > 0">{{addrError}}</span>源站服务器地址,通常是一个IP(或域名)加端口<span v-if="serverType == 'httpProxy'">,不需要加 http:// 或 https://</span>。</p>
 | 
			
		||||
				<p class="comment"><span class="red" v-if="addrError.length > 0">{{addrError}}</span>源站服务器地址,通常是一个IP(或域名)加端口,80和443端口可以省略<span v-if="serverType == 'httpProxy'">,不需要加 http:// 或 https://</span>。</p>
 | 
			
		||||
			</td>
 | 
			
		||||
		</tr>
 | 
			
		||||
        <tr v-if="(isHTTP || origin.protocol == 'tls') && !isOSS">
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user