random password button for SS & more

crypto.getRandomValues for uuid
change name randomText to randomLowerAndNum
This commit is contained in:
MHSanaei 2023-06-09 16:04:57 +03:30
parent 81aa3ed10e
commit 7fc3d37851
8 changed files with 29 additions and 26 deletions

View file

@ -707,7 +707,7 @@ class RealityStreamSettings extends XrayCommonClass {
minClient = '', minClient = '',
maxClient = '', maxClient = '',
maxTimediff = 0, maxTimediff = 0,
shortIds = RandomUtil.randomShortId(8), shortIds = RandomUtil.randomShortId(),
settings= new RealityStreamSettings.Settings() settings= new RealityStreamSettings.Settings()
){ ){
super(); super();
@ -1652,7 +1652,7 @@ Inbound.VmessSettings = class extends Inbound.Settings {
} }
}; };
Inbound.VmessSettings.Vmess = class extends XrayCommonClass { 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(); super();
this.id = id; this.id = id;
this.alterId = alterId; this.alterId = alterId;
@ -1744,7 +1744,7 @@ Inbound.VLESSSettings = class extends Inbound.Settings {
}; };
Inbound.VLESSSettings.VLESS = class extends XrayCommonClass { 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(); super();
this.id = id; this.id = id;
this.flow = flow; this.flow = flow;
@ -1867,7 +1867,7 @@ Inbound.TrojanSettings = class extends Inbound.Settings {
} }
}; };
Inbound.TrojanSettings.Trojan = class extends XrayCommonClass { 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(); super();
this.password = password; this.password = password;
this.flow = flow; this.flow = flow;
@ -2009,7 +2009,7 @@ Inbound.ShadowsocksSettings = class extends Inbound.Settings {
}; };
Inbound.ShadowsocksSettings.Shadowsocks = class extends XrayCommonClass { 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(); super();
this.password = password; this.password = password;
this.email = email; this.email = email;

View file

@ -94,28 +94,30 @@ class RandomUtil {
return str; return str;
} }
static randomShortId(count) { static randomShortId() {
let str = ''; let str = '';
for (let i = 0; i < count; ++i) { for (let i = 0; i < 8; ++i) {
str += seq[this.randomInt(16)]; str += seq[this.randomInt(16)];
} }
return str; return str;
} }
static randomText(len) { static randomLowerAndNum(len) {
let str = ''; let str = '';
for (let i = 0; i < len; i++) { for (let i = 0; i < len; ++i) {
str += seq[this.randomInt(36)]; str += seq[this.randomInt(36)];
} }
return str; return str;
} }
static randomUUID() { static randomUUID() {
let d = new Date().getTime(); const template = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { return template.replace(/[xy]/g, function (c) {
let r = (d + Math.random() * 16) % 16 | 0; const randomValues = new Uint8Array(1);
d = Math.floor(d / 16); crypto.getRandomValues(randomValues);
return (c === 'x' ? r : (r & 0x7 | 0x8)).toString(16); let randomValue = randomValues[0] % 16;
let calculatedValue = (c === 'x') ? randomValue : (randomValue & 0x3 | 0x8);
return calculatedValue.toString(16);
}); });
} }

View file

@ -18,7 +18,7 @@
</template> </template>
</a-tooltip> </a-tooltip>
</span> </span>
<a-icon @click="client.email = RandomUtil.randomText(8)" type="sync"> </a-icon> <a-icon @click="client.email = RandomUtil.randomLowerAndNum(8)" type="sync"> </a-icon>
<a-input v-model.trim="client.email" style="width: 200px;"></a-input> <a-input v-model.trim="client.email" style="width: 200px;"></a-input>
</a-form-item> </a-form-item>
<a-form-item label="Password" v-if="inbound.protocol === Protocols.TROJAN || inbound.protocol === Protocols.SHADOWSOCKS"> <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-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip> </a-tooltip>
</span> </span>
<a-icon @click="client.subId = RandomUtil.randomText(16)" type="sync"> </a-icon> <a-icon @click="client.subId = RandomUtil.randomLowerAndNum(16)" type="sync"> </a-icon>
<a-input v-model.trim="client.subId" style="width: 150px;"></a-input> <a-input v-model.trim="client.subId" style="width: 150px;"></a-input>
</a-form-item> </a-form-item>
<a-form-item v-if="client.email && app.tgBotEnable" > <a-form-item v-if="client.email && app.tgBotEnable" >

View file

@ -11,7 +11,7 @@
</template> </template>
</a-tooltip> </a-tooltip>
</span> </span>
<a-icon @click="client.email = RandomUtil.randomText(8)" type="sync"> </a-icon> <a-icon @click="client.email = RandomUtil.randomLowerAndNum(8)" type="sync"> </a-icon>
<a-input v-model.trim="client.email" style="width: 200px;"></a-input> <a-input v-model.trim="client.email" style="width: 200px;"></a-input>
</a-form-item> </a-form-item>
<a-form-item label="Password"> <a-form-item label="Password">
@ -28,7 +28,7 @@
<a-icon type="question-circle" theme="filled"></a-icon> <a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip> </a-tooltip>
</span> </span>
<a-icon @click="client.subId = RandomUtil.randomText(16)" type="sync"> </a-icon> <a-icon @click="client.subId = RandomUtil.randomLowerAndNum(16)" type="sync"> </a-icon>
<a-input v-model.trim="client.subId" style="width: 150px;"></a-input> <a-input v-model.trim="client.subId" style="width: 150px;"></a-input>
</a-form-item> </a-form-item>
<a-form-item v-if="client.email && app.tgBotEnable"> <a-form-item v-if="client.email && app.tgBotEnable">
@ -112,6 +112,7 @@
</a-select> </a-select>
</a-form-item> </a-form-item>
<a-form-item label='{{ i18n "password" }}'> <a-form-item label='{{ i18n "password" }}'>
<a-icon @click="inbound.settings.password = RandomUtil.randomShadowsocksPassword()" type="sync"> </a-icon>
<a-input v-model.trim="inbound.settings.password" style="width: 250px;"></a-input> <a-input v-model.trim="inbound.settings.password" style="width: 250px;"></a-input>
</a-form-item> </a-form-item>
<a-form-item label='{{ i18n "pages.inbounds.network" }}'> <a-form-item label='{{ i18n "pages.inbounds.network" }}'>

View file

@ -11,7 +11,7 @@
</template> </template>
</a-tooltip> </a-tooltip>
</span> </span>
<a-icon @click="client.email = RandomUtil.randomText(8)" type="sync"> </a-icon> <a-icon @click="client.email = RandomUtil.randomLowerAndNum(8)" type="sync"> </a-icon>
<a-input v-model.trim="client.email" style="width: 200px;"></a-input> <a-input v-model.trim="client.email" style="width: 200px;"></a-input>
</a-form-item> </a-form-item>
<a-form-item label="Password"> <a-form-item label="Password">
@ -28,7 +28,7 @@
<a-icon type="question-circle" theme="filled"></a-icon> <a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip> </a-tooltip>
</span> </span>
<a-icon @click="client.subId = RandomUtil.randomText(16)" type="sync"> </a-icon> <a-icon @click="client.subId = RandomUtil.randomLowerAndNum(16)" type="sync"> </a-icon>
<a-input v-model.trim="client.subId" style="width: 150px;"></a-input> <a-input v-model.trim="client.subId" style="width: 150px;"></a-input>
</a-form-item> </a-form-item>
<a-form-item v-if="client.email && app.tgBotEnable"> <a-form-item v-if="client.email && app.tgBotEnable">

View file

@ -11,7 +11,7 @@
</template> </template>
</a-tooltip> </a-tooltip>
</span> </span>
<a-icon @click="client.email = RandomUtil.randomText(8)" type="sync"> </a-icon> <a-icon @click="client.email = RandomUtil.randomLowerAndNum(8)" type="sync"> </a-icon>
<a-input v-model.trim="client.email" style="width: 200px;"></a-input> <a-input v-model.trim="client.email" style="width: 200px;"></a-input>
</a-form-item> </a-form-item>
<a-form-item label="ID"> <a-form-item label="ID">
@ -28,7 +28,7 @@
<a-icon type="question-circle" theme="filled"></a-icon> <a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip> </a-tooltip>
</span> </span>
<a-icon @click="client.subId = RandomUtil.randomText(16)" type="sync"> </a-icon> <a-icon @click="client.subId = RandomUtil.randomLowerAndNum(16)" type="sync"> </a-icon>
<a-input v-model.trim="client.subId" style="width: 150px;"></a-input> <a-input v-model.trim="client.subId" style="width: 150px;"></a-input>
</a-form-item> </a-form-item>
<a-form-item v-if="client.email && app.tgBotEnable"> <a-form-item v-if="client.email && app.tgBotEnable">

View file

@ -11,7 +11,7 @@
</template> </template>
</a-tooltip> </a-tooltip>
</span> </span>
<a-icon @click="client.email = RandomUtil.randomText(8)" type="sync"> </a-icon> <a-icon @click="client.email = RandomUtil.randomLowerAndNum(8)" type="sync"> </a-icon>
<a-input v-model.trim="client.email" style="width: 200px;"></a-input> <a-input v-model.trim="client.email" style="width: 200px;"></a-input>
</a-form-item> </a-form-item>
<br> <br>
@ -33,7 +33,7 @@
<a-icon type="question-circle" theme="filled"></a-icon> <a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip> </a-tooltip>
</span> </span>
<a-icon @click="client.subId = RandomUtil.randomText(16)" type="sync"> </a-icon> <a-icon @click="client.subId = RandomUtil.randomLowerAndNum(16)" type="sync"> </a-icon>
<a-input v-model.trim="client.subId" style="width: 150px;"></a-input> <a-input v-model.trim="client.subId" style="width: 150px;"></a-input>
</a-form-item> </a-form-item>
<a-form-item v-if="client.email && app.tgBotEnable"> <a-form-item v-if="client.email && app.tgBotEnable">

View file

@ -187,7 +187,7 @@
<a-input v-model.trim="inbound.stream.reality.serverNames" style="width: 300px"></a-input> <a-input v-model.trim="inbound.stream.reality.serverNames" style="width: 300px"></a-input>
</a-form-item> </a-form-item>
<a-form-item label="ShortIds"> <a-form-item label="ShortIds">
<a-icon @click="inbound.stream.reality.shortIds = RandomUtil.randomShortId(8)" type="sync"> </a-icon> <a-icon @click="inbound.stream.reality.shortIds = RandomUtil.randomShortId()" type="sync"> </a-icon>
<a-input v-model.trim="inbound.stream.reality.shortIds" style="width: 150px;"></a-input> <a-input v-model.trim="inbound.stream.reality.shortIds" style="width: 150px;"></a-input>
</a-form-item> </a-form-item>
<br> <br>