inbounds.html 70 KB

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