inbounds.html 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  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. themeSwitcher,
  315. spinning: false,
  316. inbounds: [],
  317. dbInbounds: [],
  318. searchKey: '',
  319. searchedInbounds: [],
  320. expireDiff: 0,
  321. trafficDiff: 0,
  322. defaultCert: '',
  323. defaultKey: '',
  324. clientCount: {},
  325. isRefreshEnabled: localStorage.getItem("isRefreshEnabled") === "true" ? true : false,
  326. refreshing: false,
  327. refreshInterval: Number(localStorage.getItem("refreshInterval")) || 5000,
  328. },
  329. methods: {
  330. loading(spinning = true) {
  331. this.spinning = spinning;
  332. },
  333. async getDBInbounds() {
  334. this.refreshing = true;
  335. const msg = await HttpUtil.post('/panel/inbound/list');
  336. if (!msg.success) {
  337. return;
  338. }
  339. this.setInbounds(msg.obj);
  340. this.refreshing = false;
  341. },
  342. async getDefaultSettings() {
  343. const msg = await HttpUtil.post('/panel/setting/defaultSettings');
  344. if (!msg.success) {
  345. return;
  346. }
  347. this.expireDiff = msg.obj.expireDiff * 86400000;
  348. this.trafficDiff = msg.obj.trafficDiff * 1073741824;
  349. this.defaultCert = msg.obj.defaultCert;
  350. this.defaultKey = msg.obj.defaultKey;
  351. },
  352. setInbounds(dbInbounds) {
  353. this.inbounds.splice(0);
  354. this.dbInbounds.splice(0);
  355. for (const inbound of dbInbounds) {
  356. const dbInbound = new DBInbound(inbound);
  357. to_inbound = dbInbound.toInbound()
  358. this.inbounds.push(to_inbound);
  359. this.dbInbounds.push(dbInbound);
  360. if ([Protocols.VMESS, Protocols.VLESS, Protocols.TROJAN].includes(inbound.protocol)) {
  361. this.clientCount[inbound.id] = this.getClientCounts(inbound, to_inbound);
  362. }
  363. }
  364. this.searchInbounds(this.searchKey);
  365. },
  366. getClientCounts(dbInbound, inbound) {
  367. let clientCount = 0, active = [], deactive = [], depleted = [], expiring = [];
  368. clients = this.getClients(dbInbound.protocol, inbound.settings);
  369. clientStats = dbInbound.clientStats
  370. now = new Date().getTime()
  371. if (clients) {
  372. clientCount = clients.length;
  373. if (dbInbound.enable) {
  374. clients.forEach(client => {
  375. client.enable ? active.push(client.email) : deactive.push(client.email);
  376. });
  377. clientStats.forEach(client => {
  378. if (!client.enable) {
  379. depleted.push(client.email);
  380. } else {
  381. if ((client.expiryTime > 0 && (client.expiryTime - now < this.expireDiff)) ||
  382. (client.total > 0 && (client.total - (client.up + client.down) < this.trafficDiff))) expiring.push(client.email);
  383. }
  384. });
  385. } else {
  386. clients.forEach(client => {
  387. deactive.push(client.email);
  388. });
  389. }
  390. }
  391. return {
  392. clients: clientCount,
  393. active: active,
  394. deactive: deactive,
  395. depleted: depleted,
  396. expiring: expiring,
  397. };
  398. },
  399. searchInbounds(key) {
  400. if (ObjectUtil.isEmpty(key)) {
  401. this.searchedInbounds = this.dbInbounds.slice();
  402. } else {
  403. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  404. this.dbInbounds.forEach(inbound => {
  405. if (ObjectUtil.deepSearch(inbound, key)) {
  406. const newInbound = new DBInbound(inbound);
  407. const inboundSettings = JSON.parse(inbound.settings);
  408. if (inboundSettings.hasOwnProperty('clients')) {
  409. const searchedSettings = { "clients": [] };
  410. inboundSettings.clients.forEach(client => {
  411. if (ObjectUtil.deepSearch(client, key)) {
  412. searchedSettings.clients.push(client);
  413. }
  414. });
  415. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, searchedSettings);
  416. }
  417. this.searchedInbounds.push(newInbound);
  418. }
  419. });
  420. }
  421. },
  422. generalActions(action) {
  423. switch (action.key) {
  424. case "export":
  425. this.exportAllLinks();
  426. break;
  427. case "resetInbounds":
  428. this.resetAllTraffic();
  429. break;
  430. case "resetClients":
  431. this.resetAllClientTraffics(-1);
  432. break;
  433. case "delDepletedClients":
  434. this.delDepletedClients(-1)
  435. break;
  436. }
  437. },
  438. clickAction(action, dbInbound) {
  439. switch (action.key) {
  440. case "qrcode":
  441. this.showQrcode(dbInbound);
  442. break;
  443. case "showInfo":
  444. this.showInfo(dbInbound);
  445. break;
  446. case "edit":
  447. this.openEditInbound(dbInbound.id);
  448. break;
  449. case "addClient":
  450. this.openAddClient(dbInbound.id)
  451. break;
  452. case "addBulkClient":
  453. this.openAddBulkClient(dbInbound.id)
  454. break;
  455. case "export":
  456. this.inboundLinks(dbInbound.id);
  457. break;
  458. case "resetTraffic":
  459. this.resetTraffic(dbInbound.id);
  460. break;
  461. case "resetClients":
  462. this.resetAllClientTraffics(dbInbound.id);
  463. break;
  464. case "clone":
  465. this.openCloneInbound(dbInbound);
  466. break;
  467. case "delete":
  468. this.delInbound(dbInbound.id);
  469. break;
  470. case "delDepletedClients":
  471. this.delDepletedClients(dbInbound.id)
  472. break;
  473. }
  474. },
  475. openCloneInbound(dbInbound) {
  476. this.$confirm({
  477. title: '{{ i18n "pages.inbounds.cloneInbound"}} \"' + dbInbound.remark + '\"',
  478. content: '{{ i18n "pages.inbounds.cloneInboundContent"}}',
  479. okText: '{{ i18n "pages.inbounds.cloneInboundOk"}}',
  480. cancelText: '{{ i18n "cancel" }}',
  481. onOk: () => {
  482. const baseInbound = dbInbound.toInbound();
  483. dbInbound.up = 0;
  484. dbInbound.down = 0;
  485. this.cloneInbound(baseInbound, dbInbound);
  486. },
  487. });
  488. },
  489. async cloneInbound(baseInbound, dbInbound) {
  490. const inbound = new Inbound();
  491. const data = {
  492. up: dbInbound.up,
  493. down: dbInbound.down,
  494. total: dbInbound.total,
  495. remark: dbInbound.remark + " - Cloned",
  496. enable: dbInbound.enable,
  497. expiryTime: dbInbound.expiryTime,
  498. listen: inbound.listen,
  499. port: inbound.port,
  500. protocol: baseInbound.protocol,
  501. settings: inbound.settings.toString(),
  502. streamSettings: baseInbound.stream.toString(),
  503. sniffing: baseInbound.canSniffing() ? baseInbound.sniffing.toString() : '{}',
  504. };
  505. await this.submit('/panel/inbound/add', data, inModal);
  506. },
  507. openAddInbound() {
  508. inModal.show({
  509. title: '{{ i18n "pages.inbounds.addInbound"}}',
  510. okText: '{{ i18n "pages.inbounds.create"}}',
  511. cancelText: '{{ i18n "close" }}',
  512. confirm: async (inbound, dbInbound) => {
  513. inModal.loading();
  514. await this.addInbound(inbound, dbInbound);
  515. inModal.close();
  516. },
  517. isEdit: false
  518. });
  519. },
  520. openEditInbound(dbInboundId) {
  521. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  522. const inbound = dbInbound.toInbound();
  523. inModal.show({
  524. title: '{{ i18n "pages.inbounds.modifyInbound"}}',
  525. okText: '{{ i18n "pages.inbounds.update"}}',
  526. cancelText: '{{ i18n "close" }}',
  527. inbound: inbound,
  528. dbInbound: dbInbound,
  529. confirm: async (inbound, dbInbound) => {
  530. inModal.loading();
  531. await this.updateInbound(inbound, dbInbound);
  532. inModal.close();
  533. },
  534. isEdit: true
  535. });
  536. },
  537. async addInbound(inbound, dbInbound) {
  538. const data = {
  539. up: dbInbound.up,
  540. down: dbInbound.down,
  541. total: dbInbound.total,
  542. remark: dbInbound.remark,
  543. enable: dbInbound.enable,
  544. expiryTime: dbInbound.expiryTime,
  545. listen: inbound.listen,
  546. port: inbound.port,
  547. protocol: inbound.protocol,
  548. settings: inbound.settings.toString(),
  549. };
  550. if (inbound.canEnableStream()) data.streamSettings = inbound.stream.toString();
  551. if (inbound.canSniffing()) data.sniffing = inbound.sniffing.toString();
  552. await this.submit('/panel/inbound/add', data, inModal);
  553. },
  554. async updateInbound(inbound, dbInbound) {
  555. const data = {
  556. up: dbInbound.up,
  557. down: dbInbound.down,
  558. total: dbInbound.total,
  559. remark: dbInbound.remark,
  560. enable: dbInbound.enable,
  561. expiryTime: dbInbound.expiryTime,
  562. listen: inbound.listen,
  563. port: inbound.port,
  564. protocol: inbound.protocol,
  565. settings: inbound.settings.toString(),
  566. };
  567. if (inbound.canEnableStream()) data.streamSettings = inbound.stream.toString();
  568. if (inbound.canSniffing()) data.sniffing = inbound.sniffing.toString();
  569. await this.submit(`/panel/inbound/update/${dbInbound.id}`, data, inModal);
  570. },
  571. openAddClient(dbInboundId) {
  572. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  573. clientModal.show({
  574. title: '{{ i18n "pages.client.add"}}',
  575. okText: '{{ i18n "pages.client.submitAdd"}}',
  576. dbInbound: dbInbound,
  577. confirm: async (clients, dbInboundId) => {
  578. clientModal.loading();
  579. await this.addClient(clients, dbInboundId);
  580. clientModal.close();
  581. },
  582. isEdit: false
  583. });
  584. },
  585. openAddBulkClient(dbInboundId) {
  586. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  587. clientsBulkModal.show({
  588. title: '{{ i18n "pages.client.bulk"}} ' + dbInbound.remark,
  589. okText: '{{ i18n "pages.client.bulk"}}',
  590. dbInbound: dbInbound,
  591. confirm: async (clients, dbInboundId) => {
  592. clientsBulkModal.loading();
  593. await this.addClient(clients, dbInboundId);
  594. clientsBulkModal.close();
  595. },
  596. });
  597. },
  598. openEditClient(dbInboundId, client) {
  599. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  600. clients = this.getInboundClients(dbInbound);
  601. index = this.findIndexOfClient(clients, client);
  602. clientModal.show({
  603. title: '{{ i18n "pages.client.edit"}}',
  604. okText: '{{ i18n "pages.client.submitEdit"}}',
  605. dbInbound: dbInbound,
  606. index: index,
  607. confirm: async (client, dbInboundId, clientId) => {
  608. clientModal.loading();
  609. await this.updateClient(client, dbInboundId, clientId);
  610. clientModal.close();
  611. },
  612. isEdit: true
  613. });
  614. },
  615. findIndexOfClient(clients, client) {
  616. firstKey = Object.keys(client)[0];
  617. return clients.findIndex(c => c[firstKey] === client[firstKey]);
  618. },
  619. async addClient(clients, dbInboundId) {
  620. const data = {
  621. id: dbInboundId,
  622. settings: '{"clients": [' + clients.toString() + ']}',
  623. };
  624. await this.submit(`/panel/inbound/addClient`, data);
  625. },
  626. async updateClient(client, dbInboundId, clientId) {
  627. const data = {
  628. id: dbInboundId,
  629. settings: '{"clients": [' + client.toString() + ']}',
  630. };
  631. await this.submit(`/panel/inbound/updateClient/${clientId}`, data);
  632. },
  633. resetTraffic(dbInboundId) {
  634. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  635. this.$confirm({
  636. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  637. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  638. class: themeSwitcher.darkCardClass,
  639. okText: '{{ i18n "reset"}}',
  640. cancelText: '{{ i18n "cancel"}}',
  641. onOk: () => {
  642. const inbound = dbInbound.toInbound();
  643. dbInbound.up = 0;
  644. dbInbound.down = 0;
  645. this.updateInbound(inbound, dbInbound);
  646. },
  647. });
  648. },
  649. delInbound(dbInboundId) {
  650. this.$confirm({
  651. title: '{{ i18n "pages.inbounds.deleteInbound"}}',
  652. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  653. class: themeSwitcher.darkCardClass,
  654. okText: '{{ i18n "delete"}}',
  655. cancelText: '{{ i18n "cancel"}}',
  656. onOk: () => this.submit('/panel/inbound/del/' + dbInboundId),
  657. });
  658. },
  659. delClient(dbInboundId, client) {
  660. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  661. clientId = this.getClientId(dbInbound.protocol, client);
  662. this.$confirm({
  663. title: '{{ i18n "pages.inbounds.deleteInbound"}}',
  664. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  665. class: themeSwitcher.darkCardClass,
  666. okText: '{{ i18n "delete"}}',
  667. cancelText: '{{ i18n "cancel"}}',
  668. onOk: () => this.submit(`/panel/inbound/${dbInboundId}/delClient/${clientId}`),
  669. });
  670. },
  671. getClients(protocol, clientSettings) {
  672. switch (protocol) {
  673. case Protocols.VMESS: return clientSettings.vmesses;
  674. case Protocols.VLESS: return clientSettings.vlesses;
  675. case Protocols.TROJAN: return clientSettings.trojans;
  676. case Protocols.SHADOWSOCKS: return clientSettings.shadowsockses;
  677. default: return null;
  678. }
  679. },
  680. getClientId(protocol, client) {
  681. switch (protocol) {
  682. case Protocols.TROJAN: return client.password;
  683. case Protocols.SHADOWSOCKS: return client.email;
  684. default: return client.id;
  685. }
  686. },
  687. showQrcode(dbInbound, clientIndex) {
  688. const clientName = JSON.parse(dbInbound.settings).clients[clientIndex].email;
  689. const link = dbInbound.genLink(clientIndex);
  690. qrModal.show('{{ i18n "qrCode"}}', link, dbInbound, '', clientName);
  691. },
  692. showInfo(dbInbound, index) {
  693. infoModal.show(dbInbound, index);
  694. },
  695. switchEnable(dbInboundId) {
  696. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  697. this.submit(`/panel/inbound/update/${dbInboundId}`, dbInbound);
  698. },
  699. async switchEnableClient(dbInboundId, client) {
  700. this.loading()
  701. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  702. inbound = dbInbound.toInbound();
  703. clients = this.getClients(dbInbound.protocol, inbound.settings);
  704. index = this.findIndexOfClient(clients, client);
  705. clients[index].enable = !clients[index].enable;
  706. clientId = this.getClientId(dbInbound.protocol, clients[index]);
  707. await this.updateClient(clients[index], dbInboundId, clientId);
  708. this.loading(false);
  709. },
  710. async submit(url, data) {
  711. const msg = await HttpUtil.postWithModal(url, data);
  712. if (msg.success) {
  713. await this.getDBInbounds();
  714. }
  715. },
  716. getInboundClients(dbInbound) {
  717. if (dbInbound.protocol == Protocols.VLESS) {
  718. return dbInbound.toInbound().settings.vlesses;
  719. } else if (dbInbound.protocol == Protocols.VMESS) {
  720. return dbInbound.toInbound().settings.vmesses;
  721. } else if (dbInbound.protocol == Protocols.TROJAN) {
  722. return dbInbound.toInbound().settings.trojans;
  723. } else if (dbInbound.protocol == Protocols.SHADOWSOCKS) {
  724. return dbInbound.toInbound().settings.shadowsockses;
  725. }
  726. },
  727. resetClientTraffic(client, dbInboundId) {
  728. this.$confirm({
  729. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  730. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  731. class: themeSwitcher.darkCardClass,
  732. okText: '{{ i18n "reset"}}',
  733. cancelText: '{{ i18n "cancel"}}',
  734. onOk: () => this.submit('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + client.email),
  735. })
  736. },
  737. resetAllTraffic() {
  738. this.$confirm({
  739. title: '{{ i18n "pages.inbounds.resetAllTrafficTitle"}}',
  740. content: '{{ i18n "pages.inbounds.resetAllTrafficContent"}}',
  741. class: themeSwitcher.darkCardClass,
  742. okText: '{{ i18n "reset"}}',
  743. cancelText: '{{ i18n "cancel"}}',
  744. onOk: () => this.submit('/panel/inbound/resetAllTraffics'),
  745. });
  746. },
  747. resetAllClientTraffics(dbInboundId) {
  748. this.$confirm({
  749. title: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficTitle"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficTitle"}}',
  750. content: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficContent"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficContent"}}',
  751. class: themeSwitcher.darkCardClass,
  752. okText: '{{ i18n "reset"}}',
  753. cancelText: '{{ i18n "cancel"}}',
  754. onOk: () => this.submit('/panel/inbound/resetAllClientTraffics/' + dbInboundId),
  755. })
  756. },
  757. delDepletedClients(dbInboundId) {
  758. this.$confirm({
  759. title: '{{ i18n "pages.inbounds.delDepletedClientsTitle"}}',
  760. content: '{{ i18n "pages.inbounds.delDepletedClientsContent"}}',
  761. class: themeSwitcher.darkCardClass,
  762. okText: '{{ i18n "reset"}}',
  763. cancelText: '{{ i18n "cancel"}}',
  764. onOk: () => this.submit('/panel/inbound/delDepletedClients/' + dbInboundId),
  765. })
  766. },
  767. isExpiry(dbInbound, index) {
  768. return dbInbound.toInbound().isExpiry(index)
  769. },
  770. getUpStats(dbInbound, email) {
  771. if (email.length == 0) return 0
  772. clientStats = dbInbound.clientStats.find(stats => stats.email === email)
  773. return clientStats ? clientStats.up : 0
  774. },
  775. getDownStats(dbInbound, email) {
  776. if (email.length == 0) return 0
  777. clientStats = dbInbound.clientStats.find(stats => stats.email === email)
  778. return clientStats ? clientStats.down : 0
  779. },
  780. isTrafficExhausted(dbInbound, email) {
  781. if (email.length == 0) return false
  782. clientStats = dbInbound.clientStats.find(stats => stats.email === email)
  783. return clientStats ? clientStats.down + clientStats.up > clientStats.total : false
  784. },
  785. isClientEnabled(dbInbound, email) {
  786. clientStats = dbInbound.clientStats ? dbInbound.clientStats.find(stats => stats.email === email) : null
  787. return clientStats ? clientStats['enable'] : true
  788. },
  789. isRemovable(dbInbound_id) {
  790. return this.getInboundClients(this.dbInbounds.find(row => row.id === dbInbound_id)).length > 1
  791. },
  792. inboundLinks(dbInboundId) {
  793. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  794. txtModal.show('{{ i18n "pages.inbounds.export"}}', dbInbound.genInboundLinks, dbInbound.remark);
  795. },
  796. exportAllLinks() {
  797. let copyText = '';
  798. for (const dbInbound of this.dbInbounds) {
  799. copyText += dbInbound.genInboundLinks
  800. }
  801. txtModal.show('{{ i18n "pages.inbounds.export"}}', copyText, 'All-Inbounds');
  802. },
  803. async startDataRefreshLoop() {
  804. while (this.isRefreshEnabled) {
  805. try {
  806. await this.getDBInbounds();
  807. } catch (e) {
  808. console.error(e);
  809. }
  810. await PromiseUtil.sleep(this.refreshInterval);
  811. }
  812. },
  813. toggleRefresh() {
  814. localStorage.setItem("isRefreshEnabled", this.isRefreshEnabled);
  815. if (this.isRefreshEnabled) {
  816. this.startDataRefreshLoop();
  817. }
  818. },
  819. changeRefreshInterval() {
  820. localStorage.setItem("refreshInterval", this.refreshInterval);
  821. },
  822. async manualRefresh() {
  823. if (!this.refreshing) {
  824. this.spinning = true;
  825. await this.getDBInbounds();
  826. this.spinning = false;
  827. }
  828. },
  829. },
  830. watch: {
  831. searchKey: debounce(function (newVal) {
  832. this.searchInbounds(newVal);
  833. }, 500)
  834. },
  835. mounted() {
  836. this.loading();
  837. this.getDefaultSettings();
  838. if (this.isRefreshEnabled) {
  839. this.startDataRefreshLoop();
  840. }
  841. else {
  842. this.getDBInbounds();
  843. }
  844. this.loading(false);
  845. },
  846. computed: {
  847. total() {
  848. let down = 0, up = 0;
  849. let clients = 0, deactive = [], depleted = [], expiring = [];
  850. this.dbInbounds.forEach(dbInbound => {
  851. down += dbInbound.down;
  852. up += dbInbound.up;
  853. if (this.clientCount[dbInbound.id]) {
  854. clients += this.clientCount[dbInbound.id].clients;
  855. deactive = deactive.concat(this.clientCount[dbInbound.id].deactive);
  856. depleted = depleted.concat(this.clientCount[dbInbound.id].depleted);
  857. expiring = expiring.concat(this.clientCount[dbInbound.id].expiring);
  858. }
  859. });
  860. return {
  861. down: down,
  862. up: up,
  863. clients: clients,
  864. deactive: deactive,
  865. depleted: depleted,
  866. expiring: expiring,
  867. };
  868. }
  869. },
  870. });
  871. </script>
  872. {{template "inboundModal"}}
  873. {{template "promptModal"}}
  874. {{template "qrcodeModal"}}
  875. {{template "textModal"}}
  876. {{template "inboundInfoModal"}}
  877. {{template "clientsModal"}}
  878. {{template "clientsBulkModal"}}
  879. </body>
  880. </html>