From 340b54d45fa4c52c7963de091d430a64254ad5e3 Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Thu, 2 Mar 2023 09:32:42 +0100 Subject: [PATCH] Add Export feature #28 --- web/assets/js/model/models.js | 5 +++++ web/assets/js/model/xray.js | 16 +++++++++++++ web/html/common/text_modal.html | 12 ++-------- web/html/xui/inbounds.html | 31 +++++++++++++++++++++----- web/translation/translate.en_US.toml | 1 + web/translation/translate.fa_IR.toml | 1 + web/translation/translate.zh_Hans.toml | 1 + 7 files changed, 52 insertions(+), 15 deletions(-) diff --git a/web/assets/js/model/models.js b/web/assets/js/model/models.js index 753eaa62..5e8bf6e3 100644 --- a/web/assets/js/model/models.js +++ b/web/assets/js/model/models.js @@ -155,6 +155,11 @@ class DBInbound { const inbound = this.toInbound(); return inbound.genLink(this.address, this.remark, clientIndex); } + + get genInboundLinks() { + const inbound = this.toInbound(); + return inbound.genInboundLinks(this.address, this.remark); + } } class AllSetting { diff --git a/web/assets/js/model/xray.js b/web/assets/js/model/xray.js index 8d855faf..2a2204a2 100644 --- a/web/assets/js/model/xray.js +++ b/web/assets/js/model/xray.js @@ -1236,6 +1236,22 @@ class Inbound extends XrayCommonClass { } } + genInboundLinks(address = '', remark = '') { + let link = ''; + switch (this.protocol) { + case Protocols.VMESS: + case Protocols.VLESS: + case Protocols.TROJAN: + JSON.parse(this.settings).clients.forEach((_,index) => { + link += this.genLink(address, remark, index) + '\r\n'; + }); + return link; + case Protocols.SHADOWSOCKS: + return (this.genSSLink(address, remark) + '\r\n'); + default: return ''; + } + } + static fromJson(json={}) { return new Inbound( json.port, diff --git a/web/html/common/text_modal.html b/web/html/common/text_modal.html index 0ae04a88..e26d9135 100644 --- a/web/html/common/text_modal.html +++ b/web/html/common/text_modal.html @@ -3,7 +3,7 @@ :closable="true" ok-text='{{ i18n "copy" }}' cancel-text='{{ i18n "close" }}' :ok-button-props="{attrs:{id:'txt-modal-ok-btn'}}"> + :href="'data:application/text;charset=utf-8,' + encodeURIComponent(txtModal.content)" :download="txtModal.fileName"> {{ i18n "download" }} [[ txtModal.fileName ]] app.$message.success('{{ i18n "copied" }}')); } - if (this.qrcode === null) { - this.qrcode = new QRious({ - element: document.querySelector('#qrCode'), - size: 260, - value: content, - }); - } else { - this.qrcode.value = content; - } }); }, close: function () { @@ -48,6 +39,7 @@ }; const textModalApp = new Vue({ + delimiters: ['[[', ']]'], el: '#text-modal', data: { txtModal: txtModal, diff --git a/web/html/xui/inbounds.html b/web/html/xui/inbounds.html index 824a9683..091962d8 100644 --- a/web/html/xui/inbounds.html +++ b/web/html/xui/inbounds.html @@ -51,6 +51,7 @@
{{ i18n "pages.inbounds.addInbound" }} + {{ i18n "pages.inbounds.export" }}
{{ i18n "edit" }} - - - {{ i18n "pages.client.add"}} - + {{ i18n "pages.inbounds.resetTraffic" }} @@ -276,6 +283,9 @@ case "qrcode": this.showQrcode(dbInbound); break; + case "export": + this.inboundLinks(dbInbound.id); + break; case "edit": this.openEditInbound(dbInbound.id); break; @@ -513,7 +523,18 @@ }, isRemovable(dbInbound_id){ return this.getInboundClients(this.dbInbounds.find(row => row.id === dbInbound_id)).length > 1 - } + }, + inboundLinks(dbInboundId) { + dbInbound = this.dbInbounds.find(row => row.id === dbInboundId); + txtModal.show('{{ i18n "pages.inbounds.export"}}',dbInbound.genInboundLinks,dbInbound.remark); + }, + exportAllLinks() { + let copyText = ''; + for (const dbInbound of this.dbInbounds) { + copyText += dbInbound.genInboundLinks + } + txtModal.show('{{ i18n "pages.inbounds.export"}}',copyText,'All-Inbounds'); + }, }, watch: { searchKey: debounce(function (newVal) { diff --git a/web/translation/translate.en_US.toml b/web/translation/translate.en_US.toml index 59b01869..981ed1d6 100644 --- a/web/translation/translate.en_US.toml +++ b/web/translation/translate.en_US.toml @@ -126,6 +126,7 @@ "keyContent" = "Key content" "clickOnQRcode" = "Click on QR Code to Copy" "client" = "Client" +"export" = "Export links" [pages.client] "add" = "Add client" diff --git a/web/translation/translate.fa_IR.toml b/web/translation/translate.fa_IR.toml index f5a72747..4f1decb8 100644 --- a/web/translation/translate.fa_IR.toml +++ b/web/translation/translate.fa_IR.toml @@ -126,6 +126,7 @@ "keyContent" = "محتوای Private.key" "clickOnQRcode" = "برای کپی بر روی کد تصویری کلیک کنید" "client" = "کاربر" +"export" = "استخراج لینک‌ها" [pages.client] "add" = "کاربر جدید" diff --git a/web/translation/translate.zh_Hans.toml b/web/translation/translate.zh_Hans.toml index 46c66bac..5cf66892 100644 --- a/web/translation/translate.zh_Hans.toml +++ b/web/translation/translate.zh_Hans.toml @@ -126,6 +126,7 @@ "keyContent" = "密钥内容" "clickOnQRcode" = "点击二维码复制" "client" = "客户" +"export" = "导出链接" [pages.client] "add" = "添加客户端"