inbounds.html 69 KB

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