[reality] random shortId #361

This commit is contained in:
Alireza Ahmadi
2023-06-04 17:48:33 +02:00
parent 81a21b8ae0
commit 6f15de752c
5 changed files with 22 additions and 9 deletions

View File

@@ -592,7 +592,7 @@ class RealityStreamSettings extends XrayCommonClass {
dest = 'microsoft.com:443',
serverNames = 'microsoft.com,www.microsoft.com',
privateKey = '', minClient = '', maxClient = '',
maxTimediff = 0, shortIds = [],
maxTimediff = 0, shortIds = RandomUtil.randomShortId(),
settings= new RealityStreamSettings.Settings()) {
super();
this.show = show;

View File

@@ -119,7 +119,7 @@ Date.prototype.formatTime = function () {
};
/**
* 格式化日期加时间
* Formatting date plus time
*
* @param split Division between date and time, the default is a space
*/

View File

@@ -149,6 +149,17 @@ class RandomUtil {
window.crypto.getRandomValues(array);
return btoa(String.fromCharCode.apply(null, array));
}
static randomShortId() {
let shortIds = ['','','',''];
for (var ii = 0; ii < 4; ii++) {
for (var jj = 0; jj < this.randomInt(8); jj++){
let randomNum = this.randomInt(256);
shortIds[ii] += ('0' + randomNum.toString(16)).slice(-2)
}
}
return shortIds;
}
}
class ObjectUtil {

View File

@@ -225,7 +225,9 @@
</td>
</tr>
<tr>
<td>Short Ids</td>
<td>Short Ids
<a-icon @click="inbound.stream.reality.shortIds = RandomUtil.randomShortId().join(',')" type="sync">
</td>
<td>
<a-form-item>
<a-input v-model.trim="inbound.stream.reality.shortIds" style="width:250px"></a-input>

View File

@@ -379,14 +379,14 @@ func (s *InboundService) AddInboundClient(data *model.Inbound) (bool, error) {
for _, client := range clients {
if len(client.Email) > 0 {
s.AddClientStat(tx, data.Id, &client)
err = s.xrayApi.AddUser(string(oldInbound.Protocol), oldInbound.Tag, map[string]interface{}{
err1 := s.xrayApi.AddUser(string(oldInbound.Protocol), oldInbound.Tag, map[string]interface{}{
"email": client.Email,
"id": client.ID,
"alterId": client.AlterIds,
"flow": client.Flow,
"password": client.Password,
})
if err == nil {
if err1 == nil {
logger.Debug("Client added by api:", client.Email)
} else {
needRestart = true
@@ -558,14 +558,14 @@ func (s *InboundService) UpdateInboundClient(data *model.Inbound, clientId strin
if len(oldEmail) > 0 {
s.xrayApi.RemoveUser(oldInbound.Tag, oldEmail)
if clients[0].Enable {
err = s.xrayApi.AddUser(string(oldInbound.Protocol), oldInbound.Tag, map[string]interface{}{
err1 := s.xrayApi.AddUser(string(oldInbound.Protocol), oldInbound.Tag, map[string]interface{}{
"email": clients[0].Email,
"id": clients[0].ID,
"alterId": clients[0].AlterIds,
"flow": clients[0].Flow,
"password": clients[0].Password,
})
if err == nil {
if err1 == nil {
logger.Debug("Client edited by api:", clients[0].Email)
needRestart = false
}
@@ -821,14 +821,14 @@ func (s *InboundService) ResetClientTraffic(id int, clientEmail string) (bool, e
for _, client := range clients {
if client.Email == clientEmail {
s.xrayApi.Init(p.GetAPIPort())
err = s.xrayApi.AddUser(string(inbound.Protocol), inbound.Tag, map[string]interface{}{
err1 := s.xrayApi.AddUser(string(inbound.Protocol), inbound.Tag, map[string]interface{}{
"email": client.Email,
"id": client.ID,
"alterId": client.AlterIds,
"flow": client.Flow,
"password": client.Password,
})
if err == nil {
if err1 == nil {
logger.Debug("Client enabled due to reset traffic:", clientEmail)
} else {
needRestart = true