inbounds.html 73 KB

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