inbounds.html 83 KB

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