inbounds.html 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  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-popover :overlay-class-name="themeSwitcher.darkClass">
  208. <template slot="content">
  209. <table cellpadding="2" width="100%">
  210. <tr>
  211. <td>↑[[ sizeFormat(dbInbound.up) ]]</td>
  212. <td>↓[[ sizeFormat(dbInbound.down) ]]</td>
  213. </tr>
  214. <tr v-if="dbInbound.total > 0 && dbInbound.up + dbInbound.down < dbInbound.total">
  215. <td>{{ i18n "remained" }}</td>
  216. <td>[[ sizeFormat(dbInbound.total - dbInbound.up - dbInbound.down) ]]</td>
  217. </tr>
  218. </table>
  219. </template>
  220. <a-tag :color="dbInbound.total == 0 ? 'green' : dbInbound.up + dbInbound.down < dbInbound.total ? 'cyan' : 'red'">
  221. [[ sizeFormat(dbInbound.up + dbInbound.down) ]] /
  222. <template v-if="dbInbound.total > 0">
  223. [[ sizeFormat(dbInbound.total) ]]
  224. </template>
  225. <template v-else>
  226. <svg style="fill: currentColor; height: 16px;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path d="M484.4 96C407 96 349.2 164.1 320 208.5C290.8 164.1 233 96 155.6 96C69.75 96 0 167.8 0 256s69.75 160 155.6 160C233.1 416 290.8 347.9 320 303.5C349.2 347.9 407 416 484.4 416C570.3 416 640 344.2 640 256S570.3 96 484.4 96zM155.6 368C96.25 368 48 317.8 48 256s48.25-112 107.6-112c67.75 0 120.5 82.25 137.1 112C276 285.8 223.4 368 155.6 368zM484.4 368c-67.75 0-120.5-82.25-137.1-112C364 226.2 416.6 144 484.4 144C543.8 144 592 194.2 592 256S543.8 368 484.4 368z"/></svg>
  227. </template>
  228. </a-tag>
  229. </a-popover>
  230. </template>
  231. <template slot="enable" slot-scope="text, dbInbound">
  232. <a-switch v-model="dbInbound.enable" @change="switchEnable(dbInbound.id)"></a-switch>
  233. </template>
  234. <template slot="expiryTime" slot-scope="text, dbInbound">
  235. <template v-if="dbInbound.expiryTime > 0">
  236. <a-tag v-if="dbInbound.isExpiry" color="red">
  237. [[ DateUtil.formatMillis(dbInbound.expiryTime) ]]
  238. </a-tag>
  239. <a-tag v-else color="blue">
  240. [[ DateUtil.formatMillis(dbInbound.expiryTime) ]]
  241. </a-tag>
  242. </template>
  243. <a-tag v-else color="green">{{ i18n "indefinite" }}</a-tag>
  244. </template>
  245. <template slot="expandedRowRender" slot-scope="record">
  246. <a-table
  247. v-if="(record.protocol === Protocols.VLESS) || (record.protocol === Protocols.VMESS)"
  248. :row-key="client => client.id"
  249. :columns="innerColumns"
  250. :data-source="getInboundClients(record)"
  251. :pagination="false"
  252. >
  253. {{template "client_table"}}
  254. </a-table>
  255. <a-table
  256. v-else-if="record.protocol === Protocols.TROJAN || record.protocol === Protocols.SHADOWSOCKS"
  257. :row-key="client => client.id"
  258. :columns="innerTrojanColumns"
  259. :data-source="getInboundClients(record)"
  260. :pagination="false"
  261. >
  262. {{template "client_table"}}
  263. </a-table>
  264. </template>
  265. </a-table>
  266. </a-card>
  267. </transition>
  268. </a-spin>
  269. </a-layout-content>
  270. </a-layout>
  271. </a-layout>
  272. {{template "js" .}}
  273. {{template "component/themeSwitcher" .}}
  274. <script>
  275. const columns = [{
  276. title: '{{ i18n "pages.inbounds.operate" }}',
  277. align: 'center',
  278. width: 60,
  279. scopedSlots: { customRender: 'action' },
  280. }, {
  281. title: '{{ i18n "pages.inbounds.enable" }}',
  282. align: 'center',
  283. width: 40,
  284. scopedSlots: { customRender: 'enable' },
  285. }, {
  286. title: "ID",
  287. align: 'center',
  288. dataIndex: "id",
  289. width: 40,
  290. }, {
  291. title: '{{ i18n "pages.inbounds.remark" }}',
  292. align: 'center',
  293. width: 80,
  294. dataIndex: "remark",
  295. }, {
  296. title: '{{ i18n "pages.inbounds.port" }}',
  297. align: 'center',
  298. dataIndex: "port",
  299. width: 40,
  300. }, {
  301. title: '{{ i18n "pages.inbounds.protocol" }}',
  302. align: 'left',
  303. width: 90,
  304. scopedSlots: { customRender: 'protocol' },
  305. }, {
  306. title: '{{ i18n "clients" }}',
  307. align: 'left',
  308. width: 40,
  309. scopedSlots: { customRender: 'clients' },
  310. }, {
  311. title: '{{ i18n "pages.inbounds.traffic" }}',
  312. align: 'center',
  313. width: 60,
  314. scopedSlots: { customRender: 'traffic' },
  315. }, {
  316. title: '{{ i18n "pages.inbounds.expireDate" }}',
  317. align: 'center',
  318. width: 80,
  319. scopedSlots: { customRender: 'expiryTime' },
  320. }];
  321. const innerColumns = [
  322. { title: '{{ i18n "pages.inbounds.operate" }}', width: 70, scopedSlots: { customRender: 'actions' } },
  323. { title: '{{ i18n "pages.inbounds.enable" }}', width: 40, scopedSlots: { customRender: 'enable' } },
  324. { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } },
  325. { title: '{{ i18n "pages.inbounds.traffic" }}', width: 50, scopedSlots: { customRender: 'traffic' } },
  326. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 50, scopedSlots: { customRender: 'expiryTime' } },
  327. { title: 'UUID', width: 120, dataIndex: "id" },
  328. ];
  329. const innerTrojanColumns = [
  330. { title: '{{ i18n "pages.inbounds.operate" }}', width: 70, scopedSlots: { customRender: 'actions' } },
  331. { title: '{{ i18n "pages.inbounds.enable" }}', width: 40, scopedSlots: { customRender: 'enable' } },
  332. { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } },
  333. { title: '{{ i18n "pages.inbounds.traffic" }}', width: 50, scopedSlots: { customRender: 'traffic' } },
  334. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 50, scopedSlots: { customRender: 'expiryTime' } },
  335. { title: 'Password', width: 170, dataIndex: "password" },
  336. ];
  337. const app = new Vue({
  338. delimiters: ['[[', ']]'],
  339. el: '#app',
  340. data: {
  341. siderDrawer,
  342. themeSwitcher,
  343. spinning: false,
  344. inbounds: [],
  345. dbInbounds: [],
  346. searchKey: '',
  347. enableFilter: false,
  348. filterBy: '',
  349. searchedInbounds: [],
  350. expireDiff: 0,
  351. trafficDiff: 0,
  352. defaultCert: '',
  353. defaultKey: '',
  354. clientCount: {},
  355. isRefreshEnabled: localStorage.getItem("isRefreshEnabled") === "true" ? true : false,
  356. refreshing: false,
  357. refreshInterval: Number(localStorage.getItem("refreshInterval")) || 5000,
  358. subSettings: {
  359. enable : false,
  360. port: 0,
  361. path: '',
  362. domain: '',
  363. tls: false
  364. },
  365. tgBotEnable: false
  366. },
  367. methods: {
  368. loading(spinning = true) {
  369. this.spinning = spinning;
  370. },
  371. async getDBInbounds() {
  372. this.refreshing = true;
  373. const msg = await HttpUtil.post('/panel/inbound/list');
  374. if (!msg.success) {
  375. this.refreshing = false;
  376. return;
  377. }
  378. this.setInbounds(msg.obj);
  379. setTimeout(() => {
  380. this.refreshing = false;
  381. }, 500);
  382. },
  383. async getDefaultSettings() {
  384. const msg = await HttpUtil.post('/panel/setting/defaultSettings');
  385. if (!msg.success) {
  386. return;
  387. }
  388. with(msg.obj){
  389. this.expireDiff = expireDiff * 86400000;
  390. this.trafficDiff = trafficDiff * 1073741824;
  391. this.defaultCert = defaultCert;
  392. this.defaultKey = defaultKey;
  393. this.tgBotEnable = tgBotEnable;
  394. this.subSettings = {
  395. enable : subEnable,
  396. port: subPort,
  397. path: subPath,
  398. domain: subDomain,
  399. tls: subTLS
  400. };
  401. }
  402. },
  403. setInbounds(dbInbounds) {
  404. this.inbounds.splice(0);
  405. this.dbInbounds.splice(0);
  406. for (const inbound of dbInbounds) {
  407. const dbInbound = new DBInbound(inbound);
  408. to_inbound = dbInbound.toInbound()
  409. this.inbounds.push(to_inbound);
  410. this.dbInbounds.push(dbInbound);
  411. if ([Protocols.VMESS, Protocols.VLESS, Protocols.TROJAN, Protocols.SHADOWSOCKS].includes(inbound.protocol)) {
  412. this.clientCount[inbound.id] = this.getClientCounts(inbound, to_inbound);
  413. }
  414. }
  415. if(this.enableFilter){
  416. this.filterInbounds();
  417. } else {
  418. this.searchInbounds(this.searchKey);
  419. }
  420. },
  421. getClientCounts(dbInbound, inbound) {
  422. let clientCount = 0, active = [], deactive = [], depleted = [], expiring = [];
  423. clients = this.getClients(dbInbound.protocol, inbound.settings);
  424. clientStats = dbInbound.clientStats
  425. now = new Date().getTime()
  426. if (clients) {
  427. clientCount = clients.length;
  428. if (dbInbound.enable) {
  429. clients.forEach(client => {
  430. client.enable ? active.push(client.email) : deactive.push(client.email);
  431. });
  432. clientStats.forEach(client => {
  433. if (!client.enable) {
  434. depleted.push(client.email);
  435. } else {
  436. if ((client.expiryTime > 0 && (client.expiryTime - now < this.expireDiff)) ||
  437. (client.total > 0 && (client.total - (client.up + client.down) < this.trafficDiff))) expiring.push(client.email);
  438. }
  439. });
  440. } else {
  441. clients.forEach(client => {
  442. deactive.push(client.email);
  443. });
  444. }
  445. }
  446. return {
  447. clients: clientCount,
  448. active: active,
  449. deactive: deactive,
  450. depleted: depleted,
  451. expiring: expiring,
  452. };
  453. },
  454. searchInbounds(key) {
  455. if (ObjectUtil.isEmpty(key)) {
  456. this.searchedInbounds = this.dbInbounds.slice();
  457. } else {
  458. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  459. this.dbInbounds.forEach(inbound => {
  460. if (ObjectUtil.deepSearch(inbound, key)) {
  461. const newInbound = new DBInbound(inbound);
  462. const inboundSettings = JSON.parse(inbound.settings);
  463. if (inboundSettings.hasOwnProperty('clients')) {
  464. const searchedSettings = { "clients": [] };
  465. inboundSettings.clients.forEach(client => {
  466. if (ObjectUtil.deepSearch(client, key)) {
  467. searchedSettings.clients.push(client);
  468. }
  469. });
  470. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, searchedSettings);
  471. }
  472. this.searchedInbounds.push(newInbound);
  473. }
  474. });
  475. }
  476. },
  477. filterInbounds() {
  478. if (ObjectUtil.isEmpty(this.filterBy)) {
  479. this.searchedInbounds = this.dbInbounds.slice();
  480. } else {
  481. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  482. this.dbInbounds.forEach(inbound => {
  483. const newInbound = new DBInbound(inbound);
  484. const inboundSettings = JSON.parse(inbound.settings);
  485. if (this.clientCount[inbound.id] && this.clientCount[inbound.id].hasOwnProperty(this.filterBy)){
  486. const list = this.clientCount[inbound.id][this.filterBy];
  487. if (list.length > 0) {
  488. const filteredSettings = { "clients": [] };
  489. inboundSettings.clients.forEach(client => {
  490. if (list.includes(client.email)) {
  491. filteredSettings.clients.push(client);
  492. }
  493. });
  494. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, filteredSettings);
  495. this.searchedInbounds.push(newInbound);
  496. }
  497. }
  498. });
  499. }
  500. },
  501. toggleFilter(){
  502. if(this.enableFilter) {
  503. this.searchKey = '';
  504. } else {
  505. this.filterBy = '';
  506. this.searchedInbounds = this.dbInbounds.slice();
  507. }
  508. },
  509. generalActions(action) {
  510. switch (action.key) {
  511. case "export":
  512. this.exportAllLinks();
  513. break;
  514. case "resetInbounds":
  515. this.resetAllTraffic();
  516. break;
  517. case "resetClients":
  518. this.resetAllClientTraffics(-1);
  519. break;
  520. case "delDepletedClients":
  521. this.delDepletedClients(-1)
  522. break;
  523. }
  524. },
  525. clickAction(action, dbInbound) {
  526. switch (action.key) {
  527. case "qrcode":
  528. this.showQrcode(dbInbound);
  529. break;
  530. case "showInfo":
  531. this.showInfo(dbInbound);
  532. break;
  533. case "edit":
  534. this.openEditInbound(dbInbound.id);
  535. break;
  536. case "addClient":
  537. this.openAddClient(dbInbound.id)
  538. break;
  539. case "addBulkClient":
  540. this.openAddBulkClient(dbInbound.id)
  541. break;
  542. case "export":
  543. this.inboundLinks(dbInbound.id);
  544. break;
  545. case "resetTraffic":
  546. this.resetTraffic(dbInbound.id);
  547. break;
  548. case "resetClients":
  549. this.resetAllClientTraffics(dbInbound.id);
  550. break;
  551. case "clone":
  552. this.openCloneInbound(dbInbound);
  553. break;
  554. case "delete":
  555. this.delInbound(dbInbound.id);
  556. break;
  557. case "delDepletedClients":
  558. this.delDepletedClients(dbInbound.id)
  559. break;
  560. }
  561. },
  562. openCloneInbound(dbInbound) {
  563. this.$confirm({
  564. title: '{{ i18n "pages.inbounds.cloneInbound"}} \"' + dbInbound.remark + '\"',
  565. content: '{{ i18n "pages.inbounds.cloneInboundContent"}}',
  566. okText: '{{ i18n "pages.inbounds.cloneInboundOk"}}',
  567. cancelText: '{{ i18n "cancel" }}',
  568. onOk: () => {
  569. const baseInbound = dbInbound.toInbound();
  570. dbInbound.up = 0;
  571. dbInbound.down = 0;
  572. this.cloneInbound(baseInbound, dbInbound);
  573. },
  574. });
  575. },
  576. async cloneInbound(baseInbound, dbInbound) {
  577. const data = {
  578. up: dbInbound.up,
  579. down: dbInbound.down,
  580. total: dbInbound.total,
  581. remark: dbInbound.remark + " - Cloned",
  582. enable: dbInbound.enable,
  583. expiryTime: dbInbound.expiryTime,
  584. listen: '',
  585. port: RandomUtil.randomIntRange(10000, 60000),
  586. protocol: baseInbound.protocol,
  587. settings: Inbound.Settings.getSettings(baseInbound.protocol).toString(),
  588. streamSettings: baseInbound.stream.toString(),
  589. sniffing: baseInbound.canSniffing() ? baseInbound.sniffing.toString() : '{}',
  590. };
  591. await this.submit('/panel/inbound/add', data, inModal);
  592. },
  593. openAddInbound() {
  594. inModal.show({
  595. title: '{{ i18n "pages.inbounds.addInbound"}}',
  596. okText: '{{ i18n "pages.inbounds.create"}}',
  597. cancelText: '{{ i18n "close" }}',
  598. confirm: async (inbound, dbInbound) => {
  599. inModal.loading();
  600. await this.addInbound(inbound, dbInbound);
  601. inModal.close();
  602. },
  603. isEdit: false
  604. });
  605. },
  606. openEditInbound(dbInboundId) {
  607. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  608. const inbound = dbInbound.toInbound();
  609. inModal.show({
  610. title: '{{ i18n "pages.inbounds.modifyInbound"}}',
  611. okText: '{{ i18n "pages.inbounds.update"}}',
  612. cancelText: '{{ i18n "close" }}',
  613. inbound: inbound,
  614. dbInbound: dbInbound,
  615. confirm: async (inbound, dbInbound) => {
  616. inModal.loading();
  617. await this.updateInbound(inbound, dbInbound);
  618. inModal.close();
  619. },
  620. isEdit: true
  621. });
  622. },
  623. async addInbound(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/add', data, inModal);
  639. },
  640. async updateInbound(inbound, dbInbound) {
  641. const data = {
  642. up: dbInbound.up,
  643. down: dbInbound.down,
  644. total: dbInbound.total,
  645. remark: dbInbound.remark,
  646. enable: dbInbound.enable,
  647. expiryTime: dbInbound.expiryTime,
  648. listen: inbound.listen,
  649. port: inbound.port,
  650. protocol: inbound.protocol,
  651. settings: inbound.settings.toString(),
  652. };
  653. if (inbound.canEnableStream()) data.streamSettings = inbound.stream.toString();
  654. if (inbound.canSniffing()) data.sniffing = inbound.sniffing.toString();
  655. await this.submit(`/panel/inbound/update/${dbInbound.id}`, data, inModal);
  656. },
  657. openAddClient(dbInboundId) {
  658. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  659. clientModal.show({
  660. title: '{{ i18n "pages.client.add"}}',
  661. okText: '{{ i18n "pages.client.submitAdd"}}',
  662. dbInbound: dbInbound,
  663. confirm: async (clients, dbInboundId) => {
  664. clientModal.loading();
  665. await this.addClient(clients, dbInboundId);
  666. clientModal.close();
  667. },
  668. isEdit: false
  669. });
  670. },
  671. openAddBulkClient(dbInboundId) {
  672. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  673. clientsBulkModal.show({
  674. title: '{{ i18n "pages.client.bulk"}} ' + dbInbound.remark,
  675. okText: '{{ i18n "pages.client.bulk"}}',
  676. dbInbound: dbInbound,
  677. confirm: async (clients, dbInboundId) => {
  678. clientsBulkModal.loading();
  679. await this.addClient(clients, dbInboundId);
  680. clientsBulkModal.close();
  681. },
  682. });
  683. },
  684. openEditClient(dbInboundId, client) {
  685. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  686. clients = this.getInboundClients(dbInbound);
  687. index = this.findIndexOfClient(clients, client);
  688. clientModal.show({
  689. title: '{{ i18n "pages.client.edit"}}',
  690. okText: '{{ i18n "pages.client.submitEdit"}}',
  691. dbInbound: dbInbound,
  692. index: index,
  693. confirm: async (client, dbInboundId, clientId) => {
  694. clientModal.loading();
  695. await this.updateClient(client, dbInboundId, clientId);
  696. clientModal.close();
  697. },
  698. isEdit: true
  699. });
  700. },
  701. findIndexOfClient(clients, client) {
  702. firstKey = Object.keys(client)[0];
  703. return clients.findIndex(c => c[firstKey] === client[firstKey]);
  704. },
  705. async addClient(clients, dbInboundId) {
  706. const data = {
  707. id: dbInboundId,
  708. settings: '{"clients": [' + clients.toString() + ']}',
  709. };
  710. await this.submit(`/panel/inbound/addClient`, data);
  711. },
  712. async updateClient(client, dbInboundId, clientId) {
  713. const data = {
  714. id: dbInboundId,
  715. settings: '{"clients": [' + client.toString() + ']}',
  716. };
  717. await this.submit(`/panel/inbound/updateClient/${clientId}`, data);
  718. },
  719. resetTraffic(dbInboundId) {
  720. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  721. this.$confirm({
  722. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  723. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  724. class: themeSwitcher.darkCardClass,
  725. okText: '{{ i18n "reset"}}',
  726. cancelText: '{{ i18n "cancel"}}',
  727. onOk: () => {
  728. const inbound = dbInbound.toInbound();
  729. dbInbound.up = 0;
  730. dbInbound.down = 0;
  731. this.updateInbound(inbound, dbInbound);
  732. },
  733. });
  734. },
  735. delInbound(dbInboundId) {
  736. this.$confirm({
  737. title: '{{ i18n "pages.inbounds.deleteInbound"}}',
  738. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  739. class: themeSwitcher.darkCardClass,
  740. okText: '{{ i18n "delete"}}',
  741. cancelText: '{{ i18n "cancel"}}',
  742. onOk: () => this.submit('/panel/inbound/del/' + dbInboundId),
  743. });
  744. },
  745. delClient(dbInboundId, client) {
  746. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  747. clientId = this.getClientId(dbInbound.protocol, client);
  748. this.$confirm({
  749. title: '{{ i18n "pages.inbounds.deleteInbound"}}',
  750. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  751. class: themeSwitcher.darkCardClass,
  752. okText: '{{ i18n "delete"}}',
  753. cancelText: '{{ i18n "cancel"}}',
  754. onOk: () => this.submit(`/panel/inbound/${dbInboundId}/delClient/${clientId}`),
  755. });
  756. },
  757. getClients(protocol, clientSettings) {
  758. switch (protocol) {
  759. case Protocols.VMESS: return clientSettings.vmesses;
  760. case Protocols.VLESS: return clientSettings.vlesses;
  761. case Protocols.TROJAN: return clientSettings.trojans;
  762. case Protocols.SHADOWSOCKS: return clientSettings.shadowsockses;
  763. default: return null;
  764. }
  765. },
  766. getClientId(protocol, client) {
  767. switch (protocol) {
  768. case Protocols.TROJAN: return client.password;
  769. case Protocols.SHADOWSOCKS: return client.email;
  770. default: return client.id;
  771. }
  772. },
  773. checkFallback(dbInbound) {
  774. newDbInbound = new DBInbound(dbInbound);
  775. if (dbInbound.listen.startsWith("@")){
  776. rootInbound = this.inbounds.find((i) =>
  777. i.tls &&
  778. ['trojan','vless'].includes(i.protocol) &&
  779. i.settings.fallbacks.find(f => f.dest === dbInbound.listen)
  780. );
  781. if (rootInbound) {
  782. newDbInbound.listen = rootInbound.listen;
  783. newDbInbound.port = rootInbound.port;
  784. newInbound = newDbInbound.toInbound();
  785. newInbound.stream.security = 'tls';
  786. newInbound.stream.tls = rootInbound.stream.tls;
  787. newDbInbound.streamSettings = newInbound.stream.toString();
  788. }
  789. }
  790. return newDbInbound;
  791. },
  792. showQrcode(dbInbound, clientIndex) {
  793. newDbInbound = this.checkFallback(dbInbound);
  794. qrModal.show('{{ i18n "qrCode"}}', newDbInbound, clientIndex);
  795. },
  796. showInfo(dbInbound, index) {
  797. newDbInbound = this.checkFallback(dbInbound);
  798. infoModal.show(newDbInbound, index);
  799. },
  800. switchEnable(dbInboundId) {
  801. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  802. this.submit(`/panel/inbound/update/${dbInboundId}`, dbInbound);
  803. },
  804. async switchEnableClient(dbInboundId, client) {
  805. this.loading()
  806. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  807. inbound = dbInbound.toInbound();
  808. clients = this.getClients(dbInbound.protocol, inbound.settings);
  809. index = this.findIndexOfClient(clients, client);
  810. clients[index].enable = !clients[index].enable;
  811. clientId = this.getClientId(dbInbound.protocol, clients[index]);
  812. await this.updateClient(clients[index], dbInboundId, clientId);
  813. this.loading(false);
  814. },
  815. async submit(url, data) {
  816. const msg = await HttpUtil.postWithModal(url, data);
  817. if (msg.success) {
  818. await this.getDBInbounds();
  819. }
  820. },
  821. getInboundClients(dbInbound) {
  822. if (dbInbound.protocol == Protocols.VLESS) {
  823. return dbInbound.toInbound().settings.vlesses;
  824. } else if (dbInbound.protocol == Protocols.VMESS) {
  825. return dbInbound.toInbound().settings.vmesses;
  826. } else if (dbInbound.protocol == Protocols.TROJAN) {
  827. return dbInbound.toInbound().settings.trojans;
  828. } else if (dbInbound.protocol == Protocols.SHADOWSOCKS) {
  829. return dbInbound.toInbound().settings.shadowsockses;
  830. }
  831. },
  832. resetClientTraffic(client, dbInboundId) {
  833. this.$confirm({
  834. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  835. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  836. class: themeSwitcher.darkCardClass,
  837. okText: '{{ i18n "reset"}}',
  838. cancelText: '{{ i18n "cancel"}}',
  839. onOk: () => this.submit('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + client.email),
  840. })
  841. },
  842. resetAllTraffic() {
  843. this.$confirm({
  844. title: '{{ i18n "pages.inbounds.resetAllTrafficTitle"}}',
  845. content: '{{ i18n "pages.inbounds.resetAllTrafficContent"}}',
  846. class: themeSwitcher.darkCardClass,
  847. okText: '{{ i18n "reset"}}',
  848. cancelText: '{{ i18n "cancel"}}',
  849. onOk: () => this.submit('/panel/inbound/resetAllTraffics'),
  850. });
  851. },
  852. resetAllClientTraffics(dbInboundId) {
  853. this.$confirm({
  854. title: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficTitle"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficTitle"}}',
  855. content: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficContent"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficContent"}}',
  856. class: themeSwitcher.darkCardClass,
  857. okText: '{{ i18n "reset"}}',
  858. cancelText: '{{ i18n "cancel"}}',
  859. onOk: () => this.submit('/panel/inbound/resetAllClientTraffics/' + dbInboundId),
  860. })
  861. },
  862. delDepletedClients(dbInboundId) {
  863. this.$confirm({
  864. title: '{{ i18n "pages.inbounds.delDepletedClientsTitle"}}',
  865. content: '{{ i18n "pages.inbounds.delDepletedClientsContent"}}',
  866. class: themeSwitcher.darkCardClass,
  867. okText: '{{ i18n "reset"}}',
  868. cancelText: '{{ i18n "cancel"}}',
  869. onOk: () => this.submit('/panel/inbound/delDepletedClients/' + dbInboundId),
  870. })
  871. },
  872. isExpiry(dbInbound, index) {
  873. return dbInbound.toInbound().isExpiry(index)
  874. },
  875. getUpStats(dbInbound, email) {
  876. if (email.length == 0) return 0
  877. clientStats = dbInbound.clientStats.find(stats => stats.email === email)
  878. return clientStats ? clientStats.up : 0
  879. },
  880. getDownStats(dbInbound, email) {
  881. if (email.length == 0) return 0
  882. clientStats = dbInbound.clientStats.find(stats => stats.email === email)
  883. return clientStats ? clientStats.down : 0
  884. },
  885. statsColor(dbInbound, email) {
  886. if(email.length == 0) return 'blue';
  887. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  888. return usageColor(clientStats.down + clientStats.up, this.trafficDiff, clientStats.total);
  889. },
  890. isClientEnabled(dbInbound, email) {
  891. clientStats = dbInbound.clientStats ? dbInbound.clientStats.find(stats => stats.email === email) : null
  892. return clientStats ? clientStats['enable'] : true
  893. },
  894. isRemovable(dbInbound_id) {
  895. return this.getInboundClients(this.dbInbounds.find(row => row.id === dbInbound_id)).length > 1
  896. },
  897. inboundLinks(dbInboundId) {
  898. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  899. newDbInbound = this.checkFallback(dbInbound);
  900. txtModal.show('{{ i18n "pages.inbounds.export"}}', newDbInbound.genInboundLinks, newDbInbound.remark);
  901. },
  902. exportAllLinks() {
  903. let copyText = '';
  904. for (const dbInbound of this.dbInbounds) {
  905. copyText += dbInbound.genInboundLinks
  906. }
  907. txtModal.show('{{ i18n "pages.inbounds.export"}}', copyText, 'All-Inbounds');
  908. },
  909. async startDataRefreshLoop() {
  910. while (this.isRefreshEnabled) {
  911. try {
  912. await this.getDBInbounds();
  913. } catch (e) {
  914. console.error(e);
  915. }
  916. await PromiseUtil.sleep(this.refreshInterval);
  917. }
  918. },
  919. toggleRefresh() {
  920. localStorage.setItem("isRefreshEnabled", this.isRefreshEnabled);
  921. if (this.isRefreshEnabled) {
  922. this.startDataRefreshLoop();
  923. }
  924. },
  925. changeRefreshInterval() {
  926. localStorage.setItem("refreshInterval", this.refreshInterval);
  927. },
  928. async manualRefresh() {
  929. if (!this.refreshing) {
  930. this.spinning = true;
  931. await this.getDBInbounds();
  932. this.spinning = false;
  933. }
  934. },
  935. },
  936. watch: {
  937. searchKey: debounce(function (newVal) {
  938. this.searchInbounds(newVal);
  939. }, 500)
  940. },
  941. mounted() {
  942. this.loading();
  943. this.getDefaultSettings();
  944. if (this.isRefreshEnabled) {
  945. this.startDataRefreshLoop();
  946. }
  947. else {
  948. this.getDBInbounds();
  949. }
  950. this.loading(false);
  951. },
  952. computed: {
  953. total() {
  954. let down = 0, up = 0;
  955. let clients = 0, deactive = [], depleted = [], expiring = [];
  956. this.dbInbounds.forEach(dbInbound => {
  957. down += dbInbound.down;
  958. up += dbInbound.up;
  959. if (this.clientCount[dbInbound.id]) {
  960. clients += this.clientCount[dbInbound.id].clients;
  961. deactive = deactive.concat(this.clientCount[dbInbound.id].deactive);
  962. depleted = depleted.concat(this.clientCount[dbInbound.id].depleted);
  963. expiring = expiring.concat(this.clientCount[dbInbound.id].expiring);
  964. }
  965. });
  966. return {
  967. down: down,
  968. up: up,
  969. clients: clients,
  970. deactive: deactive,
  971. depleted: depleted,
  972. expiring: expiring,
  973. };
  974. }
  975. },
  976. });
  977. </script>
  978. {{template "inboundModal"}}
  979. {{template "promptModal"}}
  980. {{template "qrcodeModal"}}
  981. {{template "textModal"}}
  982. {{template "inboundInfoModal"}}
  983. {{template "clientsModal"}}
  984. {{template "clientsBulkModal"}}
  985. </body>
  986. </html>