1
0

inbounds.html 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469
  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" v-if="app.datepicker === 'gregorian'">
  406. [[ DateUtil.formatMillis(dbInbound.expiryTime) ]]
  407. </template>
  408. <template v-else slot="content">
  409. [[ DateUtil.convertToJalalian(moment(dbInbound.expiryTime)) ]]
  410. </template>
  411. <a-tag style="min-width: 50px;" :color="usageColor(new Date().getTime(), app.expireDiff, dbInbound._expiryTime)">
  412. [[ remainedDays(dbInbound._expiryTime) ]]
  413. </a-tag>
  414. </a-popover>
  415. <a-tag v-else color="purple" class="infinite-tag">
  416. <svg height="10px" width="14px" viewBox="0 0 640 512" fill="currentColor">
  417. <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>
  418. </svg>
  419. </a-tag>
  420. </template>
  421. <template slot="info" slot-scope="text, dbInbound">
  422. <a-popover placement="bottomRight" :overlay-class-name="themeSwitcher.currentTheme" trigger="click">
  423. <template slot="content">
  424. <table cellpadding="2">
  425. <tr>
  426. <td>{{ i18n "pages.inbounds.protocol" }}</td>
  427. <td>
  428. <a-tag style="margin:0;" color="purple">[[ dbInbound.protocol ]]</a-tag>
  429. <template v-if="dbInbound.isVMess || dbInbound.isVLess || dbInbound.isTrojan || dbInbound.isSS">
  430. <a-tag style="margin:0;" color="blue">[[ dbInbound.toInbound().stream.network ]]</a-tag>
  431. <a-tag style="margin:0;" v-if="dbInbound.toInbound().stream.isTls" color="green">tls</a-tag>
  432. <a-tag style="margin:0;" v-if="dbInbound.toInbound().stream.isReality" color="green">reality</a-tag>
  433. </template>
  434. </td>
  435. </tr>
  436. <tr>
  437. <td>{{ i18n "pages.inbounds.port" }}</td>
  438. <td><a-tag>[[ dbInbound.port ]]</a-tag></td>
  439. </tr>
  440. <tr v-if="clientCount[dbInbound.id]">
  441. <td>{{ i18n "clients" }}</td>
  442. <td>
  443. <a-tag style="margin:0;" color="blue">[[ clientCount[dbInbound.id].clients ]]</a-tag>
  444. <a-popover title='{{ i18n "disabled" }}' :overlay-class-name="themeSwitcher.currentTheme">
  445. <template slot="content">
  446. <p v-for="clientEmail in clientCount[dbInbound.id].deactive">[[ clientEmail ]]</p>
  447. </template>
  448. <a-tag style="margin:0; padding: 0 2px;" v-if="clientCount[dbInbound.id].deactive.length">[[ clientCount[dbInbound.id].deactive.length ]]</a-tag>
  449. </a-popover>
  450. <a-popover title='{{ i18n "depleted" }}' :overlay-class-name="themeSwitcher.currentTheme">
  451. <template slot="content">
  452. <p v-for="clientEmail in clientCount[dbInbound.id].depleted">[[ clientEmail ]]</p>
  453. </template>
  454. <a-tag style="margin:0; padding: 0 2px;" color="red" v-if="clientCount[dbInbound.id].depleted.length">[[ clientCount[dbInbound.id].depleted.length ]]</a-tag>
  455. </a-popover>
  456. <a-popover title='{{ i18n "depletingSoon" }}' :overlay-class-name="themeSwitcher.currentTheme">
  457. <template slot="content">
  458. <p v-for="clientEmail in clientCount[dbInbound.id].expiring">[[ clientEmail ]]</p>
  459. </template>
  460. <a-tag style="margin:0; padding: 0 2px;" color="orange" v-if="clientCount[dbInbound.id].expiring.length">[[ clientCount[dbInbound.id].expiring.length ]]</a-tag>
  461. </a-popover>
  462. <a-popover title='{{ i18n "online" }}' :overlay-class-name="themeSwitcher.currentTheme">
  463. <template slot="content">
  464. <p v-for="clientEmail in clientCount[dbInbound.id].online">[[ clientEmail ]]</p>
  465. </template>
  466. <a-tag style="margin:0; padding: 0 2px;" color="green" v-if="clientCount[dbInbound.id].online.length">[[ clientCount[dbInbound.id].online.length ]]</a-tag>
  467. </a-popover>
  468. </td>
  469. </tr>
  470. <tr>
  471. <td>{{ i18n "pages.inbounds.traffic" }}</td>
  472. <td>
  473. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  474. <template slot="content">
  475. <table cellpadding="2" width="100%">
  476. <tr>
  477. <td>↑[[ sizeFormat(dbInbound.up) ]]</td>
  478. <td>↓[[ sizeFormat(dbInbound.down) ]]</td>
  479. </tr>
  480. <tr v-if="dbInbound.total > 0 && dbInbound.up + dbInbound.down < dbInbound.total">
  481. <td>{{ i18n "remained" }}</td>
  482. <td>[[ sizeFormat(dbInbound.total - dbInbound.up - dbInbound.down) ]]</td>
  483. </tr>
  484. </table>
  485. </template>
  486. <a-tag :color="usageColor(dbInbound.up + dbInbound.down, app.trafficDiff, dbInbound.total)">
  487. [[ sizeFormat(dbInbound.up + dbInbound.down) ]] /
  488. <template v-if="dbInbound.total > 0">
  489. [[ sizeFormat(dbInbound.total) ]]
  490. </template>
  491. <template v-else>
  492. <svg height="10px" width="14px" viewBox="0 0 640 512" fill="currentColor">
  493. <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>
  494. </svg>
  495. </template>
  496. </a-tag>
  497. </a-popover>
  498. </td>
  499. </tr>
  500. <tr>
  501. <td>{{ i18n "pages.inbounds.expireDate" }}</td>
  502. <td>
  503. <a-tag style="min-width: 50px; text-align: center;" v-if="dbInbound.expiryTime > 0"
  504. :color="dbInbound.isExpiry? 'red': 'blue'">
  505. <template v-if="app.datepicker === 'gregorian'">
  506. [[ DateUtil.formatMillis(dbInbound.expiryTime) ]]
  507. </template>
  508. <template v-else>
  509. [[ DateUtil.convertToJalalian(moment(dbInbound.expiryTime)) ]]
  510. </template>
  511. </a-tag>
  512. <a-tag v-else style="text-align: center;" color="purple" class="infinite-tag">
  513. <svg height="10px" width="14px" viewBox="0 0 640 512" fill="currentColor">
  514. <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>
  515. </svg>
  516. </a-tag>
  517. </td>
  518. </tr>
  519. </table>
  520. </template>
  521. <a-badge>
  522. <a-icon v-if="!dbInbound.enable" slot="count" type="pause-circle" :style="'color: ' + themeSwitcher.isDarkTheme ? '#2c3950' : '#bcbcbc'"></a-icon>
  523. <a-button shape="round" size="small" style="font-size: 14px; padding: 0 10px;">
  524. <a-icon type="info"></a-icon>
  525. </a-button>
  526. </a-badge>
  527. </a-popover>
  528. </template>
  529. <template slot="expandedRowRender" slot-scope="record">
  530. <a-table
  531. :row-key="client => client.id"
  532. :columns="isMobile ? innerMobileColumns : innerColumns"
  533. :data-source="getInboundClients(record)"
  534. :pagination=pagination(getInboundClients(record))
  535. :style="isMobile ? 'margin: -10px 2px -11px;' : 'margin: -10px 22px -11px;'">
  536. {{template "client_table"}}
  537. </a-table>
  538. </template>
  539. </a-table>
  540. </a-card>
  541. </transition>
  542. </a-spin>
  543. </a-layout-content>
  544. </a-layout>
  545. </a-layout>
  546. {{template "js" .}}
  547. <script src="{{ .base_path }}assets/base64/base64.min.js"></script>
  548. <script src="{{ .base_path }}assets/qrcode/qrious2.min.js?{{ .cur_ver }}"></script>
  549. <script src="{{ .base_path }}assets/clipboard/clipboard.min.js?{{ .cur_ver }}"></script>
  550. <script src="{{ .base_path }}assets/uri/URI.min.js?{{ .cur_ver }}"></script>
  551. <script src="{{ .base_path }}assets/js/model/xray.js?{{ .cur_ver }}"></script>
  552. <script src="{{ .base_path }}assets/js/model/dbinbound.js?{{ .cur_ver }}"></script>
  553. {{template "component/themeSwitcher" .}}
  554. {{template "component/persianDatepicker" .}}
  555. <script>
  556. const columns = [{
  557. title: "ID",
  558. align: 'right',
  559. dataIndex: "id",
  560. width: 30,
  561. responsive: ["xs"],
  562. }, {
  563. title: '{{ i18n "pages.inbounds.operate" }}',
  564. align: 'center',
  565. width: 30,
  566. scopedSlots: { customRender: 'action' },
  567. }, {
  568. title: '{{ i18n "pages.inbounds.enable" }}',
  569. align: 'center',
  570. width: 30,
  571. scopedSlots: { customRender: 'enable' },
  572. }, {
  573. title: '{{ i18n "pages.inbounds.remark" }}',
  574. align: 'center',
  575. width: 60,
  576. dataIndex: "remark",
  577. }, {
  578. title: '{{ i18n "pages.inbounds.port" }}',
  579. align: 'center',
  580. dataIndex: "port",
  581. width: 40,
  582. }, {
  583. title: '{{ i18n "pages.inbounds.protocol" }}',
  584. align: 'left',
  585. width: 70,
  586. scopedSlots: { customRender: 'protocol' },
  587. }, {
  588. title: '{{ i18n "clients" }}',
  589. align: 'left',
  590. width: 50,
  591. scopedSlots: { customRender: 'clients' },
  592. }, {
  593. title: '{{ i18n "pages.inbounds.traffic" }}',
  594. align: 'center',
  595. width: 60,
  596. scopedSlots: { customRender: 'traffic' },
  597. }, {
  598. title: '{{ i18n "pages.inbounds.expireDate" }}',
  599. align: 'center',
  600. width: 40,
  601. scopedSlots: { customRender: 'expiryTime' },
  602. }];
  603. const mobileColumns = [{
  604. title: "ID",
  605. align: 'right',
  606. dataIndex: "id",
  607. width: 10,
  608. responsive: ["s"],
  609. }, {
  610. title: '{{ i18n "pages.inbounds.operate" }}',
  611. align: 'center',
  612. width: 25,
  613. scopedSlots: { customRender: 'action' },
  614. }, {
  615. title: '{{ i18n "pages.inbounds.remark" }}',
  616. align: 'left',
  617. width: 70,
  618. dataIndex: "remark",
  619. }, {
  620. title: '{{ i18n "pages.inbounds.info" }}',
  621. align: 'center',
  622. width: 10,
  623. scopedSlots: { customRender: 'info' },
  624. }];
  625. const innerColumns = [
  626. { title: '{{ i18n "pages.inbounds.operate" }}', width: 65, scopedSlots: { customRender: 'actions' } },
  627. { title: '{{ i18n "pages.inbounds.enable" }}', width: 30, scopedSlots: { customRender: 'enable' } },
  628. { title: '{{ i18n "online" }}', width: 30, scopedSlots: { customRender: 'online' } },
  629. { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } },
  630. { title: '{{ i18n "pages.inbounds.traffic" }}', width: 80, align: 'center', scopedSlots: { customRender: 'traffic' } },
  631. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 80, align: 'center', scopedSlots: { customRender: 'expiryTime' } },
  632. ];
  633. const innerMobileColumns = [
  634. { title: '{{ i18n "pages.inbounds.operate" }}', width: 10, align: 'center', scopedSlots: { customRender: 'actionMenu' } },
  635. { title: '{{ i18n "pages.inbounds.client" }}', width: 90, align: 'left', scopedSlots: { customRender: 'client' } },
  636. { title: '{{ i18n "pages.inbounds.info" }}', width: 10, align: 'center', scopedSlots: { customRender: 'info' } },
  637. ];
  638. const app = new Vue({
  639. delimiters: ['[[', ']]'],
  640. el: '#app',
  641. data: {
  642. siderDrawer,
  643. themeSwitcher,
  644. persianDatepicker,
  645. spinning: false,
  646. inbounds: [],
  647. dbInbounds: [],
  648. searchKey: '',
  649. enableFilter: false,
  650. filterBy: '',
  651. searchedInbounds: [],
  652. expireDiff: 0,
  653. trafficDiff: 0,
  654. defaultCert: '',
  655. defaultKey: '',
  656. clientCount: [],
  657. onlineClients: [],
  658. isRefreshEnabled: localStorage.getItem("isRefreshEnabled") === "true" ? true : false,
  659. refreshing: false,
  660. refreshInterval: Number(localStorage.getItem("refreshInterval")) || 5000,
  661. subSettings: {
  662. enable : false,
  663. subURI : '',
  664. subJsonURI : '',
  665. },
  666. remarkModel: '-ieo',
  667. datepicker: 'gregorian',
  668. tgBotEnable: false,
  669. showAlert: false,
  670. ipLimitEnable: false,
  671. pageSize: 50,
  672. isMobile: window.innerWidth <= 768,
  673. },
  674. methods: {
  675. loading(spinning = true) {
  676. this.spinning = spinning;
  677. },
  678. async getDBInbounds() {
  679. this.refreshing = true;
  680. const msg = await HttpUtil.post('/panel/inbound/list');
  681. if (!msg.success) {
  682. this.refreshing = false;
  683. return;
  684. }
  685. await this.getOnlineUsers();
  686. this.setInbounds(msg.obj);
  687. setTimeout(() => {
  688. this.refreshing = false;
  689. }, 500);
  690. },
  691. async getOnlineUsers() {
  692. const msg = await HttpUtil.post('/panel/inbound/onlines');
  693. if (!msg.success) {
  694. return;
  695. }
  696. this.onlineClients = msg.obj != null ? msg.obj : [];
  697. },
  698. async getDefaultSettings() {
  699. const msg = await HttpUtil.post('/panel/setting/defaultSettings');
  700. if (!msg.success) {
  701. return;
  702. }
  703. with(msg.obj){
  704. this.expireDiff = expireDiff * 86400000;
  705. this.trafficDiff = trafficDiff * 1073741824;
  706. this.defaultCert = defaultCert;
  707. this.defaultKey = defaultKey;
  708. this.tgBotEnable = tgBotEnable;
  709. this.subSettings = {
  710. enable : subEnable,
  711. subURI: subURI,
  712. subJsonURI: subJsonURI
  713. };
  714. this.pageSize = pageSize;
  715. this.remarkModel = remarkModel;
  716. this.datepicker = datepicker;
  717. this.ipLimitEnable = ipLimitEnable;
  718. }
  719. },
  720. setInbounds(dbInbounds) {
  721. this.inbounds.splice(0);
  722. this.dbInbounds.splice(0);
  723. this.clientCount.splice(0);
  724. for (const inbound of dbInbounds) {
  725. const dbInbound = new DBInbound(inbound);
  726. to_inbound = dbInbound.toInbound()
  727. this.inbounds.push(to_inbound);
  728. this.dbInbounds.push(dbInbound);
  729. if ([Protocols.VMESS, Protocols.VLESS, Protocols.TROJAN, Protocols.SHADOWSOCKS].includes(inbound.protocol)) {
  730. if (dbInbound.isSS && (!to_inbound.isSSMultiUser)) {
  731. continue;
  732. }
  733. this.clientCount[inbound.id] = this.getClientCounts(inbound, to_inbound);
  734. }
  735. }
  736. if(this.enableFilter){
  737. this.filterInbounds();
  738. } else {
  739. this.searchInbounds(this.searchKey);
  740. }
  741. },
  742. getClientCounts(dbInbound, inbound) {
  743. let clientCount = 0, active = [], deactive = [], depleted = [], expiring = [], online = [];
  744. clients = inbound.clients;
  745. clientStats = dbInbound.clientStats
  746. now = new Date().getTime()
  747. if (clients) {
  748. clientCount = clients.length;
  749. if (dbInbound.enable) {
  750. clients.forEach(client => {
  751. if (client.enable) {
  752. active.push(client.email);
  753. if (this.isClientOnline(client.email)) online.push(client.email);
  754. } else {
  755. deactive.push(client.email);
  756. }
  757. });
  758. clientStats.forEach(client => {
  759. if (!client.enable) {
  760. depleted.push(client.email);
  761. } else {
  762. if ((client.expiryTime > 0 && (client.expiryTime - now < this.expireDiff)) ||
  763. (client.total > 0 && (client.total - (client.up + client.down) < this.trafficDiff))) expiring.push(client.email);
  764. }
  765. });
  766. } else {
  767. clients.forEach(client => {
  768. deactive.push(client.email);
  769. });
  770. }
  771. }
  772. return {
  773. clients: clientCount,
  774. active: active,
  775. deactive: deactive,
  776. depleted: depleted,
  777. expiring: expiring,
  778. online: online,
  779. };
  780. },
  781. searchInbounds(key) {
  782. if (ObjectUtil.isEmpty(key)) {
  783. this.searchedInbounds = this.dbInbounds.slice();
  784. } else {
  785. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  786. this.dbInbounds.forEach(inbound => {
  787. if (ObjectUtil.deepSearch(inbound, key)) {
  788. const newInbound = new DBInbound(inbound);
  789. const inboundSettings = JSON.parse(inbound.settings);
  790. if (inboundSettings.hasOwnProperty('clients')) {
  791. const searchedSettings = { "clients": [] };
  792. inboundSettings.clients.forEach(client => {
  793. if (ObjectUtil.deepSearch(client, key)) {
  794. searchedSettings.clients.push(client);
  795. }
  796. });
  797. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, searchedSettings);
  798. }
  799. this.searchedInbounds.push(newInbound);
  800. }
  801. });
  802. }
  803. },
  804. filterInbounds() {
  805. if (ObjectUtil.isEmpty(this.filterBy)) {
  806. this.searchedInbounds = this.dbInbounds.slice();
  807. } else {
  808. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  809. this.dbInbounds.forEach(inbound => {
  810. const newInbound = new DBInbound(inbound);
  811. const inboundSettings = JSON.parse(inbound.settings);
  812. if (this.clientCount[inbound.id] && this.clientCount[inbound.id].hasOwnProperty(this.filterBy)){
  813. const list = this.clientCount[inbound.id][this.filterBy];
  814. if (list.length > 0) {
  815. const filteredSettings = { "clients": [] };
  816. inboundSettings.clients.forEach(client => {
  817. if (list.includes(client.email)) {
  818. filteredSettings.clients.push(client);
  819. }
  820. });
  821. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, filteredSettings);
  822. this.searchedInbounds.push(newInbound);
  823. }
  824. }
  825. });
  826. }
  827. },
  828. toggleFilter(){
  829. if(this.enableFilter) {
  830. this.searchKey = '';
  831. } else {
  832. this.filterBy = '';
  833. this.searchedInbounds = this.dbInbounds.slice();
  834. }
  835. },
  836. generalActions(action) {
  837. switch (action.key) {
  838. case "import":
  839. this.importInbound();
  840. break;
  841. case "export":
  842. this.exportAllLinks();
  843. break;
  844. case "subs":
  845. this.exportAllSubs();
  846. break;
  847. case "resetInbounds":
  848. this.resetAllTraffic();
  849. break;
  850. case "resetClients":
  851. this.resetAllClientTraffics(-1);
  852. break;
  853. case "delDepletedClients":
  854. this.delDepletedClients(-1)
  855. break;
  856. }
  857. },
  858. clickAction(action, dbInbound) {
  859. switch (action.key) {
  860. case "qrcode":
  861. this.showQrcode(dbInbound.id);
  862. break;
  863. case "showInfo":
  864. this.showInfo(dbInbound.id);
  865. break;
  866. case "edit":
  867. this.openEditInbound(dbInbound.id);
  868. break;
  869. case "addClient":
  870. this.openAddClient(dbInbound.id)
  871. break;
  872. case "addBulkClient":
  873. this.openAddBulkClient(dbInbound.id)
  874. break;
  875. case "export":
  876. this.inboundLinks(dbInbound.id);
  877. break;
  878. case "subs":
  879. this.exportSubs(dbInbound.id);
  880. break;
  881. case "clipboard":
  882. this.copyToClipboard(dbInbound.id);
  883. break;
  884. case "resetTraffic":
  885. this.resetTraffic(dbInbound.id);
  886. break;
  887. case "resetClients":
  888. this.resetAllClientTraffics(dbInbound.id);
  889. break;
  890. case "clone":
  891. this.openCloneInbound(dbInbound);
  892. break;
  893. case "delete":
  894. this.delInbound(dbInbound.id);
  895. break;
  896. case "delDepletedClients":
  897. this.delDepletedClients(dbInbound.id)
  898. break;
  899. }
  900. },
  901. openCloneInbound(dbInbound) {
  902. this.$confirm({
  903. title: '{{ i18n "pages.inbounds.cloneInbound"}} \"' + dbInbound.remark + '\"',
  904. content: '{{ i18n "pages.inbounds.cloneInboundContent"}}',
  905. okText: '{{ i18n "pages.inbounds.cloneInboundOk"}}',
  906. class: themeSwitcher.currentTheme,
  907. cancelText: '{{ i18n "cancel" }}',
  908. onOk: () => {
  909. const baseInbound = dbInbound.toInbound();
  910. dbInbound.up = 0;
  911. dbInbound.down = 0;
  912. this.cloneInbound(baseInbound, dbInbound);
  913. },
  914. });
  915. },
  916. async cloneInbound(baseInbound, dbInbound) {
  917. const data = {
  918. up: dbInbound.up,
  919. down: dbInbound.down,
  920. total: dbInbound.total,
  921. remark: dbInbound.remark + " - Cloned",
  922. enable: dbInbound.enable,
  923. expiryTime: dbInbound.expiryTime,
  924. listen: '',
  925. port: RandomUtil.randomIntRange(10000, 60000),
  926. protocol: baseInbound.protocol,
  927. settings: Inbound.Settings.getSettings(baseInbound.protocol).toString(),
  928. streamSettings: baseInbound.stream.toString(),
  929. sniffing: baseInbound.sniffing.toString(),
  930. allocate: baseInbound.allocate.toString(),
  931. };
  932. await this.submit('/panel/inbound/add', data, inModal);
  933. },
  934. openAddInbound() {
  935. inModal.show({
  936. title: '{{ i18n "pages.inbounds.addInbound"}}',
  937. okText: '{{ i18n "pages.inbounds.create"}}',
  938. cancelText: '{{ i18n "close" }}',
  939. confirm: async (inbound, dbInbound) => {
  940. await this.addInbound(inbound, dbInbound, inModal);
  941. },
  942. isEdit: false
  943. });
  944. },
  945. openEditInbound(dbInboundId) {
  946. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  947. const inbound = dbInbound.toInbound();
  948. inModal.show({
  949. title: '{{ i18n "pages.inbounds.modifyInbound"}}',
  950. okText: '{{ i18n "pages.inbounds.update"}}',
  951. cancelText: '{{ i18n "close" }}',
  952. inbound: inbound,
  953. dbInbound: dbInbound,
  954. confirm: async (inbound, dbInbound) => {
  955. await this.updateInbound(inbound, dbInbound);
  956. },
  957. isEdit: true
  958. });
  959. },
  960. async addInbound(inbound, dbInbound) {
  961. const data = {
  962. up: dbInbound.up,
  963. down: dbInbound.down,
  964. total: dbInbound.total,
  965. remark: dbInbound.remark,
  966. enable: dbInbound.enable,
  967. expiryTime: dbInbound.expiryTime,
  968. listen: inbound.listen,
  969. port: inbound.port,
  970. protocol: inbound.protocol,
  971. settings: inbound.settings.toString(),
  972. };
  973. if (inbound.canEnableStream()) data.streamSettings = inbound.stream.toString();
  974. data.sniffing = inbound.sniffing.toString();
  975. data.allocate = inbound.allocate.toString();
  976. await this.submit('/panel/inbound/add', data, inModal);
  977. },
  978. async updateInbound(inbound, dbInbound) {
  979. const data = {
  980. up: dbInbound.up,
  981. down: dbInbound.down,
  982. total: dbInbound.total,
  983. remark: dbInbound.remark,
  984. enable: dbInbound.enable,
  985. expiryTime: dbInbound.expiryTime,
  986. listen: inbound.listen,
  987. port: inbound.port,
  988. protocol: inbound.protocol,
  989. settings: inbound.settings.toString(),
  990. };
  991. if (inbound.canEnableStream()) data.streamSettings = inbound.stream.toString();
  992. data.sniffing = inbound.sniffing.toString();
  993. data.allocate = inbound.allocate.toString();
  994. await this.submit(`/panel/inbound/update/${dbInbound.id}`, data, inModal);
  995. },
  996. openAddClient(dbInboundId) {
  997. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  998. clientModal.show({
  999. title: '{{ i18n "pages.client.add"}}',
  1000. okText: '{{ i18n "pages.client.submitAdd"}}',
  1001. dbInbound: dbInbound,
  1002. confirm: async (clients, dbInboundId) => {
  1003. await this.addClient(clients, dbInboundId, clientModal);
  1004. },
  1005. isEdit: false
  1006. });
  1007. },
  1008. openAddBulkClient(dbInboundId) {
  1009. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1010. clientsBulkModal.show({
  1011. title: '{{ i18n "pages.client.bulk"}} ' + dbInbound.remark,
  1012. okText: '{{ i18n "pages.client.bulk"}}',
  1013. dbInbound: dbInbound,
  1014. confirm: async (clients, dbInboundId) => {
  1015. await this.addClient(clients, dbInboundId, clientsBulkModal);
  1016. },
  1017. });
  1018. },
  1019. openEditClient(dbInboundId, client) {
  1020. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1021. clients = this.getInboundClients(dbInbound);
  1022. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1023. clientModal.show({
  1024. title: '{{ i18n "pages.client.edit"}}',
  1025. okText: '{{ i18n "pages.client.submitEdit"}}',
  1026. dbInbound: dbInbound,
  1027. index: index,
  1028. confirm: async (client, dbInboundId, clientId) => {
  1029. clientModal.loading();
  1030. await this.updateClient(client, dbInboundId, clientId);
  1031. clientModal.close();
  1032. },
  1033. isEdit: true
  1034. });
  1035. },
  1036. findIndexOfClient(protocol, clients, client) {
  1037. switch (protocol) {
  1038. case Protocols.TROJAN:
  1039. case Protocols.SHADOWSOCKS:
  1040. return clients.findIndex(item => item.password === client.password && item.email === client.email);
  1041. default: return clients.findIndex(item => item.id === client.id && item.email === client.email);
  1042. }
  1043. },
  1044. async addClient(clients, dbInboundId, modal) {
  1045. const data = {
  1046. id: dbInboundId,
  1047. settings: '{"clients": [' + clients.toString() + ']}',
  1048. };
  1049. await this.submit(`/panel/inbound/addClient`, data, modal);
  1050. },
  1051. async updateClient(client, dbInboundId, clientId) {
  1052. const data = {
  1053. id: dbInboundId,
  1054. settings: '{"clients": [' + client.toString() + ']}',
  1055. };
  1056. await this.submit(`/panel/inbound/updateClient/${clientId}`, data, clientModal);
  1057. },
  1058. resetTraffic(dbInboundId) {
  1059. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1060. this.$confirm({
  1061. title: '{{ i18n "pages.inbounds.resetTraffic"}}' + ' #' + dbInboundId,
  1062. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  1063. class: themeSwitcher.currentTheme,
  1064. okText: '{{ i18n "reset"}}',
  1065. cancelText: '{{ i18n "cancel"}}',
  1066. onOk: () => {
  1067. const inbound = dbInbound.toInbound();
  1068. dbInbound.up = 0;
  1069. dbInbound.down = 0;
  1070. this.updateInbound(inbound, dbInbound);
  1071. },
  1072. });
  1073. },
  1074. delInbound(dbInboundId) {
  1075. this.$confirm({
  1076. title: '{{ i18n "pages.inbounds.deleteInbound"}}' + ' #' + dbInboundId,
  1077. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  1078. class: themeSwitcher.currentTheme,
  1079. okText: '{{ i18n "delete"}}',
  1080. cancelText: '{{ i18n "cancel"}}',
  1081. onOk: () => this.submit('/panel/inbound/del/' + dbInboundId),
  1082. });
  1083. },
  1084. delClient(dbInboundId, client,confirmation = true) {
  1085. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1086. clientId = this.getClientId(dbInbound.protocol, client);
  1087. if (confirmation){
  1088. this.$confirm({
  1089. title: '{{ i18n "pages.inbounds.deleteClient"}}' + ' ' + client.email,
  1090. content: '{{ i18n "pages.inbounds.deleteClientContent"}}',
  1091. class: themeSwitcher.currentTheme,
  1092. okText: '{{ i18n "delete"}}',
  1093. cancelText: '{{ i18n "cancel"}}',
  1094. onOk: () => this.submit(`/panel/inbound/${dbInboundId}/delClient/${clientId}`),
  1095. });
  1096. } else {
  1097. this.submit(`/panel/inbound/${dbInboundId}/delClient/${clientId}`);
  1098. }
  1099. },
  1100. getClientId(protocol, client) {
  1101. switch (protocol) {
  1102. case Protocols.TROJAN: return client.password;
  1103. case Protocols.SHADOWSOCKS: return client.email;
  1104. default: return client.id;
  1105. }
  1106. },
  1107. checkFallback(dbInbound) {
  1108. newDbInbound = new DBInbound(dbInbound);
  1109. if (dbInbound.listen.startsWith("@")){
  1110. rootInbound = this.inbounds.find((i) =>
  1111. i.isTcp &&
  1112. ['trojan','vless'].includes(i.protocol) &&
  1113. i.settings.fallbacks.find(f => f.dest === dbInbound.listen)
  1114. );
  1115. if (rootInbound) {
  1116. newDbInbound.listen = rootInbound.listen;
  1117. newDbInbound.port = rootInbound.port;
  1118. newInbound = newDbInbound.toInbound();
  1119. newInbound.stream.security = rootInbound.stream.security;
  1120. newInbound.stream.tls = rootInbound.stream.tls;
  1121. newInbound.stream.externalProxy = rootInbound.stream.externalProxy;
  1122. newDbInbound.streamSettings = newInbound.stream.toString();
  1123. }
  1124. }
  1125. return newDbInbound;
  1126. },
  1127. showQrcode(dbInboundId, client) {
  1128. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1129. newDbInbound = this.checkFallback(dbInbound);
  1130. qrModal.show('{{ i18n "qrCode"}}', newDbInbound, client);
  1131. },
  1132. showInfo(dbInboundId, client) {
  1133. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1134. index=0;
  1135. if (dbInbound.isMultiUser()){
  1136. inbound = dbInbound.toInbound();
  1137. clients = inbound.clients;
  1138. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1139. }
  1140. newDbInbound = this.checkFallback(dbInbound);
  1141. infoModal.show(newDbInbound, index);
  1142. },
  1143. switchEnable(dbInboundId,state) {
  1144. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1145. dbInbound.enable = state;
  1146. this.submit(`/panel/inbound/update/${dbInboundId}`, dbInbound);
  1147. },
  1148. async switchEnableClient(dbInboundId, client) {
  1149. this.loading()
  1150. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1151. inbound = dbInbound.toInbound();
  1152. clients = inbound.clients;
  1153. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1154. clients[index].enable = !clients[index].enable;
  1155. clientId = this.getClientId(dbInbound.protocol, clients[index]);
  1156. await this.updateClient(clients[index], dbInboundId, clientId);
  1157. this.loading(false);
  1158. },
  1159. async submit(url, data, modal) {
  1160. const msg = await HttpUtil.postWithModal(url, data, modal);
  1161. if (msg.success) {
  1162. await this.getDBInbounds();
  1163. }
  1164. },
  1165. getInboundClients(dbInbound) {
  1166. return dbInbound.toInbound().clients;
  1167. },
  1168. resetClientTraffic(client, dbInboundId, confirmation = true) {
  1169. if (confirmation){
  1170. this.$confirm({
  1171. title: '{{ i18n "pages.inbounds.resetTraffic"}}' + ' ' + client.email,
  1172. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  1173. class: themeSwitcher.currentTheme,
  1174. okText: '{{ i18n "reset"}}',
  1175. cancelText: '{{ i18n "cancel"}}',
  1176. onOk: () => this.submit('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + client.email),
  1177. })
  1178. } else {
  1179. this.submit('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + client.email);
  1180. }
  1181. },
  1182. resetAllTraffic() {
  1183. this.$confirm({
  1184. title: '{{ i18n "pages.inbounds.resetAllTrafficTitle"}}',
  1185. content: '{{ i18n "pages.inbounds.resetAllTrafficContent"}}',
  1186. class: themeSwitcher.currentTheme,
  1187. okText: '{{ i18n "reset"}}',
  1188. cancelText: '{{ i18n "cancel"}}',
  1189. onOk: () => this.submit('/panel/inbound/resetAllTraffics'),
  1190. });
  1191. },
  1192. resetAllClientTraffics(dbInboundId) {
  1193. this.$confirm({
  1194. title: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficTitle"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficTitle"}}',
  1195. content: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficContent"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficContent"}}',
  1196. class: themeSwitcher.currentTheme,
  1197. okText: '{{ i18n "reset"}}',
  1198. cancelText: '{{ i18n "cancel"}}',
  1199. onOk: () => this.submit('/panel/inbound/resetAllClientTraffics/' + dbInboundId),
  1200. })
  1201. },
  1202. delDepletedClients(dbInboundId) {
  1203. this.$confirm({
  1204. title: '{{ i18n "pages.inbounds.delDepletedClientsTitle"}}',
  1205. content: '{{ i18n "pages.inbounds.delDepletedClientsContent"}}',
  1206. class: themeSwitcher.currentTheme,
  1207. okText: '{{ i18n "delete"}}',
  1208. cancelText: '{{ i18n "cancel"}}',
  1209. onOk: () => this.submit('/panel/inbound/delDepletedClients/' + dbInboundId),
  1210. })
  1211. },
  1212. isExpiry(dbInbound, index) {
  1213. return dbInbound.toInbound().isExpiry(index);
  1214. },
  1215. getUpStats(dbInbound, email) {
  1216. if (email.length == 0) return 0;
  1217. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1218. return clientStats ? clientStats.up : 0;
  1219. },
  1220. getDownStats(dbInbound, email) {
  1221. if (email.length == 0) return 0;
  1222. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1223. return clientStats ? clientStats.down : 0;
  1224. },
  1225. getSumStats(dbInbound, email) {
  1226. if (email.length == 0) return 0;
  1227. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1228. return clientStats ? clientStats.up + clientStats.down : 0;
  1229. },
  1230. getRemStats(dbInbound, email) {
  1231. if (email.length == 0) return 0;
  1232. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1233. if (!clientStats) return 0;
  1234. remained = clientStats.total - (clientStats.up + clientStats.down);
  1235. return remained>0 ? remained : 0;
  1236. },
  1237. clientStatsColor(dbInbound, email) {
  1238. if (email.length == 0) return clientUsageColor();
  1239. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1240. return clientUsageColor(clientStats, app.trafficDiff)
  1241. },
  1242. statsProgress(dbInbound, email) {
  1243. if (email.length == 0) return 100;
  1244. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1245. if (!clientStats) return 0;
  1246. if (clientStats.total == 0) return 100;
  1247. return 100*(clientStats.down + clientStats.up)/clientStats.total;
  1248. },
  1249. expireProgress(expTime, reset) {
  1250. now = new Date().getTime();
  1251. remainedSeconds = expTime < 0 ? -expTime/1000 : (expTime-now)/1000;
  1252. resetSeconds = reset * 86400;
  1253. if (remainedSeconds >= resetSeconds) return 0;
  1254. return 100*(1-(remainedSeconds/resetSeconds));
  1255. },
  1256. remainedDays(expTime){
  1257. if (expTime == 0) return null;
  1258. if (expTime < 0) return formatSecond(expTime/-1000);
  1259. now = new Date().getTime();
  1260. if (expTime < now) return '{{ i18n "depleted" }}';
  1261. return formatSecond((expTime-now)/1000);
  1262. },
  1263. statsExpColor(dbInbound, email){
  1264. if (email.length == 0) return '#7a316f';
  1265. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1266. if (!clientStats) return '#7a316f';
  1267. statsColor = usageColor(clientStats.down + clientStats.up, this.trafficDiff, clientStats.total);
  1268. expColor = usageColor(new Date().getTime(), this.expireDiff, clientStats.expiryTime);
  1269. switch (true) {
  1270. case statsColor == "red" || expColor == "red":
  1271. return "#cf3c3c"; // Red
  1272. case statsColor == "orange" || expColor == "orange":
  1273. return "#f37b24"; // Orange
  1274. case statsColor == "green" || expColor == "green":
  1275. return "#008771"; // Green
  1276. default:
  1277. return "#7a316f"; // purple
  1278. }
  1279. },
  1280. isClientEnabled(dbInbound, email) {
  1281. clientStats = dbInbound.clientStats ? dbInbound.clientStats.find(stats => stats.email === email) : null;
  1282. return clientStats ? clientStats['enable'] : true;
  1283. },
  1284. isClientOnline(email) {
  1285. return this.onlineClients.includes(email);
  1286. },
  1287. isRemovable(dbInboundId) {
  1288. return this.getInboundClients(this.dbInbounds.find(row => row.id === dbInboundId)).length > 1;
  1289. },
  1290. inboundLinks(dbInboundId) {
  1291. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1292. newDbInbound = this.checkFallback(dbInbound);
  1293. txtModal.show('{{ i18n "pages.inbounds.export"}}', newDbInbound.genInboundLinks(this.remarkModel), newDbInbound.remark);
  1294. },
  1295. exportSubs(dbInboundId) {
  1296. const dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1297. const clients = this.getInboundClients(dbInbound);
  1298. let subLinks = []
  1299. if (clients != null){
  1300. clients.forEach(c => {
  1301. if (c.subId && c.subId.length>0){
  1302. subLinks.push(this.subSettings.subURI + c.subId + "?name=" + c.subId)
  1303. }
  1304. })
  1305. }
  1306. txtModal.show(
  1307. '{{ i18n "pages.inbounds.export"}} - {{ i18n "pages.settings.subSettings" }}',
  1308. [...new Set(subLinks)].join('\n'),
  1309. dbInbound.remark + "-Subs");
  1310. },
  1311. importInbound() {
  1312. promptModal.open({
  1313. title: '{{ i18n "pages.inbounds.importInbound" }}',
  1314. type: 'textarea',
  1315. value: '',
  1316. okText: '{{ i18n "pages.inbounds.import" }}',
  1317. confirm: async (dbInboundText) => {
  1318. await this.submit('/panel/inbound/import', {data: dbInboundText}, promptModal);
  1319. },
  1320. });
  1321. },
  1322. exportAllSubs() {
  1323. let subLinks = []
  1324. for (const dbInbound of this.dbInbounds) {
  1325. const clients = this.getInboundClients(dbInbound);
  1326. if (clients != null){
  1327. clients.forEach(c => {
  1328. if (c.subId && c.subId.length>0){
  1329. subLinks.push(this.subSettings.subURI + c.subId + "?name=" + c.subId)
  1330. }
  1331. })
  1332. }
  1333. }
  1334. txtModal.show(
  1335. '{{ i18n "pages.inbounds.export"}} - {{ i18n "pages.settings.subSettings" }}',
  1336. [...new Set(subLinks)].join('\r\n'),
  1337. 'All-Inbounds-Subs');
  1338. },
  1339. exportAllLinks() {
  1340. let copyText = [];
  1341. for (const dbInbound of this.dbInbounds) {
  1342. copyText.push(dbInbound.genInboundLinks(this.remarkModel));
  1343. }
  1344. txtModal.show('{{ i18n "pages.inbounds.export"}}', copyText.join('\r\n'), 'All-Inbounds');
  1345. },
  1346. copyToClipboard(dbInboundId) {
  1347. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1348. txtModal.show('{{ i18n "pages.inbounds.inboundData" }}', JSON.stringify(dbInbound, null, 2));
  1349. },
  1350. async startDataRefreshLoop() {
  1351. while (this.isRefreshEnabled) {
  1352. try {
  1353. await this.getDBInbounds();
  1354. } catch (e) {
  1355. console.error(e);
  1356. }
  1357. await PromiseUtil.sleep(this.refreshInterval);
  1358. }
  1359. },
  1360. toggleRefresh() {
  1361. localStorage.setItem("isRefreshEnabled", this.isRefreshEnabled);
  1362. if (this.isRefreshEnabled) {
  1363. this.startDataRefreshLoop();
  1364. }
  1365. },
  1366. changeRefreshInterval() {
  1367. localStorage.setItem("refreshInterval", this.refreshInterval);
  1368. },
  1369. async manualRefresh() {
  1370. if (!this.refreshing) {
  1371. this.spinning = true;
  1372. await this.getDBInbounds();
  1373. this.spinning = false;
  1374. }
  1375. },
  1376. pagination(obj){
  1377. if (this.pageSize > 0 && obj.length>this.pageSize) {
  1378. // Set page options based on object size
  1379. sizeOptions = [];
  1380. for (i=this.pageSize;i<=obj.length;i=i+this.pageSize) {
  1381. sizeOptions.push(i.toString());
  1382. }
  1383. // Add option to see all in one page
  1384. sizeOptions.push(i.toString());
  1385. p = {
  1386. showSizeChanger: true,
  1387. size: 'small',
  1388. position: 'bottom',
  1389. pageSize: this.pageSize,
  1390. pageSizeOptions: sizeOptions
  1391. };
  1392. return p;
  1393. }
  1394. return false
  1395. },
  1396. onResize() {
  1397. this.isMobile = window.innerWidth <= 768;
  1398. }
  1399. },
  1400. watch: {
  1401. searchKey: debounce(function (newVal) {
  1402. this.searchInbounds(newVal);
  1403. }, 500)
  1404. },
  1405. mounted() {
  1406. if (window.location.protocol !== "https:") {
  1407. this.showAlert = true;
  1408. }
  1409. window.addEventListener('resize', this.onResize);
  1410. this.onResize();
  1411. this.loading();
  1412. this.getDefaultSettings();
  1413. if (this.isRefreshEnabled) {
  1414. this.startDataRefreshLoop();
  1415. }
  1416. else {
  1417. this.getDBInbounds();
  1418. }
  1419. this.loading(false);
  1420. },
  1421. computed: {
  1422. total() {
  1423. let down = 0, up = 0;
  1424. let clients = 0, deactive = [], depleted = [], expiring = [];
  1425. this.dbInbounds.forEach(dbInbound => {
  1426. down += dbInbound.down;
  1427. up += dbInbound.up;
  1428. if (this.clientCount[dbInbound.id]) {
  1429. clients += this.clientCount[dbInbound.id].clients;
  1430. deactive = deactive.concat(this.clientCount[dbInbound.id].deactive);
  1431. depleted = depleted.concat(this.clientCount[dbInbound.id].depleted);
  1432. expiring = expiring.concat(this.clientCount[dbInbound.id].expiring);
  1433. }
  1434. });
  1435. return {
  1436. down: down,
  1437. up: up,
  1438. clients: clients,
  1439. deactive: deactive,
  1440. depleted: depleted,
  1441. expiring: expiring,
  1442. };
  1443. }
  1444. },
  1445. });
  1446. </script>
  1447. {{template "inboundModal"}}
  1448. {{template "promptModal"}}
  1449. {{template "qrcodeModal"}}
  1450. {{template "textModal"}}
  1451. {{template "inboundInfoModal"}}
  1452. {{template "clientsModal"}}
  1453. {{template "clientsBulkModal"}}
  1454. </body>
  1455. </html>