inbounds.html 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. {{template "head" .}}
  4. <style>
  5. @media (min-width: 769px) {
  6. .ant-layout-content {
  7. margin: 24px 16px;
  8. }
  9. }
  10. @media (max-width: 768px) {
  11. .ant-card-body {
  12. padding: .5rem;
  13. }
  14. }
  15. .ant-col-sm-24 {
  16. margin: 0.5rem -2rem 0.5rem 2rem;
  17. }
  18. tr.hideExpandIcon .ant-table-row-expand-icon {
  19. display: none;
  20. }
  21. .infinite-tag {
  22. padding: 0 5px;
  23. border-radius: 2rem;
  24. min-width: 50px;
  25. }
  26. .infinite-bar .ant-progress-inner .ant-progress-bg {
  27. background-color: #F2EAF1;
  28. border: #D5BED2 solid 1px;
  29. }
  30. .dark .infinite-bar .ant-progress-inner .ant-progress-bg {
  31. background-color: #3c1536;
  32. border: #7a316f solid 1px;
  33. }
  34. .ant-collapse {
  35. margin: 5px 0;
  36. }
  37. .online-animation .ant-badge-status-dot {
  38. animation: 1.2s ease infinite normal none running onlineAnimation;
  39. }
  40. @keyframes onlineAnimation {
  41. 0%, 50%, 100% { transform: scale(1); opacity: 1; }
  42. 10% { transform: scale(1.5); opacity: .2; }
  43. }
  44. </style>
  45. <body>
  46. <a-layout id="app" v-cloak :class="themeSwitcher.currentTheme">
  47. {{ template "commonSider" . }}
  48. <a-layout id="content-layout">
  49. <a-layout-content>
  50. <a-spin :spinning="spinning" :delay="500" tip='{{ i18n "loading"}}'>
  51. <transition name="list" appear>
  52. <a-tag v-if="false" color="red" style="margin-bottom: 10px">
  53. Please go to the panel settings as soon as possible to modify the username and password, otherwise there may be a risk of leaking account information
  54. </a-tag>
  55. </transition>
  56. <transition name="list" appear>
  57. <a-card hoverable>
  58. <a-row>
  59. <a-col :xs="24" :sm="24" :lg="12">
  60. {{ i18n "pages.inbounds.totalDownUp" }}:
  61. <a-tag color="green">[[ sizeFormat(total.up) ]] / [[ sizeFormat(total.down) ]]</a-tag>
  62. </a-col>
  63. <a-col :xs="24" :sm="24" :lg="12">
  64. {{ i18n "pages.inbounds.totalUsage" }}:
  65. <a-tag color="green">[[ sizeFormat(total.up + total.down) ]]</a-tag>
  66. </a-col>
  67. <a-col :xs="24" :sm="24" :lg="12">
  68. {{ i18n "pages.inbounds.inboundCount" }}:
  69. <a-tag color="green">[[ dbInbounds.length ]]</a-tag>
  70. </a-col>
  71. <a-col :xs="24" :sm="24" :lg="12">
  72. {{ i18n "clients" }}:
  73. <a-tag color="green">[[ total.clients ]]</a-tag>
  74. <a-popover title='{{ i18n "disabled" }}' :overlay-class-name="themeSwitcher.currentTheme">
  75. <template slot="content">
  76. <p v-for="clientEmail in total.deactive">[[ clientEmail ]]</p>
  77. </template>
  78. <a-tag v-if="total.deactive.length">[[ total.deactive.length ]]</a-tag>
  79. </a-popover>
  80. <a-popover title='{{ i18n "depleted" }}' :overlay-class-name="themeSwitcher.currentTheme">
  81. <template slot="content">
  82. <p v-for="clientEmail in total.depleted">[[ clientEmail ]]</p>
  83. </template>
  84. <a-tag color="red" v-if="total.depleted.length">[[ total.depleted.length ]]</a-tag>
  85. </a-popover>
  86. <a-popover title='{{ i18n "depletingSoon" }}' :overlay-class-name="themeSwitcher.currentTheme">
  87. <template slot="content">
  88. <p v-for="clientEmail in total.expiring">[[ clientEmail ]]</p>
  89. </template>
  90. <a-tag color="orange" v-if="total.expiring.length">[[ total.expiring.length ]]</a-tag>
  91. </a-popover>
  92. <a-popover title='{{ i18n "online" }}' :overlay-class-name="themeSwitcher.currentTheme">
  93. <template slot="content">
  94. <p v-for="clientEmail in onlineClients">[[ clientEmail ]]</p>
  95. </template>
  96. <a-tag color="blue" v-if="onlineClients.length">[[ onlineClients.length ]]</a-tag>
  97. </a-popover>
  98. </a-col>
  99. </a-row>
  100. </a-card>
  101. </transition>
  102. <transition name="list" appear>
  103. <a-card hoverable>
  104. <div slot="title">
  105. <a-row>
  106. <a-col :xs="12" :sm="12" :lg="12">
  107. <a-button type="primary" icon="plus" @click="openAddInbound">
  108. <template v-if="!isMobile">{{ i18n "pages.inbounds.addInbound" }}</template>
  109. </a-button>
  110. <a-dropdown :trigger="['click']">
  111. <a-button type="primary" icon="menu">
  112. <template v-if="!isMobile">{{ i18n "pages.inbounds.generalActions" }}</template>
  113. </a-button>
  114. <a-menu slot="overlay" @click="a => generalActions(a)" :theme="themeSwitcher.currentTheme">
  115. <a-menu-item key="export">
  116. <a-icon type="export"></a-icon>
  117. {{ i18n "pages.inbounds.export" }}
  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">
  128. <a-icon type="rest"></a-icon>
  129. {{ i18n "pages.inbounds.delDepletedClients" }}
  130. </a-menu-item>
  131. </a-menu>
  132. </a-dropdown>
  133. </a-col>
  134. <a-col :xs="12" :sm="12" :lg="12" style="text-align: right;">
  135. <a-select v-model="refreshInterval"
  136. style="width: 65px;"
  137. v-if="isRefreshEnabled"
  138. @change="changeRefreshInterval"
  139. :dropdown-class-name="themeSwitcher.currentTheme">
  140. <a-select-option v-for="key in [5,10,30,60]" :value="key*1000">[[ key ]]s</a-select-option>
  141. </a-select>
  142. <a-icon type="sync" :spin="refreshing" @click="manualRefresh" style="margin: 0 5px;"></a-icon>
  143. <a-switch v-model="isRefreshEnabled" @change="toggleRefresh"></a-switch>
  144. </a-col>
  145. </a-row>
  146. </div>
  147. <div style="display: flex; align-items: center; justify-content: flex-start;">
  148. <a-switch v-model="enableFilter"
  149. style="margin-right: .5rem;"
  150. @change="toggleFilter">
  151. <a-icon slot="checkedChildren" type="search"></a-icon>
  152. <a-icon slot="unCheckedChildren" type="filter"></a-icon>
  153. </a-switch>
  154. <a-input v-if="!enableFilter" v-model.lazy="searchKey" placeholder='{{ i18n "search" }}' autofocus style="max-width: 300px" :size="isMobile ? 'small' : ''"></a-input>
  155. <a-radio-group v-if="enableFilter" v-model="filterBy" @change="filterInbounds" button-style="solid" :size="isMobile ? 'small' : ''">
  156. <a-radio-button value="">{{ i18n "none" }}</a-radio-button>
  157. <a-radio-button value="deactive">{{ i18n "disabled" }}</a-radio-button>
  158. <a-radio-button value="depleted">{{ i18n "depleted" }}</a-radio-button>
  159. <a-radio-button value="expiring">{{ i18n "depletingSoon" }}</a-radio-button>
  160. <a-radio-button value="online">{{ i18n "online" }}</a-radio-button>
  161. </a-radio-group>
  162. </div>
  163. <a-table :columns="isMobile ? mobileColums : columns" :row-key="dbInbound => dbInbound.id"
  164. :data-source="searchedInbounds"
  165. :scroll="isMobile ? {} : { x: 1000 }"
  166. :pagination="false"
  167. :expand-icon-as-cell="false"
  168. :expand-row-by-click="false"
  169. :expand-icon-column-index="0"
  170. :indent-size="0"
  171. :row-class-name="dbInbound => (dbInbound.isMultiUser() ? '' : 'hideExpandIcon')"
  172. style="margin-top: 10px"
  173. @change="() => getDBInbounds()">
  174. <template slot="action" slot-scope="text, dbInbound">
  175. <a-icon type="edit" style="font-size: 22px" @click="openEditInbound(dbInbound.id);"></a-icon>
  176. <a-dropdown :trigger="['click']">
  177. <a @click="e => e.preventDefault()">{{ i18n "pages.inbounds.operate" }}</a>
  178. <a-menu slot="overlay" @click="a => clickAction(a, dbInbound)" :theme="themeSwitcher.currentTheme">
  179. <a-menu-item key="edit">
  180. <a-icon type="edit"></a-icon>
  181. {{ i18n "edit" }}
  182. </a-menu-item>
  183. <a-menu-item key="qrcode" v-if="dbInbound.isSS && !dbInbound.toInbound().isSSMultiUser">
  184. <a-icon type="qrcode"></a-icon>
  185. {{ i18n "qrCode" }}
  186. </a-menu-item>
  187. <template v-if="dbInbound.isMultiUser()">
  188. <a-menu-item key="addClient">
  189. <a-icon type="user-add"></a-icon>
  190. {{ i18n "pages.client.add"}}
  191. </a-menu-item>
  192. <a-menu-item key="addBulkClient">
  193. <a-icon type="usergroup-add"></a-icon>
  194. {{ i18n "pages.client.bulk"}}
  195. </a-menu-item>
  196. <a-menu-item key="resetClients">
  197. <a-icon type="file-done"></a-icon>
  198. {{ i18n "pages.inbounds.resetInboundClientTraffics"}}
  199. </a-menu-item>
  200. <a-menu-item key="export">
  201. <a-icon type="export"></a-icon>
  202. {{ i18n "pages.inbounds.export"}}
  203. </a-menu-item>
  204. <a-menu-item key="delDepletedClients">
  205. <a-icon type="rest"></a-icon>
  206. {{ i18n "pages.inbounds.delDepletedClients" }}
  207. </a-menu-item>
  208. </template>
  209. <template v-else>
  210. <a-menu-item key="showInfo">
  211. <a-icon type="info-circle"></a-icon>
  212. {{ i18n "info"}}
  213. </a-menu-item>
  214. </template>
  215. <a-menu-item key="resetTraffic">
  216. <a-icon type="retweet"></a-icon> {{ i18n "pages.inbounds.resetTraffic" }}
  217. </a-menu-item>
  218. <a-menu-item key="clone">
  219. <a-icon type="block"></a-icon> {{ i18n "pages.inbounds.clone"}}
  220. </a-menu-item>
  221. <a-menu-item key="delete">
  222. <span style="color: #FF4D4F">
  223. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  224. </span>
  225. </a-menu-item>
  226. <a-menu-item v-if="isMobile">
  227. <a-switch size="small" v-model="dbInbound.enable" @change="switchEnable(dbInbound.id)"></a-switch>
  228. {{ i18n "pages.inbounds.enable" }}
  229. </a-menu-item>
  230. </a-menu>
  231. </a-dropdown>
  232. </template>
  233. <template slot="protocol" slot-scope="text, dbInbound">
  234. <a-tag style="margin:0;" color="purple">[[ dbInbound.protocol ]]</a-tag>
  235. <template v-if="dbInbound.isVMess || dbInbound.isVLess || dbInbound.isTrojan || dbInbound.isSS">
  236. <a-tag style="margin:0;" color="green">[[ dbInbound.toInbound().stream.network ]]</a-tag>
  237. <a-tag style="margin:0;" v-if="dbInbound.toInbound().stream.isTls" color="blue">TLS</a-tag>
  238. <a-tag style="margin:0;" v-if="dbInbound.toInbound().stream.isXtls" color="blue">XTLS</a-tag>
  239. <a-tag style="margin:0;" v-if="dbInbound.toInbound().stream.isReality" color="blue">Reality</a-tag>
  240. </template>
  241. </template>
  242. <template slot="clients" slot-scope="text, dbInbound">
  243. <template v-if="clientCount[dbInbound.id]">
  244. <a-tag style="margin:0;" color="green">[[ clientCount[dbInbound.id].clients ]]</a-tag>
  245. <a-popover title='{{ i18n "disabled" }}' :overlay-class-name="themeSwitcher.currentTheme">
  246. <template slot="content">
  247. <p v-for="clientEmail in clientCount[dbInbound.id].deactive">[[ clientEmail ]]</p>
  248. </template>
  249. <a-tag style="margin:0; padding: 0 2px;" v-if="clientCount[dbInbound.id].deactive.length">[[ clientCount[dbInbound.id].deactive.length ]]</a-tag>
  250. </a-popover>
  251. <a-popover title='{{ i18n "depleted" }}' :overlay-class-name="themeSwitcher.currentTheme">
  252. <template slot="content">
  253. <p v-for="clientEmail in clientCount[dbInbound.id].depleted">[[ clientEmail ]]</p>
  254. </template>
  255. <a-tag style="margin:0; padding: 0 2px;" color="red" v-if="clientCount[dbInbound.id].depleted.length">[[ clientCount[dbInbound.id].depleted.length ]]</a-tag>
  256. </a-popover>
  257. <a-popover title='{{ i18n "depletingSoon" }}' :overlay-class-name="themeSwitcher.currentTheme">
  258. <template slot="content">
  259. <p v-for="clientEmail in clientCount[dbInbound.id].expiring">[[ clientEmail ]]</p>
  260. </template>
  261. <a-tag style="margin:0; padding: 0 2px;" color="orange" v-if="clientCount[dbInbound.id].expiring.length">[[ clientCount[dbInbound.id].expiring.length ]]</a-tag>
  262. </a-popover>
  263. <a-popover title='{{ i18n "online" }}' :overlay-class-name="themeSwitcher.currentTheme">
  264. <template slot="content">
  265. <p v-for="clientEmail in clientCount[dbInbound.id].online">[[ clientEmail ]]</p>
  266. </template>
  267. <a-tag style="margin:0; padding: 0 2px;" color="blue" v-if="clientCount[dbInbound.id].online.length">[[ clientCount[dbInbound.id].online.length ]]</a-tag>
  268. </a-popover>
  269. </template>
  270. </template>
  271. <template slot="traffic" slot-scope="text, dbInbound">
  272. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  273. <template slot="content">
  274. <table cellpadding="2" width="100%">
  275. <tr>
  276. <td>↑[[ sizeFormat(dbInbound.up) ]]</td>
  277. <td>↓[[ sizeFormat(dbInbound.down) ]]</td>
  278. </tr>
  279. <tr v-if="dbInbound.total > 0 && dbInbound.up + dbInbound.down < dbInbound.total">
  280. <td>{{ i18n "remained" }}</td>
  281. <td>[[ sizeFormat(dbInbound.total - dbInbound.up - dbInbound.down) ]]</td>
  282. </tr>
  283. </table>
  284. </template>
  285. <a-tag :color="usageColor(dbInbound.up + dbInbound.down, app.trafficDiff, dbInbound.total)">
  286. [[ sizeFormat(dbInbound.up + dbInbound.down) ]] /
  287. <template v-if="dbInbound.total > 0">
  288. [[ sizeFormat(dbInbound.total) ]]
  289. </template>
  290. <template v-else>
  291. <svg style="fill: currentColor; height: 10px;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><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"/></svg>
  292. </template>
  293. </a-tag>
  294. </a-popover>
  295. </template>
  296. <template slot="enable" slot-scope="text, dbInbound">
  297. <a-switch v-model="dbInbound.enable" @change="switchEnable(dbInbound.id)"></a-switch>
  298. </template>
  299. <template slot="expiryTime" slot-scope="text, dbInbound">
  300. <a-popover v-if="dbInbound.expiryTime > 0" :overlay-class-name="themeSwitcher.currentTheme">
  301. <template slot="content">
  302. [[ DateUtil.formatMillis(dbInbound.expiryTime) ]]
  303. </template>
  304. <a-tag style="min-width: 50px;" :color="usageColor(new Date().getTime(), app.expireDiff, dbInbound._expiryTime)">
  305. [[ remainedDays(dbInbound._expiryTime) ]]
  306. </a-tag>
  307. </a-popover>
  308. <a-tag v-else color="purple" class="infinite-tag">&infin;</a-tag>
  309. </template>
  310. <template slot="info" slot-scope="text, dbInbound">
  311. <a-popover placement="bottomRight" :overlay-class-name="themeSwitcher.currentTheme" trigger="click">
  312. <template slot="content">
  313. <table cellpadding="2">
  314. <tr>
  315. <td>{{ i18n "pages.inbounds.protocol" }}</td>
  316. <td>
  317. <a-tag style="margin:0;" color="purple">[[ dbInbound.protocol ]]</a-tag>
  318. <template v-if="dbInbound.isVMess || dbInbound.isVLess || dbInbound.isTrojan || dbInbound.isSS">
  319. <a-tag style="margin:0;" color="blue">[[ dbInbound.toInbound().stream.network ]]</a-tag>
  320. <a-tag style="margin:0;" v-if="dbInbound.toInbound().stream.isTls" color="green">tls</a-tag>
  321. <a-tag style="margin:0;" v-if="dbInbound.toInbound().stream.isReality" color="green">reality</a-tag>
  322. </template>
  323. </td>
  324. </tr>
  325. <tr>
  326. <td>{{ i18n "pages.inbounds.port" }}</td>
  327. <td><a-tag>[[ dbInbound.port ]]</a-tag></td>
  328. </tr>
  329. <tr v-if="clientCount[dbInbound.id]">
  330. <td>{{ i18n "clients" }}</td>
  331. <td>
  332. <a-tag style="margin:0;" color="blue">[[ clientCount[dbInbound.id].clients ]]</a-tag>
  333. <a-popover title='{{ i18n "disabled" }}' :overlay-class-name="themeSwitcher.currentTheme">
  334. <template slot="content">
  335. <p v-for="clientEmail in clientCount[dbInbound.id].deactive">[[ clientEmail ]]</p>
  336. </template>
  337. <a-tag style="margin:0; padding: 0 2px;" v-if="clientCount[dbInbound.id].deactive.length">[[ clientCount[dbInbound.id].deactive.length ]]</a-tag>
  338. </a-popover>
  339. <a-popover title='{{ i18n "depleted" }}' :overlay-class-name="themeSwitcher.currentTheme">
  340. <template slot="content">
  341. <p v-for="clientEmail in clientCount[dbInbound.id].depleted">[[ clientEmail ]]</p>
  342. </template>
  343. <a-tag style="margin:0; padding: 0 2px;" color="red" v-if="clientCount[dbInbound.id].depleted.length">[[ clientCount[dbInbound.id].depleted.length ]]</a-tag>
  344. </a-popover>
  345. <a-popover title='{{ i18n "depletingSoon" }}' :overlay-class-name="themeSwitcher.currentTheme">
  346. <template slot="content">
  347. <p v-for="clientEmail in clientCount[dbInbound.id].expiring">[[ clientEmail ]]</p>
  348. </template>
  349. <a-tag style="margin:0; padding: 0 2px;" color="orange" v-if="clientCount[dbInbound.id].expiring.length">[[ clientCount[dbInbound.id].expiring.length ]]</a-tag>
  350. </a-popover>
  351. <a-popover title='{{ i18n "online" }}' :overlay-class-name="themeSwitcher.currentTheme">
  352. <template slot="content">
  353. <p v-for="clientEmail in clientCount[dbInbound.id].online">[[ clientEmail ]]</p>
  354. </template>
  355. <a-tag style="margin:0; padding: 0 2px;" color="green" v-if="clientCount[dbInbound.id].online.length">[[ clientCount[dbInbound.id].online.length ]]</a-tag>
  356. </a-popover>
  357. </td>
  358. </tr>
  359. <tr>
  360. <td>{{ i18n "pages.inbounds.traffic" }}</td>
  361. <td>
  362. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  363. <template slot="content">
  364. <table cellpadding="2" width="100%">
  365. <tr>
  366. <td>↑[[ sizeFormat(dbInbound.up) ]]</td>
  367. <td>↓[[ sizeFormat(dbInbound.down) ]]</td>
  368. </tr>
  369. <tr v-if="dbInbound.total > 0 && dbInbound.up + dbInbound.down < dbInbound.total">
  370. <td>{{ i18n "remained" }}</td>
  371. <td>[[ sizeFormat(dbInbound.total - dbInbound.up - dbInbound.down) ]]</td>
  372. </tr>
  373. </table>
  374. </template>
  375. <a-tag :color="usageColor(dbInbound.up + dbInbound.down, app.trafficDiff, dbInbound.total)">
  376. [[ sizeFormat(dbInbound.up + dbInbound.down) ]] /
  377. <template v-if="dbInbound.total > 0">
  378. [[ sizeFormat(dbInbound.total) ]]
  379. </template>
  380. <template v-else>&infin;</template>
  381. </a-tag>
  382. </a-popover>
  383. </td>
  384. </tr>
  385. <tr>
  386. <td>{{ i18n "pages.inbounds.expireDate" }}</td>
  387. <td>
  388. <a-tag style="min-width: 50px; text-align: center;" v-if="dbInbound.expiryTime > 0" :color="dbInbound.isExpiry? 'red': 'blue'">
  389. [[ DateUtil.formatMillis(dbInbound.expiryTime) ]]
  390. </a-tag>
  391. <a-tag v-else style="text-align: center;" color="purple" class="infinite-tag">&infin;</a-tag>
  392. </td>
  393. </tr>
  394. </table>
  395. </template>
  396. <a-badge>
  397. <a-icon v-if="!dbInbound.enable" slot="count" type="pause-circle" :style="'color: ' + themeSwitcher.isDarkTheme ? '#2c3950' : '#bcbcbc'"></a-icon>
  398. <a-button shape="round" size="small" style="font-size: 14px; padding: 0 10px;">
  399. <a-icon type="info"></a-icon>
  400. </a-button>
  401. </a-badge>
  402. </a-popover>
  403. </template>
  404. <template slot="expandedRowRender" slot-scope="record">
  405. <a-table
  406. :row-key="client => client.id"
  407. :columns="isMobile ? innerMobileColumns : innerColumns"
  408. :data-source="getInboundClients(record)"
  409. :pagination="false"
  410. :style="isMobile ? 'margin: -16px -5px -17px;' : 'margin-left: 10px;'">
  411. {{template "client_table"}}
  412. </a-table>
  413. </template>
  414. </a-table>
  415. </a-card>
  416. </transition>
  417. </a-spin>
  418. </a-layout-content>
  419. </a-layout>
  420. </a-layout>
  421. {{template "js" .}}
  422. {{template "component/themeSwitcher" .}}
  423. <script>
  424. const columns = [{
  425. title: "ID",
  426. align: 'right',
  427. dataIndex: "id",
  428. width: 30,
  429. responsive: ["xs"],
  430. }, {
  431. title: '{{ i18n "pages.inbounds.operate" }}',
  432. align: 'center',
  433. width: 40,
  434. scopedSlots: { customRender: 'action' },
  435. }, {
  436. title: '{{ i18n "pages.inbounds.enable" }}',
  437. align: 'center',
  438. width: 40,
  439. scopedSlots: { customRender: 'enable' },
  440. }, {
  441. title: '{{ i18n "pages.inbounds.remark" }}',
  442. align: 'center',
  443. width: 80,
  444. dataIndex: "remark",
  445. }, {
  446. title: '{{ i18n "pages.inbounds.port" }}',
  447. align: 'center',
  448. dataIndex: "port",
  449. width: 40,
  450. }, {
  451. title: '{{ i18n "pages.inbounds.protocol" }}',
  452. align: 'left',
  453. width: 90,
  454. scopedSlots: { customRender: 'protocol' },
  455. }, {
  456. title: '{{ i18n "clients" }}',
  457. align: 'left',
  458. width: 50,
  459. scopedSlots: { customRender: 'clients' },
  460. }, {
  461. title: '{{ i18n "pages.inbounds.traffic" }}',
  462. align: 'center',
  463. width: 60,
  464. scopedSlots: { customRender: 'traffic' },
  465. }, {
  466. title: '{{ i18n "pages.inbounds.expireDate" }}',
  467. align: 'center',
  468. width: 40,
  469. scopedSlots: { customRender: 'expiryTime' },
  470. }];
  471. const mobileColums = [{
  472. title: "ID",
  473. align: 'right',
  474. dataIndex: "id",
  475. width: 10,
  476. responsive: ["s"],
  477. }, {
  478. title: '{{ i18n "pages.inbounds.operate" }}',
  479. align: 'center',
  480. width: 25,
  481. scopedSlots: { customRender: 'action' },
  482. }, {
  483. title: '{{ i18n "pages.inbounds.remark" }}',
  484. align: 'left',
  485. width: 70,
  486. dataIndex: "remark",
  487. }, {
  488. title: '{{ i18n "pages.inbounds.info" }}',
  489. align: 'center',
  490. width: 10,
  491. scopedSlots: { customRender: 'info' },
  492. }];
  493. const innerColumns = [
  494. { title: '{{ i18n "pages.inbounds.operate" }}', width: 50, scopedSlots: { customRender: 'actions' } },
  495. { title: '{{ i18n "pages.inbounds.enable" }}', width: 20, scopedSlots: { customRender: 'enable' } },
  496. { title: '{{ i18n "online" }}', width: 20, scopedSlots: { customRender: 'online' } },
  497. { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } },
  498. { title: '{{ i18n "pages.inbounds.traffic" }}', width: 80, align: 'center', scopedSlots: { customRender: 'traffic' } },
  499. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 80, align: 'center', scopedSlots: { customRender: 'expiryTime' } },
  500. ];
  501. const innerMobileColumns = [
  502. { title: '{{ i18n "pages.inbounds.operate" }}', width: 10, align: 'center', scopedSlots: { customRender: 'actionMenu' } },
  503. { title: '{{ i18n "pages.inbounds.client" }}', width: 90, align: 'left', scopedSlots: { customRender: 'client' } },
  504. { title: '{{ i18n "pages.inbounds.info" }}', width: 10, align: 'center', scopedSlots: { customRender: 'info' } },
  505. ];
  506. const app = new Vue({
  507. delimiters: ['[[', ']]'],
  508. el: '#app',
  509. data: {
  510. siderDrawer,
  511. themeSwitcher,
  512. spinning: false,
  513. inbounds: [],
  514. dbInbounds: [],
  515. searchKey: '',
  516. enableFilter: false,
  517. filterBy: '',
  518. searchedInbounds: [],
  519. expireDiff: 0,
  520. trafficDiff: 0,
  521. defaultCert: '',
  522. defaultKey: '',
  523. clientCount: [],
  524. onlineClients: [],
  525. isRefreshEnabled: localStorage.getItem("isRefreshEnabled") === "true" ? true : false,
  526. refreshing: false,
  527. refreshInterval: Number(localStorage.getItem("refreshInterval")) || 5000,
  528. subSettings: {
  529. enable : false,
  530. port: 0,
  531. path: '',
  532. domain: '',
  533. tls: false
  534. },
  535. tgBotEnable: false,
  536. isMobile: window.innerWidth <= 768,
  537. },
  538. methods: {
  539. loading(spinning = true) {
  540. this.spinning = spinning;
  541. },
  542. async getDBInbounds() {
  543. this.refreshing = true;
  544. const msg = await HttpUtil.post('/panel/inbound/list');
  545. if (!msg.success) {
  546. this.refreshing = false;
  547. return;
  548. }
  549. await this.getOnlineUsers();
  550. this.setInbounds(msg.obj);
  551. setTimeout(() => {
  552. this.refreshing = false;
  553. }, 500);
  554. },
  555. async getOnlineUsers() {
  556. const msg = await HttpUtil.post('/panel/inbound/onlines');
  557. if (!msg.success) {
  558. return;
  559. }
  560. this.onlineClients = msg.obj != null ? msg.obj : [];
  561. },
  562. async getDefaultSettings() {
  563. const msg = await HttpUtil.post('/panel/setting/defaultSettings');
  564. if (!msg.success) {
  565. return;
  566. }
  567. with(msg.obj){
  568. this.expireDiff = expireDiff * 86400000;
  569. this.trafficDiff = trafficDiff * 1073741824;
  570. this.defaultCert = defaultCert;
  571. this.defaultKey = defaultKey;
  572. this.tgBotEnable = tgBotEnable;
  573. this.subSettings = {
  574. enable : subEnable,
  575. port: subPort,
  576. path: subPath,
  577. domain: subDomain,
  578. tls: subTLS
  579. };
  580. }
  581. },
  582. setInbounds(dbInbounds) {
  583. this.inbounds.splice(0);
  584. this.dbInbounds.splice(0);
  585. this.clientCount.splice(0);
  586. for (const inbound of dbInbounds) {
  587. const dbInbound = new DBInbound(inbound);
  588. to_inbound = dbInbound.toInbound()
  589. this.inbounds.push(to_inbound);
  590. this.dbInbounds.push(dbInbound);
  591. if ([Protocols.VMESS, Protocols.VLESS, Protocols.TROJAN, Protocols.SHADOWSOCKS].includes(inbound.protocol)) {
  592. if (inbound.protocol === Protocols.SHADOWSOCKS && (!to_inbound.isSSMultiUser)) {
  593. continue;
  594. }
  595. this.clientCount[inbound.id] = this.getClientCounts(inbound, to_inbound);
  596. }
  597. }
  598. if(this.enableFilter){
  599. this.filterInbounds();
  600. } else {
  601. this.searchInbounds(this.searchKey);
  602. }
  603. },
  604. getClientCounts(dbInbound, inbound) {
  605. let clientCount = 0, active = [], deactive = [], depleted = [], expiring = [], online = [];
  606. clients = this.getClients(dbInbound.protocol, inbound.settings);
  607. clientStats = dbInbound.clientStats
  608. now = new Date().getTime()
  609. if (clients) {
  610. clientCount = clients.length;
  611. if (dbInbound.enable) {
  612. clients.forEach(client => {
  613. client.enable ? active.push(client.email) : deactive.push(client.email);
  614. if(this.isClientOnline(client.email)) online.push(client.email);
  615. });
  616. clientStats.forEach(client => {
  617. if (!client.enable) {
  618. depleted.push(client.email);
  619. } else {
  620. if ((client.expiryTime > 0 && (client.expiryTime - now < this.expireDiff)) ||
  621. (client.total > 0 && (client.total - (client.up + client.down) < this.trafficDiff))) expiring.push(client.email);
  622. }
  623. });
  624. } else {
  625. clients.forEach(client => {
  626. deactive.push(client.email);
  627. });
  628. }
  629. }
  630. return {
  631. clients: clientCount,
  632. active: active,
  633. deactive: deactive,
  634. depleted: depleted,
  635. expiring: expiring,
  636. online: online,
  637. };
  638. },
  639. searchInbounds(key) {
  640. if (ObjectUtil.isEmpty(key)) {
  641. this.searchedInbounds = this.dbInbounds.slice();
  642. } else {
  643. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  644. this.dbInbounds.forEach(inbound => {
  645. if (ObjectUtil.deepSearch(inbound, key)) {
  646. const newInbound = new DBInbound(inbound);
  647. const inboundSettings = JSON.parse(inbound.settings);
  648. if (inboundSettings.hasOwnProperty('clients')) {
  649. const searchedSettings = { "clients": [] };
  650. inboundSettings.clients.forEach(client => {
  651. if (ObjectUtil.deepSearch(client, key)) {
  652. searchedSettings.clients.push(client);
  653. }
  654. });
  655. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, searchedSettings);
  656. }
  657. this.searchedInbounds.push(newInbound);
  658. }
  659. });
  660. }
  661. },
  662. filterInbounds() {
  663. if (ObjectUtil.isEmpty(this.filterBy)) {
  664. this.searchedInbounds = this.dbInbounds.slice();
  665. } else {
  666. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  667. this.dbInbounds.forEach(inbound => {
  668. const newInbound = new DBInbound(inbound);
  669. const inboundSettings = JSON.parse(inbound.settings);
  670. if (this.clientCount[inbound.id] && this.clientCount[inbound.id].hasOwnProperty(this.filterBy)){
  671. const list = this.clientCount[inbound.id][this.filterBy];
  672. if (list.length > 0) {
  673. const filteredSettings = { "clients": [] };
  674. inboundSettings.clients.forEach(client => {
  675. if (list.includes(client.email)) {
  676. filteredSettings.clients.push(client);
  677. }
  678. });
  679. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, filteredSettings);
  680. this.searchedInbounds.push(newInbound);
  681. }
  682. }
  683. });
  684. }
  685. },
  686. toggleFilter(){
  687. if(this.enableFilter) {
  688. this.searchKey = '';
  689. } else {
  690. this.filterBy = '';
  691. this.searchedInbounds = this.dbInbounds.slice();
  692. }
  693. },
  694. generalActions(action) {
  695. switch (action.key) {
  696. case "export":
  697. this.exportAllLinks();
  698. break;
  699. case "resetInbounds":
  700. this.resetAllTraffic();
  701. break;
  702. case "resetClients":
  703. this.resetAllClientTraffics(-1);
  704. break;
  705. case "delDepletedClients":
  706. this.delDepletedClients(-1)
  707. break;
  708. }
  709. },
  710. clickAction(action, dbInbound) {
  711. switch (action.key) {
  712. case "qrcode":
  713. this.showQrcode(dbInbound.id);
  714. break;
  715. case "showInfo":
  716. this.showInfo(dbInbound.id);
  717. break;
  718. case "edit":
  719. this.openEditInbound(dbInbound.id);
  720. break;
  721. case "addClient":
  722. this.openAddClient(dbInbound.id)
  723. break;
  724. case "addBulkClient":
  725. this.openAddBulkClient(dbInbound.id)
  726. break;
  727. case "export":
  728. this.inboundLinks(dbInbound.id);
  729. break;
  730. case "resetTraffic":
  731. this.resetTraffic(dbInbound.id);
  732. break;
  733. case "resetClients":
  734. this.resetAllClientTraffics(dbInbound.id);
  735. break;
  736. case "clone":
  737. this.openCloneInbound(dbInbound);
  738. break;
  739. case "delete":
  740. this.delInbound(dbInbound.id);
  741. break;
  742. case "delDepletedClients":
  743. this.delDepletedClients(dbInbound.id)
  744. break;
  745. }
  746. },
  747. openCloneInbound(dbInbound) {
  748. this.$confirm({
  749. title: '{{ i18n "pages.inbounds.cloneInbound"}} \"' + dbInbound.remark + '\"',
  750. content: '{{ i18n "pages.inbounds.cloneInboundContent"}}',
  751. okText: '{{ i18n "pages.inbounds.cloneInboundOk"}}',
  752. class: themeSwitcher.currentTheme,
  753. cancelText: '{{ i18n "cancel" }}',
  754. onOk: () => {
  755. const baseInbound = dbInbound.toInbound();
  756. dbInbound.up = 0;
  757. dbInbound.down = 0;
  758. this.cloneInbound(baseInbound, dbInbound);
  759. },
  760. });
  761. },
  762. async cloneInbound(baseInbound, dbInbound) {
  763. const data = {
  764. up: dbInbound.up,
  765. down: dbInbound.down,
  766. total: dbInbound.total,
  767. remark: dbInbound.remark + " - Cloned",
  768. enable: dbInbound.enable,
  769. expiryTime: dbInbound.expiryTime,
  770. listen: '',
  771. port: RandomUtil.randomIntRange(10000, 60000),
  772. protocol: baseInbound.protocol,
  773. settings: Inbound.Settings.getSettings(baseInbound.protocol).toString(),
  774. streamSettings: baseInbound.stream.toString(),
  775. sniffing: baseInbound.canSniffing() ? baseInbound.sniffing.toString() : '{}',
  776. };
  777. await this.submit('/panel/inbound/add', data, inModal);
  778. },
  779. openAddInbound() {
  780. inModal.show({
  781. title: '{{ i18n "pages.inbounds.addInbound"}}',
  782. okText: '{{ i18n "pages.inbounds.create"}}',
  783. cancelText: '{{ i18n "close" }}',
  784. confirm: async (inbound, dbInbound) => {
  785. inModal.loading();
  786. await this.addInbound(inbound, dbInbound);
  787. inModal.close();
  788. },
  789. isEdit: false
  790. });
  791. },
  792. openEditInbound(dbInboundId) {
  793. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  794. const inbound = dbInbound.toInbound();
  795. inModal.show({
  796. title: '{{ i18n "pages.inbounds.modifyInbound"}}',
  797. okText: '{{ i18n "pages.inbounds.update"}}',
  798. cancelText: '{{ i18n "close" }}',
  799. inbound: inbound,
  800. dbInbound: dbInbound,
  801. confirm: async (inbound, dbInbound) => {
  802. inModal.loading();
  803. await this.updateInbound(inbound, dbInbound);
  804. inModal.close();
  805. },
  806. isEdit: true
  807. });
  808. },
  809. async addInbound(inbound, dbInbound) {
  810. const data = {
  811. up: dbInbound.up,
  812. down: dbInbound.down,
  813. total: dbInbound.total,
  814. remark: dbInbound.remark,
  815. enable: dbInbound.enable,
  816. expiryTime: dbInbound.expiryTime,
  817. listen: inbound.listen,
  818. port: inbound.port,
  819. protocol: inbound.protocol,
  820. settings: inbound.settings.toString(),
  821. };
  822. if (inbound.canEnableStream()) data.streamSettings = inbound.stream.toString();
  823. if (inbound.canSniffing()) data.sniffing = inbound.sniffing.toString();
  824. await this.submit('/panel/inbound/add', data, inModal);
  825. },
  826. async updateInbound(inbound, dbInbound) {
  827. const data = {
  828. up: dbInbound.up,
  829. down: dbInbound.down,
  830. total: dbInbound.total,
  831. remark: dbInbound.remark,
  832. enable: dbInbound.enable,
  833. expiryTime: dbInbound.expiryTime,
  834. listen: inbound.listen,
  835. port: inbound.port,
  836. protocol: inbound.protocol,
  837. settings: inbound.settings.toString(),
  838. };
  839. if (inbound.canEnableStream()) data.streamSettings = inbound.stream.toString();
  840. if (inbound.canSniffing()) data.sniffing = inbound.sniffing.toString();
  841. await this.submit(`/panel/inbound/update/${dbInbound.id}`, data, inModal);
  842. },
  843. openAddClient(dbInboundId) {
  844. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  845. clientModal.show({
  846. title: '{{ i18n "pages.client.add"}}',
  847. okText: '{{ i18n "pages.client.submitAdd"}}',
  848. dbInbound: dbInbound,
  849. confirm: async (clients, dbInboundId) => {
  850. clientModal.loading();
  851. await this.addClient(clients, dbInboundId);
  852. clientModal.close();
  853. },
  854. isEdit: false
  855. });
  856. },
  857. openAddBulkClient(dbInboundId) {
  858. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  859. clientsBulkModal.show({
  860. title: '{{ i18n "pages.client.bulk"}} ' + dbInbound.remark,
  861. okText: '{{ i18n "pages.client.bulk"}}',
  862. dbInbound: dbInbound,
  863. confirm: async (clients, dbInboundId) => {
  864. clientsBulkModal.loading();
  865. await this.addClient(clients, dbInboundId);
  866. clientsBulkModal.close();
  867. },
  868. });
  869. },
  870. openEditClient(dbInboundId, client) {
  871. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  872. clients = this.getInboundClients(dbInbound);
  873. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  874. clientModal.show({
  875. title: '{{ i18n "pages.client.edit"}}',
  876. okText: '{{ i18n "pages.client.submitEdit"}}',
  877. dbInbound: dbInbound,
  878. index: index,
  879. confirm: async (client, dbInboundId, clientId) => {
  880. clientModal.loading();
  881. await this.updateClient(client, dbInboundId, clientId);
  882. clientModal.close();
  883. },
  884. isEdit: true
  885. });
  886. },
  887. findIndexOfClient(protocol, clients, client) {
  888. switch (protocol) {
  889. case Protocols.TROJAN:
  890. case Protocols.SHADOWSOCKS:
  891. return clients.findIndex(item => item.password === client.password && item.email === client.email);
  892. default: return clients.findIndex(item => item.id === client.id && item.email === client.email);
  893. }
  894. },
  895. async addClient(clients, dbInboundId) {
  896. const data = {
  897. id: dbInboundId,
  898. settings: '{"clients": [' + clients.toString() + ']}',
  899. };
  900. await this.submit(`/panel/inbound/addClient`, data);
  901. },
  902. async updateClient(client, dbInboundId, clientId) {
  903. const data = {
  904. id: dbInboundId,
  905. settings: '{"clients": [' + client.toString() + ']}',
  906. };
  907. await this.submit(`/panel/inbound/updateClient/${clientId}`, data);
  908. },
  909. resetTraffic(dbInboundId) {
  910. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  911. this.$confirm({
  912. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  913. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  914. class: themeSwitcher.currentTheme,
  915. okText: '{{ i18n "reset"}}',
  916. cancelText: '{{ i18n "cancel"}}',
  917. onOk: () => {
  918. const inbound = dbInbound.toInbound();
  919. dbInbound.up = 0;
  920. dbInbound.down = 0;
  921. this.updateInbound(inbound, dbInbound);
  922. },
  923. });
  924. },
  925. delInbound(dbInboundId) {
  926. this.$confirm({
  927. title: '{{ i18n "pages.inbounds.deleteInbound"}}',
  928. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  929. class: themeSwitcher.currentTheme,
  930. okText: '{{ i18n "delete"}}',
  931. cancelText: '{{ i18n "cancel"}}',
  932. onOk: () => this.submit('/panel/inbound/del/' + dbInboundId),
  933. });
  934. },
  935. delClient(dbInboundId, client,confirmation = true) {
  936. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  937. clientId = this.getClientId(dbInbound.protocol, client);
  938. if (confirmation){
  939. this.$confirm({
  940. title: '{{ i18n "pages.inbounds.deleteClient"}}',
  941. content: '{{ i18n "pages.inbounds.deleteClientContent"}}',
  942. class: themeSwitcher.currentTheme,
  943. okText: '{{ i18n "delete"}}',
  944. cancelText: '{{ i18n "cancel"}}',
  945. onOk: () => this.submit(`/panel/inbound/${dbInboundId}/delClient/${clientId}`),
  946. });
  947. } else {
  948. this.submit(`/panel/inbound/${dbInboundId}/delClient/${clientId}`);
  949. }
  950. },
  951. getClients(protocol, clientSettings) {
  952. switch (protocol) {
  953. case Protocols.VMESS: return clientSettings.vmesses;
  954. case Protocols.VLESS: return clientSettings.vlesses;
  955. case Protocols.TROJAN: return clientSettings.trojans;
  956. case Protocols.SHADOWSOCKS: return clientSettings.shadowsockses;
  957. default: return null;
  958. }
  959. },
  960. getClientId(protocol, client) {
  961. switch (protocol) {
  962. case Protocols.TROJAN: return client.password;
  963. case Protocols.SHADOWSOCKS: return client.email;
  964. default: return client.id;
  965. }
  966. },
  967. checkFallback(dbInbound) {
  968. newDbInbound = new DBInbound(dbInbound);
  969. if (dbInbound.listen.startsWith("@")){
  970. rootInbound = this.inbounds.find((i) =>
  971. i.tls &&
  972. ['trojan','vless'].includes(i.protocol) &&
  973. i.settings.fallbacks.find(f => f.dest === dbInbound.listen)
  974. );
  975. if (rootInbound) {
  976. newDbInbound.listen = rootInbound.listen;
  977. newDbInbound.port = rootInbound.port;
  978. newInbound = newDbInbound.toInbound();
  979. newInbound.stream.security = 'tls';
  980. newInbound.stream.tls = rootInbound.stream.tls;
  981. newDbInbound.streamSettings = newInbound.stream.toString();
  982. }
  983. }
  984. return newDbInbound;
  985. },
  986. showQrcode(dbInboundId, client) {
  987. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  988. inbound = dbInbound.toInbound();
  989. clients = this.getClients(dbInbound.protocol, inbound.settings);
  990. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  991. newDbInbound = this.checkFallback(dbInbound);
  992. qrModal.show('{{ i18n "qrCode"}}', newDbInbound, index);
  993. },
  994. showInfo(dbInboundId, client) {
  995. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  996. inbound = dbInbound.toInbound();
  997. clients = this.getClients(dbInbound.protocol, inbound.settings);
  998. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  999. newDbInbound = this.checkFallback(dbInbound);
  1000. infoModal.show(newDbInbound, index);
  1001. },
  1002. switchEnable(dbInboundId) {
  1003. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1004. this.submit(`/panel/inbound/update/${dbInboundId}`, dbInbound);
  1005. },
  1006. async switchEnableClient(dbInboundId, client) {
  1007. this.loading()
  1008. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1009. inbound = dbInbound.toInbound();
  1010. clients = this.getClients(dbInbound.protocol, inbound.settings);
  1011. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1012. clients[index].enable = !clients[index].enable;
  1013. clientId = this.getClientId(dbInbound.protocol, clients[index]);
  1014. await this.updateClient(clients[index], dbInboundId, clientId);
  1015. this.loading(false);
  1016. },
  1017. async submit(url, data) {
  1018. const msg = await HttpUtil.postWithModal(url, data);
  1019. if (msg.success) {
  1020. await this.getDBInbounds();
  1021. }
  1022. },
  1023. getInboundClients(dbInbound) {
  1024. if (dbInbound.protocol == Protocols.VLESS) {
  1025. return dbInbound.toInbound().settings.vlesses;
  1026. } else if (dbInbound.protocol == Protocols.VMESS) {
  1027. return dbInbound.toInbound().settings.vmesses;
  1028. } else if (dbInbound.protocol == Protocols.TROJAN) {
  1029. return dbInbound.toInbound().settings.trojans;
  1030. } else if (dbInbound.protocol == Protocols.SHADOWSOCKS) {
  1031. return dbInbound.toInbound().settings.shadowsockses;
  1032. }
  1033. },
  1034. resetClientTraffic(client, dbInboundId, confirmation = true) {
  1035. if (confirmation){
  1036. this.$confirm({
  1037. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  1038. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  1039. class: themeSwitcher.currentTheme,
  1040. okText: '{{ i18n "reset"}}',
  1041. cancelText: '{{ i18n "cancel"}}',
  1042. onOk: () => this.submit('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + client.email),
  1043. })
  1044. } else {
  1045. this.submit('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + client.email);
  1046. }
  1047. },
  1048. resetAllTraffic() {
  1049. this.$confirm({
  1050. title: '{{ i18n "pages.inbounds.resetAllTrafficTitle"}}',
  1051. content: '{{ i18n "pages.inbounds.resetAllTrafficContent"}}',
  1052. class: themeSwitcher.currentTheme,
  1053. okText: '{{ i18n "reset"}}',
  1054. cancelText: '{{ i18n "cancel"}}',
  1055. onOk: () => this.submit('/panel/inbound/resetAllTraffics'),
  1056. });
  1057. },
  1058. resetAllClientTraffics(dbInboundId) {
  1059. this.$confirm({
  1060. title: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficTitle"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficTitle"}}',
  1061. content: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficContent"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficContent"}}',
  1062. class: themeSwitcher.currentTheme,
  1063. okText: '{{ i18n "reset"}}',
  1064. cancelText: '{{ i18n "cancel"}}',
  1065. onOk: () => this.submit('/panel/inbound/resetAllClientTraffics/' + dbInboundId),
  1066. })
  1067. },
  1068. delDepletedClients(dbInboundId) {
  1069. this.$confirm({
  1070. title: '{{ i18n "pages.inbounds.delDepletedClientsTitle"}}',
  1071. content: '{{ i18n "pages.inbounds.delDepletedClientsContent"}}',
  1072. class: themeSwitcher.currentTheme,
  1073. okText: '{{ i18n "reset"}}',
  1074. cancelText: '{{ i18n "cancel"}}',
  1075. onOk: () => this.submit('/panel/inbound/delDepletedClients/' + dbInboundId),
  1076. })
  1077. },
  1078. isExpiry(dbInbound, index) {
  1079. return dbInbound.toInbound().isExpiry(index);
  1080. },
  1081. getUpStats(dbInbound, email) {
  1082. if (email.length == 0) return 0;
  1083. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1084. return clientStats ? clientStats.up : 0;
  1085. },
  1086. getDownStats(dbInbound, email) {
  1087. if (email.length == 0) return 0;
  1088. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1089. return clientStats ? clientStats.down : 0;
  1090. },
  1091. getSumStats(dbInbound, email) {
  1092. if (email.length == 0) return 0;
  1093. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1094. return clientStats ? clientStats.up + clientStats.down : 0;
  1095. },
  1096. getRemStats(dbInbound, email) {
  1097. if (email.length == 0) return 0;
  1098. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1099. if (!clientStats) return 0;
  1100. remained = clientStats.totalGB - (clientStats.up + clientStats.down);
  1101. return remained>0 ? remained : 0;
  1102. },
  1103. clientStatsColor(dbInbound, email) {
  1104. if (email.length == 0) return clientUsageColor();
  1105. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1106. return clientUsageColor(clientStats, app.trafficDiff)
  1107. },
  1108. statsProgress(dbInbound, email) {
  1109. if (email.length == 0) return 100;
  1110. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1111. if (!clientStats) return 0;
  1112. if (clientStats.total == 0) return 100;
  1113. return 100*(clientStats.down + clientStats.up)/clientStats.total;
  1114. },
  1115. expireProgress(expTime, reset) {
  1116. now = new Date().getTime();
  1117. remainedSeconds = expTime < 0 ? -expTime/1000 : (expTime-now)/1000;
  1118. resetSeconds = reset * 86400;
  1119. if (remainedSeconds >= resetSeconds) return 0;
  1120. return 100*(1-(remainedSeconds/resetSeconds));
  1121. },
  1122. remainedDays(expTime){
  1123. if (expTime == 0) return null;
  1124. if (expTime < 0) return formatSecond(expTime/-1000);
  1125. now = new Date().getTime();
  1126. if (expTime < now) return '{{ i18n "depleted" }}';
  1127. return formatSecond((expTime-now)/1000);
  1128. },
  1129. statsExpColor(dbInbound, email){
  1130. if (email.length == 0) return '#7a316f';
  1131. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1132. if (!clientStats) return '#7a316f';
  1133. statsColor = usageColor(clientStats.down + clientStats.up, this.trafficDiff, clientStats.total);
  1134. expColor = usageColor(new Date().getTime(), this.expireDiff, clientStats.expiryTime);
  1135. switch (true) {
  1136. case statsColor == "red" || expColor == "red":
  1137. return "#E04141";
  1138. case statsColor == "orange" || expColor == "orange":
  1139. return "#FFA031";
  1140. case statsColor == "blue" || expColor == "blue":
  1141. return "#0e49b5";
  1142. default:
  1143. return "#7a316f";
  1144. }
  1145. },
  1146. isClientEnabled(dbInbound, email) {
  1147. clientStats = dbInbound.clientStats ? dbInbound.clientStats.find(stats => stats.email === email) : null;
  1148. return clientStats ? clientStats['enable'] : true;
  1149. },
  1150. isClientOnline(email) {
  1151. return this.onlineClients.includes(email);
  1152. },
  1153. isRemovable(dbInboundId) {
  1154. return this.getInboundClients(this.dbInbounds.find(row => row.id === dbInboundId)).length > 1
  1155. },
  1156. inboundLinks(dbInboundId) {
  1157. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1158. newDbInbound = this.checkFallback(dbInbound);
  1159. txtModal.show('{{ i18n "pages.inbounds.export"}}', newDbInbound.genInboundLinks, newDbInbound.remark);
  1160. },
  1161. exportAllLinks() {
  1162. let copyText = '';
  1163. for (const dbInbound of this.dbInbounds) {
  1164. copyText += dbInbound.genInboundLinks;
  1165. }
  1166. txtModal.show('{{ i18n "pages.inbounds.export"}}', copyText, 'All-Inbounds');
  1167. },
  1168. async startDataRefreshLoop() {
  1169. while (this.isRefreshEnabled) {
  1170. try {
  1171. await this.getDBInbounds();
  1172. } catch (e) {
  1173. console.error(e);
  1174. }
  1175. await PromiseUtil.sleep(this.refreshInterval);
  1176. }
  1177. },
  1178. toggleRefresh() {
  1179. localStorage.setItem("isRefreshEnabled", this.isRefreshEnabled);
  1180. if (this.isRefreshEnabled) {
  1181. this.startDataRefreshLoop();
  1182. }
  1183. },
  1184. changeRefreshInterval() {
  1185. localStorage.setItem("refreshInterval", this.refreshInterval);
  1186. },
  1187. async manualRefresh() {
  1188. if (!this.refreshing) {
  1189. this.spinning = true;
  1190. await this.getDBInbounds();
  1191. this.spinning = false;
  1192. }
  1193. },
  1194. onResize() {
  1195. this.isMobile = window.innerWidth <= 768;
  1196. }
  1197. },
  1198. watch: {
  1199. searchKey: debounce(function (newVal) {
  1200. this.searchInbounds(newVal);
  1201. }, 500)
  1202. },
  1203. mounted() {
  1204. window.addEventListener('resize', this.onResize);
  1205. this.onResize();
  1206. this.loading();
  1207. this.getDefaultSettings();
  1208. if (this.isRefreshEnabled) {
  1209. this.startDataRefreshLoop();
  1210. }
  1211. else {
  1212. this.getDBInbounds();
  1213. }
  1214. this.loading(false);
  1215. },
  1216. computed: {
  1217. total() {
  1218. let down = 0, up = 0;
  1219. let clients = 0, deactive = [], depleted = [], expiring = [];
  1220. this.dbInbounds.forEach(dbInbound => {
  1221. down += dbInbound.down;
  1222. up += dbInbound.up;
  1223. if (this.clientCount[dbInbound.id]) {
  1224. clients += this.clientCount[dbInbound.id].clients;
  1225. deactive = deactive.concat(this.clientCount[dbInbound.id].deactive);
  1226. depleted = depleted.concat(this.clientCount[dbInbound.id].depleted);
  1227. expiring = expiring.concat(this.clientCount[dbInbound.id].expiring);
  1228. }
  1229. });
  1230. return {
  1231. down: down,
  1232. up: up,
  1233. clients: clients,
  1234. deactive: deactive,
  1235. depleted: depleted,
  1236. expiring: expiring,
  1237. };
  1238. }
  1239. },
  1240. });
  1241. </script>
  1242. {{template "inboundModal"}}
  1243. {{template "promptModal"}}
  1244. {{template "qrcodeModal"}}
  1245. {{template "textModal"}}
  1246. {{template "inboundInfoModal"}}
  1247. {{template "clientsModal"}}
  1248. {{template "clientsBulkModal"}}
  1249. </body>
  1250. </html>