inbounds.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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: '{{ i18n "pages.inbounds.remark" }}',
  162. align: 'center',
  163. width: 60,
  164. dataIndex: "remark",
  165. }, {
  166. title: '{{ i18n "pages.inbounds.protocol" }}',
  167. align: 'center',
  168. width: 40,
  169. scopedSlots: { customRender: 'protocol' },
  170. }, {
  171. title: '{{ i18n "pages.inbounds.port" }}',
  172. align: 'center',
  173. dataIndex: "port",
  174. width: 40,
  175. }, {
  176. title: '{{ i18n "pages.inbounds.traffic" }}↑|↓',
  177. align: 'center',
  178. width: 150,
  179. scopedSlots: { customRender: 'traffic' },
  180. },{
  181. title: '{{ i18n "pages.inbounds.transportConfig" }}',
  182. align: 'center',
  183. width: 60,
  184. scopedSlots: { customRender: 'stream' },
  185. }, {
  186. title: '{{ i18n "pages.inbounds.expireDate" }}',
  187. align: 'center',
  188. width: 80,
  189. scopedSlots: { customRender: 'expiryTime' },
  190. }];
  191. const innerColumns = [
  192. { title: '', width: 20, scopedSlots: { customRender: 'actions' } },
  193. { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } },
  194. { title: '{{ i18n "pages.inbounds.traffic" }}↑|↓', width: 80, scopedSlots: { customRender: 'traffic' } },
  195. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 70, scopedSlots: { customRender: 'expiryTime' } },
  196. { title: 'UID', width: 150, dataIndex: "id" },
  197. ];
  198. const innerTrojanColumns = [
  199. { title: '', width: 20, scopedSlots: { customRender: 'actions' } },
  200. { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } },
  201. { title: '{{ i18n "pages.inbounds.traffic" }}↑|↓', width: 80, scopedSlots: { customRender: 'traffic' } },
  202. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 70, scopedSlots: { customRender: 'expiryTime' } },
  203. { title: 'Password', width: 150, dataIndex: "password" },
  204. ];
  205. const innerOneColumns = [
  206. { title: '', width: 50, scopedSlots: { customRender: 'actions' } },
  207. ];
  208. const app = new Vue({
  209. delimiters: ['[[', ']]'],
  210. el: '#app',
  211. data: {
  212. siderDrawer,
  213. spinning: false,
  214. inbounds: [],
  215. dbInbounds: [],
  216. searchKey: '',
  217. searchedInbounds: [],
  218. },
  219. methods: {
  220. loading(spinning=true) {
  221. this.spinning = spinning;
  222. },
  223. async getDBInbounds() {
  224. this.loading();
  225. const msg = await HttpUtil.post('/xui/inbound/list');
  226. this.loading(false);
  227. if (!msg.success) {
  228. return;
  229. }
  230. this.setInbounds(msg.obj);
  231. },
  232. setInbounds(dbInbounds) {
  233. this.inbounds.splice(0);
  234. this.dbInbounds.splice(0);
  235. this.searchedInbounds.splice(0);
  236. for (const inbound of dbInbounds) {
  237. const dbInbound = new DBInbound(inbound);
  238. this.inbounds.push(dbInbound.toInbound());
  239. this.dbInbounds.push(dbInbound);
  240. this.searchedInbounds.push(dbInbound);
  241. }
  242. },
  243. searchInbounds(key) {
  244. if (ObjectUtil.isEmpty(key)) {
  245. this.searchedInbounds = this.dbInbounds.slice();
  246. } else {
  247. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  248. this.dbInbounds.forEach(inbound => {
  249. if (ObjectUtil.deepSearch(inbound, key)) {
  250. const newInbound = new DBInbound(inbound);
  251. const inboundSettings = JSON.parse(inbound.settings);
  252. if (inboundSettings.hasOwnProperty('clients')){
  253. const searchedSettings = { "clients": [] };
  254. inboundSettings.clients.forEach(client => {
  255. if (ObjectUtil.deepSearch(client, key)){
  256. searchedSettings.clients.push(client);
  257. }
  258. });
  259. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, searchedSettings);
  260. }
  261. this.searchedInbounds.push(newInbound);
  262. }
  263. });
  264. }
  265. },
  266. clickAction(action, dbInbound) {
  267. switch (action.key) {
  268. case "qrcode":
  269. this.showQrcode(dbInbound);
  270. break;
  271. case "edit":
  272. this.openEditInbound(dbInbound);
  273. break;
  274. case "resetTraffic":
  275. this.resetTraffic(dbInbound);
  276. break;
  277. case "delete":
  278. this.delInbound(dbInbound);
  279. break;
  280. }
  281. },
  282. openAddInbound() {
  283. inModal.show({
  284. title: '{{ i18n "pages.inbounds.addInbound"}}',
  285. okText: '{{ i18n "pages.inbounds.addTo"}}',
  286. cancelText: '{{ i18n "close" }}',
  287. confirm: async (inbound, dbInbound) => {
  288. inModal.loading();
  289. await this.addInbound(inbound, dbInbound);
  290. inModal.close();
  291. },
  292. isEdit: false
  293. });
  294. },
  295. openEditInbound(dbInbound) {
  296. const inbound = dbInbound.toInbound();
  297. inModal.show({
  298. title: '{{ i18n "pages.inbounds.modifyInbound"}}',
  299. okText: '{{ i18n "pages.inbounds.revise"}}',
  300. cancelText: '{{ i18n "close" }}',
  301. inbound: inbound,
  302. dbInbound: dbInbound,
  303. confirm: async (inbound, dbInbound) => {
  304. inModal.loading();
  305. await this.updateInbound(inbound, dbInbound);
  306. inModal.close();
  307. },
  308. isEdit: true
  309. });
  310. },
  311. async addInbound(inbound, dbInbound) {
  312. const data = {
  313. up: dbInbound.up,
  314. down: dbInbound.down,
  315. total: dbInbound.total,
  316. remark: dbInbound.remark,
  317. enable: dbInbound.enable,
  318. expiryTime: dbInbound.expiryTime,
  319. listen: inbound.listen,
  320. port: inbound.port,
  321. protocol: inbound.protocol,
  322. settings: inbound.settings.toString(),
  323. streamSettings: inbound.stream.toString(),
  324. sniffing: inbound.canSniffing() ? inbound.sniffing.toString() : '{}',
  325. };
  326. await this.submit('/xui/inbound/add', data, inModal);
  327. },
  328. async updateInbound(inbound, dbInbound) {
  329. const data = {
  330. up: dbInbound.up,
  331. down: dbInbound.down,
  332. total: dbInbound.total,
  333. remark: dbInbound.remark,
  334. enable: dbInbound.enable,
  335. expiryTime: dbInbound.expiryTime,
  336. listen: inbound.listen,
  337. port: inbound.port,
  338. protocol: inbound.protocol,
  339. settings: inbound.settings.toString(),
  340. streamSettings: inbound.stream.toString(),
  341. sniffing: inbound.canSniffing() ? inbound.sniffing.toString() : '{}',
  342. };
  343. await this.submit(`/xui/inbound/update/${dbInbound.id}`, data, inModal);
  344. },
  345. resetTraffic(dbInbound) {
  346. this.$confirm({
  347. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  348. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  349. okText: '{{ i18n "reset"}}',
  350. cancelText: '{{ i18n "cancel"}}',
  351. onOk: () => {
  352. const inbound = dbInbound.toInbound();
  353. dbInbound.up = 0;
  354. dbInbound.down = 0;
  355. this.updateInbound(inbound, dbInbound);
  356. },
  357. });
  358. },
  359. delInbound(dbInbound) {
  360. this.$confirm({
  361. title: '{{ i18n "pages.inbounds.deleteInbound"}}',
  362. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  363. okText: '{{ i18n "delete"}}',
  364. cancelText: '{{ i18n "cancel"}}',
  365. onOk: () => this.submit('/xui/inbound/del/' + dbInbound.id),
  366. });
  367. },
  368. showQrcode(dbInbound, clientIndex) {
  369. const link = dbInbound.genLink(clientIndex);
  370. qrModal.show('{{ i18n "qrCode"}}', link, dbInbound);
  371. },
  372. showInfo(dbInbound, index) {
  373. infoModal.show(dbInbound, index);
  374. },
  375. switchEnable(dbInbound) {
  376. this.submit(`/xui/inbound/update/${dbInbound.id}`, dbInbound);
  377. },
  378. async submit(url, data, modal) {
  379. const msg = await HttpUtil.postWithModal(url, data, modal);
  380. if (msg.success) {
  381. await this.getDBInbounds();
  382. }
  383. },
  384. getInboundClients(dbInbound) {
  385. if(dbInbound.protocol == Protocols.VLESS) {
  386. return dbInbound.toInbound().settings.vlesses
  387. } else if(dbInbound.protocol == Protocols.VMESS) {
  388. return dbInbound.toInbound().settings.vmesses
  389. } else if(dbInbound.protocol == Protocols.TROJAN) {
  390. return dbInbound.toInbound().settings.trojans
  391. }
  392. },
  393. resetClientTraffic(client,inbound,event) {
  394. this.$confirm({
  395. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  396. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  397. okText: '{{ i18n "reset"}}',
  398. cancelText: '{{ i18n "cancel"}}',
  399. onOk: () => {
  400. this.resetClTraffic(client,inbound,event);
  401. },
  402. });
  403. },
  404. async resetClTraffic(client,inbound,event) {
  405. const msg = await HttpUtil.post('/xui/inbound/resetClientTraffic/'+ client.email);
  406. if (!msg.success) {
  407. return;
  408. }
  409. clientStats = inbound.clientStats
  410. if(clientStats.length > 0)
  411. {
  412. for (const key in clientStats) {
  413. if (Object.hasOwnProperty.call(clientStats, key)) {
  414. if(clientStats[key]['email'] == client.email){
  415. clientStats[key]['up'] = 0
  416. clientStats[key]['down'] = 0
  417. }
  418. }
  419. }
  420. }
  421. },
  422. isExpiry(dbInbound, index) {
  423. return dbInbound.toInbound().isExpiry(index)
  424. },
  425. getUpStats(dbInbound, email) {
  426. clientStats = dbInbound.clientStats
  427. if(clientStats.length > 0)
  428. {
  429. for (const key in clientStats) {
  430. if (Object.hasOwnProperty.call(clientStats, key)) {
  431. if(clientStats[key]['email'] == email)
  432. return clientStats[key]['up']
  433. }
  434. }
  435. }
  436. },
  437. getDownStats(dbInbound, email) {
  438. clientStats = dbInbound.clientStats
  439. if(clientStats.length > 0)
  440. {
  441. for (const key in clientStats) {
  442. if (Object.hasOwnProperty.call(clientStats, key)) {
  443. if(clientStats[key]['email'] == email)
  444. return clientStats[key]['down']
  445. }
  446. }
  447. }
  448. },
  449. isTrafficExhausted(dbInbound, email) {
  450. clientStats = dbInbound.clientStats
  451. if(clientStats.length > 0)
  452. {
  453. for (const key in clientStats) {
  454. if (Object.hasOwnProperty.call(clientStats, key)) {
  455. if(clientStats[key]['email'] == email)
  456. return clientStats[key]['down']+clientStats[key]['up'] > clientStats[key]['total']
  457. }
  458. }
  459. }
  460. },
  461. isClientEnabled(dbInbound, email) {
  462. clientStats = dbInbound.clientStats
  463. if(clientStats.length > 0)
  464. {
  465. for (const key in clientStats) {
  466. if (Object.hasOwnProperty.call(clientStats, key)) {
  467. if(clientStats[key]['email'] == email)
  468. return clientStats[key]['enable']
  469. }
  470. }
  471. }
  472. else{
  473. return true
  474. }
  475. },
  476. },
  477. watch: {
  478. searchKey: debounce(function (newVal) {
  479. this.searchInbounds(newVal);
  480. }, 500)
  481. },
  482. mounted() {
  483. this.getDBInbounds();
  484. },
  485. computed: {
  486. total() {
  487. let down = 0, up = 0;
  488. for (let i = 0; i < this.dbInbounds.length; ++i) {
  489. down += this.dbInbounds[i].down;
  490. up += this.dbInbounds[i].up;
  491. }
  492. return {
  493. down: down,
  494. up: up,
  495. };
  496. }
  497. },
  498. });
  499. </script>
  500. {{template "inboundModal"}}
  501. {{template "promptModal"}}
  502. {{template "qrcodeModal"}}
  503. {{template "textModal"}}
  504. {{template "inboundInfoModal"}}
  505. </body>
  506. </html>