inbounds.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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="searchKey" placeholder="search" autofocus style="max-width: 300px"></a-input>-->
  49. <a-table :columns="columns" :row-key="dbInbound => dbInbound.id"
  50. :data-source="dbInbounds"
  51. :loading="spinning" :scroll="{ x: 1500 }"
  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.hasLink()" 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="settings" slot-scope="text, dbInbound">
  91. <a-button type="link" @click="showInfo(dbInbound)">{{ i18n "check" }}</a-button>
  92. </template>
  93. <template slot="stream" slot-scope="text, dbInbound, index">
  94. <template v-if="dbInbound.isVMess || dbInbound.isVLess || dbInbound.isTrojan || dbInbound.isSS">
  95. <a-tag color="green">[[ inbounds[index].stream.network ]]</a-tag>
  96. <a-tag v-if="inbounds[index].stream.isTls" color="blue">tls</a-tag>
  97. <a-tag v-if="inbounds[index].stream.isXTls" color="blue">xtls</a-tag>
  98. </template>
  99. <template v-else>{{ i18n "none" }}</template>
  100. </template>
  101. <template slot="enable" slot-scope="text, dbInbound">
  102. <a-switch v-model="dbInbound.enable" @change="switchEnable(dbInbound)"></a-switch>
  103. </template>
  104. <template slot="expiryTime" slot-scope="text, dbInbound">
  105. <template v-if="dbInbound.expiryTime > 0">
  106. <a-tag v-if="dbInbound.isExpiry" color="red">
  107. [[ DateUtil.formatMillis(dbInbound.expiryTime) ]]
  108. </a-tag>
  109. <a-tag v-else color="blue">
  110. [[ DateUtil.formatMillis(dbInbound.expiryTime) ]]
  111. </a-tag>
  112. </template>
  113. <a-tag v-else color="green">{{ i18n "indefinite" }}</a-tag>
  114. </template>
  115. <template slot="expandedRowRender" slot-scope="record">
  116. <a-table
  117. v-if="(record.protocol === Protocols.VLESS) || (record.protocol === Protocols.VMESS) || (record.protocol === Protocols.TROJAN)"
  118. :row-key="client => client.id"
  119. :columns="innerColumns"
  120. :data-source="getInboundClients(record)"
  121. :pagination="false"
  122. >
  123. {{template "form/client_row"}}
  124. </a-table>
  125. </template>
  126. </a-table>
  127. </a-card>
  128. </transition>
  129. </a-spin>
  130. </a-layout-content>
  131. </a-layout>
  132. </a-layout>
  133. {{template "js" .}}
  134. <script>
  135. const columns = [{
  136. title: '{{ i18n "pages.inbounds.operate" }}',
  137. align: 'center',
  138. width: 40,
  139. scopedSlots: { customRender: 'action' },
  140. }, {
  141. title: '{{ i18n "pages.inbounds.enable" }}',
  142. align: 'center',
  143. width: 40,
  144. scopedSlots: { customRender: 'enable' },
  145. }, {
  146. title: "Id",
  147. align: 'center',
  148. dataIndex: "id",
  149. width: 30,
  150. }, {
  151. title: '{{ i18n "pages.inbounds.remark" }}',
  152. align: 'center',
  153. width: 100,
  154. dataIndex: "remark",
  155. }, {
  156. title: '{{ i18n "pages.inbounds.protocol" }}',
  157. align: 'center',
  158. width: 60,
  159. scopedSlots: { customRender: 'protocol' },
  160. }, {
  161. title: '{{ i18n "pages.inbounds.port" }}',
  162. align: 'center',
  163. dataIndex: "port",
  164. width: 60,
  165. }, {
  166. title: '{{ i18n "pages.inbounds.traffic" }}↑|↓',
  167. align: 'center',
  168. width: 150,
  169. scopedSlots: { customRender: 'traffic' },
  170. }, {
  171. title: '{{ i18n "pages.inbounds.details" }}',
  172. align: 'center',
  173. width: 40,
  174. scopedSlots: { customRender: 'settings' },
  175. }, {
  176. title: '{{ i18n "pages.inbounds.transportConfig" }}',
  177. align: 'center',
  178. width: 60,
  179. scopedSlots: { customRender: 'stream' },
  180. }, {
  181. title: '{{ i18n "pages.inbounds.expireDate" }}',
  182. align: 'center',
  183. width: 80,
  184. scopedSlots: { customRender: 'expiryTime' },
  185. }];
  186. const innerColumns = [
  187. { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } },
  188. { title: '{{ i18n "pages.inbounds.traffic" }}', width: 100, scopedSlots: { customRender: 'traffic' } },
  189. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 80, scopedSlots: { customRender: 'expiryTime' } },
  190. { title: '{{ i18n "pages.inbounds.uid" }}', width: 150, dataIndex: "id" },
  191. ];
  192. const app = new Vue({
  193. delimiters: ['[[', ']]'],
  194. el: '#app',
  195. data: {
  196. siderDrawer,
  197. spinning: false,
  198. inbounds: [],
  199. dbInbounds: [],
  200. searchKey: '',
  201. },
  202. methods: {
  203. loading(spinning=true) {
  204. this.spinning = spinning;
  205. },
  206. async getDBInbounds() {
  207. this.loading();
  208. const msg = await HttpUtil.post('/xui/inbound/list');
  209. this.loading(false);
  210. if (!msg.success) {
  211. return;
  212. }
  213. this.setInbounds(msg.obj);
  214. },
  215. setInbounds(dbInbounds) {
  216. this.inbounds.splice(0);
  217. this.dbInbounds.splice(0);
  218. for (const inbound of dbInbounds) {
  219. const dbInbound = new DBInbound(inbound);
  220. this.inbounds.push(dbInbound.toInbound());
  221. this.dbInbounds.push(dbInbound);
  222. }
  223. },
  224. searchInbounds(key) {
  225. if (ObjectUtil.isEmpty(key)) {
  226. this.searchedInbounds = this.dbInbounds.slice();
  227. } else {
  228. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  229. this.dbInbounds.forEach(inbound => {
  230. if (ObjectUtil.deepSearch(inbound, key)) {
  231. this.searchedInbounds.push(inbound);
  232. }
  233. });
  234. }
  235. },
  236. clickAction(action, dbInbound) {
  237. switch (action.key) {
  238. case "qrcode":
  239. this.showQrcode(dbInbound);
  240. break;
  241. case "edit":
  242. this.openEditInbound(dbInbound);
  243. break;
  244. case "resetTraffic":
  245. this.resetTraffic(dbInbound);
  246. break;
  247. case "delete":
  248. this.delInbound(dbInbound);
  249. break;
  250. }
  251. },
  252. openAddInbound() {
  253. inModal.show({
  254. title: '{{ i18n "pages.inbounds.addInbound"}}',
  255. okText: '{{ i18n "pages.inbounds.addTo"}}',
  256. cancelText: '{{ i18n "close" }}',
  257. confirm: async (inbound, dbInbound) => {
  258. inModal.loading();
  259. await this.addInbound(inbound, dbInbound);
  260. inModal.close();
  261. },
  262. isEdit: false
  263. });
  264. },
  265. openEditInbound(dbInbound) {
  266. const inbound = dbInbound.toInbound();
  267. inModal.show({
  268. title: '{{ i18n "pages.inbounds.modifyInbound"}}',
  269. okText: '{{ i18n "pages.inbounds.revise"}}',
  270. cancelText: '{{ i18n "close" }}',
  271. inbound: inbound,
  272. dbInbound: dbInbound,
  273. confirm: async (inbound, dbInbound) => {
  274. inModal.loading();
  275. await this.updateInbound(inbound, dbInbound);
  276. inModal.close();
  277. },
  278. isEdit: true
  279. });
  280. },
  281. async addInbound(inbound, dbInbound) {
  282. const data = {
  283. up: dbInbound.up,
  284. down: dbInbound.down,
  285. total: dbInbound.total,
  286. remark: dbInbound.remark,
  287. enable: dbInbound.enable,
  288. expiryTime: dbInbound.expiryTime,
  289. listen: inbound.listen,
  290. port: inbound.port,
  291. protocol: inbound.protocol,
  292. settings: inbound.settings.toString(),
  293. streamSettings: inbound.stream.toString(),
  294. sniffing: inbound.canSniffing() ? inbound.sniffing.toString() : '{}',
  295. };
  296. await this.submit('/xui/inbound/add', data, inModal);
  297. },
  298. async updateInbound(inbound, dbInbound) {
  299. const data = {
  300. up: dbInbound.up,
  301. down: dbInbound.down,
  302. total: dbInbound.total,
  303. remark: dbInbound.remark,
  304. enable: dbInbound.enable,
  305. expiryTime: dbInbound.expiryTime,
  306. listen: inbound.listen,
  307. port: inbound.port,
  308. protocol: inbound.protocol,
  309. settings: inbound.settings.toString(),
  310. streamSettings: inbound.stream.toString(),
  311. sniffing: inbound.canSniffing() ? inbound.sniffing.toString() : '{}',
  312. };
  313. await this.submit(`/xui/inbound/update/${dbInbound.id}`, data, inModal);
  314. },
  315. resetTraffic(dbInbound) {
  316. this.$confirm({
  317. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  318. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  319. okText: '{{ i18n "reset"}}',
  320. cancelText: '{{ i18n "cancel"}}',
  321. onOk: () => {
  322. const inbound = dbInbound.toInbound();
  323. dbInbound.up = 0;
  324. dbInbound.down = 0;
  325. this.updateInbound(inbound, dbInbound);
  326. },
  327. });
  328. },
  329. delInbound(dbInbound) {
  330. this.$confirm({
  331. title: '{{ i18n "pages.inbounds.deleteInbound"}}',
  332. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  333. okText: '{{ i18n "delete"}}',
  334. cancelText: '{{ i18n "cancel"}}',
  335. onOk: () => this.submit('/xui/inbound/del/' + dbInbound.id),
  336. });
  337. },
  338. showQrcode(dbInbound) {
  339. const link = dbInbound.genLink();
  340. qrModal.show('{{ i18n "qrCode"}}', link, dbInbound);
  341. },
  342. showInfo(dbInbound) {
  343. infoModal.show(dbInbound);
  344. },
  345. switchEnable(dbInbound) {
  346. this.submit(`/xui/inbound/update/${dbInbound.id}`, dbInbound);
  347. },
  348. async submit(url, data, modal) {
  349. const msg = await HttpUtil.postWithModal(url, data, modal);
  350. if (msg.success) {
  351. await this.getDBInbounds();
  352. }
  353. },
  354. getInboundClients(dbInbound) {
  355. if(dbInbound.protocol == Protocols.VLESS) {
  356. return dbInbound.toInbound().settings.vlesses
  357. } else if(dbInbound.protocol == Protocols.VMESS) {
  358. return dbInbound.toInbound().settings.vmesses
  359. } else if(dbInbound.protocol == Protocols.TROJAN) {
  360. return dbInbound.toInbound().settings.trojans
  361. }
  362. },
  363. isExpiry(dbInbound, index) {
  364. return dbInbound.toInbound().isExpiry(index)
  365. },
  366. getUpStats(dbInbound, email) {
  367. clientStats = dbInbound.clientStats
  368. if(clientStats.length > 0)
  369. {
  370. for (const key in clientStats) {
  371. if (Object.hasOwnProperty.call(clientStats, key)) {
  372. if(clientStats[key]['email'] == email)
  373. return clientStats[key]['up']
  374. }
  375. }
  376. }
  377. },
  378. getDownStats(dbInbound, email) {
  379. clientStats = dbInbound.clientStats
  380. if(clientStats.length > 0)
  381. {
  382. for (const key in clientStats) {
  383. if (Object.hasOwnProperty.call(clientStats, key)) {
  384. if(clientStats[key]['email'] == email)
  385. return clientStats[key]['down']
  386. }
  387. }
  388. }
  389. },
  390. isTrafficExhausted(dbInbound, email) {
  391. clientStats = dbInbound.clientStats
  392. if(clientStats.length > 0)
  393. {
  394. for (const key in clientStats) {
  395. if (Object.hasOwnProperty.call(clientStats, key)) {
  396. if(clientStats[key]['email'] == email)
  397. return clientStats[key]['down']+clientStats[key]['up'] > clientStats[key]['total']
  398. }
  399. }
  400. }
  401. },
  402. isClientEnabled(dbInbound, email) {
  403. clientStats = dbInbound.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'] == email)
  409. return clientStats[key]['enable']
  410. }
  411. }
  412. }
  413. },
  414. },
  415. watch: {
  416. searchKey(value) {
  417. this.searchInbounds(value);
  418. }
  419. },
  420. mounted() {
  421. this.getDBInbounds();
  422. },
  423. computed: {
  424. total() {
  425. let down = 0, up = 0;
  426. for (let i = 0; i < this.dbInbounds.length; ++i) {
  427. down += this.dbInbounds[i].down;
  428. up += this.dbInbounds[i].up;
  429. }
  430. return {
  431. down: down,
  432. up: up,
  433. };
  434. }
  435. },
  436. });
  437. </script>
  438. {{template "inboundModal"}}
  439. {{template "promptModal"}}
  440. {{template "qrcodeModal"}}
  441. {{template "textModal"}}
  442. {{template "inboundInfoModal"}}
  443. </body>
  444. </html>