inbounds.html 50 KB

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