inbounds.html 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  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. <script src="{{ .base_path }}assets/base64/base64.min.js"></script>
  430. <script src="{{ .base_path }}assets/qrcode/qrious.min.js"></script>
  431. <script src="{{ .base_path }}assets/clipboard/clipboard.min.js"></script>
  432. <script src="{{ .base_path }}assets/uri/URI.min.js"></script>
  433. <script src="{{ .base_path }}assets/js/model/xray.js?{{ .cur_ver }}"></script>
  434. <script src="{{ .base_path }}assets/js/model/dbinbound.js?{{ .cur_ver }}"></script>
  435. {{template "component/themeSwitcher" .}}
  436. <script>
  437. const columns = [{
  438. title: "ID",
  439. align: 'right',
  440. dataIndex: "id",
  441. width: 30,
  442. responsive: ["xs"],
  443. }, {
  444. title: '{{ i18n "pages.inbounds.operate" }}',
  445. align: 'center',
  446. width: 40,
  447. scopedSlots: { customRender: 'action' },
  448. }, {
  449. title: '{{ i18n "pages.inbounds.enable" }}',
  450. align: 'center',
  451. width: 40,
  452. scopedSlots: { customRender: 'enable' },
  453. }, {
  454. title: '{{ i18n "pages.inbounds.remark" }}',
  455. align: 'center',
  456. width: 80,
  457. dataIndex: "remark",
  458. }, {
  459. title: '{{ i18n "pages.inbounds.port" }}',
  460. align: 'center',
  461. dataIndex: "port",
  462. width: 40,
  463. }, {
  464. title: '{{ i18n "pages.inbounds.protocol" }}',
  465. align: 'left',
  466. width: 90,
  467. scopedSlots: { customRender: 'protocol' },
  468. }, {
  469. title: '{{ i18n "clients" }}',
  470. align: 'left',
  471. width: 50,
  472. scopedSlots: { customRender: 'clients' },
  473. }, {
  474. title: '{{ i18n "pages.inbounds.traffic" }}',
  475. align: 'center',
  476. width: 60,
  477. scopedSlots: { customRender: 'traffic' },
  478. }, {
  479. title: '{{ i18n "pages.inbounds.expireDate" }}',
  480. align: 'center',
  481. width: 40,
  482. scopedSlots: { customRender: 'expiryTime' },
  483. }];
  484. const mobileColums = [{
  485. title: "ID",
  486. align: 'right',
  487. dataIndex: "id",
  488. width: 10,
  489. responsive: ["s"],
  490. }, {
  491. title: '{{ i18n "pages.inbounds.operate" }}',
  492. align: 'center',
  493. width: 25,
  494. scopedSlots: { customRender: 'action' },
  495. }, {
  496. title: '{{ i18n "pages.inbounds.remark" }}',
  497. align: 'left',
  498. width: 70,
  499. dataIndex: "remark",
  500. }, {
  501. title: '{{ i18n "pages.inbounds.info" }}',
  502. align: 'center',
  503. width: 10,
  504. scopedSlots: { customRender: 'info' },
  505. }];
  506. const innerColumns = [
  507. { title: '{{ i18n "pages.inbounds.operate" }}', width: 50, scopedSlots: { customRender: 'actions' } },
  508. { title: '{{ i18n "pages.inbounds.enable" }}', width: 20, scopedSlots: { customRender: 'enable' } },
  509. { title: '{{ i18n "online" }}', width: 20, scopedSlots: { customRender: 'online' } },
  510. { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } },
  511. { title: '{{ i18n "pages.inbounds.traffic" }}', width: 80, align: 'center', scopedSlots: { customRender: 'traffic' } },
  512. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 80, align: 'center', scopedSlots: { customRender: 'expiryTime' } },
  513. ];
  514. const innerMobileColumns = [
  515. { title: '{{ i18n "pages.inbounds.operate" }}', width: 10, align: 'center', scopedSlots: { customRender: 'actionMenu' } },
  516. { title: '{{ i18n "pages.inbounds.client" }}', width: 90, align: 'left', scopedSlots: { customRender: 'client' } },
  517. { title: '{{ i18n "pages.inbounds.info" }}', width: 10, align: 'center', scopedSlots: { customRender: 'info' } },
  518. ];
  519. const app = new Vue({
  520. delimiters: ['[[', ']]'],
  521. el: '#app',
  522. data: {
  523. siderDrawer,
  524. themeSwitcher,
  525. spinning: false,
  526. inbounds: [],
  527. dbInbounds: [],
  528. searchKey: '',
  529. enableFilter: false,
  530. filterBy: '',
  531. searchedInbounds: [],
  532. expireDiff: 0,
  533. trafficDiff: 0,
  534. defaultCert: '',
  535. defaultKey: '',
  536. clientCount: [],
  537. onlineClients: [],
  538. isRefreshEnabled: localStorage.getItem("isRefreshEnabled") === "true" ? true : false,
  539. refreshing: false,
  540. refreshInterval: Number(localStorage.getItem("refreshInterval")) || 5000,
  541. subSettings: {
  542. enable : false,
  543. port: 0,
  544. path: '',
  545. domain: '',
  546. tls: false
  547. },
  548. tgBotEnable: false,
  549. isMobile: window.innerWidth <= 768,
  550. },
  551. methods: {
  552. loading(spinning = true) {
  553. this.spinning = spinning;
  554. },
  555. async getDBInbounds() {
  556. this.refreshing = true;
  557. const msg = await HttpUtil.post('/panel/inbound/list');
  558. if (!msg.success) {
  559. this.refreshing = false;
  560. return;
  561. }
  562. await this.getOnlineUsers();
  563. this.setInbounds(msg.obj);
  564. setTimeout(() => {
  565. this.refreshing = false;
  566. }, 500);
  567. },
  568. async getOnlineUsers() {
  569. const msg = await HttpUtil.post('/panel/inbound/onlines');
  570. if (!msg.success) {
  571. return;
  572. }
  573. this.onlineClients = msg.obj != null ? msg.obj : [];
  574. },
  575. async getDefaultSettings() {
  576. const msg = await HttpUtil.post('/panel/setting/defaultSettings');
  577. if (!msg.success) {
  578. return;
  579. }
  580. with(msg.obj){
  581. this.expireDiff = expireDiff * 86400000;
  582. this.trafficDiff = trafficDiff * 1073741824;
  583. this.defaultCert = defaultCert;
  584. this.defaultKey = defaultKey;
  585. this.tgBotEnable = tgBotEnable;
  586. this.subSettings = {
  587. enable : subEnable,
  588. port: subPort,
  589. path: subPath,
  590. domain: subDomain,
  591. tls: subTLS
  592. };
  593. }
  594. },
  595. setInbounds(dbInbounds) {
  596. this.inbounds.splice(0);
  597. this.dbInbounds.splice(0);
  598. this.clientCount.splice(0);
  599. for (const inbound of dbInbounds) {
  600. const dbInbound = new DBInbound(inbound);
  601. to_inbound = dbInbound.toInbound()
  602. this.inbounds.push(to_inbound);
  603. this.dbInbounds.push(dbInbound);
  604. if ([Protocols.VMESS, Protocols.VLESS, Protocols.TROJAN, Protocols.SHADOWSOCKS].includes(inbound.protocol)) {
  605. if (inbound.protocol === Protocols.SHADOWSOCKS && (!to_inbound.isSSMultiUser)) {
  606. continue;
  607. }
  608. this.clientCount[inbound.id] = this.getClientCounts(inbound, to_inbound);
  609. }
  610. }
  611. if(this.enableFilter){
  612. this.filterInbounds();
  613. } else {
  614. this.searchInbounds(this.searchKey);
  615. }
  616. },
  617. getClientCounts(dbInbound, inbound) {
  618. let clientCount = 0, active = [], deactive = [], depleted = [], expiring = [], online = [];
  619. clients = this.getClients(dbInbound.protocol, inbound.settings);
  620. clientStats = dbInbound.clientStats
  621. now = new Date().getTime()
  622. if (clients) {
  623. clientCount = clients.length;
  624. if (dbInbound.enable) {
  625. clients.forEach(client => {
  626. client.enable ? active.push(client.email) : deactive.push(client.email);
  627. if(this.isClientOnline(client.email)) online.push(client.email);
  628. });
  629. clientStats.forEach(client => {
  630. if (!client.enable) {
  631. depleted.push(client.email);
  632. } else {
  633. if ((client.expiryTime > 0 && (client.expiryTime - now < this.expireDiff)) ||
  634. (client.total > 0 && (client.total - (client.up + client.down) < this.trafficDiff))) expiring.push(client.email);
  635. }
  636. });
  637. } else {
  638. clients.forEach(client => {
  639. deactive.push(client.email);
  640. });
  641. }
  642. }
  643. return {
  644. clients: clientCount,
  645. active: active,
  646. deactive: deactive,
  647. depleted: depleted,
  648. expiring: expiring,
  649. online: online,
  650. };
  651. },
  652. searchInbounds(key) {
  653. if (ObjectUtil.isEmpty(key)) {
  654. this.searchedInbounds = this.dbInbounds.slice();
  655. } else {
  656. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  657. this.dbInbounds.forEach(inbound => {
  658. if (ObjectUtil.deepSearch(inbound, key)) {
  659. const newInbound = new DBInbound(inbound);
  660. const inboundSettings = JSON.parse(inbound.settings);
  661. if (inboundSettings.hasOwnProperty('clients')) {
  662. const searchedSettings = { "clients": [] };
  663. inboundSettings.clients.forEach(client => {
  664. if (ObjectUtil.deepSearch(client, key)) {
  665. searchedSettings.clients.push(client);
  666. }
  667. });
  668. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, searchedSettings);
  669. }
  670. this.searchedInbounds.push(newInbound);
  671. }
  672. });
  673. }
  674. },
  675. filterInbounds() {
  676. if (ObjectUtil.isEmpty(this.filterBy)) {
  677. this.searchedInbounds = this.dbInbounds.slice();
  678. } else {
  679. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  680. this.dbInbounds.forEach(inbound => {
  681. const newInbound = new DBInbound(inbound);
  682. const inboundSettings = JSON.parse(inbound.settings);
  683. if (this.clientCount[inbound.id] && this.clientCount[inbound.id].hasOwnProperty(this.filterBy)){
  684. const list = this.clientCount[inbound.id][this.filterBy];
  685. if (list.length > 0) {
  686. const filteredSettings = { "clients": [] };
  687. inboundSettings.clients.forEach(client => {
  688. if (list.includes(client.email)) {
  689. filteredSettings.clients.push(client);
  690. }
  691. });
  692. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, filteredSettings);
  693. this.searchedInbounds.push(newInbound);
  694. }
  695. }
  696. });
  697. }
  698. },
  699. toggleFilter(){
  700. if(this.enableFilter) {
  701. this.searchKey = '';
  702. } else {
  703. this.filterBy = '';
  704. this.searchedInbounds = this.dbInbounds.slice();
  705. }
  706. },
  707. generalActions(action) {
  708. switch (action.key) {
  709. case "export":
  710. this.exportAllLinks();
  711. break;
  712. case "resetInbounds":
  713. this.resetAllTraffic();
  714. break;
  715. case "resetClients":
  716. this.resetAllClientTraffics(-1);
  717. break;
  718. case "delDepletedClients":
  719. this.delDepletedClients(-1)
  720. break;
  721. }
  722. },
  723. clickAction(action, dbInbound) {
  724. switch (action.key) {
  725. case "qrcode":
  726. this.showQrcode(dbInbound.id);
  727. break;
  728. case "showInfo":
  729. this.showInfo(dbInbound.id);
  730. break;
  731. case "edit":
  732. this.openEditInbound(dbInbound.id);
  733. break;
  734. case "addClient":
  735. this.openAddClient(dbInbound.id)
  736. break;
  737. case "addBulkClient":
  738. this.openAddBulkClient(dbInbound.id)
  739. break;
  740. case "export":
  741. this.inboundLinks(dbInbound.id);
  742. break;
  743. case "resetTraffic":
  744. this.resetTraffic(dbInbound.id);
  745. break;
  746. case "resetClients":
  747. this.resetAllClientTraffics(dbInbound.id);
  748. break;
  749. case "clone":
  750. this.openCloneInbound(dbInbound);
  751. break;
  752. case "delete":
  753. this.delInbound(dbInbound.id);
  754. break;
  755. case "delDepletedClients":
  756. this.delDepletedClients(dbInbound.id)
  757. break;
  758. }
  759. },
  760. openCloneInbound(dbInbound) {
  761. this.$confirm({
  762. title: '{{ i18n "pages.inbounds.cloneInbound"}} \"' + dbInbound.remark + '\"',
  763. content: '{{ i18n "pages.inbounds.cloneInboundContent"}}',
  764. okText: '{{ i18n "pages.inbounds.cloneInboundOk"}}',
  765. class: themeSwitcher.currentTheme,
  766. cancelText: '{{ i18n "cancel" }}',
  767. onOk: () => {
  768. const baseInbound = dbInbound.toInbound();
  769. dbInbound.up = 0;
  770. dbInbound.down = 0;
  771. this.cloneInbound(baseInbound, dbInbound);
  772. },
  773. });
  774. },
  775. async cloneInbound(baseInbound, dbInbound) {
  776. const data = {
  777. up: dbInbound.up,
  778. down: dbInbound.down,
  779. total: dbInbound.total,
  780. remark: dbInbound.remark + " - Cloned",
  781. enable: dbInbound.enable,
  782. expiryTime: dbInbound.expiryTime,
  783. listen: '',
  784. port: RandomUtil.randomIntRange(10000, 60000),
  785. protocol: baseInbound.protocol,
  786. settings: Inbound.Settings.getSettings(baseInbound.protocol).toString(),
  787. streamSettings: baseInbound.stream.toString(),
  788. sniffing: baseInbound.canSniffing() ? baseInbound.sniffing.toString() : '{}',
  789. };
  790. await this.submit('/panel/inbound/add', data, inModal);
  791. },
  792. openAddInbound() {
  793. inModal.show({
  794. title: '{{ i18n "pages.inbounds.addInbound"}}',
  795. okText: '{{ i18n "pages.inbounds.create"}}',
  796. cancelText: '{{ i18n "close" }}',
  797. confirm: async (inbound, dbInbound) => {
  798. inModal.loading();
  799. await this.addInbound(inbound, dbInbound);
  800. inModal.close();
  801. },
  802. isEdit: false
  803. });
  804. },
  805. openEditInbound(dbInboundId) {
  806. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  807. const inbound = dbInbound.toInbound();
  808. inModal.show({
  809. title: '{{ i18n "pages.inbounds.modifyInbound"}}',
  810. okText: '{{ i18n "pages.inbounds.update"}}',
  811. cancelText: '{{ i18n "close" }}',
  812. inbound: inbound,
  813. dbInbound: dbInbound,
  814. confirm: async (inbound, dbInbound) => {
  815. inModal.loading();
  816. await this.updateInbound(inbound, dbInbound);
  817. inModal.close();
  818. },
  819. isEdit: true
  820. });
  821. },
  822. async addInbound(inbound, dbInbound) {
  823. const data = {
  824. up: dbInbound.up,
  825. down: dbInbound.down,
  826. total: dbInbound.total,
  827. remark: dbInbound.remark,
  828. enable: dbInbound.enable,
  829. expiryTime: dbInbound.expiryTime,
  830. listen: inbound.listen,
  831. port: inbound.port,
  832. protocol: inbound.protocol,
  833. settings: inbound.settings.toString(),
  834. };
  835. if (inbound.canEnableStream()) data.streamSettings = inbound.stream.toString();
  836. if (inbound.canSniffing()) data.sniffing = inbound.sniffing.toString();
  837. await this.submit('/panel/inbound/add', data, inModal);
  838. },
  839. async updateInbound(inbound, dbInbound) {
  840. const data = {
  841. up: dbInbound.up,
  842. down: dbInbound.down,
  843. total: dbInbound.total,
  844. remark: dbInbound.remark,
  845. enable: dbInbound.enable,
  846. expiryTime: dbInbound.expiryTime,
  847. listen: inbound.listen,
  848. port: inbound.port,
  849. protocol: inbound.protocol,
  850. settings: inbound.settings.toString(),
  851. };
  852. if (inbound.canEnableStream()) data.streamSettings = inbound.stream.toString();
  853. if (inbound.canSniffing()) data.sniffing = inbound.sniffing.toString();
  854. await this.submit(`/panel/inbound/update/${dbInbound.id}`, data, inModal);
  855. },
  856. openAddClient(dbInboundId) {
  857. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  858. clientModal.show({
  859. title: '{{ i18n "pages.client.add"}}',
  860. okText: '{{ i18n "pages.client.submitAdd"}}',
  861. dbInbound: dbInbound,
  862. confirm: async (clients, dbInboundId) => {
  863. clientModal.loading();
  864. await this.addClient(clients, dbInboundId);
  865. clientModal.close();
  866. },
  867. isEdit: false
  868. });
  869. },
  870. openAddBulkClient(dbInboundId) {
  871. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  872. clientsBulkModal.show({
  873. title: '{{ i18n "pages.client.bulk"}} ' + dbInbound.remark,
  874. okText: '{{ i18n "pages.client.bulk"}}',
  875. dbInbound: dbInbound,
  876. confirm: async (clients, dbInboundId) => {
  877. clientsBulkModal.loading();
  878. await this.addClient(clients, dbInboundId);
  879. clientsBulkModal.close();
  880. },
  881. });
  882. },
  883. openEditClient(dbInboundId, client) {
  884. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  885. clients = this.getInboundClients(dbInbound);
  886. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  887. clientModal.show({
  888. title: '{{ i18n "pages.client.edit"}}',
  889. okText: '{{ i18n "pages.client.submitEdit"}}',
  890. dbInbound: dbInbound,
  891. index: index,
  892. confirm: async (client, dbInboundId, clientId) => {
  893. clientModal.loading();
  894. await this.updateClient(client, dbInboundId, clientId);
  895. clientModal.close();
  896. },
  897. isEdit: true
  898. });
  899. },
  900. findIndexOfClient(protocol, clients, client) {
  901. switch (protocol) {
  902. case Protocols.TROJAN:
  903. case Protocols.SHADOWSOCKS:
  904. return clients.findIndex(item => item.password === client.password && item.email === client.email);
  905. default: return clients.findIndex(item => item.id === client.id && item.email === client.email);
  906. }
  907. },
  908. async addClient(clients, dbInboundId) {
  909. const data = {
  910. id: dbInboundId,
  911. settings: '{"clients": [' + clients.toString() + ']}',
  912. };
  913. await this.submit(`/panel/inbound/addClient`, data);
  914. },
  915. async updateClient(client, dbInboundId, clientId) {
  916. const data = {
  917. id: dbInboundId,
  918. settings: '{"clients": [' + client.toString() + ']}',
  919. };
  920. await this.submit(`/panel/inbound/updateClient/${clientId}`, data);
  921. },
  922. resetTraffic(dbInboundId) {
  923. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  924. this.$confirm({
  925. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  926. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  927. class: themeSwitcher.currentTheme,
  928. okText: '{{ i18n "reset"}}',
  929. cancelText: '{{ i18n "cancel"}}',
  930. onOk: () => {
  931. const inbound = dbInbound.toInbound();
  932. dbInbound.up = 0;
  933. dbInbound.down = 0;
  934. this.updateInbound(inbound, dbInbound);
  935. },
  936. });
  937. },
  938. delInbound(dbInboundId) {
  939. this.$confirm({
  940. title: '{{ i18n "pages.inbounds.deleteInbound"}}',
  941. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  942. class: themeSwitcher.currentTheme,
  943. okText: '{{ i18n "delete"}}',
  944. cancelText: '{{ i18n "cancel"}}',
  945. onOk: () => this.submit('/panel/inbound/del/' + dbInboundId),
  946. });
  947. },
  948. delClient(dbInboundId, client,confirmation = true) {
  949. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  950. clientId = this.getClientId(dbInbound.protocol, client);
  951. if (confirmation){
  952. this.$confirm({
  953. title: '{{ i18n "pages.inbounds.deleteClient"}}',
  954. content: '{{ i18n "pages.inbounds.deleteClientContent"}}',
  955. class: themeSwitcher.currentTheme,
  956. okText: '{{ i18n "delete"}}',
  957. cancelText: '{{ i18n "cancel"}}',
  958. onOk: () => this.submit(`/panel/inbound/${dbInboundId}/delClient/${clientId}`),
  959. });
  960. } else {
  961. this.submit(`/panel/inbound/${dbInboundId}/delClient/${clientId}`);
  962. }
  963. },
  964. getClients(protocol, clientSettings) {
  965. switch (protocol) {
  966. case Protocols.VMESS: return clientSettings.vmesses;
  967. case Protocols.VLESS: return clientSettings.vlesses;
  968. case Protocols.TROJAN: return clientSettings.trojans;
  969. case Protocols.SHADOWSOCKS: return clientSettings.shadowsockses;
  970. default: return null;
  971. }
  972. },
  973. getClientId(protocol, client) {
  974. switch (protocol) {
  975. case Protocols.TROJAN: return client.password;
  976. case Protocols.SHADOWSOCKS: return client.email;
  977. default: return client.id;
  978. }
  979. },
  980. checkFallback(dbInbound) {
  981. newDbInbound = new DBInbound(dbInbound);
  982. if (dbInbound.listen.startsWith("@")){
  983. rootInbound = this.inbounds.find((i) =>
  984. i.tls &&
  985. ['trojan','vless'].includes(i.protocol) &&
  986. i.settings.fallbacks.find(f => f.dest === dbInbound.listen)
  987. );
  988. if (rootInbound) {
  989. newDbInbound.listen = rootInbound.listen;
  990. newDbInbound.port = rootInbound.port;
  991. newInbound = newDbInbound.toInbound();
  992. newInbound.stream.security = 'tls';
  993. newInbound.stream.tls = rootInbound.stream.tls;
  994. newDbInbound.streamSettings = newInbound.stream.toString();
  995. }
  996. }
  997. return newDbInbound;
  998. },
  999. showQrcode(dbInboundId, client) {
  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. newDbInbound = this.checkFallback(dbInbound);
  1005. qrModal.show('{{ i18n "qrCode"}}', newDbInbound, index);
  1006. },
  1007. showInfo(dbInboundId, client) {
  1008. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1009. inbound = dbInbound.toInbound();
  1010. clients = this.getClients(dbInbound.protocol, inbound.settings);
  1011. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1012. newDbInbound = this.checkFallback(dbInbound);
  1013. infoModal.show(newDbInbound, index);
  1014. },
  1015. switchEnable(dbInboundId) {
  1016. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1017. this.submit(`/panel/inbound/update/${dbInboundId}`, dbInbound);
  1018. },
  1019. async switchEnableClient(dbInboundId, client) {
  1020. this.loading()
  1021. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1022. inbound = dbInbound.toInbound();
  1023. clients = this.getClients(dbInbound.protocol, inbound.settings);
  1024. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1025. clients[index].enable = !clients[index].enable;
  1026. clientId = this.getClientId(dbInbound.protocol, clients[index]);
  1027. await this.updateClient(clients[index], dbInboundId, clientId);
  1028. this.loading(false);
  1029. },
  1030. async submit(url, data) {
  1031. const msg = await HttpUtil.postWithModal(url, data);
  1032. if (msg.success) {
  1033. await this.getDBInbounds();
  1034. }
  1035. },
  1036. getInboundClients(dbInbound) {
  1037. if (dbInbound.protocol == Protocols.VLESS) {
  1038. return dbInbound.toInbound().settings.vlesses;
  1039. } else if (dbInbound.protocol == Protocols.VMESS) {
  1040. return dbInbound.toInbound().settings.vmesses;
  1041. } else if (dbInbound.protocol == Protocols.TROJAN) {
  1042. return dbInbound.toInbound().settings.trojans;
  1043. } else if (dbInbound.protocol == Protocols.SHADOWSOCKS) {
  1044. return dbInbound.toInbound().settings.shadowsockses;
  1045. }
  1046. },
  1047. resetClientTraffic(client, dbInboundId, confirmation = true) {
  1048. if (confirmation){
  1049. this.$confirm({
  1050. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  1051. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  1052. class: themeSwitcher.currentTheme,
  1053. okText: '{{ i18n "reset"}}',
  1054. cancelText: '{{ i18n "cancel"}}',
  1055. onOk: () => this.submit('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + client.email),
  1056. })
  1057. } else {
  1058. this.submit('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + client.email);
  1059. }
  1060. },
  1061. resetAllTraffic() {
  1062. this.$confirm({
  1063. title: '{{ i18n "pages.inbounds.resetAllTrafficTitle"}}',
  1064. content: '{{ i18n "pages.inbounds.resetAllTrafficContent"}}',
  1065. class: themeSwitcher.currentTheme,
  1066. okText: '{{ i18n "reset"}}',
  1067. cancelText: '{{ i18n "cancel"}}',
  1068. onOk: () => this.submit('/panel/inbound/resetAllTraffics'),
  1069. });
  1070. },
  1071. resetAllClientTraffics(dbInboundId) {
  1072. this.$confirm({
  1073. title: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficTitle"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficTitle"}}',
  1074. content: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficContent"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficContent"}}',
  1075. class: themeSwitcher.currentTheme,
  1076. okText: '{{ i18n "reset"}}',
  1077. cancelText: '{{ i18n "cancel"}}',
  1078. onOk: () => this.submit('/panel/inbound/resetAllClientTraffics/' + dbInboundId),
  1079. })
  1080. },
  1081. delDepletedClients(dbInboundId) {
  1082. this.$confirm({
  1083. title: '{{ i18n "pages.inbounds.delDepletedClientsTitle"}}',
  1084. content: '{{ i18n "pages.inbounds.delDepletedClientsContent"}}',
  1085. class: themeSwitcher.currentTheme,
  1086. okText: '{{ i18n "reset"}}',
  1087. cancelText: '{{ i18n "cancel"}}',
  1088. onOk: () => this.submit('/panel/inbound/delDepletedClients/' + dbInboundId),
  1089. })
  1090. },
  1091. isExpiry(dbInbound, index) {
  1092. return dbInbound.toInbound().isExpiry(index);
  1093. },
  1094. getUpStats(dbInbound, email) {
  1095. if (email.length == 0) return 0;
  1096. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1097. return clientStats ? clientStats.up : 0;
  1098. },
  1099. getDownStats(dbInbound, email) {
  1100. if (email.length == 0) return 0;
  1101. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1102. return clientStats ? clientStats.down : 0;
  1103. },
  1104. getSumStats(dbInbound, email) {
  1105. if (email.length == 0) return 0;
  1106. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1107. return clientStats ? clientStats.up + clientStats.down : 0;
  1108. },
  1109. getRemStats(dbInbound, email) {
  1110. if (email.length == 0) return 0;
  1111. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1112. if (!clientStats) return 0;
  1113. remained = clientStats.total - (clientStats.up + clientStats.down);
  1114. return remained>0 ? remained : 0;
  1115. },
  1116. clientStatsColor(dbInbound, email) {
  1117. if (email.length == 0) return clientUsageColor();
  1118. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1119. return clientUsageColor(clientStats, app.trafficDiff)
  1120. },
  1121. statsProgress(dbInbound, email) {
  1122. if (email.length == 0) return 100;
  1123. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1124. if (!clientStats) return 0;
  1125. if (clientStats.total == 0) return 100;
  1126. return 100*(clientStats.down + clientStats.up)/clientStats.total;
  1127. },
  1128. expireProgress(expTime, reset) {
  1129. now = new Date().getTime();
  1130. remainedSeconds = expTime < 0 ? -expTime/1000 : (expTime-now)/1000;
  1131. resetSeconds = reset * 86400;
  1132. if (remainedSeconds >= resetSeconds) return 0;
  1133. return 100*(1-(remainedSeconds/resetSeconds));
  1134. },
  1135. remainedDays(expTime){
  1136. if (expTime == 0) return null;
  1137. if (expTime < 0) return formatSecond(expTime/-1000);
  1138. now = new Date().getTime();
  1139. if (expTime < now) return '{{ i18n "depleted" }}';
  1140. return formatSecond((expTime-now)/1000);
  1141. },
  1142. statsExpColor(dbInbound, email){
  1143. if (email.length == 0) return '#7a316f';
  1144. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1145. if (!clientStats) return '#7a316f';
  1146. statsColor = usageColor(clientStats.down + clientStats.up, this.trafficDiff, clientStats.total);
  1147. expColor = usageColor(new Date().getTime(), this.expireDiff, clientStats.expiryTime);
  1148. switch (true) {
  1149. case statsColor == "red" || expColor == "red":
  1150. return "#E04141";
  1151. case statsColor == "orange" || expColor == "orange":
  1152. return "#FFA031";
  1153. case statsColor == "blue" || expColor == "blue":
  1154. return "#0e49b5";
  1155. default:
  1156. return "#7a316f";
  1157. }
  1158. },
  1159. isClientEnabled(dbInbound, email) {
  1160. clientStats = dbInbound.clientStats ? dbInbound.clientStats.find(stats => stats.email === email) : null;
  1161. return clientStats ? clientStats['enable'] : true;
  1162. },
  1163. isClientOnline(email) {
  1164. return this.onlineClients.includes(email);
  1165. },
  1166. isRemovable(dbInboundId) {
  1167. return this.getInboundClients(this.dbInbounds.find(row => row.id === dbInboundId)).length > 1
  1168. },
  1169. inboundLinks(dbInboundId) {
  1170. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1171. newDbInbound = this.checkFallback(dbInbound);
  1172. txtModal.show('{{ i18n "pages.inbounds.export"}}', newDbInbound.genInboundLinks, newDbInbound.remark);
  1173. },
  1174. exportAllLinks() {
  1175. let copyText = '';
  1176. for (const dbInbound of this.dbInbounds) {
  1177. copyText += dbInbound.genInboundLinks;
  1178. }
  1179. txtModal.show('{{ i18n "pages.inbounds.export"}}', copyText, 'All-Inbounds');
  1180. },
  1181. async startDataRefreshLoop() {
  1182. while (this.isRefreshEnabled) {
  1183. try {
  1184. await this.getDBInbounds();
  1185. } catch (e) {
  1186. console.error(e);
  1187. }
  1188. await PromiseUtil.sleep(this.refreshInterval);
  1189. }
  1190. },
  1191. toggleRefresh() {
  1192. localStorage.setItem("isRefreshEnabled", this.isRefreshEnabled);
  1193. if (this.isRefreshEnabled) {
  1194. this.startDataRefreshLoop();
  1195. }
  1196. },
  1197. changeRefreshInterval() {
  1198. localStorage.setItem("refreshInterval", this.refreshInterval);
  1199. },
  1200. async manualRefresh() {
  1201. if (!this.refreshing) {
  1202. this.spinning = true;
  1203. await this.getDBInbounds();
  1204. this.spinning = false;
  1205. }
  1206. },
  1207. onResize() {
  1208. this.isMobile = window.innerWidth <= 768;
  1209. }
  1210. },
  1211. watch: {
  1212. searchKey: debounce(function (newVal) {
  1213. this.searchInbounds(newVal);
  1214. }, 500)
  1215. },
  1216. mounted() {
  1217. window.addEventListener('resize', this.onResize);
  1218. this.onResize();
  1219. this.loading();
  1220. this.getDefaultSettings();
  1221. if (this.isRefreshEnabled) {
  1222. this.startDataRefreshLoop();
  1223. }
  1224. else {
  1225. this.getDBInbounds();
  1226. }
  1227. this.loading(false);
  1228. },
  1229. computed: {
  1230. total() {
  1231. let down = 0, up = 0;
  1232. let clients = 0, deactive = [], depleted = [], expiring = [];
  1233. this.dbInbounds.forEach(dbInbound => {
  1234. down += dbInbound.down;
  1235. up += dbInbound.up;
  1236. if (this.clientCount[dbInbound.id]) {
  1237. clients += this.clientCount[dbInbound.id].clients;
  1238. deactive = deactive.concat(this.clientCount[dbInbound.id].deactive);
  1239. depleted = depleted.concat(this.clientCount[dbInbound.id].depleted);
  1240. expiring = expiring.concat(this.clientCount[dbInbound.id].expiring);
  1241. }
  1242. });
  1243. return {
  1244. down: down,
  1245. up: up,
  1246. clients: clients,
  1247. deactive: deactive,
  1248. depleted: depleted,
  1249. expiring: expiring,
  1250. };
  1251. }
  1252. },
  1253. });
  1254. </script>
  1255. {{template "inboundModal"}}
  1256. {{template "promptModal"}}
  1257. {{template "qrcodeModal"}}
  1258. {{template "textModal"}}
  1259. {{template "inboundInfoModal"}}
  1260. {{template "clientsModal"}}
  1261. {{template "clientsBulkModal"}}
  1262. </body>
  1263. </html>