inbounds.html 71 KB

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