Browse Source

random sub Id

optimize utils
trojan short id fix
index page better view
MHSanaei 1 year ago
parent
commit
594d682e20

+ 1 - 1
sub/subService.go

@@ -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)
 			}

+ 5 - 5
web/assets/js/model/xray.js

@@ -708,7 +708,7 @@ class RealityStreamSettings extends XrayCommonClass {
         minClient = '',
         maxClient = '',
         maxTimediff = 0,
-        shortIds = RandomUtil.randomShortId(),
+        shortIds = RandomUtil.randomShortId(8),
         settings= new RealityStreamSettings.Settings()
         ){
         super();
@@ -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;
@@ -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;
@@ -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;
@@ -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;

+ 6 - 21
web/assets/js/util/utils.js

@@ -75,9 +75,7 @@ class PromiseUtil {
     }
 }
 
-const seq = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
-
-const shortIdSeq = 'abcdef0123456789'.split('');
+const seq = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
 
 class RandomUtil {
     static randomIntRange(min, max) {
@@ -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;
@@ -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);

+ 2 - 2
web/html/xui/form/client.html

@@ -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">
@@ -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" >

+ 2 - 2
web/html/xui/form/protocol/shadowsocks.html

@@ -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">
@@ -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">

+ 2 - 2
web/html/xui/form/protocol/trojan.html

@@ -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">
@@ -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">

+ 2 - 2
web/html/xui/form/protocol/vless.html

@@ -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">
@@ -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">

+ 2 - 2
web/html/xui/form/protocol/vmess.html

@@ -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>
@@ -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">

+ 1 - 1
web/html/xui/form/tls_settings.html

@@ -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>

+ 2 - 2
web/html/xui/index.html

@@ -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">

+ 2 - 2
web/service/inbound.go

@@ -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
 			}
@@ -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
 		}

+ 1 - 1
web/translation/translate.en_US.toml

@@ -72,7 +72,7 @@
 "title" = "System Status"
 "memory" = "Memory"
 "hard" = "Hard Disk"
-"xrayStatus" = "Xray Status"
+"xrayStatus" = "Status"
 "stopXray" = "Stop"
 "restartXray" = "Restart"
 "xraySwitch" = "SwitchV"

+ 1 - 1
web/translation/translate.fa_IR.toml

@@ -72,7 +72,7 @@
 "title" = "وضعیت سیستم"
 "memory" = "حافظه رم"
 "hard" = "حافظه دیسک"
-"xrayStatus" = "وضعیت Xray"
+"xrayStatus" = "وضعیت"
 "stopXray" = "توقف"
 "restartXray" = "شروع مجدد"
 "xraySwitch" = "تغییر ورژن"

+ 1 - 1
web/translation/translate.ru_RU.toml

@@ -72,7 +72,7 @@
 "title" = "Статус системы"
 "memory" = "Память"
 "hard" = "Жесткий диск"
-"xrayStatus" = "Статус Xray"
+"xrayStatus" = "Статус"
 "stopXray" = "Остановить Xray"
 "restartXray" = "Рестарт Xray"
 "xraySwitch" = "Переключить версию"

+ 1 - 1
web/translation/translate.zh_Hans.toml

@@ -72,7 +72,7 @@
 "title" = "系统状态"
 "memory" = "内存"
 "hard" = "硬盘"
-"xrayStatus" = "xray 状态"
+"xrayStatus" = "状态"
 "stopXray" = "停止"
 "restartXray" = "重启"
 "xraySwitch" = "切换版本"