inbounds.html 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  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" :style="siderDrawer.isDarkTheme ? bgDarkStyle : ''">
  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;" :class="siderDrawer.isDarkTheme ? darkClass : ''">
  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-col :xs="24" :sm="24" :lg="12">
  41. {{ i18n "clients" }}:
  42. <a-tag color="green">[[ total.clients ]]</a-tag>
  43. <a-tag color="blue">{{ i18n "enabled" }} [[ total.active ]]</a-tag>
  44. <a-tag color="red">{{ i18n "disabled" }} [[ total.deactive ]]</a-tag>
  45. </a-col>
  46. </a-row>
  47. </a-card>
  48. </transition>
  49. <transition name="list" appear>
  50. <a-card hoverable :class="siderDrawer.isDarkTheme ? darkClass : ''">
  51. <div slot="title">
  52. <a-button type="primary" icon="plus" @click="openAddInbound">{{ i18n "pages.inbounds.addInbound" }}</a-button>
  53. <a-button type="primary" icon="export" @click="exportAllLinks">{{ i18n "pages.inbounds.export" }}</a-button>
  54. <a-button type="primary" icon="reload" @click="resetAllTraffic">{{ i18n "pages.inbounds.resetAllTraffic" }}</a-button>
  55. </div>
  56. <a-input v-model.lazy="searchKey" placeholder="{{ i18n "search" }}" autofocus style="max-width: 300px"></a-input>
  57. <a-table :columns="columns" :row-key="dbInbound => dbInbound.id"
  58. :data-source="searchedInbounds"
  59. :loading="spinning" :scroll="{ x: 1300 }"
  60. :pagination="false"
  61. style="margin-top: 20px"
  62. @change="() => getDBInbounds()">
  63. <template slot="action" slot-scope="text, dbInbound">
  64. <a-icon type="edit" style="font-size: 25px" @click="openEditInbound(dbInbound.id);"></a-icon>
  65. <a-dropdown :trigger="['click']">
  66. <a @click="e => e.preventDefault()">{{ i18n "pages.inbounds.operate" }}</a>
  67. <a-menu slot="overlay" @click="a => clickAction(a, dbInbound)" :theme="siderDrawer.theme" style="border: 1px solid rgba(255, 255, 255, 0.65);">
  68. <a-menu-item v-if="dbInbound.isSS" key="qrcode">
  69. <a-icon type="qrcode"></a-icon>
  70. {{ i18n "qrCode" }}
  71. </a-menu-item>
  72. <a-menu-item key="edit">
  73. <a-icon type="edit"></a-icon>
  74. {{ i18n "edit" }}
  75. </a-menu-item>
  76. <template v-if="dbInbound.isTrojan || dbInbound.isVLess || dbInbound.isVMess">
  77. <a-menu-item key="addClient">
  78. <a-icon type="user"></a-icon>
  79. {{ i18n "pages.client.add"}}
  80. </a-menu-item>
  81. <a-menu-item key="addBulkClient">
  82. <a-icon type="team"></a-icon>
  83. {{ i18n "pages.client.bulk"}}
  84. </a-menu-item>
  85. <a-menu-item key="export">
  86. <a-icon type="export"></a-icon>
  87. {{ i18n "pages.inbounds.export"}}
  88. </a-menu-item>
  89. </template>
  90. <template v-else>
  91. <a-menu-item key="showInfo">
  92. <a-icon type="info-circle"></a-icon>
  93. {{ i18n "info"}}
  94. </a-menu-item>
  95. </template>
  96. <a-menu-item key="resetTraffic">
  97. <a-icon type="retweet"></a-icon> {{ i18n "pages.inbounds.resetTraffic" }}
  98. </a-menu-item>
  99. <a-menu-item key="clone">
  100. <a-icon type="block"></a-icon> {{ i18n "pages.inbounds.Clone"}}
  101. </a-menu-item>
  102. <a-menu-item key="delete">
  103. <span style="color: #FF4D4F">
  104. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  105. </span>
  106. </a-menu-item>
  107. </a-menu>
  108. </a-dropdown>
  109. </template>
  110. <template slot="protocol" slot-scope="text, dbInbound">
  111. <a-tag color="blue">[[ dbInbound.protocol ]]</a-tag>
  112. </template>
  113. <template slot="traffic" slot-scope="text, dbInbound">
  114. <a-tag color="blue">[[ sizeFormat(dbInbound.up) ]] / [[ sizeFormat(dbInbound.down) ]]</a-tag>
  115. <template v-if="dbInbound.total > 0">
  116. <a-tag v-if="dbInbound.up + dbInbound.down < dbInbound.total" color="cyan">[[ sizeFormat(dbInbound.total) ]]</a-tag>
  117. <a-tag v-else color="red">[[ sizeFormat(dbInbound.total) ]]</a-tag>
  118. </template>
  119. <a-tag v-else color="green">{{ i18n "unlimited" }}</a-tag>
  120. </template>
  121. <template slot="stream" slot-scope="text, dbInbound, index">
  122. <template v-if="dbInbound.isVMess || dbInbound.isVLess || dbInbound.isTrojan || dbInbound.isSS">
  123. <a-tag color="green">[[ inbounds[index].stream.network ]]</a-tag>
  124. <a-tag v-if="inbounds[index].stream.isTls" color="blue">tls</a-tag>
  125. <a-tag v-if="inbounds[index].stream.isXTls" color="blue">xtls</a-tag>
  126. </template>
  127. <template v-else>{{ i18n "none" }}</template>
  128. </template>
  129. <template slot="enable" slot-scope="text, dbInbound">
  130. <a-switch v-model="dbInbound.enable" @change="switchEnable(dbInbound.id)"></a-switch>
  131. </template>
  132. <template slot="expiryTime" slot-scope="text, dbInbound">
  133. <template v-if="dbInbound.expiryTime > 0">
  134. <a-tag v-if="dbInbound.isExpiry" color="red">
  135. [[ DateUtil.formatMillis(dbInbound.expiryTime) ]]
  136. </a-tag>
  137. <a-tag v-else color="blue">
  138. [[ DateUtil.formatMillis(dbInbound.expiryTime) ]]
  139. </a-tag>
  140. </template>
  141. <a-tag v-else color="green">{{ i18n "indefinite" }}</a-tag>
  142. </template>
  143. <template slot="expandedRowRender" slot-scope="record">
  144. <a-table
  145. v-if="(record.protocol === Protocols.VLESS) || (record.protocol === Protocols.VMESS)"
  146. :row-key="client => client.id"
  147. :columns="innerColumns"
  148. :data-source="getInboundClients(record)"
  149. :pagination="false"
  150. >
  151. {{template "client_table"}}
  152. </a-table>
  153. <a-table
  154. v-else-if="record.protocol === Protocols.TROJAN"
  155. :row-key="client => client.id"
  156. :columns="innerTrojanColumns"
  157. :data-source="getInboundClients(record)"
  158. :pagination="false"
  159. >
  160. {{template "client_table"}}
  161. </a-table>
  162. </template>
  163. </a-table>
  164. </a-card>
  165. </transition>
  166. </a-spin>
  167. </a-layout-content>
  168. </a-layout>
  169. </a-layout>
  170. {{template "js" .}}
  171. <script>
  172. const columns = [{
  173. title: '{{ i18n "pages.inbounds.operate" }}',
  174. align: 'center',
  175. width: 60,
  176. scopedSlots: { customRender: 'action' },
  177. }, {
  178. title: '{{ i18n "pages.inbounds.enable" }}',
  179. align: 'center',
  180. width: 40,
  181. scopedSlots: { customRender: 'enable' },
  182. }, {
  183. title: "ID",
  184. align: 'center',
  185. dataIndex: "id",
  186. width: 30,
  187. }, {
  188. title: '{{ i18n "pages.inbounds.remark" }}',
  189. align: 'center',
  190. width: 80,
  191. dataIndex: "remark",
  192. }, {
  193. title: '{{ i18n "pages.inbounds.protocol" }}',
  194. align: 'center',
  195. width: 50,
  196. scopedSlots: { customRender: 'protocol' },
  197. }, {
  198. title: '{{ i18n "pages.inbounds.port" }}',
  199. align: 'center',
  200. dataIndex: "port",
  201. width: 40,
  202. }, {
  203. title: '{{ i18n "pages.inbounds.traffic" }}↑|↓',
  204. align: 'center',
  205. width: 150,
  206. scopedSlots: { customRender: 'traffic' },
  207. }, {
  208. title: '{{ i18n "pages.inbounds.transportConfig" }}',
  209. align: 'center',
  210. width: 60,
  211. scopedSlots: { customRender: 'stream' },
  212. }, {
  213. title: '{{ i18n "pages.inbounds.expireDate" }}',
  214. align: 'center',
  215. width: 80,
  216. scopedSlots: { customRender: 'expiryTime' },
  217. }];
  218. const innerColumns = [
  219. { title: '{{ i18n "pages.inbounds.operate" }}', width: 70, scopedSlots: { customRender: 'actions' } },
  220. { title: '{{ i18n "pages.inbounds.client" }}', width: 60, scopedSlots: { customRender: 'client' } },
  221. { title: '{{ i18n "pages.inbounds.traffic" }}↑|↓', width: 100, scopedSlots: { customRender: 'traffic' } },
  222. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 70, scopedSlots: { customRender: 'expiryTime' } },
  223. { title: 'UID', width: 150, dataIndex: "id" },
  224. ];
  225. const innerTrojanColumns = [
  226. { title: '{{ i18n "pages.inbounds.operate" }}', width: 70, scopedSlots: { customRender: 'actions' } },
  227. { title: '{{ i18n "pages.inbounds.client" }}', width: 60, scopedSlots: { customRender: 'client' } },
  228. { title: '{{ i18n "pages.inbounds.traffic" }}↑|↓', width: 100, scopedSlots: { customRender: 'traffic' } },
  229. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 70, scopedSlots: { customRender: 'expiryTime' } },
  230. { title: 'Password', width: 100, dataIndex: "password" },
  231. ];
  232. const app = new Vue({
  233. delimiters: ['[[', ']]'],
  234. el: '#app',
  235. data: {
  236. siderDrawer,
  237. spinning: false,
  238. inbounds: [],
  239. dbInbounds: [],
  240. searchKey: '',
  241. searchedInbounds: [],
  242. },
  243. methods: {
  244. loading(spinning=true) {
  245. this.spinning = spinning;
  246. },
  247. async getDBInbounds() {
  248. this.loading();
  249. const msg = await HttpUtil.post('/xui/inbound/list');
  250. this.loading(false);
  251. if (!msg.success) {
  252. return;
  253. }
  254. this.setInbounds(msg.obj);
  255. this.searchKey = '';
  256. },
  257. setInbounds(dbInbounds) {
  258. this.inbounds.splice(0);
  259. this.dbInbounds.splice(0);
  260. this.searchedInbounds.splice(0);
  261. for (const inbound of dbInbounds) {
  262. const dbInbound = new DBInbound(inbound);
  263. this.inbounds.push(dbInbound.toInbound());
  264. this.dbInbounds.push(dbInbound);
  265. this.searchedInbounds.push(dbInbound);
  266. }
  267. },
  268. searchInbounds(key) {
  269. if (ObjectUtil.isEmpty(key)) {
  270. this.searchedInbounds = this.dbInbounds.slice();
  271. } else {
  272. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  273. this.dbInbounds.forEach(inbound => {
  274. if (ObjectUtil.deepSearch(inbound, key)) {
  275. const newInbound = new DBInbound(inbound);
  276. const inboundSettings = JSON.parse(inbound.settings);
  277. if (inboundSettings.hasOwnProperty('clients')){
  278. const searchedSettings = { "clients": [] };
  279. inboundSettings.clients.forEach(client => {
  280. if (ObjectUtil.deepSearch(client, key)){
  281. searchedSettings.clients.push(client);
  282. }
  283. });
  284. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, searchedSettings);
  285. }
  286. this.searchedInbounds.push(newInbound);
  287. }
  288. });
  289. }
  290. },
  291. clickAction(action, dbInbound) {
  292. switch (action.key) {
  293. case "qrcode":
  294. this.showQrcode(dbInbound);
  295. break;
  296. case "showInfo":
  297. this.showInfo(dbInbound);
  298. break;
  299. case "edit":
  300. this.openEditInbound(dbInbound.id);
  301. break;
  302. case "addClient":
  303. this.openAddClient(dbInbound.id)
  304. break;
  305. case "addBulkClient":
  306. this.openAddBulkClient(dbInbound.id)
  307. break;
  308. case "export":
  309. this.inboundLinks(dbInbound.id);
  310. break;
  311. case "resetTraffic":
  312. this.resetTraffic(dbInbound.id);
  313. break;
  314. case "clone":
  315. this.openCloneInbound(dbInbound);
  316. break;
  317. case "delete":
  318. this.delInbound(dbInbound.id);
  319. break;
  320. }
  321. },
  322. openCloneInbound(dbInbound) {
  323. this.$confirm({
  324. title: '{{ i18n "pages.inbounds.cloneInbound"}} ' + dbInbound.remark,
  325. content: '{{ i18n "pages.inbounds.cloneInboundContent"}}',
  326. okText: '{{ i18n "pages.inbounds.cloneInboundOk"}}',
  327. cancelText: '{{ i18n "cancel" }}',
  328. onOk: () => {
  329. const baseInbound = dbInbound.toInbound();
  330. dbInbound.up = 0;
  331. dbInbound.down = 0;
  332. this.cloneInbound(baseInbound, dbInbound);
  333. },
  334. });
  335. },
  336. async cloneInbound(baseInbound, dbInbound) {
  337. const inbound = new Inbound();
  338. const data = {
  339. up: dbInbound.up,
  340. down: dbInbound.down,
  341. total: dbInbound.total,
  342. remark: dbInbound.remark + " - Cloned",
  343. enable: dbInbound.enable,
  344. expiryTime: dbInbound.expiryTime,
  345. listen: inbound.listen,
  346. port: inbound.port,
  347. protocol: baseInbound.protocol,
  348. settings: inbound.settings.toString(),
  349. streamSettings: baseInbound.stream.toString(),
  350. sniffing: baseInbound.canSniffing() ? baseInbound.sniffing.toString() : '{}',
  351. };
  352. await this.submit('/xui/inbound/add', data, inModal);
  353. },
  354. openAddInbound() {
  355. inModal.show({
  356. title: '{{ i18n "pages.inbounds.addInbound"}}',
  357. okText: '{{ i18n "pages.inbounds.addTo"}}',
  358. cancelText: '{{ i18n "close" }}',
  359. confirm: async (inbound, dbInbound) => {
  360. inModal.loading();
  361. await this.addInbound(inbound, dbInbound);
  362. inModal.close();
  363. },
  364. isEdit: false
  365. });
  366. },
  367. openEditInbound(dbInboundId) {
  368. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  369. const inbound = dbInbound.toInbound();
  370. inModal.show({
  371. title: '{{ i18n "pages.inbounds.modifyInbound"}}',
  372. okText: '{{ i18n "pages.inbounds.revise"}}',
  373. cancelText: '{{ i18n "close" }}',
  374. inbound: inbound,
  375. dbInbound: dbInbound,
  376. confirm: async (inbound, dbInbound) => {
  377. inModal.loading();
  378. await this.updateInbound(inbound, dbInbound);
  379. inModal.close();
  380. },
  381. isEdit: true
  382. });
  383. },
  384. async addInbound(inbound, dbInbound) {
  385. const data = {
  386. up: dbInbound.up,
  387. down: dbInbound.down,
  388. total: dbInbound.total,
  389. remark: dbInbound.remark,
  390. enable: dbInbound.enable,
  391. expiryTime: dbInbound.expiryTime,
  392. listen: inbound.listen,
  393. port: inbound.port,
  394. protocol: inbound.protocol,
  395. settings: inbound.settings.toString(),
  396. };
  397. if (inbound.canEnableStream()) data.streamSettings = inbound.stream.toString();
  398. if (inbound.canSniffing()) data.sniffing = inbound.sniffing.toString();
  399. await this.submit('/xui/inbound/add', data, inModal);
  400. },
  401. async updateInbound(inbound, dbInbound) {
  402. const data = {
  403. up: dbInbound.up,
  404. down: dbInbound.down,
  405. total: dbInbound.total,
  406. remark: dbInbound.remark,
  407. enable: dbInbound.enable,
  408. expiryTime: dbInbound.expiryTime,
  409. listen: inbound.listen,
  410. port: inbound.port,
  411. protocol: inbound.protocol,
  412. settings: inbound.settings.toString(),
  413. };
  414. if (inbound.canEnableStream()) data.streamSettings = inbound.stream.toString();
  415. if (inbound.canSniffing()) data.sniffing = inbound.sniffing.toString();
  416. await this.submit(`/xui/inbound/update/${dbInbound.id}`, data, inModal);
  417. },
  418. openAddClient(dbInboundId) {
  419. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  420. clientModal.show({
  421. title: '{{ i18n "pages.client.add"}}',
  422. okText: '{{ i18n "pages.client.submitAdd"}}',
  423. dbInbound: dbInbound,
  424. confirm: async (inbound, dbInbound, index) => {
  425. clientModal.loading();
  426. await this.addClient(inbound, dbInbound);
  427. clientModal.close();
  428. },
  429. isEdit: false
  430. });
  431. },
  432. openAddBulkClient(dbInboundId) {
  433. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  434. clientsBulkModal.show({
  435. title: '{{ i18n "pages.client.bulk"}} ' + dbInbound.remark,
  436. okText: '{{ i18n "pages.client.bulk"}}',
  437. dbInbound: dbInbound,
  438. confirm: async (inbound, dbInbound) => {
  439. clientsBulkModal.loading();
  440. await this.addClient(inbound, dbInbound);
  441. clientsBulkModal.close();
  442. },
  443. });
  444. },
  445. openEditClient(dbInboundId, client) {
  446. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  447. clients = this.getInboundClients(dbInbound);
  448. index = this.findIndexOfClient(clients, client);
  449. clientModal.show({
  450. title: '{{ i18n "pages.client.edit"}}',
  451. okText: '{{ i18n "pages.client.submitEdit"}}',
  452. dbInbound: dbInbound,
  453. index: index,
  454. confirm: async (inbound, dbInbound, index) => {
  455. clientModal.loading();
  456. await this.updateClient(inbound, dbInbound, index);
  457. clientModal.close();
  458. },
  459. isEdit: true
  460. });
  461. },
  462. findIndexOfClient(clients,client) {
  463. firstKey = Object.keys(client)[0];
  464. return clients.findIndex(c => c[firstKey] === client[firstKey]);
  465. },
  466. async addClient(inbound, dbInbound) {
  467. const data = {
  468. id: dbInbound.id,
  469. settings: inbound.settings.toString(),
  470. };
  471. await this.submit('/xui/inbound/addClient', data);
  472. },
  473. async updateClient(inbound, dbInbound, index) {
  474. const data = {
  475. id: dbInbound.id,
  476. settings: inbound.settings.toString(),
  477. };
  478. await this.submit(`/xui/inbound/updateClient/${index}`, data);
  479. },
  480. resetTraffic(dbInboundId) {
  481. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  482. this.$confirm({
  483. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  484. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  485. class: siderDrawer.isDarkTheme ? darkClass : '',
  486. okText: '{{ i18n "reset"}}',
  487. cancelText: '{{ i18n "cancel"}}',
  488. onOk: () => {
  489. const inbound = dbInbound.toInbound();
  490. dbInbound.up = 0;
  491. dbInbound.down = 0;
  492. this.updateInbound(inbound, dbInbound);
  493. },
  494. });
  495. },
  496. resetAllTraffic() {
  497. this.$confirm({
  498. title: '{{ i18n "pages.inbounds.resetAllTrafficTitle"}}',
  499. content: '{{ i18n "pages.inbounds.resetAllTrafficContent"}}',
  500. okText: '{{ i18n "pages.inbounds.resetAllTrafficOkText"}}',
  501. cancelText: '{{ i18n "pages.inbounds.resetAllTrafficCancelText"}}',
  502. onOk: async () => {
  503. for (const dbInbound of this.dbInbounds) {
  504. const inbound = dbInbound.toInbound();
  505. dbInbound.up = 0;
  506. dbInbound.down = 0;
  507. this.updateInbound(inbound, dbInbound);
  508. }
  509. },
  510. });
  511. },
  512. delInbound(dbInboundId) {
  513. this.$confirm({
  514. title: '{{ i18n "pages.inbounds.deleteInbound"}}',
  515. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  516. class: siderDrawer.isDarkTheme ? darkClass : '',
  517. okText: '{{ i18n "delete"}}',
  518. cancelText: '{{ i18n "cancel"}}',
  519. onOk: () => this.submit('/xui/inbound/del/' + dbInboundId),
  520. });
  521. },
  522. delClient(dbInboundId,client) {
  523. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  524. newDbInbound = new DBInbound(dbInbound);
  525. inbound = newDbInbound.toInbound();
  526. clients = this.getClients(dbInbound.protocol, inbound.settings);
  527. index = this.findIndexOfClient(clients, client);
  528. clients.splice(index, 1);
  529. const data = {
  530. id: dbInboundId,
  531. settings: inbound.settings.toString(),
  532. };
  533. this.$confirm({
  534. title: '{{ i18n "pages.inbounds.deleteInbound"}}',
  535. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  536. class: siderDrawer.isDarkTheme ? darkClass : '',
  537. okText: '{{ i18n "delete"}}',
  538. cancelText: '{{ i18n "cancel"}}',
  539. onOk: () => this.submit('/xui/inbound/delClient/' + client.email, data),
  540. });
  541. },
  542. getClients(protocol, clientSettings) {
  543. switch(protocol){
  544. case Protocols.VMESS: return clientSettings.vmesses;
  545. case Protocols.VLESS: return clientSettings.vlesses;
  546. case Protocols.TROJAN: return clientSettings.trojans;
  547. default: return null;
  548. }
  549. },
  550. showQrcode(dbInbound, clientIndex) {
  551. const link = dbInbound.genLink(clientIndex);
  552. qrModal.show('{{ i18n "qrCode"}}', link, dbInbound);
  553. },
  554. showInfo(dbInbound, index) {
  555. infoModal.show(dbInbound, index);
  556. },
  557. switchEnable(dbInboundId) {
  558. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  559. this.submit(`/xui/inbound/update/${dbInboundId}`, dbInbound);
  560. },
  561. async submit(url, data) {
  562. const msg = await HttpUtil.postWithModal(url, data);
  563. if (msg.success) {
  564. await this.getDBInbounds();
  565. }
  566. },
  567. getInboundClients(dbInbound) {
  568. if(dbInbound.protocol == Protocols.VLESS) {
  569. return dbInbound.toInbound().settings.vlesses
  570. } else if(dbInbound.protocol == Protocols.VMESS) {
  571. return dbInbound.toInbound().settings.vmesses
  572. } else if(dbInbound.protocol == Protocols.TROJAN) {
  573. return dbInbound.toInbound().settings.trojans
  574. }
  575. },
  576. resetClientTraffic(client,dbInboundId) {
  577. this.$confirm({
  578. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  579. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  580. class: siderDrawer.isDarkTheme ? darkClass : '',
  581. okText: '{{ i18n "reset"}}',
  582. cancelText: '{{ i18n "cancel"}}',
  583. onOk: () => this.submit('/xui/inbound/' + dbInboundId + '/resetClientTraffic/'+ client.email),
  584. })
  585. },
  586. isExpiry(dbInbound, index) {
  587. return dbInbound.toInbound().isExpiry(index)
  588. },
  589. getUpStats(dbInbound, email) {
  590. if(email.length == 0) return 0
  591. clientStats = dbInbound.clientStats.find(stats => stats.email === email)
  592. return clientStats ? clientStats.up : 0
  593. },
  594. getDownStats(dbInbound, email) {
  595. if(email.length == 0) return 0
  596. clientStats = dbInbound.clientStats.find(stats => stats.email === email)
  597. return clientStats ? clientStats.down : 0
  598. },
  599. isTrafficExhausted(dbInbound, email) {
  600. if(email.length == 0) return false
  601. clientStats = dbInbound.clientStats.find(stats => stats.email === email)
  602. return clientStats ? clientStats.down + clientStats.up > clientStats.total : false
  603. },
  604. isClientEnabled(dbInbound, email) {
  605. clientStats = dbInbound.clientStats ? dbInbound.clientStats.find(stats => stats.email === email) : null
  606. return clientStats ? clientStats['enable'] : true
  607. },
  608. isRemovable(dbInbound_id){
  609. return this.getInboundClients(this.dbInbounds.find(row => row.id === dbInbound_id)).length > 1
  610. },
  611. inboundLinks(dbInboundId) {
  612. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  613. txtModal.show('{{ i18n "pages.inbounds.export"}}',dbInbound.genInboundLinks,dbInbound.remark);
  614. },
  615. exportAllLinks() {
  616. let copyText = '';
  617. for (const dbInbound of this.dbInbounds) {
  618. copyText += dbInbound.genInboundLinks
  619. }
  620. txtModal.show('{{ i18n "pages.inbounds.export"}}',copyText,'All-Inbounds');
  621. },
  622. },
  623. watch: {
  624. searchKey: debounce(function (newVal) {
  625. this.searchInbounds(newVal);
  626. }, 500)
  627. },
  628. mounted() {
  629. this.getDBInbounds();
  630. },
  631. computed: {
  632. total() {
  633. let down = 0, up = 0;
  634. let clients = 0, active = 0, deactive = 0;
  635. this.dbInbounds.forEach(dbInbound => {
  636. down += dbInbound.down;
  637. up += dbInbound.up;
  638. inbound = dbInbound.toInbound();
  639. clients = this.getClients(dbInbound.protocol, inbound.settings);
  640. if(clients){
  641. if(dbInbound.enable){
  642. isClientEnable = false;
  643. clients.forEach(client => {
  644. isClientEnable = client.email == "" ? true: this.isClientEnabled(dbInbound,client.email);
  645. isClientEnable ? active++ : deactive++;
  646. });
  647. } else {
  648. deactive += clients.length;
  649. }
  650. } else {
  651. dbInbound.enable ? active++ : deactive++;
  652. }
  653. });
  654. return {
  655. down: down,
  656. up: up,
  657. clients: active + deactive,
  658. active: active,
  659. deactive: deactive,
  660. };
  661. }
  662. },
  663. });
  664. </script>
  665. {{template "inboundModal"}}
  666. {{template "promptModal"}}
  667. {{template "qrcodeModal"}}
  668. {{template "textModal"}}
  669. {{template "inboundInfoModal"}}
  670. {{template "clientsModal"}}
  671. {{template "clientsBulkModal"}}
  672. </body>
  673. </html>