inbounds.html 43 KB

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