1
0

inbounds.html 83 KB

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