inbounds.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  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: 40,
  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: 30,
  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: 50, scopedSlots: { customRender: 'actions' } },
  198. { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } },
  199. { title: '{{ i18n "pages.inbounds.traffic" }}', width: 100, scopedSlots: { customRender: 'traffic' } },
  200. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 80, scopedSlots: { customRender: 'expiryTime' } },
  201. { title: 'UID', width: 150, dataIndex: "id" },
  202. ];
  203. const innerTrojanColumns = [
  204. { title: '', width: 50, scopedSlots: { customRender: 'actions' } },
  205. { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } },
  206. { title: '{{ i18n "pages.inbounds.traffic" }}', width: 100, scopedSlots: { customRender: 'traffic' } },
  207. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 80, scopedSlots: { customRender: 'expiryTime' } },
  208. { title: 'Password', width: 150, dataIndex: "password" },
  209. ];
  210. const innerOneColumns = [
  211. { title: '', width: 50, 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. this.searchedInbounds.push(inbound);
  256. }
  257. });
  258. }
  259. },
  260. clickAction(action, dbInbound) {
  261. switch (action.key) {
  262. case "qrcode":
  263. this.showQrcode(dbInbound);
  264. break;
  265. case "edit":
  266. this.openEditInbound(dbInbound);
  267. break;
  268. case "resetTraffic":
  269. this.resetTraffic(dbInbound);
  270. break;
  271. case "delete":
  272. this.delInbound(dbInbound);
  273. break;
  274. }
  275. },
  276. openAddInbound() {
  277. inModal.show({
  278. title: '{{ i18n "pages.inbounds.addInbound"}}',
  279. okText: '{{ i18n "pages.inbounds.addTo"}}',
  280. cancelText: '{{ i18n "close" }}',
  281. confirm: async (inbound, dbInbound) => {
  282. inModal.loading();
  283. await this.addInbound(inbound, dbInbound);
  284. inModal.close();
  285. },
  286. isEdit: false
  287. });
  288. },
  289. openEditInbound(dbInbound) {
  290. const inbound = dbInbound.toInbound();
  291. inModal.show({
  292. title: '{{ i18n "pages.inbounds.modifyInbound"}}',
  293. okText: '{{ i18n "pages.inbounds.revise"}}',
  294. cancelText: '{{ i18n "close" }}',
  295. inbound: inbound,
  296. dbInbound: dbInbound,
  297. confirm: async (inbound, dbInbound) => {
  298. inModal.loading();
  299. await this.updateInbound(inbound, dbInbound);
  300. inModal.close();
  301. },
  302. isEdit: true
  303. });
  304. },
  305. async addInbound(inbound, dbInbound) {
  306. const data = {
  307. up: dbInbound.up,
  308. down: dbInbound.down,
  309. total: dbInbound.total,
  310. remark: dbInbound.remark,
  311. enable: dbInbound.enable,
  312. expiryTime: dbInbound.expiryTime,
  313. listen: inbound.listen,
  314. port: inbound.port,
  315. protocol: inbound.protocol,
  316. settings: inbound.settings.toString(),
  317. streamSettings: inbound.stream.toString(),
  318. sniffing: inbound.canSniffing() ? inbound.sniffing.toString() : '{}',
  319. };
  320. await this.submit('/xui/inbound/add', data, inModal);
  321. },
  322. async updateInbound(inbound, dbInbound) {
  323. const data = {
  324. up: dbInbound.up,
  325. down: dbInbound.down,
  326. total: dbInbound.total,
  327. remark: dbInbound.remark,
  328. enable: dbInbound.enable,
  329. expiryTime: dbInbound.expiryTime,
  330. listen: inbound.listen,
  331. port: inbound.port,
  332. protocol: inbound.protocol,
  333. settings: inbound.settings.toString(),
  334. streamSettings: inbound.stream.toString(),
  335. sniffing: inbound.canSniffing() ? inbound.sniffing.toString() : '{}',
  336. };
  337. await this.submit(`/xui/inbound/update/${dbInbound.id}`, data, inModal);
  338. },
  339. resetTraffic(dbInbound) {
  340. this.$confirm({
  341. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  342. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  343. okText: '{{ i18n "reset"}}',
  344. cancelText: '{{ i18n "cancel"}}',
  345. onOk: () => {
  346. const inbound = dbInbound.toInbound();
  347. dbInbound.up = 0;
  348. dbInbound.down = 0;
  349. this.updateInbound(inbound, dbInbound);
  350. },
  351. });
  352. },
  353. delInbound(dbInbound) {
  354. this.$confirm({
  355. title: '{{ i18n "pages.inbounds.deleteInbound"}}',
  356. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  357. okText: '{{ i18n "delete"}}',
  358. cancelText: '{{ i18n "cancel"}}',
  359. onOk: () => this.submit('/xui/inbound/del/' + dbInbound.id),
  360. });
  361. },
  362. showQrcode(dbInbound, clientIndex) {
  363. const link = dbInbound.genLink(clientIndex);
  364. qrModal.show('{{ i18n "qrCode"}}', link, dbInbound);
  365. },
  366. showInfo(dbInbound, index) {
  367. infoModal.show(dbInbound, index);
  368. },
  369. switchEnable(dbInbound) {
  370. this.submit(`/xui/inbound/update/${dbInbound.id}`, dbInbound);
  371. },
  372. async submit(url, data, modal) {
  373. const msg = await HttpUtil.postWithModal(url, data, modal);
  374. if (msg.success) {
  375. await this.getDBInbounds();
  376. }
  377. },
  378. getInboundClients(dbInbound) {
  379. if(dbInbound.protocol == Protocols.VLESS) {
  380. return dbInbound.toInbound().settings.vlesses
  381. } else if(dbInbound.protocol == Protocols.VMESS) {
  382. return dbInbound.toInbound().settings.vmesses
  383. } else if(dbInbound.protocol == Protocols.TROJAN) {
  384. return dbInbound.toInbound().settings.trojans
  385. }
  386. },
  387. resetClientTraffic(client,inbound,event) {
  388. this.$confirm({
  389. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  390. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  391. okText: '{{ i18n "reset"}}',
  392. cancelText: '{{ i18n "cancel"}}',
  393. onOk: () => {
  394. this.resetClTraffic(client,inbound,event);
  395. },
  396. });
  397. },
  398. async resetClTraffic(client,inbound,event) {
  399. const msg = await HttpUtil.post('/xui/inbound/resetClientTraffic/'+ client.email);
  400. if (!msg.success) {
  401. return;
  402. }
  403. clientStats = inbound.clientStats
  404. if(clientStats.length > 0)
  405. {
  406. for (const key in clientStats) {
  407. if (Object.hasOwnProperty.call(clientStats, key)) {
  408. if(clientStats[key]['email'] == client.email){
  409. clientStats[key]['up'] = 0
  410. clientStats[key]['down'] = 0
  411. }
  412. }
  413. }
  414. }
  415. },
  416. isExpiry(dbInbound, index) {
  417. return dbInbound.toInbound().isExpiry(index)
  418. },
  419. getUpStats(dbInbound, email) {
  420. clientStats = dbInbound.clientStats
  421. if(clientStats.length > 0)
  422. {
  423. for (const key in clientStats) {
  424. if (Object.hasOwnProperty.call(clientStats, key)) {
  425. if(clientStats[key]['email'] == email)
  426. return clientStats[key]['up']
  427. }
  428. }
  429. }
  430. },
  431. getDownStats(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]['down']
  439. }
  440. }
  441. }
  442. },
  443. isTrafficExhausted(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']+clientStats[key]['up'] > clientStats[key]['total']
  451. }
  452. }
  453. }
  454. },
  455. isClientEnabled(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]['enable']
  463. }
  464. }
  465. }
  466. else{
  467. return true
  468. }
  469. },
  470. },
  471. watch: {
  472. searchKey: debounce(function (newVal) {
  473. this.searchInbounds(newVal);
  474. }, 500)
  475. },
  476. mounted() {
  477. this.getDBInbounds();
  478. },
  479. computed: {
  480. total() {
  481. let down = 0, up = 0;
  482. for (let i = 0; i < this.dbInbounds.length; ++i) {
  483. down += this.dbInbounds[i].down;
  484. up += this.dbInbounds[i].up;
  485. }
  486. return {
  487. down: down,
  488. up: up,
  489. };
  490. }
  491. },
  492. });
  493. </script>
  494. {{template "inboundModal"}}
  495. {{template "promptModal"}}
  496. {{template "qrcodeModal"}}
  497. {{template "textModal"}}
  498. {{template "inboundInfoModal"}}
  499. </body>
  500. </html>