1
0

inbounds.html 78 KB

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