inbounds.html 71 KB

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