inbounds.html 48 KB

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