mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-20 05:52:24 +00:00
Merge pull request #214 from MHSanaei/dev
bug fixed + reality for trojan
This commit is contained in:
commit
2c7b8d1d36
4 changed files with 101 additions and 40 deletions
|
@ -600,8 +600,20 @@ TlsStreamSettings.Settings = class extends XrayCommonClass {
|
||||||
};
|
};
|
||||||
|
|
||||||
class RealityStreamSettings extends XrayCommonClass {
|
class RealityStreamSettings extends XrayCommonClass {
|
||||||
constructor(show = false,xver = 0, fingerprint = UTLS_FINGERPRINT.UTLS_FIREFOX, dest = 'github.io:443', serverNames = 'github.io,www.github.io,', privateKey = RandomUtil.randomX25519PrivateKey(), publicKey = '', minClient = '',
|
|
||||||
maxClient = '', maxTimediff = 0, shortIds = RandomUtil.randowShortId()) {
|
constructor(
|
||||||
|
show = false,xver = 0,
|
||||||
|
fingerprint = UTLS_FINGERPRINT.UTLS_FIREFOX,
|
||||||
|
dest = 'yahoo.com:443',
|
||||||
|
serverNames = 'yahoo.com,www.yahoo.com',
|
||||||
|
privateKey = RandomUtil.randomX25519PrivateKey(),
|
||||||
|
publicKey = '',
|
||||||
|
minClient = '',
|
||||||
|
maxClient = '',
|
||||||
|
maxTimediff = 0,
|
||||||
|
shortIds = RandomUtil.randowShortId()
|
||||||
|
)
|
||||||
|
{
|
||||||
super();
|
super();
|
||||||
this.show = show;
|
this.show = show;
|
||||||
this.xver = xver;
|
this.xver = xver;
|
||||||
|
@ -614,9 +626,7 @@ class RealityStreamSettings extends XrayCommonClass {
|
||||||
this.maxClient = maxClient;
|
this.maxClient = maxClient;
|
||||||
this.maxTimediff = maxTimediff;
|
this.maxTimediff = maxTimediff;
|
||||||
this.shortIds = shortIds instanceof Array ? shortIds.join(",") : shortIds;
|
this.shortIds = shortIds instanceof Array ? shortIds.join(",") : shortIds;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json = {}) {
|
static fromJson(json = {}) {
|
||||||
return new RealityStreamSettings(
|
return new RealityStreamSettings(
|
||||||
json.show,
|
json.show,
|
||||||
|
@ -631,7 +641,6 @@ class RealityStreamSettings extends XrayCommonClass {
|
||||||
json.maxTimediff,
|
json.maxTimediff,
|
||||||
json.shortIds
|
json.shortIds
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
toJson() {
|
toJson() {
|
||||||
return {
|
return {
|
||||||
|
@ -715,7 +724,7 @@ class StreamSettings extends XrayCommonClass {
|
||||||
static fromJson(json = {}) {
|
static fromJson(json = {}) {
|
||||||
let tls, reality;
|
let tls, reality;
|
||||||
if (json.security === "xtls") {
|
if (json.security === "xtls") {
|
||||||
tls = TlsStreamSettings.fromJson(json.xtlsSettings);
|
tls = TlsStreamSettings.fromJson(json.XTLSSettings);
|
||||||
} else if (json.security === "tls") {
|
} else if (json.security === "tls") {
|
||||||
tls = TlsStreamSettings.fromJson(json.tlsSettings);
|
tls = TlsStreamSettings.fromJson(json.tlsSettings);
|
||||||
}
|
}
|
||||||
|
@ -1056,6 +1065,7 @@ class Inbound extends XrayCommonClass {
|
||||||
canEnableReality() {
|
canEnableReality() {
|
||||||
switch (this.protocol) {
|
switch (this.protocol) {
|
||||||
case Protocols.VLESS:
|
case Protocols.VLESS:
|
||||||
|
case Protocols.TROJAN:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
@ -1379,6 +1389,26 @@ class Inbound extends XrayCommonClass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.reality) {
|
||||||
|
params.set("security", "reality");
|
||||||
|
if (!ObjectUtil.isArrEmpty(this.stream.reality.serverNames)) {
|
||||||
|
params.set("sni", this.stream.reality.serverNames.split(/,|,|\s+/)[0]);
|
||||||
|
}
|
||||||
|
if (this.stream.reality.publicKey != "") {
|
||||||
|
//params.set("pbk", Ed25519.getPublicKey(this.stream.reality.privateKey));
|
||||||
|
params.set("pbk", this.stream.reality.publicKey);
|
||||||
|
}
|
||||||
|
if (this.stream.network === 'tcp') {
|
||||||
|
params.set("flow", this.settings.trojans[clientIndex].flow);
|
||||||
|
}
|
||||||
|
if (this.stream.reality.shortIds != "") {
|
||||||
|
params.set("sid", this.stream.reality.shortIds);
|
||||||
|
}
|
||||||
|
if (this.stream.reality.fingerprint != "") {
|
||||||
|
params.set("fp", this.stream.reality.fingerprint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.XTLS) {
|
if (this.XTLS) {
|
||||||
params.set("security", "xtls");
|
params.set("security", "xtls");
|
||||||
params.set("alpn", this.stream.tls.alpn);
|
params.set("alpn", this.stream.tls.alpn);
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
tls: <a-tag color="green">{{ i18n "enabled" }}</a-tag><br />
|
tls: <a-tag color="green">{{ i18n "enabled" }}</a-tag><br />
|
||||||
tls {{ i18n "domainName" }}: <a-tag :color="inbound.serverName ? 'green' : 'orange'">[[ inbound.serverName ? inbound.serverName : '' ]]</a-tag>
|
tls {{ i18n "domainName" }}: <a-tag :color="inbound.serverName ? 'green' : 'orange'">[[ inbound.serverName ? inbound.serverName : '' ]]</a-tag>
|
||||||
</td>
|
</td>
|
||||||
<td v-else-if="inbound.xtls">
|
<td v-else-if="inbound.XTLS">
|
||||||
xtls: <a-tag color="green">{{ i18n "enabled" }}</a-tag><br />
|
xtls: <a-tag color="green">{{ i18n "enabled" }}</a-tag><br />
|
||||||
xtls {{ i18n "domainName" }}: <a-tag :color="inbound.serverName ? 'green' : 'orange'">[[ inbound.serverName ? inbound.serverName : '' ]]</a-tag>
|
xtls {{ i18n "domainName" }}: <a-tag :color="inbound.serverName ? 'green' : 'orange'">[[ inbound.serverName ? inbound.serverName : '' ]]</a-tag>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -453,12 +453,10 @@ func (s *InboundService) adjustTraffics(traffics []*xray.ClientTraffic) (full_tr
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// get settings clients
|
// get clients
|
||||||
settings := map[string]interface{}{}
|
clients, err := s.getClients(inbound)
|
||||||
json.Unmarshal([]byte(inbound.Settings), &settings)
|
|
||||||
clients, ok := settings["clients"].([]model.Client)
|
|
||||||
needUpdate := false
|
needUpdate := false
|
||||||
if ok {
|
if err == nil {
|
||||||
for client_index, client := range clients {
|
for client_index, client := range clients {
|
||||||
if traffic.Email == client.Email {
|
if traffic.Email == client.Email {
|
||||||
if client.ExpiryTime < 0 {
|
if client.ExpiryTime < 0 {
|
||||||
|
@ -473,7 +471,16 @@ func (s *InboundService) adjustTraffics(traffics []*xray.ClientTraffic) (full_tr
|
||||||
}
|
}
|
||||||
|
|
||||||
if needUpdate {
|
if needUpdate {
|
||||||
settings["clients"] = clients
|
settings := map[string]interface{}{}
|
||||||
|
json.Unmarshal([]byte(inbound.Settings), &settings)
|
||||||
|
|
||||||
|
// Convert clients to []interface to update clients in settings
|
||||||
|
var clientsInterface []interface{}
|
||||||
|
for _, c := range clients {
|
||||||
|
clientsInterface = append(clientsInterface, interface{}(c))
|
||||||
|
}
|
||||||
|
|
||||||
|
settings["clients"] = clientsInterface
|
||||||
modifiedSettings, err := json.MarshalIndent(settings, "", " ")
|
modifiedSettings, err := json.MarshalIndent(settings, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -300,7 +300,7 @@ func (s *SubService) genVlessLink(inbound *model.Inbound, email string) string {
|
||||||
|
|
||||||
if security == "xtls" {
|
if security == "xtls" {
|
||||||
params["security"] = "xtls"
|
params["security"] = "xtls"
|
||||||
xtlsSetting, _ := stream["xtlsSettings"].(map[string]interface{})
|
xtlsSetting, _ := stream["XTLSSettings"].(map[string]interface{})
|
||||||
alpns, _ := xtlsSetting["alpn"].([]interface{})
|
alpns, _ := xtlsSetting["alpn"].([]interface{})
|
||||||
var alpn []string
|
var alpn []string
|
||||||
for _, a := range alpns {
|
for _, a := range alpns {
|
||||||
|
@ -310,15 +310,15 @@ func (s *SubService) genVlessLink(inbound *model.Inbound, email string) string {
|
||||||
params["alpn"] = strings.Join(alpn, ",")
|
params["alpn"] = strings.Join(alpn, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
xtlsSettings, _ := searchKey(xtlsSetting, "settings")
|
XTLSSettings, _ := searchKey(xtlsSetting, "settings")
|
||||||
if xtlsSetting != nil {
|
if xtlsSetting != nil {
|
||||||
if sniValue, ok := searchKey(xtlsSettings, "serverName"); ok {
|
if sniValue, ok := searchKey(XTLSSettings, "serverName"); ok {
|
||||||
params["sni"], _ = sniValue.(string)
|
params["sni"], _ = sniValue.(string)
|
||||||
}
|
}
|
||||||
if fpValue, ok := searchKey(xtlsSettings, "fingerprint"); ok {
|
if fpValue, ok := searchKey(XTLSSettings, "fingerprint"); ok {
|
||||||
params["fp"], _ = fpValue.(string)
|
params["fp"], _ = fpValue.(string)
|
||||||
}
|
}
|
||||||
if insecure, ok := searchKey(xtlsSettings, "allowInsecure"); ok {
|
if insecure, ok := searchKey(XTLSSettings, "allowInsecure"); ok {
|
||||||
if insecure.(bool) {
|
if insecure.(bool) {
|
||||||
params["allowInsecure"] = "1"
|
params["allowInsecure"] = "1"
|
||||||
}
|
}
|
||||||
|
@ -442,9 +442,33 @@ func (s *SubService) genTrojanLink(inbound *model.Inbound, email string) string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if security == "reality" {
|
||||||
|
params["security"] = "reality"
|
||||||
|
realitySetting, _ := stream["realitySettings"].(map[string]interface{})
|
||||||
|
realitySettings, _ := searchKey(realitySetting, "settings")
|
||||||
|
if realitySetting != nil {
|
||||||
|
if sniValue, ok := searchKey(realitySettings, "serverName"); ok {
|
||||||
|
params["sni"], _ = sniValue.(string)
|
||||||
|
}
|
||||||
|
if pbkValue, ok := searchKey(realitySettings, "publicKey"); ok {
|
||||||
|
params["pbk"], _ = pbkValue.(string)
|
||||||
|
}
|
||||||
|
if sidValue, ok := searchKey(realitySettings, "shortIds"); ok {
|
||||||
|
params["sid"], _ = sidValue.(string)
|
||||||
|
}
|
||||||
|
if fpValue, ok := searchKey(realitySettings, "fingerprint"); ok {
|
||||||
|
params["fp"], _ = fpValue.(string)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
serverName, _ := realitySetting["serverName"].(string)
|
||||||
|
if serverName != "" {
|
||||||
|
address = serverName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if security == "xtls" {
|
if security == "xtls" {
|
||||||
params["security"] = "xtls"
|
params["security"] = "xtls"
|
||||||
xtlsSetting, _ := stream["xtlsSettings"].(map[string]interface{})
|
xtlsSetting, _ := stream["XTLSSettings"].(map[string]interface{})
|
||||||
alpns, _ := xtlsSetting["alpn"].([]interface{})
|
alpns, _ := xtlsSetting["alpn"].([]interface{})
|
||||||
var alpn []string
|
var alpn []string
|
||||||
for _, a := range alpns {
|
for _, a := range alpns {
|
||||||
|
@ -454,15 +478,15 @@ func (s *SubService) genTrojanLink(inbound *model.Inbound, email string) string
|
||||||
params["alpn"] = strings.Join(alpn, ",")
|
params["alpn"] = strings.Join(alpn, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
xtlsSettings, _ := searchKey(xtlsSetting, "settings")
|
XTLSSettings, _ := searchKey(xtlsSetting, "settings")
|
||||||
if xtlsSetting != nil {
|
if xtlsSetting != nil {
|
||||||
if sniValue, ok := searchKey(xtlsSettings, "serverName"); ok {
|
if sniValue, ok := searchKey(XTLSSettings, "serverName"); ok {
|
||||||
params["sni"], _ = sniValue.(string)
|
params["sni"], _ = sniValue.(string)
|
||||||
}
|
}
|
||||||
if fpValue, ok := searchKey(xtlsSettings, "fingerprint"); ok {
|
if fpValue, ok := searchKey(XTLSSettings, "fingerprint"); ok {
|
||||||
params["fp"], _ = fpValue.(string)
|
params["fp"], _ = fpValue.(string)
|
||||||
}
|
}
|
||||||
if insecure, ok := searchKey(xtlsSettings, "allowInsecure"); ok {
|
if insecure, ok := searchKey(XTLSSettings, "allowInsecure"); ok {
|
||||||
if insecure.(bool) {
|
if insecure.(bool) {
|
||||||
params["allowInsecure"] = "1"
|
params["allowInsecure"] = "1"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue