1
0

inbounds.html 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175
  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. const settings = msg.obj || {};
  1159. this.expireDiff = settings.expireDiff * 86400000;
  1160. this.trafficDiff = settings.trafficDiff * 1073741824;
  1161. this.defaultCert = settings.defaultCert;
  1162. this.defaultKey = settings.defaultKey;
  1163. this.tgBotEnable = settings.tgBotEnable;
  1164. this.subSettings = {
  1165. enable: settings.subEnable,
  1166. subTitle: settings.subTitle,
  1167. subURI: settings.subURI,
  1168. subJsonURI: settings.subJsonURI,
  1169. subJsonEnable: settings.subJsonEnable,
  1170. };
  1171. this.pageSize = settings.pageSize;
  1172. this.remarkModel = settings.remarkModel;
  1173. this.datepicker = settings.datepicker;
  1174. this.ipLimitEnable = settings.ipLimitEnable;
  1175. },
  1176. setInbounds(dbInbounds) {
  1177. this.inbounds.splice(0);
  1178. this.dbInbounds.splice(0);
  1179. this.clientCount.splice(0);
  1180. for (const inbound of dbInbounds) {
  1181. const dbInbound = new DBInbound(inbound);
  1182. to_inbound = dbInbound.toInbound()
  1183. this.inbounds.push(to_inbound);
  1184. this.dbInbounds.push(dbInbound);
  1185. if ([Protocols.VMESS, Protocols.VLESS, Protocols.TROJAN, Protocols.SHADOWSOCKS].includes(inbound.protocol)) {
  1186. if (dbInbound.isSS && (!to_inbound.isSSMultiUser)) {
  1187. continue;
  1188. }
  1189. this.clientCount[inbound.id] = this.getClientCounts(inbound, to_inbound);
  1190. }
  1191. }
  1192. if (!this.loadingStates.fetched) {
  1193. this.loadingStates.fetched = true
  1194. }
  1195. if (this.enableFilter) {
  1196. this.filterInbounds();
  1197. } else {
  1198. this.searchInbounds(this.searchKey);
  1199. }
  1200. },
  1201. getClientCounts(dbInbound, inbound) {
  1202. let clientCount = 0, active = [], deactive = [], depleted = [], expiring = [], online = [], comments = new Map();
  1203. clients = inbound.clients;
  1204. clientStats = dbInbound.clientStats
  1205. now = new Date().getTime()
  1206. if (clients) {
  1207. clientCount = clients.length;
  1208. if (dbInbound.enable) {
  1209. clients.forEach(client => {
  1210. if (client.comment) {
  1211. comments.set(client.email, client.comment)
  1212. }
  1213. if (client.enable) {
  1214. active.push(client.email);
  1215. if (this.isClientOnline(client.email)) online.push(client.email);
  1216. } else {
  1217. deactive.push(client.email);
  1218. }
  1219. });
  1220. clientStats.forEach(stats => {
  1221. const exhausted = stats.total > 0 && (stats.up + stats.down) >= stats.total;
  1222. const expired = stats.expiryTime > 0 && stats.expiryTime <= now;
  1223. if (expired || exhausted) {
  1224. depleted.push(stats.email);
  1225. } else {
  1226. const expiringSoon = (stats.expiryTime > 0 && (stats.expiryTime - now < this.expireDiff)) ||
  1227. (stats.total > 0 && (stats.total - (stats.up + stats.down) < this.trafficDiff));
  1228. if (expiringSoon) expiring.push(stats.email);
  1229. }
  1230. });
  1231. } else {
  1232. clients.forEach(client => {
  1233. deactive.push(client.email);
  1234. });
  1235. }
  1236. }
  1237. return {
  1238. clients: clientCount,
  1239. active: active,
  1240. deactive: deactive,
  1241. depleted: depleted,
  1242. expiring: expiring,
  1243. online: online,
  1244. comments: comments,
  1245. };
  1246. },
  1247. searchInbounds(key) {
  1248. if (ObjectUtil.isEmpty(key)) {
  1249. this.searchedInbounds = this.dbInbounds.slice();
  1250. } else {
  1251. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  1252. this.dbInbounds.forEach(inbound => {
  1253. if (ObjectUtil.deepSearch(inbound, key)) {
  1254. const newInbound = new DBInbound(inbound);
  1255. const inboundSettings = JSON.parse(inbound.settings);
  1256. if (inboundSettings.hasOwnProperty('clients')) {
  1257. const searchedSettings = { "clients": [] };
  1258. inboundSettings.clients.forEach(client => {
  1259. if (ObjectUtil.deepSearch(client, key)) {
  1260. searchedSettings.clients.push(client);
  1261. }
  1262. });
  1263. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, searchedSettings);
  1264. }
  1265. this.searchedInbounds.push(newInbound);
  1266. }
  1267. });
  1268. }
  1269. },
  1270. filterInbounds() {
  1271. if (ObjectUtil.isEmpty(this.filterBy)) {
  1272. this.searchedInbounds = this.dbInbounds.slice();
  1273. } else {
  1274. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  1275. this.dbInbounds.forEach(inbound => {
  1276. const newInbound = new DBInbound(inbound);
  1277. const inboundSettings = JSON.parse(inbound.settings);
  1278. if (this.clientCount[inbound.id] && this.clientCount[inbound.id].hasOwnProperty(this.filterBy)) {
  1279. const list = this.clientCount[inbound.id][this.filterBy];
  1280. if (list.length > 0) {
  1281. const filteredSettings = { "clients": [] };
  1282. if (inboundSettings.clients) {
  1283. inboundSettings.clients.forEach(client => {
  1284. if (list.includes(client.email)) {
  1285. filteredSettings.clients.push(client);
  1286. }
  1287. });
  1288. }
  1289. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, filteredSettings);
  1290. this.searchedInbounds.push(newInbound);
  1291. }
  1292. }
  1293. });
  1294. }
  1295. },
  1296. toggleFilter() {
  1297. if (this.enableFilter) {
  1298. this.searchKey = '';
  1299. } else {
  1300. this.filterBy = '';
  1301. this.searchedInbounds = this.dbInbounds.slice();
  1302. }
  1303. },
  1304. generalActions(action) {
  1305. switch (action.key) {
  1306. case "import":
  1307. this.importInbound();
  1308. break;
  1309. case "export":
  1310. this.exportAllLinks();
  1311. break;
  1312. case "subs":
  1313. this.exportAllSubs();
  1314. break;
  1315. case "resetInbounds":
  1316. this.resetAllTraffic();
  1317. break;
  1318. case "resetClients":
  1319. this.resetAllClientTraffics(-1);
  1320. break;
  1321. case "delDepletedClients":
  1322. this.delDepletedClients(-1)
  1323. break;
  1324. }
  1325. },
  1326. clickAction(action, dbInbound) {
  1327. switch (action.key) {
  1328. case "qrcode":
  1329. this.showQrcode(dbInbound.id);
  1330. break;
  1331. case "showInfo":
  1332. this.showInfo(dbInbound.id);
  1333. break;
  1334. case "edit":
  1335. this.openEditInbound(dbInbound.id);
  1336. break;
  1337. case "addClient":
  1338. this.openAddClient(dbInbound.id)
  1339. break;
  1340. case "addBulkClient":
  1341. this.openAddBulkClient(dbInbound.id)
  1342. break;
  1343. case "copyClients":
  1344. copyClientsModal.show(dbInbound);
  1345. break;
  1346. case "export":
  1347. this.inboundLinks(dbInbound.id);
  1348. break;
  1349. case "subs":
  1350. this.exportSubs(dbInbound.id);
  1351. break;
  1352. case "clipboard":
  1353. this.copy(dbInbound.id);
  1354. break;
  1355. case "resetTraffic":
  1356. this.resetTraffic(dbInbound.id);
  1357. break;
  1358. case "resetClients":
  1359. this.resetAllClientTraffics(dbInbound.id);
  1360. break;
  1361. case "clone":
  1362. this.openCloneInbound(dbInbound);
  1363. break;
  1364. case "delete":
  1365. this.delInbound(dbInbound.id);
  1366. break;
  1367. case "delDepletedClients":
  1368. this.delDepletedClients(dbInbound.id)
  1369. break;
  1370. }
  1371. },
  1372. openCloneInbound(dbInbound) {
  1373. this.$confirm({
  1374. title: '{{ i18n "pages.inbounds.cloneInbound"}} \"' + dbInbound.remark + '\"',
  1375. content: '{{ i18n "pages.inbounds.cloneInboundContent"}}',
  1376. okText: '{{ i18n "pages.inbounds.cloneInboundOk"}}',
  1377. class: themeSwitcher.currentTheme,
  1378. cancelText: '{{ i18n "cancel" }}',
  1379. onOk: () => {
  1380. const baseInbound = dbInbound.toInbound();
  1381. dbInbound.up = 0;
  1382. dbInbound.down = 0;
  1383. this.cloneInbound(baseInbound, dbInbound);
  1384. },
  1385. });
  1386. },
  1387. async cloneInbound(baseInbound, dbInbound) {
  1388. const data = {
  1389. up: dbInbound.up,
  1390. down: dbInbound.down,
  1391. total: dbInbound.total,
  1392. remark: dbInbound.remark + " - Cloned",
  1393. enable: dbInbound.enable,
  1394. expiryTime: dbInbound.expiryTime,
  1395. trafficReset: dbInbound.trafficReset,
  1396. lastTrafficResetTime: dbInbound.lastTrafficResetTime,
  1397. listen: '',
  1398. port: RandomUtil.randomInteger(10000, 60000),
  1399. protocol: baseInbound.protocol,
  1400. settings: Inbound.Settings.getSettings(baseInbound.protocol).toString(),
  1401. streamSettings: baseInbound.stream.toString(),
  1402. sniffing: baseInbound.sniffing.toString(),
  1403. };
  1404. await this.submit('/panel/api/inbounds/add', data, inModal);
  1405. },
  1406. openAddInbound() {
  1407. inModal.show({
  1408. title: '{{ i18n "pages.inbounds.addInbound"}}',
  1409. okText: '{{ i18n "create"}}',
  1410. cancelText: '{{ i18n "close" }}',
  1411. confirm: async (inbound, dbInbound) => {
  1412. await this.addInbound(inbound, dbInbound, inModal);
  1413. },
  1414. isEdit: false
  1415. });
  1416. },
  1417. openEditInbound(dbInboundId) {
  1418. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1419. const inbound = dbInbound.toInbound();
  1420. inModal.show({
  1421. title: '{{ i18n "pages.inbounds.modifyInbound"}}',
  1422. okText: '{{ i18n "update"}}',
  1423. cancelText: '{{ i18n "close" }}',
  1424. inbound: inbound,
  1425. dbInbound: dbInbound,
  1426. confirm: async (inbound, dbInbound) => {
  1427. await this.updateInbound(inbound, dbInbound);
  1428. },
  1429. isEdit: true
  1430. });
  1431. },
  1432. async addInbound(inbound, dbInbound) {
  1433. const data = {
  1434. up: dbInbound.up,
  1435. down: dbInbound.down,
  1436. total: dbInbound.total,
  1437. remark: dbInbound.remark,
  1438. enable: dbInbound.enable,
  1439. expiryTime: dbInbound.expiryTime,
  1440. trafficReset: dbInbound.trafficReset,
  1441. lastTrafficResetTime: dbInbound.lastTrafficResetTime,
  1442. listen: inbound.listen,
  1443. port: inbound.port,
  1444. protocol: inbound.protocol,
  1445. settings: inbound.settings.toString(),
  1446. };
  1447. if (inbound.canEnableStream()) {
  1448. data.streamSettings = inbound.stream.toString();
  1449. } else if (inbound.stream?.sockopt) {
  1450. data.streamSettings = JSON.stringify({ sockopt: inbound.stream.sockopt.toJson() }, null, 2);
  1451. }
  1452. data.sniffing = inbound.sniffing.toString();
  1453. await this.submit('/panel/api/inbounds/add', data, inModal);
  1454. },
  1455. async updateInbound(inbound, dbInbound) {
  1456. const data = {
  1457. up: dbInbound.up,
  1458. down: dbInbound.down,
  1459. total: dbInbound.total,
  1460. remark: dbInbound.remark,
  1461. enable: dbInbound.enable,
  1462. expiryTime: dbInbound.expiryTime,
  1463. trafficReset: dbInbound.trafficReset,
  1464. lastTrafficResetTime: dbInbound.lastTrafficResetTime,
  1465. listen: inbound.listen,
  1466. port: inbound.port,
  1467. protocol: inbound.protocol,
  1468. settings: inbound.settings.toString(),
  1469. };
  1470. if (inbound.canEnableStream()) {
  1471. data.streamSettings = inbound.stream.toString();
  1472. } else if (inbound.stream?.sockopt) {
  1473. data.streamSettings = JSON.stringify({ sockopt: inbound.stream.sockopt.toJson() }, null, 2);
  1474. }
  1475. data.sniffing = inbound.sniffing.toString();
  1476. const formData = new FormData();
  1477. Object.keys(data).forEach(key => formData.append(key, data[key]));
  1478. await this.submit(`/panel/api/inbounds/update/${dbInbound.id}`, formData, inModal);
  1479. },
  1480. openAddClient(dbInboundId) {
  1481. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1482. clientModal.show({
  1483. title: '{{ i18n "pages.client.add"}}',
  1484. okText: '{{ i18n "pages.client.submitAdd"}}',
  1485. dbInbound: dbInbound,
  1486. confirm: async (clients, dbInboundId) => {
  1487. await this.addClient(clients, dbInboundId, clientModal);
  1488. },
  1489. isEdit: false
  1490. });
  1491. },
  1492. openAddBulkClient(dbInboundId) {
  1493. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1494. clientsBulkModal.show({
  1495. title: '{{ i18n "pages.client.bulk"}} ' + dbInbound.remark,
  1496. okText: '{{ i18n "pages.client.bulk"}}',
  1497. dbInbound: dbInbound,
  1498. confirm: async (clients, dbInboundId) => {
  1499. await this.addClient(clients, dbInboundId, clientsBulkModal);
  1500. },
  1501. });
  1502. },
  1503. openEditClient(dbInboundId, client) {
  1504. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1505. if (!dbInbound) return;
  1506. clients = this.getInboundClients(dbInbound);
  1507. if (!clients || !Array.isArray(clients)) return;
  1508. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1509. if (index < 0) return;
  1510. clientModal.show({
  1511. title: '{{ i18n "pages.client.edit"}}',
  1512. okText: '{{ i18n "pages.client.submitEdit"}}',
  1513. dbInbound: dbInbound,
  1514. index: index,
  1515. confirm: async (client, dbInboundId, clientId) => {
  1516. clientModal.loading();
  1517. await this.updateClient(client, dbInboundId, clientId);
  1518. clientModal.close();
  1519. },
  1520. isEdit: true
  1521. });
  1522. },
  1523. findIndexOfClient(protocol, clients, client) {
  1524. if (!clients || !Array.isArray(clients) || !client) {
  1525. return -1;
  1526. }
  1527. switch (protocol) {
  1528. case Protocols.TROJAN:
  1529. case Protocols.SHADOWSOCKS:
  1530. return clients.findIndex(item => item && item.password === client.password && item.email === client.email);
  1531. default: return clients.findIndex(item => item && item.id === client.id && item.email === client.email);
  1532. }
  1533. },
  1534. async addClient(clients, dbInboundId, modal) {
  1535. const data = {
  1536. id: dbInboundId,
  1537. settings: '{"clients": [' + clients.toString() + ']}',
  1538. };
  1539. await this.submit(`/panel/api/inbounds/addClient`, data, modal);
  1540. },
  1541. async updateClient(client, dbInboundId, clientId) {
  1542. const data = {
  1543. id: dbInboundId,
  1544. settings: '{"clients": [' + client.toString() + ']}',
  1545. };
  1546. await this.submit(`/panel/api/inbounds/updateClient/${clientId}`, data, clientModal);
  1547. },
  1548. resetTraffic(dbInboundId) {
  1549. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1550. this.$confirm({
  1551. title: '{{ i18n "pages.inbounds.resetTraffic"}}' + ' #' + dbInboundId,
  1552. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  1553. class: themeSwitcher.currentTheme,
  1554. okText: '{{ i18n "reset"}}',
  1555. cancelText: '{{ i18n "cancel"}}',
  1556. onOk: () => {
  1557. const inbound = dbInbound.toInbound();
  1558. dbInbound.up = 0;
  1559. dbInbound.down = 0;
  1560. this.updateInbound(inbound, dbInbound);
  1561. },
  1562. });
  1563. },
  1564. delInbound(dbInboundId) {
  1565. this.$confirm({
  1566. title: '{{ i18n "pages.inbounds.deleteInbound"}}' + ' #' + dbInboundId,
  1567. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  1568. class: themeSwitcher.currentTheme,
  1569. okText: '{{ i18n "delete"}}',
  1570. cancelText: '{{ i18n "cancel"}}',
  1571. onOk: () => this.submit('/panel/api/inbounds/del/' + dbInboundId),
  1572. });
  1573. },
  1574. delClient(dbInboundId, client, confirmation = true) {
  1575. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1576. clientId = this.getClientId(dbInbound.protocol, client);
  1577. if (confirmation) {
  1578. this.$confirm({
  1579. title: '{{ i18n "pages.inbounds.deleteClient"}}' + ' ' + client.email,
  1580. content: '{{ i18n "pages.inbounds.deleteClientContent"}}',
  1581. class: themeSwitcher.currentTheme,
  1582. okText: '{{ i18n "delete"}}',
  1583. cancelText: '{{ i18n "cancel"}}',
  1584. onOk: () => this.submit(`/panel/api/inbounds/${dbInboundId}/delClient/${clientId}`),
  1585. });
  1586. } else {
  1587. this.submit(`/panel/api/inbounds/${dbInboundId}/delClient/${clientId}`);
  1588. }
  1589. },
  1590. getSubGroupClients(dbInbounds, currentClient) {
  1591. const response = {
  1592. inbounds: [],
  1593. clients: [],
  1594. editIds: []
  1595. }
  1596. if (dbInbounds && dbInbounds.length > 0 && currentClient) {
  1597. dbInbounds.forEach((dbInboundItem) => {
  1598. const dbInbound = new DBInbound(dbInboundItem);
  1599. if (dbInbound) {
  1600. const inbound = dbInbound.toInbound();
  1601. if (inbound) {
  1602. const clients = inbound.clients;
  1603. if (clients.length > 0) {
  1604. clients.forEach((client) => {
  1605. if (client['subId'] === currentClient['subId']) {
  1606. client['inboundId'] = dbInboundItem.id
  1607. client['clientId'] = this.getClientId(dbInbound.protocol, client)
  1608. response.inbounds.push(dbInboundItem.id)
  1609. response.clients.push(client)
  1610. response.editIds.push(client['clientId'])
  1611. }
  1612. })
  1613. }
  1614. }
  1615. }
  1616. })
  1617. }
  1618. return response;
  1619. },
  1620. getClientId(protocol, client) {
  1621. switch (protocol) {
  1622. case Protocols.TROJAN: return client.password;
  1623. case Protocols.SHADOWSOCKS: return client.email;
  1624. case Protocols.HYSTERIA: return client.auth;
  1625. default: return client.id;
  1626. }
  1627. },
  1628. checkFallback(dbInbound) {
  1629. newDbInbound = new DBInbound(dbInbound);
  1630. if (dbInbound.listen.startsWith("@")) {
  1631. rootInbound = this.inbounds.find((i) =>
  1632. i.isTcp &&
  1633. ['trojan', 'vless'].includes(i.protocol) &&
  1634. i.settings.fallbacks.find(f => f.dest === dbInbound.listen)
  1635. );
  1636. if (rootInbound) {
  1637. newDbInbound.listen = rootInbound.listen;
  1638. newDbInbound.port = rootInbound.port;
  1639. newInbound = newDbInbound.toInbound();
  1640. newInbound.stream.security = rootInbound.stream.security;
  1641. newInbound.stream.tls = rootInbound.stream.tls;
  1642. newInbound.stream.externalProxy = rootInbound.stream.externalProxy;
  1643. newDbInbound.streamSettings = newInbound.stream.toString();
  1644. }
  1645. }
  1646. return newDbInbound;
  1647. },
  1648. showQrcode(dbInboundId, client) {
  1649. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1650. newDbInbound = this.checkFallback(dbInbound);
  1651. qrModal.show('{{ i18n "qrCode"}}', newDbInbound, client);
  1652. },
  1653. showInfo(dbInboundId, client) {
  1654. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1655. if (!dbInbound) return;
  1656. index = 0;
  1657. if (dbInbound.isMultiUser()) {
  1658. inbound = dbInbound.toInbound();
  1659. clients = inbound && inbound.clients ? inbound.clients : null;
  1660. if (clients && Array.isArray(clients)) {
  1661. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1662. if (index < 0) index = 0;
  1663. }
  1664. }
  1665. newDbInbound = this.checkFallback(dbInbound);
  1666. infoModal.show(newDbInbound, index);
  1667. },
  1668. switchEnable(dbInboundId, state) {
  1669. let dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1670. if (!dbInbound) return;
  1671. dbInbound.enable = state;
  1672. let inbound = dbInbound.toInbound();
  1673. const data = {
  1674. up: dbInbound.up,
  1675. down: dbInbound.down,
  1676. total: dbInbound.total,
  1677. remark: dbInbound.remark,
  1678. enable: dbInbound.enable,
  1679. expiryTime: dbInbound.expiryTime,
  1680. trafficReset: dbInbound.trafficReset,
  1681. lastTrafficResetTime: dbInbound.lastTrafficResetTime,
  1682. listen: inbound.listen,
  1683. port: inbound.port,
  1684. protocol: inbound.protocol,
  1685. settings: inbound.settings.toString(),
  1686. };
  1687. if (inbound.canEnableStream()) {
  1688. data.streamSettings = inbound.stream.toString();
  1689. } else if (inbound.stream?.sockopt) {
  1690. data.streamSettings = JSON.stringify({ sockopt: inbound.stream.sockopt.toJson() }, null, 2);
  1691. }
  1692. data.sniffing = inbound.sniffing.toString();
  1693. const formData = new FormData();
  1694. Object.keys(data).forEach(key => formData.append(key, data[key]));
  1695. this.submit(`/panel/api/inbounds/update/${dbInboundId}`, formData);
  1696. },
  1697. async switchEnableClient(dbInboundId, client, state) {
  1698. this.loading();
  1699. try {
  1700. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1701. if (!dbInbound) return;
  1702. inbound = dbInbound.toInbound();
  1703. clients = inbound && inbound.clients ? inbound.clients : null;
  1704. if (!clients || !Array.isArray(clients)) return;
  1705. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1706. if (index < 0 || !clients[index]) return;
  1707. clients[index].enable = typeof state === 'boolean' ? state : !!client.enable;
  1708. clientId = this.getClientId(dbInbound.protocol, clients[index]);
  1709. await this.updateClient(clients[index], dbInboundId, clientId);
  1710. } finally {
  1711. this.loading(false);
  1712. }
  1713. },
  1714. async submit(url, data, modal) {
  1715. const msg = await HttpUtil.postWithModal(url, data, modal);
  1716. if (msg.success) {
  1717. await this.getDBInbounds();
  1718. }
  1719. },
  1720. getInboundClients(dbInbound) {
  1721. if (!dbInbound) return null;
  1722. const inbound = dbInbound.toInbound();
  1723. return inbound && inbound.clients ? inbound.clients : null;
  1724. },
  1725. resetClientTraffic(client, dbInboundId, confirmation = true) {
  1726. if (confirmation) {
  1727. this.$confirm({
  1728. title: '{{ i18n "pages.inbounds.resetTraffic"}}' + ' ' + client.email,
  1729. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  1730. class: themeSwitcher.currentTheme,
  1731. okText: '{{ i18n "reset"}}',
  1732. cancelText: '{{ i18n "cancel"}}',
  1733. onOk: () => this.submit('/panel/api/inbounds/' + dbInboundId + '/resetClientTraffic/' + client.email),
  1734. })
  1735. } else {
  1736. this.submit('/panel/api/inbounds/' + dbInboundId + '/resetClientTraffic/' + client.email);
  1737. }
  1738. },
  1739. resetAllTraffic() {
  1740. this.$confirm({
  1741. title: '{{ i18n "pages.inbounds.resetAllTrafficTitle"}}',
  1742. content: '{{ i18n "pages.inbounds.resetAllTrafficContent"}}',
  1743. class: themeSwitcher.currentTheme,
  1744. okText: '{{ i18n "reset"}}',
  1745. cancelText: '{{ i18n "cancel"}}',
  1746. onOk: () => this.submit('/panel/api/inbounds/resetAllTraffics'),
  1747. });
  1748. },
  1749. resetAllClientTraffics(dbInboundId) {
  1750. this.$confirm({
  1751. title: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficTitle"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficTitle"}}',
  1752. content: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficContent"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficContent"}}',
  1753. class: themeSwitcher.currentTheme,
  1754. okText: '{{ i18n "reset"}}',
  1755. cancelText: '{{ i18n "cancel"}}',
  1756. onOk: () => this.submit('/panel/api/inbounds/resetAllClientTraffics/' + dbInboundId),
  1757. })
  1758. },
  1759. delDepletedClients(dbInboundId) {
  1760. this.$confirm({
  1761. title: '{{ i18n "pages.inbounds.delDepletedClientsTitle"}}',
  1762. content: '{{ i18n "pages.inbounds.delDepletedClientsContent"}}',
  1763. class: themeSwitcher.currentTheme,
  1764. okText: '{{ i18n "delete"}}',
  1765. cancelText: '{{ i18n "cancel"}}',
  1766. onOk: () => this.submit('/panel/api/inbounds/delDepletedClients/' + dbInboundId),
  1767. })
  1768. },
  1769. isExpiry(dbInbound, index) {
  1770. return dbInbound.toInbound().isExpiry(index);
  1771. },
  1772. getClientStats(dbInbound, email) {
  1773. if (!dbInbound) return null;
  1774. if (!dbInbound._clientStatsMap) {
  1775. dbInbound._clientStatsMap = new Map();
  1776. if (dbInbound.clientStats && Array.isArray(dbInbound.clientStats)) {
  1777. for (const stats of dbInbound.clientStats) {
  1778. dbInbound._clientStatsMap.set(stats.email, stats);
  1779. }
  1780. }
  1781. }
  1782. return dbInbound._clientStatsMap.get(email);
  1783. },
  1784. getUpStats(dbInbound, email) {
  1785. if (!email || email.length == 0) return 0;
  1786. let clientStats = this.getClientStats(dbInbound, email);
  1787. return clientStats ? clientStats.up : 0;
  1788. },
  1789. getDownStats(dbInbound, email) {
  1790. if (!email || email.length == 0) return 0;
  1791. let clientStats = this.getClientStats(dbInbound, email);
  1792. return clientStats ? clientStats.down : 0;
  1793. },
  1794. getSumStats(dbInbound, email) {
  1795. if (!email || email.length == 0) return 0;
  1796. let clientStats = this.getClientStats(dbInbound, email);
  1797. return clientStats ? clientStats.up + clientStats.down : 0;
  1798. },
  1799. getAllTimeClient(dbInbound, email) {
  1800. if (!email || email.length == 0) return 0;
  1801. let clientStats = this.getClientStats(dbInbound, email);
  1802. if (!clientStats) return 0;
  1803. return clientStats.allTime || (clientStats.up + clientStats.down);
  1804. },
  1805. getRemStats(dbInbound, email) {
  1806. if (!email || email.length == 0) return 0;
  1807. let clientStats = this.getClientStats(dbInbound, email);
  1808. if (!clientStats) return 0;
  1809. let remained = clientStats.total - (clientStats.up + clientStats.down);
  1810. return remained > 0 ? remained : 0;
  1811. },
  1812. clientStatsColor(dbInbound, email) {
  1813. if (!email || email.length == 0) return ColorUtils.clientUsageColor();
  1814. let clientStats = this.getClientStats(dbInbound, email);
  1815. return ColorUtils.clientUsageColor(clientStats, app.trafficDiff)
  1816. },
  1817. statsProgress(dbInbound, email) {
  1818. if (!email || email.length == 0) return 100;
  1819. let clientStats = this.getClientStats(dbInbound, email);
  1820. if (!clientStats) return 0;
  1821. if (clientStats.total == 0) return 100;
  1822. return 100 * (clientStats.down + clientStats.up) / clientStats.total;
  1823. },
  1824. expireProgress(expTime, reset) {
  1825. now = new Date().getTime();
  1826. remainedSeconds = expTime < 0 ? -expTime / 1000 : (expTime - now) / 1000;
  1827. resetSeconds = reset * 86400;
  1828. if (remainedSeconds >= resetSeconds) return 0;
  1829. return 100 * (1 - (remainedSeconds / resetSeconds));
  1830. },
  1831. statsExpColor(dbInbound, email) {
  1832. if (!email || email.length == 0) return '#7a316f';
  1833. let clientStats = this.getClientStats(dbInbound, email);
  1834. if (!clientStats) return '#7a316f';
  1835. let statsColor = ColorUtils.usageColor(clientStats.down + clientStats.up, this.trafficDiff, clientStats.total);
  1836. let expColor = ColorUtils.usageColor(new Date().getTime(), this.expireDiff, clientStats.expiryTime);
  1837. switch (true) {
  1838. case statsColor == "red" || expColor == "red":
  1839. return "#cf3c3c"; // Red
  1840. case statsColor == "orange" || expColor == "orange":
  1841. return "#f37b24"; // Orange
  1842. case statsColor == "green" || expColor == "green":
  1843. return "#008771"; // Green
  1844. default:
  1845. return "#7a316f"; // purple
  1846. }
  1847. },
  1848. isClientEnabled(dbInbound, email) {
  1849. let clientStats = dbInbound ? this.getClientStats(dbInbound, email) : null;
  1850. return clientStats ? clientStats['enable'] : true;
  1851. },
  1852. isClientDepleted(dbInbound, email) {
  1853. if (!email || !dbInbound) return false;
  1854. const stats = this.getClientStats(dbInbound, email);
  1855. if (!stats) return false;
  1856. const total = stats.total ?? 0;
  1857. const used = (stats.up ?? 0) + (stats.down ?? 0);
  1858. const hasTotal = total > 0;
  1859. const exhausted = hasTotal && used >= total;
  1860. const expiryTime = stats.expiryTime ?? 0;
  1861. const hasExpiry = expiryTime > 0;
  1862. const now = Date.now();
  1863. const expired = hasExpiry && expiryTime <= now;
  1864. return expired || exhausted;
  1865. },
  1866. isClientOnline(email) {
  1867. return this.onlineClients.includes(email);
  1868. },
  1869. getLastOnline(email) {
  1870. return this.lastOnlineMap[email] || null
  1871. },
  1872. formatLastOnline(email) {
  1873. const ts = this.getLastOnline(email)
  1874. if (!ts) return '-'
  1875. // Check if IntlUtil is available (may not be loaded yet)
  1876. if (typeof IntlUtil !== 'undefined' && IntlUtil.formatDate) {
  1877. return IntlUtil.formatDate(ts)
  1878. }
  1879. // Fallback to simple date formatting if IntlUtil is not available
  1880. return new Date(ts).toLocaleString()
  1881. },
  1882. isRemovable(dbInboundId) {
  1883. return this.getInboundClients(this.dbInbounds.find(row => row.id === dbInboundId)).length > 1;
  1884. },
  1885. inboundLinks(dbInboundId) {
  1886. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1887. newDbInbound = this.checkFallback(dbInbound);
  1888. txtModal.show('{{ i18n "pages.inbounds.export"}}', newDbInbound.genInboundLinks(this.remarkModel), newDbInbound.remark);
  1889. },
  1890. exportSubs(dbInboundId) {
  1891. const dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1892. const clients = this.getInboundClients(dbInbound);
  1893. let subLinks = []
  1894. if (clients != null) {
  1895. clients.forEach(c => {
  1896. if (c.subId && c.subId.length > 0) {
  1897. subLinks.push(this.subSettings.subURI + c.subId)
  1898. }
  1899. })
  1900. }
  1901. txtModal.show(
  1902. '{{ i18n "pages.inbounds.export"}} - {{ i18n "pages.settings.subSettings" }}',
  1903. [...new Set(subLinks)].join('\n'),
  1904. dbInbound.remark + "-Subs");
  1905. },
  1906. importInbound() {
  1907. promptModal.open({
  1908. title: '{{ i18n "pages.inbounds.importInbound" }}',
  1909. type: 'textarea',
  1910. value: '',
  1911. okText: '{{ i18n "pages.inbounds.import" }}',
  1912. confirm: async (dbInboundText) => {
  1913. await this.submit('/panel/api/inbounds/import', { data: dbInboundText }, promptModal);
  1914. },
  1915. });
  1916. },
  1917. exportAllSubs() {
  1918. let subLinks = []
  1919. for (const dbInbound of this.dbInbounds) {
  1920. const clients = this.getInboundClients(dbInbound);
  1921. if (clients != null) {
  1922. clients.forEach(c => {
  1923. if (c.subId && c.subId.length > 0) {
  1924. subLinks.push(this.subSettings.subURI + c.subId)
  1925. }
  1926. })
  1927. }
  1928. }
  1929. txtModal.show(
  1930. '{{ i18n "pages.inbounds.export"}} - {{ i18n "pages.settings.subSettings" }}',
  1931. [...new Set(subLinks)].join('\r\n'),
  1932. 'All-Inbounds-Subs');
  1933. },
  1934. exportAllLinks() {
  1935. let copyText = [];
  1936. for (const dbInbound of this.dbInbounds) {
  1937. copyText.push(dbInbound.genInboundLinks(this.remarkModel));
  1938. }
  1939. txtModal.show('{{ i18n "pages.inbounds.export"}}', copyText.join('\r\n'), 'All-Inbounds');
  1940. },
  1941. copy(dbInboundId) {
  1942. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1943. txtModal.show('{{ i18n "pages.inbounds.inboundData" }}', JSON.stringify(dbInbound, null, 2));
  1944. },
  1945. async startDataRefreshLoop() {
  1946. while (this.isRefreshEnabled) {
  1947. try {
  1948. await this.getDBInbounds();
  1949. } catch (e) {
  1950. console.error(e);
  1951. }
  1952. await PromiseUtil.sleep(this.refreshInterval);
  1953. }
  1954. },
  1955. toggleRefresh() {
  1956. localStorage.setItem("isRefreshEnabled", this.isRefreshEnabled);
  1957. if (this.isRefreshEnabled) {
  1958. this.startDataRefreshLoop();
  1959. }
  1960. },
  1961. changeRefreshInterval() {
  1962. localStorage.setItem("refreshInterval", this.refreshInterval);
  1963. },
  1964. async manualRefresh() {
  1965. if (!this.refreshing) {
  1966. this.loadingStates.spinning = true;
  1967. await this.getDBInbounds();
  1968. this.loadingStates.spinning = false;
  1969. }
  1970. },
  1971. pagination(obj) {
  1972. if (this.pageSize > 0 && obj.length > this.pageSize) {
  1973. // Set page options based on object size
  1974. let sizeOptions = [this.pageSize.toString()];
  1975. const increments = [2, 5, 10, 20];
  1976. for (const m of increments) {
  1977. const val = this.pageSize * m;
  1978. if (val < obj.length && val <= 1000) {
  1979. sizeOptions.push(val.toString());
  1980. }
  1981. }
  1982. // Add option to see all in one page
  1983. if (!sizeOptions.includes(obj.length.toString())) {
  1984. sizeOptions.push(obj.length.toString());
  1985. }
  1986. p = {
  1987. showSizeChanger: true,
  1988. size: 'small',
  1989. position: 'bottom',
  1990. pageSize: this.pageSize,
  1991. pageSizeOptions: sizeOptions
  1992. };
  1993. return p;
  1994. }
  1995. return false
  1996. }
  1997. },
  1998. watch: {
  1999. searchKey: Utils.debounce(function (newVal) {
  2000. this.searchInbounds(newVal);
  2001. }, 500)
  2002. },
  2003. mounted() {
  2004. if (window.location.protocol !== "https:") {
  2005. this.showAlert = true;
  2006. }
  2007. this.loading();
  2008. this.getDefaultSettings();
  2009. // Initial data fetch
  2010. this.getDBInbounds().then(() => {
  2011. this.loading(false);
  2012. });
  2013. // Setup WebSocket for real-time updates
  2014. if (window.wsClient) {
  2015. window.wsClient.connect();
  2016. // Listen for inbounds updates
  2017. window.wsClient.on('inbounds', (payload) => {
  2018. if (payload && Array.isArray(payload)) {
  2019. // Use setInbounds to properly convert to DBInbound objects with methods
  2020. this.setInbounds(payload);
  2021. }
  2022. });
  2023. // Listen for invalidate signals (sent when payload is too large for WebSocket)
  2024. // The server sends a lightweight notification and we re-fetch via REST API
  2025. let invalidateTimer = null;
  2026. window.wsClient.on('invalidate', (payload) => {
  2027. if (payload && (payload.type === 'inbounds' || payload.type === 'traffic')) {
  2028. // Debounce to avoid flooding the REST API with multiple invalidate signals
  2029. if (invalidateTimer) clearTimeout(invalidateTimer);
  2030. invalidateTimer = setTimeout(() => {
  2031. invalidateTimer = null;
  2032. this.getDBInbounds();
  2033. }, 1000);
  2034. }
  2035. });
  2036. // Listen for traffic updates
  2037. window.wsClient.on('traffic', (payload) => {
  2038. // Note: Do NOT update total consumed traffic (stats.up, stats.down) from this event
  2039. // because clientTraffics contains delta/incremental values, not total accumulated values.
  2040. // Total traffic is updated via the 'inbounds' WebSocket event (or 'invalidate' fallback for large panels).
  2041. // Update online clients list in real-time
  2042. if (payload && Array.isArray(payload.onlineClients)) {
  2043. const nextOnlineClients = payload.onlineClients;
  2044. let onlineChanged = this.onlineClients.length !== nextOnlineClients.length;
  2045. if (!onlineChanged) {
  2046. const prevSet = new Set(this.onlineClients);
  2047. for (const email of nextOnlineClients) {
  2048. if (!prevSet.has(email)) {
  2049. onlineChanged = true;
  2050. break;
  2051. }
  2052. }
  2053. }
  2054. this.onlineClients = nextOnlineClients;
  2055. if (onlineChanged) {
  2056. // Recalculate client counts to update online status
  2057. // Use $set for Vue 2 reactivity — direct array index assignment is not reactive
  2058. this.dbInbounds.forEach(dbInbound => {
  2059. const inbound = this.inbounds.find(ib => ib.id === dbInbound.id);
  2060. if (inbound && this.clientCount[dbInbound.id]) {
  2061. this.$set(this.clientCount, dbInbound.id, this.getClientCounts(dbInbound, inbound));
  2062. }
  2063. });
  2064. // Always trigger UI refresh — not just when filter is enabled
  2065. if (this.enableFilter) {
  2066. this.filterInbounds();
  2067. } else {
  2068. this.searchInbounds(this.searchKey);
  2069. }
  2070. }
  2071. }
  2072. // Update last online map in real-time
  2073. // Replace entirely (server sends the full map) to avoid unbounded growth from deleted clients
  2074. if (payload && payload.lastOnlineMap && typeof payload.lastOnlineMap === 'object') {
  2075. this.lastOnlineMap = payload.lastOnlineMap;
  2076. }
  2077. });
  2078. // Fallback to polling if WebSocket fails
  2079. window.wsClient.on('error', () => {
  2080. console.warn('WebSocket connection failed, falling back to polling');
  2081. if (this.isRefreshEnabled) {
  2082. this.startDataRefreshLoop();
  2083. }
  2084. });
  2085. window.wsClient.on('disconnected', () => {
  2086. if (window.wsClient.reconnectAttempts >= window.wsClient.maxReconnectAttempts) {
  2087. console.warn('WebSocket reconnection failed, falling back to polling');
  2088. if (this.isRefreshEnabled) {
  2089. this.startDataRefreshLoop();
  2090. }
  2091. }
  2092. });
  2093. } else {
  2094. // Fallback to polling if WebSocket is not available
  2095. if (this.isRefreshEnabled) {
  2096. this.startDataRefreshLoop();
  2097. }
  2098. }
  2099. },
  2100. computed: {
  2101. total() {
  2102. let down = 0, up = 0, allTime = 0;
  2103. let clients = 0, deactive = [], depleted = [], expiring = [];
  2104. this.dbInbounds.forEach(dbInbound => {
  2105. down += dbInbound.down;
  2106. up += dbInbound.up;
  2107. allTime += (dbInbound.allTime || (dbInbound.up + dbInbound.down));
  2108. if (this.clientCount[dbInbound.id]) {
  2109. clients += this.clientCount[dbInbound.id].clients;
  2110. deactive = deactive.concat(this.clientCount[dbInbound.id].deactive);
  2111. depleted = depleted.concat(this.clientCount[dbInbound.id].depleted);
  2112. expiring = expiring.concat(this.clientCount[dbInbound.id].expiring);
  2113. }
  2114. });
  2115. return {
  2116. down: down,
  2117. up: up,
  2118. allTime: allTime,
  2119. clients: clients,
  2120. deactive: deactive,
  2121. depleted: depleted,
  2122. expiring: expiring,
  2123. };
  2124. }
  2125. },
  2126. });
  2127. </script>
  2128. <style>
  2129. #content-layout > .ant-layout-content > .ant-spin-nested-loading > div > .ant-spin {
  2130. position: fixed !important;
  2131. top: 50vh !important;
  2132. left: calc(50vw + 100px) !important;
  2133. transform: translate(-50%, -50%);
  2134. z-index: 99999 !important;
  2135. }
  2136. @media (max-width: 768px) {
  2137. #content-layout > .ant-layout-content > .ant-spin-nested-loading > div > .ant-spin {
  2138. left: 50vw !important;
  2139. }
  2140. }
  2141. </style>
  2142. {{ template "page/body_end" .}}