inbounds.html 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176
  1. {{ template "page/head_start" .}}
  2. {{ template "page/head_end" .}}
  3. {{ template "page/body_start" .}}
  4. <a-layout id="app" v-cloak
  5. :class="themeSwitcher.currentTheme + ' inbounds-page'">
  6. <a-sidebar></a-sidebar>
  7. <a-layout id="content-layout">
  8. <a-layout-content>
  9. <a-spin :spinning="loadingStates.spinning" :delay="500"
  10. tip='{{ i18n "loading"}}' size="large">
  11. <transition name="list" appear>
  12. <a-alert type="error" v-if="showAlert && loadingStates.fetched"
  13. :style="{ marginBottom: '10px' }"
  14. message='{{ i18n "secAlertTitle" }}' color="red"
  15. description='{{ i18n "secAlertSsl" }}' show-icon closable>
  16. </a-alert>
  17. </transition>
  18. <transition name="list" appear>
  19. <a-row v-if="!loadingStates.fetched">
  20. <div :style="{ minHeight: 'calc(100vh - 120px)' }"></div>
  21. </a-row>
  22. <a-row :gutter="[isMobile ? 8 : 16, isMobile ? 0 : 12]" v-else>
  23. <a-col>
  24. <a-card size="small" :style="{ padding: '16px' }" hoverable>
  25. <a-row>
  26. <a-col :sm="12" :md="5">
  27. <a-custom-statistic
  28. title='{{ i18n "pages.inbounds.totalDownUp" }}'
  29. :value="`${SizeFormatter.sizeFormat(total.up)} / ${SizeFormatter.sizeFormat(total.down)}`">
  30. <template #prefix>
  31. <a-icon type="swap"></a-icon>
  32. </template>
  33. </a-custom-statistic>
  34. </a-col>
  35. <a-col :sm="12" :md="5">
  36. <a-custom-statistic
  37. title='{{ i18n "pages.inbounds.totalUsage" }}'
  38. :value="SizeFormatter.sizeFormat(total.up + total.down)"
  39. :style="{ marginTop: isMobile ? '10px' : 0 }">
  40. <template #prefix>
  41. <a-icon type="pie-chart"></a-icon>
  42. </template>
  43. </a-custom-statistic>
  44. </a-col>
  45. <a-col :sm="12" :md="5">
  46. <a-custom-statistic
  47. title='{{ i18n "pages.inbounds.allTimeTrafficUsage" }}'
  48. :value="SizeFormatter.sizeFormat(total.allTime)"
  49. :style="{ marginTop: isMobile ? '10px' : 0 }">
  50. <template #prefix>
  51. <a-icon type="history"></a-icon>
  52. </template>
  53. </a-custom-statistic>
  54. </a-col>
  55. <a-col :sm="12" :md="5">
  56. <a-custom-statistic
  57. title='{{ i18n "pages.inbounds.inboundCount" }}'
  58. :value="dbInbounds.length"
  59. :style="{ marginTop: isMobile ? '10px' : 0 }">
  60. <template #prefix>
  61. <a-icon type="bars"></a-icon>
  62. </template>
  63. </a-custom-statistic>
  64. </a-col>
  65. <a-col :sm="12" :md="4">
  66. <a-custom-statistic title='{{ i18n "clients" }}' value=" "
  67. :style="{ marginTop: isMobile ? '10px' : 0 }">
  68. <template #prefix>
  69. <a-space direction="horizontal">
  70. <a-icon type="team"></a-icon>
  71. <div>
  72. <a-back-top
  73. :target="() => document.getElementById('content-layout')"
  74. visibility-height="200"></a-back-top>
  75. <a-tag color="green">[[ total.clients ]]</a-tag>
  76. <a-popover title='{{ i18n "disabled" }}'
  77. :overlay-class-name="themeSwitcher.currentTheme">
  78. <template slot="content">
  79. <div
  80. v-for="clientEmail in total.deactive"><span>[[
  81. clientEmail ]]</span></div>
  82. </template>
  83. <a-tag v-if="total.deactive.length">[[
  84. total.deactive.length ]]</a-tag>
  85. </a-popover>
  86. <a-popover title='{{ i18n "depleted" }}'
  87. :overlay-class-name="themeSwitcher.currentTheme">
  88. <template slot="content">
  89. <div
  90. v-for="clientEmail in total.depleted"><span>[[
  91. clientEmail ]]</span></div>
  92. </template>
  93. <a-tag color="red" v-if="total.depleted.length">[[
  94. total.depleted.length ]]</a-tag>
  95. </a-popover>
  96. <a-popover title='{{ i18n "depletingSoon" }}'
  97. :overlay-class-name="themeSwitcher.currentTheme">
  98. <template slot="content">
  99. <div
  100. v-for="clientEmail in total.expiring"><span>[[
  101. clientEmail ]]</span></div>
  102. </template>
  103. <a-tag color="orange"
  104. v-if="total.expiring.length">[[
  105. total.expiring.length ]]</a-tag>
  106. </a-popover>
  107. <a-popover title='{{ i18n "online" }}'
  108. :overlay-class-name="themeSwitcher.currentTheme">
  109. <template slot="content">
  110. <div
  111. v-for="clientEmail in onlineClients"><span>[[
  112. clientEmail ]]</span></div>
  113. </template>
  114. <a-tag color="blue" v-if="onlineClients.length">[[
  115. onlineClients.length ]]</a-tag>
  116. </a-popover>
  117. </div>
  118. </a-space>
  119. </template>
  120. </a-custom-statistic>
  121. </a-col>
  122. </a-row>
  123. </a-card>
  124. </a-col>
  125. <a-col>
  126. <a-card hoverable>
  127. <template #title>
  128. <a-space direction="horizontal">
  129. <a-button type="primary" icon="plus"
  130. @click="openAddInbound">
  131. <template v-if="!isMobile">{{ i18n
  132. "pages.inbounds.addInbound" }}</template>
  133. </a-button>
  134. <a-dropdown :trigger="['click']">
  135. <a-button type="primary" icon="menu">
  136. <template v-if="!isMobile">{{ i18n
  137. "pages.inbounds.generalActions" }}</template>
  138. </a-button>
  139. <a-menu slot="overlay" @click="a => generalActions(a)"
  140. :theme="themeSwitcher.currentTheme">
  141. <a-menu-item key="import">
  142. <a-icon type="import"></a-icon>
  143. {{ i18n "pages.inbounds.importInbound" }}
  144. </a-menu-item>
  145. <a-menu-item key="export">
  146. <a-icon type="export"></a-icon>
  147. {{ i18n "pages.inbounds.export" }}
  148. </a-menu-item>
  149. <a-menu-item key="subs" v-if="subSettings.enable">
  150. <a-icon type="export"></a-icon>
  151. {{ i18n "pages.inbounds.export" }} - {{ i18n
  152. "pages.settings.subSettings" }}
  153. </a-menu-item>
  154. <a-menu-item key="resetInbounds">
  155. <a-icon type="reload"></a-icon>
  156. {{ i18n "pages.inbounds.resetAllTraffic" }}
  157. </a-menu-item>
  158. <a-menu-item key="resetClients">
  159. <a-icon type="file-done"></a-icon>
  160. {{ i18n "pages.inbounds.resetAllClientTraffics" }}
  161. </a-menu-item>
  162. <a-menu-item key="delDepletedClients"
  163. :style="{ color: '#FF4D4F' }">
  164. <a-icon type="rest"></a-icon>
  165. {{ i18n "pages.inbounds.delDepletedClients" }}
  166. </a-menu-item>
  167. </a-menu>
  168. </a-dropdown>
  169. </a-space>
  170. </template>
  171. <template #extra>
  172. <a-button-group>
  173. <a-button icon="sync" @click="manualRefresh"
  174. :loading="refreshing"></a-button>
  175. <a-popover placement="bottomRight" trigger="click"
  176. :overlay-class-name="themeSwitcher.currentTheme">
  177. <template #title>
  178. <div class="ant-custom-popover-title">
  179. <a-switch v-model="isRefreshEnabled"
  180. @change="toggleRefresh" size="small"></a-switch>
  181. <span>{{ i18n "pages.inbounds.autoRefresh" }}</span>
  182. </div>
  183. </template>
  184. <template #content>
  185. <a-space direction="vertical">
  186. <span>{{ i18n "pages.inbounds.autoRefreshInterval"
  187. }}</span>
  188. <a-select v-model="refreshInterval"
  189. :disabled="!isRefreshEnabled"
  190. :style="{ width: '100%' }"
  191. @change="changeRefreshInterval"
  192. :dropdown-class-name="themeSwitcher.currentTheme">
  193. <a-select-option v-for="key in [5,10,30,60]"
  194. :value="key*1000">[[ key ]]s</a-select-option>
  195. </a-select>
  196. </a-space>
  197. </template>
  198. <a-button icon="down"></a-button>
  199. </a-popover>
  200. </a-button-group>
  201. </template>
  202. <a-space direction="vertical">
  203. <div
  204. :style="isMobile ? {} : { display: 'flex', alignItems: 'center', justifyContent: 'flex-start' }">
  205. <a-switch v-model="enableFilter"
  206. :style="isMobile ? { marginBottom: '.5rem', display: 'flex' } : { marginRight: '.5rem' }"
  207. @change="toggleFilter">
  208. <a-icon slot="checkedChildren" type="search"></a-icon>
  209. <a-icon slot="unCheckedChildren" type="filter"></a-icon>
  210. </a-switch>
  211. <a-input v-if="!enableFilter" v-model.lazy="searchKey"
  212. placeholder='{{ i18n "search" }}' autofocus
  213. :style="{ maxWidth: '300px' }"
  214. :size="isMobile ? 'small' : ''"></a-input>
  215. <a-radio-group v-if="enableFilter" v-model="filterBy"
  216. @change="filterInbounds" button-style="solid"
  217. :size="isMobile ? 'small' : ''">
  218. <a-radio-button value>{{ i18n "none" }}</a-radio-button>
  219. <a-radio-button value="deactive">{{ i18n "disabled"
  220. }}</a-radio-button>
  221. <a-radio-button value="depleted">{{ i18n "depleted"
  222. }}</a-radio-button>
  223. <a-radio-button value="expiring">{{ i18n "depletingSoon"
  224. }}</a-radio-button>
  225. <a-radio-button value="online">{{ i18n "online"
  226. }}</a-radio-button>
  227. </a-radio-group>
  228. </div>
  229. <a-table :columns="isMobile ? mobileColumns : columns"
  230. :row-key="dbInbound => dbInbound.id"
  231. :data-source="searchedInbounds"
  232. :scroll="isMobile ? {} : { x: 1000 }"
  233. :pagination=pagination(searchedInbounds)
  234. :expand-icon-as-cell="false" :expand-row-by-click="false"
  235. :expand-icon-column-index="0" :indent-size="0"
  236. :row-class-name="dbInbound => (dbInbound.isMultiUser() ? '' : 'hideExpandIcon')"
  237. :style="{ marginTop: '10px' }"
  238. :locale='{ filterConfirm: `{{ i18n "confirm" }}`, filterReset: `{{ i18n "reset" }}`, emptyText: `{{ i18n "noData" }}` }'>
  239. <template slot="action" slot-scope="text, dbInbound">
  240. <a-dropdown :trigger="['click']">
  241. <a-icon @click="e => e.preventDefault()" type="more"
  242. :style="{ fontSize: '20px', textDecoration: 'solid' }"></a-icon>
  243. <a-menu slot="overlay"
  244. @click="a => clickAction(a, dbInbound)"
  245. :theme="themeSwitcher.currentTheme">
  246. <a-menu-item key="edit">
  247. <a-icon type="edit"></a-icon>
  248. {{ i18n "edit" }}
  249. </a-menu-item>
  250. <a-menu-item key="qrcode"
  251. v-if="(dbInbound.isSS && !dbInbound.toInbound().isSSMultiUser) || dbInbound.isWireguard">
  252. <a-icon type="qrcode"></a-icon>
  253. {{ i18n "qrCode" }}
  254. </a-menu-item>
  255. <template v-if="dbInbound.isMultiUser()">
  256. <a-menu-item key="addClient">
  257. <a-icon type="user-add"></a-icon>
  258. {{ i18n "pages.client.add"}}
  259. </a-menu-item>
  260. <a-menu-item key="addBulkClient">
  261. <a-icon type="usergroup-add"></a-icon>
  262. {{ i18n "pages.client.bulk"}}
  263. </a-menu-item>
  264. <a-menu-item key="copyClients">
  265. <a-icon type="copy"></a-icon>
  266. {{ i18n "pages.client.copyFromInbound"}}
  267. </a-menu-item>
  268. <a-menu-item key="resetClients">
  269. <a-icon type="file-done"></a-icon>
  270. {{ i18n
  271. "pages.inbounds.resetInboundClientTraffics"}}
  272. </a-menu-item>
  273. <a-menu-item key="export">
  274. <a-icon type="export"></a-icon>
  275. {{ i18n "pages.inbounds.export"}}
  276. </a-menu-item>
  277. <a-menu-item key="subs" v-if="subSettings.enable">
  278. <a-icon type="export"></a-icon>
  279. {{ i18n "pages.inbounds.export"}} - {{ i18n
  280. "pages.settings.subSettings" }}
  281. </a-menu-item>
  282. <a-menu-item key="delDepletedClients"
  283. :style="{ color: '#FF4D4F' }">
  284. <a-icon type="rest"></a-icon>
  285. {{ i18n "pages.inbounds.delDepletedClients" }}
  286. </a-menu-item>
  287. </template>
  288. <template v-else>
  289. <a-menu-item key="showInfo">
  290. <a-icon type="info-circle"></a-icon>
  291. {{ i18n "info"}}
  292. </a-menu-item>
  293. </template>
  294. <a-menu-item key="clipboard">
  295. <a-icon type="copy"></a-icon>
  296. {{ i18n "pages.inbounds.exportInbound" }}
  297. </a-menu-item>
  298. <a-menu-item key="resetTraffic">
  299. <a-icon type="retweet"></a-icon> {{ i18n
  300. "pages.inbounds.resetTraffic" }}
  301. </a-menu-item>
  302. <a-menu-item key="clone">
  303. <a-icon type="block"></a-icon> {{ i18n
  304. "pages.inbounds.clone"}}
  305. </a-menu-item>
  306. <a-menu-item key="delete">
  307. <span :style="{ color: '#FF4D4F' }">
  308. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  309. </span>
  310. </a-menu-item>
  311. <a-menu-item v-if="isMobile">
  312. <a-switch size="small" v-model="dbInbound.enable"
  313. @change="switchEnable(dbInbound.id,dbInbound.enable)"></a-switch>
  314. {{ i18n "pages.inbounds.enable" }}
  315. </a-menu-item>
  316. </a-menu>
  317. </a-dropdown>
  318. </template>
  319. <template slot="protocol" slot-scope="text, dbInbound">
  320. <a-tag :style="{ margin: '0' }" color="purple">[[
  321. dbInbound.protocol ]]</a-tag>
  322. <template
  323. v-if="dbInbound.isVMess || dbInbound.isVLess || dbInbound.isTrojan || dbInbound.isSS">
  324. <a-tag :style="{ margin: '0' }" color="green">[[
  325. dbInbound.toInbound().stream.network ]]</a-tag>
  326. <a-tag :style="{ margin: '0' }"
  327. v-if="dbInbound.toInbound().stream.isTls"
  328. color="blue">TLS</a-tag>
  329. <a-tag :style="{ margin: '0' }"
  330. v-if="dbInbound.toInbound().stream.isReality"
  331. color="blue">Reality</a-tag>
  332. </template>
  333. </template>
  334. <template slot="clients" slot-scope="text, dbInbound">
  335. <template v-if="clientCount[dbInbound.id]">
  336. <a-tag :style="{ margin: '0' }" color="green">[[
  337. clientCount[dbInbound.id].clients ]]</a-tag>
  338. <a-popover title='{{ i18n "disabled" }}'
  339. :overlay-class-name="themeSwitcher.currentTheme">
  340. <template slot="content">
  341. <div
  342. v-for="clientEmail in clientCount[dbInbound.id].deactive"
  343. :key="clientEmail"
  344. class="client-popup-item">
  345. <span>[[ clientEmail ]]</span>
  346. <a-tooltip
  347. :overlay-class-name="themeSwitcher.currentTheme">
  348. <template #title>
  349. [[
  350. clientCount[dbInbound.id].comments.get(clientEmail)
  351. ]]
  352. </template>
  353. <a-icon type="message"
  354. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  355. </a-tooltip>
  356. </div>
  357. </template>
  358. <a-tag :style="{ margin: '0', padding: '0 2px' }"
  359. v-if="clientCount[dbInbound.id].deactive.length">[[
  360. clientCount[dbInbound.id].deactive.length ]]</a-tag>
  361. </a-popover>
  362. <a-popover title='{{ i18n "depleted" }}'
  363. :overlay-class-name="themeSwitcher.currentTheme">
  364. <template slot="content">
  365. <div
  366. v-for="clientEmail in clientCount[dbInbound.id].depleted"
  367. :key="clientEmail"
  368. class="client-popup-item">
  369. <span>[[ clientEmail ]]</span>
  370. <a-tooltip
  371. :overlay-class-name="themeSwitcher.currentTheme">
  372. <template #title>
  373. [[
  374. clientCount[dbInbound.id].comments.get(clientEmail)
  375. ]]
  376. </template>
  377. <a-icon type="message"
  378. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  379. </a-tooltip>
  380. </div>
  381. </template>
  382. <a-tag :style="{ margin: '0', padding: '0 2px' }"
  383. color="red"
  384. v-if="clientCount[dbInbound.id].depleted.length">[[
  385. clientCount[dbInbound.id].depleted.length ]]</a-tag>
  386. </a-popover>
  387. <a-popover title='{{ i18n "depletingSoon" }}'
  388. :overlay-class-name="themeSwitcher.currentTheme">
  389. <template slot="content">
  390. <div
  391. v-for="clientEmail in clientCount[dbInbound.id].expiring"
  392. :key="clientEmail"
  393. class="client-popup-item">
  394. <span>[[ clientEmail ]]</span>
  395. <a-tooltip
  396. :overlay-class-name="themeSwitcher.currentTheme">
  397. <template #title>
  398. [[
  399. clientCount[dbInbound.id].comments.get(clientEmail)
  400. ]]
  401. </template>
  402. <a-icon type="message"
  403. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  404. </a-tooltip>
  405. </div>
  406. </template>
  407. <a-tag :style="{ margin: '0', padding: '0 2px' }"
  408. color="orange"
  409. v-if="clientCount[dbInbound.id].expiring.length">[[
  410. clientCount[dbInbound.id].expiring.length ]]</a-tag>
  411. </a-popover>
  412. <a-popover title='{{ i18n "online" }}'
  413. :overlay-class-name="themeSwitcher.currentTheme">
  414. <template slot="content">
  415. <div
  416. v-for="clientEmail in clientCount[dbInbound.id].online"
  417. :key="clientEmail"
  418. class="client-popup-item">
  419. <span>[[ clientEmail ]]</span>
  420. <a-tooltip
  421. :overlay-class-name="themeSwitcher.currentTheme">
  422. <template #title>
  423. [[
  424. clientCount[dbInbound.id].comments.get(clientEmail)
  425. ]]
  426. </template>
  427. <a-icon type="message"
  428. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  429. </a-tooltip>
  430. </div>
  431. </template>
  432. <a-tag :style="{ margin: '0', padding: '0 2px' }"
  433. color="blue"
  434. v-if="clientCount[dbInbound.id].online.length">[[
  435. clientCount[dbInbound.id].online.length
  436. ]]</a-tag>
  437. </a-popover>
  438. </template>
  439. </template>
  440. <template slot="traffic" slot-scope="text, dbInbound">
  441. <a-popover
  442. :overlay-class-name="themeSwitcher.currentTheme">
  443. <template slot="content">
  444. <table cellpadding="2" width="100%">
  445. <tr>
  446. <td>↑[[ SizeFormatter.sizeFormat(dbInbound.up)
  447. ]]</td>
  448. <td>↓[[ SizeFormatter.sizeFormat(dbInbound.down)
  449. ]]</td>
  450. </tr>
  451. <tr
  452. v-if="dbInbound.total > 0 && dbInbound.up + dbInbound.down < dbInbound.total">
  453. <td>{{ i18n "remained" }}</td>
  454. <td>[[ SizeFormatter.sizeFormat(dbInbound.total -
  455. dbInbound.up - dbInbound.down) ]]</td>
  456. </tr>
  457. </table>
  458. </template>
  459. <a-tag
  460. :color="ColorUtils.usageColor(dbInbound.up + dbInbound.down, app.trafficDiff, dbInbound.total)">
  461. [[ SizeFormatter.sizeFormat(dbInbound.up +
  462. dbInbound.down) ]] /
  463. <template v-if="dbInbound.total > 0">
  464. [[ SizeFormatter.sizeFormat(dbInbound.total) ]]
  465. </template>
  466. <template v-else>
  467. <svg height="10px" width="14px"
  468. viewBox="0 0 640 512" fill="currentColor">
  469. <path
  470. 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"
  471. fill="currentColor"></path>
  472. </svg>
  473. </template>
  474. </a-tag>
  475. </a-popover>
  476. </template>
  477. <template slot="allTimeInbound"
  478. slot-scope="text, dbInbound">
  479. <a-tag>[[ SizeFormatter.sizeFormat(dbInbound.allTime || 0)
  480. ]]</a-tag>
  481. </template>
  482. <template slot="enable" slot-scope="text, dbInbound">
  483. <a-switch v-model="dbInbound.enable"
  484. @change="switchEnable(dbInbound.id,dbInbound.enable)"></a-switch>
  485. </template>
  486. <template slot="expiryTime" slot-scope="text, dbInbound">
  487. <a-popover v-if="dbInbound.expiryTime > 0"
  488. :overlay-class-name="themeSwitcher.currentTheme">
  489. <template slot="content">
  490. [[ IntlUtil.formatDate(dbInbound.expiryTime) ]]
  491. </template>
  492. <a-tag :style="{ minWidth: '50px' }"
  493. :color="ColorUtils.usageColor(new Date().getTime(), app.expireDiff, dbInbound._expiryTime)">
  494. [[ IntlUtil.formatRelativeTime(dbInbound.expiryTime)
  495. ]]
  496. </a-tag>
  497. </a-popover>
  498. <a-tag v-else color="purple" class="infinite-tag">
  499. <svg height="10px" width="14px" viewBox="0 0 640 512"
  500. fill="currentColor">
  501. <path
  502. 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"
  503. fill="currentColor"></path>
  504. </svg>
  505. </a-tag>
  506. </template>
  507. <template slot="info" slot-scope="text, dbInbound">
  508. <a-popover placement="bottomRight"
  509. :overlay-class-name="themeSwitcher.currentTheme"
  510. trigger="click">
  511. <template slot="content">
  512. <table cellpadding="2">
  513. <tr>
  514. <td>{{ i18n "pages.inbounds.protocol" }}</td>
  515. <td>
  516. <a-tag :style="{ margin: '0' }"
  517. color="purple">[[ dbInbound.protocol
  518. ]]</a-tag>
  519. <template
  520. v-if="dbInbound.isVMess || dbInbound.isVLess || dbInbound.isTrojan || dbInbound.isSS">
  521. <a-tag :style="{ margin: '0' }"
  522. color="blue">[[
  523. dbInbound.toInbound().stream.network
  524. ]]</a-tag>
  525. <a-tag :style="{ margin: '0' }"
  526. v-if="dbInbound.toInbound().stream.isTls"
  527. color="green">tls</a-tag>
  528. <a-tag :style="{ margin: '0' }"
  529. v-if="dbInbound.toInbound().stream.isReality"
  530. color="green">reality</a-tag>
  531. </template>
  532. </td>
  533. </tr>
  534. <tr>
  535. <td>{{ i18n "pages.inbounds.port" }}</td>
  536. <td><a-tag>[[ dbInbound.port ]]</a-tag></td>
  537. </tr>
  538. <tr v-if="clientCount[dbInbound.id]">
  539. <td>{{ i18n "clients" }}</td>
  540. <td>
  541. <a-tag :style="{ margin: '0' }" color="blue">[[
  542. clientCount[dbInbound.id].clients
  543. ]]</a-tag>
  544. <a-popover title='{{ i18n "disabled" }}'
  545. :overlay-class-name="themeSwitcher.currentTheme">
  546. <template slot="content">
  547. <div
  548. v-for="clientEmail in clientCount[dbInbound.id].deactive"
  549. :key="clientEmail"
  550. class="client-popup-item">
  551. <span>[[ clientEmail ]]</span>
  552. <a-tooltip
  553. :overlay-class-name="themeSwitcher.currentTheme">
  554. <template #title>
  555. [[
  556. clientCount[dbInbound.id].comments.get(clientEmail)
  557. ]]
  558. </template>
  559. <a-icon type="message"
  560. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  561. </a-tooltip>
  562. </div>
  563. </template>
  564. <a-tag
  565. :style="{ margin: '0', padding: '0 2px' }"
  566. v-if="clientCount[dbInbound.id].deactive.length">[[
  567. clientCount[dbInbound.id].deactive.length
  568. ]]</a-tag>
  569. </a-popover>
  570. <a-popover title='{{ i18n "depleted" }}'
  571. :overlay-class-name="themeSwitcher.currentTheme">
  572. <template slot="content">
  573. <div
  574. v-for="clientEmail in clientCount[dbInbound.id].depleted"
  575. :key="clientEmail"
  576. class="client-popup-item">
  577. <span>[[ clientEmail ]]</span>
  578. <a-tooltip
  579. :overlay-class-name="themeSwitcher.currentTheme">
  580. <template #title>
  581. [[
  582. clientCount[dbInbound.id].comments.get(clientEmail)
  583. ]]
  584. </template>
  585. <a-icon type="message"
  586. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  587. </a-tooltip>
  588. </div>
  589. </template>
  590. <a-tag
  591. :style="{ margin: '0', padding: '0 2px' }"
  592. color="red"
  593. v-if="clientCount[dbInbound.id].depleted.length">[[
  594. clientCount[dbInbound.id].depleted.length
  595. ]]</a-tag>
  596. </a-popover>
  597. <a-popover title='{{ i18n "depletingSoon" }}'
  598. :overlay-class-name="themeSwitcher.currentTheme">
  599. <template slot="content">
  600. <div
  601. v-for="clientEmail in clientCount[dbInbound.id].expiring"
  602. :key="clientEmail"
  603. class="client-popup-item">
  604. <span>[[ clientEmail ]]</span>
  605. <a-tooltip
  606. :overlay-class-name="themeSwitcher.currentTheme">
  607. <template #title>
  608. [[
  609. clientCount[dbInbound.id].comments.get(clientEmail)
  610. ]]
  611. </template>
  612. <a-icon type="message"
  613. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  614. </a-tooltip>
  615. </div>
  616. </template>
  617. <a-tag
  618. :style="{ margin: '0', padding: '0 2px' }"
  619. color="orange"
  620. v-if="clientCount[dbInbound.id].expiring.length">[[
  621. clientCount[dbInbound.id].expiring.length
  622. ]]</a-tag>
  623. </a-popover>
  624. <a-popover title='{{ i18n "online" }}'
  625. :overlay-class-name="themeSwitcher.currentTheme">
  626. <template slot="content">
  627. <div
  628. v-for="clientEmail in clientCount[dbInbound.id].online"
  629. :key="clientEmail"
  630. class="client-popup-item">
  631. <span>[[ clientEmail ]]</span>
  632. <a-tooltip
  633. :overlay-class-name="themeSwitcher.currentTheme">
  634. <template #title>
  635. [[
  636. clientCount[dbInbound.id].comments.get(clientEmail)
  637. ]]
  638. </template>
  639. <a-icon type="message"
  640. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  641. </a-tooltip>
  642. </div>
  643. </template>
  644. <a-tag
  645. :style="{ margin: '0', padding: '0 2px' }"
  646. color="green"
  647. v-if="clientCount[dbInbound.id].online.length">[[
  648. clientCount[dbInbound.id].online.length
  649. ]]</a-tag>
  650. </a-popover>
  651. </td>
  652. </tr>
  653. <tr>
  654. <td>{{ i18n "pages.inbounds.traffic" }}</td>
  655. <td>
  656. <a-popover
  657. :overlay-class-name="themeSwitcher.currentTheme">
  658. <template slot="content">
  659. <table cellpadding="2" width="100%">
  660. <tr>
  661. <td>↑[[
  662. SizeFormatter.sizeFormat(dbInbound.up)
  663. ]]</td>
  664. <td>↓[[
  665. SizeFormatter.sizeFormat(dbInbound.down)
  666. ]]</td>
  667. </tr>
  668. <tr
  669. v-if="dbInbound.total > 0 && dbInbound.up + dbInbound.down < dbInbound.total">
  670. <td>{{ i18n "remained" }}</td>
  671. <td>[[
  672. SizeFormatter.sizeFormat(dbInbound.total
  673. - dbInbound.up - dbInbound.down)
  674. ]]</td>
  675. </tr>
  676. </table>
  677. </template>
  678. <a-tag
  679. :color="ColorUtils.usageColor(dbInbound.up + dbInbound.down, app.trafficDiff, dbInbound.total)">
  680. [[ SizeFormatter.sizeFormat(dbInbound.up +
  681. dbInbound.down) ]] /
  682. <template v-if="dbInbound.total > 0">
  683. [[
  684. SizeFormatter.sizeFormat(dbInbound.total)
  685. ]]
  686. </template>
  687. <template v-else>
  688. <svg height="10px" width="14px"
  689. viewBox="0 0 640 512"
  690. fill="currentColor">
  691. <path
  692. 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"
  693. fill="currentColor"></path>
  694. </svg>
  695. </template>
  696. </a-tag>
  697. </a-popover>
  698. </td>
  699. </tr>
  700. <tr>
  701. <td>{{ i18n "pages.inbounds.expireDate" }}</td>
  702. <td>
  703. <a-tag
  704. :style="{ minWidth: '50px', textAlign: 'center' }"
  705. v-if="dbInbound.expiryTime > 0"
  706. :color="dbInbound.isExpiry? 'red': 'blue'">
  707. [[ IntlUtil.formatDate(dbInbound.expiryTime)
  708. ]]
  709. </a-tag>
  710. <a-tag v-else :style="{ textAlign: 'center' }"
  711. color="purple" class="infinite-tag">
  712. <svg height="10px" width="14px"
  713. viewBox="0 0 640 512" fill="currentColor">
  714. <path
  715. 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"
  716. fill="currentColor"></path>
  717. </svg>
  718. </a-tag>
  719. </td>
  720. </tr>
  721. <tr>
  722. <td>{{ i18n
  723. "pages.inbounds.periodicTrafficResetTitle"
  724. }}</td>
  725. <td>
  726. <a-tag color="blue">[[ dbInbound.trafficReset
  727. ]]</a-tag>
  728. </td>
  729. </tr>
  730. </table>
  731. </template>
  732. <a-badge>
  733. <a-icon v-if="!dbInbound.enable" slot="count"
  734. type="pause-circle"
  735. :style="{ color: themeSwitcher.isDarkTheme ? '#2c3950' : '#bcbcbc' }"></a-icon>
  736. <a-button shape="round" size="small"
  737. :style="{ fontSize: '14px', padding: '0 10px' }">
  738. <a-icon type="info"></a-icon>
  739. </a-button>
  740. </a-badge>
  741. </a-popover>
  742. </template>
  743. <template slot="expandedRowRender" slot-scope="record">
  744. <a-table :row-key="client => client.id"
  745. :columns="isMobile ? innerMobileColumns : innerColumns"
  746. :data-source="getInboundClients(record)"
  747. :pagination=pagination(getInboundClients(record))
  748. :style="{ margin: `-10px ${isMobile ? '2px' : '22px'} -11px` }">
  749. {{template "component/aClientTable"}}
  750. </a-table>
  751. </template>
  752. </a-table>
  753. </a-space>
  754. </a-card>
  755. </a-col>
  756. </a-row>
  757. </transition>
  758. </a-spin>
  759. </a-layout-content>
  760. </a-layout>
  761. </a-layout>
  762. {{template "page/body_scripts" .}}
  763. <script
  764. src="{{ .base_path }}assets/qrcode/qrious2.min.js?{{ .cur_ver }}"></script>
  765. <script src="{{ .base_path }}assets/uri/URI.min.js?{{ .cur_ver }}"></script>
  766. <script
  767. src="{{ .base_path }}assets/js/model/reality_targets.js?{{ .cur_ver }}"></script>
  768. <script
  769. src="{{ .base_path }}assets/js/model/inbound.js?{{ .cur_ver }}"></script>
  770. <script
  771. src="{{ .base_path }}assets/js/model/dbinbound.js?{{ .cur_ver }}"></script>
  772. {{template "component/aSidebar" .}}
  773. {{template "component/aThemeSwitch" .}}
  774. {{template "component/aCustomStatistic" .}}
  775. {{template "component/aPersianDatepicker" .}}
  776. {{template "modals/inboundModal"}}
  777. {{template "modals/promptModal"}}
  778. {{template "modals/qrcodeModal"}}
  779. {{template "modals/textModal"}}
  780. {{template "modals/inboundInfoModal"}}
  781. {{template "modals/clientsModal"}}
  782. {{template "modals/clientsBulkModal"}}
  783. <a-modal id="copy-clients-modal"
  784. :title="copyClientsModal.title"
  785. :visible="copyClientsModal.visible"
  786. :confirm-loading="copyClientsModal.confirmLoading"
  787. ok-text='{{ i18n "pages.client.copySelected" }}'
  788. cancel-text='{{ i18n "close" }}'
  789. :class="themeSwitcher.currentTheme"
  790. :closable="true"
  791. :mask-closable="false"
  792. @ok="() => copyClientsModal.ok()"
  793. @cancel="() => copyClientsModal.close()"
  794. width="900px">
  795. <a-space direction="vertical" style="width: 100%;">
  796. <div>
  797. <div style="margin-bottom: 6px;">{{ i18n "pages.client.copySource" }}</div>
  798. <a-select v-model="copyClientsModal.sourceInboundId"
  799. style="width: 100%;"
  800. :dropdown-class-name="themeSwitcher.currentTheme"
  801. @change="id => copyClientsModal.onSourceChange(id)">
  802. <a-select-option v-for="item in copyClientsModal.sources"
  803. :key="item.id"
  804. :value="item.id">
  805. [[ item.label ]]
  806. </a-select-option>
  807. </a-select>
  808. </div>
  809. <div v-if="copyClientsModal.sourceInboundId">
  810. <a-space style="margin-bottom: 10px;">
  811. <a-button size="small" @click="() => copyClientsModal.selectAll()">{{ i18n "pages.client.selectAll" }}</a-button>
  812. <a-button size="small" @click="() => copyClientsModal.clearAll()">{{ i18n "pages.client.clearAll" }}</a-button>
  813. </a-space>
  814. <a-table :columns="copyClientsColumns"
  815. :data-source="copyClientsModal.sourceClients"
  816. :pagination="false"
  817. size="small"
  818. :row-key="item => item.email"
  819. :scroll="{ y: 280 }">
  820. <template slot="emailCheckbox" slot-scope="text, record">
  821. <a-checkbox :checked="copyClientsModal.selectedEmails.includes(record.email)"
  822. @change="event => copyClientsModal.toggleEmail(record.email, event.target.checked)">
  823. [[ record.email ]]
  824. </a-checkbox>
  825. </template>
  826. </a-table>
  827. </div>
  828. <div v-if="copyClientsModal.showFlow">
  829. <div style="margin-bottom: 6px;">{{ i18n "pages.client.copyFlowLabel" }}</div>
  830. <a-select v-model="copyClientsModal.flow"
  831. style="width: 100%;"
  832. :dropdown-class-name="themeSwitcher.currentTheme"
  833. allow-clear>
  834. <a-select-option value="">{{ i18n "none" }}</a-select-option>
  835. <a-select-option value="xtls-rprx-vision">xtls-rprx-vision</a-select-option>
  836. <a-select-option value="xtls-rprx-vision-udp443">xtls-rprx-vision-udp443</a-select-option>
  837. </a-select>
  838. <div style="margin-top: 4px; font-size: 12px; opacity: 0.7;">
  839. {{ i18n "pages.client.copyFlowHint" }}
  840. </div>
  841. </div>
  842. <div v-if="copyClientsModal.selectedEmails.length > 0">
  843. <div style="margin-bottom: 4px;">{{ i18n "pages.client.copyEmailPreview" }}</div>
  844. <div style="max-height: 120px; overflow-y: auto;">
  845. <a-tag v-for="preview in previewEmails" :key="preview" style="margin-bottom: 4px;">
  846. [[ preview ]]
  847. </a-tag>
  848. </div>
  849. </div>
  850. </a-space>
  851. </a-modal>
  852. <script>
  853. const copyClientsColumns = [
  854. { title: '{{ i18n "pages.inbounds.email" }}', width: 300, scopedSlots: { customRender: 'emailCheckbox' } },
  855. { title: '{{ i18n "pages.inbounds.traffic" }}', width: 160, dataIndex: 'trafficLabel' },
  856. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 180, dataIndex: 'expiryLabel' },
  857. ];
  858. const copyClientsModal = {
  859. visible: false,
  860. confirmLoading: false,
  861. title: '',
  862. targetInboundId: 0,
  863. targetInboundRemark: '',
  864. targetProtocol: '',
  865. showFlow: false,
  866. flow: '',
  867. sourceInboundId: undefined,
  868. sources: [],
  869. sourceClients: [],
  870. selectedEmails: [],
  871. show(targetDbInbound) {
  872. if (!targetDbInbound) return;
  873. const sources = app.dbInbounds
  874. .filter(row => row.id !== targetDbInbound.id && typeof row.isMultiUser === 'function' && row.isMultiUser())
  875. .map(row => {
  876. const clients = app.getInboundClients(row) || [];
  877. return { id: row.id, label: `${row.remark} (${row.protocol}, ${clients.length})` };
  878. });
  879. let showFlow = false;
  880. try {
  881. const targetInbound = targetDbInbound.toInbound();
  882. showFlow = !!(targetInbound && typeof targetInbound.canEnableTlsFlow === 'function' && targetInbound.canEnableTlsFlow());
  883. } catch (e) {
  884. showFlow = false;
  885. }
  886. copyClientsModal.targetInboundId = targetDbInbound.id;
  887. copyClientsModal.targetInboundRemark = targetDbInbound.remark;
  888. copyClientsModal.targetProtocol = targetDbInbound.protocol;
  889. copyClientsModal.showFlow = showFlow;
  890. copyClientsModal.flow = '';
  891. copyClientsModal.title = `{{ i18n "pages.client.copyToInbound" }} ${targetDbInbound.remark}`;
  892. copyClientsModal.sources = sources;
  893. copyClientsModal.sourceInboundId = undefined;
  894. copyClientsModal.sourceClients = [];
  895. copyClientsModal.selectedEmails = [];
  896. copyClientsModal.confirmLoading = false;
  897. copyClientsModal.visible = true;
  898. },
  899. close() {
  900. copyClientsModal.visible = false;
  901. copyClientsModal.confirmLoading = false;
  902. },
  903. onSourceChange(sourceInboundId) {
  904. copyClientsModal.selectedEmails = [];
  905. const sourceInbound = app.dbInbounds.find(row => row.id === Number(sourceInboundId));
  906. if (!sourceInbound) {
  907. copyClientsModal.sourceClients = [];
  908. return;
  909. }
  910. const sourceClients = app.getInboundClients(sourceInbound) || [];
  911. copyClientsModal.sourceClients = sourceClients.map(client => {
  912. const stats = app.getClientStats(sourceInbound, client.email);
  913. const used = stats ? ((stats.up || 0) + (stats.down || 0)) : 0;
  914. let expiryLabel = '{{ i18n "unlimited" }}';
  915. if (client.expiryTime > 0) {
  916. expiryLabel = IntlUtil.formatDate(client.expiryTime);
  917. } else if (client.expiryTime < 0) {
  918. expiryLabel = `${-client.expiryTime / 86400000}d`;
  919. }
  920. return {
  921. email: client.email,
  922. trafficLabel: SizeFormatter.sizeFormat(used),
  923. expiryLabel,
  924. };
  925. });
  926. },
  927. toggleEmail(email, checked) {
  928. const selected = copyClientsModal.selectedEmails.slice();
  929. if (checked) {
  930. if (!selected.includes(email)) selected.push(email);
  931. } else {
  932. const idx = selected.indexOf(email);
  933. if (idx >= 0) selected.splice(idx, 1);
  934. }
  935. copyClientsModal.selectedEmails = selected;
  936. },
  937. selectAll() {
  938. copyClientsModal.selectedEmails = copyClientsModal.sourceClients.map(item => item.email);
  939. },
  940. clearAll() {
  941. copyClientsModal.selectedEmails = [];
  942. },
  943. async ok() {
  944. if (!copyClientsModal.sourceInboundId) {
  945. app.$message.error('{{ i18n "pages.client.copySelectSourceFirst" }}');
  946. return;
  947. }
  948. copyClientsModal.confirmLoading = true;
  949. const payload = {
  950. sourceInboundId: copyClientsModal.sourceInboundId,
  951. clientEmails: copyClientsModal.selectedEmails,
  952. };
  953. if (copyClientsModal.showFlow && copyClientsModal.flow) {
  954. payload.flow = copyClientsModal.flow;
  955. }
  956. try {
  957. const msg = await HttpUtil.post(`/panel/api/inbounds/${copyClientsModal.targetInboundId}/copyClients`, payload);
  958. if (!msg || !msg.success) return;
  959. const obj = msg.obj || {};
  960. const addedCount = (obj.added || []).length;
  961. const errorList = obj.errors || [];
  962. if (addedCount > 0) {
  963. app.$message.success(`{{ i18n "pages.client.copyResultSuccess" }}: ${addedCount}`);
  964. } else {
  965. app.$message.warning('{{ i18n "pages.client.copyResultNone" }}');
  966. }
  967. if (errorList.length > 0) {
  968. app.$message.error(`{{ i18n "pages.client.copyResultErrors" }}: ${errorList.join('; ')}`);
  969. }
  970. copyClientsModal.close();
  971. await app.getDBInbounds();
  972. } finally {
  973. copyClientsModal.confirmLoading = false;
  974. }
  975. },
  976. };
  977. const copyClientsModalApp = new Vue({
  978. delimiters: ['[[', ']]'],
  979. el: '#copy-clients-modal',
  980. data: {
  981. copyClientsModal,
  982. copyClientsColumns,
  983. themeSwitcher,
  984. },
  985. computed: {
  986. previewEmails() {
  987. if (!this.copyClientsModal.targetInboundId) return [];
  988. return this.copyClientsModal.selectedEmails.map(email => `${email}_${this.copyClientsModal.targetInboundId}`);
  989. },
  990. },
  991. });
  992. </script>
  993. <script>
  994. const columns = [{
  995. title: "ID",
  996. align: 'right',
  997. dataIndex: "id",
  998. width: 30,
  999. responsive: ["xs"],
  1000. }, {
  1001. title: '{{ i18n "pages.inbounds.operate" }}',
  1002. align: 'center',
  1003. width: 30,
  1004. scopedSlots: { customRender: 'action' },
  1005. }, {
  1006. title: '{{ i18n "pages.inbounds.enable" }}',
  1007. align: 'center',
  1008. width: 35,
  1009. scopedSlots: { customRender: 'enable' },
  1010. }, {
  1011. title: '{{ i18n "pages.inbounds.remark" }}',
  1012. align: 'center',
  1013. width: 60,
  1014. dataIndex: "remark",
  1015. }, {
  1016. title: '{{ i18n "pages.inbounds.port" }}',
  1017. align: 'center',
  1018. dataIndex: "port",
  1019. width: 40,
  1020. }, {
  1021. title: '{{ i18n "pages.inbounds.protocol" }}',
  1022. align: 'left',
  1023. width: 70,
  1024. scopedSlots: { customRender: 'protocol' },
  1025. }, {
  1026. title: '{{ i18n "clients" }}',
  1027. align: 'left',
  1028. width: 50,
  1029. scopedSlots: { customRender: 'clients' },
  1030. }, {
  1031. title: '{{ i18n "pages.inbounds.traffic" }}',
  1032. align: 'center',
  1033. width: 90,
  1034. scopedSlots: { customRender: 'traffic' },
  1035. }, {
  1036. title: '{{ i18n "pages.inbounds.allTimeTraffic" }}',
  1037. align: 'center',
  1038. width: 60,
  1039. scopedSlots: { customRender: 'allTimeInbound' },
  1040. }, {
  1041. title: '{{ i18n "pages.inbounds.expireDate" }}',
  1042. align: 'center',
  1043. width: 40,
  1044. scopedSlots: { customRender: 'expiryTime' },
  1045. }];
  1046. const mobileColumns = [{
  1047. title: "ID",
  1048. align: 'right',
  1049. dataIndex: "id",
  1050. width: 10,
  1051. responsive: ["s"],
  1052. }, {
  1053. title: '{{ i18n "pages.inbounds.operate" }}',
  1054. align: 'center',
  1055. width: 25,
  1056. scopedSlots: { customRender: 'action' },
  1057. }, {
  1058. title: '{{ i18n "pages.inbounds.remark" }}',
  1059. align: 'left',
  1060. width: 70,
  1061. dataIndex: "remark",
  1062. }, {
  1063. title: '{{ i18n "pages.inbounds.info" }}',
  1064. align: 'center',
  1065. width: 10,
  1066. scopedSlots: { customRender: 'info' },
  1067. }];
  1068. const innerColumns = [
  1069. { title: '{{ i18n "pages.inbounds.operate" }}', width: 70, scopedSlots: { customRender: 'actions' } },
  1070. { title: '{{ i18n "pages.inbounds.enable" }}', width: 30, scopedSlots: { customRender: 'enable' } },
  1071. { title: '{{ i18n "online" }}', width: 32, scopedSlots: { customRender: 'online' } },
  1072. { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } },
  1073. { title: '{{ i18n "pages.inbounds.traffic" }}', width: 80, align: 'center', scopedSlots: { customRender: 'traffic' } },
  1074. { title: '{{ i18n "pages.inbounds.allTimeTraffic" }}', width: 60, align: 'center', scopedSlots: { customRender: 'allTime' } },
  1075. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 80, align: 'center', scopedSlots: { customRender: 'expiryTime' } },
  1076. ];
  1077. const innerMobileColumns = [
  1078. { title: '{{ i18n "pages.inbounds.operate" }}', width: 10, align: 'center', scopedSlots: { customRender: 'actionMenu' } },
  1079. { title: '{{ i18n "pages.inbounds.client" }}', width: 90, align: 'left', scopedSlots: { customRender: 'client' } },
  1080. { title: '{{ i18n "pages.inbounds.info" }}', width: 10, align: 'center', scopedSlots: { customRender: 'info' } },
  1081. ];
  1082. const app = new Vue({
  1083. delimiters: ['[[', ']]'],
  1084. el: '#app',
  1085. mixins: [MediaQueryMixin],
  1086. data: {
  1087. themeSwitcher,
  1088. persianDatepicker,
  1089. loadingStates: {
  1090. fetched: false,
  1091. spinning: false
  1092. },
  1093. inbounds: [],
  1094. dbInbounds: [],
  1095. searchKey: '',
  1096. enableFilter: false,
  1097. filterBy: '',
  1098. searchedInbounds: [],
  1099. expireDiff: 0,
  1100. trafficDiff: 0,
  1101. defaultCert: '',
  1102. defaultKey: '',
  1103. clientCount: [],
  1104. onlineClients: [],
  1105. lastOnlineMap: {},
  1106. isRefreshEnabled: localStorage.getItem("isRefreshEnabled") === "true" ? true : false,
  1107. refreshing: false,
  1108. refreshInterval: Number(localStorage.getItem("refreshInterval")) || 5000,
  1109. subSettings: {
  1110. enable: false,
  1111. subTitle: '',
  1112. subURI: '',
  1113. subJsonURI: '',
  1114. subJsonEnable: false,
  1115. },
  1116. remarkModel: '-ieo',
  1117. datepicker: 'gregorian',
  1118. tgBotEnable: false,
  1119. showAlert: false,
  1120. ipLimitEnable: false,
  1121. pageSize: 0,
  1122. },
  1123. methods: {
  1124. loading(spinning = true) {
  1125. this.loadingStates.spinning = spinning;
  1126. },
  1127. async getDBInbounds() {
  1128. this.refreshing = true;
  1129. const msg = await HttpUtil.get('/panel/api/inbounds/list');
  1130. if (!msg.success) {
  1131. this.refreshing = false;
  1132. return;
  1133. }
  1134. await this.getLastOnlineMap();
  1135. await this.getOnlineUsers();
  1136. this.setInbounds(msg.obj);
  1137. setTimeout(() => {
  1138. this.refreshing = false;
  1139. }, 500);
  1140. },
  1141. async getOnlineUsers() {
  1142. const msg = await HttpUtil.post('/panel/api/inbounds/onlines');
  1143. if (!msg.success) {
  1144. return;
  1145. }
  1146. this.onlineClients = msg.obj != null ? msg.obj : [];
  1147. },
  1148. async getLastOnlineMap() {
  1149. const msg = await HttpUtil.post('/panel/api/inbounds/lastOnline');
  1150. if (!msg.success || !msg.obj) return;
  1151. this.lastOnlineMap = msg.obj || {}
  1152. },
  1153. async getDefaultSettings() {
  1154. const msg = await HttpUtil.post('/panel/setting/defaultSettings');
  1155. if (!msg.success) {
  1156. return;
  1157. }
  1158. with (msg.obj) {
  1159. this.expireDiff = expireDiff * 86400000;
  1160. this.trafficDiff = trafficDiff * 1073741824;
  1161. this.defaultCert = defaultCert;
  1162. this.defaultKey = defaultKey;
  1163. this.tgBotEnable = tgBotEnable;
  1164. this.subSettings = {
  1165. enable: subEnable,
  1166. subTitle: subTitle,
  1167. subURI: subURI,
  1168. subJsonURI: subJsonURI,
  1169. subJsonEnable: subJsonEnable,
  1170. };
  1171. this.pageSize = pageSize;
  1172. this.remarkModel = remarkModel;
  1173. this.datepicker = datepicker;
  1174. this.ipLimitEnable = ipLimitEnable;
  1175. }
  1176. },
  1177. setInbounds(dbInbounds) {
  1178. this.inbounds.splice(0);
  1179. this.dbInbounds.splice(0);
  1180. this.clientCount.splice(0);
  1181. for (const inbound of dbInbounds) {
  1182. const dbInbound = new DBInbound(inbound);
  1183. to_inbound = dbInbound.toInbound()
  1184. this.inbounds.push(to_inbound);
  1185. this.dbInbounds.push(dbInbound);
  1186. if ([Protocols.VMESS, Protocols.VLESS, Protocols.TROJAN, Protocols.SHADOWSOCKS].includes(inbound.protocol)) {
  1187. if (dbInbound.isSS && (!to_inbound.isSSMultiUser)) {
  1188. continue;
  1189. }
  1190. this.clientCount[inbound.id] = this.getClientCounts(inbound, to_inbound);
  1191. }
  1192. }
  1193. if (!this.loadingStates.fetched) {
  1194. this.loadingStates.fetched = true
  1195. }
  1196. if (this.enableFilter) {
  1197. this.filterInbounds();
  1198. } else {
  1199. this.searchInbounds(this.searchKey);
  1200. }
  1201. },
  1202. getClientCounts(dbInbound, inbound) {
  1203. let clientCount = 0, active = [], deactive = [], depleted = [], expiring = [], online = [], comments = new Map();
  1204. clients = inbound.clients;
  1205. clientStats = dbInbound.clientStats
  1206. now = new Date().getTime()
  1207. if (clients) {
  1208. clientCount = clients.length;
  1209. if (dbInbound.enable) {
  1210. clients.forEach(client => {
  1211. if (client.comment) {
  1212. comments.set(client.email, client.comment)
  1213. }
  1214. if (client.enable) {
  1215. active.push(client.email);
  1216. if (this.isClientOnline(client.email)) online.push(client.email);
  1217. } else {
  1218. deactive.push(client.email);
  1219. }
  1220. });
  1221. clientStats.forEach(stats => {
  1222. const exhausted = stats.total > 0 && (stats.up + stats.down) >= stats.total;
  1223. const expired = stats.expiryTime > 0 && stats.expiryTime <= now;
  1224. if (expired || exhausted) {
  1225. depleted.push(stats.email);
  1226. } else {
  1227. const expiringSoon = (stats.expiryTime > 0 && (stats.expiryTime - now < this.expireDiff)) ||
  1228. (stats.total > 0 && (stats.total - (stats.up + stats.down) < this.trafficDiff));
  1229. if (expiringSoon) expiring.push(stats.email);
  1230. }
  1231. });
  1232. } else {
  1233. clients.forEach(client => {
  1234. deactive.push(client.email);
  1235. });
  1236. }
  1237. }
  1238. return {
  1239. clients: clientCount,
  1240. active: active,
  1241. deactive: deactive,
  1242. depleted: depleted,
  1243. expiring: expiring,
  1244. online: online,
  1245. comments: comments,
  1246. };
  1247. },
  1248. searchInbounds(key) {
  1249. if (ObjectUtil.isEmpty(key)) {
  1250. this.searchedInbounds = this.dbInbounds.slice();
  1251. } else {
  1252. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  1253. this.dbInbounds.forEach(inbound => {
  1254. if (ObjectUtil.deepSearch(inbound, key)) {
  1255. const newInbound = new DBInbound(inbound);
  1256. const inboundSettings = JSON.parse(inbound.settings);
  1257. if (inboundSettings.hasOwnProperty('clients')) {
  1258. const searchedSettings = { "clients": [] };
  1259. inboundSettings.clients.forEach(client => {
  1260. if (ObjectUtil.deepSearch(client, key)) {
  1261. searchedSettings.clients.push(client);
  1262. }
  1263. });
  1264. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, searchedSettings);
  1265. }
  1266. this.searchedInbounds.push(newInbound);
  1267. }
  1268. });
  1269. }
  1270. },
  1271. filterInbounds() {
  1272. if (ObjectUtil.isEmpty(this.filterBy)) {
  1273. this.searchedInbounds = this.dbInbounds.slice();
  1274. } else {
  1275. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  1276. this.dbInbounds.forEach(inbound => {
  1277. const newInbound = new DBInbound(inbound);
  1278. const inboundSettings = JSON.parse(inbound.settings);
  1279. if (this.clientCount[inbound.id] && this.clientCount[inbound.id].hasOwnProperty(this.filterBy)) {
  1280. const list = this.clientCount[inbound.id][this.filterBy];
  1281. if (list.length > 0) {
  1282. const filteredSettings = { "clients": [] };
  1283. if (inboundSettings.clients) {
  1284. inboundSettings.clients.forEach(client => {
  1285. if (list.includes(client.email)) {
  1286. filteredSettings.clients.push(client);
  1287. }
  1288. });
  1289. }
  1290. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, filteredSettings);
  1291. this.searchedInbounds.push(newInbound);
  1292. }
  1293. }
  1294. });
  1295. }
  1296. },
  1297. toggleFilter() {
  1298. if (this.enableFilter) {
  1299. this.searchKey = '';
  1300. } else {
  1301. this.filterBy = '';
  1302. this.searchedInbounds = this.dbInbounds.slice();
  1303. }
  1304. },
  1305. generalActions(action) {
  1306. switch (action.key) {
  1307. case "import":
  1308. this.importInbound();
  1309. break;
  1310. case "export":
  1311. this.exportAllLinks();
  1312. break;
  1313. case "subs":
  1314. this.exportAllSubs();
  1315. break;
  1316. case "resetInbounds":
  1317. this.resetAllTraffic();
  1318. break;
  1319. case "resetClients":
  1320. this.resetAllClientTraffics(-1);
  1321. break;
  1322. case "delDepletedClients":
  1323. this.delDepletedClients(-1)
  1324. break;
  1325. }
  1326. },
  1327. clickAction(action, dbInbound) {
  1328. switch (action.key) {
  1329. case "qrcode":
  1330. this.showQrcode(dbInbound.id);
  1331. break;
  1332. case "showInfo":
  1333. this.showInfo(dbInbound.id);
  1334. break;
  1335. case "edit":
  1336. this.openEditInbound(dbInbound.id);
  1337. break;
  1338. case "addClient":
  1339. this.openAddClient(dbInbound.id)
  1340. break;
  1341. case "addBulkClient":
  1342. this.openAddBulkClient(dbInbound.id)
  1343. break;
  1344. case "copyClients":
  1345. copyClientsModal.show(dbInbound);
  1346. break;
  1347. case "export":
  1348. this.inboundLinks(dbInbound.id);
  1349. break;
  1350. case "subs":
  1351. this.exportSubs(dbInbound.id);
  1352. break;
  1353. case "clipboard":
  1354. this.copy(dbInbound.id);
  1355. break;
  1356. case "resetTraffic":
  1357. this.resetTraffic(dbInbound.id);
  1358. break;
  1359. case "resetClients":
  1360. this.resetAllClientTraffics(dbInbound.id);
  1361. break;
  1362. case "clone":
  1363. this.openCloneInbound(dbInbound);
  1364. break;
  1365. case "delete":
  1366. this.delInbound(dbInbound.id);
  1367. break;
  1368. case "delDepletedClients":
  1369. this.delDepletedClients(dbInbound.id)
  1370. break;
  1371. }
  1372. },
  1373. openCloneInbound(dbInbound) {
  1374. this.$confirm({
  1375. title: '{{ i18n "pages.inbounds.cloneInbound"}} \"' + dbInbound.remark + '\"',
  1376. content: '{{ i18n "pages.inbounds.cloneInboundContent"}}',
  1377. okText: '{{ i18n "pages.inbounds.cloneInboundOk"}}',
  1378. class: themeSwitcher.currentTheme,
  1379. cancelText: '{{ i18n "cancel" }}',
  1380. onOk: () => {
  1381. const baseInbound = dbInbound.toInbound();
  1382. dbInbound.up = 0;
  1383. dbInbound.down = 0;
  1384. this.cloneInbound(baseInbound, dbInbound);
  1385. },
  1386. });
  1387. },
  1388. async cloneInbound(baseInbound, dbInbound) {
  1389. const data = {
  1390. up: dbInbound.up,
  1391. down: dbInbound.down,
  1392. total: dbInbound.total,
  1393. remark: dbInbound.remark + " - Cloned",
  1394. enable: dbInbound.enable,
  1395. expiryTime: dbInbound.expiryTime,
  1396. trafficReset: dbInbound.trafficReset,
  1397. lastTrafficResetTime: dbInbound.lastTrafficResetTime,
  1398. listen: '',
  1399. port: RandomUtil.randomInteger(10000, 60000),
  1400. protocol: baseInbound.protocol,
  1401. settings: Inbound.Settings.getSettings(baseInbound.protocol).toString(),
  1402. streamSettings: baseInbound.stream.toString(),
  1403. sniffing: baseInbound.sniffing.toString(),
  1404. };
  1405. await this.submit('/panel/api/inbounds/add', data, inModal);
  1406. },
  1407. openAddInbound() {
  1408. inModal.show({
  1409. title: '{{ i18n "pages.inbounds.addInbound"}}',
  1410. okText: '{{ i18n "create"}}',
  1411. cancelText: '{{ i18n "close" }}',
  1412. confirm: async (inbound, dbInbound) => {
  1413. await this.addInbound(inbound, dbInbound, inModal);
  1414. },
  1415. isEdit: false
  1416. });
  1417. },
  1418. openEditInbound(dbInboundId) {
  1419. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1420. const inbound = dbInbound.toInbound();
  1421. inModal.show({
  1422. title: '{{ i18n "pages.inbounds.modifyInbound"}}',
  1423. okText: '{{ i18n "update"}}',
  1424. cancelText: '{{ i18n "close" }}',
  1425. inbound: inbound,
  1426. dbInbound: dbInbound,
  1427. confirm: async (inbound, dbInbound) => {
  1428. await this.updateInbound(inbound, dbInbound);
  1429. },
  1430. isEdit: true
  1431. });
  1432. },
  1433. async addInbound(inbound, dbInbound) {
  1434. const data = {
  1435. up: dbInbound.up,
  1436. down: dbInbound.down,
  1437. total: dbInbound.total,
  1438. remark: dbInbound.remark,
  1439. enable: dbInbound.enable,
  1440. expiryTime: dbInbound.expiryTime,
  1441. trafficReset: dbInbound.trafficReset,
  1442. lastTrafficResetTime: dbInbound.lastTrafficResetTime,
  1443. listen: inbound.listen,
  1444. port: inbound.port,
  1445. protocol: inbound.protocol,
  1446. settings: inbound.settings.toString(),
  1447. };
  1448. if (inbound.canEnableStream()) {
  1449. data.streamSettings = inbound.stream.toString();
  1450. } else if (inbound.stream?.sockopt) {
  1451. data.streamSettings = JSON.stringify({ sockopt: inbound.stream.sockopt.toJson() }, null, 2);
  1452. }
  1453. data.sniffing = inbound.sniffing.toString();
  1454. await this.submit('/panel/api/inbounds/add', data, inModal);
  1455. },
  1456. async updateInbound(inbound, dbInbound) {
  1457. const data = {
  1458. up: dbInbound.up,
  1459. down: dbInbound.down,
  1460. total: dbInbound.total,
  1461. remark: dbInbound.remark,
  1462. enable: dbInbound.enable,
  1463. expiryTime: dbInbound.expiryTime,
  1464. trafficReset: dbInbound.trafficReset,
  1465. lastTrafficResetTime: dbInbound.lastTrafficResetTime,
  1466. listen: inbound.listen,
  1467. port: inbound.port,
  1468. protocol: inbound.protocol,
  1469. settings: inbound.settings.toString(),
  1470. };
  1471. if (inbound.canEnableStream()) {
  1472. data.streamSettings = inbound.stream.toString();
  1473. } else if (inbound.stream?.sockopt) {
  1474. data.streamSettings = JSON.stringify({ sockopt: inbound.stream.sockopt.toJson() }, null, 2);
  1475. }
  1476. data.sniffing = inbound.sniffing.toString();
  1477. const formData = new FormData();
  1478. Object.keys(data).forEach(key => formData.append(key, data[key]));
  1479. await this.submit(`/panel/api/inbounds/update/${dbInbound.id}`, formData, inModal);
  1480. },
  1481. openAddClient(dbInboundId) {
  1482. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1483. clientModal.show({
  1484. title: '{{ i18n "pages.client.add"}}',
  1485. okText: '{{ i18n "pages.client.submitAdd"}}',
  1486. dbInbound: dbInbound,
  1487. confirm: async (clients, dbInboundId) => {
  1488. await this.addClient(clients, dbInboundId, clientModal);
  1489. },
  1490. isEdit: false
  1491. });
  1492. },
  1493. openAddBulkClient(dbInboundId) {
  1494. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1495. clientsBulkModal.show({
  1496. title: '{{ i18n "pages.client.bulk"}} ' + dbInbound.remark,
  1497. okText: '{{ i18n "pages.client.bulk"}}',
  1498. dbInbound: dbInbound,
  1499. confirm: async (clients, dbInboundId) => {
  1500. await this.addClient(clients, dbInboundId, clientsBulkModal);
  1501. },
  1502. });
  1503. },
  1504. openEditClient(dbInboundId, client) {
  1505. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1506. if (!dbInbound) return;
  1507. clients = this.getInboundClients(dbInbound);
  1508. if (!clients || !Array.isArray(clients)) return;
  1509. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1510. if (index < 0) return;
  1511. clientModal.show({
  1512. title: '{{ i18n "pages.client.edit"}}',
  1513. okText: '{{ i18n "pages.client.submitEdit"}}',
  1514. dbInbound: dbInbound,
  1515. index: index,
  1516. confirm: async (client, dbInboundId, clientId) => {
  1517. clientModal.loading();
  1518. await this.updateClient(client, dbInboundId, clientId);
  1519. clientModal.close();
  1520. },
  1521. isEdit: true
  1522. });
  1523. },
  1524. findIndexOfClient(protocol, clients, client) {
  1525. if (!clients || !Array.isArray(clients) || !client) {
  1526. return -1;
  1527. }
  1528. switch (protocol) {
  1529. case Protocols.TROJAN:
  1530. case Protocols.SHADOWSOCKS:
  1531. return clients.findIndex(item => item && item.password === client.password && item.email === client.email);
  1532. default: return clients.findIndex(item => item && item.id === client.id && item.email === client.email);
  1533. }
  1534. },
  1535. async addClient(clients, dbInboundId, modal) {
  1536. const data = {
  1537. id: dbInboundId,
  1538. settings: '{"clients": [' + clients.toString() + ']}',
  1539. };
  1540. await this.submit(`/panel/api/inbounds/addClient`, data, modal);
  1541. },
  1542. async updateClient(client, dbInboundId, clientId) {
  1543. const data = {
  1544. id: dbInboundId,
  1545. settings: '{"clients": [' + client.toString() + ']}',
  1546. };
  1547. await this.submit(`/panel/api/inbounds/updateClient/${clientId}`, data, clientModal);
  1548. },
  1549. resetTraffic(dbInboundId) {
  1550. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1551. this.$confirm({
  1552. title: '{{ i18n "pages.inbounds.resetTraffic"}}' + ' #' + dbInboundId,
  1553. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  1554. class: themeSwitcher.currentTheme,
  1555. okText: '{{ i18n "reset"}}',
  1556. cancelText: '{{ i18n "cancel"}}',
  1557. onOk: () => {
  1558. const inbound = dbInbound.toInbound();
  1559. dbInbound.up = 0;
  1560. dbInbound.down = 0;
  1561. this.updateInbound(inbound, dbInbound);
  1562. },
  1563. });
  1564. },
  1565. delInbound(dbInboundId) {
  1566. this.$confirm({
  1567. title: '{{ i18n "pages.inbounds.deleteInbound"}}' + ' #' + dbInboundId,
  1568. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  1569. class: themeSwitcher.currentTheme,
  1570. okText: '{{ i18n "delete"}}',
  1571. cancelText: '{{ i18n "cancel"}}',
  1572. onOk: () => this.submit('/panel/api/inbounds/del/' + dbInboundId),
  1573. });
  1574. },
  1575. delClient(dbInboundId, client, confirmation = true) {
  1576. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1577. clientId = this.getClientId(dbInbound.protocol, client);
  1578. if (confirmation) {
  1579. this.$confirm({
  1580. title: '{{ i18n "pages.inbounds.deleteClient"}}' + ' ' + client.email,
  1581. content: '{{ i18n "pages.inbounds.deleteClientContent"}}',
  1582. class: themeSwitcher.currentTheme,
  1583. okText: '{{ i18n "delete"}}',
  1584. cancelText: '{{ i18n "cancel"}}',
  1585. onOk: () => this.submit(`/panel/api/inbounds/${dbInboundId}/delClient/${clientId}`),
  1586. });
  1587. } else {
  1588. this.submit(`/panel/api/inbounds/${dbInboundId}/delClient/${clientId}`);
  1589. }
  1590. },
  1591. getSubGroupClients(dbInbounds, currentClient) {
  1592. const response = {
  1593. inbounds: [],
  1594. clients: [],
  1595. editIds: []
  1596. }
  1597. if (dbInbounds && dbInbounds.length > 0 && currentClient) {
  1598. dbInbounds.forEach((dbInboundItem) => {
  1599. const dbInbound = new DBInbound(dbInboundItem);
  1600. if (dbInbound) {
  1601. const inbound = dbInbound.toInbound();
  1602. if (inbound) {
  1603. const clients = inbound.clients;
  1604. if (clients.length > 0) {
  1605. clients.forEach((client) => {
  1606. if (client['subId'] === currentClient['subId']) {
  1607. client['inboundId'] = dbInboundItem.id
  1608. client['clientId'] = this.getClientId(dbInbound.protocol, client)
  1609. response.inbounds.push(dbInboundItem.id)
  1610. response.clients.push(client)
  1611. response.editIds.push(client['clientId'])
  1612. }
  1613. })
  1614. }
  1615. }
  1616. }
  1617. })
  1618. }
  1619. return response;
  1620. },
  1621. getClientId(protocol, client) {
  1622. switch (protocol) {
  1623. case Protocols.TROJAN: return client.password;
  1624. case Protocols.SHADOWSOCKS: return client.email;
  1625. case Protocols.HYSTERIA: return client.auth;
  1626. default: return client.id;
  1627. }
  1628. },
  1629. checkFallback(dbInbound) {
  1630. newDbInbound = new DBInbound(dbInbound);
  1631. if (dbInbound.listen.startsWith("@")) {
  1632. rootInbound = this.inbounds.find((i) =>
  1633. i.isTcp &&
  1634. ['trojan', 'vless'].includes(i.protocol) &&
  1635. i.settings.fallbacks.find(f => f.dest === dbInbound.listen)
  1636. );
  1637. if (rootInbound) {
  1638. newDbInbound.listen = rootInbound.listen;
  1639. newDbInbound.port = rootInbound.port;
  1640. newInbound = newDbInbound.toInbound();
  1641. newInbound.stream.security = rootInbound.stream.security;
  1642. newInbound.stream.tls = rootInbound.stream.tls;
  1643. newInbound.stream.externalProxy = rootInbound.stream.externalProxy;
  1644. newDbInbound.streamSettings = newInbound.stream.toString();
  1645. }
  1646. }
  1647. return newDbInbound;
  1648. },
  1649. showQrcode(dbInboundId, client) {
  1650. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1651. newDbInbound = this.checkFallback(dbInbound);
  1652. qrModal.show('{{ i18n "qrCode"}}', newDbInbound, client);
  1653. },
  1654. showInfo(dbInboundId, client) {
  1655. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1656. if (!dbInbound) return;
  1657. index = 0;
  1658. if (dbInbound.isMultiUser()) {
  1659. inbound = dbInbound.toInbound();
  1660. clients = inbound && inbound.clients ? inbound.clients : null;
  1661. if (clients && Array.isArray(clients)) {
  1662. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1663. if (index < 0) index = 0;
  1664. }
  1665. }
  1666. newDbInbound = this.checkFallback(dbInbound);
  1667. infoModal.show(newDbInbound, index);
  1668. },
  1669. switchEnable(dbInboundId, state) {
  1670. let dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1671. if (!dbInbound) return;
  1672. dbInbound.enable = state;
  1673. let inbound = dbInbound.toInbound();
  1674. const data = {
  1675. up: dbInbound.up,
  1676. down: dbInbound.down,
  1677. total: dbInbound.total,
  1678. remark: dbInbound.remark,
  1679. enable: dbInbound.enable,
  1680. expiryTime: dbInbound.expiryTime,
  1681. trafficReset: dbInbound.trafficReset,
  1682. lastTrafficResetTime: dbInbound.lastTrafficResetTime,
  1683. listen: inbound.listen,
  1684. port: inbound.port,
  1685. protocol: inbound.protocol,
  1686. settings: inbound.settings.toString(),
  1687. };
  1688. if (inbound.canEnableStream()) {
  1689. data.streamSettings = inbound.stream.toString();
  1690. } else if (inbound.stream?.sockopt) {
  1691. data.streamSettings = JSON.stringify({ sockopt: inbound.stream.sockopt.toJson() }, null, 2);
  1692. }
  1693. data.sniffing = inbound.sniffing.toString();
  1694. const formData = new FormData();
  1695. Object.keys(data).forEach(key => formData.append(key, data[key]));
  1696. this.submit(`/panel/api/inbounds/update/${dbInboundId}`, formData);
  1697. },
  1698. async switchEnableClient(dbInboundId, client, state) {
  1699. this.loading();
  1700. try {
  1701. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1702. if (!dbInbound) return;
  1703. inbound = dbInbound.toInbound();
  1704. clients = inbound && inbound.clients ? inbound.clients : null;
  1705. if (!clients || !Array.isArray(clients)) return;
  1706. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1707. if (index < 0 || !clients[index]) return;
  1708. clients[index].enable = typeof state === 'boolean' ? state : !!client.enable;
  1709. clientId = this.getClientId(dbInbound.protocol, clients[index]);
  1710. await this.updateClient(clients[index], dbInboundId, clientId);
  1711. } finally {
  1712. this.loading(false);
  1713. }
  1714. },
  1715. async submit(url, data, modal) {
  1716. const msg = await HttpUtil.postWithModal(url, data, modal);
  1717. if (msg.success) {
  1718. await this.getDBInbounds();
  1719. }
  1720. },
  1721. getInboundClients(dbInbound) {
  1722. if (!dbInbound) return null;
  1723. const inbound = dbInbound.toInbound();
  1724. return inbound && inbound.clients ? inbound.clients : null;
  1725. },
  1726. resetClientTraffic(client, dbInboundId, confirmation = true) {
  1727. if (confirmation) {
  1728. this.$confirm({
  1729. title: '{{ i18n "pages.inbounds.resetTraffic"}}' + ' ' + client.email,
  1730. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  1731. class: themeSwitcher.currentTheme,
  1732. okText: '{{ i18n "reset"}}',
  1733. cancelText: '{{ i18n "cancel"}}',
  1734. onOk: () => this.submit('/panel/api/inbounds/' + dbInboundId + '/resetClientTraffic/' + client.email),
  1735. })
  1736. } else {
  1737. this.submit('/panel/api/inbounds/' + dbInboundId + '/resetClientTraffic/' + client.email);
  1738. }
  1739. },
  1740. resetAllTraffic() {
  1741. this.$confirm({
  1742. title: '{{ i18n "pages.inbounds.resetAllTrafficTitle"}}',
  1743. content: '{{ i18n "pages.inbounds.resetAllTrafficContent"}}',
  1744. class: themeSwitcher.currentTheme,
  1745. okText: '{{ i18n "reset"}}',
  1746. cancelText: '{{ i18n "cancel"}}',
  1747. onOk: () => this.submit('/panel/api/inbounds/resetAllTraffics'),
  1748. });
  1749. },
  1750. resetAllClientTraffics(dbInboundId) {
  1751. this.$confirm({
  1752. title: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficTitle"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficTitle"}}',
  1753. content: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficContent"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficContent"}}',
  1754. class: themeSwitcher.currentTheme,
  1755. okText: '{{ i18n "reset"}}',
  1756. cancelText: '{{ i18n "cancel"}}',
  1757. onOk: () => this.submit('/panel/api/inbounds/resetAllClientTraffics/' + dbInboundId),
  1758. })
  1759. },
  1760. delDepletedClients(dbInboundId) {
  1761. this.$confirm({
  1762. title: '{{ i18n "pages.inbounds.delDepletedClientsTitle"}}',
  1763. content: '{{ i18n "pages.inbounds.delDepletedClientsContent"}}',
  1764. class: themeSwitcher.currentTheme,
  1765. okText: '{{ i18n "delete"}}',
  1766. cancelText: '{{ i18n "cancel"}}',
  1767. onOk: () => this.submit('/panel/api/inbounds/delDepletedClients/' + dbInboundId),
  1768. })
  1769. },
  1770. isExpiry(dbInbound, index) {
  1771. return dbInbound.toInbound().isExpiry(index);
  1772. },
  1773. getClientStats(dbInbound, email) {
  1774. if (!dbInbound) return null;
  1775. if (!dbInbound._clientStatsMap) {
  1776. dbInbound._clientStatsMap = new Map();
  1777. if (dbInbound.clientStats && Array.isArray(dbInbound.clientStats)) {
  1778. for (const stats of dbInbound.clientStats) {
  1779. dbInbound._clientStatsMap.set(stats.email, stats);
  1780. }
  1781. }
  1782. }
  1783. return dbInbound._clientStatsMap.get(email);
  1784. },
  1785. getUpStats(dbInbound, email) {
  1786. if (!email || email.length == 0) return 0;
  1787. let clientStats = this.getClientStats(dbInbound, email);
  1788. return clientStats ? clientStats.up : 0;
  1789. },
  1790. getDownStats(dbInbound, email) {
  1791. if (!email || email.length == 0) return 0;
  1792. let clientStats = this.getClientStats(dbInbound, email);
  1793. return clientStats ? clientStats.down : 0;
  1794. },
  1795. getSumStats(dbInbound, email) {
  1796. if (!email || email.length == 0) return 0;
  1797. let clientStats = this.getClientStats(dbInbound, email);
  1798. return clientStats ? clientStats.up + clientStats.down : 0;
  1799. },
  1800. getAllTimeClient(dbInbound, email) {
  1801. if (!email || email.length == 0) return 0;
  1802. let clientStats = this.getClientStats(dbInbound, email);
  1803. if (!clientStats) return 0;
  1804. return clientStats.allTime || (clientStats.up + clientStats.down);
  1805. },
  1806. getRemStats(dbInbound, email) {
  1807. if (!email || email.length == 0) return 0;
  1808. let clientStats = this.getClientStats(dbInbound, email);
  1809. if (!clientStats) return 0;
  1810. let remained = clientStats.total - (clientStats.up + clientStats.down);
  1811. return remained > 0 ? remained : 0;
  1812. },
  1813. clientStatsColor(dbInbound, email) {
  1814. if (!email || email.length == 0) return ColorUtils.clientUsageColor();
  1815. let clientStats = this.getClientStats(dbInbound, email);
  1816. return ColorUtils.clientUsageColor(clientStats, app.trafficDiff)
  1817. },
  1818. statsProgress(dbInbound, email) {
  1819. if (!email || email.length == 0) return 100;
  1820. let clientStats = this.getClientStats(dbInbound, email);
  1821. if (!clientStats) return 0;
  1822. if (clientStats.total == 0) return 100;
  1823. return 100 * (clientStats.down + clientStats.up) / clientStats.total;
  1824. },
  1825. expireProgress(expTime, reset) {
  1826. now = new Date().getTime();
  1827. remainedSeconds = expTime < 0 ? -expTime / 1000 : (expTime - now) / 1000;
  1828. resetSeconds = reset * 86400;
  1829. if (remainedSeconds >= resetSeconds) return 0;
  1830. return 100 * (1 - (remainedSeconds / resetSeconds));
  1831. },
  1832. statsExpColor(dbInbound, email) {
  1833. if (!email || email.length == 0) return '#7a316f';
  1834. let clientStats = this.getClientStats(dbInbound, email);
  1835. if (!clientStats) return '#7a316f';
  1836. let statsColor = ColorUtils.usageColor(clientStats.down + clientStats.up, this.trafficDiff, clientStats.total);
  1837. let expColor = ColorUtils.usageColor(new Date().getTime(), this.expireDiff, clientStats.expiryTime);
  1838. switch (true) {
  1839. case statsColor == "red" || expColor == "red":
  1840. return "#cf3c3c"; // Red
  1841. case statsColor == "orange" || expColor == "orange":
  1842. return "#f37b24"; // Orange
  1843. case statsColor == "green" || expColor == "green":
  1844. return "#008771"; // Green
  1845. default:
  1846. return "#7a316f"; // purple
  1847. }
  1848. },
  1849. isClientEnabled(dbInbound, email) {
  1850. let clientStats = dbInbound ? this.getClientStats(dbInbound, email) : null;
  1851. return clientStats ? clientStats['enable'] : true;
  1852. },
  1853. isClientDepleted(dbInbound, email) {
  1854. if (!email || !dbInbound) return false;
  1855. const stats = this.getClientStats(dbInbound, email);
  1856. if (!stats) return false;
  1857. const total = stats.total ?? 0;
  1858. const used = (stats.up ?? 0) + (stats.down ?? 0);
  1859. const hasTotal = total > 0;
  1860. const exhausted = hasTotal && used >= total;
  1861. const expiryTime = stats.expiryTime ?? 0;
  1862. const hasExpiry = expiryTime > 0;
  1863. const now = Date.now();
  1864. const expired = hasExpiry && expiryTime <= now;
  1865. return expired || exhausted;
  1866. },
  1867. isClientOnline(email) {
  1868. return this.onlineClients.includes(email);
  1869. },
  1870. getLastOnline(email) {
  1871. return this.lastOnlineMap[email] || null
  1872. },
  1873. formatLastOnline(email) {
  1874. const ts = this.getLastOnline(email)
  1875. if (!ts) return '-'
  1876. // Check if IntlUtil is available (may not be loaded yet)
  1877. if (typeof IntlUtil !== 'undefined' && IntlUtil.formatDate) {
  1878. return IntlUtil.formatDate(ts)
  1879. }
  1880. // Fallback to simple date formatting if IntlUtil is not available
  1881. return new Date(ts).toLocaleString()
  1882. },
  1883. isRemovable(dbInboundId) {
  1884. return this.getInboundClients(this.dbInbounds.find(row => row.id === dbInboundId)).length > 1;
  1885. },
  1886. inboundLinks(dbInboundId) {
  1887. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1888. newDbInbound = this.checkFallback(dbInbound);
  1889. txtModal.show('{{ i18n "pages.inbounds.export"}}', newDbInbound.genInboundLinks(this.remarkModel), newDbInbound.remark);
  1890. },
  1891. exportSubs(dbInboundId) {
  1892. const dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1893. const clients = this.getInboundClients(dbInbound);
  1894. let subLinks = []
  1895. if (clients != null) {
  1896. clients.forEach(c => {
  1897. if (c.subId && c.subId.length > 0) {
  1898. subLinks.push(this.subSettings.subURI + c.subId)
  1899. }
  1900. })
  1901. }
  1902. txtModal.show(
  1903. '{{ i18n "pages.inbounds.export"}} - {{ i18n "pages.settings.subSettings" }}',
  1904. [...new Set(subLinks)].join('\n'),
  1905. dbInbound.remark + "-Subs");
  1906. },
  1907. importInbound() {
  1908. promptModal.open({
  1909. title: '{{ i18n "pages.inbounds.importInbound" }}',
  1910. type: 'textarea',
  1911. value: '',
  1912. okText: '{{ i18n "pages.inbounds.import" }}',
  1913. confirm: async (dbInboundText) => {
  1914. await this.submit('/panel/api/inbounds/import', { data: dbInboundText }, promptModal);
  1915. },
  1916. });
  1917. },
  1918. exportAllSubs() {
  1919. let subLinks = []
  1920. for (const dbInbound of this.dbInbounds) {
  1921. const clients = this.getInboundClients(dbInbound);
  1922. if (clients != null) {
  1923. clients.forEach(c => {
  1924. if (c.subId && c.subId.length > 0) {
  1925. subLinks.push(this.subSettings.subURI + c.subId)
  1926. }
  1927. })
  1928. }
  1929. }
  1930. txtModal.show(
  1931. '{{ i18n "pages.inbounds.export"}} - {{ i18n "pages.settings.subSettings" }}',
  1932. [...new Set(subLinks)].join('\r\n'),
  1933. 'All-Inbounds-Subs');
  1934. },
  1935. exportAllLinks() {
  1936. let copyText = [];
  1937. for (const dbInbound of this.dbInbounds) {
  1938. copyText.push(dbInbound.genInboundLinks(this.remarkModel));
  1939. }
  1940. txtModal.show('{{ i18n "pages.inbounds.export"}}', copyText.join('\r\n'), 'All-Inbounds');
  1941. },
  1942. copy(dbInboundId) {
  1943. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1944. txtModal.show('{{ i18n "pages.inbounds.inboundData" }}', JSON.stringify(dbInbound, null, 2));
  1945. },
  1946. async startDataRefreshLoop() {
  1947. while (this.isRefreshEnabled) {
  1948. try {
  1949. await this.getDBInbounds();
  1950. } catch (e) {
  1951. console.error(e);
  1952. }
  1953. await PromiseUtil.sleep(this.refreshInterval);
  1954. }
  1955. },
  1956. toggleRefresh() {
  1957. localStorage.setItem("isRefreshEnabled", this.isRefreshEnabled);
  1958. if (this.isRefreshEnabled) {
  1959. this.startDataRefreshLoop();
  1960. }
  1961. },
  1962. changeRefreshInterval() {
  1963. localStorage.setItem("refreshInterval", this.refreshInterval);
  1964. },
  1965. async manualRefresh() {
  1966. if (!this.refreshing) {
  1967. this.loadingStates.spinning = true;
  1968. await this.getDBInbounds();
  1969. this.loadingStates.spinning = false;
  1970. }
  1971. },
  1972. pagination(obj) {
  1973. if (this.pageSize > 0 && obj.length > this.pageSize) {
  1974. // Set page options based on object size
  1975. let sizeOptions = [this.pageSize.toString()];
  1976. const increments = [2, 5, 10, 20];
  1977. for (const m of increments) {
  1978. const val = this.pageSize * m;
  1979. if (val < obj.length && val <= 1000) {
  1980. sizeOptions.push(val.toString());
  1981. }
  1982. }
  1983. // Add option to see all in one page
  1984. if (!sizeOptions.includes(obj.length.toString())) {
  1985. sizeOptions.push(obj.length.toString());
  1986. }
  1987. p = {
  1988. showSizeChanger: true,
  1989. size: 'small',
  1990. position: 'bottom',
  1991. pageSize: this.pageSize,
  1992. pageSizeOptions: sizeOptions
  1993. };
  1994. return p;
  1995. }
  1996. return false
  1997. }
  1998. },
  1999. watch: {
  2000. searchKey: Utils.debounce(function (newVal) {
  2001. this.searchInbounds(newVal);
  2002. }, 500)
  2003. },
  2004. mounted() {
  2005. if (window.location.protocol !== "https:") {
  2006. this.showAlert = true;
  2007. }
  2008. this.loading();
  2009. this.getDefaultSettings();
  2010. // Initial data fetch
  2011. this.getDBInbounds().then(() => {
  2012. this.loading(false);
  2013. });
  2014. // Setup WebSocket for real-time updates
  2015. if (window.wsClient) {
  2016. window.wsClient.connect();
  2017. // Listen for inbounds updates
  2018. window.wsClient.on('inbounds', (payload) => {
  2019. if (payload && Array.isArray(payload)) {
  2020. // Use setInbounds to properly convert to DBInbound objects with methods
  2021. this.setInbounds(payload);
  2022. }
  2023. });
  2024. // Listen for invalidate signals (sent when payload is too large for WebSocket)
  2025. // The server sends a lightweight notification and we re-fetch via REST API
  2026. let invalidateTimer = null;
  2027. window.wsClient.on('invalidate', (payload) => {
  2028. if (payload && (payload.type === 'inbounds' || payload.type === 'traffic')) {
  2029. // Debounce to avoid flooding the REST API with multiple invalidate signals
  2030. if (invalidateTimer) clearTimeout(invalidateTimer);
  2031. invalidateTimer = setTimeout(() => {
  2032. invalidateTimer = null;
  2033. this.getDBInbounds();
  2034. }, 1000);
  2035. }
  2036. });
  2037. // Listen for traffic updates
  2038. window.wsClient.on('traffic', (payload) => {
  2039. // Note: Do NOT update total consumed traffic (stats.up, stats.down) from this event
  2040. // because clientTraffics contains delta/incremental values, not total accumulated values.
  2041. // Total traffic is updated via the 'inbounds' WebSocket event (or 'invalidate' fallback for large panels).
  2042. // Update online clients list in real-time
  2043. if (payload && Array.isArray(payload.onlineClients)) {
  2044. const nextOnlineClients = payload.onlineClients;
  2045. let onlineChanged = this.onlineClients.length !== nextOnlineClients.length;
  2046. if (!onlineChanged) {
  2047. const prevSet = new Set(this.onlineClients);
  2048. for (const email of nextOnlineClients) {
  2049. if (!prevSet.has(email)) {
  2050. onlineChanged = true;
  2051. break;
  2052. }
  2053. }
  2054. }
  2055. this.onlineClients = nextOnlineClients;
  2056. if (onlineChanged) {
  2057. // Recalculate client counts to update online status
  2058. // Use $set for Vue 2 reactivity — direct array index assignment is not reactive
  2059. this.dbInbounds.forEach(dbInbound => {
  2060. const inbound = this.inbounds.find(ib => ib.id === dbInbound.id);
  2061. if (inbound && this.clientCount[dbInbound.id]) {
  2062. this.$set(this.clientCount, dbInbound.id, this.getClientCounts(dbInbound, inbound));
  2063. }
  2064. });
  2065. // Always trigger UI refresh — not just when filter is enabled
  2066. if (this.enableFilter) {
  2067. this.filterInbounds();
  2068. } else {
  2069. this.searchInbounds(this.searchKey);
  2070. }
  2071. }
  2072. }
  2073. // Update last online map in real-time
  2074. // Replace entirely (server sends the full map) to avoid unbounded growth from deleted clients
  2075. if (payload && payload.lastOnlineMap && typeof payload.lastOnlineMap === 'object') {
  2076. this.lastOnlineMap = payload.lastOnlineMap;
  2077. }
  2078. });
  2079. // Fallback to polling if WebSocket fails
  2080. window.wsClient.on('error', () => {
  2081. console.warn('WebSocket connection failed, falling back to polling');
  2082. if (this.isRefreshEnabled) {
  2083. this.startDataRefreshLoop();
  2084. }
  2085. });
  2086. window.wsClient.on('disconnected', () => {
  2087. if (window.wsClient.reconnectAttempts >= window.wsClient.maxReconnectAttempts) {
  2088. console.warn('WebSocket reconnection failed, falling back to polling');
  2089. if (this.isRefreshEnabled) {
  2090. this.startDataRefreshLoop();
  2091. }
  2092. }
  2093. });
  2094. } else {
  2095. // Fallback to polling if WebSocket is not available
  2096. if (this.isRefreshEnabled) {
  2097. this.startDataRefreshLoop();
  2098. }
  2099. }
  2100. },
  2101. computed: {
  2102. total() {
  2103. let down = 0, up = 0, allTime = 0;
  2104. let clients = 0, deactive = [], depleted = [], expiring = [];
  2105. this.dbInbounds.forEach(dbInbound => {
  2106. down += dbInbound.down;
  2107. up += dbInbound.up;
  2108. allTime += (dbInbound.allTime || (dbInbound.up + dbInbound.down));
  2109. if (this.clientCount[dbInbound.id]) {
  2110. clients += this.clientCount[dbInbound.id].clients;
  2111. deactive = deactive.concat(this.clientCount[dbInbound.id].deactive);
  2112. depleted = depleted.concat(this.clientCount[dbInbound.id].depleted);
  2113. expiring = expiring.concat(this.clientCount[dbInbound.id].expiring);
  2114. }
  2115. });
  2116. return {
  2117. down: down,
  2118. up: up,
  2119. allTime: allTime,
  2120. clients: clients,
  2121. deactive: deactive,
  2122. depleted: depleted,
  2123. expiring: expiring,
  2124. };
  2125. }
  2126. },
  2127. });
  2128. </script>
  2129. <style>
  2130. #content-layout > .ant-layout-content > .ant-spin-nested-loading > div > .ant-spin {
  2131. position: fixed !important;
  2132. top: 50vh !important;
  2133. left: calc(50vw + 100px) !important;
  2134. transform: translate(-50%, -50%);
  2135. z-index: 99999 !important;
  2136. }
  2137. @media (max-width: 768px) {
  2138. #content-layout > .ant-layout-content > .ant-spin-nested-loading > div > .ant-spin {
  2139. left: 50vw !important;
  2140. }
  2141. }
  2142. </style>
  2143. {{ template "page/body_end" .}}