inbounds.html 74 KB

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