1
0

inbounds.html 66 KB

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