inbounds.html 71 KB

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