inbounds.html 45 KB

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