inbounds.html 82 KB

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