1
0

inbounds.html 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532
  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. </table>
  506. </template>
  507. <a-badge>
  508. <a-icon v-if="!dbInbound.enable" slot="count" type="pause-circle" :style="{ color: themeSwitcher.isDarkTheme ? '#2c3950' : '#bcbcbc' }"></a-icon>
  509. <a-button shape="round" size="small" :style="{ fontSize: '14px', padding: '0 10px' }">
  510. <a-icon type="info"></a-icon>
  511. </a-button>
  512. </a-badge>
  513. </a-popover>
  514. </template>
  515. <template slot="expandedRowRender" slot-scope="record">
  516. <a-table
  517. :row-key="client => client.id"
  518. :columns="isMobile ? innerMobileColumns : innerColumns"
  519. :data-source="getInboundClients(record)"
  520. :pagination=pagination(getInboundClients(record))
  521. :style="{ margin: `-10px ${isMobile ? '2px' : '22px'} -11px` }">
  522. {{template "component/aClientTable"}}
  523. </a-table>
  524. </template>
  525. </a-table>
  526. </a-space>
  527. </a-card>
  528. </a-col>
  529. </a-row>
  530. </transition>
  531. </a-spin>
  532. </a-layout-content>
  533. </a-layout>
  534. </a-layout>
  535. {{template "page/body_scripts" .}}
  536. <script src="{{ .base_path }}assets/qrcode/qrious2.min.js?{{ .cur_ver }}"></script>
  537. <script src="{{ .base_path }}assets/uri/URI.min.js?{{ .cur_ver }}"></script>
  538. <script src="{{ .base_path }}assets/js/model/inbound.js?{{ .cur_ver }}"></script>
  539. <script src="{{ .base_path }}assets/js/model/dbinbound.js?{{ .cur_ver }}"></script>
  540. {{template "component/aSidebar" .}}
  541. {{template "component/aThemeSwitch" .}}
  542. {{template "component/aCustomStatistic" .}}
  543. {{template "component/aPersianDatepicker" .}}
  544. {{template "modals/inboundModal"}}
  545. {{template "modals/promptModal"}}
  546. {{template "modals/qrcodeModal"}}
  547. {{template "modals/textModal"}}
  548. {{template "modals/inboundInfoModal"}}
  549. {{template "modals/clientsModal"}}
  550. {{template "modals/clientsBulkModal"}}
  551. <script>
  552. const columns = [{
  553. title: "ID",
  554. align: 'right',
  555. dataIndex: "id",
  556. width: 30,
  557. responsive: ["xs"],
  558. }, {
  559. title: '{{ i18n "pages.inbounds.operate" }}',
  560. align: 'center',
  561. width: 30,
  562. scopedSlots: { customRender: 'action' },
  563. }, {
  564. title: '{{ i18n "pages.inbounds.enable" }}',
  565. align: 'center',
  566. width: 35,
  567. scopedSlots: { customRender: 'enable' },
  568. }, {
  569. title: '{{ i18n "pages.inbounds.remark" }}',
  570. align: 'center',
  571. width: 60,
  572. dataIndex: "remark",
  573. }, {
  574. title: '{{ i18n "pages.inbounds.port" }}',
  575. align: 'center',
  576. dataIndex: "port",
  577. width: 40,
  578. }, {
  579. title: '{{ i18n "pages.inbounds.protocol" }}',
  580. align: 'left',
  581. width: 70,
  582. scopedSlots: { customRender: 'protocol' },
  583. }, {
  584. title: '{{ i18n "clients" }}',
  585. align: 'left',
  586. width: 50,
  587. scopedSlots: { customRender: 'clients' },
  588. }, {
  589. title: '{{ i18n "pages.inbounds.traffic" }}',
  590. align: 'center',
  591. width: 90,
  592. scopedSlots: { customRender: 'traffic' },
  593. }, {
  594. title: '{{ i18n "pages.inbounds.allTimeTraffic" }}',
  595. align: 'center',
  596. width: 70,
  597. scopedSlots: { customRender: 'allTimeInbound' },
  598. }, {
  599. title: '{{ i18n "pages.inbounds.expireDate" }}',
  600. align: 'center',
  601. width: 40,
  602. scopedSlots: { customRender: 'expiryTime' },
  603. }];
  604. const mobileColumns = [{
  605. title: "ID",
  606. align: 'right',
  607. dataIndex: "id",
  608. width: 10,
  609. responsive: ["s"],
  610. }, {
  611. title: '{{ i18n "pages.inbounds.operate" }}',
  612. align: 'center',
  613. width: 25,
  614. scopedSlots: { customRender: 'action' },
  615. }, {
  616. title: '{{ i18n "pages.inbounds.remark" }}',
  617. align: 'left',
  618. width: 70,
  619. dataIndex: "remark",
  620. }, {
  621. title: '{{ i18n "pages.inbounds.info" }}',
  622. align: 'center',
  623. width: 10,
  624. scopedSlots: { customRender: 'info' },
  625. }];
  626. const innerColumns = [
  627. { title: '{{ i18n "pages.inbounds.operate" }}', width: 65, scopedSlots: { customRender: 'actions' } },
  628. { title: '{{ i18n "pages.inbounds.enable" }}', width: 35, scopedSlots: { customRender: 'enable' } },
  629. { title: '{{ i18n "online" }}', width: 32, scopedSlots: { customRender: 'online' } },
  630. { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } },
  631. { title: '{{ i18n "pages.inbounds.traffic" }}', width: 80, align: 'center', scopedSlots: { customRender: 'traffic' } },
  632. { title: '{{ i18n "pages.inbounds.allTimeTraffic" }}', width: 80, align: 'center', scopedSlots: { customRender: 'allTime' } },
  633. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 80, align: 'center', scopedSlots: { customRender: 'expiryTime' } },
  634. ];
  635. const innerMobileColumns = [
  636. { title: '{{ i18n "pages.inbounds.operate" }}', width: 10, align: 'center', scopedSlots: { customRender: 'actionMenu' } },
  637. { title: '{{ i18n "pages.inbounds.client" }}', width: 90, align: 'left', scopedSlots: { customRender: 'client' } },
  638. { title: '{{ i18n "pages.inbounds.info" }}', width: 10, align: 'center', scopedSlots: { customRender: 'info' } },
  639. ];
  640. const app = new Vue({
  641. delimiters: ['[[', ']]'],
  642. el: '#app',
  643. mixins: [MediaQueryMixin],
  644. data: {
  645. themeSwitcher,
  646. persianDatepicker,
  647. loadingStates: {
  648. fetched: false,
  649. spinning: false
  650. },
  651. inbounds: [],
  652. dbInbounds: [],
  653. searchKey: '',
  654. enableFilter: false,
  655. filterBy: '',
  656. searchedInbounds: [],
  657. expireDiff: 0,
  658. trafficDiff: 0,
  659. defaultCert: '',
  660. defaultKey: '',
  661. clientCount: [],
  662. onlineClients: [],
  663. lastOnlineMap: {},
  664. isRefreshEnabled: localStorage.getItem("isRefreshEnabled") === "true" ? true : false,
  665. refreshing: false,
  666. refreshInterval: Number(localStorage.getItem("refreshInterval")) || 5000,
  667. subSettings: {
  668. enable : false,
  669. subTitle : '',
  670. subURI : '',
  671. subJsonURI : '',
  672. },
  673. remarkModel: '-ieo',
  674. datepicker: 'gregorian',
  675. tgBotEnable: false,
  676. showAlert: false,
  677. ipLimitEnable: false,
  678. pageSize: 50,
  679. },
  680. methods: {
  681. loading(spinning = true) {
  682. this.loadingStates.spinning = spinning;
  683. },
  684. async getDBInbounds() {
  685. this.refreshing = true;
  686. const msg = await HttpUtil.get('/panel/api/inbounds/list');
  687. if (!msg.success) {
  688. this.refreshing = false;
  689. return;
  690. }
  691. await this.getLastOnlineMap();
  692. await this.getOnlineUsers();
  693. this.setInbounds(msg.obj);
  694. setTimeout(() => {
  695. this.refreshing = false;
  696. }, 500);
  697. },
  698. async getOnlineUsers() {
  699. const msg = await HttpUtil.post('/panel/api/inbounds/onlines');
  700. if (!msg.success) {
  701. return;
  702. }
  703. this.onlineClients = msg.obj != null ? msg.obj : [];
  704. },
  705. async getLastOnlineMap() {
  706. const msg = await HttpUtil.post('/panel/api/inbounds/lastOnline');
  707. if (!msg.success || !msg.obj) return;
  708. this.lastOnlineMap = msg.obj || {}
  709. },
  710. async getDefaultSettings() {
  711. const msg = await HttpUtil.post('/panel/setting/defaultSettings');
  712. if (!msg.success) {
  713. return;
  714. }
  715. with(msg.obj){
  716. this.expireDiff = expireDiff * 86400000;
  717. this.trafficDiff = trafficDiff * 1073741824;
  718. this.defaultCert = defaultCert;
  719. this.defaultKey = defaultKey;
  720. this.tgBotEnable = tgBotEnable;
  721. this.subSettings = {
  722. enable : subEnable,
  723. subTitle : subTitle,
  724. subURI: subURI,
  725. subJsonURI: subJsonURI
  726. };
  727. this.pageSize = pageSize;
  728. this.remarkModel = remarkModel;
  729. this.datepicker = datepicker;
  730. this.ipLimitEnable = ipLimitEnable;
  731. }
  732. },
  733. setInbounds(dbInbounds) {
  734. this.inbounds.splice(0);
  735. this.dbInbounds.splice(0);
  736. this.clientCount.splice(0);
  737. for (const inbound of dbInbounds) {
  738. const dbInbound = new DBInbound(inbound);
  739. to_inbound = dbInbound.toInbound()
  740. this.inbounds.push(to_inbound);
  741. this.dbInbounds.push(dbInbound);
  742. if ([Protocols.VMESS, Protocols.VLESS, Protocols.TROJAN, Protocols.SHADOWSOCKS].includes(inbound.protocol)) {
  743. if (dbInbound.isSS && (!to_inbound.isSSMultiUser)) {
  744. continue;
  745. }
  746. this.clientCount[inbound.id] = this.getClientCounts(inbound, to_inbound);
  747. }
  748. }
  749. if (!this.loadingStates.fetched) {
  750. this.loadingStates.fetched = true
  751. }
  752. if(this.enableFilter){
  753. this.filterInbounds();
  754. } else {
  755. this.searchInbounds(this.searchKey);
  756. }
  757. },
  758. getClientCounts(dbInbound, inbound) {
  759. let clientCount = 0, active = [], deactive = [], depleted = [], expiring = [], online = [], comments = new Map();
  760. clients = inbound.clients;
  761. clientStats = dbInbound.clientStats
  762. now = new Date().getTime()
  763. if (clients) {
  764. clientCount = clients.length;
  765. if (dbInbound.enable) {
  766. clients.forEach(client => {
  767. if (client.comment) {
  768. comments.set(client.email, client.comment)
  769. }
  770. if (client.enable) {
  771. active.push(client.email);
  772. if (this.isClientOnline(client.email)) online.push(client.email);
  773. } else {
  774. deactive.push(client.email);
  775. }
  776. });
  777. clientStats.forEach(client => {
  778. if (!client.enable) {
  779. depleted.push(client.email);
  780. } else {
  781. if ((client.expiryTime > 0 && (client.expiryTime - now < this.expireDiff)) ||
  782. (client.total > 0 && (client.total - (client.up + client.down) < this.trafficDiff))) expiring.push(client.email);
  783. }
  784. });
  785. } else {
  786. clients.forEach(client => {
  787. deactive.push(client.email);
  788. });
  789. }
  790. }
  791. return {
  792. clients: clientCount,
  793. active: active,
  794. deactive: deactive,
  795. depleted: depleted,
  796. expiring: expiring,
  797. online: online,
  798. comments: comments,
  799. };
  800. },
  801. searchInbounds(key) {
  802. if (ObjectUtil.isEmpty(key)) {
  803. this.searchedInbounds = this.dbInbounds.slice();
  804. } else {
  805. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  806. this.dbInbounds.forEach(inbound => {
  807. if (ObjectUtil.deepSearch(inbound, key)) {
  808. const newInbound = new DBInbound(inbound);
  809. const inboundSettings = JSON.parse(inbound.settings);
  810. if (inboundSettings.hasOwnProperty('clients')) {
  811. const searchedSettings = { "clients": [] };
  812. inboundSettings.clients.forEach(client => {
  813. if (ObjectUtil.deepSearch(client, key)) {
  814. searchedSettings.clients.push(client);
  815. }
  816. });
  817. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, searchedSettings);
  818. }
  819. this.searchedInbounds.push(newInbound);
  820. }
  821. });
  822. }
  823. },
  824. filterInbounds() {
  825. if (ObjectUtil.isEmpty(this.filterBy)) {
  826. this.searchedInbounds = this.dbInbounds.slice();
  827. } else {
  828. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  829. this.dbInbounds.forEach(inbound => {
  830. const newInbound = new DBInbound(inbound);
  831. const inboundSettings = JSON.parse(inbound.settings);
  832. if (this.clientCount[inbound.id] && this.clientCount[inbound.id].hasOwnProperty(this.filterBy)){
  833. const list = this.clientCount[inbound.id][this.filterBy];
  834. if (list.length > 0) {
  835. const filteredSettings = { "clients": [] };
  836. if (inboundSettings.clients) {
  837. inboundSettings.clients.forEach(client => {
  838. if (list.includes(client.email)) {
  839. filteredSettings.clients.push(client);
  840. }
  841. });
  842. }
  843. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, filteredSettings);
  844. this.searchedInbounds.push(newInbound);
  845. }
  846. }
  847. });
  848. }
  849. },
  850. toggleFilter(){
  851. if(this.enableFilter) {
  852. this.searchKey = '';
  853. } else {
  854. this.filterBy = '';
  855. this.searchedInbounds = this.dbInbounds.slice();
  856. }
  857. },
  858. generalActions(action) {
  859. switch (action.key) {
  860. case "import":
  861. this.importInbound();
  862. break;
  863. case "export":
  864. this.exportAllLinks();
  865. break;
  866. case "subs":
  867. this.exportAllSubs();
  868. break;
  869. case "resetInbounds":
  870. this.resetAllTraffic();
  871. break;
  872. case "resetClients":
  873. this.resetAllClientTraffics(-1);
  874. break;
  875. case "delDepletedClients":
  876. this.delDepletedClients(-1)
  877. break;
  878. }
  879. },
  880. clickAction(action, dbInbound) {
  881. switch (action.key) {
  882. case "qrcode":
  883. this.showQrcode(dbInbound.id);
  884. break;
  885. case "showInfo":
  886. this.showInfo(dbInbound.id);
  887. break;
  888. case "edit":
  889. this.openEditInbound(dbInbound.id);
  890. break;
  891. case "addClient":
  892. this.openAddClient(dbInbound.id)
  893. break;
  894. case "addBulkClient":
  895. this.openAddBulkClient(dbInbound.id)
  896. break;
  897. case "export":
  898. this.inboundLinks(dbInbound.id);
  899. break;
  900. case "subs":
  901. this.exportSubs(dbInbound.id);
  902. break;
  903. case "clipboard":
  904. this.copy(dbInbound.id);
  905. break;
  906. case "resetTraffic":
  907. this.resetTraffic(dbInbound.id);
  908. break;
  909. case "resetClients":
  910. this.resetAllClientTraffics(dbInbound.id);
  911. break;
  912. case "clone":
  913. this.openCloneInbound(dbInbound);
  914. break;
  915. case "delete":
  916. this.delInbound(dbInbound.id);
  917. break;
  918. case "delDepletedClients":
  919. this.delDepletedClients(dbInbound.id)
  920. break;
  921. }
  922. },
  923. openCloneInbound(dbInbound) {
  924. this.$confirm({
  925. title: '{{ i18n "pages.inbounds.cloneInbound"}} \"' + dbInbound.remark + '\"',
  926. content: '{{ i18n "pages.inbounds.cloneInboundContent"}}',
  927. okText: '{{ i18n "pages.inbounds.cloneInboundOk"}}',
  928. class: themeSwitcher.currentTheme,
  929. cancelText: '{{ i18n "cancel" }}',
  930. onOk: () => {
  931. const baseInbound = dbInbound.toInbound();
  932. dbInbound.up = 0;
  933. dbInbound.down = 0;
  934. this.cloneInbound(baseInbound, dbInbound);
  935. },
  936. });
  937. },
  938. async cloneInbound(baseInbound, dbInbound) {
  939. const data = {
  940. up: dbInbound.up,
  941. down: dbInbound.down,
  942. total: dbInbound.total,
  943. remark: dbInbound.remark + " - Cloned",
  944. enable: dbInbound.enable,
  945. expiryTime: dbInbound.expiryTime,
  946. listen: '',
  947. port: RandomUtil.randomInteger(10000, 60000),
  948. protocol: baseInbound.protocol,
  949. settings: Inbound.Settings.getSettings(baseInbound.protocol).toString(),
  950. streamSettings: baseInbound.stream.toString(),
  951. sniffing: baseInbound.sniffing.toString(),
  952. };
  953. await this.submit('/panel/api/inbounds/add', data, inModal);
  954. },
  955. openAddInbound() {
  956. inModal.show({
  957. title: '{{ i18n "pages.inbounds.addInbound"}}',
  958. okText: '{{ i18n "create"}}',
  959. cancelText: '{{ i18n "close" }}',
  960. confirm: async (inbound, dbInbound) => {
  961. await this.addInbound(inbound, dbInbound, inModal);
  962. },
  963. isEdit: false
  964. });
  965. },
  966. openEditInbound(dbInboundId) {
  967. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  968. const inbound = dbInbound.toInbound();
  969. inModal.show({
  970. title: '{{ i18n "pages.inbounds.modifyInbound"}}',
  971. okText: '{{ i18n "update"}}',
  972. cancelText: '{{ i18n "close" }}',
  973. inbound: inbound,
  974. dbInbound: dbInbound,
  975. confirm: async (inbound, dbInbound) => {
  976. await this.updateInbound(inbound, dbInbound);
  977. },
  978. isEdit: true
  979. });
  980. },
  981. async addInbound(inbound, dbInbound) {
  982. const data = {
  983. up: dbInbound.up,
  984. down: dbInbound.down,
  985. total: dbInbound.total,
  986. remark: dbInbound.remark,
  987. enable: dbInbound.enable,
  988. expiryTime: dbInbound.expiryTime,
  989. listen: inbound.listen,
  990. port: inbound.port,
  991. protocol: inbound.protocol,
  992. settings: inbound.settings.toString(),
  993. };
  994. if (inbound.canEnableStream()){
  995. data.streamSettings = inbound.stream.toString();
  996. } else if (inbound.stream?.sockopt) {
  997. data.streamSettings = JSON.stringify({ sockopt: inbound.stream.sockopt.toJson() }, null, 2);
  998. }
  999. data.sniffing = inbound.sniffing.toString();
  1000. await this.submit('/panel/api/inbounds/add', data, inModal);
  1001. },
  1002. async updateInbound(inbound, dbInbound) {
  1003. const data = {
  1004. up: dbInbound.up,
  1005. down: dbInbound.down,
  1006. total: dbInbound.total,
  1007. remark: dbInbound.remark,
  1008. enable: dbInbound.enable,
  1009. expiryTime: dbInbound.expiryTime,
  1010. listen: inbound.listen,
  1011. port: inbound.port,
  1012. protocol: inbound.protocol,
  1013. settings: inbound.settings.toString(),
  1014. };
  1015. if (inbound.canEnableStream()){
  1016. data.streamSettings = inbound.stream.toString();
  1017. } else if (inbound.stream?.sockopt) {
  1018. data.streamSettings = JSON.stringify({ sockopt: inbound.stream.sockopt.toJson() }, null, 2);
  1019. }
  1020. data.sniffing = inbound.sniffing.toString();
  1021. await this.submit(`/panel/api/inbounds/update/${dbInbound.id}`, data, inModal);
  1022. },
  1023. openAddClient(dbInboundId) {
  1024. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1025. clientModal.show({
  1026. title: '{{ i18n "pages.client.add"}}',
  1027. okText: '{{ i18n "pages.client.submitAdd"}}',
  1028. dbInbound: dbInbound,
  1029. confirm: async (clients, dbInboundId) => {
  1030. await this.addClient(clients, dbInboundId, clientModal);
  1031. },
  1032. isEdit: false
  1033. });
  1034. },
  1035. openAddBulkClient(dbInboundId) {
  1036. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1037. clientsBulkModal.show({
  1038. title: '{{ i18n "pages.client.bulk"}} ' + dbInbound.remark,
  1039. okText: '{{ i18n "pages.client.bulk"}}',
  1040. dbInbound: dbInbound,
  1041. confirm: async (clients, dbInboundId) => {
  1042. await this.addClient(clients, dbInboundId, clientsBulkModal);
  1043. },
  1044. });
  1045. },
  1046. openEditClient(dbInboundId, client) {
  1047. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1048. clients = this.getInboundClients(dbInbound);
  1049. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1050. clientModal.show({
  1051. title: '{{ i18n "pages.client.edit"}}',
  1052. okText: '{{ i18n "pages.client.submitEdit"}}',
  1053. dbInbound: dbInbound,
  1054. index: index,
  1055. confirm: async (client, dbInboundId, clientId) => {
  1056. clientModal.loading();
  1057. await this.updateClient(client, dbInboundId, clientId);
  1058. clientModal.close();
  1059. },
  1060. isEdit: true
  1061. });
  1062. },
  1063. findIndexOfClient(protocol, clients, client) {
  1064. switch (protocol) {
  1065. case Protocols.TROJAN:
  1066. case Protocols.SHADOWSOCKS:
  1067. return clients.findIndex(item => item.password === client.password && item.email === client.email);
  1068. default: return clients.findIndex(item => item.id === client.id && item.email === client.email);
  1069. }
  1070. },
  1071. async addClient(clients, dbInboundId, modal) {
  1072. const data = {
  1073. id: dbInboundId,
  1074. settings: '{"clients": [' + clients.toString() + ']}',
  1075. };
  1076. await this.submit(`/panel/api/inbounds/addClient`, data, modal);
  1077. },
  1078. async updateClient(client, dbInboundId, clientId) {
  1079. const data = {
  1080. id: dbInboundId,
  1081. settings: '{"clients": [' + client.toString() + ']}',
  1082. };
  1083. await this.submit(`/panel/api/inbounds/updateClient/${clientId}`, data, clientModal);
  1084. },
  1085. resetTraffic(dbInboundId) {
  1086. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1087. this.$confirm({
  1088. title: '{{ i18n "pages.inbounds.resetTraffic"}}' + ' #' + dbInboundId,
  1089. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  1090. class: themeSwitcher.currentTheme,
  1091. okText: '{{ i18n "reset"}}',
  1092. cancelText: '{{ i18n "cancel"}}',
  1093. onOk: () => {
  1094. const inbound = dbInbound.toInbound();
  1095. dbInbound.up = 0;
  1096. dbInbound.down = 0;
  1097. this.updateInbound(inbound, dbInbound);
  1098. },
  1099. });
  1100. },
  1101. delInbound(dbInboundId) {
  1102. this.$confirm({
  1103. title: '{{ i18n "pages.inbounds.deleteInbound"}}' + ' #' + dbInboundId,
  1104. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  1105. class: themeSwitcher.currentTheme,
  1106. okText: '{{ i18n "delete"}}',
  1107. cancelText: '{{ i18n "cancel"}}',
  1108. onOk: () => this.submit('/panel/api/inbounds/del/' + dbInboundId),
  1109. });
  1110. },
  1111. delClient(dbInboundId, client,confirmation = true) {
  1112. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1113. clientId = this.getClientId(dbInbound.protocol, client);
  1114. if (confirmation){
  1115. this.$confirm({
  1116. title: '{{ i18n "pages.inbounds.deleteClient"}}' + ' ' + client.email,
  1117. content: '{{ i18n "pages.inbounds.deleteClientContent"}}',
  1118. class: themeSwitcher.currentTheme,
  1119. okText: '{{ i18n "delete"}}',
  1120. cancelText: '{{ i18n "cancel"}}',
  1121. onOk: () => this.submit(`/panel/api/inbounds/${dbInboundId}/delClient/${clientId}`),
  1122. });
  1123. } else {
  1124. this.submit(`/panel/api/inbounds/${dbInboundId}/delClient/${clientId}`);
  1125. }
  1126. },
  1127. getSubGroupClients(dbInbounds, currentClient) {
  1128. const response = {
  1129. inbounds: [],
  1130. clients: [],
  1131. editIds: []
  1132. }
  1133. if (dbInbounds && dbInbounds.length > 0 && currentClient) {
  1134. dbInbounds.forEach((dbInboundItem) => {
  1135. const dbInbound = new DBInbound(dbInboundItem);
  1136. if (dbInbound) {
  1137. const inbound = dbInbound.toInbound();
  1138. if (inbound) {
  1139. const clients = inbound.clients;
  1140. if (clients.length > 0) {
  1141. clients.forEach((client) => {
  1142. if (client['subId'] === currentClient['subId']) {
  1143. client['inboundId'] = dbInboundItem.id
  1144. client['clientId'] = this.getClientId(dbInbound.protocol, client)
  1145. response.inbounds.push(dbInboundItem.id)
  1146. response.clients.push(client)
  1147. response.editIds.push(client['clientId'])
  1148. }
  1149. })
  1150. }
  1151. }
  1152. }
  1153. })
  1154. }
  1155. return response;
  1156. },
  1157. getClientId(protocol, client) {
  1158. switch (protocol) {
  1159. case Protocols.TROJAN: return client.password;
  1160. case Protocols.SHADOWSOCKS: return client.email;
  1161. default: return client.id;
  1162. }
  1163. },
  1164. checkFallback(dbInbound) {
  1165. newDbInbound = new DBInbound(dbInbound);
  1166. if (dbInbound.listen.startsWith("@")){
  1167. rootInbound = this.inbounds.find((i) =>
  1168. i.isTcp &&
  1169. ['trojan','vless'].includes(i.protocol) &&
  1170. i.settings.fallbacks.find(f => f.dest === dbInbound.listen)
  1171. );
  1172. if (rootInbound) {
  1173. newDbInbound.listen = rootInbound.listen;
  1174. newDbInbound.port = rootInbound.port;
  1175. newInbound = newDbInbound.toInbound();
  1176. newInbound.stream.security = rootInbound.stream.security;
  1177. newInbound.stream.tls = rootInbound.stream.tls;
  1178. newInbound.stream.externalProxy = rootInbound.stream.externalProxy;
  1179. newDbInbound.streamSettings = newInbound.stream.toString();
  1180. }
  1181. }
  1182. return newDbInbound;
  1183. },
  1184. showQrcode(dbInboundId, client) {
  1185. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1186. newDbInbound = this.checkFallback(dbInbound);
  1187. qrModal.show('{{ i18n "qrCode"}}', newDbInbound, client);
  1188. },
  1189. showInfo(dbInboundId, client) {
  1190. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1191. index=0;
  1192. if (dbInbound.isMultiUser()){
  1193. inbound = dbInbound.toInbound();
  1194. clients = inbound.clients;
  1195. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1196. }
  1197. newDbInbound = this.checkFallback(dbInbound);
  1198. infoModal.show(newDbInbound, index);
  1199. },
  1200. switchEnable(dbInboundId,state) {
  1201. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1202. dbInbound.enable = state;
  1203. this.submit(`/panel/api/inbounds/update/${dbInboundId}`, dbInbound);
  1204. },
  1205. async switchEnableClient(dbInboundId, client) {
  1206. this.loading()
  1207. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1208. inbound = dbInbound.toInbound();
  1209. clients = inbound.clients;
  1210. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1211. clients[index].enable = !clients[index].enable;
  1212. clientId = this.getClientId(dbInbound.protocol, clients[index]);
  1213. await this.updateClient(clients[index], dbInboundId, clientId);
  1214. this.loading(false);
  1215. },
  1216. async submit(url, data, modal) {
  1217. const msg = await HttpUtil.postWithModal(url, data, modal);
  1218. if (msg.success) {
  1219. await this.getDBInbounds();
  1220. }
  1221. },
  1222. getInboundClients(dbInbound) {
  1223. return dbInbound.toInbound().clients;
  1224. },
  1225. resetClientTraffic(client, dbInboundId, confirmation = true) {
  1226. if (confirmation){
  1227. this.$confirm({
  1228. title: '{{ i18n "pages.inbounds.resetTraffic"}}' + ' ' + client.email,
  1229. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  1230. class: themeSwitcher.currentTheme,
  1231. okText: '{{ i18n "reset"}}',
  1232. cancelText: '{{ i18n "cancel"}}',
  1233. onOk: () => this.submit('/panel/api/inbounds/' + dbInboundId + '/resetClientTraffic/' + client.email),
  1234. })
  1235. } else {
  1236. this.submit('/panel/api/inbounds/' + dbInboundId + '/resetClientTraffic/' + client.email);
  1237. }
  1238. },
  1239. resetAllTraffic() {
  1240. this.$confirm({
  1241. title: '{{ i18n "pages.inbounds.resetAllTrafficTitle"}}',
  1242. content: '{{ i18n "pages.inbounds.resetAllTrafficContent"}}',
  1243. class: themeSwitcher.currentTheme,
  1244. okText: '{{ i18n "reset"}}',
  1245. cancelText: '{{ i18n "cancel"}}',
  1246. onOk: () => this.submit('/panel/api/inbounds/resetAllTraffics'),
  1247. });
  1248. },
  1249. resetAllClientTraffics(dbInboundId) {
  1250. this.$confirm({
  1251. title: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficTitle"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficTitle"}}',
  1252. content: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficContent"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficContent"}}',
  1253. class: themeSwitcher.currentTheme,
  1254. okText: '{{ i18n "reset"}}',
  1255. cancelText: '{{ i18n "cancel"}}',
  1256. onOk: () => this.submit('/panel/api/inbounds/resetAllClientTraffics/' + dbInboundId),
  1257. })
  1258. },
  1259. delDepletedClients(dbInboundId) {
  1260. this.$confirm({
  1261. title: '{{ i18n "pages.inbounds.delDepletedClientsTitle"}}',
  1262. content: '{{ i18n "pages.inbounds.delDepletedClientsContent"}}',
  1263. class: themeSwitcher.currentTheme,
  1264. okText: '{{ i18n "delete"}}',
  1265. cancelText: '{{ i18n "cancel"}}',
  1266. onOk: () => this.submit('/panel/api/inbounds/delDepletedClients/' + dbInboundId),
  1267. })
  1268. },
  1269. isExpiry(dbInbound, index) {
  1270. return dbInbound.toInbound().isExpiry(index);
  1271. },
  1272. getUpStats(dbInbound, email) {
  1273. if (email.length == 0) return 0;
  1274. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1275. return clientStats ? clientStats.up : 0;
  1276. },
  1277. getDownStats(dbInbound, email) {
  1278. if (email.length == 0) return 0;
  1279. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1280. return clientStats ? clientStats.down : 0;
  1281. },
  1282. getSumStats(dbInbound, email) {
  1283. if (email.length == 0) return 0;
  1284. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1285. return clientStats ? clientStats.up + clientStats.down : 0;
  1286. },
  1287. getAllTimeClient(dbInbound, email) {
  1288. if (email.length == 0) return 0;
  1289. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1290. if (!clientStats) return 0;
  1291. return clientStats.allTime || (clientStats.up + clientStats.down);
  1292. },
  1293. getRemStats(dbInbound, email) {
  1294. if (email.length == 0) return 0;
  1295. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1296. if (!clientStats) return 0;
  1297. remained = clientStats.total - (clientStats.up + clientStats.down);
  1298. return remained>0 ? remained : 0;
  1299. },
  1300. clientStatsColor(dbInbound, email) {
  1301. if (email.length == 0) return ColorUtils.clientUsageColor();
  1302. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1303. return ColorUtils.clientUsageColor(clientStats, app.trafficDiff)
  1304. },
  1305. statsProgress(dbInbound, email) {
  1306. if (email.length == 0) return 100;
  1307. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1308. if (!clientStats) return 0;
  1309. if (clientStats.total == 0) return 100;
  1310. return 100*(clientStats.down + clientStats.up)/clientStats.total;
  1311. },
  1312. expireProgress(expTime, reset) {
  1313. now = new Date().getTime();
  1314. remainedSeconds = expTime < 0 ? -expTime/1000 : (expTime-now)/1000;
  1315. resetSeconds = reset * 86400;
  1316. if (remainedSeconds >= resetSeconds) return 0;
  1317. return 100*(1-(remainedSeconds/resetSeconds));
  1318. },
  1319. remainedDays(expTime){
  1320. if (expTime == 0) return null;
  1321. if (expTime < 0) return TimeFormatter.formatSecond(expTime/-1000);
  1322. now = new Date().getTime();
  1323. if (expTime < now) return '{{ i18n "depleted" }}';
  1324. return TimeFormatter.formatSecond((expTime-now)/1000);
  1325. },
  1326. statsExpColor(dbInbound, email){
  1327. if (email.length == 0) return '#7a316f';
  1328. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1329. if (!clientStats) return '#7a316f';
  1330. statsColor = ColorUtils.usageColor(clientStats.down + clientStats.up, this.trafficDiff, clientStats.total);
  1331. expColor = ColorUtils.usageColor(new Date().getTime(), this.expireDiff, clientStats.expiryTime);
  1332. switch (true) {
  1333. case statsColor == "red" || expColor == "red":
  1334. return "#cf3c3c"; // Red
  1335. case statsColor == "orange" || expColor == "orange":
  1336. return "#f37b24"; // Orange
  1337. case statsColor == "green" || expColor == "green":
  1338. return "#008771"; // Green
  1339. default:
  1340. return "#7a316f"; // purple
  1341. }
  1342. },
  1343. isClientEnabled(dbInbound, email) {
  1344. clientStats = dbInbound.clientStats ? dbInbound.clientStats.find(stats => stats.email === email) : null;
  1345. return clientStats ? clientStats['enable'] : true;
  1346. },
  1347. isClientOnline(email) {
  1348. return this.onlineClients.includes(email);
  1349. },
  1350. getLastOnline(email) {
  1351. return this.lastOnlineMap[email] || null
  1352. },
  1353. formatLastOnline(email) {
  1354. const ts = this.getLastOnline(email)
  1355. if (!ts) return '-'
  1356. if (this.datepicker === 'gregorian') {
  1357. return DateUtil.formatMillis(ts)
  1358. }
  1359. return DateUtil.convertToJalalian(moment(ts))
  1360. },
  1361. isRemovable(dbInboundId) {
  1362. return this.getInboundClients(this.dbInbounds.find(row => row.id === dbInboundId)).length > 1;
  1363. },
  1364. inboundLinks(dbInboundId) {
  1365. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1366. newDbInbound = this.checkFallback(dbInbound);
  1367. txtModal.show('{{ i18n "pages.inbounds.export"}}', newDbInbound.genInboundLinks(this.remarkModel), newDbInbound.remark);
  1368. },
  1369. exportSubs(dbInboundId) {
  1370. const dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1371. const clients = this.getInboundClients(dbInbound);
  1372. let subLinks = []
  1373. if (clients != null){
  1374. clients.forEach(c => {
  1375. if (c.subId && c.subId.length>0){
  1376. subLinks.push(this.subSettings.subURI + c.subId)
  1377. }
  1378. })
  1379. }
  1380. txtModal.show(
  1381. '{{ i18n "pages.inbounds.export"}} - {{ i18n "pages.settings.subSettings" }}',
  1382. [...new Set(subLinks)].join('\n'),
  1383. dbInbound.remark + "-Subs");
  1384. },
  1385. importInbound() {
  1386. promptModal.open({
  1387. title: '{{ i18n "pages.inbounds.importInbound" }}',
  1388. type: 'textarea',
  1389. value: '',
  1390. okText: '{{ i18n "pages.inbounds.import" }}',
  1391. confirm: async (dbInboundText) => {
  1392. await this.submit('/panel/api/inbounds/import', {data: dbInboundText}, promptModal);
  1393. },
  1394. });
  1395. },
  1396. exportAllSubs() {
  1397. let subLinks = []
  1398. for (const dbInbound of this.dbInbounds) {
  1399. const clients = this.getInboundClients(dbInbound);
  1400. if (clients != null){
  1401. clients.forEach(c => {
  1402. if (c.subId && c.subId.length>0){
  1403. subLinks.push(this.subSettings.subURI + c.subId)
  1404. }
  1405. })
  1406. }
  1407. }
  1408. txtModal.show(
  1409. '{{ i18n "pages.inbounds.export"}} - {{ i18n "pages.settings.subSettings" }}',
  1410. [...new Set(subLinks)].join('\r\n'),
  1411. 'All-Inbounds-Subs');
  1412. },
  1413. exportAllLinks() {
  1414. let copyText = [];
  1415. for (const dbInbound of this.dbInbounds) {
  1416. copyText.push(dbInbound.genInboundLinks(this.remarkModel));
  1417. }
  1418. txtModal.show('{{ i18n "pages.inbounds.export"}}', copyText.join('\r\n'), 'All-Inbounds');
  1419. },
  1420. copy(dbInboundId) {
  1421. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1422. txtModal.show('{{ i18n "pages.inbounds.inboundData" }}', JSON.stringify(dbInbound, null, 2));
  1423. },
  1424. async startDataRefreshLoop() {
  1425. while (this.isRefreshEnabled) {
  1426. try {
  1427. await this.getDBInbounds();
  1428. } catch (e) {
  1429. console.error(e);
  1430. }
  1431. await PromiseUtil.sleep(this.refreshInterval);
  1432. }
  1433. },
  1434. toggleRefresh() {
  1435. localStorage.setItem("isRefreshEnabled", this.isRefreshEnabled);
  1436. if (this.isRefreshEnabled) {
  1437. this.startDataRefreshLoop();
  1438. }
  1439. },
  1440. changeRefreshInterval() {
  1441. localStorage.setItem("refreshInterval", this.refreshInterval);
  1442. },
  1443. async manualRefresh() {
  1444. if (!this.refreshing) {
  1445. this.loadingStates.spinning = true;
  1446. await this.getDBInbounds();
  1447. this.loadingStates.spinning = false;
  1448. }
  1449. },
  1450. pagination(obj){
  1451. if (this.pageSize > 0 && obj.length>this.pageSize) {
  1452. // Set page options based on object size
  1453. sizeOptions = [];
  1454. for (i=this.pageSize;i<=obj.length;i=i+this.pageSize) {
  1455. sizeOptions.push(i.toString());
  1456. }
  1457. // Add option to see all in one page
  1458. sizeOptions.push(i.toString());
  1459. p = {
  1460. showSizeChanger: true,
  1461. size: 'small',
  1462. position: 'bottom',
  1463. pageSize: this.pageSize,
  1464. pageSizeOptions: sizeOptions
  1465. };
  1466. return p;
  1467. }
  1468. return false
  1469. }
  1470. },
  1471. watch: {
  1472. searchKey: Utils.debounce(function (newVal) {
  1473. this.searchInbounds(newVal);
  1474. }, 500)
  1475. },
  1476. mounted() {
  1477. if (window.location.protocol !== "https:") {
  1478. this.showAlert = true;
  1479. }
  1480. this.loading();
  1481. this.getDefaultSettings();
  1482. if (this.isRefreshEnabled) {
  1483. this.startDataRefreshLoop();
  1484. }
  1485. else {
  1486. this.getDBInbounds();
  1487. }
  1488. this.loading(false);
  1489. },
  1490. computed: {
  1491. total() {
  1492. let down = 0, up = 0, allTime = 0;
  1493. let clients = 0, deactive = [], depleted = [], expiring = [];
  1494. this.dbInbounds.forEach(dbInbound => {
  1495. down += dbInbound.down;
  1496. up += dbInbound.up;
  1497. allTime += (dbInbound.allTime || (dbInbound.up + dbInbound.down));
  1498. if (this.clientCount[dbInbound.id]) {
  1499. clients += this.clientCount[dbInbound.id].clients;
  1500. deactive = deactive.concat(this.clientCount[dbInbound.id].deactive);
  1501. depleted = depleted.concat(this.clientCount[dbInbound.id].depleted);
  1502. expiring = expiring.concat(this.clientCount[dbInbound.id].expiring);
  1503. }
  1504. });
  1505. return {
  1506. down: down,
  1507. up: up,
  1508. allTime: allTime,
  1509. clients: clients,
  1510. deactive: deactive,
  1511. depleted: depleted,
  1512. expiring: expiring,
  1513. };
  1514. }
  1515. },
  1516. });
  1517. </script>
  1518. {{ template "page/body_end" .}}