inbounds.html 77 KB

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