Skip to content

Commit

Permalink
random sub Id
Browse files Browse the repository at this point in the history
optimize utils
trojan short id fix
index page better view
  • Loading branch information
MHSanaei committed Jun 7, 2023
1 parent 70f250d commit 594d682
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 46 deletions.
2 changes: 1 addition & 1 deletion sub/subService.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ func (s *SubService) genTrojanLink(inbound *model.Inbound, email string) string
if pbkValue, ok := searchKey(realitySettings, "publicKey"); ok {
params["pbk"], _ = pbkValue.(string)
}
if sidValue, ok := searchKey(realitySettings, "shortIds"); ok {
if sidValue, ok := searchKey(realitySetting, "shortIds"); ok {
shortIds, _ := sidValue.([]interface{})
params["sid"], _ = shortIds[0].(string)
}
Expand Down
10 changes: 5 additions & 5 deletions web/assets/js/model/xray.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ class RealityStreamSettings extends XrayCommonClass {
minClient = '',
maxClient = '',
maxTimediff = 0,
shortIds = RandomUtil.randomShortId(),
shortIds = RandomUtil.randomShortId(8),
settings= new RealityStreamSettings.Settings()
){
super();
Expand Down Expand Up @@ -1655,7 +1655,7 @@ Inbound.VmessSettings = class extends Inbound.Settings {
}
};
Inbound.VmessSettings.Vmess = class extends XrayCommonClass {
constructor(id=RandomUtil.randomUUID(), alterId=0, email=RandomUtil.randomText(),limitIp=0, totalGB=0, expiryTime=0, enable=true, tgId='', subId='') {
constructor(id=RandomUtil.randomUUID(), alterId=0, email=RandomUtil.randomText(8),limitIp=0, totalGB=0, expiryTime=0, enable=true, tgId='', subId=RandomUtil.randomText(16)) {
super();
this.id = id;
this.alterId = alterId;
Expand Down Expand Up @@ -1747,7 +1747,7 @@ Inbound.VLESSSettings = class extends Inbound.Settings {

};
Inbound.VLESSSettings.VLESS = class extends XrayCommonClass {
constructor(id=RandomUtil.randomUUID(), flow='', email=RandomUtil.randomText(),limitIp=0, totalGB=0, expiryTime=0, enable=true, tgId='', subId='') {
constructor(id=RandomUtil.randomUUID(), flow='', email=RandomUtil.randomText(8),limitIp=0, totalGB=0, expiryTime=0, enable=true, tgId='', subId=RandomUtil.randomText(16)) {
super();
this.id = id;
this.flow = flow;
Expand Down Expand Up @@ -1870,7 +1870,7 @@ Inbound.TrojanSettings = class extends Inbound.Settings {
}
};
Inbound.TrojanSettings.Trojan = class extends XrayCommonClass {
constructor(password=RandomUtil.randomSeq(10), flow='', email=RandomUtil.randomText(),limitIp=0, totalGB=0, expiryTime=0, enable=true, tgId='', subId='') {
constructor(password=RandomUtil.randomSeq(10), flow='', email=RandomUtil.randomText(8),limitIp=0, totalGB=0, expiryTime=0, enable=true, tgId='', subId=RandomUtil.randomText(16)) {
super();
this.password = password;
this.flow = flow;
Expand Down Expand Up @@ -2012,7 +2012,7 @@ Inbound.ShadowsocksSettings = class extends Inbound.Settings {
};

Inbound.ShadowsocksSettings.Shadowsocks = class extends XrayCommonClass {
constructor(password=RandomUtil.randomShadowsocksPassword(), email=RandomUtil.randomText(),limitIp=0, totalGB=0, expiryTime=0, enable=true, tgId='', subId='') {
constructor(password=RandomUtil.randomShadowsocksPassword(), email=RandomUtil.randomText(8),limitIp=0, totalGB=0, expiryTime=0, enable=true, tgId='', subId=RandomUtil.randomText(16)) {
super();
this.password = password;
this.email = email;
Expand Down
27 changes: 6 additions & 21 deletions web/assets/js/util/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ class PromiseUtil {
}
}

const seq = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');

const shortIdSeq = 'abcdef0123456789'.split('');
const seq = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');

class RandomUtil {
static randomIntRange(min, max) {
Expand All @@ -96,21 +94,17 @@ class RandomUtil {
return str;
}

static randomShortIdSeq(count) {
static randomShortId(count) {
let str = '';
for (let i = 0; i < count; ++i) {
str += shortIdSeq[this.randomInt(16)];
str += seq[this.randomInt(16)];
}
return str;
}

static randomShortId() {
return this.randomShortIdSeq(8);
}

static randomLowerAndNum(count) {
static randomText(len) {
let str = '';
for (let i = 0; i < count; ++i) {
for (let i = 0; i < len; i++) {
str += seq[this.randomInt(36)];
}
return str;
Expand All @@ -136,16 +130,7 @@ class RandomUtil {
d = Math.floor(d / 16);
return (c === 'x' ? r : (r & 0x7 | 0x8)).toString(16);
});
}

static randomText() {
var chars = 'abcdefghijklmnopqrstuvwxyz1234567890';
var string = '';
for (var ii = 0; ii < 8; ii++) {
string += chars[Math.floor(Math.random() * chars.length)];
}
return string;
}
}

static randomShadowsocksPassword() {
let array = new Uint8Array(32);
Expand Down
4 changes: 2 additions & 2 deletions web/html/xui/form/client.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</template>
</a-tooltip>
</span>
<a-icon @click="client.email = RandomUtil.randomText()" type="sync"> </a-icon>
<a-icon @click="client.email = RandomUtil.randomText(8)" type="sync"> </a-icon>
<a-input v-model.trim="client.email" style="width: 200px;"></a-input>
</a-form-item>
<a-form-item label="Password" v-if="inbound.protocol === Protocols.TROJAN || inbound.protocol === Protocols.SHADOWSOCKS">
Expand All @@ -44,7 +44,7 @@
<a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip>
</span>
<a-icon @click="client.subId = RandomUtil.randomText()" type="sync"> </a-icon>
<a-icon @click="client.subId = RandomUtil.randomText(16)" type="sync"> </a-icon>
<a-input v-model.trim="client.subId" style="width: 150px;"></a-input>
</a-form-item>
<a-form-item v-if="client.email && app.tgBotEnable" >
Expand Down
4 changes: 2 additions & 2 deletions web/html/xui/form/protocol/shadowsocks.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</template>
</a-tooltip>
</span>
<a-icon @click="client.email = RandomUtil.randomText()" type="sync"> </a-icon>
<a-icon @click="client.email = RandomUtil.randomText(8)" type="sync"> </a-icon>
<a-input v-model.trim="client.email" style="width: 200px;"></a-input>
</a-form-item>
<a-form-item label="Password">
Expand All @@ -28,7 +28,7 @@
<a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip>
</span>
<a-icon @click="client.subId = RandomUtil.randomText()" type="sync"> </a-icon>
<a-icon @click="client.subId = RandomUtil.randomText(16)" type="sync"> </a-icon>
<a-input v-model.trim="client.subId" style="width: 150px;"></a-input>
</a-form-item>
<a-form-item v-if="client.email && app.tgBotEnable">
Expand Down
4 changes: 2 additions & 2 deletions web/html/xui/form/protocol/trojan.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</template>
</a-tooltip>
</span>
<a-icon @click="client.email = RandomUtil.randomText()" type="sync"> </a-icon>
<a-icon @click="client.email = RandomUtil.randomText(8)" type="sync"> </a-icon>
<a-input v-model.trim="client.email" style="width: 200px;"></a-input>
</a-form-item>
<a-form-item label="Password">
Expand All @@ -28,7 +28,7 @@
<a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip>
</span>
<a-icon @click="client.subId = RandomUtil.randomText()" type="sync"> </a-icon>
<a-icon @click="client.subId = RandomUtil.randomText(16)" type="sync"> </a-icon>
<a-input v-model.trim="client.subId" style="width: 150px;"></a-input>
</a-form-item>
<a-form-item v-if="client.email && app.tgBotEnable">
Expand Down
4 changes: 2 additions & 2 deletions web/html/xui/form/protocol/vless.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</template>
</a-tooltip>
</span>
<a-icon @click="client.email = RandomUtil.randomText()" type="sync"> </a-icon>
<a-icon @click="client.email = RandomUtil.randomText(8)" type="sync"> </a-icon>
<a-input v-model.trim="client.email" style="width: 200px;"></a-input>
</a-form-item>
<a-form-item label="ID">
Expand All @@ -28,7 +28,7 @@
<a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip>
</span>
<a-icon @click="client.subId = RandomUtil.randomText()" type="sync"> </a-icon>
<a-icon @click="client.subId = RandomUtil.randomText(16)" type="sync"> </a-icon>
<a-input v-model.trim="client.subId" style="width: 150px;"></a-input>
</a-form-item>
<a-form-item v-if="client.email && app.tgBotEnable">
Expand Down
4 changes: 2 additions & 2 deletions web/html/xui/form/protocol/vmess.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</template>
</a-tooltip>
</span>
<a-icon @click="client.email = RandomUtil.randomText()" type="sync"> </a-icon>
<a-icon @click="client.email = RandomUtil.randomText(8)" type="sync"> </a-icon>
<a-input v-model.trim="client.email" style="width: 200px;"></a-input>
</a-form-item>
<br>
Expand All @@ -33,7 +33,7 @@
<a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip>
</span>
<a-icon @click="client.subId = RandomUtil.randomText()" type="sync"> </a-icon>
<a-icon @click="client.subId = RandomUtil.randomText(16)" type="sync"> </a-icon>
<a-input v-model.trim="client.subId" style="width: 150px;"></a-input>
</a-form-item>
<a-form-item v-if="client.email && app.tgBotEnable">
Expand Down
2 changes: 1 addition & 1 deletion web/html/xui/form/tls_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
<a-input v-model.trim="inbound.stream.reality.serverNames" style="width: 300px"></a-input>
</a-form-item>
<a-form-item label="ShortIds">
<a-icon @click="inbound.stream.reality.shortIds = RandomUtil.randomShortId()" type="sync"> </a-icon>
<a-icon @click="inbound.stream.reality.shortIds = RandomUtil.randomShortId(8)" type="sync"> </a-icon>
<a-input v-model.trim="inbound.stream.reality.shortIds" style="width: 150px;"></a-input>
</a-form-item>
<br>
Expand Down
4 changes: 2 additions & 2 deletions web/html/xui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@
<a-row>
<a-col :sm="24" :md="12">
<a-card hoverable :class="themeSwitcher.darkCardClass">
3x-ui: <a href="https://github.com/MHSanaei/3x-ui/releases" target="_blank"><a-tag color="green">v{{ .cur_ver }}</a-tag></a>
3X: <a href="https://github.com/MHSanaei/3x-ui/releases" target="_blank"><a-tag color="green">v{{ .cur_ver }}</a-tag></a>
Xray: <a-tag color="green" style="cursor: pointer;" @click="openSelectV2rayVersion">v[[ status.xray.version ]]</a-tag>
Telegram: <a href="https://t.me/panel3xui" target="_blank"><a-tag color="green">@panel3xui</a-tag></a>
<a href="https://t.me/panel3xui" target="_blank"><a-tag color="green">@panel3xui</a-tag></a>
</a-card>
</a-col>
<a-col :sm="24" :md="12">
Expand Down
4 changes: 2 additions & 2 deletions web/service/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ func (s *InboundService) UpdateInboundClient(data *model.Inbound, clientId strin
if err != nil {
return false, err
}
err = s.UpdateClientIPs(db, oldEmail, clients[0].Email)
err = s.UpdateClientIPs(tx, oldEmail, clients[0].Email)
if err != nil {
return false, err
}
Expand All @@ -576,7 +576,7 @@ func (s *InboundService) UpdateInboundClient(data *model.Inbound, clientId strin
if err != nil {
return false, err
}
err = s.DelClientIPs(db, oldEmail)
err = s.DelClientIPs(tx, oldEmail)
if err != nil {
return false, err
}
Expand Down
2 changes: 1 addition & 1 deletion web/translation/translate.en_US.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"title" = "System Status"
"memory" = "Memory"
"hard" = "Hard Disk"
"xrayStatus" = "Xray Status"
"xrayStatus" = "Status"
"stopXray" = "Stop"
"restartXray" = "Restart"
"xraySwitch" = "SwitchV"
Expand Down
2 changes: 1 addition & 1 deletion web/translation/translate.fa_IR.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"title" = "وضعیت سیستم"
"memory" = "حافظه رم"
"hard" = "حافظه دیسک"
"xrayStatus" = "وضعیت Xray"
"xrayStatus" = "وضعیت"
"stopXray" = "توقف"
"restartXray" = "شروع مجدد"
"xraySwitch" = "تغییر ورژن"
Expand Down
2 changes: 1 addition & 1 deletion web/translation/translate.ru_RU.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"title" = "Статус системы"
"memory" = "Память"
"hard" = "Жесткий диск"
"xrayStatus" = "Статус Xray"
"xrayStatus" = "Статус"
"stopXray" = "Остановить Xray"
"restartXray" = "Рестарт Xray"
"xraySwitch" = "Переключить версию"
Expand Down
2 changes: 1 addition & 1 deletion web/translation/translate.zh_Hans.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"title" = "系统状态"
"memory" = "内存"
"hard" = "硬盘"
"xrayStatus" = "xray 状态"
"xrayStatus" = "状态"
"stopXray" = "停止"
"restartXray" = "重启"
"xraySwitch" = "切换版本"
Expand Down

0 comments on commit 594d682

Please sign in to comment.