1
0

inbounds.html 71 KB

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