inbounds.html 82 KB

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