inbounds.html 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654
  1. {{ template "page/head_start" .}}
  2. <style>
  3. .ant-table:not(.ant-table-expanded-row .ant-table) {
  4. outline: 1px solid #f0f0f0;
  5. outline-offset: -1px;
  6. border-radius: 1rem;
  7. overflow-x: hidden;
  8. }
  9. .dark .ant-table:not(.ant-table-expanded-row .ant-table) {
  10. outline-color: var(--dark-color-table-ring);
  11. }
  12. .ant-table .ant-table-content .ant-table-scroll .ant-table-body {
  13. overflow-y: hidden;
  14. }
  15. .ant-table .ant-table-content .ant-table-tbody tr:last-child .ant-table-wrapper {
  16. margin:-10px 22px !important;
  17. }
  18. .ant-table .ant-table-content .ant-table-tbody tr:last-child .ant-table-wrapper .ant-table {
  19. border-bottom-left-radius: 1rem;
  20. border-bottom-right-radius: 1rem;
  21. }
  22. .ant-table .ant-table-content .ant-table-tbody tr:last-child tr:last-child td {
  23. border-bottom-color: transparent;
  24. }
  25. .ant-table .ant-table-tbody tr:last-child.ant-table-expanded-row .ant-table-wrapper .ant-table-tbody>tr:last-child>td:first-child {
  26. border-bottom-left-radius: 6px;
  27. }
  28. .ant-table .ant-table-tbody tr:last-child.ant-table-expanded-row .ant-table-wrapper .ant-table-tbody>tr:last-child>td:last-child {
  29. border-bottom-right-radius: 6px;
  30. }
  31. @media (min-width: 769px) {
  32. .ant-layout-content {
  33. margin: 24px 16px;
  34. }
  35. }
  36. @media (max-width: 768px) {
  37. .ant-card-body {
  38. padding: .5rem;
  39. }
  40. .ant-table .ant-table-content .ant-table-tbody tr:last-child .ant-table-wrapper {
  41. margin:-10px 2px !important;
  42. }
  43. }
  44. .dark .ant-switch-small:not(.ant-switch-checked) {
  45. background-color: var(--dark-color-surface-100) !important;
  46. }
  47. .ant-custom-popover-title {
  48. display: flex;
  49. align-items: center;
  50. gap: 10px;
  51. margin: 5px 0;
  52. }
  53. .ant-col-sm-24 {
  54. margin: 0.5rem -2rem 0.5rem 2rem;
  55. }
  56. tr.hideExpandIcon .ant-table-row-expand-icon {
  57. display: none;
  58. }
  59. .infinite-tag {
  60. padding: 0 5px;
  61. border-radius: 2rem;
  62. min-width: 50px;
  63. min-height: 22px;
  64. }
  65. .infinite-bar .ant-progress-inner .ant-progress-bg {
  66. background-color: #F2EAF1;
  67. border: #D5BED2 solid 1px;
  68. }
  69. .dark .infinite-bar .ant-progress-inner .ant-progress-bg {
  70. background-color: #7a316f !important;
  71. border: #7a316f solid 1px;
  72. }
  73. .ant-collapse {
  74. margin: 5px 0;
  75. }
  76. .info-large-tag {
  77. max-width: 200px;
  78. overflow: hidden;
  79. }
  80. .client-comment {
  81. font-size: 12px;
  82. opacity: 0.75;
  83. cursor: help;
  84. }
  85. .client-email {
  86. font-weight: 500;
  87. }
  88. .client-popup-item {
  89. display: flex;
  90. align-items: center;
  91. gap: 5px;
  92. }
  93. .online-animation .ant-badge-status-dot {
  94. animation: onlineAnimation 1.2s linear infinite;
  95. }
  96. @keyframes onlineAnimation {
  97. 0%,
  98. 50%,
  99. 100% {
  100. transform: scale(1);
  101. opacity: 1;
  102. }
  103. 10% {
  104. transform: scale(1.5);
  105. opacity: .2;
  106. }
  107. }
  108. .tr-table-box {
  109. display: flex;
  110. gap: 4px;
  111. justify-content: center;
  112. align-items: center;
  113. }
  114. .tr-table-rt {
  115. flex-basis: 70px;
  116. min-width: 70px;
  117. text-align: end;
  118. }
  119. .tr-table-lt {
  120. flex-basis: 70px;
  121. min-width: 70px;
  122. text-align: start;
  123. }
  124. .tr-table-bar {
  125. flex-basis: 160px;
  126. min-width: 60px;
  127. }
  128. .tr-infinity-ch {
  129. font-size: 14pt;
  130. max-height: 24px;
  131. display: inline-flex;
  132. align-items: center;
  133. }
  134. .ant-table-expanded-row .ant-table .ant-table-body {
  135. overflow-x: hidden;
  136. }
  137. .ant-table-expanded-row .ant-table-tbody>tr>td {
  138. padding: 10px 2px;
  139. }
  140. .ant-table-expanded-row .ant-table-thead>tr>th {
  141. padding: 12px 2px;
  142. }
  143. </style>
  144. {{ template "page/head_end" .}}
  145. {{ template "page/body_start" .}}
  146. <a-layout id="app" v-cloak :class="themeSwitcher.currentTheme">
  147. <a-sidebar></a-sidebar>
  148. <a-layout id="content-layout">
  149. <a-layout-content>
  150. <a-spin :spinning="loadingStates.spinning" :delay="500" tip='{{ i18n "loading"}}'>
  151. <transition name="list" appear>
  152. <a-alert type="error" v-if="showAlert && loadingStates.fetched" :style="{ marginBottom: '10px' }"
  153. message='{{ i18n "secAlertTitle" }}'
  154. color="red"
  155. description='{{ i18n "secAlertSsl" }}'
  156. show-icon closable>
  157. </a-alert>
  158. </transition>
  159. <transition name="list" appear>
  160. <a-row v-if="!loadingStates.fetched">
  161. <a-card :style="{ textAlign: 'center', padding: '30px 0', marginTop: '10px', background: 'transparent', border: 'none' }">
  162. <a-spin tip='{{ i18n "loading" }}'></a-spin>
  163. </a-card>
  164. </a-row>
  165. <a-row :gutter="[isMobile ? 8 : 16, isMobile ? 0 : 12]" v-else>
  166. <a-col>
  167. <a-card size="small" :style="{ padding: '16px' }" hoverable>
  168. <a-row>
  169. <a-col :sm="12" :md="5">
  170. <a-custom-statistic title='{{ i18n "pages.inbounds.totalDownUp" }}' :value="`${SizeFormatter.sizeFormat(total.up)} / ${SizeFormatter.sizeFormat(total.down)}`">
  171. <template #prefix>
  172. <a-icon type="swap"></a-icon>
  173. </template>
  174. </a-custom-statistic>
  175. </a-col>
  176. <a-col :sm="12" :md="5">
  177. <a-custom-statistic title='{{ i18n "pages.inbounds.totalUsage" }}' :value="SizeFormatter.sizeFormat(total.up + total.down)" :style="{ marginTop: isMobile ? '10px' : 0 }">
  178. <template #prefix>
  179. <a-icon type="pie-chart"></a-icon>
  180. </template>
  181. </a-custom-statistic>
  182. </a-col>
  183. <a-col :sm="12" :md="5">
  184. <a-custom-statistic title='{{ i18n "pages.inbounds.allTimeTrafficUsage" }}' :value="SizeFormatter.sizeFormat(total.allTime)" :style="{ marginTop: isMobile ? '10px' : 0 }">
  185. <template #prefix>
  186. <a-icon type="history"></a-icon>
  187. </template>
  188. </a-custom-statistic>
  189. </a-col>
  190. <a-col :sm="12" :md="5">
  191. <a-custom-statistic title='{{ i18n "pages.inbounds.inboundCount" }}' :value="dbInbounds.length" :style="{ marginTop: isMobile ? '10px' : 0 }">
  192. <template #prefix>
  193. <a-icon type="bars"></a-icon>
  194. </template>
  195. </a-custom-statistic>
  196. </a-col>
  197. <a-col :sm="12" :md="4">
  198. <a-custom-statistic title='{{ i18n "clients" }}' value=" " :style="{ marginTop: isMobile ? '10px' : 0 }">
  199. <template #prefix>
  200. <a-space direction="horizontal">
  201. <a-icon type="team"></a-icon>
  202. <div>
  203. <a-back-top :target="() => document.getElementById('content-layout')" visibility-height="200"></a-back-top>
  204. <a-tag color="green">[[ total.clients ]]</a-tag>
  205. <a-popover title='{{ i18n "disabled" }}' :overlay-class-name="themeSwitcher.currentTheme">
  206. <template slot="content">
  207. <div v-for="clientEmail in total.deactive"><span>[[ clientEmail ]]</span></div>
  208. </template>
  209. <a-tag v-if="total.deactive.length">[[ total.deactive.length ]]</a-tag>
  210. </a-popover>
  211. <a-popover title='{{ i18n "depleted" }}' :overlay-class-name="themeSwitcher.currentTheme">
  212. <template slot="content">
  213. <div v-for="clientEmail in total.depleted"><span>[[ clientEmail ]]</span></div>
  214. </template>
  215. <a-tag color="red" v-if="total.depleted.length">[[ total.depleted.length ]]</a-tag>
  216. </a-popover>
  217. <a-popover title='{{ i18n "depletingSoon" }}' :overlay-class-name="themeSwitcher.currentTheme">
  218. <template slot="content">
  219. <div v-for="clientEmail in total.expiring"><span>[[ clientEmail ]]</span></div>
  220. </template>
  221. <a-tag color="orange" v-if="total.expiring.length">[[ total.expiring.length ]]</a-tag>
  222. </a-popover>
  223. <a-popover title='{{ i18n "online" }}' :overlay-class-name="themeSwitcher.currentTheme">
  224. <template slot="content">
  225. <div v-for="clientEmail in onlineClients"><span>[[ clientEmail ]]</span></div>
  226. </template>
  227. <a-tag color="blue" v-if="onlineClients.length">[[ onlineClients.length ]]</a-tag>
  228. </a-popover>
  229. </div>
  230. </a-space>
  231. </template>
  232. </a-custom-statistic>
  233. </a-col>
  234. </a-row>
  235. </a-card>
  236. </a-col>
  237. <a-col>
  238. <a-card hoverable>
  239. <template #title>
  240. <a-space direction="horizontal">
  241. <a-button type="primary" icon="plus" @click="openAddInbound">
  242. <template v-if="!isMobile">{{ i18n "pages.inbounds.addInbound" }}</template>
  243. </a-button>
  244. <a-dropdown :trigger="['click']">
  245. <a-button type="primary" icon="menu">
  246. <template v-if="!isMobile">{{ i18n "pages.inbounds.generalActions" }}</template>
  247. </a-button>
  248. <a-menu slot="overlay" @click="a => generalActions(a)" :theme="themeSwitcher.currentTheme">
  249. <a-menu-item key="import">
  250. <a-icon type="import"></a-icon>
  251. {{ i18n "pages.inbounds.importInbound" }}
  252. </a-menu-item>
  253. <a-menu-item key="export">
  254. <a-icon type="export"></a-icon>
  255. {{ i18n "pages.inbounds.export" }}
  256. </a-menu-item>
  257. <a-menu-item key="subs" v-if="subSettings.enable">
  258. <a-icon type="export"></a-icon>
  259. {{ i18n "pages.inbounds.export" }} - {{ i18n "pages.settings.subSettings" }}
  260. </a-menu-item>
  261. <a-menu-item key="resetInbounds">
  262. <a-icon type="reload"></a-icon>
  263. {{ i18n "pages.inbounds.resetAllTraffic" }}
  264. </a-menu-item>
  265. <a-menu-item key="resetClients">
  266. <a-icon type="file-done"></a-icon>
  267. {{ i18n "pages.inbounds.resetAllClientTraffics" }}
  268. </a-menu-item>
  269. <a-menu-item key="delDepletedClients" :style="{ color: '#FF4D4F' }">
  270. <a-icon type="rest"></a-icon>
  271. {{ i18n "pages.inbounds.delDepletedClients" }}
  272. </a-menu-item>
  273. </a-menu>
  274. </a-dropdown>
  275. </a-space>
  276. </template>
  277. <template #extra>
  278. <a-button-group>
  279. <a-button icon="sync" @click="manualRefresh" :loading="refreshing"></a-button>
  280. <a-popover placement="bottomRight" trigger="click" :overlay-class-name="themeSwitcher.currentTheme">
  281. <template #title>
  282. <div class="ant-custom-popover-title">
  283. <a-switch v-model="isRefreshEnabled" @change="toggleRefresh" size="small"></a-switch>
  284. <span>{{ i18n "pages.inbounds.autoRefresh" }}</span>
  285. </div>
  286. </template>
  287. <template #content>
  288. <a-space direction="vertical">
  289. <span>{{ i18n "pages.inbounds.autoRefreshInterval" }}</span>
  290. <a-select v-model="refreshInterval"
  291. :disabled="!isRefreshEnabled"
  292. :style="{ width: '100%' }"
  293. @change="changeRefreshInterval"
  294. :dropdown-class-name="themeSwitcher.currentTheme">
  295. <a-select-option v-for="key in [5,10,30,60]" :value="key*1000">[[ key ]]s</a-select-option>
  296. </a-select>
  297. </a-space>
  298. </template>
  299. <a-button icon="down"></a-button>
  300. </a-popover>
  301. </a-button-group>
  302. </template>
  303. <a-space direction="vertical">
  304. <div :style="isMobile ? {} : { display: 'flex', alignItems: 'center', justifyContent: 'flex-start' }">
  305. <a-switch v-model="enableFilter"
  306. :style="isMobile ? { marginBottom: '.5rem', display: 'flex' } : { marginRight: '.5rem' }"
  307. @change="toggleFilter">
  308. <a-icon slot="checkedChildren" type="search"></a-icon>
  309. <a-icon slot="unCheckedChildren" type="filter"></a-icon>
  310. </a-switch>
  311. <a-input v-if="!enableFilter" v-model.lazy="searchKey" placeholder='{{ i18n "search" }}' autofocus :style="{ maxWidth: '300px' }" :size="isMobile ? 'small' : ''"></a-input>
  312. <a-radio-group v-if="enableFilter" v-model="filterBy" @change="filterInbounds" button-style="solid" :size="isMobile ? 'small' : ''">
  313. <a-radio-button value="">{{ i18n "none" }}</a-radio-button>
  314. <a-radio-button value="deactive">{{ i18n "disabled" }}</a-radio-button>
  315. <a-radio-button value="depleted">{{ i18n "depleted" }}</a-radio-button>
  316. <a-radio-button value="expiring">{{ i18n "depletingSoon" }}</a-radio-button>
  317. <a-radio-button value="online">{{ i18n "online" }}</a-radio-button>
  318. </a-radio-group>
  319. </div>
  320. <a-table :columns="isMobile ? mobileColumns : columns" :row-key="dbInbound => dbInbound.id"
  321. :data-source="searchedInbounds"
  322. :scroll="isMobile ? {} : { x: 1000 }"
  323. :pagination=pagination(searchedInbounds)
  324. :expand-icon-as-cell="false"
  325. :expand-row-by-click="false"
  326. :expand-icon-column-index="0"
  327. :indent-size="0"
  328. :row-class-name="dbInbound => (dbInbound.isMultiUser() ? '' : 'hideExpandIcon')"
  329. :style="{ marginTop: '10px' }"
  330. :locale='{ filterConfirm: `{{ i18n "confirm" }}`, filterReset: `{{ i18n "reset" }}`, emptyText: `{{ i18n "noData" }}` }'>
  331. <template slot="action" slot-scope="text, dbInbound">
  332. <a-dropdown :trigger="['click']">
  333. <a-icon @click="e => e.preventDefault()" type="more" :style="{ fontSize: '20px', textDecoration: 'solid' }"></a-icon>
  334. <a-menu slot="overlay" @click="a => clickAction(a, dbInbound)" :theme="themeSwitcher.currentTheme">
  335. <a-menu-item key="edit">
  336. <a-icon type="edit"></a-icon>
  337. {{ i18n "edit" }}
  338. </a-menu-item>
  339. <a-menu-item key="qrcode" v-if="(dbInbound.isSS && !dbInbound.toInbound().isSSMultiUser) || dbInbound.isWireguard">
  340. <a-icon type="qrcode"></a-icon>
  341. {{ i18n "qrCode" }}
  342. </a-menu-item>
  343. <template v-if="dbInbound.isMultiUser()">
  344. <a-menu-item key="addClient">
  345. <a-icon type="user-add"></a-icon>
  346. {{ i18n "pages.client.add"}}
  347. </a-menu-item>
  348. <a-menu-item key="addBulkClient">
  349. <a-icon type="usergroup-add"></a-icon>
  350. {{ i18n "pages.client.bulk"}}
  351. </a-menu-item>
  352. <a-menu-item key="resetClients">
  353. <a-icon type="file-done"></a-icon>
  354. {{ i18n "pages.inbounds.resetInboundClientTraffics"}}
  355. </a-menu-item>
  356. <a-menu-item key="export">
  357. <a-icon type="export"></a-icon>
  358. {{ i18n "pages.inbounds.export"}}
  359. </a-menu-item>
  360. <a-menu-item key="subs" v-if="subSettings.enable">
  361. <a-icon type="export"></a-icon>
  362. {{ i18n "pages.inbounds.export"}} - {{ i18n "pages.settings.subSettings" }}
  363. </a-menu-item>
  364. <a-menu-item key="delDepletedClients" :style="{ color: '#FF4D4F' }">
  365. <a-icon type="rest"></a-icon>
  366. {{ i18n "pages.inbounds.delDepletedClients" }}
  367. </a-menu-item>
  368. </template>
  369. <template v-else>
  370. <a-menu-item key="showInfo">
  371. <a-icon type="info-circle"></a-icon>
  372. {{ i18n "info"}}
  373. </a-menu-item>
  374. </template>
  375. <a-menu-item key="clipboard">
  376. <a-icon type="copy"></a-icon>
  377. {{ i18n "pages.inbounds.exportInbound" }}
  378. </a-menu-item>
  379. <a-menu-item key="resetTraffic">
  380. <a-icon type="retweet"></a-icon> {{ i18n "pages.inbounds.resetTraffic" }}
  381. </a-menu-item>
  382. <a-menu-item key="clone">
  383. <a-icon type="block"></a-icon> {{ i18n "pages.inbounds.clone"}}
  384. </a-menu-item>
  385. <a-menu-item key="delete">
  386. <span :style="{ color: '#FF4D4F' }">
  387. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  388. </span>
  389. </a-menu-item>
  390. <a-menu-item v-if="isMobile">
  391. <a-switch size="small" v-model="dbInbound.enable" @change="switchEnable(dbInbound.id,dbInbound.enable)"></a-switch>
  392. {{ i18n "pages.inbounds.enable" }}
  393. </a-menu-item>
  394. </a-menu>
  395. </a-dropdown>
  396. </template>
  397. <template slot="protocol" slot-scope="text, dbInbound">
  398. <a-tag :style="{ margin: '0' }" color="purple">[[ dbInbound.protocol ]]</a-tag>
  399. <template v-if="dbInbound.isVMess || dbInbound.isVLess || dbInbound.isTrojan || dbInbound.isSS">
  400. <a-tag :style="{ margin: '0' }" color="green">[[ dbInbound.toInbound().stream.network ]]</a-tag>
  401. <a-tag :style="{ margin: '0' }" v-if="dbInbound.toInbound().stream.isTls" color="blue">TLS</a-tag>
  402. <a-tag :style="{ margin: '0' }" v-if="dbInbound.toInbound().stream.isReality" color="blue">Reality</a-tag>
  403. </template>
  404. </template>
  405. <template slot="clients" slot-scope="text, dbInbound">
  406. <template v-if="clientCount[dbInbound.id]">
  407. <a-tag :style="{ margin: '0' }" color="green">[[ clientCount[dbInbound.id].clients ]]</a-tag>
  408. <a-popover title='{{ i18n "disabled" }}' :overlay-class-name="themeSwitcher.currentTheme">
  409. <template slot="content">
  410. <div v-for="clientEmail in clientCount[dbInbound.id].deactive" :key="clientEmail" class="client-popup-item">
  411. <span>[[ clientEmail ]]</span>
  412. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme">
  413. <template #title>
  414. [[ clientCount[dbInbound.id].comments.get(clientEmail) ]]
  415. </template>
  416. <a-icon type="message" v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  417. </a-tooltip>
  418. </div>
  419. </template>
  420. <a-tag :style="{ margin: '0', padding: '0 2px' }" v-if="clientCount[dbInbound.id].deactive.length">[[ clientCount[dbInbound.id].deactive.length ]]</a-tag>
  421. </a-popover>
  422. <a-popover title='{{ i18n "depleted" }}' :overlay-class-name="themeSwitcher.currentTheme">
  423. <template slot="content">
  424. <div v-for="clientEmail in clientCount[dbInbound.id].depleted" :key="clientEmail" class="client-popup-item">
  425. <span>[[ clientEmail ]]</span>
  426. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme">
  427. <template #title>
  428. [[ clientCount[dbInbound.id].comments.get(clientEmail) ]]
  429. </template>
  430. <a-icon type="message" v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  431. </a-tooltip>
  432. </div>
  433. </template>
  434. <a-tag :style="{ margin: '0', padding: '0 2px' }" color="red" v-if="clientCount[dbInbound.id].depleted.length">[[ clientCount[dbInbound.id].depleted.length ]]</a-tag>
  435. </a-popover>
  436. <a-popover title='{{ i18n "depletingSoon" }}' :overlay-class-name="themeSwitcher.currentTheme">
  437. <template slot="content">
  438. <div v-for="clientEmail in clientCount[dbInbound.id].expiring" :key="clientEmail" class="client-popup-item">
  439. <span>[[ clientEmail ]]</span>
  440. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme">
  441. <template #title>
  442. [[ clientCount[dbInbound.id].comments.get(clientEmail) ]]
  443. </template>
  444. <a-icon type="message" v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  445. </a-tooltip>
  446. </div>
  447. </template>
  448. <a-tag :style="{ margin: '0', padding: '0 2px' }" color="orange" v-if="clientCount[dbInbound.id].expiring.length">[[ clientCount[dbInbound.id].expiring.length ]]</a-tag>
  449. </a-popover>
  450. <a-popover title='{{ i18n "online" }}' :overlay-class-name="themeSwitcher.currentTheme">
  451. <template slot="content">
  452. <div v-for="clientEmail in clientCount[dbInbound.id].online" :key="clientEmail" class="client-popup-item">
  453. <span>[[ clientEmail ]]</span>
  454. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme">
  455. <template #title>
  456. [[ clientCount[dbInbound.id].comments.get(clientEmail) ]]
  457. </template>
  458. <a-icon type="message" v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  459. </a-tooltip>
  460. </div>
  461. </template>
  462. <a-tag :style="{ margin: '0', padding: '0 2px' }" color="blue" v-if="clientCount[dbInbound.id].online.length">[[ clientCount[dbInbound.id].online.length ]]</a-tag>
  463. </a-popover>
  464. </template>
  465. </template>
  466. <template slot="traffic" slot-scope="text, dbInbound">
  467. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  468. <template slot="content">
  469. <table cellpadding="2" width="100%">
  470. <tr>
  471. <td>↑[[ SizeFormatter.sizeFormat(dbInbound.up) ]]</td>
  472. <td>↓[[ SizeFormatter.sizeFormat(dbInbound.down) ]]</td>
  473. </tr>
  474. <tr v-if="dbInbound.total > 0 && dbInbound.up + dbInbound.down < dbInbound.total">
  475. <td>{{ i18n "remained" }}</td>
  476. <td>[[ SizeFormatter.sizeFormat(dbInbound.total - dbInbound.up - dbInbound.down) ]]</td>
  477. </tr>
  478. </table>
  479. </template>
  480. <a-tag :color="ColorUtils.usageColor(dbInbound.up + dbInbound.down, app.trafficDiff, dbInbound.total)">
  481. [[ SizeFormatter.sizeFormat(dbInbound.up + dbInbound.down) ]] /
  482. <template v-if="dbInbound.total > 0">
  483. [[ SizeFormatter.sizeFormat(dbInbound.total) ]]
  484. </template>
  485. <template v-else>
  486. <svg height="10px" width="14px" viewBox="0 0 640 512" fill="currentColor">
  487. <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" fill="currentColor"></path>
  488. </svg>
  489. </template>
  490. </a-tag>
  491. </a-popover>
  492. </template>
  493. <template slot="allTimeInbound" slot-scope="text, dbInbound">
  494. <a-tag>[[ SizeFormatter.sizeFormat(dbInbound.allTime || 0) ]]</a-tag>
  495. </template>
  496. <template slot="enable" slot-scope="text, dbInbound">
  497. <a-switch v-model="dbInbound.enable" @change="switchEnable(dbInbound.id,dbInbound.enable)"></a-switch>
  498. </template>
  499. <template slot="expiryTime" slot-scope="text, dbInbound">
  500. <a-popover v-if="dbInbound.expiryTime > 0" :overlay-class-name="themeSwitcher.currentTheme">
  501. <template slot="content" v-if="app.datepicker === 'gregorian'">
  502. [[ DateUtil.formatMillis(dbInbound.expiryTime) ]]
  503. </template>
  504. <template v-else slot="content">
  505. [[ DateUtil.convertToJalalian(moment(dbInbound.expiryTime)) ]]
  506. </template>
  507. <a-tag :style="{ minWidth: '50px' }" :color="ColorUtils.usageColor(new Date().getTime(), app.expireDiff, dbInbound._expiryTime)">
  508. [[ remainedDays(dbInbound._expiryTime) ]]
  509. </a-tag>
  510. </a-popover>
  511. <a-tag v-else color="purple" class="infinite-tag">
  512. <svg height="10px" width="14px" viewBox="0 0 640 512" fill="currentColor">
  513. <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" fill="currentColor"></path>
  514. </svg>
  515. </a-tag>
  516. </template>
  517. <template slot="info" slot-scope="text, dbInbound">
  518. <a-popover placement="bottomRight" :overlay-class-name="themeSwitcher.currentTheme" trigger="click">
  519. <template slot="content">
  520. <table cellpadding="2">
  521. <tr>
  522. <td>{{ i18n "pages.inbounds.protocol" }}</td>
  523. <td>
  524. <a-tag :style="{ margin: '0' }" color="purple">[[ dbInbound.protocol ]]</a-tag>
  525. <template v-if="dbInbound.isVMess || dbInbound.isVLess || dbInbound.isTrojan || dbInbound.isSS">
  526. <a-tag :style="{ margin: '0' }" color="blue">[[ dbInbound.toInbound().stream.network ]]</a-tag>
  527. <a-tag :style="{ margin: '0' }" v-if="dbInbound.toInbound().stream.isTls" color="green">tls</a-tag>
  528. <a-tag :style="{ margin: '0' }" v-if="dbInbound.toInbound().stream.isReality" color="green">reality</a-tag>
  529. </template>
  530. </td>
  531. </tr>
  532. <tr>
  533. <td>{{ i18n "pages.inbounds.port" }}</td>
  534. <td><a-tag>[[ dbInbound.port ]]</a-tag></td>
  535. </tr>
  536. <tr v-if="clientCount[dbInbound.id]">
  537. <td>{{ i18n "clients" }}</td>
  538. <td>
  539. <a-tag :style="{ margin: '0' }" color="blue">[[ clientCount[dbInbound.id].clients ]]</a-tag>
  540. <a-popover title='{{ i18n "disabled" }}' :overlay-class-name="themeSwitcher.currentTheme">
  541. <template slot="content">
  542. <div v-for="clientEmail in clientCount[dbInbound.id].deactive" :key="clientEmail" class="client-popup-item">
  543. <span>[[ clientEmail ]]</span>
  544. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme">
  545. <template #title>
  546. [[ clientCount[dbInbound.id].comments.get(clientEmail) ]]
  547. </template>
  548. <a-icon type="message" v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  549. </a-tooltip>
  550. </div>
  551. </template>
  552. <a-tag :style="{ margin: '0', padding: '0 2px' }" v-if="clientCount[dbInbound.id].deactive.length">[[ clientCount[dbInbound.id].deactive.length ]]</a-tag>
  553. </a-popover>
  554. <a-popover title='{{ i18n "depleted" }}' :overlay-class-name="themeSwitcher.currentTheme">
  555. <template slot="content">
  556. <div v-for="clientEmail in clientCount[dbInbound.id].depleted" :key="clientEmail" class="client-popup-item">
  557. <span>[[ clientEmail ]]</span>
  558. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme">
  559. <template #title>
  560. [[ clientCount[dbInbound.id].comments.get(clientEmail) ]]
  561. </template>
  562. <a-icon type="message" v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  563. </a-tooltip>
  564. </div>
  565. </template>
  566. <a-tag :style="{ margin: '0', padding: '0 2px' }" color="red" v-if="clientCount[dbInbound.id].depleted.length">[[ clientCount[dbInbound.id].depleted.length ]]</a-tag>
  567. </a-popover>
  568. <a-popover title='{{ i18n "depletingSoon" }}' :overlay-class-name="themeSwitcher.currentTheme">
  569. <template slot="content">
  570. <div v-for="clientEmail in clientCount[dbInbound.id].expiring" :key="clientEmail" class="client-popup-item">
  571. <span>[[ clientEmail ]]</span>
  572. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme">
  573. <template #title>
  574. [[ clientCount[dbInbound.id].comments.get(clientEmail) ]]
  575. </template>
  576. <a-icon type="message" v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  577. </a-tooltip>
  578. </div>
  579. </template>
  580. <a-tag :style="{ margin: '0', padding: '0 2px' }" color="orange" v-if="clientCount[dbInbound.id].expiring.length">[[ clientCount[dbInbound.id].expiring.length ]]</a-tag>
  581. </a-popover>
  582. <a-popover title='{{ i18n "online" }}' :overlay-class-name="themeSwitcher.currentTheme">
  583. <template slot="content">
  584. <div v-for="clientEmail in clientCount[dbInbound.id].online" :key="clientEmail" class="client-popup-item">
  585. <span>[[ clientEmail ]]</span>
  586. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme">
  587. <template #title>
  588. [[ clientCount[dbInbound.id].comments.get(clientEmail) ]]
  589. </template>
  590. <a-icon type="message" v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  591. </a-tooltip>
  592. </div>
  593. </template>
  594. <a-tag :style="{ margin: '0', padding: '0 2px' }" color="green" v-if="clientCount[dbInbound.id].online.length">[[ clientCount[dbInbound.id].online.length ]]</a-tag>
  595. </a-popover>
  596. </td>
  597. </tr>
  598. <tr>
  599. <td>{{ i18n "pages.inbounds.traffic" }}</td>
  600. <td>
  601. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  602. <template slot="content">
  603. <table cellpadding="2" width="100%">
  604. <tr>
  605. <td>↑[[ SizeFormatter.sizeFormat(dbInbound.up) ]]</td>
  606. <td>↓[[ SizeFormatter.sizeFormat(dbInbound.down) ]]</td>
  607. </tr>
  608. <tr v-if="dbInbound.total > 0 && dbInbound.up + dbInbound.down < dbInbound.total">
  609. <td>{{ i18n "remained" }}</td>
  610. <td>[[ SizeFormatter.sizeFormat(dbInbound.total - dbInbound.up - dbInbound.down) ]]</td>
  611. </tr>
  612. </table>
  613. </template>
  614. <a-tag :color="ColorUtils.usageColor(dbInbound.up + dbInbound.down, app.trafficDiff, dbInbound.total)">
  615. [[ SizeFormatter.sizeFormat(dbInbound.up + dbInbound.down) ]] /
  616. <template v-if="dbInbound.total > 0">
  617. [[ SizeFormatter.sizeFormat(dbInbound.total) ]]
  618. </template>
  619. <template v-else>
  620. <svg height="10px" width="14px" viewBox="0 0 640 512" fill="currentColor">
  621. <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" fill="currentColor"></path>
  622. </svg>
  623. </template>
  624. </a-tag>
  625. </a-popover>
  626. </td>
  627. </tr>
  628. <tr>
  629. <td>{{ i18n "pages.inbounds.expireDate" }}</td>
  630. <td>
  631. <a-tag :style="{ minWidth: '50px', textAlign: 'center' }" v-if="dbInbound.expiryTime > 0"
  632. :color="dbInbound.isExpiry? 'red': 'blue'">
  633. <template v-if="app.datepicker === 'gregorian'">
  634. [[ DateUtil.formatMillis(dbInbound.expiryTime) ]]
  635. </template>
  636. <template v-else>
  637. [[ DateUtil.convertToJalalian(moment(dbInbound.expiryTime)) ]]
  638. </template>
  639. </a-tag>
  640. <a-tag v-else :style="{ textAlign: 'center' }" color="purple" class="infinite-tag">
  641. <svg height="10px" width="14px" viewBox="0 0 640 512" fill="currentColor">
  642. <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" fill="currentColor"></path>
  643. </svg>
  644. </a-tag>
  645. </td>
  646. </tr>
  647. </table>
  648. </template>
  649. <a-badge>
  650. <a-icon v-if="!dbInbound.enable" slot="count" type="pause-circle" :style="{ color: themeSwitcher.isDarkTheme ? '#2c3950' : '#bcbcbc' }"></a-icon>
  651. <a-button shape="round" size="small" :style="{ fontSize: '14px', padding: '0 10px' }">
  652. <a-icon type="info"></a-icon>
  653. </a-button>
  654. </a-badge>
  655. </a-popover>
  656. </template>
  657. <template slot="expandedRowRender" slot-scope="record">
  658. <a-table
  659. :row-key="client => client.id"
  660. :columns="isMobile ? innerMobileColumns : innerColumns"
  661. :data-source="getInboundClients(record)"
  662. :pagination=pagination(getInboundClients(record))
  663. :style="{ margin: `-10px ${isMobile ? '2px' : '22px'} -11px` }">
  664. {{template "component/aClientTable"}}
  665. </a-table>
  666. </template>
  667. </a-table>
  668. </a-space>
  669. </a-card>
  670. </a-col>
  671. </a-row>
  672. </transition>
  673. </a-spin>
  674. </a-layout-content>
  675. </a-layout>
  676. </a-layout>
  677. {{template "page/body_scripts" .}}
  678. <script src="{{ .base_path }}assets/qrcode/qrious2.min.js?{{ .cur_ver }}"></script>
  679. <script src="{{ .base_path }}assets/uri/URI.min.js?{{ .cur_ver }}"></script>
  680. <script src="{{ .base_path }}assets/js/model/inbound.js?{{ .cur_ver }}"></script>
  681. <script src="{{ .base_path }}assets/js/model/dbinbound.js?{{ .cur_ver }}"></script>
  682. {{template "component/aSidebar" .}}
  683. {{template "component/aThemeSwitch" .}}
  684. {{template "component/aCustomStatistic" .}}
  685. {{template "component/aPersianDatepicker" .}}
  686. {{template "modals/inboundModal"}}
  687. {{template "modals/promptModal"}}
  688. {{template "modals/qrcodeModal"}}
  689. {{template "modals/textModal"}}
  690. {{template "modals/inboundInfoModal"}}
  691. {{template "modals/clientsModal"}}
  692. {{template "modals/clientsBulkModal"}}
  693. <script>
  694. const columns = [{
  695. title: "ID",
  696. align: 'right',
  697. dataIndex: "id",
  698. width: 30,
  699. responsive: ["xs"],
  700. }, {
  701. title: '{{ i18n "pages.inbounds.operate" }}',
  702. align: 'center',
  703. width: 30,
  704. scopedSlots: { customRender: 'action' },
  705. }, {
  706. title: '{{ i18n "pages.inbounds.enable" }}',
  707. align: 'center',
  708. width: 30,
  709. scopedSlots: { customRender: 'enable' },
  710. }, {
  711. title: '{{ i18n "pages.inbounds.remark" }}',
  712. align: 'center',
  713. width: 60,
  714. dataIndex: "remark",
  715. }, {
  716. title: '{{ i18n "pages.inbounds.port" }}',
  717. align: 'center',
  718. dataIndex: "port",
  719. width: 40,
  720. }, {
  721. title: '{{ i18n "pages.inbounds.protocol" }}',
  722. align: 'left',
  723. width: 70,
  724. scopedSlots: { customRender: 'protocol' },
  725. }, {
  726. title: '{{ i18n "clients" }}',
  727. align: 'left',
  728. width: 50,
  729. scopedSlots: { customRender: 'clients' },
  730. }, {
  731. title: '{{ i18n "pages.inbounds.traffic" }}',
  732. align: 'center',
  733. width: 90,
  734. scopedSlots: { customRender: 'traffic' },
  735. }, {
  736. title: '{{ i18n "pages.inbounds.allTimeTraffic" }}',
  737. align: 'center',
  738. width: 70,
  739. scopedSlots: { customRender: 'allTimeInbound' },
  740. }, {
  741. title: '{{ i18n "pages.inbounds.expireDate" }}',
  742. align: 'center',
  743. width: 40,
  744. scopedSlots: { customRender: 'expiryTime' },
  745. }];
  746. const mobileColumns = [{
  747. title: "ID",
  748. align: 'right',
  749. dataIndex: "id",
  750. width: 10,
  751. responsive: ["s"],
  752. }, {
  753. title: '{{ i18n "pages.inbounds.operate" }}',
  754. align: 'center',
  755. width: 25,
  756. scopedSlots: { customRender: 'action' },
  757. }, {
  758. title: '{{ i18n "pages.inbounds.remark" }}',
  759. align: 'left',
  760. width: 70,
  761. dataIndex: "remark",
  762. }, {
  763. title: '{{ i18n "pages.inbounds.info" }}',
  764. align: 'center',
  765. width: 10,
  766. scopedSlots: { customRender: 'info' },
  767. }];
  768. const innerColumns = [
  769. { title: '{{ i18n "pages.inbounds.operate" }}', width: 65, scopedSlots: { customRender: 'actions' } },
  770. { title: '{{ i18n "pages.inbounds.enable" }}', width: 30, scopedSlots: { customRender: 'enable' } },
  771. { title: '{{ i18n "online" }}', width: 30, scopedSlots: { customRender: 'online' } },
  772. { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } },
  773. { title: '{{ i18n "pages.inbounds.traffic" }}', width: 80, align: 'center', scopedSlots: { customRender: 'traffic' } },
  774. { title: '{{ i18n "pages.inbounds.allTimeTraffic" }}', width: 80, align: 'center', scopedSlots: { customRender: 'allTime' } },
  775. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 80, align: 'center', scopedSlots: { customRender: 'expiryTime' } },
  776. ];
  777. const innerMobileColumns = [
  778. { title: '{{ i18n "pages.inbounds.operate" }}', width: 10, align: 'center', scopedSlots: { customRender: 'actionMenu' } },
  779. { title: '{{ i18n "pages.inbounds.client" }}', width: 90, align: 'left', scopedSlots: { customRender: 'client' } },
  780. { title: '{{ i18n "pages.inbounds.info" }}', width: 10, align: 'center', scopedSlots: { customRender: 'info' } },
  781. ];
  782. const app = new Vue({
  783. delimiters: ['[[', ']]'],
  784. el: '#app',
  785. mixins: [MediaQueryMixin],
  786. data: {
  787. themeSwitcher,
  788. persianDatepicker,
  789. loadingStates: {
  790. fetched: false,
  791. spinning: false
  792. },
  793. inbounds: [],
  794. dbInbounds: [],
  795. searchKey: '',
  796. enableFilter: false,
  797. filterBy: '',
  798. searchedInbounds: [],
  799. expireDiff: 0,
  800. trafficDiff: 0,
  801. defaultCert: '',
  802. defaultKey: '',
  803. clientCount: [],
  804. onlineClients: [],
  805. isRefreshEnabled: localStorage.getItem("isRefreshEnabled") === "true" ? true : false,
  806. refreshing: false,
  807. refreshInterval: Number(localStorage.getItem("refreshInterval")) || 5000,
  808. subSettings: {
  809. enable : false,
  810. subTitle : '',
  811. subURI : '',
  812. subJsonURI : '',
  813. },
  814. remarkModel: '-ieo',
  815. datepicker: 'gregorian',
  816. tgBotEnable: false,
  817. showAlert: false,
  818. ipLimitEnable: false,
  819. pageSize: 50,
  820. },
  821. methods: {
  822. loading(spinning = true) {
  823. this.loadingStates.spinning = spinning;
  824. },
  825. async getDBInbounds() {
  826. this.refreshing = true;
  827. const msg = await HttpUtil.post('/panel/inbound/list');
  828. if (!msg.success) {
  829. this.refreshing = false;
  830. return;
  831. }
  832. await this.getOnlineUsers();
  833. this.setInbounds(msg.obj);
  834. setTimeout(() => {
  835. this.refreshing = false;
  836. }, 500);
  837. },
  838. async getOnlineUsers() {
  839. const msg = await HttpUtil.post('/panel/inbound/onlines');
  840. if (!msg.success) {
  841. return;
  842. }
  843. this.onlineClients = msg.obj != null ? msg.obj : [];
  844. },
  845. async getDefaultSettings() {
  846. const msg = await HttpUtil.post('/panel/setting/defaultSettings');
  847. if (!msg.success) {
  848. return;
  849. }
  850. with(msg.obj){
  851. this.expireDiff = expireDiff * 86400000;
  852. this.trafficDiff = trafficDiff * 1073741824;
  853. this.defaultCert = defaultCert;
  854. this.defaultKey = defaultKey;
  855. this.tgBotEnable = tgBotEnable;
  856. this.subSettings = {
  857. enable : subEnable,
  858. subTitle : subTitle,
  859. subURI: subURI,
  860. subJsonURI: subJsonURI
  861. };
  862. this.pageSize = pageSize;
  863. this.remarkModel = remarkModel;
  864. this.datepicker = datepicker;
  865. this.ipLimitEnable = ipLimitEnable;
  866. }
  867. },
  868. setInbounds(dbInbounds) {
  869. this.inbounds.splice(0);
  870. this.dbInbounds.splice(0);
  871. this.clientCount.splice(0);
  872. for (const inbound of dbInbounds) {
  873. const dbInbound = new DBInbound(inbound);
  874. to_inbound = dbInbound.toInbound()
  875. this.inbounds.push(to_inbound);
  876. this.dbInbounds.push(dbInbound);
  877. if ([Protocols.VMESS, Protocols.VLESS, Protocols.TROJAN, Protocols.SHADOWSOCKS].includes(inbound.protocol)) {
  878. if (dbInbound.isSS && (!to_inbound.isSSMultiUser)) {
  879. continue;
  880. }
  881. this.clientCount[inbound.id] = this.getClientCounts(inbound, to_inbound);
  882. }
  883. }
  884. if (!this.loadingStates.fetched) {
  885. this.loadingStates.fetched = true
  886. }
  887. if(this.enableFilter){
  888. this.filterInbounds();
  889. } else {
  890. this.searchInbounds(this.searchKey);
  891. }
  892. },
  893. getClientCounts(dbInbound, inbound) {
  894. let clientCount = 0, active = [], deactive = [], depleted = [], expiring = [], online = [], comments = new Map();
  895. clients = inbound.clients;
  896. clientStats = dbInbound.clientStats
  897. now = new Date().getTime()
  898. if (clients) {
  899. clientCount = clients.length;
  900. if (dbInbound.enable) {
  901. clients.forEach(client => {
  902. if (client.comment) {
  903. comments.set(client.email, client.comment)
  904. }
  905. if (client.enable) {
  906. active.push(client.email);
  907. if (this.isClientOnline(client.email)) online.push(client.email);
  908. } else {
  909. deactive.push(client.email);
  910. }
  911. });
  912. clientStats.forEach(client => {
  913. if (!client.enable) {
  914. depleted.push(client.email);
  915. } else {
  916. if ((client.expiryTime > 0 && (client.expiryTime - now < this.expireDiff)) ||
  917. (client.total > 0 && (client.total - (client.up + client.down) < this.trafficDiff))) expiring.push(client.email);
  918. }
  919. });
  920. } else {
  921. clients.forEach(client => {
  922. deactive.push(client.email);
  923. });
  924. }
  925. }
  926. return {
  927. clients: clientCount,
  928. active: active,
  929. deactive: deactive,
  930. depleted: depleted,
  931. expiring: expiring,
  932. online: online,
  933. comments: comments,
  934. };
  935. },
  936. searchInbounds(key) {
  937. if (ObjectUtil.isEmpty(key)) {
  938. this.searchedInbounds = this.dbInbounds.slice();
  939. } else {
  940. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  941. this.dbInbounds.forEach(inbound => {
  942. if (ObjectUtil.deepSearch(inbound, key)) {
  943. const newInbound = new DBInbound(inbound);
  944. const inboundSettings = JSON.parse(inbound.settings);
  945. if (inboundSettings.hasOwnProperty('clients')) {
  946. const searchedSettings = { "clients": [] };
  947. inboundSettings.clients.forEach(client => {
  948. if (ObjectUtil.deepSearch(client, key)) {
  949. searchedSettings.clients.push(client);
  950. }
  951. });
  952. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, searchedSettings);
  953. }
  954. this.searchedInbounds.push(newInbound);
  955. }
  956. });
  957. }
  958. },
  959. filterInbounds() {
  960. if (ObjectUtil.isEmpty(this.filterBy)) {
  961. this.searchedInbounds = this.dbInbounds.slice();
  962. } else {
  963. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  964. this.dbInbounds.forEach(inbound => {
  965. const newInbound = new DBInbound(inbound);
  966. const inboundSettings = JSON.parse(inbound.settings);
  967. if (this.clientCount[inbound.id] && this.clientCount[inbound.id].hasOwnProperty(this.filterBy)){
  968. const list = this.clientCount[inbound.id][this.filterBy];
  969. if (list.length > 0) {
  970. const filteredSettings = { "clients": [] };
  971. inboundSettings.clients.forEach(client => {
  972. if (list.includes(client.email)) {
  973. filteredSettings.clients.push(client);
  974. }
  975. });
  976. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, filteredSettings);
  977. this.searchedInbounds.push(newInbound);
  978. }
  979. }
  980. });
  981. }
  982. },
  983. toggleFilter(){
  984. if(this.enableFilter) {
  985. this.searchKey = '';
  986. } else {
  987. this.filterBy = '';
  988. this.searchedInbounds = this.dbInbounds.slice();
  989. }
  990. },
  991. generalActions(action) {
  992. switch (action.key) {
  993. case "import":
  994. this.importInbound();
  995. break;
  996. case "export":
  997. this.exportAllLinks();
  998. break;
  999. case "subs":
  1000. this.exportAllSubs();
  1001. break;
  1002. case "resetInbounds":
  1003. this.resetAllTraffic();
  1004. break;
  1005. case "resetClients":
  1006. this.resetAllClientTraffics(-1);
  1007. break;
  1008. case "delDepletedClients":
  1009. this.delDepletedClients(-1)
  1010. break;
  1011. }
  1012. },
  1013. clickAction(action, dbInbound) {
  1014. switch (action.key) {
  1015. case "qrcode":
  1016. this.showQrcode(dbInbound.id);
  1017. break;
  1018. case "showInfo":
  1019. this.showInfo(dbInbound.id);
  1020. break;
  1021. case "edit":
  1022. this.openEditInbound(dbInbound.id);
  1023. break;
  1024. case "addClient":
  1025. this.openAddClient(dbInbound.id)
  1026. break;
  1027. case "addBulkClient":
  1028. this.openAddBulkClient(dbInbound.id)
  1029. break;
  1030. case "export":
  1031. this.inboundLinks(dbInbound.id);
  1032. break;
  1033. case "subs":
  1034. this.exportSubs(dbInbound.id);
  1035. break;
  1036. case "clipboard":
  1037. this.copy(dbInbound.id);
  1038. break;
  1039. case "resetTraffic":
  1040. this.resetTraffic(dbInbound.id);
  1041. break;
  1042. case "resetClients":
  1043. this.resetAllClientTraffics(dbInbound.id);
  1044. break;
  1045. case "clone":
  1046. this.openCloneInbound(dbInbound);
  1047. break;
  1048. case "delete":
  1049. this.delInbound(dbInbound.id);
  1050. break;
  1051. case "delDepletedClients":
  1052. this.delDepletedClients(dbInbound.id)
  1053. break;
  1054. }
  1055. },
  1056. openCloneInbound(dbInbound) {
  1057. this.$confirm({
  1058. title: '{{ i18n "pages.inbounds.cloneInbound"}} \"' + dbInbound.remark + '\"',
  1059. content: '{{ i18n "pages.inbounds.cloneInboundContent"}}',
  1060. okText: '{{ i18n "pages.inbounds.cloneInboundOk"}}',
  1061. class: themeSwitcher.currentTheme,
  1062. cancelText: '{{ i18n "cancel" }}',
  1063. onOk: () => {
  1064. const baseInbound = dbInbound.toInbound();
  1065. dbInbound.up = 0;
  1066. dbInbound.down = 0;
  1067. this.cloneInbound(baseInbound, dbInbound);
  1068. },
  1069. });
  1070. },
  1071. async cloneInbound(baseInbound, dbInbound) {
  1072. const data = {
  1073. up: dbInbound.up,
  1074. down: dbInbound.down,
  1075. total: dbInbound.total,
  1076. remark: dbInbound.remark + " - Cloned",
  1077. enable: dbInbound.enable,
  1078. expiryTime: dbInbound.expiryTime,
  1079. listen: '',
  1080. port: RandomUtil.randomInteger(10000, 60000),
  1081. protocol: baseInbound.protocol,
  1082. settings: Inbound.Settings.getSettings(baseInbound.protocol).toString(),
  1083. streamSettings: baseInbound.stream.toString(),
  1084. sniffing: baseInbound.sniffing.toString(),
  1085. };
  1086. await this.submit('/panel/inbound/add', data, inModal);
  1087. },
  1088. openAddInbound() {
  1089. inModal.show({
  1090. title: '{{ i18n "pages.inbounds.addInbound"}}',
  1091. okText: '{{ i18n "create"}}',
  1092. cancelText: '{{ i18n "close" }}',
  1093. confirm: async (inbound, dbInbound) => {
  1094. await this.addInbound(inbound, dbInbound, inModal);
  1095. },
  1096. isEdit: false
  1097. });
  1098. },
  1099. openEditInbound(dbInboundId) {
  1100. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1101. const inbound = dbInbound.toInbound();
  1102. inModal.show({
  1103. title: '{{ i18n "pages.inbounds.modifyInbound"}}',
  1104. okText: '{{ i18n "update"}}',
  1105. cancelText: '{{ i18n "close" }}',
  1106. inbound: inbound,
  1107. dbInbound: dbInbound,
  1108. confirm: async (inbound, dbInbound) => {
  1109. await this.updateInbound(inbound, dbInbound);
  1110. },
  1111. isEdit: true
  1112. });
  1113. },
  1114. async addInbound(inbound, dbInbound) {
  1115. const data = {
  1116. up: dbInbound.up,
  1117. down: dbInbound.down,
  1118. total: dbInbound.total,
  1119. remark: dbInbound.remark,
  1120. enable: dbInbound.enable,
  1121. expiryTime: dbInbound.expiryTime,
  1122. listen: inbound.listen,
  1123. port: inbound.port,
  1124. protocol: inbound.protocol,
  1125. settings: inbound.settings.toString(),
  1126. };
  1127. if (inbound.canEnableStream()){
  1128. data.streamSettings = inbound.stream.toString();
  1129. } else if (inbound.stream?.sockopt) {
  1130. data.streamSettings = JSON.stringify({ sockopt: inbound.stream.sockopt.toJson() }, null, 2);
  1131. }
  1132. data.sniffing = inbound.sniffing.toString();
  1133. await this.submit('/panel/inbound/add', data, inModal);
  1134. },
  1135. async updateInbound(inbound, dbInbound) {
  1136. const data = {
  1137. up: dbInbound.up,
  1138. down: dbInbound.down,
  1139. total: dbInbound.total,
  1140. remark: dbInbound.remark,
  1141. enable: dbInbound.enable,
  1142. expiryTime: dbInbound.expiryTime,
  1143. listen: inbound.listen,
  1144. port: inbound.port,
  1145. protocol: inbound.protocol,
  1146. settings: inbound.settings.toString(),
  1147. };
  1148. if (inbound.canEnableStream()){
  1149. data.streamSettings = inbound.stream.toString();
  1150. } else if (inbound.stream?.sockopt) {
  1151. data.streamSettings = JSON.stringify({ sockopt: inbound.stream.sockopt.toJson() }, null, 2);
  1152. }
  1153. data.sniffing = inbound.sniffing.toString();
  1154. await this.submit(`/panel/inbound/update/${dbInbound.id}`, data, inModal);
  1155. },
  1156. openAddClient(dbInboundId) {
  1157. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1158. clientModal.show({
  1159. title: '{{ i18n "pages.client.add"}}',
  1160. okText: '{{ i18n "pages.client.submitAdd"}}',
  1161. dbInbound: dbInbound,
  1162. confirm: async (clients, dbInboundId) => {
  1163. await this.addClient(clients, dbInboundId, clientModal);
  1164. },
  1165. isEdit: false
  1166. });
  1167. },
  1168. openAddBulkClient(dbInboundId) {
  1169. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1170. clientsBulkModal.show({
  1171. title: '{{ i18n "pages.client.bulk"}} ' + dbInbound.remark,
  1172. okText: '{{ i18n "pages.client.bulk"}}',
  1173. dbInbound: dbInbound,
  1174. confirm: async (clients, dbInboundId) => {
  1175. await this.addClient(clients, dbInboundId, clientsBulkModal);
  1176. },
  1177. });
  1178. },
  1179. openEditClient(dbInboundId, client) {
  1180. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1181. clients = this.getInboundClients(dbInbound);
  1182. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1183. clientModal.show({
  1184. title: '{{ i18n "pages.client.edit"}}',
  1185. okText: '{{ i18n "pages.client.submitEdit"}}',
  1186. dbInbound: dbInbound,
  1187. index: index,
  1188. confirm: async (client, dbInboundId, clientId) => {
  1189. clientModal.loading();
  1190. await this.updateClient(client, dbInboundId, clientId);
  1191. clientModal.close();
  1192. },
  1193. isEdit: true
  1194. });
  1195. },
  1196. findIndexOfClient(protocol, clients, client) {
  1197. switch (protocol) {
  1198. case Protocols.TROJAN:
  1199. case Protocols.SHADOWSOCKS:
  1200. return clients.findIndex(item => item.password === client.password && item.email === client.email);
  1201. default: return clients.findIndex(item => item.id === client.id && item.email === client.email);
  1202. }
  1203. },
  1204. async addClient(clients, dbInboundId, modal) {
  1205. const data = {
  1206. id: dbInboundId,
  1207. settings: '{"clients": [' + clients.toString() + ']}',
  1208. };
  1209. await this.submit(`/panel/inbound/addClient`, data, modal);
  1210. },
  1211. async updateClient(client, dbInboundId, clientId) {
  1212. const data = {
  1213. id: dbInboundId,
  1214. settings: '{"clients": [' + client.toString() + ']}',
  1215. };
  1216. await this.submit(`/panel/inbound/updateClient/${clientId}`, data, clientModal);
  1217. },
  1218. resetTraffic(dbInboundId) {
  1219. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1220. this.$confirm({
  1221. title: '{{ i18n "pages.inbounds.resetTraffic"}}' + ' #' + dbInboundId,
  1222. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  1223. class: themeSwitcher.currentTheme,
  1224. okText: '{{ i18n "reset"}}',
  1225. cancelText: '{{ i18n "cancel"}}',
  1226. onOk: () => {
  1227. const inbound = dbInbound.toInbound();
  1228. dbInbound.up = 0;
  1229. dbInbound.down = 0;
  1230. this.updateInbound(inbound, dbInbound);
  1231. },
  1232. });
  1233. },
  1234. delInbound(dbInboundId) {
  1235. this.$confirm({
  1236. title: '{{ i18n "pages.inbounds.deleteInbound"}}' + ' #' + dbInboundId,
  1237. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  1238. class: themeSwitcher.currentTheme,
  1239. okText: '{{ i18n "delete"}}',
  1240. cancelText: '{{ i18n "cancel"}}',
  1241. onOk: () => this.submit('/panel/inbound/del/' + dbInboundId),
  1242. });
  1243. },
  1244. delClient(dbInboundId, client,confirmation = true) {
  1245. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1246. clientId = this.getClientId(dbInbound.protocol, client);
  1247. if (confirmation){
  1248. this.$confirm({
  1249. title: '{{ i18n "pages.inbounds.deleteClient"}}' + ' ' + client.email,
  1250. content: '{{ i18n "pages.inbounds.deleteClientContent"}}',
  1251. class: themeSwitcher.currentTheme,
  1252. okText: '{{ i18n "delete"}}',
  1253. cancelText: '{{ i18n "cancel"}}',
  1254. onOk: () => this.submit(`/panel/inbound/${dbInboundId}/delClient/${clientId}`),
  1255. });
  1256. } else {
  1257. this.submit(`/panel/inbound/${dbInboundId}/delClient/${clientId}`);
  1258. }
  1259. },
  1260. getSubGroupClients(dbInbounds, currentClient) {
  1261. const response = {
  1262. inbounds: [],
  1263. clients: [],
  1264. editIds: []
  1265. }
  1266. if (dbInbounds && dbInbounds.length > 0 && currentClient) {
  1267. dbInbounds.forEach((dbInboundItem) => {
  1268. const dbInbound = new DBInbound(dbInboundItem);
  1269. if (dbInbound) {
  1270. const inbound = dbInbound.toInbound();
  1271. if (inbound) {
  1272. const clients = inbound.clients;
  1273. if (clients.length > 0) {
  1274. clients.forEach((client) => {
  1275. if (client['subId'] === currentClient['subId']) {
  1276. client['inboundId'] = dbInboundItem.id
  1277. client['clientId'] = this.getClientId(dbInbound.protocol, client)
  1278. response.inbounds.push(dbInboundItem.id)
  1279. response.clients.push(client)
  1280. response.editIds.push(client['clientId'])
  1281. }
  1282. })
  1283. }
  1284. }
  1285. }
  1286. })
  1287. }
  1288. return response;
  1289. },
  1290. getClientId(protocol, client) {
  1291. switch (protocol) {
  1292. case Protocols.TROJAN: return client.password;
  1293. case Protocols.SHADOWSOCKS: return client.email;
  1294. default: return client.id;
  1295. }
  1296. },
  1297. checkFallback(dbInbound) {
  1298. newDbInbound = new DBInbound(dbInbound);
  1299. if (dbInbound.listen.startsWith("@")){
  1300. rootInbound = this.inbounds.find((i) =>
  1301. i.isTcp &&
  1302. ['trojan','vless'].includes(i.protocol) &&
  1303. i.settings.fallbacks.find(f => f.dest === dbInbound.listen)
  1304. );
  1305. if (rootInbound) {
  1306. newDbInbound.listen = rootInbound.listen;
  1307. newDbInbound.port = rootInbound.port;
  1308. newInbound = newDbInbound.toInbound();
  1309. newInbound.stream.security = rootInbound.stream.security;
  1310. newInbound.stream.tls = rootInbound.stream.tls;
  1311. newInbound.stream.externalProxy = rootInbound.stream.externalProxy;
  1312. newDbInbound.streamSettings = newInbound.stream.toString();
  1313. }
  1314. }
  1315. return newDbInbound;
  1316. },
  1317. showQrcode(dbInboundId, client) {
  1318. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1319. newDbInbound = this.checkFallback(dbInbound);
  1320. qrModal.show('{{ i18n "qrCode"}}', newDbInbound, client);
  1321. },
  1322. showInfo(dbInboundId, client) {
  1323. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1324. index=0;
  1325. if (dbInbound.isMultiUser()){
  1326. inbound = dbInbound.toInbound();
  1327. clients = inbound.clients;
  1328. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1329. }
  1330. newDbInbound = this.checkFallback(dbInbound);
  1331. infoModal.show(newDbInbound, index);
  1332. },
  1333. switchEnable(dbInboundId,state) {
  1334. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1335. dbInbound.enable = state;
  1336. this.submit(`/panel/inbound/update/${dbInboundId}`, dbInbound);
  1337. },
  1338. async switchEnableClient(dbInboundId, client) {
  1339. this.loading()
  1340. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1341. inbound = dbInbound.toInbound();
  1342. clients = inbound.clients;
  1343. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1344. clients[index].enable = !clients[index].enable;
  1345. clientId = this.getClientId(dbInbound.protocol, clients[index]);
  1346. await this.updateClient(clients[index], dbInboundId, clientId);
  1347. this.loading(false);
  1348. },
  1349. async submit(url, data, modal) {
  1350. const msg = await HttpUtil.postWithModal(url, data, modal);
  1351. if (msg.success) {
  1352. await this.getDBInbounds();
  1353. }
  1354. },
  1355. getInboundClients(dbInbound) {
  1356. return dbInbound.toInbound().clients;
  1357. },
  1358. resetClientTraffic(client, dbInboundId, confirmation = true) {
  1359. if (confirmation){
  1360. this.$confirm({
  1361. title: '{{ i18n "pages.inbounds.resetTraffic"}}' + ' ' + client.email,
  1362. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  1363. class: themeSwitcher.currentTheme,
  1364. okText: '{{ i18n "reset"}}',
  1365. cancelText: '{{ i18n "cancel"}}',
  1366. onOk: () => this.submit('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + client.email),
  1367. })
  1368. } else {
  1369. this.submit('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + client.email);
  1370. }
  1371. },
  1372. resetAllTraffic() {
  1373. this.$confirm({
  1374. title: '{{ i18n "pages.inbounds.resetAllTrafficTitle"}}',
  1375. content: '{{ i18n "pages.inbounds.resetAllTrafficContent"}}',
  1376. class: themeSwitcher.currentTheme,
  1377. okText: '{{ i18n "reset"}}',
  1378. cancelText: '{{ i18n "cancel"}}',
  1379. onOk: () => this.submit('/panel/inbound/resetAllTraffics'),
  1380. });
  1381. },
  1382. resetAllClientTraffics(dbInboundId) {
  1383. this.$confirm({
  1384. title: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficTitle"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficTitle"}}',
  1385. content: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficContent"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficContent"}}',
  1386. class: themeSwitcher.currentTheme,
  1387. okText: '{{ i18n "reset"}}',
  1388. cancelText: '{{ i18n "cancel"}}',
  1389. onOk: () => this.submit('/panel/inbound/resetAllClientTraffics/' + dbInboundId),
  1390. })
  1391. },
  1392. delDepletedClients(dbInboundId) {
  1393. this.$confirm({
  1394. title: '{{ i18n "pages.inbounds.delDepletedClientsTitle"}}',
  1395. content: '{{ i18n "pages.inbounds.delDepletedClientsContent"}}',
  1396. class: themeSwitcher.currentTheme,
  1397. okText: '{{ i18n "delete"}}',
  1398. cancelText: '{{ i18n "cancel"}}',
  1399. onOk: () => this.submit('/panel/inbound/delDepletedClients/' + dbInboundId),
  1400. })
  1401. },
  1402. isExpiry(dbInbound, index) {
  1403. return dbInbound.toInbound().isExpiry(index);
  1404. },
  1405. getUpStats(dbInbound, email) {
  1406. if (email.length == 0) return 0;
  1407. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1408. return clientStats ? clientStats.up : 0;
  1409. },
  1410. getDownStats(dbInbound, email) {
  1411. if (email.length == 0) return 0;
  1412. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1413. return clientStats ? clientStats.down : 0;
  1414. },
  1415. getSumStats(dbInbound, email) {
  1416. if (email.length == 0) return 0;
  1417. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1418. return clientStats ? clientStats.up + clientStats.down : 0;
  1419. },
  1420. getAllTimeClient(dbInbound, email) {
  1421. if (email.length == 0) return 0;
  1422. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1423. if (!clientStats) return 0;
  1424. return clientStats.allTime || (clientStats.up + clientStats.down);
  1425. },
  1426. getRemStats(dbInbound, email) {
  1427. if (email.length == 0) return 0;
  1428. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1429. if (!clientStats) return 0;
  1430. remained = clientStats.total - (clientStats.up + clientStats.down);
  1431. return remained>0 ? remained : 0;
  1432. },
  1433. clientStatsColor(dbInbound, email) {
  1434. if (email.length == 0) return ColorUtils.clientUsageColor();
  1435. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1436. return ColorUtils.clientUsageColor(clientStats, app.trafficDiff)
  1437. },
  1438. statsProgress(dbInbound, email) {
  1439. if (email.length == 0) return 100;
  1440. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1441. if (!clientStats) return 0;
  1442. if (clientStats.total == 0) return 100;
  1443. return 100*(clientStats.down + clientStats.up)/clientStats.total;
  1444. },
  1445. expireProgress(expTime, reset) {
  1446. now = new Date().getTime();
  1447. remainedSeconds = expTime < 0 ? -expTime/1000 : (expTime-now)/1000;
  1448. resetSeconds = reset * 86400;
  1449. if (remainedSeconds >= resetSeconds) return 0;
  1450. return 100*(1-(remainedSeconds/resetSeconds));
  1451. },
  1452. remainedDays(expTime){
  1453. if (expTime == 0) return null;
  1454. if (expTime < 0) return TimeFormatter.formatSecond(expTime/-1000);
  1455. now = new Date().getTime();
  1456. if (expTime < now) return '{{ i18n "depleted" }}';
  1457. return TimeFormatter.formatSecond((expTime-now)/1000);
  1458. },
  1459. statsExpColor(dbInbound, email){
  1460. if (email.length == 0) return '#7a316f';
  1461. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1462. if (!clientStats) return '#7a316f';
  1463. statsColor = ColorUtils.usageColor(clientStats.down + clientStats.up, this.trafficDiff, clientStats.total);
  1464. expColor = ColorUtils.usageColor(new Date().getTime(), this.expireDiff, clientStats.expiryTime);
  1465. switch (true) {
  1466. case statsColor == "red" || expColor == "red":
  1467. return "#cf3c3c"; // Red
  1468. case statsColor == "orange" || expColor == "orange":
  1469. return "#f37b24"; // Orange
  1470. case statsColor == "green" || expColor == "green":
  1471. return "#008771"; // Green
  1472. default:
  1473. return "#7a316f"; // purple
  1474. }
  1475. },
  1476. isClientEnabled(dbInbound, email) {
  1477. clientStats = dbInbound.clientStats ? dbInbound.clientStats.find(stats => stats.email === email) : null;
  1478. return clientStats ? clientStats['enable'] : true;
  1479. },
  1480. isClientOnline(email) {
  1481. return this.onlineClients.includes(email);
  1482. },
  1483. isRemovable(dbInboundId) {
  1484. return this.getInboundClients(this.dbInbounds.find(row => row.id === dbInboundId)).length > 1;
  1485. },
  1486. inboundLinks(dbInboundId) {
  1487. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1488. newDbInbound = this.checkFallback(dbInbound);
  1489. txtModal.show('{{ i18n "pages.inbounds.export"}}', newDbInbound.genInboundLinks(this.remarkModel), newDbInbound.remark);
  1490. },
  1491. exportSubs(dbInboundId) {
  1492. const dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1493. const clients = this.getInboundClients(dbInbound);
  1494. let subLinks = []
  1495. if (clients != null){
  1496. clients.forEach(c => {
  1497. if (c.subId && c.subId.length>0){
  1498. subLinks.push(this.subSettings.subURI + c.subId)
  1499. }
  1500. })
  1501. }
  1502. txtModal.show(
  1503. '{{ i18n "pages.inbounds.export"}} - {{ i18n "pages.settings.subSettings" }}',
  1504. [...new Set(subLinks)].join('\n'),
  1505. dbInbound.remark + "-Subs");
  1506. },
  1507. importInbound() {
  1508. promptModal.open({
  1509. title: '{{ i18n "pages.inbounds.importInbound" }}',
  1510. type: 'textarea',
  1511. value: '',
  1512. okText: '{{ i18n "pages.inbounds.import" }}',
  1513. confirm: async (dbInboundText) => {
  1514. await this.submit('/panel/inbound/import', {data: dbInboundText}, promptModal);
  1515. },
  1516. });
  1517. },
  1518. exportAllSubs() {
  1519. let subLinks = []
  1520. for (const dbInbound of this.dbInbounds) {
  1521. const clients = this.getInboundClients(dbInbound);
  1522. if (clients != null){
  1523. clients.forEach(c => {
  1524. if (c.subId && c.subId.length>0){
  1525. subLinks.push(this.subSettings.subURI + c.subId)
  1526. }
  1527. })
  1528. }
  1529. }
  1530. txtModal.show(
  1531. '{{ i18n "pages.inbounds.export"}} - {{ i18n "pages.settings.subSettings" }}',
  1532. [...new Set(subLinks)].join('\r\n'),
  1533. 'All-Inbounds-Subs');
  1534. },
  1535. exportAllLinks() {
  1536. let copyText = [];
  1537. for (const dbInbound of this.dbInbounds) {
  1538. copyText.push(dbInbound.genInboundLinks(this.remarkModel));
  1539. }
  1540. txtModal.show('{{ i18n "pages.inbounds.export"}}', copyText.join('\r\n'), 'All-Inbounds');
  1541. },
  1542. copy(dbInboundId) {
  1543. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1544. txtModal.show('{{ i18n "pages.inbounds.inboundData" }}', JSON.stringify(dbInbound, null, 2));
  1545. },
  1546. async startDataRefreshLoop() {
  1547. while (this.isRefreshEnabled) {
  1548. try {
  1549. await this.getDBInbounds();
  1550. } catch (e) {
  1551. console.error(e);
  1552. }
  1553. await PromiseUtil.sleep(this.refreshInterval);
  1554. }
  1555. },
  1556. toggleRefresh() {
  1557. localStorage.setItem("isRefreshEnabled", this.isRefreshEnabled);
  1558. if (this.isRefreshEnabled) {
  1559. this.startDataRefreshLoop();
  1560. }
  1561. },
  1562. changeRefreshInterval() {
  1563. localStorage.setItem("refreshInterval", this.refreshInterval);
  1564. },
  1565. async manualRefresh() {
  1566. if (!this.refreshing) {
  1567. this.loadingStates.spinning = true;
  1568. await this.getDBInbounds();
  1569. this.loadingStates.spinning = false;
  1570. }
  1571. },
  1572. pagination(obj){
  1573. if (this.pageSize > 0 && obj.length>this.pageSize) {
  1574. // Set page options based on object size
  1575. sizeOptions = [];
  1576. for (i=this.pageSize;i<=obj.length;i=i+this.pageSize) {
  1577. sizeOptions.push(i.toString());
  1578. }
  1579. // Add option to see all in one page
  1580. sizeOptions.push(i.toString());
  1581. p = {
  1582. showSizeChanger: true,
  1583. size: 'small',
  1584. position: 'bottom',
  1585. pageSize: this.pageSize,
  1586. pageSizeOptions: sizeOptions
  1587. };
  1588. return p;
  1589. }
  1590. return false
  1591. }
  1592. },
  1593. watch: {
  1594. searchKey: Utils.debounce(function (newVal) {
  1595. this.searchInbounds(newVal);
  1596. }, 500)
  1597. },
  1598. mounted() {
  1599. if (window.location.protocol !== "https:") {
  1600. this.showAlert = true;
  1601. }
  1602. this.loading();
  1603. this.getDefaultSettings();
  1604. if (this.isRefreshEnabled) {
  1605. this.startDataRefreshLoop();
  1606. }
  1607. else {
  1608. this.getDBInbounds();
  1609. }
  1610. this.loading(false);
  1611. },
  1612. computed: {
  1613. total() {
  1614. let down = 0, up = 0, allTime = 0;
  1615. let clients = 0, deactive = [], depleted = [], expiring = [];
  1616. this.dbInbounds.forEach(dbInbound => {
  1617. down += dbInbound.down;
  1618. up += dbInbound.up;
  1619. allTime += (dbInbound.allTime || (dbInbound.up + dbInbound.down));
  1620. if (this.clientCount[dbInbound.id]) {
  1621. clients += this.clientCount[dbInbound.id].clients;
  1622. deactive = deactive.concat(this.clientCount[dbInbound.id].deactive);
  1623. depleted = depleted.concat(this.clientCount[dbInbound.id].depleted);
  1624. expiring = expiring.concat(this.clientCount[dbInbound.id].expiring);
  1625. }
  1626. });
  1627. return {
  1628. down: down,
  1629. up: up,
  1630. allTime: allTime,
  1631. clients: clients,
  1632. deactive: deactive,
  1633. depleted: depleted,
  1634. expiring: expiring,
  1635. };
  1636. }
  1637. },
  1638. });
  1639. </script>
  1640. {{ template "page/body_end" .}}