inbounds.html 41 KB

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