inbounds.html 68 KB

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