inbounds.html 74 KB

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