inbounds.html 23 KB

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