inbounds.html 69 KB

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