1
0

inbounds.html 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957
  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="resetClients">
  265. <a-icon type="file-done"></a-icon>
  266. {{ i18n
  267. "pages.inbounds.resetInboundClientTraffics"}}
  268. </a-menu-item>
  269. <a-menu-item key="export">
  270. <a-icon type="export"></a-icon>
  271. {{ i18n "pages.inbounds.export"}}
  272. </a-menu-item>
  273. <a-menu-item key="subs" v-if="subSettings.enable">
  274. <a-icon type="export"></a-icon>
  275. {{ i18n "pages.inbounds.export"}} - {{ i18n
  276. "pages.settings.subSettings" }}
  277. </a-menu-item>
  278. <a-menu-item key="delDepletedClients"
  279. :style="{ color: '#FF4D4F' }">
  280. <a-icon type="rest"></a-icon>
  281. {{ i18n "pages.inbounds.delDepletedClients" }}
  282. </a-menu-item>
  283. </template>
  284. <template v-else>
  285. <a-menu-item key="showInfo">
  286. <a-icon type="info-circle"></a-icon>
  287. {{ i18n "info"}}
  288. </a-menu-item>
  289. </template>
  290. <a-menu-item key="clipboard">
  291. <a-icon type="copy"></a-icon>
  292. {{ i18n "pages.inbounds.exportInbound" }}
  293. </a-menu-item>
  294. <a-menu-item key="resetTraffic">
  295. <a-icon type="retweet"></a-icon> {{ i18n
  296. "pages.inbounds.resetTraffic" }}
  297. </a-menu-item>
  298. <a-menu-item key="clone">
  299. <a-icon type="block"></a-icon> {{ i18n
  300. "pages.inbounds.clone"}}
  301. </a-menu-item>
  302. <a-menu-item key="delete">
  303. <span :style="{ color: '#FF4D4F' }">
  304. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  305. </span>
  306. </a-menu-item>
  307. <a-menu-item v-if="isMobile">
  308. <a-switch size="small" v-model="dbInbound.enable"
  309. @change="switchEnable(dbInbound.id,dbInbound.enable)"></a-switch>
  310. {{ i18n "pages.inbounds.enable" }}
  311. </a-menu-item>
  312. </a-menu>
  313. </a-dropdown>
  314. </template>
  315. <template slot="protocol" slot-scope="text, dbInbound">
  316. <a-tag :style="{ margin: '0' }" color="purple">[[
  317. dbInbound.protocol ]]</a-tag>
  318. <template
  319. v-if="dbInbound.isVMess || dbInbound.isVLess || dbInbound.isTrojan || dbInbound.isSS">
  320. <a-tag :style="{ margin: '0' }" color="green">[[
  321. dbInbound.toInbound().stream.network ]]</a-tag>
  322. <a-tag :style="{ margin: '0' }"
  323. v-if="dbInbound.toInbound().stream.isTls"
  324. color="blue">TLS</a-tag>
  325. <a-tag :style="{ margin: '0' }"
  326. v-if="dbInbound.toInbound().stream.isReality"
  327. color="blue">Reality</a-tag>
  328. </template>
  329. </template>
  330. <template slot="clients" slot-scope="text, dbInbound">
  331. <template v-if="clientCount[dbInbound.id]">
  332. <a-tag :style="{ margin: '0' }" color="green">[[
  333. clientCount[dbInbound.id].clients ]]</a-tag>
  334. <a-popover title='{{ i18n "disabled" }}'
  335. :overlay-class-name="themeSwitcher.currentTheme">
  336. <template slot="content">
  337. <div
  338. v-for="clientEmail in clientCount[dbInbound.id].deactive"
  339. :key="clientEmail"
  340. class="client-popup-item">
  341. <span>[[ clientEmail ]]</span>
  342. <a-tooltip
  343. :overlay-class-name="themeSwitcher.currentTheme">
  344. <template #title>
  345. [[
  346. clientCount[dbInbound.id].comments.get(clientEmail)
  347. ]]
  348. </template>
  349. <a-icon type="message"
  350. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  351. </a-tooltip>
  352. </div>
  353. </template>
  354. <a-tag :style="{ margin: '0', padding: '0 2px' }"
  355. v-if="clientCount[dbInbound.id].deactive.length">[[
  356. clientCount[dbInbound.id].deactive.length ]]</a-tag>
  357. </a-popover>
  358. <a-popover title='{{ i18n "depleted" }}'
  359. :overlay-class-name="themeSwitcher.currentTheme">
  360. <template slot="content">
  361. <div
  362. v-for="clientEmail in clientCount[dbInbound.id].depleted"
  363. :key="clientEmail"
  364. class="client-popup-item">
  365. <span>[[ clientEmail ]]</span>
  366. <a-tooltip
  367. :overlay-class-name="themeSwitcher.currentTheme">
  368. <template #title>
  369. [[
  370. clientCount[dbInbound.id].comments.get(clientEmail)
  371. ]]
  372. </template>
  373. <a-icon type="message"
  374. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  375. </a-tooltip>
  376. </div>
  377. </template>
  378. <a-tag :style="{ margin: '0', padding: '0 2px' }"
  379. color="red"
  380. v-if="clientCount[dbInbound.id].depleted.length">[[
  381. clientCount[dbInbound.id].depleted.length ]]</a-tag>
  382. </a-popover>
  383. <a-popover title='{{ i18n "depletingSoon" }}'
  384. :overlay-class-name="themeSwitcher.currentTheme">
  385. <template slot="content">
  386. <div
  387. v-for="clientEmail in clientCount[dbInbound.id].expiring"
  388. :key="clientEmail"
  389. class="client-popup-item">
  390. <span>[[ clientEmail ]]</span>
  391. <a-tooltip
  392. :overlay-class-name="themeSwitcher.currentTheme">
  393. <template #title>
  394. [[
  395. clientCount[dbInbound.id].comments.get(clientEmail)
  396. ]]
  397. </template>
  398. <a-icon type="message"
  399. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  400. </a-tooltip>
  401. </div>
  402. </template>
  403. <a-tag :style="{ margin: '0', padding: '0 2px' }"
  404. color="orange"
  405. v-if="clientCount[dbInbound.id].expiring.length">[[
  406. clientCount[dbInbound.id].expiring.length ]]</a-tag>
  407. </a-popover>
  408. <a-popover title='{{ i18n "online" }}'
  409. :overlay-class-name="themeSwitcher.currentTheme">
  410. <template slot="content">
  411. <div
  412. v-for="clientEmail in clientCount[dbInbound.id].online"
  413. :key="clientEmail"
  414. class="client-popup-item">
  415. <span>[[ clientEmail ]]</span>
  416. <a-tooltip
  417. :overlay-class-name="themeSwitcher.currentTheme">
  418. <template #title>
  419. [[
  420. clientCount[dbInbound.id].comments.get(clientEmail)
  421. ]]
  422. </template>
  423. <a-icon type="message"
  424. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  425. </a-tooltip>
  426. </div>
  427. </template>
  428. <a-tag :style="{ margin: '0', padding: '0 2px' }"
  429. color="blue"
  430. v-if="clientCount[dbInbound.id].online.length">[[
  431. clientCount[dbInbound.id].online.length
  432. ]]</a-tag>
  433. </a-popover>
  434. </template>
  435. </template>
  436. <template slot="traffic" slot-scope="text, dbInbound">
  437. <a-popover
  438. :overlay-class-name="themeSwitcher.currentTheme">
  439. <template slot="content">
  440. <table cellpadding="2" width="100%">
  441. <tr>
  442. <td>↑[[ SizeFormatter.sizeFormat(dbInbound.up)
  443. ]]</td>
  444. <td>↓[[ SizeFormatter.sizeFormat(dbInbound.down)
  445. ]]</td>
  446. </tr>
  447. <tr
  448. v-if="dbInbound.total > 0 && dbInbound.up + dbInbound.down < dbInbound.total">
  449. <td>{{ i18n "remained" }}</td>
  450. <td>[[ SizeFormatter.sizeFormat(dbInbound.total -
  451. dbInbound.up - dbInbound.down) ]]</td>
  452. </tr>
  453. </table>
  454. </template>
  455. <a-tag
  456. :color="ColorUtils.usageColor(dbInbound.up + dbInbound.down, app.trafficDiff, dbInbound.total)">
  457. [[ SizeFormatter.sizeFormat(dbInbound.up +
  458. dbInbound.down) ]] /
  459. <template v-if="dbInbound.total > 0">
  460. [[ SizeFormatter.sizeFormat(dbInbound.total) ]]
  461. </template>
  462. <template v-else>
  463. <svg height="10px" width="14px"
  464. viewBox="0 0 640 512" fill="currentColor">
  465. <path
  466. 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"
  467. fill="currentColor"></path>
  468. </svg>
  469. </template>
  470. </a-tag>
  471. </a-popover>
  472. </template>
  473. <template slot="allTimeInbound"
  474. slot-scope="text, dbInbound">
  475. <a-tag>[[ SizeFormatter.sizeFormat(dbInbound.allTime || 0)
  476. ]]</a-tag>
  477. </template>
  478. <template slot="enable" slot-scope="text, dbInbound">
  479. <a-switch v-model="dbInbound.enable"
  480. @change="switchEnable(dbInbound.id,dbInbound.enable)"></a-switch>
  481. </template>
  482. <template slot="expiryTime" slot-scope="text, dbInbound">
  483. <a-popover v-if="dbInbound.expiryTime > 0"
  484. :overlay-class-name="themeSwitcher.currentTheme">
  485. <template slot="content">
  486. [[ IntlUtil.formatDate(dbInbound.expiryTime) ]]
  487. </template>
  488. <a-tag :style="{ minWidth: '50px' }"
  489. :color="ColorUtils.usageColor(new Date().getTime(), app.expireDiff, dbInbound._expiryTime)">
  490. [[ IntlUtil.formatRelativeTime(dbInbound.expiryTime)
  491. ]]
  492. </a-tag>
  493. </a-popover>
  494. <a-tag v-else color="purple" class="infinite-tag">
  495. <svg height="10px" width="14px" viewBox="0 0 640 512"
  496. fill="currentColor">
  497. <path
  498. 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"
  499. fill="currentColor"></path>
  500. </svg>
  501. </a-tag>
  502. </template>
  503. <template slot="info" slot-scope="text, dbInbound">
  504. <a-popover placement="bottomRight"
  505. :overlay-class-name="themeSwitcher.currentTheme"
  506. trigger="click">
  507. <template slot="content">
  508. <table cellpadding="2">
  509. <tr>
  510. <td>{{ i18n "pages.inbounds.protocol" }}</td>
  511. <td>
  512. <a-tag :style="{ margin: '0' }"
  513. color="purple">[[ dbInbound.protocol
  514. ]]</a-tag>
  515. <template
  516. v-if="dbInbound.isVMess || dbInbound.isVLess || dbInbound.isTrojan || dbInbound.isSS">
  517. <a-tag :style="{ margin: '0' }"
  518. color="blue">[[
  519. dbInbound.toInbound().stream.network
  520. ]]</a-tag>
  521. <a-tag :style="{ margin: '0' }"
  522. v-if="dbInbound.toInbound().stream.isTls"
  523. color="green">tls</a-tag>
  524. <a-tag :style="{ margin: '0' }"
  525. v-if="dbInbound.toInbound().stream.isReality"
  526. color="green">reality</a-tag>
  527. </template>
  528. </td>
  529. </tr>
  530. <tr>
  531. <td>{{ i18n "pages.inbounds.port" }}</td>
  532. <td><a-tag>[[ dbInbound.port ]]</a-tag></td>
  533. </tr>
  534. <tr v-if="clientCount[dbInbound.id]">
  535. <td>{{ i18n "clients" }}</td>
  536. <td>
  537. <a-tag :style="{ margin: '0' }" color="blue">[[
  538. clientCount[dbInbound.id].clients
  539. ]]</a-tag>
  540. <a-popover title='{{ i18n "disabled" }}'
  541. :overlay-class-name="themeSwitcher.currentTheme">
  542. <template slot="content">
  543. <div
  544. v-for="clientEmail in clientCount[dbInbound.id].deactive"
  545. :key="clientEmail"
  546. class="client-popup-item">
  547. <span>[[ clientEmail ]]</span>
  548. <a-tooltip
  549. :overlay-class-name="themeSwitcher.currentTheme">
  550. <template #title>
  551. [[
  552. clientCount[dbInbound.id].comments.get(clientEmail)
  553. ]]
  554. </template>
  555. <a-icon type="message"
  556. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  557. </a-tooltip>
  558. </div>
  559. </template>
  560. <a-tag
  561. :style="{ margin: '0', padding: '0 2px' }"
  562. v-if="clientCount[dbInbound.id].deactive.length">[[
  563. clientCount[dbInbound.id].deactive.length
  564. ]]</a-tag>
  565. </a-popover>
  566. <a-popover title='{{ i18n "depleted" }}'
  567. :overlay-class-name="themeSwitcher.currentTheme">
  568. <template slot="content">
  569. <div
  570. v-for="clientEmail in clientCount[dbInbound.id].depleted"
  571. :key="clientEmail"
  572. class="client-popup-item">
  573. <span>[[ clientEmail ]]</span>
  574. <a-tooltip
  575. :overlay-class-name="themeSwitcher.currentTheme">
  576. <template #title>
  577. [[
  578. clientCount[dbInbound.id].comments.get(clientEmail)
  579. ]]
  580. </template>
  581. <a-icon type="message"
  582. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  583. </a-tooltip>
  584. </div>
  585. </template>
  586. <a-tag
  587. :style="{ margin: '0', padding: '0 2px' }"
  588. color="red"
  589. v-if="clientCount[dbInbound.id].depleted.length">[[
  590. clientCount[dbInbound.id].depleted.length
  591. ]]</a-tag>
  592. </a-popover>
  593. <a-popover title='{{ i18n "depletingSoon" }}'
  594. :overlay-class-name="themeSwitcher.currentTheme">
  595. <template slot="content">
  596. <div
  597. v-for="clientEmail in clientCount[dbInbound.id].expiring"
  598. :key="clientEmail"
  599. class="client-popup-item">
  600. <span>[[ clientEmail ]]</span>
  601. <a-tooltip
  602. :overlay-class-name="themeSwitcher.currentTheme">
  603. <template #title>
  604. [[
  605. clientCount[dbInbound.id].comments.get(clientEmail)
  606. ]]
  607. </template>
  608. <a-icon type="message"
  609. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  610. </a-tooltip>
  611. </div>
  612. </template>
  613. <a-tag
  614. :style="{ margin: '0', padding: '0 2px' }"
  615. color="orange"
  616. v-if="clientCount[dbInbound.id].expiring.length">[[
  617. clientCount[dbInbound.id].expiring.length
  618. ]]</a-tag>
  619. </a-popover>
  620. <a-popover title='{{ i18n "online" }}'
  621. :overlay-class-name="themeSwitcher.currentTheme">
  622. <template slot="content">
  623. <div
  624. v-for="clientEmail in clientCount[dbInbound.id].online"
  625. :key="clientEmail"
  626. class="client-popup-item">
  627. <span>[[ clientEmail ]]</span>
  628. <a-tooltip
  629. :overlay-class-name="themeSwitcher.currentTheme">
  630. <template #title>
  631. [[
  632. clientCount[dbInbound.id].comments.get(clientEmail)
  633. ]]
  634. </template>
  635. <a-icon type="message"
  636. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  637. </a-tooltip>
  638. </div>
  639. </template>
  640. <a-tag
  641. :style="{ margin: '0', padding: '0 2px' }"
  642. color="green"
  643. v-if="clientCount[dbInbound.id].online.length">[[
  644. clientCount[dbInbound.id].online.length
  645. ]]</a-tag>
  646. </a-popover>
  647. </td>
  648. </tr>
  649. <tr>
  650. <td>{{ i18n "pages.inbounds.traffic" }}</td>
  651. <td>
  652. <a-popover
  653. :overlay-class-name="themeSwitcher.currentTheme">
  654. <template slot="content">
  655. <table cellpadding="2" width="100%">
  656. <tr>
  657. <td>↑[[
  658. SizeFormatter.sizeFormat(dbInbound.up)
  659. ]]</td>
  660. <td>↓[[
  661. SizeFormatter.sizeFormat(dbInbound.down)
  662. ]]</td>
  663. </tr>
  664. <tr
  665. v-if="dbInbound.total > 0 && dbInbound.up + dbInbound.down < dbInbound.total">
  666. <td>{{ i18n "remained" }}</td>
  667. <td>[[
  668. SizeFormatter.sizeFormat(dbInbound.total
  669. - dbInbound.up - dbInbound.down)
  670. ]]</td>
  671. </tr>
  672. </table>
  673. </template>
  674. <a-tag
  675. :color="ColorUtils.usageColor(dbInbound.up + dbInbound.down, app.trafficDiff, dbInbound.total)">
  676. [[ SizeFormatter.sizeFormat(dbInbound.up +
  677. dbInbound.down) ]] /
  678. <template v-if="dbInbound.total > 0">
  679. [[
  680. SizeFormatter.sizeFormat(dbInbound.total)
  681. ]]
  682. </template>
  683. <template v-else>
  684. <svg height="10px" width="14px"
  685. viewBox="0 0 640 512"
  686. fill="currentColor">
  687. <path
  688. 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"
  689. fill="currentColor"></path>
  690. </svg>
  691. </template>
  692. </a-tag>
  693. </a-popover>
  694. </td>
  695. </tr>
  696. <tr>
  697. <td>{{ i18n "pages.inbounds.expireDate" }}</td>
  698. <td>
  699. <a-tag
  700. :style="{ minWidth: '50px', textAlign: 'center' }"
  701. v-if="dbInbound.expiryTime > 0"
  702. :color="dbInbound.isExpiry? 'red': 'blue'">
  703. [[ IntlUtil.formatDate(dbInbound.expiryTime)
  704. ]]
  705. </a-tag>
  706. <a-tag v-else :style="{ textAlign: 'center' }"
  707. color="purple" class="infinite-tag">
  708. <svg height="10px" width="14px"
  709. viewBox="0 0 640 512" fill="currentColor">
  710. <path
  711. 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"
  712. fill="currentColor"></path>
  713. </svg>
  714. </a-tag>
  715. </td>
  716. </tr>
  717. <tr>
  718. <td>{{ i18n
  719. "pages.inbounds.periodicTrafficResetTitle"
  720. }}</td>
  721. <td>
  722. <a-tag color="blue">[[ dbInbound.trafficReset
  723. ]]</a-tag>
  724. </td>
  725. </tr>
  726. </table>
  727. </template>
  728. <a-badge>
  729. <a-icon v-if="!dbInbound.enable" slot="count"
  730. type="pause-circle"
  731. :style="{ color: themeSwitcher.isDarkTheme ? '#2c3950' : '#bcbcbc' }"></a-icon>
  732. <a-button shape="round" size="small"
  733. :style="{ fontSize: '14px', padding: '0 10px' }">
  734. <a-icon type="info"></a-icon>
  735. </a-button>
  736. </a-badge>
  737. </a-popover>
  738. </template>
  739. <template slot="expandedRowRender" slot-scope="record">
  740. <a-table :row-key="client => client.id"
  741. :columns="isMobile ? innerMobileColumns : innerColumns"
  742. :data-source="getInboundClients(record)"
  743. :pagination=pagination(getInboundClients(record))
  744. :style="{ margin: `-10px ${isMobile ? '2px' : '22px'} -11px` }">
  745. {{template "component/aClientTable"}}
  746. </a-table>
  747. </template>
  748. </a-table>
  749. </a-space>
  750. </a-card>
  751. </a-col>
  752. </a-row>
  753. </transition>
  754. </a-spin>
  755. </a-layout-content>
  756. </a-layout>
  757. </a-layout>
  758. {{template "page/body_scripts" .}}
  759. <script
  760. src="{{ .base_path }}assets/qrcode/qrious2.min.js?{{ .cur_ver }}"></script>
  761. <script src="{{ .base_path }}assets/uri/URI.min.js?{{ .cur_ver }}"></script>
  762. <script
  763. src="{{ .base_path }}assets/js/model/reality_targets.js?{{ .cur_ver }}"></script>
  764. <script
  765. src="{{ .base_path }}assets/js/model/inbound.js?{{ .cur_ver }}"></script>
  766. <script
  767. src="{{ .base_path }}assets/js/model/dbinbound.js?{{ .cur_ver }}"></script>
  768. {{template "component/aSidebar" .}}
  769. {{template "component/aThemeSwitch" .}}
  770. {{template "component/aCustomStatistic" .}}
  771. {{template "component/aPersianDatepicker" .}}
  772. {{template "modals/inboundModal"}}
  773. {{template "modals/promptModal"}}
  774. {{template "modals/qrcodeModal"}}
  775. {{template "modals/textModal"}}
  776. {{template "modals/inboundInfoModal"}}
  777. {{template "modals/clientsModal"}}
  778. {{template "modals/clientsBulkModal"}}
  779. <script>
  780. const columns = [{
  781. title: "ID",
  782. align: 'right',
  783. dataIndex: "id",
  784. width: 30,
  785. responsive: ["xs"],
  786. }, {
  787. title: '{{ i18n "pages.inbounds.operate" }}',
  788. align: 'center',
  789. width: 30,
  790. scopedSlots: { customRender: 'action' },
  791. }, {
  792. title: '{{ i18n "pages.inbounds.enable" }}',
  793. align: 'center',
  794. width: 35,
  795. scopedSlots: { customRender: 'enable' },
  796. }, {
  797. title: '{{ i18n "pages.inbounds.remark" }}',
  798. align: 'center',
  799. width: 60,
  800. dataIndex: "remark",
  801. }, {
  802. title: '{{ i18n "pages.inbounds.port" }}',
  803. align: 'center',
  804. dataIndex: "port",
  805. width: 40,
  806. }, {
  807. title: '{{ i18n "pages.inbounds.protocol" }}',
  808. align: 'left',
  809. width: 70,
  810. scopedSlots: { customRender: 'protocol' },
  811. }, {
  812. title: '{{ i18n "clients" }}',
  813. align: 'left',
  814. width: 50,
  815. scopedSlots: { customRender: 'clients' },
  816. }, {
  817. title: '{{ i18n "pages.inbounds.traffic" }}',
  818. align: 'center',
  819. width: 90,
  820. scopedSlots: { customRender: 'traffic' },
  821. }, {
  822. title: '{{ i18n "pages.inbounds.allTimeTraffic" }}',
  823. align: 'center',
  824. width: 60,
  825. scopedSlots: { customRender: 'allTimeInbound' },
  826. }, {
  827. title: '{{ i18n "pages.inbounds.expireDate" }}',
  828. align: 'center',
  829. width: 40,
  830. scopedSlots: { customRender: 'expiryTime' },
  831. }];
  832. const mobileColumns = [{
  833. title: "ID",
  834. align: 'right',
  835. dataIndex: "id",
  836. width: 10,
  837. responsive: ["s"],
  838. }, {
  839. title: '{{ i18n "pages.inbounds.operate" }}',
  840. align: 'center',
  841. width: 25,
  842. scopedSlots: { customRender: 'action' },
  843. }, {
  844. title: '{{ i18n "pages.inbounds.remark" }}',
  845. align: 'left',
  846. width: 70,
  847. dataIndex: "remark",
  848. }, {
  849. title: '{{ i18n "pages.inbounds.info" }}',
  850. align: 'center',
  851. width: 10,
  852. scopedSlots: { customRender: 'info' },
  853. }];
  854. const innerColumns = [
  855. { title: '{{ i18n "pages.inbounds.operate" }}', width: 70, scopedSlots: { customRender: 'actions' } },
  856. { title: '{{ i18n "pages.inbounds.enable" }}', width: 30, scopedSlots: { customRender: 'enable' } },
  857. { title: '{{ i18n "online" }}', width: 32, scopedSlots: { customRender: 'online' } },
  858. { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } },
  859. { title: '{{ i18n "pages.inbounds.traffic" }}', width: 80, align: 'center', scopedSlots: { customRender: 'traffic' } },
  860. { title: '{{ i18n "pages.inbounds.allTimeTraffic" }}', width: 60, align: 'center', scopedSlots: { customRender: 'allTime' } },
  861. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 80, align: 'center', scopedSlots: { customRender: 'expiryTime' } },
  862. ];
  863. const innerMobileColumns = [
  864. { title: '{{ i18n "pages.inbounds.operate" }}', width: 10, align: 'center', scopedSlots: { customRender: 'actionMenu' } },
  865. { title: '{{ i18n "pages.inbounds.client" }}', width: 90, align: 'left', scopedSlots: { customRender: 'client' } },
  866. { title: '{{ i18n "pages.inbounds.info" }}', width: 10, align: 'center', scopedSlots: { customRender: 'info' } },
  867. ];
  868. const app = new Vue({
  869. delimiters: ['[[', ']]'],
  870. el: '#app',
  871. mixins: [MediaQueryMixin],
  872. data: {
  873. themeSwitcher,
  874. persianDatepicker,
  875. loadingStates: {
  876. fetched: false,
  877. spinning: false
  878. },
  879. inbounds: [],
  880. dbInbounds: [],
  881. searchKey: '',
  882. enableFilter: false,
  883. filterBy: '',
  884. searchedInbounds: [],
  885. expireDiff: 0,
  886. trafficDiff: 0,
  887. defaultCert: '',
  888. defaultKey: '',
  889. clientCount: [],
  890. onlineClients: [],
  891. lastOnlineMap: {},
  892. isRefreshEnabled: localStorage.getItem("isRefreshEnabled") === "true" ? true : false,
  893. refreshing: false,
  894. refreshInterval: Number(localStorage.getItem("refreshInterval")) || 5000,
  895. subSettings: {
  896. enable: false,
  897. subTitle: '',
  898. subURI: '',
  899. subJsonURI: '',
  900. subJsonEnable: false,
  901. },
  902. remarkModel: '-ieo',
  903. datepicker: 'gregorian',
  904. tgBotEnable: false,
  905. showAlert: false,
  906. ipLimitEnable: false,
  907. pageSize: 0,
  908. },
  909. methods: {
  910. loading(spinning = true) {
  911. this.loadingStates.spinning = spinning;
  912. },
  913. async getDBInbounds() {
  914. this.refreshing = true;
  915. const msg = await HttpUtil.get('/panel/api/inbounds/list');
  916. if (!msg.success) {
  917. this.refreshing = false;
  918. return;
  919. }
  920. await this.getLastOnlineMap();
  921. await this.getOnlineUsers();
  922. this.setInbounds(msg.obj);
  923. setTimeout(() => {
  924. this.refreshing = false;
  925. }, 500);
  926. },
  927. async getOnlineUsers() {
  928. const msg = await HttpUtil.post('/panel/api/inbounds/onlines');
  929. if (!msg.success) {
  930. return;
  931. }
  932. this.onlineClients = msg.obj != null ? msg.obj : [];
  933. },
  934. async getLastOnlineMap() {
  935. const msg = await HttpUtil.post('/panel/api/inbounds/lastOnline');
  936. if (!msg.success || !msg.obj) return;
  937. this.lastOnlineMap = msg.obj || {}
  938. },
  939. async getDefaultSettings() {
  940. const msg = await HttpUtil.post('/panel/setting/defaultSettings');
  941. if (!msg.success) {
  942. return;
  943. }
  944. with (msg.obj) {
  945. this.expireDiff = expireDiff * 86400000;
  946. this.trafficDiff = trafficDiff * 1073741824;
  947. this.defaultCert = defaultCert;
  948. this.defaultKey = defaultKey;
  949. this.tgBotEnable = tgBotEnable;
  950. this.subSettings = {
  951. enable: subEnable,
  952. subTitle: subTitle,
  953. subURI: subURI,
  954. subJsonURI: subJsonURI,
  955. subJsonEnable: subJsonEnable,
  956. };
  957. this.pageSize = pageSize;
  958. this.remarkModel = remarkModel;
  959. this.datepicker = datepicker;
  960. this.ipLimitEnable = ipLimitEnable;
  961. }
  962. },
  963. setInbounds(dbInbounds) {
  964. this.inbounds.splice(0);
  965. this.dbInbounds.splice(0);
  966. this.clientCount.splice(0);
  967. for (const inbound of dbInbounds) {
  968. const dbInbound = new DBInbound(inbound);
  969. to_inbound = dbInbound.toInbound()
  970. this.inbounds.push(to_inbound);
  971. this.dbInbounds.push(dbInbound);
  972. if ([Protocols.VMESS, Protocols.VLESS, Protocols.TROJAN, Protocols.SHADOWSOCKS].includes(inbound.protocol)) {
  973. if (dbInbound.isSS && (!to_inbound.isSSMultiUser)) {
  974. continue;
  975. }
  976. this.clientCount[inbound.id] = this.getClientCounts(inbound, to_inbound);
  977. }
  978. }
  979. if (!this.loadingStates.fetched) {
  980. this.loadingStates.fetched = true
  981. }
  982. if (this.enableFilter) {
  983. this.filterInbounds();
  984. } else {
  985. this.searchInbounds(this.searchKey);
  986. }
  987. },
  988. getClientCounts(dbInbound, inbound) {
  989. let clientCount = 0, active = [], deactive = [], depleted = [], expiring = [], online = [], comments = new Map();
  990. clients = inbound.clients;
  991. clientStats = dbInbound.clientStats
  992. now = new Date().getTime()
  993. if (clients) {
  994. clientCount = clients.length;
  995. if (dbInbound.enable) {
  996. clients.forEach(client => {
  997. if (client.comment) {
  998. comments.set(client.email, client.comment)
  999. }
  1000. if (client.enable) {
  1001. active.push(client.email);
  1002. if (this.isClientOnline(client.email)) online.push(client.email);
  1003. } else {
  1004. deactive.push(client.email);
  1005. }
  1006. });
  1007. clientStats.forEach(stats => {
  1008. const exhausted = stats.total > 0 && (stats.up + stats.down) >= stats.total;
  1009. const expired = stats.expiryTime > 0 && stats.expiryTime <= now;
  1010. if (expired || exhausted) {
  1011. depleted.push(stats.email);
  1012. } else {
  1013. const expiringSoon = (stats.expiryTime > 0 && (stats.expiryTime - now < this.expireDiff)) ||
  1014. (stats.total > 0 && (stats.total - (stats.up + stats.down) < this.trafficDiff));
  1015. if (expiringSoon) expiring.push(stats.email);
  1016. }
  1017. });
  1018. } else {
  1019. clients.forEach(client => {
  1020. deactive.push(client.email);
  1021. });
  1022. }
  1023. }
  1024. return {
  1025. clients: clientCount,
  1026. active: active,
  1027. deactive: deactive,
  1028. depleted: depleted,
  1029. expiring: expiring,
  1030. online: online,
  1031. comments: comments,
  1032. };
  1033. },
  1034. searchInbounds(key) {
  1035. if (ObjectUtil.isEmpty(key)) {
  1036. this.searchedInbounds = this.dbInbounds.slice();
  1037. } else {
  1038. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  1039. this.dbInbounds.forEach(inbound => {
  1040. if (ObjectUtil.deepSearch(inbound, key)) {
  1041. const newInbound = new DBInbound(inbound);
  1042. const inboundSettings = JSON.parse(inbound.settings);
  1043. if (inboundSettings.hasOwnProperty('clients')) {
  1044. const searchedSettings = { "clients": [] };
  1045. inboundSettings.clients.forEach(client => {
  1046. if (ObjectUtil.deepSearch(client, key)) {
  1047. searchedSettings.clients.push(client);
  1048. }
  1049. });
  1050. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, searchedSettings);
  1051. }
  1052. this.searchedInbounds.push(newInbound);
  1053. }
  1054. });
  1055. }
  1056. },
  1057. filterInbounds() {
  1058. if (ObjectUtil.isEmpty(this.filterBy)) {
  1059. this.searchedInbounds = this.dbInbounds.slice();
  1060. } else {
  1061. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  1062. this.dbInbounds.forEach(inbound => {
  1063. const newInbound = new DBInbound(inbound);
  1064. const inboundSettings = JSON.parse(inbound.settings);
  1065. if (this.clientCount[inbound.id] && this.clientCount[inbound.id].hasOwnProperty(this.filterBy)) {
  1066. const list = this.clientCount[inbound.id][this.filterBy];
  1067. if (list.length > 0) {
  1068. const filteredSettings = { "clients": [] };
  1069. if (inboundSettings.clients) {
  1070. inboundSettings.clients.forEach(client => {
  1071. if (list.includes(client.email)) {
  1072. filteredSettings.clients.push(client);
  1073. }
  1074. });
  1075. }
  1076. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, filteredSettings);
  1077. this.searchedInbounds.push(newInbound);
  1078. }
  1079. }
  1080. });
  1081. }
  1082. },
  1083. toggleFilter() {
  1084. if (this.enableFilter) {
  1085. this.searchKey = '';
  1086. } else {
  1087. this.filterBy = '';
  1088. this.searchedInbounds = this.dbInbounds.slice();
  1089. }
  1090. },
  1091. generalActions(action) {
  1092. switch (action.key) {
  1093. case "import":
  1094. this.importInbound();
  1095. break;
  1096. case "export":
  1097. this.exportAllLinks();
  1098. break;
  1099. case "subs":
  1100. this.exportAllSubs();
  1101. break;
  1102. case "resetInbounds":
  1103. this.resetAllTraffic();
  1104. break;
  1105. case "resetClients":
  1106. this.resetAllClientTraffics(-1);
  1107. break;
  1108. case "delDepletedClients":
  1109. this.delDepletedClients(-1)
  1110. break;
  1111. }
  1112. },
  1113. clickAction(action, dbInbound) {
  1114. switch (action.key) {
  1115. case "qrcode":
  1116. this.showQrcode(dbInbound.id);
  1117. break;
  1118. case "showInfo":
  1119. this.showInfo(dbInbound.id);
  1120. break;
  1121. case "edit":
  1122. this.openEditInbound(dbInbound.id);
  1123. break;
  1124. case "addClient":
  1125. this.openAddClient(dbInbound.id)
  1126. break;
  1127. case "addBulkClient":
  1128. this.openAddBulkClient(dbInbound.id)
  1129. break;
  1130. case "export":
  1131. this.inboundLinks(dbInbound.id);
  1132. break;
  1133. case "subs":
  1134. this.exportSubs(dbInbound.id);
  1135. break;
  1136. case "clipboard":
  1137. this.copy(dbInbound.id);
  1138. break;
  1139. case "resetTraffic":
  1140. this.resetTraffic(dbInbound.id);
  1141. break;
  1142. case "resetClients":
  1143. this.resetAllClientTraffics(dbInbound.id);
  1144. break;
  1145. case "clone":
  1146. this.openCloneInbound(dbInbound);
  1147. break;
  1148. case "delete":
  1149. this.delInbound(dbInbound.id);
  1150. break;
  1151. case "delDepletedClients":
  1152. this.delDepletedClients(dbInbound.id)
  1153. break;
  1154. }
  1155. },
  1156. openCloneInbound(dbInbound) {
  1157. this.$confirm({
  1158. title: '{{ i18n "pages.inbounds.cloneInbound"}} \"' + dbInbound.remark + '\"',
  1159. content: '{{ i18n "pages.inbounds.cloneInboundContent"}}',
  1160. okText: '{{ i18n "pages.inbounds.cloneInboundOk"}}',
  1161. class: themeSwitcher.currentTheme,
  1162. cancelText: '{{ i18n "cancel" }}',
  1163. onOk: () => {
  1164. const baseInbound = dbInbound.toInbound();
  1165. dbInbound.up = 0;
  1166. dbInbound.down = 0;
  1167. this.cloneInbound(baseInbound, dbInbound);
  1168. },
  1169. });
  1170. },
  1171. async cloneInbound(baseInbound, dbInbound) {
  1172. const data = {
  1173. up: dbInbound.up,
  1174. down: dbInbound.down,
  1175. total: dbInbound.total,
  1176. remark: dbInbound.remark + " - Cloned",
  1177. enable: dbInbound.enable,
  1178. expiryTime: dbInbound.expiryTime,
  1179. trafficReset: dbInbound.trafficReset,
  1180. lastTrafficResetTime: dbInbound.lastTrafficResetTime,
  1181. listen: '',
  1182. port: RandomUtil.randomInteger(10000, 60000),
  1183. protocol: baseInbound.protocol,
  1184. settings: Inbound.Settings.getSettings(baseInbound.protocol).toString(),
  1185. streamSettings: baseInbound.stream.toString(),
  1186. sniffing: baseInbound.sniffing.toString(),
  1187. };
  1188. await this.submit('/panel/api/inbounds/add', data, inModal);
  1189. },
  1190. openAddInbound() {
  1191. inModal.show({
  1192. title: '{{ i18n "pages.inbounds.addInbound"}}',
  1193. okText: '{{ i18n "create"}}',
  1194. cancelText: '{{ i18n "close" }}',
  1195. confirm: async (inbound, dbInbound) => {
  1196. await this.addInbound(inbound, dbInbound, inModal);
  1197. },
  1198. isEdit: false
  1199. });
  1200. },
  1201. openEditInbound(dbInboundId) {
  1202. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1203. const inbound = dbInbound.toInbound();
  1204. inModal.show({
  1205. title: '{{ i18n "pages.inbounds.modifyInbound"}}',
  1206. okText: '{{ i18n "update"}}',
  1207. cancelText: '{{ i18n "close" }}',
  1208. inbound: inbound,
  1209. dbInbound: dbInbound,
  1210. confirm: async (inbound, dbInbound) => {
  1211. await this.updateInbound(inbound, dbInbound);
  1212. },
  1213. isEdit: true
  1214. });
  1215. },
  1216. async addInbound(inbound, dbInbound) {
  1217. const data = {
  1218. up: dbInbound.up,
  1219. down: dbInbound.down,
  1220. total: dbInbound.total,
  1221. remark: dbInbound.remark,
  1222. enable: dbInbound.enable,
  1223. expiryTime: dbInbound.expiryTime,
  1224. trafficReset: dbInbound.trafficReset,
  1225. lastTrafficResetTime: dbInbound.lastTrafficResetTime,
  1226. listen: inbound.listen,
  1227. port: inbound.port,
  1228. protocol: inbound.protocol,
  1229. settings: inbound.settings.toString(),
  1230. };
  1231. if (inbound.canEnableStream()) {
  1232. data.streamSettings = inbound.stream.toString();
  1233. } else if (inbound.stream?.sockopt) {
  1234. data.streamSettings = JSON.stringify({ sockopt: inbound.stream.sockopt.toJson() }, null, 2);
  1235. }
  1236. data.sniffing = inbound.sniffing.toString();
  1237. await this.submit('/panel/api/inbounds/add', data, inModal);
  1238. },
  1239. async updateInbound(inbound, dbInbound) {
  1240. const data = {
  1241. up: dbInbound.up,
  1242. down: dbInbound.down,
  1243. total: dbInbound.total,
  1244. remark: dbInbound.remark,
  1245. enable: dbInbound.enable,
  1246. expiryTime: dbInbound.expiryTime,
  1247. trafficReset: dbInbound.trafficReset,
  1248. lastTrafficResetTime: dbInbound.lastTrafficResetTime,
  1249. listen: inbound.listen,
  1250. port: inbound.port,
  1251. protocol: inbound.protocol,
  1252. settings: inbound.settings.toString(),
  1253. };
  1254. if (inbound.canEnableStream()) {
  1255. data.streamSettings = inbound.stream.toString();
  1256. } else if (inbound.stream?.sockopt) {
  1257. data.streamSettings = JSON.stringify({ sockopt: inbound.stream.sockopt.toJson() }, null, 2);
  1258. }
  1259. data.sniffing = inbound.sniffing.toString();
  1260. const formData = new FormData();
  1261. Object.keys(data).forEach(key => formData.append(key, data[key]));
  1262. await this.submit(`/panel/api/inbounds/update/${dbInbound.id}`, formData, inModal);
  1263. },
  1264. openAddClient(dbInboundId) {
  1265. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1266. clientModal.show({
  1267. title: '{{ i18n "pages.client.add"}}',
  1268. okText: '{{ i18n "pages.client.submitAdd"}}',
  1269. dbInbound: dbInbound,
  1270. confirm: async (clients, dbInboundId) => {
  1271. await this.addClient(clients, dbInboundId, clientModal);
  1272. },
  1273. isEdit: false
  1274. });
  1275. },
  1276. openAddBulkClient(dbInboundId) {
  1277. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1278. clientsBulkModal.show({
  1279. title: '{{ i18n "pages.client.bulk"}} ' + dbInbound.remark,
  1280. okText: '{{ i18n "pages.client.bulk"}}',
  1281. dbInbound: dbInbound,
  1282. confirm: async (clients, dbInboundId) => {
  1283. await this.addClient(clients, dbInboundId, clientsBulkModal);
  1284. },
  1285. });
  1286. },
  1287. openEditClient(dbInboundId, client) {
  1288. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1289. if (!dbInbound) return;
  1290. clients = this.getInboundClients(dbInbound);
  1291. if (!clients || !Array.isArray(clients)) return;
  1292. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1293. if (index < 0) return;
  1294. clientModal.show({
  1295. title: '{{ i18n "pages.client.edit"}}',
  1296. okText: '{{ i18n "pages.client.submitEdit"}}',
  1297. dbInbound: dbInbound,
  1298. index: index,
  1299. confirm: async (client, dbInboundId, clientId) => {
  1300. clientModal.loading();
  1301. await this.updateClient(client, dbInboundId, clientId);
  1302. clientModal.close();
  1303. },
  1304. isEdit: true
  1305. });
  1306. },
  1307. findIndexOfClient(protocol, clients, client) {
  1308. if (!clients || !Array.isArray(clients) || !client) {
  1309. return -1;
  1310. }
  1311. switch (protocol) {
  1312. case Protocols.TROJAN:
  1313. case Protocols.SHADOWSOCKS:
  1314. return clients.findIndex(item => item && item.password === client.password && item.email === client.email);
  1315. default: return clients.findIndex(item => item && item.id === client.id && item.email === client.email);
  1316. }
  1317. },
  1318. async addClient(clients, dbInboundId, modal) {
  1319. const data = {
  1320. id: dbInboundId,
  1321. settings: '{"clients": [' + clients.toString() + ']}',
  1322. };
  1323. await this.submit(`/panel/api/inbounds/addClient`, data, modal);
  1324. },
  1325. async updateClient(client, dbInboundId, clientId) {
  1326. const data = {
  1327. id: dbInboundId,
  1328. settings: '{"clients": [' + client.toString() + ']}',
  1329. };
  1330. await this.submit(`/panel/api/inbounds/updateClient/${clientId}`, data, clientModal);
  1331. },
  1332. resetTraffic(dbInboundId) {
  1333. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1334. this.$confirm({
  1335. title: '{{ i18n "pages.inbounds.resetTraffic"}}' + ' #' + dbInboundId,
  1336. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  1337. class: themeSwitcher.currentTheme,
  1338. okText: '{{ i18n "reset"}}',
  1339. cancelText: '{{ i18n "cancel"}}',
  1340. onOk: () => {
  1341. const inbound = dbInbound.toInbound();
  1342. dbInbound.up = 0;
  1343. dbInbound.down = 0;
  1344. this.updateInbound(inbound, dbInbound);
  1345. },
  1346. });
  1347. },
  1348. delInbound(dbInboundId) {
  1349. this.$confirm({
  1350. title: '{{ i18n "pages.inbounds.deleteInbound"}}' + ' #' + dbInboundId,
  1351. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  1352. class: themeSwitcher.currentTheme,
  1353. okText: '{{ i18n "delete"}}',
  1354. cancelText: '{{ i18n "cancel"}}',
  1355. onOk: () => this.submit('/panel/api/inbounds/del/' + dbInboundId),
  1356. });
  1357. },
  1358. delClient(dbInboundId, client, confirmation = true) {
  1359. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1360. clientId = this.getClientId(dbInbound.protocol, client);
  1361. if (confirmation) {
  1362. this.$confirm({
  1363. title: '{{ i18n "pages.inbounds.deleteClient"}}' + ' ' + client.email,
  1364. content: '{{ i18n "pages.inbounds.deleteClientContent"}}',
  1365. class: themeSwitcher.currentTheme,
  1366. okText: '{{ i18n "delete"}}',
  1367. cancelText: '{{ i18n "cancel"}}',
  1368. onOk: () => this.submit(`/panel/api/inbounds/${dbInboundId}/delClient/${clientId}`),
  1369. });
  1370. } else {
  1371. this.submit(`/panel/api/inbounds/${dbInboundId}/delClient/${clientId}`);
  1372. }
  1373. },
  1374. getSubGroupClients(dbInbounds, currentClient) {
  1375. const response = {
  1376. inbounds: [],
  1377. clients: [],
  1378. editIds: []
  1379. }
  1380. if (dbInbounds && dbInbounds.length > 0 && currentClient) {
  1381. dbInbounds.forEach((dbInboundItem) => {
  1382. const dbInbound = new DBInbound(dbInboundItem);
  1383. if (dbInbound) {
  1384. const inbound = dbInbound.toInbound();
  1385. if (inbound) {
  1386. const clients = inbound.clients;
  1387. if (clients.length > 0) {
  1388. clients.forEach((client) => {
  1389. if (client['subId'] === currentClient['subId']) {
  1390. client['inboundId'] = dbInboundItem.id
  1391. client['clientId'] = this.getClientId(dbInbound.protocol, client)
  1392. response.inbounds.push(dbInboundItem.id)
  1393. response.clients.push(client)
  1394. response.editIds.push(client['clientId'])
  1395. }
  1396. })
  1397. }
  1398. }
  1399. }
  1400. })
  1401. }
  1402. return response;
  1403. },
  1404. getClientId(protocol, client) {
  1405. switch (protocol) {
  1406. case Protocols.TROJAN: return client.password;
  1407. case Protocols.SHADOWSOCKS: return client.email;
  1408. case Protocols.HYSTERIA: return client.auth;
  1409. default: return client.id;
  1410. }
  1411. },
  1412. checkFallback(dbInbound) {
  1413. newDbInbound = new DBInbound(dbInbound);
  1414. if (dbInbound.listen.startsWith("@")) {
  1415. rootInbound = this.inbounds.find((i) =>
  1416. i.isTcp &&
  1417. ['trojan', 'vless'].includes(i.protocol) &&
  1418. i.settings.fallbacks.find(f => f.dest === dbInbound.listen)
  1419. );
  1420. if (rootInbound) {
  1421. newDbInbound.listen = rootInbound.listen;
  1422. newDbInbound.port = rootInbound.port;
  1423. newInbound = newDbInbound.toInbound();
  1424. newInbound.stream.security = rootInbound.stream.security;
  1425. newInbound.stream.tls = rootInbound.stream.tls;
  1426. newInbound.stream.externalProxy = rootInbound.stream.externalProxy;
  1427. newDbInbound.streamSettings = newInbound.stream.toString();
  1428. }
  1429. }
  1430. return newDbInbound;
  1431. },
  1432. showQrcode(dbInboundId, client) {
  1433. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1434. newDbInbound = this.checkFallback(dbInbound);
  1435. qrModal.show('{{ i18n "qrCode"}}', newDbInbound, client);
  1436. },
  1437. showInfo(dbInboundId, client) {
  1438. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1439. if (!dbInbound) return;
  1440. index = 0;
  1441. if (dbInbound.isMultiUser()) {
  1442. inbound = dbInbound.toInbound();
  1443. clients = inbound && inbound.clients ? inbound.clients : null;
  1444. if (clients && Array.isArray(clients)) {
  1445. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1446. if (index < 0) index = 0;
  1447. }
  1448. }
  1449. newDbInbound = this.checkFallback(dbInbound);
  1450. infoModal.show(newDbInbound, index);
  1451. },
  1452. switchEnable(dbInboundId, state) {
  1453. let dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1454. if (!dbInbound) return;
  1455. dbInbound.enable = state;
  1456. let inbound = dbInbound.toInbound();
  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. this.submit(`/panel/api/inbounds/update/${dbInboundId}`, formData);
  1480. },
  1481. async switchEnableClient(dbInboundId, client, state) {
  1482. this.loading();
  1483. try {
  1484. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1485. if (!dbInbound) return;
  1486. inbound = dbInbound.toInbound();
  1487. clients = inbound && inbound.clients ? inbound.clients : null;
  1488. if (!clients || !Array.isArray(clients)) return;
  1489. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1490. if (index < 0 || !clients[index]) return;
  1491. clients[index].enable = typeof state === 'boolean' ? state : !!client.enable;
  1492. clientId = this.getClientId(dbInbound.protocol, clients[index]);
  1493. await this.updateClient(clients[index], dbInboundId, clientId);
  1494. } finally {
  1495. this.loading(false);
  1496. }
  1497. },
  1498. async submit(url, data, modal) {
  1499. const msg = await HttpUtil.postWithModal(url, data, modal);
  1500. if (msg.success) {
  1501. await this.getDBInbounds();
  1502. }
  1503. },
  1504. getInboundClients(dbInbound) {
  1505. if (!dbInbound) return null;
  1506. const inbound = dbInbound.toInbound();
  1507. return inbound && inbound.clients ? inbound.clients : null;
  1508. },
  1509. resetClientTraffic(client, dbInboundId, confirmation = true) {
  1510. if (confirmation) {
  1511. this.$confirm({
  1512. title: '{{ i18n "pages.inbounds.resetTraffic"}}' + ' ' + client.email,
  1513. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  1514. class: themeSwitcher.currentTheme,
  1515. okText: '{{ i18n "reset"}}',
  1516. cancelText: '{{ i18n "cancel"}}',
  1517. onOk: () => this.submit('/panel/api/inbounds/' + dbInboundId + '/resetClientTraffic/' + client.email),
  1518. })
  1519. } else {
  1520. this.submit('/panel/api/inbounds/' + dbInboundId + '/resetClientTraffic/' + client.email);
  1521. }
  1522. },
  1523. resetAllTraffic() {
  1524. this.$confirm({
  1525. title: '{{ i18n "pages.inbounds.resetAllTrafficTitle"}}',
  1526. content: '{{ i18n "pages.inbounds.resetAllTrafficContent"}}',
  1527. class: themeSwitcher.currentTheme,
  1528. okText: '{{ i18n "reset"}}',
  1529. cancelText: '{{ i18n "cancel"}}',
  1530. onOk: () => this.submit('/panel/api/inbounds/resetAllTraffics'),
  1531. });
  1532. },
  1533. resetAllClientTraffics(dbInboundId) {
  1534. this.$confirm({
  1535. title: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficTitle"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficTitle"}}',
  1536. content: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficContent"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficContent"}}',
  1537. class: themeSwitcher.currentTheme,
  1538. okText: '{{ i18n "reset"}}',
  1539. cancelText: '{{ i18n "cancel"}}',
  1540. onOk: () => this.submit('/panel/api/inbounds/resetAllClientTraffics/' + dbInboundId),
  1541. })
  1542. },
  1543. delDepletedClients(dbInboundId) {
  1544. this.$confirm({
  1545. title: '{{ i18n "pages.inbounds.delDepletedClientsTitle"}}',
  1546. content: '{{ i18n "pages.inbounds.delDepletedClientsContent"}}',
  1547. class: themeSwitcher.currentTheme,
  1548. okText: '{{ i18n "delete"}}',
  1549. cancelText: '{{ i18n "cancel"}}',
  1550. onOk: () => this.submit('/panel/api/inbounds/delDepletedClients/' + dbInboundId),
  1551. })
  1552. },
  1553. isExpiry(dbInbound, index) {
  1554. return dbInbound.toInbound().isExpiry(index);
  1555. },
  1556. getClientStats(dbInbound, email) {
  1557. if (!dbInbound) return null;
  1558. if (!dbInbound._clientStatsMap) {
  1559. dbInbound._clientStatsMap = new Map();
  1560. if (dbInbound.clientStats && Array.isArray(dbInbound.clientStats)) {
  1561. for (const stats of dbInbound.clientStats) {
  1562. dbInbound._clientStatsMap.set(stats.email, stats);
  1563. }
  1564. }
  1565. }
  1566. return dbInbound._clientStatsMap.get(email);
  1567. },
  1568. getUpStats(dbInbound, email) {
  1569. if (!email || email.length == 0) return 0;
  1570. let clientStats = this.getClientStats(dbInbound, email);
  1571. return clientStats ? clientStats.up : 0;
  1572. },
  1573. getDownStats(dbInbound, email) {
  1574. if (!email || email.length == 0) return 0;
  1575. let clientStats = this.getClientStats(dbInbound, email);
  1576. return clientStats ? clientStats.down : 0;
  1577. },
  1578. getSumStats(dbInbound, email) {
  1579. if (!email || email.length == 0) return 0;
  1580. let clientStats = this.getClientStats(dbInbound, email);
  1581. return clientStats ? clientStats.up + clientStats.down : 0;
  1582. },
  1583. getAllTimeClient(dbInbound, email) {
  1584. if (!email || email.length == 0) return 0;
  1585. let clientStats = this.getClientStats(dbInbound, email);
  1586. if (!clientStats) return 0;
  1587. return clientStats.allTime || (clientStats.up + clientStats.down);
  1588. },
  1589. getRemStats(dbInbound, email) {
  1590. if (!email || email.length == 0) return 0;
  1591. let clientStats = this.getClientStats(dbInbound, email);
  1592. if (!clientStats) return 0;
  1593. let remained = clientStats.total - (clientStats.up + clientStats.down);
  1594. return remained > 0 ? remained : 0;
  1595. },
  1596. clientStatsColor(dbInbound, email) {
  1597. if (!email || email.length == 0) return ColorUtils.clientUsageColor();
  1598. let clientStats = this.getClientStats(dbInbound, email);
  1599. return ColorUtils.clientUsageColor(clientStats, app.trafficDiff)
  1600. },
  1601. statsProgress(dbInbound, email) {
  1602. if (!email || email.length == 0) return 100;
  1603. let clientStats = this.getClientStats(dbInbound, email);
  1604. if (!clientStats) return 0;
  1605. if (clientStats.total == 0) return 100;
  1606. return 100 * (clientStats.down + clientStats.up) / clientStats.total;
  1607. },
  1608. expireProgress(expTime, reset) {
  1609. now = new Date().getTime();
  1610. remainedSeconds = expTime < 0 ? -expTime / 1000 : (expTime - now) / 1000;
  1611. resetSeconds = reset * 86400;
  1612. if (remainedSeconds >= resetSeconds) return 0;
  1613. return 100 * (1 - (remainedSeconds / resetSeconds));
  1614. },
  1615. statsExpColor(dbInbound, email) {
  1616. if (!email || email.length == 0) return '#7a316f';
  1617. let clientStats = this.getClientStats(dbInbound, email);
  1618. if (!clientStats) return '#7a316f';
  1619. let statsColor = ColorUtils.usageColor(clientStats.down + clientStats.up, this.trafficDiff, clientStats.total);
  1620. let expColor = ColorUtils.usageColor(new Date().getTime(), this.expireDiff, clientStats.expiryTime);
  1621. switch (true) {
  1622. case statsColor == "red" || expColor == "red":
  1623. return "#cf3c3c"; // Red
  1624. case statsColor == "orange" || expColor == "orange":
  1625. return "#f37b24"; // Orange
  1626. case statsColor == "green" || expColor == "green":
  1627. return "#008771"; // Green
  1628. default:
  1629. return "#7a316f"; // purple
  1630. }
  1631. },
  1632. isClientEnabled(dbInbound, email) {
  1633. let clientStats = dbInbound ? this.getClientStats(dbInbound, email) : null;
  1634. return clientStats ? clientStats['enable'] : true;
  1635. },
  1636. isClientDepleted(dbInbound, email) {
  1637. if (!email || !dbInbound) return false;
  1638. const stats = this.getClientStats(dbInbound, email);
  1639. if (!stats) return false;
  1640. const total = stats.total ?? 0;
  1641. const used = (stats.up ?? 0) + (stats.down ?? 0);
  1642. const hasTotal = total > 0;
  1643. const exhausted = hasTotal && used >= total;
  1644. const expiryTime = stats.expiryTime ?? 0;
  1645. const hasExpiry = expiryTime > 0;
  1646. const now = Date.now();
  1647. const expired = hasExpiry && expiryTime <= now;
  1648. return expired || exhausted;
  1649. },
  1650. isClientOnline(email) {
  1651. return this.onlineClients.includes(email);
  1652. },
  1653. getLastOnline(email) {
  1654. return this.lastOnlineMap[email] || null
  1655. },
  1656. formatLastOnline(email) {
  1657. const ts = this.getLastOnline(email)
  1658. if (!ts) return '-'
  1659. // Check if IntlUtil is available (may not be loaded yet)
  1660. if (typeof IntlUtil !== 'undefined' && IntlUtil.formatDate) {
  1661. return IntlUtil.formatDate(ts)
  1662. }
  1663. // Fallback to simple date formatting if IntlUtil is not available
  1664. return new Date(ts).toLocaleString()
  1665. },
  1666. isRemovable(dbInboundId) {
  1667. return this.getInboundClients(this.dbInbounds.find(row => row.id === dbInboundId)).length > 1;
  1668. },
  1669. inboundLinks(dbInboundId) {
  1670. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1671. newDbInbound = this.checkFallback(dbInbound);
  1672. txtModal.show('{{ i18n "pages.inbounds.export"}}', newDbInbound.genInboundLinks(this.remarkModel), newDbInbound.remark);
  1673. },
  1674. exportSubs(dbInboundId) {
  1675. const dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1676. const clients = this.getInboundClients(dbInbound);
  1677. let subLinks = []
  1678. if (clients != null) {
  1679. clients.forEach(c => {
  1680. if (c.subId && c.subId.length > 0) {
  1681. subLinks.push(this.subSettings.subURI + c.subId)
  1682. }
  1683. })
  1684. }
  1685. txtModal.show(
  1686. '{{ i18n "pages.inbounds.export"}} - {{ i18n "pages.settings.subSettings" }}',
  1687. [...new Set(subLinks)].join('\n'),
  1688. dbInbound.remark + "-Subs");
  1689. },
  1690. importInbound() {
  1691. promptModal.open({
  1692. title: '{{ i18n "pages.inbounds.importInbound" }}',
  1693. type: 'textarea',
  1694. value: '',
  1695. okText: '{{ i18n "pages.inbounds.import" }}',
  1696. confirm: async (dbInboundText) => {
  1697. await this.submit('/panel/api/inbounds/import', { data: dbInboundText }, promptModal);
  1698. },
  1699. });
  1700. },
  1701. exportAllSubs() {
  1702. let subLinks = []
  1703. for (const dbInbound of this.dbInbounds) {
  1704. const clients = this.getInboundClients(dbInbound);
  1705. if (clients != null) {
  1706. clients.forEach(c => {
  1707. if (c.subId && c.subId.length > 0) {
  1708. subLinks.push(this.subSettings.subURI + c.subId)
  1709. }
  1710. })
  1711. }
  1712. }
  1713. txtModal.show(
  1714. '{{ i18n "pages.inbounds.export"}} - {{ i18n "pages.settings.subSettings" }}',
  1715. [...new Set(subLinks)].join('\r\n'),
  1716. 'All-Inbounds-Subs');
  1717. },
  1718. exportAllLinks() {
  1719. let copyText = [];
  1720. for (const dbInbound of this.dbInbounds) {
  1721. copyText.push(dbInbound.genInboundLinks(this.remarkModel));
  1722. }
  1723. txtModal.show('{{ i18n "pages.inbounds.export"}}', copyText.join('\r\n'), 'All-Inbounds');
  1724. },
  1725. copy(dbInboundId) {
  1726. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1727. txtModal.show('{{ i18n "pages.inbounds.inboundData" }}', JSON.stringify(dbInbound, null, 2));
  1728. },
  1729. async startDataRefreshLoop() {
  1730. while (this.isRefreshEnabled) {
  1731. try {
  1732. await this.getDBInbounds();
  1733. } catch (e) {
  1734. console.error(e);
  1735. }
  1736. await PromiseUtil.sleep(this.refreshInterval);
  1737. }
  1738. },
  1739. toggleRefresh() {
  1740. localStorage.setItem("isRefreshEnabled", this.isRefreshEnabled);
  1741. if (this.isRefreshEnabled) {
  1742. this.startDataRefreshLoop();
  1743. }
  1744. },
  1745. changeRefreshInterval() {
  1746. localStorage.setItem("refreshInterval", this.refreshInterval);
  1747. },
  1748. async manualRefresh() {
  1749. if (!this.refreshing) {
  1750. this.loadingStates.spinning = true;
  1751. await this.getDBInbounds();
  1752. this.loadingStates.spinning = false;
  1753. }
  1754. },
  1755. pagination(obj) {
  1756. if (this.pageSize > 0 && obj.length > this.pageSize) {
  1757. // Set page options based on object size
  1758. let sizeOptions = [this.pageSize.toString()];
  1759. const increments = [2, 5, 10, 20];
  1760. for (const m of increments) {
  1761. const val = this.pageSize * m;
  1762. if (val < obj.length && val <= 1000) {
  1763. sizeOptions.push(val.toString());
  1764. }
  1765. }
  1766. // Add option to see all in one page
  1767. if (!sizeOptions.includes(obj.length.toString())) {
  1768. sizeOptions.push(obj.length.toString());
  1769. }
  1770. p = {
  1771. showSizeChanger: true,
  1772. size: 'small',
  1773. position: 'bottom',
  1774. pageSize: this.pageSize,
  1775. pageSizeOptions: sizeOptions
  1776. };
  1777. return p;
  1778. }
  1779. return false
  1780. }
  1781. },
  1782. watch: {
  1783. searchKey: Utils.debounce(function (newVal) {
  1784. this.searchInbounds(newVal);
  1785. }, 500)
  1786. },
  1787. mounted() {
  1788. if (window.location.protocol !== "https:") {
  1789. this.showAlert = true;
  1790. }
  1791. this.loading();
  1792. this.getDefaultSettings();
  1793. // Initial data fetch
  1794. this.getDBInbounds().then(() => {
  1795. this.loading(false);
  1796. });
  1797. // Setup WebSocket for real-time updates
  1798. if (window.wsClient) {
  1799. window.wsClient.connect();
  1800. // Listen for inbounds updates
  1801. window.wsClient.on('inbounds', (payload) => {
  1802. if (payload && Array.isArray(payload)) {
  1803. // Use setInbounds to properly convert to DBInbound objects with methods
  1804. this.setInbounds(payload);
  1805. }
  1806. });
  1807. // Listen for invalidate signals (sent when payload is too large for WebSocket)
  1808. // The server sends a lightweight notification and we re-fetch via REST API
  1809. let invalidateTimer = null;
  1810. window.wsClient.on('invalidate', (payload) => {
  1811. if (payload && (payload.type === 'inbounds' || payload.type === 'traffic')) {
  1812. // Debounce to avoid flooding the REST API with multiple invalidate signals
  1813. if (invalidateTimer) clearTimeout(invalidateTimer);
  1814. invalidateTimer = setTimeout(() => {
  1815. invalidateTimer = null;
  1816. this.getDBInbounds();
  1817. }, 1000);
  1818. }
  1819. });
  1820. // Listen for traffic updates
  1821. window.wsClient.on('traffic', (payload) => {
  1822. // Note: Do NOT update total consumed traffic (stats.up, stats.down) from this event
  1823. // because clientTraffics contains delta/incremental values, not total accumulated values.
  1824. // Total traffic is updated via the 'inbounds' WebSocket event (or 'invalidate' fallback for large panels).
  1825. // Update online clients list in real-time
  1826. if (payload && Array.isArray(payload.onlineClients)) {
  1827. const nextOnlineClients = payload.onlineClients;
  1828. let onlineChanged = this.onlineClients.length !== nextOnlineClients.length;
  1829. if (!onlineChanged) {
  1830. const prevSet = new Set(this.onlineClients);
  1831. for (const email of nextOnlineClients) {
  1832. if (!prevSet.has(email)) {
  1833. onlineChanged = true;
  1834. break;
  1835. }
  1836. }
  1837. }
  1838. this.onlineClients = nextOnlineClients;
  1839. if (onlineChanged) {
  1840. // Recalculate client counts to update online status
  1841. // Use $set for Vue 2 reactivity — direct array index assignment is not reactive
  1842. this.dbInbounds.forEach(dbInbound => {
  1843. const inbound = this.inbounds.find(ib => ib.id === dbInbound.id);
  1844. if (inbound && this.clientCount[dbInbound.id]) {
  1845. this.$set(this.clientCount, dbInbound.id, this.getClientCounts(dbInbound, inbound));
  1846. }
  1847. });
  1848. // Always trigger UI refresh — not just when filter is enabled
  1849. if (this.enableFilter) {
  1850. this.filterInbounds();
  1851. } else {
  1852. this.searchInbounds(this.searchKey);
  1853. }
  1854. }
  1855. }
  1856. // Update last online map in real-time
  1857. // Replace entirely (server sends the full map) to avoid unbounded growth from deleted clients
  1858. if (payload && payload.lastOnlineMap && typeof payload.lastOnlineMap === 'object') {
  1859. this.lastOnlineMap = payload.lastOnlineMap;
  1860. }
  1861. });
  1862. // Fallback to polling if WebSocket fails
  1863. window.wsClient.on('error', () => {
  1864. console.warn('WebSocket connection failed, falling back to polling');
  1865. if (this.isRefreshEnabled) {
  1866. this.startDataRefreshLoop();
  1867. }
  1868. });
  1869. window.wsClient.on('disconnected', () => {
  1870. if (window.wsClient.reconnectAttempts >= window.wsClient.maxReconnectAttempts) {
  1871. console.warn('WebSocket reconnection failed, falling back to polling');
  1872. if (this.isRefreshEnabled) {
  1873. this.startDataRefreshLoop();
  1874. }
  1875. }
  1876. });
  1877. } else {
  1878. // Fallback to polling if WebSocket is not available
  1879. if (this.isRefreshEnabled) {
  1880. this.startDataRefreshLoop();
  1881. }
  1882. }
  1883. },
  1884. computed: {
  1885. total() {
  1886. let down = 0, up = 0, allTime = 0;
  1887. let clients = 0, deactive = [], depleted = [], expiring = [];
  1888. this.dbInbounds.forEach(dbInbound => {
  1889. down += dbInbound.down;
  1890. up += dbInbound.up;
  1891. allTime += (dbInbound.allTime || (dbInbound.up + dbInbound.down));
  1892. if (this.clientCount[dbInbound.id]) {
  1893. clients += this.clientCount[dbInbound.id].clients;
  1894. deactive = deactive.concat(this.clientCount[dbInbound.id].deactive);
  1895. depleted = depleted.concat(this.clientCount[dbInbound.id].depleted);
  1896. expiring = expiring.concat(this.clientCount[dbInbound.id].expiring);
  1897. }
  1898. });
  1899. return {
  1900. down: down,
  1901. up: up,
  1902. allTime: allTime,
  1903. clients: clients,
  1904. deactive: deactive,
  1905. depleted: depleted,
  1906. expiring: expiring,
  1907. };
  1908. }
  1909. },
  1910. });
  1911. </script>
  1912. <style>
  1913. #content-layout > .ant-layout-content > .ant-spin-nested-loading > div > .ant-spin {
  1914. position: fixed !important;
  1915. top: 50vh !important;
  1916. left: calc(50vw + 100px) !important;
  1917. transform: translate(-50%, -50%);
  1918. z-index: 99999 !important;
  1919. }
  1920. @media (max-width: 768px) {
  1921. #content-layout > .ant-layout-content > .ant-spin-nested-loading > div > .ant-spin {
  1922. left: 50vw !important;
  1923. }
  1924. }
  1925. </style>
  1926. {{ template "page/body_end" .}}