inbounds.html 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  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-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="themeSwitcher.currentTheme">
  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="themeSwitcher.darkClass">
  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="themeSwitcher.darkClass">
  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="themeSwitcher.darkClass">
  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. {{template "component/themeSwitcher" .}}
  247. <script>
  248. const columns = [{
  249. title: '{{ i18n "pages.inbounds.operate" }}',
  250. align: 'center',
  251. width: 60,
  252. scopedSlots: { customRender: 'action' },
  253. }, {
  254. title: '{{ i18n "pages.inbounds.enable" }}',
  255. align: 'center',
  256. width: 40,
  257. scopedSlots: { customRender: 'enable' },
  258. }, {
  259. title: "ID",
  260. align: 'center',
  261. dataIndex: "id",
  262. width: 40,
  263. }, {
  264. title: '{{ i18n "pages.inbounds.remark" }}',
  265. align: 'center',
  266. width: 80,
  267. dataIndex: "remark",
  268. }, {
  269. title: '{{ i18n "pages.inbounds.port" }}',
  270. align: 'center',
  271. dataIndex: "port",
  272. width: 40,
  273. }, {
  274. title: '{{ i18n "pages.inbounds.protocol" }}',
  275. align: 'left',
  276. width: 90,
  277. scopedSlots: { customRender: 'protocol' },
  278. }, {
  279. title: '{{ i18n "clients" }}',
  280. align: 'left',
  281. width: 50,
  282. scopedSlots: { customRender: 'clients' },
  283. }, {
  284. title: '{{ i18n "pages.inbounds.traffic" }}↑|↓',
  285. align: 'center',
  286. width: 120,
  287. scopedSlots: { customRender: 'traffic' },
  288. }, {
  289. title: '{{ i18n "pages.inbounds.expireDate" }}',
  290. align: 'center',
  291. width: 80,
  292. scopedSlots: { customRender: 'expiryTime' },
  293. }];
  294. const innerColumns = [
  295. { title: '{{ i18n "pages.inbounds.operate" }}', width: 70, scopedSlots: { customRender: 'actions' } },
  296. { title: '{{ i18n "pages.inbounds.enable" }}', width: 40, scopedSlots: { customRender: 'enable' } },
  297. { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } },
  298. { title: '{{ i18n "pages.inbounds.traffic" }}↑|↓', width: 120, scopedSlots: { customRender: 'traffic' } },
  299. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 70, scopedSlots: { customRender: 'expiryTime' } },
  300. { title: 'UID', width: 120, dataIndex: "id" },
  301. ];
  302. const innerTrojanColumns = [
  303. { title: '{{ i18n "pages.inbounds.operate" }}', width: 70, scopedSlots: { customRender: 'actions' } },
  304. { title: '{{ i18n "pages.inbounds.enable" }}', width: 40, scopedSlots: { customRender: 'enable' } },
  305. { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } },
  306. { title: '{{ i18n "pages.inbounds.traffic" }}↑|↓', width: 120, scopedSlots: { customRender: 'traffic' } },
  307. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 70, scopedSlots: { customRender: 'expiryTime' } },
  308. { title: 'Password', width: 170, dataIndex: "password" },
  309. ];
  310. const app = new Vue({
  311. delimiters: ['[[', ']]'],
  312. el: '#app',
  313. data: {
  314. siderDrawer,
  315. themeSwitcher,
  316. spinning: false,
  317. inbounds: [],
  318. dbInbounds: [],
  319. searchKey: '',
  320. searchedInbounds: [],
  321. expireDiff: 0,
  322. trafficDiff: 0,
  323. defaultCert: '',
  324. defaultKey: '',
  325. clientCount: {},
  326. isRefreshEnabled: localStorage.getItem("isRefreshEnabled") === "true" ? true : false,
  327. refreshing: false,
  328. refreshInterval: Number(localStorage.getItem("refreshInterval")) || 5000,
  329. },
  330. methods: {
  331. loading(spinning = true) {
  332. this.spinning = spinning;
  333. },
  334. async getDBInbounds() {
  335. this.refreshing = true;
  336. const msg = await HttpUtil.post('/panel/inbound/list');
  337. if (!msg.success) {
  338. return;
  339. }
  340. this.setInbounds(msg.obj);
  341. setTimeout(() => {
  342. this.refreshing = false;
  343. }, 500);
  344. },
  345. async getDefaultSettings() {
  346. const msg = await HttpUtil.post('/panel/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 data = {
  494. up: dbInbound.up,
  495. down: dbInbound.down,
  496. total: dbInbound.total,
  497. remark: dbInbound.remark + " - Cloned",
  498. enable: dbInbound.enable,
  499. expiryTime: dbInbound.expiryTime,
  500. listen: '',
  501. port: RandomUtil.randomIntRange(10000, 60000),
  502. protocol: baseInbound.protocol,
  503. settings: Inbound.Settings.getSettings(baseInbound.protocol).toString(),
  504. streamSettings: baseInbound.stream.toString(),
  505. sniffing: baseInbound.canSniffing() ? baseInbound.sniffing.toString() : '{}',
  506. };
  507. await this.submit('/panel/inbound/add', data, inModal);
  508. },
  509. openAddInbound() {
  510. inModal.show({
  511. title: '{{ i18n "pages.inbounds.addInbound"}}',
  512. okText: '{{ i18n "pages.inbounds.create"}}',
  513. cancelText: '{{ i18n "close" }}',
  514. confirm: async (inbound, dbInbound) => {
  515. inModal.loading();
  516. await this.addInbound(inbound, dbInbound);
  517. inModal.close();
  518. },
  519. isEdit: false
  520. });
  521. },
  522. openEditInbound(dbInboundId) {
  523. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  524. const inbound = dbInbound.toInbound();
  525. inModal.show({
  526. title: '{{ i18n "pages.inbounds.modifyInbound"}}',
  527. okText: '{{ i18n "pages.inbounds.update"}}',
  528. cancelText: '{{ i18n "close" }}',
  529. inbound: inbound,
  530. dbInbound: dbInbound,
  531. confirm: async (inbound, dbInbound) => {
  532. inModal.loading();
  533. await this.updateInbound(inbound, dbInbound);
  534. inModal.close();
  535. },
  536. isEdit: true
  537. });
  538. },
  539. async addInbound(inbound, dbInbound) {
  540. const data = {
  541. up: dbInbound.up,
  542. down: dbInbound.down,
  543. total: dbInbound.total,
  544. remark: dbInbound.remark,
  545. enable: dbInbound.enable,
  546. expiryTime: dbInbound.expiryTime,
  547. listen: inbound.listen,
  548. port: inbound.port,
  549. protocol: inbound.protocol,
  550. settings: inbound.settings.toString(),
  551. };
  552. if (inbound.canEnableStream()) data.streamSettings = inbound.stream.toString();
  553. if (inbound.canSniffing()) data.sniffing = inbound.sniffing.toString();
  554. await this.submit('/panel/inbound/add', data, inModal);
  555. },
  556. async updateInbound(inbound, dbInbound) {
  557. const data = {
  558. up: dbInbound.up,
  559. down: dbInbound.down,
  560. total: dbInbound.total,
  561. remark: dbInbound.remark,
  562. enable: dbInbound.enable,
  563. expiryTime: dbInbound.expiryTime,
  564. listen: inbound.listen,
  565. port: inbound.port,
  566. protocol: inbound.protocol,
  567. settings: inbound.settings.toString(),
  568. };
  569. if (inbound.canEnableStream()) data.streamSettings = inbound.stream.toString();
  570. if (inbound.canSniffing()) data.sniffing = inbound.sniffing.toString();
  571. await this.submit(`/panel/inbound/update/${dbInbound.id}`, data, inModal);
  572. },
  573. openAddClient(dbInboundId) {
  574. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  575. clientModal.show({
  576. title: '{{ i18n "pages.client.add"}}',
  577. okText: '{{ i18n "pages.client.submitAdd"}}',
  578. dbInbound: dbInbound,
  579. confirm: async (clients, dbInboundId) => {
  580. clientModal.loading();
  581. await this.addClient(clients, dbInboundId);
  582. clientModal.close();
  583. },
  584. isEdit: false
  585. });
  586. },
  587. openAddBulkClient(dbInboundId) {
  588. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  589. clientsBulkModal.show({
  590. title: '{{ i18n "pages.client.bulk"}} ' + dbInbound.remark,
  591. okText: '{{ i18n "pages.client.bulk"}}',
  592. dbInbound: dbInbound,
  593. confirm: async (clients, dbInboundId) => {
  594. clientsBulkModal.loading();
  595. await this.addClient(clients, dbInboundId);
  596. clientsBulkModal.close();
  597. },
  598. });
  599. },
  600. openEditClient(dbInboundId, client) {
  601. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  602. clients = this.getInboundClients(dbInbound);
  603. index = this.findIndexOfClient(clients, client);
  604. clientModal.show({
  605. title: '{{ i18n "pages.client.edit"}}',
  606. okText: '{{ i18n "pages.client.submitEdit"}}',
  607. dbInbound: dbInbound,
  608. index: index,
  609. confirm: async (client, dbInboundId, clientId) => {
  610. clientModal.loading();
  611. await this.updateClient(client, dbInboundId, clientId);
  612. clientModal.close();
  613. },
  614. isEdit: true
  615. });
  616. },
  617. findIndexOfClient(clients, client) {
  618. firstKey = Object.keys(client)[0];
  619. return clients.findIndex(c => c[firstKey] === client[firstKey]);
  620. },
  621. async addClient(clients, dbInboundId) {
  622. const data = {
  623. id: dbInboundId,
  624. settings: '{"clients": [' + clients.toString() + ']}',
  625. };
  626. await this.submit(`/panel/inbound/addClient`, data);
  627. },
  628. async updateClient(client, dbInboundId, clientId) {
  629. const data = {
  630. id: dbInboundId,
  631. settings: '{"clients": [' + client.toString() + ']}',
  632. };
  633. await this.submit(`/panel/inbound/updateClient/${clientId}`, data);
  634. },
  635. resetTraffic(dbInboundId) {
  636. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  637. this.$confirm({
  638. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  639. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  640. class: themeSwitcher.darkCardClass,
  641. okText: '{{ i18n "reset"}}',
  642. cancelText: '{{ i18n "cancel"}}',
  643. onOk: () => {
  644. const inbound = dbInbound.toInbound();
  645. dbInbound.up = 0;
  646. dbInbound.down = 0;
  647. this.updateInbound(inbound, dbInbound);
  648. },
  649. });
  650. },
  651. delInbound(dbInboundId) {
  652. this.$confirm({
  653. title: '{{ i18n "pages.inbounds.deleteInbound"}}',
  654. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  655. class: themeSwitcher.darkCardClass,
  656. okText: '{{ i18n "delete"}}',
  657. cancelText: '{{ i18n "cancel"}}',
  658. onOk: () => this.submit('/panel/inbound/del/' + dbInboundId),
  659. });
  660. },
  661. delClient(dbInboundId, client) {
  662. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  663. clientId = this.getClientId(dbInbound.protocol, client);
  664. this.$confirm({
  665. title: '{{ i18n "pages.inbounds.deleteInbound"}}',
  666. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  667. class: themeSwitcher.darkCardClass,
  668. okText: '{{ i18n "delete"}}',
  669. cancelText: '{{ i18n "cancel"}}',
  670. onOk: () => this.submit(`/panel/inbound/${dbInboundId}/delClient/${clientId}`),
  671. });
  672. },
  673. getClients(protocol, clientSettings) {
  674. switch (protocol) {
  675. case Protocols.VMESS: return clientSettings.vmesses;
  676. case Protocols.VLESS: return clientSettings.vlesses;
  677. case Protocols.TROJAN: return clientSettings.trojans;
  678. case Protocols.SHADOWSOCKS: return clientSettings.shadowsockses;
  679. default: return null;
  680. }
  681. },
  682. getClientId(protocol, client) {
  683. switch (protocol) {
  684. case Protocols.TROJAN: return client.password;
  685. case Protocols.SHADOWSOCKS: return client.email;
  686. default: return client.id;
  687. }
  688. },
  689. showQrcode(dbInbound, clientIndex) {
  690. const clientName = JSON.parse(dbInbound.settings).clients[clientIndex].email;
  691. const link = dbInbound.genLink(clientIndex);
  692. qrModal.show('{{ i18n "qrCode"}}', link, dbInbound, '', clientName);
  693. },
  694. showInfo(dbInbound, index) {
  695. infoModal.show(dbInbound, index);
  696. },
  697. switchEnable(dbInboundId) {
  698. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  699. this.submit(`/panel/inbound/update/${dbInboundId}`, dbInbound);
  700. },
  701. async switchEnableClient(dbInboundId, client) {
  702. this.loading()
  703. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  704. inbound = dbInbound.toInbound();
  705. clients = this.getClients(dbInbound.protocol, inbound.settings);
  706. index = this.findIndexOfClient(clients, client);
  707. clients[index].enable = !clients[index].enable;
  708. clientId = this.getClientId(dbInbound.protocol, clients[index]);
  709. await this.updateClient(clients[index], dbInboundId, clientId);
  710. this.loading(false);
  711. },
  712. async submit(url, data) {
  713. const msg = await HttpUtil.postWithModal(url, data);
  714. if (msg.success) {
  715. await this.getDBInbounds();
  716. }
  717. },
  718. getInboundClients(dbInbound) {
  719. if (dbInbound.protocol == Protocols.VLESS) {
  720. return dbInbound.toInbound().settings.vlesses;
  721. } else if (dbInbound.protocol == Protocols.VMESS) {
  722. return dbInbound.toInbound().settings.vmesses;
  723. } else if (dbInbound.protocol == Protocols.TROJAN) {
  724. return dbInbound.toInbound().settings.trojans;
  725. } else if (dbInbound.protocol == Protocols.SHADOWSOCKS) {
  726. return dbInbound.toInbound().settings.shadowsockses;
  727. }
  728. },
  729. resetClientTraffic(client, dbInboundId) {
  730. this.$confirm({
  731. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  732. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  733. class: themeSwitcher.darkCardClass,
  734. okText: '{{ i18n "reset"}}',
  735. cancelText: '{{ i18n "cancel"}}',
  736. onOk: () => this.submit('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + client.email),
  737. })
  738. },
  739. resetAllTraffic() {
  740. this.$confirm({
  741. title: '{{ i18n "pages.inbounds.resetAllTrafficTitle"}}',
  742. content: '{{ i18n "pages.inbounds.resetAllTrafficContent"}}',
  743. class: themeSwitcher.darkCardClass,
  744. okText: '{{ i18n "reset"}}',
  745. cancelText: '{{ i18n "cancel"}}',
  746. onOk: () => this.submit('/panel/inbound/resetAllTraffics'),
  747. });
  748. },
  749. resetAllClientTraffics(dbInboundId) {
  750. this.$confirm({
  751. title: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficTitle"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficTitle"}}',
  752. content: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficContent"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficContent"}}',
  753. class: themeSwitcher.darkCardClass,
  754. okText: '{{ i18n "reset"}}',
  755. cancelText: '{{ i18n "cancel"}}',
  756. onOk: () => this.submit('/panel/inbound/resetAllClientTraffics/' + dbInboundId),
  757. })
  758. },
  759. delDepletedClients(dbInboundId) {
  760. this.$confirm({
  761. title: '{{ i18n "pages.inbounds.delDepletedClientsTitle"}}',
  762. content: '{{ i18n "pages.inbounds.delDepletedClientsContent"}}',
  763. class: themeSwitcher.darkCardClass,
  764. okText: '{{ i18n "reset"}}',
  765. cancelText: '{{ i18n "cancel"}}',
  766. onOk: () => this.submit('/panel/inbound/delDepletedClients/' + dbInboundId),
  767. })
  768. },
  769. isExpiry(dbInbound, index) {
  770. return dbInbound.toInbound().isExpiry(index)
  771. },
  772. getUpStats(dbInbound, email) {
  773. if (email.length == 0) return 0
  774. clientStats = dbInbound.clientStats.find(stats => stats.email === email)
  775. return clientStats ? clientStats.up : 0
  776. },
  777. getDownStats(dbInbound, email) {
  778. if (email.length == 0) return 0
  779. clientStats = dbInbound.clientStats.find(stats => stats.email === email)
  780. return clientStats ? clientStats.down : 0
  781. },
  782. isTrafficExhausted(dbInbound, email) {
  783. if (email.length == 0) return false
  784. clientStats = dbInbound.clientStats.find(stats => stats.email === email)
  785. return clientStats ? clientStats.down + clientStats.up > clientStats.total : false
  786. },
  787. isClientEnabled(dbInbound, email) {
  788. clientStats = dbInbound.clientStats ? dbInbound.clientStats.find(stats => stats.email === email) : null
  789. return clientStats ? clientStats['enable'] : true
  790. },
  791. isRemovable(dbInbound_id) {
  792. return this.getInboundClients(this.dbInbounds.find(row => row.id === dbInbound_id)).length > 1
  793. },
  794. inboundLinks(dbInboundId) {
  795. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  796. txtModal.show('{{ i18n "pages.inbounds.export"}}', dbInbound.genInboundLinks, dbInbound.remark);
  797. },
  798. exportAllLinks() {
  799. let copyText = '';
  800. for (const dbInbound of this.dbInbounds) {
  801. copyText += dbInbound.genInboundLinks
  802. }
  803. txtModal.show('{{ i18n "pages.inbounds.export"}}', copyText, 'All-Inbounds');
  804. },
  805. async startDataRefreshLoop() {
  806. while (this.isRefreshEnabled) {
  807. try {
  808. await this.getDBInbounds();
  809. } catch (e) {
  810. console.error(e);
  811. }
  812. await PromiseUtil.sleep(this.refreshInterval);
  813. }
  814. },
  815. toggleRefresh() {
  816. localStorage.setItem("isRefreshEnabled", this.isRefreshEnabled);
  817. if (this.isRefreshEnabled) {
  818. this.startDataRefreshLoop();
  819. }
  820. },
  821. changeRefreshInterval() {
  822. localStorage.setItem("refreshInterval", this.refreshInterval);
  823. },
  824. async manualRefresh() {
  825. if (!this.refreshing) {
  826. this.spinning = true;
  827. await this.getDBInbounds();
  828. this.spinning = false;
  829. }
  830. },
  831. },
  832. watch: {
  833. searchKey: debounce(function (newVal) {
  834. this.searchInbounds(newVal);
  835. }, 500)
  836. },
  837. mounted() {
  838. this.loading();
  839. this.getDefaultSettings();
  840. if (this.isRefreshEnabled) {
  841. this.startDataRefreshLoop();
  842. }
  843. else {
  844. this.getDBInbounds();
  845. }
  846. this.loading(false);
  847. },
  848. computed: {
  849. total() {
  850. let down = 0, up = 0;
  851. let clients = 0, deactive = [], depleted = [], expiring = [];
  852. this.dbInbounds.forEach(dbInbound => {
  853. down += dbInbound.down;
  854. up += dbInbound.up;
  855. if (this.clientCount[dbInbound.id]) {
  856. clients += this.clientCount[dbInbound.id].clients;
  857. deactive = deactive.concat(this.clientCount[dbInbound.id].deactive);
  858. depleted = depleted.concat(this.clientCount[dbInbound.id].depleted);
  859. expiring = expiring.concat(this.clientCount[dbInbound.id].expiring);
  860. }
  861. });
  862. return {
  863. down: down,
  864. up: up,
  865. clients: clients,
  866. deactive: deactive,
  867. depleted: depleted,
  868. expiring: expiring,
  869. };
  870. }
  871. },
  872. });
  873. </script>
  874. {{template "inboundModal"}}
  875. {{template "promptModal"}}
  876. {{template "qrcodeModal"}}
  877. {{template "textModal"}}
  878. {{template "inboundInfoModal"}}
  879. {{template "clientsModal"}}
  880. {{template "clientsBulkModal"}}
  881. </body>
  882. </html>