inbounds.html 71 KB

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