Add host for WS

This commit is contained in:
mhsanaei 2024-04-01 17:02:02 +04:30
parent 44b7eb881c
commit 4e20bb5f02
5 changed files with 50 additions and 10 deletions

View file

@ -202,8 +202,13 @@ func (s *SubService) genVmessLink(inbound *model.Inbound, email string) string {
case "ws": case "ws":
ws, _ := stream["wsSettings"].(map[string]interface{}) ws, _ := stream["wsSettings"].(map[string]interface{})
obj["path"] = ws["path"].(string) obj["path"] = ws["path"].(string)
headers, _ := ws["headers"].(map[string]interface{}) obj["host"] = ws["host"].(string)
obj["host"] = searchHost(headers) if headers, ok := ws["headers"].(map[string]interface{}); ok {
hostFromHeaders := searchHost(headers)
if hostFromHeaders != "" {
obj["host"] = hostFromHeaders
}
}
case "http": case "http":
obj["net"] = "h2" obj["net"] = "h2"
http, _ := stream["httpSettings"].(map[string]interface{}) http, _ := stream["httpSettings"].(map[string]interface{})
@ -343,7 +348,13 @@ func (s *SubService) genVlessLink(inbound *model.Inbound, email string) string {
ws, _ := stream["wsSettings"].(map[string]interface{}) ws, _ := stream["wsSettings"].(map[string]interface{})
params["path"] = ws["path"].(string) params["path"] = ws["path"].(string)
headers, _ := ws["headers"].(map[string]interface{}) headers, _ := ws["headers"].(map[string]interface{})
params["host"] = searchHost(headers) params["host"] = ws["host"].(string)
if headers != nil {
hostFromHeaders := searchHost(headers)
if hostFromHeaders != "" {
params["host"] = hostFromHeaders
}
}
case "http": case "http":
http, _ := stream["httpSettings"].(map[string]interface{}) http, _ := stream["httpSettings"].(map[string]interface{})
params["path"] = http["path"].(string) params["path"] = http["path"].(string)
@ -560,7 +571,13 @@ func (s *SubService) genTrojanLink(inbound *model.Inbound, email string) string
ws, _ := stream["wsSettings"].(map[string]interface{}) ws, _ := stream["wsSettings"].(map[string]interface{})
params["path"] = ws["path"].(string) params["path"] = ws["path"].(string)
headers, _ := ws["headers"].(map[string]interface{}) headers, _ := ws["headers"].(map[string]interface{})
params["host"] = searchHost(headers) params["host"] = ws["host"].(string)
if headers != nil {
hostFromHeaders := searchHost(headers)
if hostFromHeaders != "" {
params["host"] = hostFromHeaders
}
}
case "http": case "http":
http, _ := stream["httpSettings"].(map[string]interface{}) http, _ := stream["httpSettings"].(map[string]interface{})
params["path"] = http["path"].(string) params["path"] = http["path"].(string)
@ -778,7 +795,13 @@ func (s *SubService) genShadowsocksLink(inbound *model.Inbound, email string) st
ws, _ := stream["wsSettings"].(map[string]interface{}) ws, _ := stream["wsSettings"].(map[string]interface{})
params["path"] = ws["path"].(string) params["path"] = ws["path"].(string)
headers, _ := ws["headers"].(map[string]interface{}) headers, _ := ws["headers"].(map[string]interface{})
params["host"] = searchHost(headers) params["host"] = ws["host"].(string)
if headers != nil {
hostFromHeaders := searchHost(headers)
if hostFromHeaders != "" {
params["host"] = hostFromHeaders
}
}
case "http": case "http":
http, _ := stream["httpSettings"].(map[string]interface{}) http, _ := stream["httpSettings"].(map[string]interface{})
params["path"] = http["path"].(string) params["path"] = http["path"].(string)

View file

@ -194,6 +194,7 @@ class WsStreamSettings extends CommonClass {
static fromJson(json={}) { static fromJson(json={}) {
return new WsStreamSettings( return new WsStreamSettings(
json.path, json.path,
json.host,
json.headers && !ObjectUtil.isEmpty(json.headers.Host) ? json.headers.Host : '', json.headers && !ObjectUtil.isEmpty(json.headers.Host) ? json.headers.Host : '',
); );
} }
@ -201,6 +202,7 @@ class WsStreamSettings extends CommonClass {
toJson() { toJson() {
return { return {
path: this.path, path: this.path,
host: this.host,
headers: ObjectUtil.isEmpty(this.host) ? undefined : {Host: this.host}, headers: ObjectUtil.isEmpty(this.host) ? undefined : {Host: this.host},
}; };
} }

View file

@ -338,10 +338,11 @@ class KcpStreamSettings extends XrayCommonClass {
} }
class WsStreamSettings extends XrayCommonClass { class WsStreamSettings extends XrayCommonClass {
constructor(acceptProxyProtocol=false, path='/', headers=[]) { constructor(acceptProxyProtocol=false, path='/', host='', headers=[]) {
super(); super();
this.acceptProxyProtocol = acceptProxyProtocol; this.acceptProxyProtocol = acceptProxyProtocol;
this.path = path; this.path = path;
this.host = host;
this.headers = headers; this.headers = headers;
} }
@ -366,6 +367,7 @@ class WsStreamSettings extends XrayCommonClass {
return new WsStreamSettings( return new WsStreamSettings(
json.acceptProxyProtocol, json.acceptProxyProtocol,
json.path, json.path,
json.host,
XrayCommonClass.toHeaders(json.headers), XrayCommonClass.toHeaders(json.headers),
); );
} }
@ -374,6 +376,7 @@ class WsStreamSettings extends XrayCommonClass {
return { return {
acceptProxyProtocol: this.acceptProxyProtocol, acceptProxyProtocol: this.acceptProxyProtocol,
path: this.path, path: this.path,
host: this.host,
headers: XrayCommonClass.toV2Headers(this.headers, false), headers: XrayCommonClass.toV2Headers(this.headers, false),
}; };
} }
@ -1108,7 +1111,12 @@ class Inbound extends XrayCommonClass {
if (this.isTcp) { if (this.isTcp) {
return this.stream.tcp.request.getHeader("Host"); return this.stream.tcp.request.getHeader("Host");
} else if (this.isWs) { } else if (this.isWs) {
return this.stream.ws.getHeader("Host"); const hostHeader = this.stream.ws.getHeader("Host");
if (hostHeader !== null) {
return hostHeader;
} else {
return this.stream.ws.host;
}
} else if (this.isH2) { } else if (this.isH2) {
return this.stream.http.host[0]; return this.stream.http.host[0];
} else if (this.isHttpupgrade) { } else if (this.isHttpupgrade) {
@ -1230,6 +1238,7 @@ class Inbound extends XrayCommonClass {
} else if (network === 'ws') { } else if (network === 'ws') {
let ws = this.stream.ws; let ws = this.stream.ws;
obj.path = ws.path; obj.path = ws.path;
obj.host = ws.host;
let index = ws.headers.findIndex(header => header.name.toLowerCase() === 'host'); let index = ws.headers.findIndex(header => header.name.toLowerCase() === 'host');
if (index >= 0) { if (index >= 0) {
obj.host = ws.headers[index].value; obj.host = ws.headers[index].value;
@ -1300,6 +1309,7 @@ class Inbound extends XrayCommonClass {
case "ws": case "ws":
const ws = this.stream.ws; const ws = this.stream.ws;
params.set("path", ws.path); params.set("path", ws.path);
params.set("host", ws.host);
const index = ws.headers.findIndex(header => header.name.toLowerCase() === 'host'); const index = ws.headers.findIndex(header => header.name.toLowerCase() === 'host');
if (index >= 0) { if (index >= 0) {
const host = ws.headers[index].value; const host = ws.headers[index].value;
@ -1420,6 +1430,7 @@ class Inbound extends XrayCommonClass {
case "ws": case "ws":
const ws = this.stream.ws; const ws = this.stream.ws;
params.set("path", ws.path); params.set("path", ws.path);
params.set("host", ws.host);
const index = ws.headers.findIndex(header => header.name.toLowerCase() === 'host'); const index = ws.headers.findIndex(header => header.name.toLowerCase() === 'host');
if (index >= 0) { if (index >= 0) {
const host = ws.headers[index].value; const host = ws.headers[index].value;
@ -1507,6 +1518,7 @@ class Inbound extends XrayCommonClass {
case "ws": case "ws":
const ws = this.stream.ws; const ws = this.stream.ws;
params.set("path", ws.path); params.set("path", ws.path);
params.set("host", ws.host);
const index = ws.headers.findIndex(header => header.name.toLowerCase() === 'host'); const index = ws.headers.findIndex(header => header.name.toLowerCase() === 'host');
if (index >= 0) { if (index >= 0) {
const host = ws.headers[index].value; const host = ws.headers[index].value;

View file

@ -3,11 +3,11 @@
<a-form-item label="PROXY Protocol"> <a-form-item label="PROXY Protocol">
<a-switch v-model="inbound.stream.httpupgrade.acceptProxyProtocol"></a-switch> <a-switch v-model="inbound.stream.httpupgrade.acceptProxyProtocol"></a-switch>
</a-form-item> </a-form-item>
<a-form-item label='{{ i18n "path" }}'>
<a-input v-model.trim="inbound.stream.httpupgrade.path"></a-input>
</a-form-item>
<a-form-item label='{{ i18n "host" }}'> <a-form-item label='{{ i18n "host" }}'>
<a-input v-model.trim="inbound.stream.httpupgrade.host"></a-input> <a-input v-model.trim="inbound.stream.httpupgrade.host"></a-input>
</a-form-item> </a-form-item>
<a-form-item label='{{ i18n "path" }}'>
<a-input v-model.trim="inbound.stream.httpupgrade.path"></a-input>
</a-form-item>
</a-form> </a-form>
{{end}} {{end}}

View file

@ -3,6 +3,9 @@
<a-form-item label="PROXY Protocol"> <a-form-item label="PROXY Protocol">
<a-switch v-model="inbound.stream.ws.acceptProxyProtocol"></a-switch> <a-switch v-model="inbound.stream.ws.acceptProxyProtocol"></a-switch>
</a-form-item> </a-form-item>
<a-form-item label='{{ i18n "host" }}'>
<a-input v-model.trim="inbound.stream.ws.host"></a-input>
</a-form-item>
<a-form-item label='{{ i18n "path" }}'> <a-form-item label='{{ i18n "path" }}'>
<a-input v-model.trim="inbound.stream.ws.path"></a-input> <a-input v-model.trim="inbound.stream.ws.path"></a-input>
</a-form-item> </a-form-item>