inbounds.html 77 KB

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