From 7fc3d3785160faddfd8745da063265ab50ee1753 Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Fri, 9 Jun 2023 16:04:57 +0330 Subject: [PATCH] random password button for SS & more crypto.getRandomValues for uuid change name randomText to randomLowerAndNum --- web/assets/js/model/xray.js | 10 +++++----- web/assets/js/util/utils.js | 22 +++++++++++---------- web/html/xui/form/client.html | 4 ++-- web/html/xui/form/protocol/shadowsocks.html | 5 +++-- web/html/xui/form/protocol/trojan.html | 4 ++-- web/html/xui/form/protocol/vless.html | 4 ++-- web/html/xui/form/protocol/vmess.html | 4 ++-- web/html/xui/form/tls_settings.html | 2 +- 8 files changed, 29 insertions(+), 26 deletions(-) diff --git a/web/assets/js/model/xray.js b/web/assets/js/model/xray.js index 748ce526..b627570f 100644 --- a/web/assets/js/model/xray.js +++ b/web/assets/js/model/xray.js @@ -707,7 +707,7 @@ class RealityStreamSettings extends XrayCommonClass { minClient = '', maxClient = '', maxTimediff = 0, - shortIds = RandomUtil.randomShortId(8), + shortIds = RandomUtil.randomShortId(), settings= new RealityStreamSettings.Settings() ){ super(); @@ -1652,7 +1652,7 @@ Inbound.VmessSettings = class extends Inbound.Settings { } }; Inbound.VmessSettings.Vmess = class extends XrayCommonClass { - constructor(id=RandomUtil.randomUUID(), alterId=0, email=RandomUtil.randomText(8),limitIp=0, totalGB=0, expiryTime=0, enable=true, tgId='', subId=RandomUtil.randomText(16)) { + constructor(id=RandomUtil.randomUUID(), alterId=0, email=RandomUtil.randomLowerAndNum(8),limitIp=0, totalGB=0, expiryTime=0, enable=true, tgId='', subId=RandomUtil.randomLowerAndNum(16)) { super(); this.id = id; this.alterId = alterId; @@ -1744,7 +1744,7 @@ Inbound.VLESSSettings = class extends Inbound.Settings { }; Inbound.VLESSSettings.VLESS = class extends XrayCommonClass { - constructor(id=RandomUtil.randomUUID(), flow='', email=RandomUtil.randomText(8),limitIp=0, totalGB=0, expiryTime=0, enable=true, tgId='', subId=RandomUtil.randomText(16)) { + constructor(id=RandomUtil.randomUUID(), flow='', email=RandomUtil.randomLowerAndNum(8),limitIp=0, totalGB=0, expiryTime=0, enable=true, tgId='', subId=RandomUtil.randomLowerAndNum(16)) { super(); this.id = id; this.flow = flow; @@ -1867,7 +1867,7 @@ Inbound.TrojanSettings = class extends Inbound.Settings { } }; Inbound.TrojanSettings.Trojan = class extends XrayCommonClass { - constructor(password=RandomUtil.randomSeq(10), flow='', email=RandomUtil.randomText(8),limitIp=0, totalGB=0, expiryTime=0, enable=true, tgId='', subId=RandomUtil.randomText(16)) { + constructor(password=RandomUtil.randomSeq(10), flow='', email=RandomUtil.randomLowerAndNum(8),limitIp=0, totalGB=0, expiryTime=0, enable=true, tgId='', subId=RandomUtil.randomLowerAndNum(16)) { super(); this.password = password; this.flow = flow; @@ -2009,7 +2009,7 @@ Inbound.ShadowsocksSettings = class extends Inbound.Settings { }; Inbound.ShadowsocksSettings.Shadowsocks = class extends XrayCommonClass { - constructor(password=RandomUtil.randomShadowsocksPassword(), email=RandomUtil.randomText(8),limitIp=0, totalGB=0, expiryTime=0, enable=true, tgId='', subId=RandomUtil.randomText(16)) { + constructor(password=RandomUtil.randomShadowsocksPassword(), email=RandomUtil.randomLowerAndNum(8),limitIp=0, totalGB=0, expiryTime=0, enable=true, tgId='', subId=RandomUtil.randomLowerAndNum(16)) { super(); this.password = password; this.email = email; diff --git a/web/assets/js/util/utils.js b/web/assets/js/util/utils.js index 612d4b5b..781e13a8 100644 --- a/web/assets/js/util/utils.js +++ b/web/assets/js/util/utils.js @@ -94,30 +94,32 @@ class RandomUtil { return str; } - static randomShortId(count) { + static randomShortId() { let str = ''; - for (let i = 0; i < count; ++i) { + for (let i = 0; i < 8; ++i) { str += seq[this.randomInt(16)]; } return str; } - static randomText(len) { + static randomLowerAndNum(len) { let str = ''; - for (let i = 0; i < len; i++) { + for (let i = 0; i < len; ++i) { str += seq[this.randomInt(36)]; } return str; } static randomUUID() { - let d = new Date().getTime(); - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { - let r = (d + Math.random() * 16) % 16 | 0; - d = Math.floor(d / 16); - return (c === 'x' ? r : (r & 0x7 | 0x8)).toString(16); + const template = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'; + return template.replace(/[xy]/g, function (c) { + const randomValues = new Uint8Array(1); + crypto.getRandomValues(randomValues); + let randomValue = randomValues[0] % 16; + let calculatedValue = (c === 'x') ? randomValue : (randomValue & 0x3 | 0x8); + return calculatedValue.toString(16); }); - } + } static randomShadowsocksPassword() { let array = new Uint8Array(32); diff --git a/web/html/xui/form/client.html b/web/html/xui/form/client.html index cfac5cff..bd6b08af 100644 --- a/web/html/xui/form/client.html +++ b/web/html/xui/form/client.html @@ -18,7 +18,7 @@ - + @@ -44,7 +44,7 @@ - + diff --git a/web/html/xui/form/protocol/shadowsocks.html b/web/html/xui/form/protocol/shadowsocks.html index e4eaf155..e9b01ea5 100644 --- a/web/html/xui/form/protocol/shadowsocks.html +++ b/web/html/xui/form/protocol/shadowsocks.html @@ -11,7 +11,7 @@ - + @@ -28,7 +28,7 @@ - + @@ -112,6 +112,7 @@ + diff --git a/web/html/xui/form/protocol/trojan.html b/web/html/xui/form/protocol/trojan.html index cf56f438..f494adb9 100644 --- a/web/html/xui/form/protocol/trojan.html +++ b/web/html/xui/form/protocol/trojan.html @@ -11,7 +11,7 @@ - + @@ -28,7 +28,7 @@ - + diff --git a/web/html/xui/form/protocol/vless.html b/web/html/xui/form/protocol/vless.html index 59ba7672..f661a839 100644 --- a/web/html/xui/form/protocol/vless.html +++ b/web/html/xui/form/protocol/vless.html @@ -11,7 +11,7 @@ - + @@ -28,7 +28,7 @@ - + diff --git a/web/html/xui/form/protocol/vmess.html b/web/html/xui/form/protocol/vmess.html index de6e5250..6dd31307 100644 --- a/web/html/xui/form/protocol/vmess.html +++ b/web/html/xui/form/protocol/vmess.html @@ -11,7 +11,7 @@ - +
@@ -33,7 +33,7 @@ - + diff --git a/web/html/xui/form/tls_settings.html b/web/html/xui/form/tls_settings.html index d0692e13..58edf992 100644 --- a/web/html/xui/form/tls_settings.html +++ b/web/html/xui/form/tls_settings.html @@ -187,7 +187,7 @@ - +