inbounds.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. {{template "head" .}}
  4. <style>
  5. @media (min-width: 769px) {
  6. .ant-layout-content {
  7. margin: 24px 16px;
  8. }
  9. }
  10. .ant-col-sm-24 {
  11. margin-top: 10px;
  12. }
  13. </style>
  14. <body>
  15. <a-layout id="app" v-cloak>
  16. {{ template "commonSider" . }}
  17. <a-layout id="content-layout">
  18. <a-layout-content>
  19. <a-spin :spinning="spinning" :delay="500" tip="loading">
  20. <transition name="list" appear>
  21. <a-tag v-if="false" color="red" style="margin-bottom: 10px">
  22. Please go to the panel settings as soon as possible to modify the username and password, otherwise there may be a risk of leaking account information
  23. </a-tag>
  24. </transition>
  25. <transition name="list" appear>
  26. <a-card hoverable style="margin-bottom: 20px;">
  27. <a-row>
  28. <a-col :xs="24" :sm="24" :lg="12">
  29. {{ i18n "pages.inbounds.totalDownUp" }}:
  30. <a-tag color="green">[[ sizeFormat(total.up) ]] / [[ sizeFormat(total.down) ]]</a-tag>
  31. </a-col>
  32. <a-col :xs="24" :sm="24" :lg="12">
  33. {{ i18n "pages.inbounds.totalUsage" }}:
  34. <a-tag color="green">[[ sizeFormat(total.up + total.down) ]]</a-tag>
  35. </a-col>
  36. <a-col :xs="24" :sm="24" :lg="12">
  37. {{ i18n "pages.inbounds.inboundCount" }}:
  38. <a-tag color="green">[[ dbInbounds.length ]]</a-tag>
  39. </a-col>
  40. </a-row>
  41. </a-card>
  42. </transition>
  43. <transition name="list" appear>
  44. <a-card hoverable>
  45. <div slot="title">
  46. <a-button type="primary" @click="openAddInbound">Add Inbound</a-button>
  47. <a-button type="primary" @click="exportAllLinks" class="copy-btn">Export Links</a-button>
  48. </div>
  49. <a-input v-model.lazy="searchKey" placeholder="{{ i18n "search" }}" autofocus style="max-width: 300px"></a-input>
  50. <a-table :columns="columns" :row-key="dbInbound => dbInbound.id"
  51. :data-source="searchedInbounds"
  52. :loading="spinning" :scroll="{ x: 1300 }"
  53. :pagination="false"
  54. style="margin-top: 20px"
  55. @change="() => getDBInbounds()">
  56. <template slot="action" slot-scope="text, dbInbound">
  57. <a-icon type="edit" style="font-size: 25px" @click="openEditInbound(dbInbound.id);"></a-icon>
  58. <a-dropdown :trigger="['click']">
  59. <a @click="e => e.preventDefault()">{{ i18n "pages.inbounds.operate" }}</a>
  60. <a-menu slot="overlay" @click="a => clickAction(a, dbInbound)">
  61. <a-menu-item v-if="dbInbound.isSS" key="qrcode">
  62. <a-icon type="qrcode"></a-icon>
  63. {{ i18n "qrCode" }}
  64. </a-menu-item>
  65. <a-menu-item key="edit">
  66. <a-icon type="edit"></a-icon>
  67. {{ i18n "edit" }}
  68. </a-menu-item>
  69. <a-menu-item key="resetTraffic">
  70. <a-icon type="retweet"></a-icon> {{ i18n "pages.inbounds.resetTraffic" }}
  71. </a-menu-item>
  72. <a-menu-item key="delete">
  73. <span style="color: #FF4D4F">
  74. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  75. </span>
  76. </a-menu-item>
  77. </a-menu>
  78. </a-dropdown>
  79. </template>
  80. <template slot="protocol" slot-scope="text, dbInbound">
  81. <a-tag color="blue">[[ dbInbound.protocol ]]</a-tag>
  82. </template>
  83. <template slot="traffic" slot-scope="text, dbInbound">
  84. <a-tag color="blue">[[ sizeFormat(dbInbound.up) ]] / [[ sizeFormat(dbInbound.down) ]]</a-tag>
  85. <template v-if="dbInbound.total > 0">
  86. <a-tag v-if="dbInbound.up + dbInbound.down < dbInbound.total" color="cyan">[[ sizeFormat(dbInbound.total) ]]</a-tag>
  87. <a-tag v-else color="red">[[ sizeFormat(dbInbound.total) ]]</a-tag>
  88. </template>
  89. <a-tag v-else color="green">{{ i18n "unlimited" }}</a-tag>
  90. </template>
  91. <template slot="stream" slot-scope="text, dbInbound, index">
  92. <template v-if="dbInbound.isVMess || dbInbound.isVLess || dbInbound.isTrojan || dbInbound.isSS">
  93. <a-tag color="green">[[ inbounds[index].stream.network ]]</a-tag>
  94. <a-tag v-if="inbounds[index].stream.isTls" color="blue">tls</a-tag>
  95. <a-tag v-if="inbounds[index].stream.isXTls" color="blue">xtls</a-tag>
  96. </template>
  97. <template v-else>{{ i18n "none" }}</template>
  98. </template>
  99. <template slot="enable" slot-scope="text, dbInbound">
  100. <a-switch v-model="dbInbound.enable" @change="switchEnable(dbInbound)"></a-switch>
  101. </template>
  102. <template slot="expiryTime" slot-scope="text, dbInbound">
  103. <template v-if="dbInbound.expiryTime > 0">
  104. <a-tag v-if="dbInbound.isExpiry" color="red">
  105. [[ DateUtil.formatMillis(dbInbound.expiryTime) ]]
  106. </a-tag>
  107. <a-tag v-else color="blue">
  108. [[ DateUtil.formatMillis(dbInbound.expiryTime) ]]
  109. </a-tag>
  110. </template>
  111. <a-tag v-else color="green">{{ i18n "indefinite" }}</a-tag>
  112. </template>
  113. <template slot="expandedRowRender" slot-scope="record">
  114. <a-table
  115. v-if="(record.protocol === Protocols.VLESS) || (record.protocol === Protocols.VMESS)"
  116. :row-key="client => client.id"
  117. :columns="innerColumns"
  118. :data-source="getInboundClients(record)"
  119. :pagination="false"
  120. >
  121. {{template "client_row"}}
  122. </a-table>
  123. <a-table
  124. v-else-if="record.protocol === Protocols.TROJAN"
  125. :row-key="client => client.id"
  126. :columns="innerTrojanColumns"
  127. :data-source="getInboundClients(record)"
  128. :pagination="false"
  129. >
  130. {{template "client_row"}}
  131. </a-table>
  132. <a-table
  133. v-else
  134. :row-key="client => client.id"
  135. :columns="innerOneColumns"
  136. :data-source="record"
  137. :pagination="false"
  138. >
  139. {{template "client_row"}}
  140. </a-table>
  141. </template>
  142. </a-table>
  143. </a-card>
  144. </transition>
  145. </a-spin>
  146. </a-layout-content>
  147. </a-layout>
  148. </a-layout>
  149. {{template "js" .}}
  150. <script>
  151. const columns = [{
  152. title: '{{ i18n "pages.inbounds.operate" }}',
  153. align: 'center',
  154. width: 60,
  155. scopedSlots: { customRender: 'action' },
  156. }, {
  157. title: '{{ i18n "pages.inbounds.enable" }}',
  158. align: 'center',
  159. width: 40,
  160. scopedSlots: { customRender: 'enable' },
  161. }, {
  162. title: "Id",
  163. align: 'center',
  164. dataIndex: "id",
  165. width: 30,
  166. }, {
  167. title: '{{ i18n "pages.inbounds.remark" }}',
  168. align: 'center',
  169. width: 80,
  170. dataIndex: "remark",
  171. }, {
  172. title: '{{ i18n "pages.inbounds.protocol" }}',
  173. align: 'center',
  174. width: 50,
  175. scopedSlots: { customRender: 'protocol' },
  176. }, {
  177. title: '{{ i18n "pages.inbounds.port" }}',
  178. align: 'center',
  179. dataIndex: "port",
  180. width: 40,
  181. }, {
  182. title: '{{ i18n "pages.inbounds.traffic" }}↑|↓',
  183. align: 'center',
  184. width: 150,
  185. scopedSlots: { customRender: 'traffic' },
  186. },{
  187. title: '{{ i18n "pages.inbounds.transportConfig" }}',
  188. align: 'center',
  189. width: 60,
  190. scopedSlots: { customRender: 'stream' },
  191. }, {
  192. title: '{{ i18n "pages.inbounds.expireDate" }}',
  193. align: 'center',
  194. width: 80,
  195. scopedSlots: { customRender: 'expiryTime' },
  196. }];
  197. const innerColumns = [
  198. { title: '', width: 70, scopedSlots: { customRender: 'actions' } },
  199. { title: '{{ i18n "pages.inbounds.client" }}', width: 60, scopedSlots: { customRender: 'client' } },
  200. { title: '{{ i18n "pages.inbounds.traffic" }}↑|↓', width: 100, scopedSlots: { customRender: 'traffic' } },
  201. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 70, scopedSlots: { customRender: 'expiryTime' } },
  202. { title: 'UID', width: 120, dataIndex: "id" },
  203. ];
  204. const innerTrojanColumns = [
  205. { title: '', width: 70, scopedSlots: { customRender: 'actions' } },
  206. { title: '{{ i18n "pages.inbounds.client" }}', width: 60, scopedSlots: { customRender: 'client' } },
  207. { title: '{{ i18n "pages.inbounds.traffic" }}↑|↓', width: 100, scopedSlots: { customRender: 'traffic' } },
  208. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 70, scopedSlots: { customRender: 'expiryTime' } },
  209. { title: 'Password', width: 100, dataIndex: "password" },
  210. ];
  211. const innerOneColumns = [
  212. { title: '', width: 70, scopedSlots: { customRender: 'actions' } },
  213. ];
  214. const app = new Vue({
  215. delimiters: ['[[', ']]'],
  216. el: '#app',
  217. data: {
  218. siderDrawer,
  219. spinning: false,
  220. inbounds: [],
  221. dbInbounds: [],
  222. searchKey: '',
  223. searchedInbounds: [],
  224. },
  225. methods: {
  226. loading(spinning=true) {
  227. this.spinning = spinning;
  228. },
  229. async getDBInbounds() {
  230. this.loading();
  231. const msg = await HttpUtil.post('/xui/inbound/list');
  232. this.loading(false);
  233. if (!msg.success) {
  234. return;
  235. }
  236. this.setInbounds(msg.obj);
  237. },
  238. setInbounds(dbInbounds) {
  239. this.inbounds.splice(0);
  240. this.dbInbounds.splice(0);
  241. this.searchedInbounds.splice(0);
  242. for (const inbound of dbInbounds) {
  243. const dbInbound = new DBInbound(inbound);
  244. this.inbounds.push(dbInbound.toInbound());
  245. this.dbInbounds.push(dbInbound);
  246. this.searchedInbounds.push(dbInbound);
  247. }
  248. },
  249. searchInbounds(key) {
  250. if (ObjectUtil.isEmpty(key)) {
  251. this.searchedInbounds = this.dbInbounds.slice();
  252. } else {
  253. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  254. this.dbInbounds.forEach(inbound => {
  255. if (ObjectUtil.deepSearch(inbound, key)) {
  256. const newInbound = new DBInbound(inbound);
  257. const inboundSettings = JSON.parse(inbound.settings);
  258. if (inboundSettings.hasOwnProperty('clients')){
  259. const searchedSettings = { "clients": [] };
  260. inboundSettings.clients.forEach(client => {
  261. if (ObjectUtil.deepSearch(client, key)){
  262. searchedSettings.clients.push(client);
  263. }
  264. });
  265. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, searchedSettings);
  266. }
  267. this.searchedInbounds.push(newInbound);
  268. }
  269. });
  270. }
  271. },
  272. clickAction(action, dbInbound) {
  273. switch (action.key) {
  274. case "qrcode":
  275. this.showQrcode(dbInbound);
  276. break;
  277. case "edit":
  278. this.openEditInbound(dbInbound.id);
  279. break;
  280. case "resetTraffic":
  281. this.resetTraffic(dbInbound);
  282. break;
  283. case "delete":
  284. this.delInbound(dbInbound);
  285. break;
  286. }
  287. },
  288. openAddInbound() {
  289. inModal.show({
  290. title: '{{ i18n "pages.inbounds.addInbound"}}',
  291. okText: '{{ i18n "pages.inbounds.addTo"}}',
  292. cancelText: '{{ i18n "close" }}',
  293. confirm: async (inbound, dbInbound) => {
  294. inModal.loading();
  295. await this.addInbound(inbound, dbInbound);
  296. inModal.close();
  297. },
  298. isEdit: false
  299. });
  300. },
  301. openEditInbound(dbInbound_id) {
  302. dbInbound = this.dbInbounds.find(row => row.id === dbInbound_id);
  303. const inbound = dbInbound.toInbound();
  304. inModal.show({
  305. title: '{{ i18n "pages.inbounds.modifyInbound"}}',
  306. okText: '{{ i18n "pages.inbounds.revise"}}',
  307. cancelText: '{{ i18n "close" }}',
  308. inbound: inbound,
  309. dbInbound: dbInbound,
  310. confirm: async (inbound, dbInbound) => {
  311. inModal.loading();
  312. await this.updateInbound(inbound, dbInbound);
  313. inModal.close();
  314. },
  315. isEdit: true
  316. });
  317. },
  318. async addInbound(inbound, dbInbound) {
  319. const data = {
  320. up: dbInbound.up,
  321. down: dbInbound.down,
  322. total: dbInbound.total,
  323. remark: dbInbound.remark,
  324. enable: dbInbound.enable,
  325. expiryTime: dbInbound.expiryTime,
  326. listen: inbound.listen,
  327. port: inbound.port,
  328. protocol: inbound.protocol,
  329. settings: inbound.settings.toString(),
  330. streamSettings: inbound.stream.toString(),
  331. sniffing: inbound.canSniffing() ? inbound.sniffing.toString() : '{}',
  332. };
  333. await this.submit('/xui/inbound/add', data, inModal);
  334. },
  335. async updateInbound(inbound, dbInbound) {
  336. const data = {
  337. up: dbInbound.up,
  338. down: dbInbound.down,
  339. total: dbInbound.total,
  340. remark: dbInbound.remark,
  341. enable: dbInbound.enable,
  342. expiryTime: dbInbound.expiryTime,
  343. listen: inbound.listen,
  344. port: inbound.port,
  345. protocol: inbound.protocol,
  346. settings: inbound.settings.toString(),
  347. streamSettings: inbound.stream.toString(),
  348. sniffing: inbound.canSniffing() ? inbound.sniffing.toString() : '{}',
  349. };
  350. await this.submit(`/xui/inbound/update/${dbInbound.id}`, data, inModal);
  351. },
  352. resetTraffic(dbInbound) {
  353. this.$confirm({
  354. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  355. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  356. okText: '{{ i18n "reset"}}',
  357. cancelText: '{{ i18n "cancel"}}',
  358. onOk: () => {
  359. const inbound = dbInbound.toInbound();
  360. dbInbound.up = 0;
  361. dbInbound.down = 0;
  362. this.updateInbound(inbound, dbInbound);
  363. },
  364. });
  365. },
  366. exportAllLinks() {
  367. let copyText = '';
  368. for (const dbInbound of this.dbInbounds) {
  369. copyText += dbInbound.genInboundLinks
  370. }
  371. const clipboard = new ClipboardJS('.copy-btn', {
  372. text: function () {
  373. return copyText;
  374. }
  375. });
  376. clipboard.on('success', () => { this.$message.success('Export Links succeed'); });
  377. },
  378. delInbound(dbInbound) {
  379. this.$confirm({
  380. title: '{{ i18n "pages.inbounds.deleteInbound"}}',
  381. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  382. okText: '{{ i18n "delete"}}',
  383. cancelText: '{{ i18n "cancel"}}',
  384. onOk: () => this.submit('/xui/inbound/del/' + dbInbound.id),
  385. });
  386. },
  387. showQrcode(dbInbound, clientIndex) {
  388. const link = dbInbound.genLink(clientIndex);
  389. qrModal.show('{{ i18n "qrCode"}}', link, dbInbound);
  390. },
  391. showInfo(dbInbound, index) {
  392. infoModal.show(dbInbound, index);
  393. },
  394. switchEnable(dbInbound) {
  395. this.submit(`/xui/inbound/update/${dbInbound.id}`, dbInbound);
  396. },
  397. async submit(url, data, modal) {
  398. const msg = await HttpUtil.postWithModal(url, data, modal);
  399. if (msg.success) {
  400. await this.getDBInbounds();
  401. }
  402. },
  403. getInboundClients(dbInbound) {
  404. if(dbInbound.protocol == Protocols.VLESS) {
  405. return dbInbound.toInbound().settings.vlesses
  406. } else if(dbInbound.protocol == Protocols.VMESS) {
  407. return dbInbound.toInbound().settings.vmesses
  408. } else if(dbInbound.protocol == Protocols.TROJAN) {
  409. return dbInbound.toInbound().settings.trojans
  410. }
  411. },
  412. resetClientTraffic(client,inbound,event) {
  413. this.$confirm({
  414. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  415. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  416. okText: '{{ i18n "reset"}}',
  417. cancelText: '{{ i18n "cancel"}}',
  418. onOk: () => {
  419. this.resetClTraffic(client,inbound,event);
  420. },
  421. });
  422. },
  423. async resetClTraffic(client,inbound,event) {
  424. const msg = await HttpUtil.post('/xui/inbound/resetClientTraffic/'+ client.email);
  425. if (!msg.success) {
  426. return;
  427. }
  428. clientStats = inbound.clientStats
  429. if(clientStats.length > 0)
  430. {
  431. for (const key in clientStats) {
  432. if (Object.hasOwnProperty.call(clientStats, key)) {
  433. if(clientStats[key]['email'] == client.email){
  434. clientStats[key]['up'] = 0
  435. clientStats[key]['down'] = 0
  436. }
  437. }
  438. }
  439. }
  440. },
  441. isExpiry(dbInbound, index) {
  442. return dbInbound.toInbound().isExpiry(index)
  443. },
  444. getUpStats(dbInbound, email) {
  445. clientStats = dbInbound.clientStats
  446. if(clientStats.length > 0)
  447. {
  448. for (const key in clientStats) {
  449. if (Object.hasOwnProperty.call(clientStats, key)) {
  450. if(clientStats[key]['email'] == email)
  451. return clientStats[key]['up']
  452. }
  453. }
  454. }
  455. },
  456. getDownStats(dbInbound, email) {
  457. clientStats = dbInbound.clientStats
  458. if(clientStats.length > 0)
  459. {
  460. for (const key in clientStats) {
  461. if (Object.hasOwnProperty.call(clientStats, key)) {
  462. if(clientStats[key]['email'] == email)
  463. return clientStats[key]['down']
  464. }
  465. }
  466. }
  467. },
  468. isTrafficExhausted(dbInbound, email) {
  469. clientStats = dbInbound.clientStats
  470. if(clientStats.length > 0)
  471. {
  472. for (const key in clientStats) {
  473. if (Object.hasOwnProperty.call(clientStats, key)) {
  474. if(clientStats[key]['email'] == email)
  475. return clientStats[key]['down']+clientStats[key]['up'] > clientStats[key]['total']
  476. }
  477. }
  478. }
  479. },
  480. isClientEnabled(dbInbound, email) {
  481. clientStats = dbInbound.clientStats
  482. if(clientStats.length > 0)
  483. {
  484. for (const key in clientStats) {
  485. if (Object.hasOwnProperty.call(clientStats, key)) {
  486. if(clientStats[key]['email'] == email)
  487. return clientStats[key]['enable']
  488. }
  489. }
  490. }
  491. else{
  492. return true
  493. }
  494. },
  495. },
  496. watch: {
  497. searchKey: debounce(function (newVal) {
  498. this.searchInbounds(newVal);
  499. }, 500)
  500. },
  501. mounted() {
  502. this.getDBInbounds();
  503. },
  504. computed: {
  505. total() {
  506. let down = 0, up = 0;
  507. for (let i = 0; i < this.dbInbounds.length; ++i) {
  508. down += this.dbInbounds[i].down;
  509. up += this.dbInbounds[i].up;
  510. }
  511. return {
  512. down: down,
  513. up: up,
  514. };
  515. }
  516. },
  517. });
  518. </script>
  519. {{template "inboundModal"}}
  520. {{template "promptModal"}}
  521. {{template "qrcodeModal"}}
  522. {{template "textModal"}}
  523. {{template "inboundInfoModal"}}
  524. </body>
  525. </html>