inbounds.html 71 KB

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