Co-Authored-By: Alireza Ahmadi <alireza7@gmail.com>
This commit is contained in:
MHSanaei 2023-04-19 11:55:38 +03:30
parent 4d479102ad
commit e1132a3f41
3 changed files with 36 additions and 25 deletions

View File

@ -853,6 +853,7 @@ class StreamSettings extends XrayCommonClass {
} }
static fromJson(json={}) { static fromJson(json={}) {
return new StreamSettings( return new StreamSettings(
json.network, json.network,
json.security, json.security,
@ -1412,13 +1413,13 @@ class Inbound extends XrayCommonClass {
if (!ObjectUtil.isArrEmpty(this.stream.reality.serverNames)) { if (!ObjectUtil.isArrEmpty(this.stream.reality.serverNames)) {
params.set("sni", this.stream.reality.serverNames.split(",")[0]); params.set("sni", this.stream.reality.serverNames.split(",")[0]);
} }
if (this.stream.network === 'tcp') { if (this.stream.network === 'tcp' && !ObjectUtil.isEmpty(this.settings.vlesses[clientIndex].flow)) {
params.set("flow", this.settings.vlesses[clientIndex].flow); params.set("flow", this.settings.vlesses[clientIndex].flow);
} }
if (this.stream.reality.shortIds != "") { if (this.stream.reality.shortIds.length > 0) {
params.set("sid", this.stream.reality.shortIds.split(",")[0]); params.set("sid", this.stream.reality.shortIds.split(",")[0]);
} }
if (this.stream.reality.settings.fingerprint != "") { if (!ObjectUtil.isEmpty(this.stream.reality.fingerprint)) {
params.set("fp", this.stream.reality.settings.fingerprint); params.set("fp", this.stream.reality.settings.fingerprint);
} }
if (!ObjectUtil.isEmpty(this.stream.reality.settings.serverName)) { if (!ObjectUtil.isEmpty(this.stream.reality.settings.serverName)) {
@ -1519,10 +1520,10 @@ class Inbound extends XrayCommonClass {
if (!ObjectUtil.isEmpty(this.stream.reality.settings.serverName)) { if (!ObjectUtil.isEmpty(this.stream.reality.settings.serverName)) {
address = this.stream.reality.settings.serverName; address = this.stream.reality.settings.serverName;
} }
if (this.stream.reality.shortIds != "") { if (this.stream.reality.shortIds.length > 0) {
params.set("sid", this.stream.reality.shortIds.split(",")[0]); params.set("sid", this.stream.reality.shortIds.split(",")[0]);
} }
if (this.stream.reality.settings.fingerprint != "") { if (!ObjectUtil.isEmpty(this.stream.reality.fingerprint)) {
params.set("fp", this.stream.reality.settings.fingerprint); params.set("fp", this.stream.reality.settings.fingerprint);
} }
if (!ObjectUtil.isEmpty(this.stream.reality.settings.serverName)) { if (!ObjectUtil.isEmpty(this.stream.reality.settings.serverName)) {

View File

@ -658,8 +658,8 @@
inbound = dbInbound.toInbound(); inbound = dbInbound.toInbound();
clients = this.getClients(dbInbound.protocol, inbound.settings); clients = this.getClients(dbInbound.protocol, inbound.settings);
index = this.findIndexOfClient(clients, client); index = this.findIndexOfClient(clients, client);
clients[index].enable = ! clients[index].enable clients[index].enable = !clients[index].enable;
await this.updateClient(inbound, dbInbound, index); await this.updateClient(clients[index],dbInboundId, index);
this.loading(false); this.loading(false);
}, },
async submit(url, data) { async submit(url, data) {

View File

@ -266,11 +266,18 @@ func (s *InboundService) AddInboundClient(data *model.Inbound) error {
if err != nil { if err != nil {
return err return err
} }
existEmail, err := s.checkEmailsExistForClients(clients)
var settings map[string]interface{}
err = json.Unmarshal([]byte(data.Settings), &settings)
if err != nil { if err != nil {
return err return err
} }
interfaceClients := settings["clients"].([]interface{})
existEmail, err := s.checkEmailsExistForClients(clients)
if err != nil {
return err
}
if existEmail != "" { if existEmail != "" {
return common.NewError("Duplicate email:", existEmail) return common.NewError("Duplicate email:", existEmail)
} }
@ -280,21 +287,18 @@ func (s *InboundService) AddInboundClient(data *model.Inbound) error {
return err return err
} }
var settings map[string]interface{} var oldSettings map[string]interface{}
err = json.Unmarshal([]byte(oldInbound.Settings), &settings) err = json.Unmarshal([]byte(oldInbound.Settings), &oldSettings)
if err != nil { if err != nil {
return err return err
} }
oldClients := settings["clients"].([]interface{}) oldClients := oldSettings["clients"].([]interface{})
var newClients []interface{} oldClients = append(oldClients, interfaceClients...)
for _, client := range clients {
newClients = append(newClients, client)
}
settings["clients"] = append(oldClients, newClients...) oldSettings["clients"] = oldClients
newSettings, err := json.MarshalIndent(settings, "", " ") newSettings, err := json.MarshalIndent(oldSettings, "", " ")
if err != nil { if err != nil {
return err return err
} }
@ -341,6 +345,14 @@ func (s *InboundService) UpdateInboundClient(data *model.Inbound, index int) err
return err return err
} }
var settings map[string]interface{}
err = json.Unmarshal([]byte(data.Settings), &settings)
if err != nil {
return err
}
inerfaceClients := settings["clients"].([]interface{})
oldInbound, err := s.GetInbound(data.Id) oldInbound, err := s.GetInbound(data.Id)
if err != nil { if err != nil {
return err return err
@ -361,20 +373,18 @@ func (s *InboundService) UpdateInboundClient(data *model.Inbound, index int) err
} }
} }
var settings map[string]interface{} var oldSettings map[string]interface{}
err = json.Unmarshal([]byte(oldInbound.Settings), &settings) err = json.Unmarshal([]byte(oldInbound.Settings), &oldSettings)
if err != nil { if err != nil {
return err return err
} }
settingsClients := settings["clients"].([]interface{}) settingsClients := oldSettings["clients"].([]interface{})
var newClients []interface{} settingsClients[index] = inerfaceClients[0]
newClients = append(newClients, clients[0])
settingsClients[index] = newClients[0]
settings["clients"] = settingsClients oldSettings["clients"] = settingsClients
newSettings, err := json.MarshalIndent(settings, "", " ") newSettings, err := json.MarshalIndent(oldSettings, "", " ")
if err != nil { if err != nil {
return err return err
} }