Skip to content

Commit

Permalink
[feature] Auto renew
Browse files Browse the repository at this point in the history
  • Loading branch information
alireza0 committed Nov 8, 2023
1 parent 7a4055e commit 9640896
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 27 deletions.
1 change: 1 addition & 0 deletions database/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ type Client struct {
Enable bool `json:"enable" form:"enable"`
TgID string `json:"tgId" form:"tgId"`
SubID string `json:"subId" form:"subId"`
Reset int `json:"reset" form:"reset"`
}
18 changes: 14 additions & 4 deletions web/assets/js/model/xray.js
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,7 @@ Inbound.VmessSettings = class extends Inbound.Settings {
}
};
Inbound.VmessSettings.Vmess = class extends XrayCommonClass {
constructor(id=RandomUtil.randomUUID(), email=RandomUtil.randomLowerAndNum(9), totalGB=0, expiryTime=0, enable=true, tgId='', subId=RandomUtil.randomLowerAndNum(16)) {
constructor(id=RandomUtil.randomUUID(), email=RandomUtil.randomLowerAndNum(9), totalGB=0, expiryTime=0, enable=true, tgId='', subId=RandomUtil.randomLowerAndNum(16), reset=0) {
super();
this.id = id;
this.email = email;
Expand All @@ -1586,6 +1586,7 @@ Inbound.VmessSettings.Vmess = class extends XrayCommonClass {
this.enable = enable;
this.tgId = tgId;
this.subId = subId;
this.reset = reset;
}

static fromJson(json={}) {
Expand All @@ -1597,6 +1598,7 @@ Inbound.VmessSettings.Vmess = class extends XrayCommonClass {
json.enable,
json.tgId,
json.subId,
json.reset,
);
}
get _expiryTime() {
Expand Down Expand Up @@ -1665,7 +1667,7 @@ Inbound.VLESSSettings = class extends Inbound.Settings {

};
Inbound.VLESSSettings.VLESS = class extends XrayCommonClass {
constructor(id=RandomUtil.randomUUID(), flow='', email=RandomUtil.randomLowerAndNum(9), totalGB=0, expiryTime=0, enable=true, tgId='', subId=RandomUtil.randomLowerAndNum(16)) {
constructor(id=RandomUtil.randomUUID(), flow='', email=RandomUtil.randomLowerAndNum(9), totalGB=0, expiryTime=0, enable=true, tgId='', subId=RandomUtil.randomLowerAndNum(16), reset=0) {
super();
this.id = id;
this.flow = flow;
Expand All @@ -1675,6 +1677,7 @@ Inbound.VLESSSettings.VLESS = class extends XrayCommonClass {
this.enable = enable;
this.tgId = tgId;
this.subId = subId;
this.reset = reset;
}

static fromJson(json={}) {
Expand All @@ -1687,6 +1690,7 @@ Inbound.VLESSSettings.VLESS = class extends XrayCommonClass {
json.enable,
json.tgId,
json.subId,
json.reset,
);
}

Expand Down Expand Up @@ -1786,7 +1790,7 @@ Inbound.TrojanSettings = class extends Inbound.Settings {
}
};
Inbound.TrojanSettings.Trojan = class extends XrayCommonClass {
constructor(password=RandomUtil.randomSeq(10), email=RandomUtil.randomLowerAndNum(9), totalGB=0, expiryTime=0, enable=true, tgId='', subId=RandomUtil.randomLowerAndNum(16)) {
constructor(password=RandomUtil.randomSeq(10), email=RandomUtil.randomLowerAndNum(9), totalGB=0, expiryTime=0, enable=true, tgId='', subId=RandomUtil.randomLowerAndNum(16), reset=0) {
super();
this.password = password;
this.email = email;
Expand All @@ -1795,6 +1799,7 @@ Inbound.TrojanSettings.Trojan = class extends XrayCommonClass {
this.enable = enable;
this.tgId = tgId;
this.subId = subId;
this.reset = reset;
}

toJson() {
Expand All @@ -1806,6 +1811,7 @@ Inbound.TrojanSettings.Trojan = class extends XrayCommonClass {
enable: this.enable,
tgId: this.tgId,
subId: this.subId,
reset: this.reset,
};
}

Expand All @@ -1818,6 +1824,7 @@ Inbound.TrojanSettings.Trojan = class extends XrayCommonClass {
json.enable,
json.tgId,
json.subId,
json.reset,
);
}

Expand Down Expand Up @@ -1922,7 +1929,7 @@ Inbound.ShadowsocksSettings = class extends Inbound.Settings {
};

Inbound.ShadowsocksSettings.Shadowsocks = class extends XrayCommonClass {
constructor(method='', password=RandomUtil.randomShadowsocksPassword(), email=RandomUtil.randomLowerAndNum(9), totalGB=0, expiryTime=0, enable=true, tgId='', subId=RandomUtil.randomLowerAndNum(16)) {
constructor(method='', password=RandomUtil.randomShadowsocksPassword(), email=RandomUtil.randomLowerAndNum(9), totalGB=0, expiryTime=0, enable=true, tgId='', subId=RandomUtil.randomLowerAndNum(16), reset=0) {
super();
this.method = method;
this.password = password;
Expand All @@ -1932,6 +1939,7 @@ Inbound.ShadowsocksSettings.Shadowsocks = class extends XrayCommonClass {
this.enable = enable;
this.tgId = tgId;
this.subId = subId;
this.reset = reset;
}

toJson() {
Expand All @@ -1944,6 +1952,7 @@ Inbound.ShadowsocksSettings.Shadowsocks = class extends XrayCommonClass {
enable: this.enable,
tgId: this.tgId,
subId: this.subId,
reset: this.reset,
};
}

Expand All @@ -1957,6 +1966,7 @@ Inbound.ShadowsocksSettings.Shadowsocks = class extends XrayCommonClass {
json.enable,
json.tgId,
json.subId,
json.reset,
);
}

Expand Down
19 changes: 19 additions & 0 deletions web/html/xui/client_bulk_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@
</a-form-item>
</td>
</tr>
<tr v-if="clientsBulkModal.expiryTime != 0">
<td>
<span>{{ i18n "pages.client.renew" }}</span>
<a-tooltip>
<template slot="title">
<span>{{ i18n "pages.client.renewDesc" }}</span>
</template>
<a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip>
</td>
<td>
<a-form-item>
<a-input-number v-model.number="clientsBulkModal.reset" :min="0"></a-input-number>
</a-form-item>
</td>
</tr>
</table>
</a-form>
</a-modal>
Expand All @@ -160,6 +176,7 @@
tgId: "",
flow: "",
delayedStart: false,
reset: 0,
ok() {
clients = [];
method=clientsBulkModal.emailMethod;
Expand All @@ -184,6 +201,7 @@
if(clientsBulkModal.inbound.canEnableTlsFlow()){
newClient.flow = clientsBulkModal.flow;
}
newClient.reset = clientsBulkModal.reset;
clients.push(newClient);
}
ObjectUtil.execute(clientsBulkModal.confirm, clients, clientsBulkModal.dbInbound.id);
Expand All @@ -207,6 +225,7 @@
this.dbInbound = new DBInbound(dbInbound);
this.inbound = dbInbound.toInbound();
this.delayedStart = false;
this.reset = 0;
},
newClient(protocol) {
switch (protocol) {
Expand Down
16 changes: 16 additions & 0 deletions web/html/xui/form/client.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@
</a-form-item>
</td>
</tr>
<tr v-if="client.expiryTime != 0">
<td>
<span>{{ i18n "pages.client.renew" }}</span>
<a-tooltip>
<template slot="title">
<span>{{ i18n "pages.client.renewDesc" }}</span>
</template>
<a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip>
</td>
<td>
<a-form-item>
<a-input-number v-model.number="client.reset" :min="0"></a-input-number>
</a-form-item>
</td>
</tr>
</table>
</a-form>
{{end}}
16 changes: 16 additions & 0 deletions web/html/xui/form/protocol/shadowsocks.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@
</a-form-item>
</td>
</tr>
<tr v-if="client.expiryTime != 0">
<td>
<span>{{ i18n "pages.client.renew" }}</span>
<a-tooltip>
<template slot="title">
<span>{{ i18n "pages.client.renewDesc" }}</span>
</template>
<a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip>
</td>
<td>
<a-form-item>
<a-input-number v-model.number="client.reset" :min="0"></a-input-number>
</a-form-item>
</td>
</tr>
</table>
</a-collapse-panel>
</a-collapse>
Expand Down
16 changes: 16 additions & 0 deletions web/html/xui/form/protocol/trojan.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@
</a-form-item>
</td>
</tr>
<tr v-if="client.expiryTime != 0">
<td>
<span>{{ i18n "pages.client.renew" }}</span>
<a-tooltip>
<template slot="title">
<span>{{ i18n "pages.client.renewDesc" }}</span>
</template>
<a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip>
</td>
<td>
<a-form-item>
<a-input-number v-model.number="client.reset" :min="0"></a-input-number>
</a-form-item>
</td>
</tr>
</table>
</a-collapse-panel>
</a-collapse>
Expand Down
16 changes: 16 additions & 0 deletions web/html/xui/form/protocol/vless.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,22 @@
</a-form-item>
</td>
</tr>
<tr v-if="client.expiryTime != 0">
<td>
<span>{{ i18n "pages.client.renew" }}</span>
<a-tooltip>
<template slot="title">
<span>{{ i18n "pages.client.renewDesc" }}</span>
</template>
<a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip>
</td>
<td>
<a-form-item>
<a-input-number v-model.number="client.reset" :min="0"></a-input-number>
</a-form-item>
</td>
</tr>
</table>
</a-collapse-panel>
</a-collapse>
Expand Down
16 changes: 16 additions & 0 deletions web/html/xui/form/protocol/vmess.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@
</a-form-item>
</td>
</tr>
<tr v-if="client.expiryTime != 0">
<td>
<span>{{ i18n "pages.client.renew" }}</span>
<a-tooltip>
<template slot="title">
<span>{{ i18n "pages.client.renewDesc" }}</span>
</template>
<a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip>
</td>
<td>
<a-form-item>
<a-input-number v-model.number="client.reset" :min="0"></a-input-number>
</a-form-item>
</td>
</tr>
</table>
</a-collapse-panel>
</a-collapse>
Expand Down
69 changes: 46 additions & 23 deletions web/html/xui/inbound_client_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,28 @@
</table>
</a-popover>
</template>
<template slot="expiryTime" slot-scope="text, client, index">
<a-popover v-if="client.expiryTime != 0" :overlay-class-name="themeSwitcher.currentTheme">
<template slot="content" v-if="client.expiryTime > 0">
[[ DateUtil.formatMillis(client._expiryTime) ]]
</template>
<a-tag style="min-width: 50px; border: none;" :color="userExpiryColor(app.expireDiff, client, themeSwitcher.isDarkTheme)">
[[ remainedDays(client.expiryTime) ]]
</a-tag>
</a-popover>
<template slot="expiryTime" slot-scope="text, client, index">
<a-badge v-if="client.expiryTime !=0 && client.reset >0"
:count="'+' + client.reset + 'd'"
:number-style="{
backgroundColor: 'transparent',
color: userExpiryColor(app.expireDiff, client, themeSwitcher.isDarkTheme),
fontSize: '8pt',
padding: '0',
boxShadow: '0 0px',
}">
<a-popover v-if="client.expiryTime > 0" :overlay-class-name="themeSwitcher.currentTheme">
<template slot="content">
[[ DateUtil.formatMillis(client._expiryTime) ]]
</template>
<a-tag style="min-width: 50px; border: none;" :color="userExpiryColor(app.expireDiff, client, themeSwitcher.isDarkTheme)">
[[ remainedDays(client.expiryTime) ]]
</a-tag>
</a-popover>
<a-tag v-else-if="client.expiryTime < 0" style="min-width: 50px; border: none;" :color="userExpiryColor(app.expireDiff, client, themeSwitcher.isDarkTheme)">
[[ remainedDays(client.expiryTime) ]]
</a-tag>
</a-badge>
<a-tag v-else :color="userExpiryColor(app.expireDiff, client, themeSwitcher.isDarkTheme)" style="border: 0;" class="infinite-tag">&infin;</a-tag>
</template>
<template slot="actionMenu" slot-scope="text, client, index">
Expand Down Expand Up @@ -201,20 +214,30 @@
</tr>
<tr>
<td colspan="3" style="text-align: center;">
<a-popover v-if="client.expiryTime > 0" :overlay-class-name="themeSwitcher.currentTheme">
<template slot="content" v-if="client.expiryTime > 0">
[[ DateUtil.formatMillis(client._expiryTime) ]]
</template>
<a-tag style="min-width: 50px; border: none;"
:color="userExpiryColor(app.expireDiff, client, themeSwitcher.isDarkTheme)">
[[ remainedDays(client.expiryTime) ]]
</a-tag>
</a-popover>
<a-tag v-else-if="client.expiryTime < 0"
style="min-width: 50px; border: none;"
:color="client.enable ? '#0e49b5' : themeSwitcher.isDarkTheme ? '#2c3950' : '#bcbcbc'">
[[ remainedDays(client.expiryTime) ]]
</a-tag>
<a-badge v-if="client.expiryTime !=0 && client.reset >0"
:count="'+' + client.reset + 'd'"
:number-style="{
backgroundColor: 'transparent',
color: userExpiryColor(app.expireDiff, client, themeSwitcher.isDarkTheme),
fontSize: '8pt',
padding: '0',
boxShadow: '0 0px',
}">
<a-popover v-if="client.expiryTime > 0" :overlay-class-name="themeSwitcher.currentTheme">
<template slot="content" v-if="client.expiryTime > 0">
[[ DateUtil.formatMillis(client._expiryTime) ]]
</template>
<a-tag style="min-width: 50px; border: none;"
:color="userExpiryColor(app.expireDiff, client, themeSwitcher.isDarkTheme)">
[[ remainedDays(client.expiryTime) ]]
</a-tag>
</a-popover>
<a-tag v-else-if="client.expiryTime < 0"
style="min-width: 50px; border: none;"
:color="client.enable ? '#0e49b5' : themeSwitcher.isDarkTheme ? '#2c3950' : '#bcbcbc'">
[[ remainedDays(client.expiryTime) ]]
</a-tag>
</a-badge>
<a-tag v-else :color="client.enable ? 'purple' : themeSwitcher.isDarkTheme ? '#2c3950' : '#bcbcbc'" class="infinite-tag">&infin;</a-tag>
</td>
</tr>
Expand Down
1 change: 1 addition & 0 deletions xray/client_traffic.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ type ClientTraffic struct {
Down int64 `json:"down" form:"down"`
ExpiryTime int64 `json:"expiryTime" form:"expiryTime"`
Total int64 `json:"total" form:"total"`
Reset int `json:"reset" form:"reset" gorm:"default:0"`
}

0 comments on commit 9640896

Please sign in to comment.