inbounds.html 40 KB

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