inbounds.html 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  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 key="edit">
  119. <a-icon type="edit"></a-icon>
  120. {{ i18n "edit" }}
  121. </a-menu-item>
  122. <template v-if="dbInbound.isTrojan || dbInbound.isVLess || dbInbound.isVMess || dbInbound.isSS">
  123. <a-menu-item key="addClient">
  124. <a-icon type="user-add"></a-icon>
  125. {{ i18n "pages.client.add"}}
  126. </a-menu-item>
  127. <a-menu-item key="addBulkClient">
  128. <a-icon type="usergroup-add"></a-icon>
  129. {{ i18n "pages.client.bulk"}}
  130. </a-menu-item>
  131. <a-menu-item key="resetClients">
  132. <a-icon type="file-done"></a-icon>
  133. {{ i18n "pages.inbounds.resetInboundClientTraffics"}}
  134. </a-menu-item>
  135. <a-menu-item key="export">
  136. <a-icon type="export"></a-icon>
  137. {{ i18n "pages.inbounds.export"}}
  138. </a-menu-item>
  139. <a-menu-item key="delDepletedClients">
  140. <a-icon type="rest"></a-icon>
  141. {{ i18n "pages.inbounds.delDepletedClients" }}
  142. </a-menu-item>
  143. </template>
  144. <template v-else>
  145. <a-menu-item key="showInfo">
  146. <a-icon type="info-circle"></a-icon>
  147. {{ i18n "info"}}
  148. </a-menu-item>
  149. </template>
  150. <a-menu-item key="resetTraffic">
  151. <a-icon type="retweet"></a-icon> {{ i18n "pages.inbounds.resetTraffic" }}
  152. </a-menu-item>
  153. <a-menu-item key="clone">
  154. <a-icon type="block"></a-icon> {{ i18n "pages.inbounds.clone"}}
  155. </a-menu-item>
  156. <a-menu-item key="delete">
  157. <span style="color: #FF4D4F">
  158. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  159. </span>
  160. </a-menu-item>
  161. </a-menu>
  162. </a-dropdown>
  163. </template>
  164. <template slot="protocol" slot-scope="text, dbInbound">
  165. <a-tag style="margin:0;" color="blue">[[ dbInbound.protocol ]]</a-tag>
  166. <template v-if="dbInbound.isVMess || dbInbound.isVLess || dbInbound.isTrojan">
  167. <a-tag style="margin:0;" color="green">[[ dbInbound.toInbound().stream.network ]]</a-tag>
  168. <a-tag style="margin:0;" v-if="dbInbound.toInbound().stream.isTls" color="cyan">TLS</a-tag>
  169. <a-tag style="margin:0;" v-if="dbInbound.toInbound().stream.isXtls" color="cyan">XTLS</a-tag>
  170. <a-tag style="margin:0;" v-if="dbInbound.toInbound().stream.isReality" color="cyan">Reality</a-tag>
  171. </template>
  172. </template>
  173. <template slot="clients" slot-scope="text, dbInbound">
  174. <template v-if="clientCount[dbInbound.id]">
  175. <a-tag style="margin:0;" color="green">[[ clientCount[dbInbound.id].clients ]]</a-tag>
  176. <a-popover title='{{ i18n "disabled" }}' :overlay-class-name="siderDrawer.isDarkTheme ? 'ant-dark' : ''">
  177. <template slot="content">
  178. <p v-for="clientEmail in clientCount[dbInbound.id].deactive">[[ clientEmail ]]</p>
  179. </template>
  180. <a-tag style="margin:0; padding: 0 2px;" v-if="clientCount[dbInbound.id].deactive.length">[[ clientCount[dbInbound.id].deactive.length ]]</a-tag>
  181. </a-popover>
  182. <a-popover title='{{ i18n "depleted" }}' :overlay-class-name="siderDrawer.isDarkTheme ? 'ant-dark' : ''">
  183. <template slot="content">
  184. <p v-for="clientEmail in clientCount[dbInbound.id].depleted">[[ clientEmail ]]</p>
  185. </template>
  186. <a-tag style="margin:0; padding: 0 2px;" color="red" v-if="clientCount[dbInbound.id].depleted.length">[[ clientCount[dbInbound.id].depleted.length ]]</a-tag>
  187. </a-popover>
  188. <a-popover title='{{ i18n "depletingSoon" }}' :overlay-class-name="siderDrawer.isDarkTheme ? 'ant-dark' : ''">
  189. <template slot="content">
  190. <p v-for="clientEmail in clientCount[dbInbound.id].expiring">[[ clientEmail ]]</p>
  191. </template>
  192. <a-tag style="margin:0; padding: 0 2px;" color="orange" v-if="clientCount[dbInbound.id].expiring.length">[[ clientCount[dbInbound.id].expiring.length ]]</a-tag>
  193. </a-popover>
  194. </template>
  195. </template>
  196. <template slot="traffic" slot-scope="text, dbInbound">
  197. <a-tag color="blue">[[ sizeFormat(dbInbound.up) ]] / [[ sizeFormat(dbInbound.down) ]]</a-tag>
  198. <template v-if="dbInbound.total > 0">
  199. <a-tag v-if="dbInbound.up + dbInbound.down < dbInbound.total" color="cyan">[[ sizeFormat(dbInbound.total) ]]</a-tag>
  200. <a-tag v-else color="red">[[ sizeFormat(dbInbound.total) ]]</a-tag>
  201. </template>
  202. <a-tag v-else color="green">{{ i18n "unlimited" }}</a-tag>
  203. </template>
  204. <template slot="enable" slot-scope="text, dbInbound">
  205. <a-switch v-model="dbInbound.enable" @change="switchEnable(dbInbound.id)"></a-switch>
  206. </template>
  207. <template slot="expiryTime" slot-scope="text, dbInbound">
  208. <template v-if="dbInbound.expiryTime > 0">
  209. <a-tag v-if="dbInbound.isExpiry" color="red">
  210. [[ DateUtil.formatMillis(dbInbound.expiryTime) ]]
  211. </a-tag>
  212. <a-tag v-else color="blue">
  213. [[ DateUtil.formatMillis(dbInbound.expiryTime) ]]
  214. </a-tag>
  215. </template>
  216. <a-tag v-else color="green">{{ i18n "indefinite" }}</a-tag>
  217. </template>
  218. <template slot="expandedRowRender" slot-scope="record">
  219. <a-table
  220. v-if="(record.protocol === Protocols.VLESS) || (record.protocol === Protocols.VMESS)"
  221. :row-key="client => client.id"
  222. :columns="innerColumns"
  223. :data-source="getInboundClients(record)"
  224. :pagination="false"
  225. >
  226. {{template "client_table"}}
  227. </a-table>
  228. <a-table
  229. v-else-if="record.protocol === Protocols.TROJAN || record.protocol === Protocols.SHADOWSOCKS"
  230. :row-key="client => client.id"
  231. :columns="innerTrojanColumns"
  232. :data-source="getInboundClients(record)"
  233. :pagination="false"
  234. >
  235. {{template "client_table"}}
  236. </a-table>
  237. </template>
  238. </a-table>
  239. </a-card>
  240. </transition>
  241. </a-spin>
  242. </a-layout-content>
  243. </a-layout>
  244. </a-layout>
  245. {{template "js" .}}
  246. <script>
  247. const columns = [{
  248. title: '{{ i18n "pages.inbounds.operate" }}',
  249. align: 'center',
  250. width: 60,
  251. scopedSlots: { customRender: 'action' },
  252. }, {
  253. title: '{{ i18n "pages.inbounds.enable" }}',
  254. align: 'center',
  255. width: 40,
  256. scopedSlots: { customRender: 'enable' },
  257. }, {
  258. title: "ID",
  259. align: 'center',
  260. dataIndex: "id",
  261. width: 40,
  262. }, {
  263. title: '{{ i18n "pages.inbounds.remark" }}',
  264. align: 'center',
  265. width: 80,
  266. dataIndex: "remark",
  267. }, {
  268. title: '{{ i18n "pages.inbounds.port" }}',
  269. align: 'center',
  270. dataIndex: "port",
  271. width: 40,
  272. }, {
  273. title: '{{ i18n "pages.inbounds.protocol" }}',
  274. align: 'left',
  275. width: 90,
  276. scopedSlots: { customRender: 'protocol' },
  277. }, {
  278. title: '{{ i18n "clients" }}',
  279. align: 'left',
  280. width: 50,
  281. scopedSlots: { customRender: 'clients' },
  282. }, {
  283. title: '{{ i18n "pages.inbounds.traffic" }}↑|↓',
  284. align: 'center',
  285. width: 120,
  286. scopedSlots: { customRender: 'traffic' },
  287. }, {
  288. title: '{{ i18n "pages.inbounds.expireDate" }}',
  289. align: 'center',
  290. width: 80,
  291. scopedSlots: { customRender: 'expiryTime' },
  292. }];
  293. const innerColumns = [
  294. { title: '{{ i18n "pages.inbounds.operate" }}', width: 70, scopedSlots: { customRender: 'actions' } },
  295. { title: '{{ i18n "pages.inbounds.enable" }}', width: 40, scopedSlots: { customRender: 'enable' } },
  296. { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } },
  297. { title: '{{ i18n "pages.inbounds.traffic" }}↑|↓', width: 120, scopedSlots: { customRender: 'traffic' } },
  298. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 70, scopedSlots: { customRender: 'expiryTime' } },
  299. { title: 'UID', width: 120, dataIndex: "id" },
  300. ];
  301. const innerTrojanColumns = [
  302. { title: '{{ i18n "pages.inbounds.operate" }}', width: 70, scopedSlots: { customRender: 'actions' } },
  303. { title: '{{ i18n "pages.inbounds.enable" }}', width: 40, scopedSlots: { customRender: 'enable' } },
  304. { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } },
  305. { title: '{{ i18n "pages.inbounds.traffic" }}↑|↓', width: 120, scopedSlots: { customRender: 'traffic' } },
  306. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 70, scopedSlots: { customRender: 'expiryTime' } },
  307. { title: 'Password', width: 170, dataIndex: "password" },
  308. ];
  309. const app = new Vue({
  310. delimiters: ['[[', ']]'],
  311. el: '#app',
  312. data: {
  313. siderDrawer,
  314. spinning: false,
  315. inbounds: [],
  316. dbInbounds: [],
  317. searchKey: '',
  318. searchedInbounds: [],
  319. expireDiff: 0,
  320. trafficDiff: 0,
  321. defaultCert: '',
  322. defaultKey: '',
  323. clientCount: {},
  324. isRefreshEnabled: localStorage.getItem("isRefreshEnabled") === "true" ? true : false,
  325. refreshing: false,
  326. refreshInterval: Number(localStorage.getItem("refreshInterval")) || 5000,
  327. },
  328. methods: {
  329. loading(spinning=true) {
  330. this.spinning = spinning;
  331. },
  332. async getDBInbounds() {
  333. this.refreshing = true;
  334. const msg = await HttpUtil.post('/xui/inbound/list');
  335. if (!msg.success) {
  336. return;
  337. }
  338. this.setInbounds(msg.obj);
  339. this.refreshing = false;
  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.create"}}',
  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.update"}}',
  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 = this.getClientId(dbInbound.protocol,client);
  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. case Protocols.SHADOWSOCKS: return clientSettings.shadowsockses;
  676. default: return null;
  677. }
  678. },
  679. getClientId(protocol, client) {
  680. switch(protocol){
  681. case Protocols.TROJAN: return client.password;
  682. case Protocols.SHADOWSOCKS: return client.email;
  683. default: return client.id;
  684. }
  685. },
  686. showQrcode(dbInbound, clientIndex) {
  687. const link = dbInbound.genLink(clientIndex);
  688. qrModal.show('{{ i18n "qrCode"}}', link, dbInbound);
  689. },
  690. showInfo(dbInbound, index) {
  691. infoModal.show(dbInbound, index);
  692. },
  693. switchEnable(dbInboundId) {
  694. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  695. this.submit(`/xui/inbound/update/${dbInboundId}`, dbInbound);
  696. },
  697. async switchEnableClient(dbInboundId, client) {
  698. this.loading()
  699. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  700. inbound = dbInbound.toInbound();
  701. clients = this.getClients(dbInbound.protocol, inbound.settings);
  702. index = this.findIndexOfClient(clients, client);
  703. clients[index].enable = !clients[index].enable;
  704. clientId = this.getClientId(dbInbound.protocol,clients[index]);
  705. await this.updateClient(clients[index],dbInboundId, clientId);
  706. this.loading(false);
  707. },
  708. async submit(url, data) {
  709. const msg = await HttpUtil.postWithModal(url, data);
  710. if (msg.success) {
  711. await this.getDBInbounds();
  712. }
  713. },
  714. getInboundClients(dbInbound) {
  715. if(dbInbound.protocol == Protocols.VLESS) {
  716. return dbInbound.toInbound().settings.vlesses;
  717. } else if(dbInbound.protocol == Protocols.VMESS) {
  718. return dbInbound.toInbound().settings.vmesses;
  719. } else if(dbInbound.protocol == Protocols.TROJAN) {
  720. return dbInbound.toInbound().settings.trojans;
  721. } else if(dbInbound.protocol == Protocols.SHADOWSOCKS) {
  722. return dbInbound.toInbound().settings.shadowsockses;
  723. }
  724. },
  725. resetClientTraffic(client,dbInboundId) {
  726. this.$confirm({
  727. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  728. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  729. class: siderDrawer.isDarkTheme ? darkClass : '',
  730. okText: '{{ i18n "reset"}}',
  731. cancelText: '{{ i18n "cancel"}}',
  732. onOk: () => this.submit('/xui/inbound/' + dbInboundId + '/resetClientTraffic/'+ client.email),
  733. })
  734. },
  735. resetAllTraffic() {
  736. this.$confirm({
  737. title: '{{ i18n "pages.inbounds.resetAllTrafficTitle"}}',
  738. content: '{{ i18n "pages.inbounds.resetAllTrafficContent"}}',
  739. class: siderDrawer.isDarkTheme ? darkClass : '',
  740. okText: '{{ i18n "reset"}}',
  741. cancelText: '{{ i18n "cancel"}}',
  742. onOk: () => this.submit('/xui/inbound/resetAllTraffics'),
  743. });
  744. },
  745. resetAllClientTraffics(dbInboundId) {
  746. this.$confirm({
  747. title: dbInboundId>0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficTitle"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficTitle"}}',
  748. content: dbInboundId>0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficContent"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficContent"}}',
  749. class: siderDrawer.isDarkTheme ? darkClass : '',
  750. okText: '{{ i18n "reset"}}',
  751. cancelText: '{{ i18n "cancel"}}',
  752. onOk: () => this.submit('/xui/inbound/resetAllClientTraffics/' + dbInboundId),
  753. })
  754. },
  755. delDepletedClients(dbInboundId) {
  756. this.$confirm({
  757. title: '{{ i18n "pages.inbounds.delDepletedClientsTitle"}}',
  758. content: '{{ i18n "pages.inbounds.delDepletedClientsContent"}}',
  759. class: siderDrawer.isDarkTheme ? darkClass : '',
  760. okText: '{{ i18n "reset"}}',
  761. cancelText: '{{ i18n "cancel"}}',
  762. onOk: () => this.submit('/xui/inbound/delDepletedClients/' + dbInboundId),
  763. })
  764. },
  765. isExpiry(dbInbound, index) {
  766. return dbInbound.toInbound().isExpiry(index)
  767. },
  768. getUpStats(dbInbound, email) {
  769. if(email.length == 0) return 0
  770. clientStats = dbInbound.clientStats.find(stats => stats.email === email)
  771. return clientStats ? clientStats.up : 0
  772. },
  773. getDownStats(dbInbound, email) {
  774. if(email.length == 0) return 0
  775. clientStats = dbInbound.clientStats.find(stats => stats.email === email)
  776. return clientStats ? clientStats.down : 0
  777. },
  778. isTrafficExhausted(dbInbound, email) {
  779. if(email.length == 0) return false
  780. clientStats = dbInbound.clientStats.find(stats => stats.email === email)
  781. return clientStats ? clientStats.down + clientStats.up > clientStats.total : false
  782. },
  783. isClientEnabled(dbInbound, email) {
  784. clientStats = dbInbound.clientStats ? dbInbound.clientStats.find(stats => stats.email === email) : null
  785. return clientStats ? clientStats['enable'] : true
  786. },
  787. isRemovable(dbInbound_id){
  788. return this.getInboundClients(this.dbInbounds.find(row => row.id === dbInbound_id)).length > 1
  789. },
  790. inboundLinks(dbInboundId) {
  791. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  792. txtModal.show('{{ i18n "pages.inbounds.export"}}',dbInbound.genInboundLinks,dbInbound.remark);
  793. },
  794. exportAllLinks() {
  795. let copyText = '';
  796. for (const dbInbound of this.dbInbounds) {
  797. copyText += dbInbound.genInboundLinks
  798. }
  799. txtModal.show('{{ i18n "pages.inbounds.export"}}',copyText,'All-Inbounds');
  800. },
  801. async startDataRefreshLoop() {
  802. while (this.isRefreshEnabled) {
  803. try {
  804. await this.getDBInbounds();
  805. } catch (e) {
  806. console.error(e);
  807. }
  808. await PromiseUtil.sleep(this.refreshInterval);
  809. }
  810. },
  811. toggleRefresh() {
  812. localStorage.setItem("isRefreshEnabled", this.isRefreshEnabled);
  813. if (this.isRefreshEnabled) {
  814. this.startDataRefreshLoop();
  815. }
  816. },
  817. changeRefreshInterval(){
  818. localStorage.setItem("refreshInterval", this.refreshInterval);
  819. },
  820. async manualRefresh(){
  821. if(!this.refreshing){
  822. this.spinning = true;
  823. await this.getDBInbounds();
  824. this.spinning = false;
  825. }
  826. },
  827. },
  828. watch: {
  829. searchKey: debounce(function (newVal) {
  830. this.searchInbounds(newVal);
  831. }, 500)
  832. },
  833. mounted() {
  834. this.loading();
  835. this.getDefaultSettings();
  836. if (this.isRefreshEnabled) {
  837. this.startDataRefreshLoop();
  838. }
  839. else {
  840. this.getDBInbounds();
  841. }
  842. this.loading(false);
  843. },
  844. computed: {
  845. total() {
  846. let down = 0, up = 0;
  847. let clients = 0, deactive = [], depleted = [], expiring = [];
  848. this.dbInbounds.forEach(dbInbound => {
  849. down += dbInbound.down;
  850. up += dbInbound.up;
  851. if (this.clientCount[dbInbound.id]) {
  852. clients += this.clientCount[dbInbound.id].clients;
  853. deactive = deactive.concat(this.clientCount[dbInbound.id].deactive);
  854. depleted = depleted.concat(this.clientCount[dbInbound.id].depleted);
  855. expiring = expiring.concat(this.clientCount[dbInbound.id].expiring);
  856. }
  857. });
  858. return {
  859. down: down,
  860. up: up,
  861. clients: clients,
  862. deactive: deactive,
  863. depleted: depleted,
  864. expiring: expiring,
  865. };
  866. }
  867. },
  868. });
  869. </script>
  870. {{template "inboundModal"}}
  871. {{template "promptModal"}}
  872. {{template "qrcodeModal"}}
  873. {{template "textModal"}}
  874. {{template "inboundInfoModal"}}
  875. {{template "clientsModal"}}
  876. {{template "clientsBulkModal"}}
  877. </body>
  878. </html>