inbounds.html 45 KB

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