inbounds.html 74 KB

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