inbounds.html 79 KB

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