inbounds.html 80 KB

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